Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Oct 10, 2023
1 parent cd8cb85 commit 01bc7c8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/struct_pack/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ cc_test(
deps = [
"//:ylt"
],
data = [
"//src/struct_pack/tests/binary_data:test_cross_platform.dat",
"//src/struct_pack/tests/binary_data:test_cross_platform_without_debug_info.dat"
],
)
1 change: 1 addition & 0 deletions src/struct_pack/tests/binary_data/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["test_cross_platform.dat","test_cross_platform_without_debug_info.dat"])
Binary file modified src/struct_pack/tests/binary_data/test_cross_platform.dat
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions src/struct_pack/tests/test_cross_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,36 @@ TEST_CASE("testing deserialize other platform data without debug info") {
REQUIRE(result.has_value());
auto object = create_complicated_object();
CHECK(result.value() == object);
}

TEST_CASE("testing serialize other platform data") {
std::ifstream ifs("binary_data/test_cross_platform.dat");
if (!ifs.is_open()) {
ifs.open("src/struct_pack/tests/binary_data/test_cross_platform.dat");
}
REQUIRE(ifs.is_open());
std::string content(std::istreambuf_iterator<char>{ifs},
std::istreambuf_iterator<char>{});
auto object = create_complicated_object();
auto buffer =
struct_pack::serialize<std::string,
struct_pack::type_info_config::enable>(object);
CHECK(buffer == content);
}

TEST_CASE("testing serialize other platform data") {
std::ifstream ifs("binary_data/test_cross_platform_without_debug_info.dat");
if (!ifs.is_open()) {
ifs.open(
"src/struct_pack/tests/binary_data/"
"test_cross_platform_without_debug_info.dat");
}
REQUIRE(ifs.is_open());
std::string content(std::istreambuf_iterator<char>{ifs},
std::istreambuf_iterator<char>{});
auto object = create_complicated_object();
auto buffer =
struct_pack::serialize<std::string,
struct_pack::type_info_config::disable>(object);
CHECK(buffer == content);
}
4 changes: 2 additions & 2 deletions src/struct_pack/tests/test_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ inline complicated_object create_complicated_object() {
{1, 2},
{{1, {20, "tom"}}, {1, {22, "jerry"}}},
{{1, 2}, {1, 3}},
{person{20, "tom"}, {22, "jerry"}},
{person{20, "tom"}, {22, "jerry"}},
{person{20, "tom"}},
{person{26, "tom"}},
std::make_pair("aa", person{20, "tom"})};
}

Expand Down

0 comments on commit 01bc7c8

Please sign in to comment.