-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deb7154
commit ab72519
Showing
43 changed files
with
1,396 additions
and
77 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
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,46 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_add_struct_name { | ||
|
||
using Age = rfl::Validator<unsigned int, rfl::Minimum<0>, rfl::Maximum<130>>; | ||
|
||
struct Person { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
std::string town = "Springfield"; | ||
rfl::Timestamp<"%Y-%m-%d"> birthday; | ||
Age age; | ||
rfl::Email email; | ||
std::vector<Person> children; | ||
}; | ||
|
||
TEST(ubjson, test_add_struct_name) { | ||
const auto bart = Person{.first_name = "Bart", | ||
.birthday = "1987-04-19", | ||
.age = 10, | ||
.email = "[email protected]"}; | ||
|
||
const auto lisa = Person{.first_name = "Lisa", | ||
.birthday = "1987-04-19", | ||
.age = 8, | ||
.email = "[email protected]"}; | ||
|
||
const auto maggie = Person{.first_name = "Maggie", | ||
.birthday = "1987-04-19", | ||
.age = 0, | ||
.email = "[email protected]"}; | ||
|
||
const auto homer = | ||
Person{.first_name = "Homer", | ||
.birthday = "1987-04-19", | ||
.age = 45, | ||
.email = "[email protected]", | ||
.children = std::vector<Person>({bart, lisa, maggie})}; | ||
|
||
write_and_read<rfl::AddStructName<"type">>(homer); | ||
} | ||
} // namespace test_add_struct_name |
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,35 @@ | ||
#include <array> | ||
#include <iostream> | ||
#include <memory> | ||
#include <rfl/ubjson.hpp> | ||
#include <string> | ||
|
||
// Make sure things still compile when | ||
// rfl.hpp is included after rfl/ubjson.hpp. | ||
#include <rfl.hpp> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_array { | ||
|
||
struct Person { | ||
rfl::Rename<"firstName", std::string> first_name; | ||
rfl::Rename<"lastName", std::string> last_name = "Simpson"; | ||
std::unique_ptr<std::array<Person, 3>> children = nullptr; | ||
}; | ||
|
||
TEST(ubjson, test_array) { | ||
auto bart = Person{.first_name = "Bart"}; | ||
|
||
auto lisa = Person{.first_name = "Lisa"}; | ||
|
||
auto maggie = Person{.first_name = "Maggie"}; | ||
|
||
const auto homer = Person{ | ||
.first_name = "Homer", | ||
.children = std::make_unique<std::array<Person, 3>>(std::array<Person, 3>{ | ||
std::move(bart), std::move(lisa), std::move(maggie)})}; | ||
|
||
write_and_read(homer); | ||
} | ||
} // namespace test_array |
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,44 @@ | ||
#include <cassert> | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_box { | ||
|
||
struct DecisionTree { | ||
struct Leaf { | ||
using Tag = rfl::Literal<"Leaf">; | ||
double value; | ||
}; | ||
|
||
struct Node { | ||
using Tag = rfl::Literal<"Node">; | ||
rfl::Rename<"criticalValue", double> critical_value; | ||
rfl::Box<DecisionTree> lesser; | ||
rfl::Box<DecisionTree> greater; | ||
}; | ||
|
||
using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; | ||
|
||
rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; | ||
}; | ||
|
||
TEST(ubjson, test_box) { | ||
auto leaf1 = DecisionTree::Leaf{.value = 3.0}; | ||
|
||
auto leaf2 = DecisionTree::Leaf{.value = 5.0}; | ||
|
||
auto node = DecisionTree::Node{ | ||
.critical_value = 10.0, | ||
.lesser = rfl::make_box<DecisionTree>(DecisionTree{leaf1}), | ||
.greater = rfl::make_box<DecisionTree>(DecisionTree{leaf2})}; | ||
|
||
const DecisionTree tree{.leaf_or_node = std::move(node)}; | ||
|
||
write_and_read(tree); | ||
|
||
} | ||
} // namespace test_box |
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,21 @@ | ||
#include <iostream> | ||
#include <rfl.hpp> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "write_and_read.hpp" | ||
|
||
namespace test_bytestring { | ||
|
||
struct TestStruct { | ||
rfl::Bytestring bytestring; | ||
}; | ||
|
||
TEST(ubjson, test_bytestring) { | ||
const auto test = | ||
TestStruct{.bytestring = rfl::Bytestring({std::byte{13}, std::byte{14}, | ||
std::byte{15}, std::byte{16}})}; | ||
|
||
write_and_read(test); | ||
} | ||
} // namespace test_bytestring |
Oops, something went wrong.