szdytom 6b0875ee34
complete ProcedureManager
Signed-off-by: szdytom <szdytom@qq.com>
2024-02-04 15:55:43 +08:00

51 lines
990 B
C++

#include "pc/ProcedureManager.h"
#include "pc/BinaryBuffer.h"
#include "test/u.hpp"
#include <tuple>
#include <cstdint>
inline namespace {
using Void = std::tuple<>;
AddTestCase _(20, "ProcedureManager", [](TestCase& t) {
t.expectEq<int>([] {
std::int32_t x = 0;
auto f1 = [&x] (std::int32_t d) -> Void {
x += d;
return {};
};
auto f2 = [&x] (std::int32_t d) -> Void {
x -= d;
return {};
};
ProcedureManager pm;
pm.registerProcedure(1, f1);
pm.registerProcedure(2, f2);
unsigned char ibuf[256] = {
0x45, 0x27, 0xd1, 0xf2, 0x93, 0x43, 0xfc, 0xb1,
0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x45, 0x27, 0xd1, 0xf2, 0x93, 0x43, 0xfc, 0xb2,
0x02, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
};
unsigned char obuf[256];
FILE *in = fmemopen(ibuf, 256, "r"),
*out = fmemopen(obuf, 256, "w");
pm.handleCall(in, out);
pm.handleCall(in, out);
return x;
}, 1);
});
}