MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / TEST

Function TEST

test/loader/serializeModuleTest.cpp:15–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13WasmEdge::Loader::Serializer Ser(Conf);
14
15TEST(serializeModuleTest, SerializeModule) {
16 std::vector<uint8_t> Expected;
17 std::vector<uint8_t> Output;
18
19 // 1. Test serialize module.
20 //
21 // 1. Serialize module only with magic and version;
22 // 2. Serialize module with ordered sections.
23
24 WasmEdge::AST::Module Module;
25
26 Module.getMagic() = {0x00U, 0x61U, 0x73U, 0x6DU};
27 Module.getVersion() = {0x01U, 0x00U, 0x00U, 0x00U};
28 Output = *Ser.serializeModule(Module);
29 Expected = {
30 0x00U, 0x61U, 0x73U, 0x6DU, // Magic
31 0x01U, 0x00U, 0x00U, 0x00U, // Version
32 };
33 EXPECT_EQ(Output, Expected);
34
35 WasmEdge::AST::CustomSection Sec1;
36 Sec1.setName("2");
37 Sec1.setStartOffset(2);
38 WasmEdge::AST::CustomSection Sec2;
39 Sec2.setName("3");
40 Sec2.setStartOffset(3);
41 WasmEdge::AST::CustomSection Sec3;
42 Sec3.setName("1");
43 Sec3.setStartOffset(1);
44 Module.getCustomSections() = {Sec1, Sec2, Sec3};
45
46 Output = *Ser.serializeModule(Module);
47 Expected = {
48 0x00U, 0x61U, 0x73U, 0x6DU, // Magic
49 0x01U, 0x00U, 0x00U, 0x00U, // Version
50 0x00U, 0x02U, 0x01U, 0x31U, // Sec3
51 0x00U, 0x02U, 0x01U, 0x32U, // Sec1
52 0x00U, 0x02U, 0x01U, 0x33U, // Sec2
53 };
54 EXPECT_EQ(Output, Expected);
55}
56} // namespace

Callers

nothing calls this directly

Calls 5

setNameMethod · 0.80
setStartOffsetMethod · 0.80
getCustomSectionsMethod · 0.80
getVersionMethod · 0.45
serializeModuleMethod · 0.45

Tested by

no test coverage detected