Skip to content

Commit

Permalink
[UTest] Guard checks of sanity fields with macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
ImmanuelHaffner committed Apr 26, 2023
1 parent b402b72 commit 7252fde
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions unittest/IR/TupleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,71 @@ using namespace m;
* Value
*====================================================================================================================*/

#ifdef M_ENABLE_SANITY_FIELDS
TEST_CASE("Value/default c'tor", "[core][storage][Value]")
{
Value val;
REQUIRE(val.type == Value::VNone);
}
#endif

TEST_CASE("Value/value c'tor", "[core][storage][Value]")
{
SECTION("b")
{
Value val(true);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vb);
#endif
REQUIRE(val.as_b() == true);
}
SECTION("i32")
{
Value val(42);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vi);
#endif
REQUIRE(val.as_i() == 42);
}
SECTION("i64")
{
Value val(1337L);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vi);
#endif
REQUIRE(val.as_i() == 1337L);
}
SECTION("u64")
{
Value val(1337UL);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vi);
#endif
REQUIRE(val.as_i() == 1337L);
}
SECTION("f")
{
Value val(3.14f);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vf);
#endif
REQUIRE(val.as_f() == 3.14f);
}
SECTION("d")
{
Value val(3.14159);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vd);
#endif
REQUIRE(val.as_d() == 3.14159);
}
SECTION("p")
{
int x;
Value val(&x);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vp);
#endif
REQUIRE(val.as_p() == &x);
}
}
Expand Down Expand Up @@ -112,50 +128,74 @@ TEST_CASE("Value/assignment", "[core][storage][Value]")
SECTION("b")
{
src = true;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vb);
#endif
REQUIRE(src.as_b() == true);

dst = src;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vb);
#endif
REQUIRE(src.as_b() == true);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(dst.type == Value::Vb);
#endif
REQUIRE(dst.as_b() == true);
}
SECTION("i32")
{
src = 42;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vi);
#endif
REQUIRE(src.as_i() == 42);

dst = src;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vi);
#endif
REQUIRE(src.as_i() == 42);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(dst.type == Value::Vi);
#endif
REQUIRE(dst.as_i() == 42);
}
SECTION("i64")
{
src = 1337L;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vi);
#endif
REQUIRE(src.as_i() == 1337L);

dst = src;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vi);
#endif
REQUIRE(src.as_i() == 1337L);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(dst.type == Value::Vi);
#endif
REQUIRE(dst.as_i() == 1337L);
}
SECTION("p")
{
int x;
src = &x;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vp);
#endif
REQUIRE(src.as_p() == &x);

dst = src;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(src.type == Value::Vp);
#endif
REQUIRE(src.as_p() == &x);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(dst.type == Value::Vp);
#endif
REQUIRE(dst.as_p() == &x);
}
}
Expand All @@ -168,21 +208,27 @@ TEST_CASE("Value/conversion assignment", "[core][storage][Value]")
{
val = true;
val.as_b() = false;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vb);
#endif
REQUIRE(val.as_b() == false);
}
SECTION("i32")
{
val = 1337;
val.as_i() = 42;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vi);
#endif
REQUIRE(val.as_i() == 42);
}
SECTION("i64")
{
val = 42L;
val.as_i() = 1337L;
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(val.type == Value::Vi);
#endif
REQUIRE(val.as_i() == 1337L);
}
}
Expand Down
6 changes: 6 additions & 0 deletions unittest/io/DSVReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,17 @@ TEST_CASE("DSVReader::operator() sanity tests", "[core][io][unit]")
table.layout(), S));
Tuple *args[] = { &tup };
(*W)(args);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(tup[0].type == m::Value::VNone);
#endif
(*W)(args);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(tup[0].type == m::Value::VNone);
#endif
(*W)(args);
#ifdef M_ENABLE_SANITY_FIELDS
REQUIRE(tup[0].type == m::Value::VNone);
#endif
}

SECTION("Const<CharacterSequence>& sanity tests")
Expand Down

0 comments on commit 7252fde

Please sign in to comment.