| 13 | WasmEdge::Loader::Serializer Ser(Conf); |
| 14 | |
| 15 | TEST(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 |
nothing calls this directly
no test coverage detected