56 lines
1.1 KiB
C++

#include "pc/ProcedureManager.h"
#include "pc/BinaryBuffer.h"
#include "test/u.hpp"
#include <tuple>
#include <cstdint>
#include <cstdio>
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,
};
FILE *in = fopen(".in.tmp", "wb");
fwrite(ibuf, 128, 1, in);
fclose(in);
in = fopen(".in.tmp", "rb");
FILE *out = fopen(".out.tmp", "wb");
pm.handleCall(in, out);
pm.handleCall(in, out);
fclose(in);
fclose(out);
return x;
}, 1);
});
}