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

Function TEST

test/loader/serializeDescriptionTest.cpp:27–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27TEST(SerializeDescriptionTest, SerializeImportDesc) {
28 WasmEdge::AST::ImportDesc Desc;
29 std::vector<uint8_t> Expected;
30 std::vector<uint8_t> Output;
31
32 WasmEdge::Configure ConfNoImpMutGlob;
33 ConfNoImpMutGlob.setWASMStandard(WasmEdge::Standard::WASM_1);
34 ConfNoImpMutGlob.removeProposal(WasmEdge::Proposal::ImportExportMutGlobals);
35 WasmEdge::Loader::Serializer SerNoImpMutGlob(ConfNoImpMutGlob);
36 WasmEdge::Configure ConfWASM2;
37 ConfWASM2.setWASMStandard(WasmEdge::Standard::WASM_2);
38 WasmEdge::Loader::Serializer SerWASM2(ConfWASM2);
39
40 // 1. Test serialize import description.
41 //
42 // 1. Serialize import description with empty module and external name.
43 // 2. Serialize import description with module and external names.
44 // 3. Serialize import description of table type.
45 // 4. Serialize import description of memory type.
46 // 5. Serialize import description of global type.
47 // 6. Serialize invalid import description of global type without
48 // Mut-Globals proposal.
49 // 7. Serialize import description of tag type.
50 // 8. Serialize import description of tag type without the exception
51 // handling proposal.
52
53 Desc.setModuleName("");
54 Desc.setExternalName("");
55 Desc.setExternalType(WasmEdge::ExternalType::Function);
56 Desc.setExternalFuncTypeIdx(0x00U);
57
58 Output = {};
59 EXPECT_TRUE(Ser.serializeSection(createImportSec(Desc), Output));
60 Expected = {
61 0x02U, // Import section
62 0x05U, // Content size = 5
63 0x01U, // Vector length = 1
64 0x00U, // Empty module name
65 0x00U, // Empty external name
66 0x00U, 0x00U // function type and index
67 };
68 EXPECT_EQ(Output, Expected);
69
70 Desc.setModuleName("test");
71 Desc.setExternalName("Loader");
72 Desc.setExternalType(WasmEdge::ExternalType::Function);
73 Desc.setExternalFuncTypeIdx(0x00U);
74
75 Output = {};
76 EXPECT_TRUE(Ser.serializeSection(createImportSec(Desc), Output));
77 Expected = {
78 0x02U, // Import section
79 0x0FU, // Content size = 15
80 0x01U, // Vector length = 1
81 0x04U, 0x74U, 0x65U, 0x73U, 0x74U, // Module name: test
82 0x06U, 0x4CU, 0x6FU, 0x61U, 0x64U, 0x65U, 0x72U, // External name: Loader
83 0x00U, 0x00U // function type and index
84 };

Callers

nothing calls this directly

Calls 15

createImportSecFunction · 0.85
createExportSecFunction · 0.85
setWASMStandardMethod · 0.80
removeProposalMethod · 0.80
setModuleNameMethod · 0.80
setExternalNameMethod · 0.80
setExternalTypeMethod · 0.80
serializeSectionMethod · 0.80
setMinMethod · 0.80
setMaxMethod · 0.80
setTypeIdxMethod · 0.80

Tested by

no test coverage detected