84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "matador/object/schema.hpp"
|
|
|
|
#include "../../models/department.hpp"
|
|
|
|
struct node {};
|
|
|
|
using namespace matador;
|
|
|
|
struct person {
|
|
virtual ~person() = default;
|
|
template < typename Operator >
|
|
void process(Operator &/*op*/) {}
|
|
};
|
|
|
|
struct student final : person {};
|
|
struct teacher final : person {};
|
|
|
|
struct names {
|
|
std::vector<std::string> names_list;
|
|
|
|
template<typename Operator>
|
|
void process(Operator &op) {
|
|
namespace field = matador::access;
|
|
field::has_many(op, "name_list", names_list, "names_id", utils::fetch_type::EAGER);
|
|
}
|
|
};
|
|
|
|
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
|
|
const object::schema tree;
|
|
|
|
REQUIRE( tree.empty() );
|
|
}
|
|
|
|
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
|
|
object::schema tree;
|
|
|
|
REQUIRE( tree.empty() );
|
|
|
|
auto res = tree.attach<person>("person");
|
|
REQUIRE( res.is_ok() );
|
|
res = tree.attach<student, person>("student");
|
|
REQUIRE( res.is_ok() );
|
|
res = tree.attach<teacher, person>("teacher");
|
|
REQUIRE( res.is_ok() );
|
|
|
|
REQUIRE( !tree.empty() );
|
|
REQUIRE( tree.size() == 3 );
|
|
}
|
|
|
|
TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") {
|
|
object::schema tree;
|
|
|
|
REQUIRE( tree.empty() );
|
|
|
|
auto res = tree.attach<person>("person");
|
|
REQUIRE( res.is_ok() );
|
|
|
|
REQUIRE( tree.size() == 1 );
|
|
|
|
auto it = tree.begin();
|
|
REQUIRE( it->name() == "person" );
|
|
REQUIRE( (--it)->name() == "person" );
|
|
REQUIRE( ++it == tree.end() );
|
|
}
|
|
|
|
TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") {
|
|
object::schema tree;
|
|
|
|
REQUIRE( tree.empty() );
|
|
|
|
auto res = tree.attach<test::department>("department");
|
|
REQUIRE( res.is_ok() );
|
|
}
|
|
|
|
TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") {
|
|
object::schema tree;
|
|
|
|
REQUIRE( tree.empty() );
|
|
|
|
auto res = tree.attach<names>("names");
|
|
REQUIRE( res.is_ok() );
|
|
} |