-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[struct_pack] add test for cross_platform (#471)
- Loading branch information
1 parent
62dd9f2
commit 44ea4e4
Showing
8 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file added
BIN
+184 Bytes
src/struct_pack/tests/binary_data/test_cross_platform_without_debug_info.dat
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <cstdint> | ||
#include <fstream> | ||
#include <ylt/struct_pack.hpp> | ||
|
||
#include "doctest.h" | ||
#include "test_struct.hpp" | ||
using namespace struct_pack; | ||
using namespace doctest; | ||
|
||
TEST_CASE("testing deserialize 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()); | ||
auto result = struct_pack::deserialize<complicated_object>(ifs); | ||
REQUIRE(result.has_value()); | ||
auto object = create_complicated_object(); | ||
CHECK(result.value() == object); | ||
} | ||
|
||
TEST_CASE("testing deserialize other platform data without debug info") { | ||
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()); | ||
auto result = struct_pack::deserialize<complicated_object>(ifs); | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters