MCPcopy Create free account
hub / github.com/apache/fory / run_test_map

Function run_test_map

cpp/fory/serialization/xlang_test_main.cc:1661–1692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1659}
1660
1661void run_test_map(const std::string &data_file) {
1662 auto bytes = read_file(data_file);
1663 auto fory = build_fory(true, true);
1664 ensure_ok(fory.register_struct<Item>(102), "register Item");
1665 Buffer buffer = make_buffer(bytes);
1666
1667 using OptStr = std::optional<std::string>;
1668 using OptItem = std::optional<Item>;
1669 std::map<OptStr, OptStr> str_map = {{std::string("k1"), std::string("v1")},
1670 {std::nullopt, std::string("v2")},
1671 {std::string("k3"), std::nullopt},
1672 {std::string("k4"), std::string("v4")}};
1673 Item item1{std::string("item1")};
1674 Item item2{std::string("item2")};
1675 Item item3{std::string("item3")};
1676 std::map<OptStr, OptItem> item_map = {{std::string("k1"), item1},
1677 {std::nullopt, item2},
1678 {std::string("k3"), std::nullopt},
1679 {std::string("k4"), item3}};
1680
1681 if (read_next<std::map<OptStr, OptStr>>(fory, buffer) != str_map) {
1682 fail("Map<string,string> mismatch");
1683 }
1684 if (read_next<std::map<OptStr, OptItem>>(fory, buffer) != item_map) {
1685 fail("Map<string,item> mismatch");
1686 }
1687
1688 std::vector<uint8_t> out;
1689 append_serialized(fory, str_map, out);
1690 append_serialized(fory, item_map, out);
1691 write_file(data_file, out);
1692}
1693
1694void run_test_integer(const std::string &data_file) {
1695 auto bytes = read_file(data_file);

Callers 1

mainFunction · 0.85

Calls 8

read_fileFunction · 0.85
ensure_okFunction · 0.85
make_bufferFunction · 0.85
failFunction · 0.85
append_serializedFunction · 0.85
write_fileFunction · 0.85
build_foryFunction · 0.70
stringFunction · 0.50

Tested by

no test coverage detected