From 74a14be0e4af617ca898faa61adde9f7e828603a Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 27 Sep 2024 12:58:07 -0700 Subject: [PATCH 01/21] Add GoogleTest to AX test; run cppunit and gtest in tandem for gradual conversion; convert TestPrinters to gtest Signed-off-by: Tim Straubinger --- openvdb_ax/openvdb_ax/test/CMakeLists.txt | 12 ++++ .../openvdb_ax/test/ast/TestPrinters.cc | 58 ++++++++----------- openvdb_ax/openvdb_ax/test/main.cc | 9 ++- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/CMakeLists.txt b/openvdb_ax/openvdb_ax/test/CMakeLists.txt index 3a72871cfe..af59537680 100644 --- a/openvdb_ax/openvdb_ax/test/CMakeLists.txt +++ b/openvdb_ax/openvdb_ax/test/CMakeLists.txt @@ -52,6 +52,18 @@ endif() find_package(CppUnit ${MINIMUM_CPPUNIT_VERSION} REQUIRED) list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS CppUnit::cppunit) +find_package(GTest ${MINIMUM_GOOGLETEST_VERSION} REQUIRED) + +if(TARGET GTest::gtest_main) + # New gtest targets as of CMake 3.20. Defined by both the Config and Module + # find modes + list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS GTest::gtest GTest::gtest_main) +else() + # Older targets, only defined by the Module find_package calls + list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS GTest::GTest GTest::Main) +endif() + + set(TEST_SOURCE_FILES ast/TestScanners.cc ast/TestPrinters.cc diff --git a/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc b/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc index 9c00e40cba..eb54d43d7d 100644 --- a/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc +++ b/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -13,40 +13,30 @@ using namespace openvdb::ax::ast; using namespace openvdb::ax::ast::tokens; -class TestPrinters : public CppUnit::TestCase +class TestPrinters : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestPrinters); - CPPUNIT_TEST(testReprint); - CPPUNIT_TEST_SUITE_END(); - - void testReprint(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestPrinters); - -void TestPrinters::testReprint() +TEST_F(TestPrinters, testReprint) { // Small function providing more verbose output on failures auto check = [](const std::string& in, const std::string& expected) { const size_t min = std::min(in.size(), expected.size()); for (size_t i = 0; i < min; ++i) { if (in[i] != expected[i]) { - std::ostringstream msg; - msg << "TestReprint failed at character " << i << '.' + std::cout << "TestReprint failed at character " << i << '.' << '[' << in[i] << "] vs [" << expected[i] << "]\n" << "Got:\n" << in << "Expected:\n" << expected; - CPPUNIT_FAIL(msg.str()); + ADD_FAILURE(); + return; } } if (in.size() != expected.size()) { - std::ostringstream msg; - msg << "TestReprint failed at end character.\n" + std::cout << "TestReprint failed at end character.\n" << "Got:\n" << in << "Expected:\n" << expected ; - CPPUNIT_FAIL(msg.str()); + ADD_FAILURE(); } }; @@ -54,9 +44,9 @@ void TestPrinters::testReprint() // Test binary ops std::string in = "a + b * c / d % e << f >> g = h & i | j ^ k && l || m;"; - std::string expected = "(((a + (((b * c) / d) % e)) << f) >> g = ((((h & i) | (j ^ k)) && l) || m));\n"; + std::string expected = "((( a + (((b * c) / d) % e)) << f) >> g = ((((h & i) | (j ^ k)) && l) || m));\n"; Tree::ConstPtr tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -65,7 +55,7 @@ void TestPrinters::testReprint() in = "(a + b) * (c / d) % e << (f) >> g = (((h & i) | j) ^ k) && l || m;"; expected = "(((((a + b) * (c / d)) % e) << f) >> g = (((((h & i) | j) ^ k) && l) || m));\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -74,7 +64,7 @@ void TestPrinters::testReprint() in = "a <= b; c >= d; e == f; g != h; i < j; k > l;"; expected = "(a <= b);\n(c >= d);\n(e == f);\n(g != h);\n(i < j);\n(k > l);\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -83,7 +73,7 @@ void TestPrinters::testReprint() in = "a = b; b += c; c -= d; d /= e; e *= f; f %= 1; g &= 2; h |= 3; i ^= 4; j <<= 5; k >>= 6;"; expected = "a = b;\nb += c;\nc -= d;\nd /= e;\ne *= f;\nf %= 1;\ng &= 2;\nh |= 3;\ni ^= 4;\nj <<= 5;\nk >>= 6;\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -92,7 +82,7 @@ void TestPrinters::testReprint() in = "++++a; ----b; a++; b--;"; expected = "++++a;\n----b;\na++;\nb--;\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -101,7 +91,7 @@ void TestPrinters::testReprint() in = "a,b,(c,d),(e,(f,(g,h,i)));"; expected = "(a, b, (c, d), (e, (f, (g, h, i))));\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -110,7 +100,7 @@ void TestPrinters::testReprint() in = "a.x; b.y; c.z; d[0]; d[1,2]; e[(a.r, c.b), b.g];"; expected = "a[0];\nb[1];\nc[2];\nd[0];\nd[1, 2];\ne[(a[0], c[2]), b[1]];\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -119,7 +109,7 @@ void TestPrinters::testReprint() in = "a = {0,1}; b = {2,3,4}; c = {a,(b,c), d};"; expected = "a = {0, 1};\nb = {2, 3, 4};\nc = {a, (b, c), d};\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -128,7 +118,7 @@ void TestPrinters::testReprint() in = "bool a; int b,c; int32 d=0, e; int64 f; float g; double h, i=0;"; expected = "bool a;\nint32 b, c;\nint32 d = 0, e;\nint64 f;\nfloat g;\ndouble h, i = 0;\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -137,7 +127,7 @@ void TestPrinters::testReprint() in = "if (a) b; else if (c) d; else e; if (a) if (b) { c,d; } else { e,f; }"; expected = "if (a)\n{\nb;\n}\nelse\n{\nif (c)\n{\nd;\n}\nelse\n{\ne;\n}\n}\nif (a)\n{\nif (b)\n{\n(c, d);\n}\nelse\n{\n(e, f);\n}\n}\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -146,7 +136,7 @@ void TestPrinters::testReprint() in = "return; break; continue; true; false;"; expected = "return;\nbreak;\ncontinue;\ntrue;\nfalse;\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -155,7 +145,7 @@ void TestPrinters::testReprint() in = "@a; $a; v@b; v$b; f@a; f$a; i@c; i$c; s@d; s$d;"; expected = "float@a;\nfloat$a;\nvec3f@b;\nvec3f$b;\nfloat@a;\nfloat$a;\nint32@c;\nint32$c;\nstring@d;\nstring$d;\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -164,7 +154,7 @@ void TestPrinters::testReprint() in = "a ? b : c; a ? b ? c ? : d : e : f;"; expected = "a ? b : c;\na ? b ? c ?: d : e : f;\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -173,7 +163,7 @@ void TestPrinters::testReprint() in = "while (a) for (int32 b, c;;) do { d; } while (e)"; expected = "while (a)\n{\nfor (int32 b, c; true; )\n{\ndo\n{\nd;\n}\nwhile (e)\n}\n}\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); check(os.str(), ("{\n" + expected + "}\n")); @@ -182,7 +172,7 @@ void TestPrinters::testReprint() in = "while (a) for (int32 b, c;;) do { d; } while (e)"; expected = " while (a)\n {\n for (int32 b, c; true; )\n {\n do\n {\n d;\n }\n while (e)\n }\n }\n"; tree = parse(in.c_str()); - CPPUNIT_ASSERT(tree.get()); + ASSERT_TRUE(tree.get()); reprint(*tree, os, " "); check(os.str(), ("{\n" + expected + "}\n")); } diff --git a/openvdb_ax/openvdb_ax/test/main.cc b/openvdb_ax/openvdb_ax/test/main.cc index 12670ebbd6..fa3bce1bdc 100644 --- a/openvdb_ax/openvdb_ax/test/main.cc +++ b/openvdb_ax/openvdb_ax/test/main.cc @@ -17,6 +17,8 @@ #include #include +#include + #include // for std::shuffle() #include // for std::round() #include // for EXIT_SUCCESS @@ -274,11 +276,14 @@ main(int argc, char *argv[]) registerType>(); registerType>(); - auto value = run(argc, argv); + auto cppunit_result = run(argc, argv); + + ::testing::InitGoogleTest(&argc, argv); + auto gtest_result = RUN_ALL_TESTS(); openvdb::ax::uninitialize(); openvdb::uninitialize(); - return value; + return (cppunit_result == 0 ? gtest_result : cppunit_result); } From 7aa409a18d9d72cfa9dc8efc96a3bb6bee26f4f6 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 14:26:50 -0700 Subject: [PATCH 02/21] Revert deliberate test failure used for testing Signed-off-by: Tim Straubinger --- openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc b/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc index eb54d43d7d..675d42188c 100644 --- a/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc +++ b/openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc @@ -44,7 +44,7 @@ TEST_F(TestPrinters, testReprint) // Test binary ops std::string in = "a + b * c / d % e << f >> g = h & i | j ^ k && l || m;"; - std::string expected = "((( a + (((b * c) / d) % e)) << f) >> g = ((((h & i) | (j ^ k)) && l) || m));\n"; + std::string expected = "(((a + (((b * c) / d) % e)) << f) >> g = ((((h & i) | (j ^ k)) && l) || m));\n"; Tree::ConstPtr tree = parse(in.c_str()); ASSERT_TRUE(tree.get()); reprint(*tree, os, ""); From 1c51ba5431806f7eee0c79055eb51aac17d312dd Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 15:01:12 -0700 Subject: [PATCH 03/21] Convert TestScanners.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/ast/TestScanners.cc | 356 ++++++++---------- 1 file changed, 159 insertions(+), 197 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/ast/TestScanners.cc b/openvdb_ax/openvdb_ax/test/ast/TestScanners.cc index 5381af88fe..748180de8d 100644 --- a/openvdb_ax/openvdb_ax/test/ast/TestScanners.cc +++ b/openvdb_ax/openvdb_ax/test/ast/TestScanners.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include @@ -98,26 +98,11 @@ const std::vector indirect = { } -class TestScanners : public CppUnit::TestCase +class TestScanners : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestScanners); - CPPUNIT_TEST(testVisitNodeType); - CPPUNIT_TEST(testFirstLastLocation); - CPPUNIT_TEST(testAttributeDependencyTokens); - // CPPUNIT_TEST(testVariableDependencies); - CPPUNIT_TEST_SUITE_END(); - - void testVisitNodeType(); - void testFirstLastLocation(); - void testAttributeDependencyTokens(); - // void testVariableDependencies(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestScanners); - -void TestScanners::testVisitNodeType() +TEST_F(TestScanners, testVisitNodeType) { size_t count = 0; auto counter = [&](const Node&) -> bool { @@ -128,19 +113,19 @@ void TestScanners::testVisitNodeType() Node::Ptr node(new Attribute("a", CoreType::INT64)); visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(1), count); + ASSERT_EQ(size_t(1), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(0), count); + ASSERT_EQ(size_t(0), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(1), count); + ASSERT_EQ(size_t(1), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(1), count); + ASSERT_EQ(size_t(1), count); // "{1.0f, 2.0, 3};" node.reset(new ArrayPack( { @@ -151,27 +136,27 @@ void TestScanners::testVisitNodeType() count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(4), count); + ASSERT_EQ(size_t(4), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(0), count); + ASSERT_EQ(size_t(0), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(3), count); + ASSERT_EQ(size_t(3), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(1), count); + ASSERT_EQ(size_t(1), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(4), count); + ASSERT_EQ(size_t(4), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(4), count); + ASSERT_EQ(size_t(4), count); // "@a += v@b.x = x %= 1;" // @note 9 explicit nodes @@ -193,34 +178,34 @@ void TestScanners::testVisitNodeType() count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(9), count); + ASSERT_EQ(size_t(9), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(1), count); + ASSERT_EQ(size_t(1), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(2), count); + ASSERT_EQ(size_t(2), count); count = 0; visitNodeType>(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(2), count); + ASSERT_EQ(size_t(2), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(1), count); + ASSERT_EQ(size_t(1), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(3), count); + ASSERT_EQ(size_t(3), count); count = 0; visitNodeType(*node, counter); - CPPUNIT_ASSERT_EQUAL(size_t(9), count); + ASSERT_EQ(size_t(9), count); } -void TestScanners::testFirstLastLocation() +TEST_F(TestScanners, testFirstLastLocation) { // The list of above code sets which are expected to have the same // first and last use of @a. @@ -233,13 +218,12 @@ void TestScanners::testFirstLastLocation() for (const auto& samples : snippets) { for (const std::string& code : *samples) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); const Variable* first = firstUse(*tree, "@a"); const Variable* last = lastUse(*tree, "@a"); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Unable to locate first @a AST node", code), first); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Unable to locate last @a AST node", code), last); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid first/last AST node comparison", code), - first == last); + ASSERT_TRUE(first) << ERROR_MSG("Unable to locate first @a AST node", code); + ASSERT_TRUE(last) << ERROR_MSG("Unable to locate last @a AST node", code); + ASSERT_TRUE(first == last) << ERROR_MSG("Invalid first/last AST node comparison", code); } } @@ -254,15 +238,13 @@ void TestScanners::testFirstLastLocation() static_cast(node.get())->lhs(); const Node* expectedLast = static_cast(node.get())->rhs(); - CPPUNIT_ASSERT(expectedFirst != expectedLast); + ASSERT_TRUE(expectedFirst != expectedLast); const Node* first = firstUse(*node, "@a"); const Node* last = lastUse(*node, "@a"); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", "@a=@a"), - first, expectedFirst); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", "@a=@a"), - last, expectedLast); + ASSERT_EQ(first, expectedFirst) << ERROR_MSG("Unexpected location of @a AST node", "@a=@a"); + ASSERT_EQ(last, expectedLast) << ERROR_MSG("Unexpected location of @a AST node", "@a=@a"); // for(@a;@a;@a) { @a; } node.reset(new Loop( @@ -275,15 +257,13 @@ void TestScanners::testFirstLastLocation() expectedFirst = static_cast(node.get())->initial(); expectedLast = static_cast(node.get())->body()->child(0); - CPPUNIT_ASSERT(expectedFirst != expectedLast); + ASSERT_TRUE(expectedFirst != expectedLast); first = firstUse(*node, "@a"); last = lastUse(*node, "@a"); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", - "for(@a;@a;@a) { @a; }"), first, expectedFirst); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", - "for(@a;@a;@a) { @a; }"), last, expectedLast); + ASSERT_EQ(first, expectedFirst) << ERROR_MSG("Unexpected location of @a AST node", "for(@a;@a;@a) { @a; }"); + ASSERT_EQ(last, expectedLast) << ERROR_MSG("Unexpected location of @a AST node", "for(@a;@a;@a) { @a; }"); // do { @a; } while(@a); node.reset(new Loop( @@ -296,15 +276,13 @@ void TestScanners::testFirstLastLocation() expectedFirst = static_cast(node.get())->body()->child(0); expectedLast = static_cast(node.get())->condition(); - CPPUNIT_ASSERT(expectedFirst != expectedLast); + ASSERT_TRUE(expectedFirst != expectedLast); first = firstUse(*node, "@a"); last = lastUse(*node, "@a"); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", - "do { @a; } while(@a);"), first, expectedFirst); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", - "do { @a; } while(@a);"), last, expectedLast); + ASSERT_EQ(first, expectedFirst) << ERROR_MSG("Unexpected location of @a AST node", "do { @a; } while(@a);"); + ASSERT_EQ(last, expectedLast) << ERROR_MSG("Unexpected location of @a AST node", "do { @a; } while(@a);"); // if (@a) {} else if (@a) {} else { @a; } node.reset(new ConditionalStatement( @@ -326,67 +304,60 @@ void TestScanners::testFirstLastLocation() ->falseBranch()->child(0)) ->falseBranch()->child(0); - CPPUNIT_ASSERT(expectedFirst != expectedLast); + ASSERT_TRUE(expectedFirst != expectedLast); first = firstUse(*node, "@a"); last = lastUse(*node, "@a"); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", - "if (@a) {} else if (1) {} else { @a; }"), first, expectedFirst); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Unexpected location of @a AST node", - "if (@a) {} else if (1) {} else { @a; }"), last, expectedLast); + ASSERT_EQ(first, expectedFirst) << ERROR_MSG("Unexpected location of @a AST node", "if (@a) {} else if (1) {} else { @a; }"); + ASSERT_EQ(last, expectedLast) << ERROR_MSG("Unexpected location of @a AST node", "if (@a) {} else if (1) {} else { @a; }"); } -void TestScanners::testAttributeDependencyTokens() +TEST_F(TestScanners, testAttributeDependencyTokens) { for (const std::string& code : none) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); std::vector dependencies; attributeDependencyTokens(*tree, "a", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Expected 0 deps", code), - dependencies.empty()); + ASSERT_TRUE(dependencies.empty()) << ERROR_MSG("Expected 0 deps", code); } for (const std::string& code : self) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); std::vector dependencies; attributeDependencyTokens(*tree, "a", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT(!dependencies.empty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - dependencies.front(), std::string("float@a")); + ASSERT_TRUE(!dependencies.empty()); + ASSERT_EQ(dependencies.front(), std::string("float@a")) << ERROR_MSG("Invalid variable dependency", code); } for (const std::string& code : direct) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); std::vector dependencies; attributeDependencyTokens(*tree, "a", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT(!dependencies.empty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - dependencies.front(), std::string("float@b")); + ASSERT_TRUE(!dependencies.empty()); + ASSERT_EQ(dependencies.front(), std::string("float@b")) << ERROR_MSG("Invalid variable dependency", code); } for (const std::string& code : directvec) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); std::vector dependencies; attributeDependencyTokens(*tree, "a", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT(!dependencies.empty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - dependencies.front(), std::string("vec3f@b")); + ASSERT_TRUE(!dependencies.empty()); + ASSERT_EQ(dependencies.front(), std::string("vec3f@b")) << ERROR_MSG("Invalid variable dependency", code); } for (const std::string& code : indirect) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); std::vector dependencies; attributeDependencyTokens(*tree, "a", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT(!dependencies.empty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - dependencies.front(), std::string("float@b")); + ASSERT_TRUE(!dependencies.empty()); + ASSERT_EQ(dependencies.front(), std::string("float@b")) << ERROR_MSG("Invalid variable dependency", code); } // Test a more complicated code snippet. Note that this also checks the @@ -413,121 +384,112 @@ void TestScanners::testAttributeDependencyTokens() "}"; const Tree::ConstPtr tree = parse(complex.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); std::vector dependencies; attributeDependencyTokens(*tree, "b", tokens::CoreType::FLOAT, dependencies); // @b should depend on: @a, @e, @f, v@v - CPPUNIT_ASSERT_EQUAL(size_t(4), dependencies.size()); - CPPUNIT_ASSERT_EQUAL(dependencies[0], std::string("float@a")); - CPPUNIT_ASSERT_EQUAL(dependencies[1], std::string("float@e")); - CPPUNIT_ASSERT_EQUAL(dependencies[2], std::string("float@f")); - CPPUNIT_ASSERT_EQUAL(dependencies[3], std::string("vec3f@v")); + ASSERT_EQ(size_t(4), dependencies.size()); + ASSERT_EQ(dependencies[0], std::string("float@a")); + ASSERT_EQ(dependencies[1], std::string("float@e")); + ASSERT_EQ(dependencies[2], std::string("float@f")); + ASSERT_EQ(dependencies[3], std::string("vec3f@v")); // @c should depend on: @a, @c, @d, @e, @f dependencies.clear(); attributeDependencyTokens(*tree, "c", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT_EQUAL(size_t(5), dependencies.size()); - CPPUNIT_ASSERT_EQUAL(dependencies[0], std::string("float@a")); - CPPUNIT_ASSERT_EQUAL(dependencies[1], std::string("float@c")); - CPPUNIT_ASSERT_EQUAL(dependencies[2], std::string("float@d")); - CPPUNIT_ASSERT_EQUAL(dependencies[3], std::string("float@e")); - CPPUNIT_ASSERT_EQUAL(dependencies[4], std::string("float@f")); + ASSERT_EQ(size_t(5), dependencies.size()); + ASSERT_EQ(dependencies[0], std::string("float@a")); + ASSERT_EQ(dependencies[1], std::string("float@c")); + ASSERT_EQ(dependencies[2], std::string("float@d")); + ASSERT_EQ(dependencies[3], std::string("float@e")); + ASSERT_EQ(dependencies[4], std::string("float@f")); // @d should depend on: @d, @e dependencies.clear(); attributeDependencyTokens(*tree, "d", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT_EQUAL(size_t(2), dependencies.size()); - CPPUNIT_ASSERT_EQUAL(dependencies[0], std::string("float@d")); - CPPUNIT_ASSERT_EQUAL(dependencies[1], std::string("float@e")); + ASSERT_EQ(size_t(2), dependencies.size()); + ASSERT_EQ(dependencies[0], std::string("float@d")); + ASSERT_EQ(dependencies[1], std::string("float@e")); // @e should depend on itself dependencies.clear(); attributeDependencyTokens(*tree, "e", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT_EQUAL(size_t(1), dependencies.size()); - CPPUNIT_ASSERT_EQUAL(dependencies[0], std::string("float@e")); + ASSERT_EQ(size_t(1), dependencies.size()); + ASSERT_EQ(dependencies[0], std::string("float@e")); // @f should depend on nothing dependencies.clear(); attributeDependencyTokens(*tree, "f", tokens::CoreType::FLOAT, dependencies); - CPPUNIT_ASSERT(dependencies.empty()); + ASSERT_TRUE(dependencies.empty()); // @v should depend on: v@v dependencies.clear(); attributeDependencyTokens(*tree, "v", tokens::CoreType::VEC3F, dependencies); - CPPUNIT_ASSERT_EQUAL(size_t(1), dependencies.size()); - CPPUNIT_ASSERT_EQUAL(dependencies[0], std::string("vec3f@v")); + ASSERT_EQ(size_t(1), dependencies.size()); + ASSERT_EQ(dependencies[0], std::string("vec3f@v")); } /* -void TestScanners::testVariableDependencies() +TEST_F(TestScanners, testVariableDependencies) { for (const std::string& code : none) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); const Variable* last = lastUse(*tree, "@a"); - CPPUNIT_ASSERT(last); + ASSERT_TRUE(last); std::vector vars; variableDependencies(*last, vars); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Expected 0 deps", code), - vars.empty()); + ASSERT_TRUE(vars.empty()) << ERROR_MSG("Expected 0 deps", code); } for (const std::string& code : self) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); const Variable* last = lastUse(*tree, "@a"); - CPPUNIT_ASSERT(last); + ASSERT_TRUE(last); std::vector vars; variableDependencies(*last, vars); const Variable* var = vars.front(); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - var->isType()); + ASSERT_TRUE(var->isType()) << ERROR_MSG("Invalid variable dependency", code); const Attribute* attrib = static_cast(var); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - std::string("float@a"), attrib->tokenname()); + ASSERT_EQ(std::string("float@a"), attrib->tokenname()) << ERROR_MSG("Invalid variable dependency", code); } for (const std::string& code : direct) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); const Variable* last = lastUse(*tree, "@a"); - CPPUNIT_ASSERT(last); + ASSERT_TRUE(last); std::vector vars; variableDependencies(*last, vars); const Variable* var = vars.front(); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - var->isType()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - std::string("b"), var->name()); + ASSERT_TRUE(var->isType()) << ERROR_MSG("Invalid variable dependency", code); + ASSERT_EQ(std::string("b"), var->name()) << ERROR_MSG("Invalid variable dependency", code); } for (const std::string& code : indirect) { const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); const Variable* last = lastUse(*tree, "@a"); - CPPUNIT_ASSERT(last); + ASSERT_TRUE(last); std::vector vars; variableDependencies(*last, vars); // check c const Variable* var = vars[0]; - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - var->isType()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - std::string("c"), var->name()); + ASSERT_TRUE(var->isType()) << ERROR_MSG("Invalid variable dependency", code); + ASSERT_EQ(std::string("c"), var->name()) << ERROR_MSG("Invalid variable dependency", code); // check @b var = vars[1]; - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - var->isType()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MSG("Invalid variable dependency", code), - std::string("b"), var->name()); + ASSERT_TRUE(var->isType()) << ERROR_MSG("Invalid variable dependency", code); + ASSERT_EQ(std::string("b"), var->name()) << ERROR_MSG("Invalid variable dependency", code); } // Test a more complicated code snippet. Note that this also checks the @@ -554,7 +516,7 @@ void TestScanners::testVariableDependencies() "}"; const Tree::ConstPtr tree = parse(complex.c_str()); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); const Variable* lasta = lastUse(*tree, "@a"); const Variable* lastb = lastUse(*tree, "@b"); const Variable* lastc = lastUse(*tree, "@c"); @@ -562,100 +524,100 @@ void TestScanners::testVariableDependencies() const Variable* laste = lastUse(*tree, "@e"); const Variable* lastf = lastUse(*tree, "@f"); const Variable* lastv = lastUse(*tree, "vec3f@v"); - CPPUNIT_ASSERT(lasta); - CPPUNIT_ASSERT(lastb); - CPPUNIT_ASSERT(lastc); - CPPUNIT_ASSERT(lastd); - CPPUNIT_ASSERT(laste); - CPPUNIT_ASSERT(lastf); - CPPUNIT_ASSERT(lastv); + ASSERT_TRUE(lasta); + ASSERT_TRUE(lastb); + ASSERT_TRUE(lastc); + ASSERT_TRUE(lastd); + ASSERT_TRUE(laste); + ASSERT_TRUE(lastf); + ASSERT_TRUE(lastv); std::vector vars; variableDependencies(*lasta, vars); - CPPUNIT_ASSERT(vars.empty()); + ASSERT_TRUE(vars.empty()); // @b should depend on: m, m, v@v, @a, @e, @e, f1, f2, f3, @f variableDependencies(*lastb, vars); - CPPUNIT_ASSERT_EQUAL(10ul, vars.size()); - CPPUNIT_ASSERT(vars[0]->isType()); - CPPUNIT_ASSERT(vars[0]->name() == "m"); - CPPUNIT_ASSERT(vars[1]->isType()); - CPPUNIT_ASSERT(vars[1]->name() == "m"); - CPPUNIT_ASSERT(vars[2]->isType()); - CPPUNIT_ASSERT(static_cast(vars[2])->tokenname() == "vec3f@v"); - CPPUNIT_ASSERT(vars[3]->isType()); - CPPUNIT_ASSERT(static_cast(vars[3])->tokenname() == "float@a"); - CPPUNIT_ASSERT(vars[4]->isType()); - CPPUNIT_ASSERT(static_cast(vars[4])->tokenname() == "float@e"); - CPPUNIT_ASSERT(vars[5]->isType()); - CPPUNIT_ASSERT(static_cast(vars[5])->tokenname() == "float@e"); - CPPUNIT_ASSERT(vars[6]->isType()); - CPPUNIT_ASSERT(vars[6]->name() == "f1"); - CPPUNIT_ASSERT(vars[7]->isType()); - CPPUNIT_ASSERT(vars[7]->name() == "f2"); - CPPUNIT_ASSERT(vars[8]->isType()); - CPPUNIT_ASSERT(vars[8]->name() == "f3"); - CPPUNIT_ASSERT(vars[9]->isType()); - CPPUNIT_ASSERT(static_cast(vars[9])->tokenname() == "float@f"); + ASSERT_EQ(10ul, vars.size()); + ASSERT_TRUE(vars[0]->isType()); + ASSERT_TRUE(vars[0]->name() == "m"); + ASSERT_TRUE(vars[1]->isType()); + ASSERT_TRUE(vars[1]->name() == "m"); + ASSERT_TRUE(vars[2]->isType()); + ASSERT_TRUE(static_cast(vars[2])->tokenname() == "vec3f@v"); + ASSERT_TRUE(vars[3]->isType()); + ASSERT_TRUE(static_cast(vars[3])->tokenname() == "float@a"); + ASSERT_TRUE(vars[4]->isType()); + ASSERT_TRUE(static_cast(vars[4])->tokenname() == "float@e"); + ASSERT_TRUE(vars[5]->isType()); + ASSERT_TRUE(static_cast(vars[5])->tokenname() == "float@e"); + ASSERT_TRUE(vars[6]->isType()); + ASSERT_TRUE(vars[6]->name() == "f1"); + ASSERT_TRUE(vars[7]->isType()); + ASSERT_TRUE(vars[7]->name() == "f2"); + ASSERT_TRUE(vars[8]->isType()); + ASSERT_TRUE(vars[8]->name() == "f3"); + ASSERT_TRUE(vars[9]->isType()); + ASSERT_TRUE(static_cast(vars[9])->tokenname() == "float@f"); // @c should depend on: @c, a, @e, @d, a, @e, @a, @e, f1, f2, f3, @f vars.clear(); variableDependencies(*lastc, vars); - CPPUNIT_ASSERT_EQUAL(11ul, vars.size()); - CPPUNIT_ASSERT(vars[0]->isType()); - CPPUNIT_ASSERT(static_cast(vars[0])->tokenname() == "float@c"); - CPPUNIT_ASSERT(vars[1]->isType()); - CPPUNIT_ASSERT(vars[1]->name() == "a"); - CPPUNIT_ASSERT(vars[2]->isType()); - CPPUNIT_ASSERT(static_cast(vars[2])->tokenname() == "float@e"); - CPPUNIT_ASSERT(vars[3]->isType()); - CPPUNIT_ASSERT(static_cast(vars[3])->tokenname() == "float@d"); - CPPUNIT_ASSERT(vars[4]->isType()); - CPPUNIT_ASSERT(vars[4]->name() == "a"); - CPPUNIT_ASSERT(vars[5]->isType()); - CPPUNIT_ASSERT(static_cast(vars[5])->tokenname() == "float@a"); - CPPUNIT_ASSERT(vars[6]->isType()); - CPPUNIT_ASSERT(static_cast(vars[6])->tokenname() == "float@e"); - CPPUNIT_ASSERT(vars[7]->isType()); - CPPUNIT_ASSERT(vars[7]->name() == "f1"); - CPPUNIT_ASSERT(vars[8]->isType()); - CPPUNIT_ASSERT(vars[8]->name() == "f2"); - CPPUNIT_ASSERT(vars[9]->isType()); - CPPUNIT_ASSERT(vars[9]->name() == "f3"); - CPPUNIT_ASSERT(vars[10]->isType()); - CPPUNIT_ASSERT(static_cast(vars[10])->tokenname() == "float@f"); + ASSERT_EQ(11ul, vars.size()); + ASSERT_TRUE(vars[0]->isType()); + ASSERT_TRUE(static_cast(vars[0])->tokenname() == "float@c"); + ASSERT_TRUE(vars[1]->isType()); + ASSERT_TRUE(vars[1]->name() == "a"); + ASSERT_TRUE(vars[2]->isType()); + ASSERT_TRUE(static_cast(vars[2])->tokenname() == "float@e"); + ASSERT_TRUE(vars[3]->isType()); + ASSERT_TRUE(static_cast(vars[3])->tokenname() == "float@d"); + ASSERT_TRUE(vars[4]->isType()); + ASSERT_TRUE(vars[4]->name() == "a"); + ASSERT_TRUE(vars[5]->isType()); + ASSERT_TRUE(static_cast(vars[5])->tokenname() == "float@a"); + ASSERT_TRUE(vars[6]->isType()); + ASSERT_TRUE(static_cast(vars[6])->tokenname() == "float@e"); + ASSERT_TRUE(vars[7]->isType()); + ASSERT_TRUE(vars[7]->name() == "f1"); + ASSERT_TRUE(vars[8]->isType()); + ASSERT_TRUE(vars[8]->name() == "f2"); + ASSERT_TRUE(vars[9]->isType()); + ASSERT_TRUE(vars[9]->name() == "f3"); + ASSERT_TRUE(vars[10]->isType()); + ASSERT_TRUE(static_cast(vars[10])->tokenname() == "float@f"); // @d should depend on: @d, a, @e vars.clear(); variableDependencies(*lastd, vars); - CPPUNIT_ASSERT_EQUAL(3ul, vars.size()); - CPPUNIT_ASSERT(vars[0]->isType()); - CPPUNIT_ASSERT(static_cast(vars[0])->tokenname() == "float@d"); - CPPUNIT_ASSERT(vars[1]->isType()); - CPPUNIT_ASSERT(vars[1]->name() == "a"); - CPPUNIT_ASSERT(vars[2]->isType()); - CPPUNIT_ASSERT(static_cast(vars[2])->tokenname() == "float@e"); + ASSERT_EQ(3ul, vars.size()); + ASSERT_TRUE(vars[0]->isType()); + ASSERT_TRUE(static_cast(vars[0])->tokenname() == "float@d"); + ASSERT_TRUE(vars[1]->isType()); + ASSERT_TRUE(vars[1]->name() == "a"); + ASSERT_TRUE(vars[2]->isType()); + ASSERT_TRUE(static_cast(vars[2])->tokenname() == "float@e"); // @e should depend on itself vars.clear(); variableDependencies(*laste, vars); - CPPUNIT_ASSERT_EQUAL(1ul, vars.size()); - CPPUNIT_ASSERT(vars[0]->isType()); - CPPUNIT_ASSERT(static_cast(vars[0])->tokenname() == "float@e"); + ASSERT_EQ(1ul, vars.size()); + ASSERT_TRUE(vars[0]->isType()); + ASSERT_TRUE(static_cast(vars[0])->tokenname() == "float@e"); // @f should depend on nothing vars.clear(); variableDependencies(*lastf, vars); - CPPUNIT_ASSERT(vars.empty()); + ASSERT_TRUE(vars.empty()); // @v should depend on: m, v@v vars.clear(); variableDependencies(*lastv, vars); - CPPUNIT_ASSERT_EQUAL(2ul, vars.size()); - CPPUNIT_ASSERT(vars[0]->isType()); - CPPUNIT_ASSERT(vars[0]->name() == "m"); - CPPUNIT_ASSERT(vars[1]->isType()); - CPPUNIT_ASSERT(static_cast(vars[1])->tokenname() == "vec3f@v"); + ASSERT_EQ(2ul, vars.size()); + ASSERT_TRUE(vars[0]->isType()); + ASSERT_TRUE(vars[0]->name() == "m"); + ASSERT_TRUE(vars[1]->isType()); + ASSERT_TRUE(static_cast(vars[1])->tokenname() == "vec3f@v"); } */ From 8c8fbda8b4e64f3f3ed2319061bb0351ef7b60b5 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 15:15:37 -0700 Subject: [PATCH 04/21] Convert TestAttributeBindings.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../test/backend/TestAttributeBindings.cc | 146 +++++++----------- 1 file changed, 60 insertions(+), 86 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestAttributeBindings.cc b/openvdb_ax/openvdb_ax/test/backend/TestAttributeBindings.cc index e0adf0a1ce..0e56719736 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestAttributeBindings.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestAttributeBindings.cc @@ -5,133 +5,107 @@ #include -#include +#include -class TestAttributeBindings : public CppUnit::TestCase +class TestAttributeBindings : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestAttributeBindings); - CPPUNIT_TEST(testSet); - CPPUNIT_TEST(testSetFromVector); - CPPUNIT_TEST(testSetFromInitList); - CPPUNIT_TEST(testSetToExistingAXName); - CPPUNIT_TEST(testSetToExistingDataName); - CPPUNIT_TEST(testSwapNames); - CPPUNIT_TEST_SUITE_END(); - - void testSet(); - void testSetFromVector(); - void testSetFromInitList(); - void testSetToExistingAXName(); - void testSetToExistingDataName(); - void testSwapNames(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestAttributeBindings); - - -void -TestAttributeBindings::testSet() +TEST_F(TestAttributeBindings, testSet) { openvdb::ax::AttributeBindings bindings; - CPPUNIT_ASSERT(!bindings.isBoundAXName("a")); - CPPUNIT_ASSERT(!bindings.isBoundDataName("b")); + ASSERT_TRUE(!bindings.isBoundAXName("a")); + ASSERT_TRUE(!bindings.isBoundDataName("b")); bindings.set("a", "b"); - CPPUNIT_ASSERT(bindings.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings.isBoundAXName("a")); + ASSERT_TRUE(bindings.isBoundDataName("b")); + ASSERT_EQ(*bindings.dataNameBoundTo("a"), std::string("b")); + ASSERT_EQ(*bindings.axNameBoundTo("b"), std::string("a")); } -void -TestAttributeBindings::testSetFromVector() +TEST_F(TestAttributeBindings, testSetFromVector) { std::vector> vec = {{"a", "b"}}; openvdb::ax::AttributeBindings bindings0(vec); - CPPUNIT_ASSERT(bindings0.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings0.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings0.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings0.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings0.isBoundAXName("a")); + ASSERT_TRUE(bindings0.isBoundDataName("b")); + ASSERT_EQ(*bindings0.dataNameBoundTo("a"), std::string("b")); + ASSERT_EQ(*bindings0.axNameBoundTo("b"), std::string("a")); } -void -TestAttributeBindings::testSetFromInitList() +TEST_F(TestAttributeBindings, testSetFromInitList) { openvdb::ax::AttributeBindings bindings0 = {{"a", "b"}}; - CPPUNIT_ASSERT(bindings0.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings0.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings0.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings0.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings0.isBoundAXName("a")); + ASSERT_TRUE(bindings0.isBoundDataName("b")); + ASSERT_EQ(*bindings0.dataNameBoundTo("a"), std::string("b")); + ASSERT_EQ(*bindings0.axNameBoundTo("b"), std::string("a")); // initializer list ctor openvdb::ax::AttributeBindings bindings1({{"a","b"}}); - CPPUNIT_ASSERT(bindings1.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings1.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings1.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings1.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings1.isBoundAXName("a")); + ASSERT_TRUE(bindings1.isBoundDataName("b")); + ASSERT_EQ(*bindings1.dataNameBoundTo("a"), std::string("b")); + ASSERT_EQ(*bindings1.axNameBoundTo("b"), std::string("a")); } -void -TestAttributeBindings::testSetToExistingAXName() +TEST_F(TestAttributeBindings, testSetToExistingAXName) { openvdb::ax::AttributeBindings bindings; bindings.set("a", "b"); - CPPUNIT_ASSERT(bindings.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings.isBoundAXName("a")); + ASSERT_TRUE(bindings.isBoundDataName("b")); + ASSERT_EQ(*bindings.dataNameBoundTo("a"), std::string("b")); + ASSERT_EQ(*bindings.axNameBoundTo("b"), std::string("a")); bindings.set("a", "c"); - CPPUNIT_ASSERT(bindings.isBoundAXName("a")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("a"), std::string("c")); - CPPUNIT_ASSERT(!bindings.isBoundDataName("b")); - CPPUNIT_ASSERT(!bindings.axNameBoundTo("b")); // i.e. is nullptr - CPPUNIT_ASSERT(bindings.isBoundDataName("c")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("c"), std::string("a")); + ASSERT_TRUE(bindings.isBoundAXName("a")); + ASSERT_EQ(*bindings.dataNameBoundTo("a"), std::string("c")); + ASSERT_TRUE(!bindings.isBoundDataName("b")); + ASSERT_TRUE(!bindings.axNameBoundTo("b")); // i.e. is nullptr + ASSERT_TRUE(bindings.isBoundDataName("c")); + ASSERT_EQ(*bindings.axNameBoundTo("c"), std::string("a")); } -void -TestAttributeBindings::testSetToExistingDataName() +TEST_F(TestAttributeBindings, testSetToExistingDataName) { openvdb::ax::AttributeBindings bindings; bindings.set("a", "b"); - CPPUNIT_ASSERT(bindings.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings.isBoundAXName("a")); + ASSERT_TRUE(bindings.isBoundDataName("b")); + ASSERT_EQ(*bindings.dataNameBoundTo("a"), std::string("b")); + ASSERT_EQ(*bindings.axNameBoundTo("b"), std::string("a")); bindings.set("c", "b"); - CPPUNIT_ASSERT(bindings.isBoundAXName("c")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("c"), std::string("b")); + ASSERT_TRUE(bindings.isBoundAXName("c")); + ASSERT_EQ(*bindings.dataNameBoundTo("c"), std::string("b")); - CPPUNIT_ASSERT(!bindings.isBoundAXName("a")); - CPPUNIT_ASSERT(!bindings.dataNameBoundTo("a")); // i.e. is nullptr + ASSERT_TRUE(!bindings.isBoundAXName("a")); + ASSERT_TRUE(!bindings.dataNameBoundTo("a")); // i.e. is nullptr - CPPUNIT_ASSERT(bindings.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("b"), std::string("c")); + ASSERT_TRUE(bindings.isBoundDataName("b")); + ASSERT_EQ(*bindings.axNameBoundTo("b"), std::string("c")); } -void -TestAttributeBindings::testSwapNames() +TEST_F(TestAttributeBindings, testSwapNames) { openvdb::ax::AttributeBindings bindings; bindings.set("a", "a"); - CPPUNIT_ASSERT(bindings.isBoundAXName("a")); - CPPUNIT_ASSERT(bindings.isBoundDataName("a")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("a"), std::string("a")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("a"), std::string("a")); + ASSERT_TRUE(bindings.isBoundAXName("a")); + ASSERT_TRUE(bindings.isBoundDataName("a")); + ASSERT_EQ(*bindings.dataNameBoundTo("a"), std::string("a")); + ASSERT_EQ(*bindings.axNameBoundTo("a"), std::string("a")); bindings.set("b", "b"); - CPPUNIT_ASSERT(bindings.isBoundAXName("b")); - CPPUNIT_ASSERT(bindings.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("b"), std::string("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("b"), std::string("b")); + ASSERT_TRUE(bindings.isBoundAXName("b")); + ASSERT_TRUE(bindings.isBoundDataName("b")); + ASSERT_EQ(*bindings.dataNameBoundTo("b"), std::string("b")); + ASSERT_EQ(*bindings.axNameBoundTo("b"), std::string("b")); bindings.set("a", "b"); - CPPUNIT_ASSERT(bindings.isBoundAXName("a")); - CPPUNIT_ASSERT_EQUAL(*bindings.dataNameBoundTo("a"), std::string("b")); - CPPUNIT_ASSERT(bindings.isBoundDataName("b")); - CPPUNIT_ASSERT_EQUAL(*bindings.axNameBoundTo("b"), std::string("a")); + ASSERT_TRUE(bindings.isBoundAXName("a")); + ASSERT_EQ(*bindings.dataNameBoundTo("a"), std::string("b")); + ASSERT_TRUE(bindings.isBoundDataName("b")); + ASSERT_EQ(*bindings.axNameBoundTo("b"), std::string("a")); - CPPUNIT_ASSERT(!bindings.isBoundDataName("a")); - CPPUNIT_ASSERT(!bindings.axNameBoundTo("a")); + ASSERT_TRUE(!bindings.isBoundDataName("a")); + ASSERT_TRUE(!bindings.axNameBoundTo("a")); } From 3194d389f4e40ebe010163d413a093045a4cd0d4 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 15:37:19 -0700 Subject: [PATCH 05/21] Convert TestCodecs.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/backend/TestCodecs.cc | 192 +++++++++--------- 1 file changed, 98 insertions(+), 94 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestCodecs.cc b/openvdb_ax/openvdb_ax/test/backend/TestCodecs.cc index 6ee11452ad..14fc63f14e 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestCodecs.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestCodecs.cc @@ -9,7 +9,7 @@ #include // for native codec types -#include +#include #include @@ -24,26 +24,10 @@ struct UFxpt16 { static const bool OneByte = false; using type = FixedPointCode struct PRFxpt8 { static const bool OneByte = true; using type = FixedPointCodec; }; struct PRFxpt16 { static const bool OneByte = false; using type = FixedPointCodec; }; -class TestCodecs : public CppUnit::TestCase +class TestCodecs : public ::testing::Test { -public: - CPPUNIT_TEST_SUITE(TestCodecs); - CPPUNIT_TEST(testRegisteredCodecs); - CPPUNIT_TEST(testTruncateCodec); - CPPUNIT_TEST(testFxptCodec); - CPPUNIT_TEST(testFxptCodec); - CPPUNIT_TEST(testFxptCodec); - CPPUNIT_TEST(testFxptCodec); - CPPUNIT_TEST_SUITE_END(); - - void testRegisteredCodecs(); - void testTruncateCodec(); - template - void testFxptCodec(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestCodecs); - inline const Codec* getCodecByCodecName(const std::string& name) { @@ -59,7 +43,7 @@ getCodecByCodecName(const std::string& name) return nullptr; } -void TestCodecs::testRegisteredCodecs() +TEST_F(TestCodecs, testRegisteredCodecs) { // For each codec, verify the way its been setup. Really this should be // enforced as part of the API but the majority of the setup code is internal. @@ -88,7 +72,7 @@ void TestCodecs::testRegisteredCodecs() #endif // currently only 5 codecs are registered by default - CPPUNIT_ASSERT_EQUAL(codecs.size(), count); + ASSERT_EQ(codecs.size(), count); // for each codec, check: // make sure the codecs flags are unique @@ -96,7 +80,7 @@ void TestCodecs::testRegisteredCodecs() std::set flags; for (const Codec* codec : codecs) { - CPPUNIT_ASSERT(!flags.count(codec->flag())); + ASSERT_TRUE(!flags.count(codec->flag())); flags.insert(codec->flag()); } @@ -105,42 +89,42 @@ void TestCodecs::testRegisteredCodecs() for (const Codec* codec : codecs) { const codegen::FunctionGroup* encoder = codec->encoder(); const codegen::FunctionGroup* decoder = codec->decoder(); - CPPUNIT_ASSERT(encoder); - CPPUNIT_ASSERT(decoder); - CPPUNIT_ASSERT(!encoder->list().empty()); - CPPUNIT_ASSERT(!decoder->list().empty()); + ASSERT_TRUE(encoder); + ASSERT_TRUE(decoder); + ASSERT_TRUE(!encoder->list().empty()); + ASSERT_TRUE(!decoder->list().empty()); std::set> decoderSignatures, encoderSignatures; for (const auto& F : decoder->list()) { // check the function takes 2 arguments (in/out) // @note This could change in the future e.g. a value is returned - CPPUNIT_ASSERT_EQUAL(F->size(), size_t(2)); // input/output + ASSERT_EQ(F->size(), size_t(2)); // input/output std::vector types; llvm::Type* ret = F->types(types, C); // currently expect codecs to ret void - CPPUNIT_ASSERT_EQUAL(ret, codegen::LLVMType::get(C)); + ASSERT_EQ(ret, codegen::LLVMType::get(C)); // signature should be unqiue - CPPUNIT_ASSERT(!decoderSignatures.count(types)); + ASSERT_TRUE(!decoderSignatures.count(types)); decoderSignatures.insert(types); } for (const auto& F : encoder->list()) { // check the function takes 2 arguments (in/out) // @note This could change in the future e.g. a value is returned - CPPUNIT_ASSERT_EQUAL(F->size(), size_t(2)); // input/output + ASSERT_EQ(F->size(), size_t(2)); // input/output std::vector types; llvm::Type* ret = F->types(types, C); // currently expect codecs to ret void - CPPUNIT_ASSERT_EQUAL(ret, codegen::LLVMType::get(C)); + ASSERT_EQ(ret, codegen::LLVMType::get(C)); // signature should be unqiue - CPPUNIT_ASSERT(!encoderSignatures.count(types)); + ASSERT_TRUE(!encoderSignatures.count(types)); encoderSignatures.insert(types); } - CPPUNIT_ASSERT(!encoderSignatures.empty()); - CPPUNIT_ASSERT(!decoderSignatures.empty()); - CPPUNIT_ASSERT_EQUAL(decoderSignatures.size(), encoderSignatures.size()); + ASSERT_TRUE(!encoderSignatures.empty()); + ASSERT_TRUE(!decoderSignatures.empty()); + ASSERT_EQ(decoderSignatures.size(), encoderSignatures.size()); // check signatures have unique input/output types // @note This is necessary so that the IR knows what type to expect for a given input @@ -154,8 +138,8 @@ void TestCodecs::testRegisteredCodecs() const llvm::Type* second = types[1]; copy.pop_back(); for (const auto& remaining : copy) { - CPPUNIT_ASSERT(first != remaining[0]); - CPPUNIT_ASSERT(second != remaining[1]); + ASSERT_TRUE(first != remaining[0]); + ASSERT_TRUE(second != remaining[1]); } } @@ -171,8 +155,8 @@ void TestCodecs::testRegisteredCodecs() const llvm::Type* second = types[1]; copy.pop_back(); for (const auto& remaining : copy) { - CPPUNIT_ASSERT(first != remaining[0]); - CPPUNIT_ASSERT(second != remaining[1]); + ASSERT_TRUE(first != remaining[0]); + ASSERT_TRUE(second != remaining[1]); } } @@ -181,12 +165,12 @@ void TestCodecs::testRegisteredCodecs() for (const auto& types : decoderSignatures) { std::vector rev = types; std::reverse(rev.begin(), rev.end()); - CPPUNIT_ASSERT(encoderSignatures.find(rev) != encoderSignatures.end()); + ASSERT_TRUE(encoderSignatures.find(rev) != encoderSignatures.end()); } } } -void TestCodecs::testTruncateCodec() +TEST_F(TestCodecs, testTruncateCodec) { #if defined(__i386__) || defined(_M_IX86) || \ defined(__x86_64__) || defined(_M_X64) @@ -199,32 +183,32 @@ void TestCodecs::testTruncateCodec() const Codec* const codec = getCodecByCodecName(TruncateCodec::name()); - CPPUNIT_ASSERT(codec); + ASSERT_TRUE(codec); llvm::Type* floatty = codegen::LLVMType::get(C); llvm::Type* vfloatty = codegen::LLVMType>::get(C); llvm::Type* halfty = codegen::LLVMType::get(C); llvm::Type* vhalfty = codegen::LLVMType>::get(C); - CPPUNIT_ASSERT_EQUAL(halfty, codec->decodedToEncoded(ast::tokens::CoreType::FLOAT, C)); - CPPUNIT_ASSERT_EQUAL(vhalfty, codec->decodedToEncoded(ast::tokens::CoreType::VEC3F, C)); - CPPUNIT_ASSERT_EQUAL(floatty, codec->encodedToDecoded(halfty)); - CPPUNIT_ASSERT_EQUAL(vfloatty, codec->encodedToDecoded(vhalfty)); + ASSERT_EQ(halfty, codec->decodedToEncoded(ast::tokens::CoreType::FLOAT, C)); + ASSERT_EQ(vhalfty, codec->decodedToEncoded(ast::tokens::CoreType::VEC3F, C)); + ASSERT_EQ(floatty, codec->encodedToDecoded(halfty)); + ASSERT_EQ(vfloatty, codec->encodedToDecoded(vhalfty)); // JIT the codec and test the IR const codegen::FunctionGroup* encoder = codec->encoder(); const codegen::FunctionGroup* decoder = codec->decoder(); - CPPUNIT_ASSERT(encoder); - CPPUNIT_ASSERT(decoder); - CPPUNIT_ASSERT(!encoder->list().empty()); - CPPUNIT_ASSERT(!decoder->list().empty()); + ASSERT_TRUE(encoder); + ASSERT_TRUE(decoder); + ASSERT_TRUE(!encoder->list().empty()); + ASSERT_TRUE(!decoder->list().empty()); - for (auto& F : encoder->list()) CPPUNIT_ASSERT(F->create(M)); - for (auto& F : decoder->list()) CPPUNIT_ASSERT(F->create(M)); + for (auto& F : encoder->list()) ASSERT_TRUE(F->create(M)); + for (auto& F : decoder->list()) ASSERT_TRUE(F->create(M)); auto EE = state.EE(); - CPPUNIT_ASSERT(EE); + ASSERT_TRUE(EE); // test truncate encoders @@ -247,7 +231,7 @@ void TestCodecs::testTruncateCodec() { const int64_t address = EE->getFunctionAddress(encoder->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto truncEncodeFloatToHalf = reinterpret_cast::type>(address); HalfTy result1, result2; @@ -256,15 +240,15 @@ void TestCodecs::testTruncateCodec() { const float tmp = input; truncEncodeFloatToHalf(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change TruncateCodec::encode(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } { const int64_t address = EE->getFunctionAddress(encoder->list()[5]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto truncEncodeVecFloatToHalf = reinterpret_cast::type>(address); math::Vec3 result1, result2; @@ -273,9 +257,9 @@ void TestCodecs::testTruncateCodec() { const math::Vec3 tmp(input); truncEncodeVecFloatToHalf(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change TruncateCodec::encode, math::Vec3>(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } @@ -300,7 +284,7 @@ void TestCodecs::testTruncateCodec() { const int64_t address = EE->getFunctionAddress(decoder->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto truncDecodeHalfToFloat = reinterpret_cast::type>(address); float result1, result2; @@ -309,15 +293,15 @@ void TestCodecs::testTruncateCodec() { const HalfTy tmp = input; truncDecodeHalfToFloat(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change TruncateCodec::encode(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } { const int64_t address = EE->getFunctionAddress(decoder->list()[5]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto truncDecodeVecHalfToFloat = reinterpret_cast::type>(address); math::Vec3 result1, result2; @@ -326,15 +310,15 @@ void TestCodecs::testTruncateCodec() { const math::Vec3 tmp(input); truncDecodeVecHalfToFloat(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change TruncateCodec::encode, math::Vec3>(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } } template -void TestCodecs::testFxptCodec() +void testFxptCodec() { static const bool OneByte = FxptCodecT::OneByte; using IntT = typename std::conditional::type; @@ -345,37 +329,37 @@ void TestCodecs::testFxptCodec() llvm::Module& M = state.module(); const Codec* const codec = getCodecByCodecName(FixedPointCodecType::name()); - CPPUNIT_ASSERT(codec); + ASSERT_TRUE(codec); llvm::Type* uintty = OneByte ? codegen::LLVMType::get(C) : codegen::LLVMType::get(C); llvm::Type* vuintty = OneByte ? codegen::LLVMType>::get(C) : codegen::LLVMType>::get(C); llvm::Type* floatty = codegen::LLVMType::get(C); llvm::Type* vfloatty = codegen::LLVMType>::get(C); - CPPUNIT_ASSERT(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::INT32, C)); - CPPUNIT_ASSERT(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::VEC2F, C)); - CPPUNIT_ASSERT(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::STRING, C)); - CPPUNIT_ASSERT_EQUAL(uintty, codec->decodedToEncoded(ast::tokens::CoreType::FLOAT, C)); - CPPUNIT_ASSERT_EQUAL(vuintty, codec->decodedToEncoded(ast::tokens::CoreType::VEC3F, C)); - CPPUNIT_ASSERT_EQUAL(floatty, codec->encodedToDecoded(uintty)); - CPPUNIT_ASSERT_EQUAL(vfloatty, codec->encodedToDecoded(vuintty)); + ASSERT_TRUE(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::INT32, C)); + ASSERT_TRUE(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::VEC2F, C)); + ASSERT_TRUE(nullptr == codec->decodedToEncoded(ast::tokens::CoreType::STRING, C)); + ASSERT_EQ(uintty, codec->decodedToEncoded(ast::tokens::CoreType::FLOAT, C)); + ASSERT_EQ(vuintty, codec->decodedToEncoded(ast::tokens::CoreType::VEC3F, C)); + ASSERT_EQ(floatty, codec->encodedToDecoded(uintty)); + ASSERT_EQ(vfloatty, codec->encodedToDecoded(vuintty)); // JIT the codec and test the IR const codegen::FunctionGroup* encoder = codec->encoder(); const codegen::FunctionGroup* decoder = codec->decoder(); - CPPUNIT_ASSERT(encoder); - CPPUNIT_ASSERT(decoder); - CPPUNIT_ASSERT(!encoder->list().empty()); - CPPUNIT_ASSERT(!decoder->list().empty()); - CPPUNIT_ASSERT_EQUAL(encoder->list().size(), size_t(2)); - CPPUNIT_ASSERT_EQUAL(decoder->list().size(), size_t(2)); + ASSERT_TRUE(encoder); + ASSERT_TRUE(decoder); + ASSERT_TRUE(!encoder->list().empty()); + ASSERT_TRUE(!decoder->list().empty()); + ASSERT_EQ(encoder->list().size(), size_t(2)); + ASSERT_EQ(decoder->list().size(), size_t(2)); - for (auto& F : encoder->list()) CPPUNIT_ASSERT(F->create(M)); - for (auto& F : decoder->list()) CPPUNIT_ASSERT(F->create(M)); + for (auto& F : encoder->list()) ASSERT_TRUE(F->create(M)); + for (auto& F : decoder->list()) ASSERT_TRUE(F->create(M)); auto EE = state.EE(); - CPPUNIT_ASSERT(EE); + ASSERT_TRUE(EE); // test truncate encoders @@ -400,7 +384,7 @@ void TestCodecs::testFxptCodec() { const int64_t address = EE->getFunctionAddress(encoder->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto fxptEncodeFloat = reinterpret_cast(address); IntT result1, result2; @@ -409,15 +393,15 @@ void TestCodecs::testFxptCodec() { const float tmp = input; fxptEncodeFloat(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change FixedPointCodecType::template encode(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } { const int64_t address = EE->getFunctionAddress(encoder->list()[1]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto fxptEncodeVFloat = reinterpret_cast(address); math::Vec3 result1, result2; @@ -426,9 +410,9 @@ void TestCodecs::testFxptCodec() { const math::Vec3 tmp(input); fxptEncodeVFloat(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change FixedPointCodecType::template encode, math::Vec3>(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } @@ -457,7 +441,7 @@ void TestCodecs::testFxptCodec() { const int64_t address = EE->getFunctionAddress(decoder->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto fxptDecodeUint8 = reinterpret_cast(address); float result1, result2; @@ -466,15 +450,15 @@ void TestCodecs::testFxptCodec() { const IntT tmp = input; fxptDecodeUint8(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change FixedPointCodecType::template decode(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } { const int64_t address = EE->getFunctionAddress(decoder->list()[1]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); const auto fxptDecodeVuint8 = reinterpret_cast(address); math::Vec3 result1, result2; @@ -483,9 +467,29 @@ void TestCodecs::testFxptCodec() { const math::Vec3 tmp(input); fxptDecodeVuint8(&result1, &input); - CPPUNIT_ASSERT_EQUAL(input, tmp); // doesn't change + ASSERT_EQ(input, tmp); // doesn't change FixedPointCodecType::template decode, math::Vec3>(input, result2); - CPPUNIT_ASSERT_EQUAL(result2, result1); + ASSERT_EQ(result2, result1); } } } + +TEST_F(TestCodecs, testFxptCodecUFxpt8) +{ + testFxptCodec(); +} + +TEST_F(TestCodecs, testFxptCodecUFxpt16) +{ + testFxptCodec(); +} + +TEST_F(TestCodecs, testFxptCodecPRFxpt8) +{ + testFxptCodec(); +} + +TEST_F(TestCodecs, testFxptCodecPRFxpt16) +{ + testFxptCodec(); +} From ce3ffd475d3675ac76eb6ef5ce7f0d3771d19afa Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 15:43:04 -0700 Subject: [PATCH 06/21] Convert TestComputeGeneratorFailures.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../backend/TestComputeGeneratorFailures.cc | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestComputeGeneratorFailures.cc b/openvdb_ax/openvdb_ax/test/backend/TestComputeGeneratorFailures.cc index 55a01d066d..bcca7df077 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestComputeGeneratorFailures.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestComputeGeneratorFailures.cc @@ -11,7 +11,7 @@ #include #include -#include +#include static const std::vector tests { // codegen errors @@ -333,22 +333,11 @@ static const std::vector tests { "vec2i v; 1, v++;" }; -class TestComputeGeneratorFailures : public CppUnit::TestCase +class TestComputeGeneratorFailures : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestComputeGeneratorFailures); - CPPUNIT_TEST(testFailures); - CPPUNIT_TEST_SUITE_END(); - - void testFailures(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestComputeGeneratorFailures); - - -void -TestComputeGeneratorFailures::testFailures() +TEST_F(TestComputeGeneratorFailures, testFailures) { openvdb::ax::FunctionOptions opts; openvdb::ax::codegen::FunctionRegistry::UniquePtr reg = @@ -361,14 +350,14 @@ TestComputeGeneratorFailures::testFailures() for (const auto& code : tests) { const openvdb::ax::ast::Tree::ConstPtr ast = openvdb::ax::ast::parse(code.c_str(), logger); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Unable to parse", code), ast.get()); - CPPUNIT_ASSERT(!logger.hasError()); + ASSERT_TRUE(ast.get()) << ERROR_MSG("Unable to parse", code); + ASSERT_TRUE(!logger.hasError()); unittest_util::LLVMState state; openvdb::ax::codegen::codegen_internal::ComputeGenerator gen(state.module(), opts, *reg, logger); gen.generate(*ast); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Expected Compiler Error", code), logger.hasError()); + ASSERT_TRUE(logger.hasError()) << ERROR_MSG("Expected Compiler Error", code); logger.clear(); } } From 3a6781dea418cf6d5f3e2d3a482f77d7a0cd888c Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 15:48:53 -0700 Subject: [PATCH 07/21] Convert TestFunctionGroup.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../test/backend/TestFunctionGroup.cc | 277 ++++++++---------- 1 file changed, 130 insertions(+), 147 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestFunctionGroup.cc b/openvdb_ax/openvdb_ax/test/backend/TestFunctionGroup.cc index d76bc7f552..d8ba2743aa 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestFunctionGroup.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestFunctionGroup.cc @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -111,26 +111,11 @@ axtestmulti(llvm::LLVMContext& C) /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -class TestFunctionGroup : public CppUnit::TestCase +class TestFunctionGroup : public ::testing::Test { -public: - - // Test FunctionGroup signature matching and execution errors - CPPUNIT_TEST_SUITE(TestFunctionGroup); - CPPUNIT_TEST(testFunctionGroup); - CPPUNIT_TEST(testMatch); - CPPUNIT_TEST(testExecute); - CPPUNIT_TEST_SUITE_END(); - - void testFunctionGroup(); - void testMatch(); - void testExecute(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestFunctionGroup); - -void -TestFunctionGroup::testFunctionGroup() +TEST_F(TestFunctionGroup, testFunctionGroup) { using openvdb::ax::codegen::Function; using openvdb::ax::codegen::FunctionGroup; @@ -149,16 +134,15 @@ TestFunctionGroup::testFunctionGroup() decl1, decl2, decl3 })); - CPPUNIT_ASSERT_EQUAL(std::string("test"), std::string(group->name())); - CPPUNIT_ASSERT_EQUAL(std::string("The documentation"), std::string(group->doc())); - CPPUNIT_ASSERT_EQUAL(size_t(3), group->list().size()); - CPPUNIT_ASSERT_EQUAL(decl1, group->list()[0]); - CPPUNIT_ASSERT_EQUAL(decl2, group->list()[1]); - CPPUNIT_ASSERT_EQUAL(decl3, group->list()[2]); + ASSERT_EQ(std::string("test"), std::string(group->name())); + ASSERT_EQ(std::string("The documentation"), std::string(group->doc())); + ASSERT_EQ(size_t(3), group->list().size()); + ASSERT_EQ(decl1, group->list()[0]); + ASSERT_EQ(decl2, group->list()[1]); + ASSERT_EQ(decl3, group->list()[2]); } -void -TestFunctionGroup::testMatch() +TEST_F(TestFunctionGroup, testMatch) { using openvdb::ax::codegen::LLVMType; using openvdb::ax::codegen::Function; @@ -180,49 +164,49 @@ TestFunctionGroup::testMatch() types.resize(1); types[0] = llvm::Type::getInt1Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[5].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[5].get()), result); // types[0] = llvm::Type::getInt16Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[4].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[4].get()), result); // types[0] = llvm::Type::getInt32Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[3].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[3].get()), result); // types[0] = llvm::Type::getInt64Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[2].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[2].get()), result); // types[0] = llvm::Type::getFloatTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[1].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[1].get()), result); // types[0] = llvm::Type::getDoubleTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[0].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[0].get()), result); // test unsigned integers automatic type creation - these are not supported in the // language however can be constructed from the API. The function framework does @@ -230,18 +214,18 @@ TestFunctionGroup::testMatch() types[0] = LLVMType::get(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[2].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[2].get()), result); // test implicit matching - types should match to the first available castable signature // which is always the void(double) "tsfd" function for all provided scalars types[0] = llvm::Type::getInt8Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Implicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[0].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Implicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[0].get()), result); types.clear(); @@ -249,33 +233,33 @@ TestFunctionGroup::testMatch() // the size result = group->match(types, C, &match); - CPPUNIT_ASSERT_EQUAL(Function::SignatureMatch::None, match); - CPPUNIT_ASSERT(!result); + ASSERT_EQ(Function::SignatureMatch::None, match); + ASSERT_TRUE(!result); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::None == match); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(Function::SignatureMatch::None == match); + ASSERT_TRUE(!result); // types.emplace_back(llvm::Type::getInt1Ty(C)->getPointerTo()); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Size == match); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(Function::SignatureMatch::Size == match); + ASSERT_TRUE(!result); // types[0] = llvm::ArrayType::get(llvm::Type::getInt1Ty(C), 1); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Size == match); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(Function::SignatureMatch::Size == match); + ASSERT_TRUE(!result); // types[0] = llvm::Type::getInt1Ty(C); types.emplace_back(llvm::Type::getInt1Ty(C)); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::None == match); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(Function::SignatureMatch::None == match); + ASSERT_TRUE(!result); // // Test varying argument size function @@ -288,26 +272,26 @@ TestFunctionGroup::testMatch() types[0] = llvm::Type::getDoubleTy(C); types[1] = llvm::Type::getDoubleTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[2].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[2].get()), result); // types.resize(1); types[0] = llvm::Type::getDoubleTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[1].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[1].get()), result); // types.clear(); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[0].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[0].get()), result); // Test implicit matching @@ -316,9 +300,9 @@ TestFunctionGroup::testMatch() types[0] = llvm::Type::getFloatTy(C); types[1] = llvm::Type::getInt32Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Implicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[2].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Implicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[2].get()), result); // Test non matching @@ -328,8 +312,8 @@ TestFunctionGroup::testMatch() types[1] = llvm::Type::getDoubleTy(C); types[2] = llvm::Type::getDoubleTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::None == match); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(Function::SignatureMatch::None == match); + ASSERT_TRUE(!result); // // Test multi function @@ -342,9 +326,9 @@ TestFunctionGroup::testMatch() types.clear(); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[0].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[0].get()), result); // @@ -352,27 +336,27 @@ TestFunctionGroup::testMatch() types[0] = llvm::Type::getDoubleTy(C); types[1] = llvm::Type::getDoubleTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[2].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[2].get()), result); // types[0] = llvm::Type::getInt32Ty(C); types[1] = llvm::Type::getDoubleTy(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[3].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[3].get()), result); // types[0] = llvm::Type::getInt32Ty(C); types[1] = llvm::Type::getInt32Ty(C); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Implicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[2].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Implicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[2].get()), result); // @@ -380,21 +364,20 @@ TestFunctionGroup::testMatch() types[0] = llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 1)->getPointerTo(); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[5].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[5].get()), result); // types[0] = llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)->getPointerTo(); result = group->match(types, C, &match); - CPPUNIT_ASSERT(Function::SignatureMatch::Explicit == match); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_EQUAL(const_cast((*list)[6].get()), result); + ASSERT_TRUE(Function::SignatureMatch::Explicit == match); + ASSERT_TRUE(result); + ASSERT_EQ(const_cast((*list)[6].get()), result); } -void -TestFunctionGroup::testExecute() +TEST_F(TestFunctionGroup, testExecute) { using openvdb::ax::codegen::LLVMType; using openvdb::ax::codegen::Function; @@ -412,13 +395,13 @@ TestFunctionGroup::testExecute() // test invalid arguments throws FunctionGroup::Ptr group(new FunctionGroup("empty", "", {})); - CPPUNIT_ASSERT(!group->execute(/*args*/{}, B, result)); + ASSERT_TRUE(!group->execute(/*args*/{}, B, result)); group = axtestscalar(C); const std::vector* list = &group->list(); - CPPUNIT_ASSERT(!group->execute({}, B, result)); - CPPUNIT_ASSERT(!group->execute({ + ASSERT_TRUE(!group->execute({}, B, result)); + ASSERT_TRUE(!group->execute({ B.getTrue(), B.getTrue() }, B, result)); @@ -432,78 +415,78 @@ TestFunctionGroup::testExecute() args[0] = B.getTrue(); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[5]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[5]->create(state.module()), target); // args[0] = B.getInt16(1); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[4]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[4]->create(state.module()), target); // args[0] = B.getInt32(1); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[3]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[3]->create(state.module()), target); // args[0] = B.getInt64(1); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[2]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[2]->create(state.module()), target); // args[0] = llvm::ConstantFP::get(llvm::Type::getFloatTy(C), 1.0f); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[1]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[1]->create(state.module()), target); // args[0] = llvm::ConstantFP::get(llvm::Type::getDoubleTy(C), 1.0); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[0]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[0]->create(state.module()), target); // // Test multi function @@ -514,13 +497,13 @@ TestFunctionGroup::testExecute() args.clear(); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[0]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[0]->create(state.module()), target); // @@ -528,26 +511,26 @@ TestFunctionGroup::testExecute() args[0] = B.CreateAlloca(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 1)); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[5]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[5]->create(state.module()), target); // args[0] = B.CreateAlloca(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[6]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[6]->create(state.module()), target); // @@ -556,12 +539,12 @@ TestFunctionGroup::testExecute() args[1] = llvm::ConstantFP::get(llvm::Type::getDoubleTy(C), 1.0); result = group->execute(args, B); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(llvm::isa(result)); + ASSERT_TRUE(result); + ASSERT_TRUE(llvm::isa(result)); call = llvm::cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); target = call->getCalledFunction(); - CPPUNIT_ASSERT(target); - CPPUNIT_ASSERT_EQUAL((*list)[2]->create(state.module()), target); + ASSERT_TRUE(target); + ASSERT_EQ((*list)[2]->create(state.module()), target); } From c0e66ce8056636115e7a6bd1bd5efaf1030a49b7 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 15:54:29 -0700 Subject: [PATCH 08/21] Convert TestFunctionRegistry.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../test/backend/TestFunctionRegistry.cc | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestFunctionRegistry.cc b/openvdb_ax/openvdb_ax/test/backend/TestFunctionRegistry.cc index 3c1f64bcdd..fbf39a1a4c 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestFunctionRegistry.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestFunctionRegistry.cc @@ -8,23 +8,14 @@ #include #include #include -#include -class TestFunctionRegistry : public CppUnit::TestCase -{ -public: - - CPPUNIT_TEST_SUITE(TestFunctionRegistry); - CPPUNIT_TEST(testCreateAllVerify); - CPPUNIT_TEST_SUITE_END(); +#include - void testCreateAllVerify(); +class TestFunctionRegistry : public ::testing::Test +{ }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestFunctionRegistry); - -void -TestFunctionRegistry::testCreateAllVerify() +TEST_F(TestFunctionRegistry, testCreateAllVerify) { openvdb::ax::codegen::FunctionRegistry::UniquePtr reg = openvdb::ax::codegen::createDefaultRegistry(); @@ -41,7 +32,7 @@ TestFunctionRegistry::testCreateAllVerify() std::cerr.rdbuf(buffer.rdbuf()); reg->createAll(opts, true); const std::string& result = buffer.str(); - CPPUNIT_ASSERT_MESSAGE(result, result.empty()); + ASSERT_TRUE(result.empty()) << result; } catch (...) { std::cerr.rdbuf(sbuf); From 323dc5c0d05924ad5bc58d7e9744da867bad2de1 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Thu, 3 Oct 2024 17:48:06 -0700 Subject: [PATCH 09/21] Convert TestFunctionTypes.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../test/backend/TestFunctionTypes.cc | 1527 +++++++++-------- 1 file changed, 766 insertions(+), 761 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestFunctionTypes.cc b/openvdb_ax/openvdb_ax/test/backend/TestFunctionTypes.cc index 2b155af4be..88789ff22e 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestFunctionTypes.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestFunctionTypes.cc @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -93,20 +93,20 @@ finalizeFunction(llvm::IRBuilder<>& B, llvm::Function* F = nullptr) #define VERIFY_FUNCTION_IR(Function) { \ std::string error; llvm::raw_string_ostream os(error); \ const bool valid = !llvm::verifyFunction(*Function, &os); \ - CPPUNIT_ASSERT_MESSAGE(os.str(), valid); \ + ASSERT_TRUE(valid) << os.str(); \ } #define VERIFY_MODULE_IR(Module) { \ std::string error; llvm::raw_string_ostream os(error); \ const bool valid = !llvm::verifyModule(*Module, &os); \ - CPPUNIT_ASSERT_MESSAGE(os.str(), valid); \ + ASSERT_TRUE(valid) << os.str(); \ } #define VERIFY_MODULE_IR_INVALID(Module) { \ const bool valid = llvm::verifyModule(*Module); \ - CPPUNIT_ASSERT_MESSAGE("Expected IR to be invalid!", valid); \ + ASSERT_TRUE(valid) << "Expected IR to be invalid!"; \ } #define VERIFY_FUNCTION_IR_INVALID(Function) { \ const bool valid = llvm::verifyFunction(*Function); \ - CPPUNIT_ASSERT_MESSAGE("Expected IR to be invalid!", valid); \ + ASSERT_TRUE(valid) << "Expected IR to be invalid!"; \ } inline auto getNumArgFromCallInst(llvm::CallInst* CI) @@ -122,46 +122,11 @@ inline auto getNumArgFromCallInst(llvm::CallInst* CI) /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -class TestFunctionTypes : public CppUnit::TestCase +class TestFunctionTypes : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestFunctionTypes); - CPPUNIT_TEST(testLLVMTypesFromSignature); - CPPUNIT_TEST(testLLVMFunctionTypeFromSignature); - CPPUNIT_TEST(testPrintSignature); - // Test Function::create, Function::types and other base methods - CPPUNIT_TEST(testFunctionCreate); - // Test Function::call - CPPUNIT_TEST(testFunctionCall); - // Test Function::match - CPPUNIT_TEST(testFunctionMatch); - // Test derived CFunctions, mainly CFunction::create and CFunction::types - CPPUNIT_TEST(testCFunctions); - // Test C constant folding - CPPUNIT_TEST(testCFunctionCF); - // Test derived IR Function, IRFunctionBase::create and IRFunctionBase::call - CPPUNIT_TEST(testIRFunctions); - // Test SRET methods for both C and IR functions - CPPUNIT_TEST(testSRETFunctions); - CPPUNIT_TEST_SUITE_END(); - - void testLLVMTypesFromSignature(); - void testLLVMFunctionTypeFromSignature(); - void testPrintSignature(); - void testFunctionCreate(); - void testFunctionCall(); - void testFunctionMatch(); - void testCFunctions(); - void testCFunctionCF(); - void testIRFunctions(); - void testSRETFunctions(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestFunctionTypes); - -void -TestFunctionTypes::testLLVMTypesFromSignature() +TEST_F(TestFunctionTypes, testLLVMTypesFromSignature) { using openvdb::ax::codegen::llvmTypesFromSignature; @@ -170,38 +135,37 @@ TestFunctionTypes::testLLVMTypesFromSignature() std::vector types; type = llvmTypesFromSignature(state.context()); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isVoidTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isVoidTy()); type = llvmTypesFromSignature(state.context(), &types); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isVoidTy()); - CPPUNIT_ASSERT(types.empty()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isVoidTy()); + ASSERT_TRUE(types.empty()); type = llvmTypesFromSignature(state.context(), &types); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isFloatTy()); - CPPUNIT_ASSERT(types.empty()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isFloatTy()); + ASSERT_TRUE(types.empty()); type = llvmTypesFromSignature(state.context(), &types); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isFloatTy()); - CPPUNIT_ASSERT_EQUAL(size_t(3), types.size()); - CPPUNIT_ASSERT(types[0]->isDoubleTy()); - CPPUNIT_ASSERT(types[1]->isIntegerTy(64)); - CPPUNIT_ASSERT(types[2]->isPointerTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isFloatTy()); + ASSERT_EQ(size_t(3), types.size()); + ASSERT_TRUE(types[0]->isDoubleTy()); + ASSERT_TRUE(types[1]->isIntegerTy(64)); + ASSERT_TRUE(types[2]->isPointerTy()); type = types[2]->getPointerElementType(); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isArrayTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isArrayTy()); type = type->getArrayElementType(); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isFloatTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isFloatTy()); } -void -TestFunctionTypes::testLLVMFunctionTypeFromSignature() +TEST_F(TestFunctionTypes, testLLVMFunctionTypeFromSignature) { using openvdb::ax::codegen::llvmFunctionTypeFromSignature; @@ -210,30 +174,29 @@ TestFunctionTypes::testLLVMFunctionTypeFromSignature() std::vector types; ftype = llvmFunctionTypeFromSignature(state.context()); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(0u, ftype->getNumParams()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(0u, ftype->getNumParams()); ftype = llvmFunctionTypeFromSignature(state.context()); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isFloatTy()); - CPPUNIT_ASSERT_EQUAL(3u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0)->isDoubleTy()); - CPPUNIT_ASSERT(ftype->getParamType(1)->isIntegerTy(64)); - CPPUNIT_ASSERT(ftype->getParamType(2)->isPointerTy()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isFloatTy()); + ASSERT_EQ(3u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0)->isDoubleTy()); + ASSERT_TRUE(ftype->getParamType(1)->isIntegerTy(64)); + ASSERT_TRUE(ftype->getParamType(2)->isPointerTy()); llvm::Type* type = ftype->getParamType(2)->getPointerElementType(); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isArrayTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isArrayTy()); type = type->getArrayElementType(); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isFloatTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isFloatTy()); } -void -TestFunctionTypes::testPrintSignature() +TEST_F(TestFunctionTypes, testPrintSignature) { using openvdb::ax::codegen::printSignature; @@ -245,55 +208,55 @@ TestFunctionTypes::testPrintSignature() std::ostringstream os; printSignature(os, types, vt); - CPPUNIT_ASSERT(os.str() == "void()"); + ASSERT_TRUE(os.str() == "void()"); os.str(""); types.emplace_back(llvm::Type::getInt32Ty(C)); types.emplace_back(llvm::Type::getInt64Ty(C)); printSignature(os, types, vt); - CPPUNIT_ASSERT_EQUAL(std::string("void(i32; i64)"), os.str()); + ASSERT_EQ(std::string("void(i32; i64)"), os.str()); os.str(""); printSignature(os, types, vt, "test"); - CPPUNIT_ASSERT_EQUAL(std::string("void test(i32; i64)"), os.str()); + ASSERT_EQ(std::string("void test(i32; i64)"), os.str()); os.str(""); printSignature(os, types, vt, "", {"one"}, true); - CPPUNIT_ASSERT_EQUAL(std::string("void(int32 one; int64)"), os.str()); + ASSERT_EQ(std::string("void(int32 one; int64)"), os.str()); os.str(""); printSignature(os, types, vt, "", {"one", "two"}, true); - CPPUNIT_ASSERT_EQUAL(std::string("void(int32 one; int64 two)"), os.str()); + ASSERT_EQ(std::string("void(int32 one; int64 two)"), os.str()); os.str(""); printSignature(os, types, vt, "1", {"one", "two", "three"}, true); - CPPUNIT_ASSERT_EQUAL(std::string("void 1(int32 one; int64 two)"), os.str()); + ASSERT_EQ(std::string("void 1(int32 one; int64 two)"), os.str()); os.str(""); printSignature(os, types, vt, "1", {"", "two"}, false); - CPPUNIT_ASSERT_EQUAL(std::string("void 1(i32; i64 two)"), os.str()); + ASSERT_EQ(std::string("void 1(i32; i64 two)"), os.str()); os.str(""); printSignature(os, types, vt, "1", {"", "two"}, false); - CPPUNIT_ASSERT_EQUAL(std::string("void 1(i32; i64 two)"), os.str()); + ASSERT_EQ(std::string("void 1(i32; i64 two)"), os.str()); os.str(""); types.emplace_back(llvm::Type::getInt8PtrTy(C)); types.emplace_back(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)); printSignature(os, types, llvm::Type::getInt64Ty(C), "test", {"", "two"}, true); - CPPUNIT_ASSERT_EQUAL(std::string("int64 test(int32; int64 two; i8*; vec3i)"), os.str()); + ASSERT_EQ(std::string("int64 test(int32; int64 two; i8*; vec3i)"), os.str()); os.str(""); types.clear(); printSignature(os, types, llvm::Type::getInt64Ty(C), "test", {"", "two"}); - CPPUNIT_ASSERT_EQUAL(std::string("i64 test()"), os.str()); + ASSERT_EQ(std::string("i64 test()"), os.str()); os.str(""); } -void -TestFunctionTypes::testFunctionCreate() +// Test Function::create, Function::types and other base methods +TEST_F(TestFunctionTypes, testFunctionCreate) { using openvdb::ax::codegen::Function; @@ -309,58 +272,58 @@ TestFunctionTypes::testFunctionCreate() // test types type = test->types(types, C); - CPPUNIT_ASSERT_EQUAL(size_t(1), types.size()); - CPPUNIT_ASSERT(types[0]->isIntegerTy(32)); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isVoidTy()); + ASSERT_EQ(size_t(1), types.size()); + ASSERT_TRUE(types[0]->isIntegerTy(32)); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isVoidTy()); // test various getters - CPPUNIT_ASSERT_EQUAL(std::string("ax.test"), std::string(test->symbol())); - CPPUNIT_ASSERT_EQUAL(size_t(1), test->size()); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(0))); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(1))); + ASSERT_EQ(std::string("ax.test"), std::string(test->symbol())); + ASSERT_EQ(size_t(1), test->size()); + ASSERT_EQ(std::string(""), std::string(test->argName(0))); + ASSERT_EQ(std::string(""), std::string(test->argName(1))); // test create detached llvm::Function* function = test->create(C); llvm::Function* function2 = test->create(C); // additional create call should create a new function - CPPUNIT_ASSERT(function != function2); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(1), function->arg_size()); + ASSERT_TRUE(function != function2); + ASSERT_TRUE(function); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(1), function->arg_size()); llvm::FunctionType* ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(1u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0)->isIntegerTy(32)); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(1u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0)->isIntegerTy(32)); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; delete function2; // test create with a module (same as above, but check inserted into M) - CPPUNIT_ASSERT(!M.getFunction("ax.test")); + ASSERT_TRUE(!M.getFunction("ax.test")); function = test->create(M); // additional call should match - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.test")); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.test")); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(1), function->arg_size()); + ASSERT_EQ(function, test->create(M)); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.test")); + ASSERT_EQ(function, M.getFunction("ax.test")); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(1), function->arg_size()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(1u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0)->isIntegerTy(32)); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(1u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0)->isIntegerTy(32)); + ASSERT_TRUE(function->getAttributes().isEmpty()); // test print os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("void name(int32)"), os.str()); + ASSERT_EQ(std::string("void name(int32)"), os.str()); // // Test empty signature @@ -370,40 +333,40 @@ TestFunctionTypes::testFunctionCreate() // test types type = test->types(types, C); - CPPUNIT_ASSERT_EQUAL(size_t(0), types.size()); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isIntegerTy(32)); + ASSERT_EQ(size_t(0), types.size()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isIntegerTy(32)); // test various getters - CPPUNIT_ASSERT_EQUAL(std::string("ax.empty.test"), std::string(test->symbol())); - CPPUNIT_ASSERT_EQUAL(size_t(0), test->size()); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(0))); + ASSERT_EQ(std::string("ax.empty.test"), std::string(test->symbol())); + ASSERT_EQ(size_t(0), test->size()); + ASSERT_EQ(std::string(""), std::string(test->argName(0))); // test create detached function = test->create(C); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(0), function->arg_size()); + ASSERT_TRUE(function); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(0), function->arg_size()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isIntegerTy(32)); - CPPUNIT_ASSERT_EQUAL(0u, ftype->getNumParams()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isIntegerTy(32)); + ASSERT_EQ(0u, ftype->getNumParams()); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; // test create with a module (same as above, but check inserted into M) - CPPUNIT_ASSERT(!M.getFunction("ax.empty.test")); + ASSERT_TRUE(!M.getFunction("ax.empty.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.empty.test")); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.empty.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.empty.test")); + ASSERT_EQ(function, M.getFunction("ax.empty.test")); + ASSERT_EQ(function, test->create(M)); // test print os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("int32 name()"), os.str()); + ASSERT_EQ(std::string("int32 name()"), os.str()); // // Test scalar types @@ -419,51 +382,51 @@ TestFunctionTypes::testFunctionCreate() llvm::Type::getInt16Ty(C), "ax.scalars.test")); types.clear(); - CPPUNIT_ASSERT_EQUAL(std::string("ax.scalars.test"), std::string(test->symbol())); + ASSERT_EQ(std::string("ax.scalars.test"), std::string(test->symbol())); type = test->types(types, state.context()); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isIntegerTy(16)); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0]->isIntegerTy(1)); - CPPUNIT_ASSERT(types[1]->isIntegerTy(16)); - CPPUNIT_ASSERT(types[2]->isIntegerTy(32)); - CPPUNIT_ASSERT(types[3]->isIntegerTy(64)); - CPPUNIT_ASSERT(types[4]->isFloatTy()); - CPPUNIT_ASSERT(types[5]->isDoubleTy()); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isIntegerTy(16)); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0]->isIntegerTy(1)); + ASSERT_TRUE(types[1]->isIntegerTy(16)); + ASSERT_TRUE(types[2]->isIntegerTy(32)); + ASSERT_TRUE(types[3]->isIntegerTy(64)); + ASSERT_TRUE(types[4]->isFloatTy()); + ASSERT_TRUE(types[5]->isDoubleTy()); // test create detached function = test->create(C); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(6), function->arg_size()); + ASSERT_TRUE(function); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(6), function->arg_size()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isIntegerTy(16)); - CPPUNIT_ASSERT_EQUAL(6u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0)->isIntegerTy(1)); - CPPUNIT_ASSERT(ftype->getParamType(1)->isIntegerTy(16)); - CPPUNIT_ASSERT(ftype->getParamType(2)->isIntegerTy(32)); - CPPUNIT_ASSERT(ftype->getParamType(3)->isIntegerTy(64)); - CPPUNIT_ASSERT(ftype->getParamType(4)->isFloatTy()); - CPPUNIT_ASSERT(ftype->getParamType(5)->isDoubleTy()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isIntegerTy(16)); + ASSERT_EQ(6u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0)->isIntegerTy(1)); + ASSERT_TRUE(ftype->getParamType(1)->isIntegerTy(16)); + ASSERT_TRUE(ftype->getParamType(2)->isIntegerTy(32)); + ASSERT_TRUE(ftype->getParamType(3)->isIntegerTy(64)); + ASSERT_TRUE(ftype->getParamType(4)->isFloatTy()); + ASSERT_TRUE(ftype->getParamType(5)->isDoubleTy()); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; // test create with a module (same as above, but check inserted into M) - CPPUNIT_ASSERT(!M.getFunction("ax.scalars.test")); + ASSERT_TRUE(!M.getFunction("ax.scalars.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.scalars.test")); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.scalars.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.scalars.test")); + ASSERT_EQ(function, M.getFunction("ax.scalars.test")); + ASSERT_EQ(function, test->create(M)); // test print os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("int16 name(bool; int16; int32; int64; float; double)"), os.str()); + ASSERT_EQ(std::string("int16 name(bool; int16; int32; int64; float; double)"), os.str()); // // Test scalar ptrs types @@ -479,45 +442,45 @@ TestFunctionTypes::testFunctionCreate() llvm::Type::getInt32Ty(C), "ax.scalarptrs.test")); types.clear(); - CPPUNIT_ASSERT_EQUAL(std::string("ax.scalarptrs.test"), std::string(test->symbol())); + ASSERT_EQ(std::string("ax.scalarptrs.test"), std::string(test->symbol())); type = test->types(types, C); - CPPUNIT_ASSERT(type->isIntegerTy(32)); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::Type::getInt1Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[1] == llvm::Type::getInt16Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::Type::getInt32Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::Type::getInt64Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::Type::getDoubleTy(C)->getPointerTo()); + ASSERT_TRUE(type->isIntegerTy(32)); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0] == llvm::Type::getInt1Ty(C)->getPointerTo()); + ASSERT_TRUE(types[1] == llvm::Type::getInt16Ty(C)->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::Type::getInt32Ty(C)->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::Type::getInt64Ty(C)->getPointerTo()); + ASSERT_TRUE(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::Type::getDoubleTy(C)->getPointerTo()); // test create detached function = test->create(C); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(6), function->arg_size()); + ASSERT_TRUE(function); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(6), function->arg_size()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isIntegerTy(32)); - CPPUNIT_ASSERT_EQUAL(6u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0) == llvm::Type::getInt1Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(1) == llvm::Type::getInt16Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(2) == llvm::Type::getInt32Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(3) == llvm::Type::getInt64Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(4) == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(5) == llvm::Type::getDoubleTy(C)->getPointerTo()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isIntegerTy(32)); + ASSERT_EQ(6u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0) == llvm::Type::getInt1Ty(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(1) == llvm::Type::getInt16Ty(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(2) == llvm::Type::getInt32Ty(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(3) == llvm::Type::getInt64Ty(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(4) == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(5) == llvm::Type::getDoubleTy(C)->getPointerTo()); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; // test create with a module (same as above, but check inserted into M) - CPPUNIT_ASSERT(!M.getFunction("ax.scalarptrs.test")); + ASSERT_TRUE(!M.getFunction("ax.scalarptrs.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.scalarptrs.test")); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.scalarptrs.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.scalarptrs.test")); + ASSERT_EQ(function, M.getFunction("ax.scalarptrs.test")); + ASSERT_EQ(function, test->create(M)); // // Test array ptrs types @@ -543,65 +506,65 @@ TestFunctionTypes::testFunctionCreate() types.clear(); type = test->types(types, C); - CPPUNIT_ASSERT(type->isIntegerTy(64)); - CPPUNIT_ASSERT_EQUAL(size_t(15), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(types[1] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(types[4] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(types[6] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(types[7] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(types[8] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(types[9] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 9)->getPointerTo()); - CPPUNIT_ASSERT(types[10] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 9)->getPointerTo()); - CPPUNIT_ASSERT(types[11] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 9)->getPointerTo()); - CPPUNIT_ASSERT(types[12] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 16)->getPointerTo()); - CPPUNIT_ASSERT(types[13] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 16)->getPointerTo()); - CPPUNIT_ASSERT(types[14] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 16)->getPointerTo()); + ASSERT_TRUE(type->isIntegerTy(64)); + ASSERT_EQ(size_t(15), types.size()); + ASSERT_TRUE(types[0] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)->getPointerTo()); + ASSERT_TRUE(types[1] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 2)->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)->getPointerTo()); + ASSERT_TRUE(types[4] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3)->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 3)->getPointerTo()); + ASSERT_TRUE(types[6] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)->getPointerTo()); + ASSERT_TRUE(types[7] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 4)->getPointerTo()); + ASSERT_TRUE(types[8] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 4)->getPointerTo()); + ASSERT_TRUE(types[9] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 9)->getPointerTo()); + ASSERT_TRUE(types[10] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 9)->getPointerTo()); + ASSERT_TRUE(types[11] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 9)->getPointerTo()); + ASSERT_TRUE(types[12] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 16)->getPointerTo()); + ASSERT_TRUE(types[13] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 16)->getPointerTo()); + ASSERT_TRUE(types[14] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 16)->getPointerTo()); // test create detached function = test->create(C); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(15), function->arg_size()); + ASSERT_TRUE(function); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(15), function->arg_size()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isIntegerTy(64)); - CPPUNIT_ASSERT_EQUAL(15u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(1) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(2) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(3) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(4) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(5) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(6) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(7) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(8) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(9) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 9)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(10) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 9)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(11) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 9)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(12) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 16)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(13) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 16)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(14) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 16)->getPointerTo()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isIntegerTy(64)); + ASSERT_EQ(15u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(1) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 2)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(2) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(3) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(4) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(5) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 3)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(6) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(7) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 4)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(8) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 4)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(9) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 9)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(10) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 9)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(11) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 9)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(12) == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 16)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(13) == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 16)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(14) == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 16)->getPointerTo()); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; // test create with a module (same as above, but check inserted into M) - CPPUNIT_ASSERT(!M.getFunction("ax.arrayptrs.test")); + ASSERT_TRUE(!M.getFunction("ax.arrayptrs.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.arrayptrs.test")); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.arrayptrs.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.arrayptrs.test")); + ASSERT_EQ(function, M.getFunction("ax.arrayptrs.test")); + ASSERT_EQ(function, test->create(M)); // test print - note mat/i types are not ax types os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("int64 name(vec2i; vec2f; vec2d; vec3i; vec3f; vec3d;" + ASSERT_EQ(std::string("int64 name(vec2i; vec2f; vec2d; vec3i; vec3f; vec3d;" " vec4i; vec4f; vec4d; [9 x i32]*; mat3f; mat3d; [16 x i32]*; mat4f; mat4d)"), os.str()); @@ -623,87 +586,87 @@ TestFunctionTypes::testFunctionCreate() // unmodified in this example where we use the derived TestFunction type = test->types(types, C); - CPPUNIT_ASSERT(type->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::Type::getVoidTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[1] == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); + ASSERT_TRUE(type->isVoidTy()); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0] == llvm::Type::getVoidTy(C)->getPointerTo()); + ASSERT_TRUE(types[1] == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); // test create detached function = test->create(C); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(6), function->arg_size()); + ASSERT_TRUE(function); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(6), function->arg_size()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(6u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0) == llvm::Type::getVoidTy(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(1) == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(2) == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(3) == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(4) == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(5) == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(6u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0) == llvm::Type::getVoidTy(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(1) == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(2) == llvm::Type::getVoidTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(3) == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(4) == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(5) == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; // test create with a module (same as above, but check inserted into M) - CPPUNIT_ASSERT(!M.getFunction("ax.vptrs.test")); + ASSERT_TRUE(!M.getFunction("ax.vptrs.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.vptrs.test")); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.vptrs.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.vptrs.test")); + ASSERT_EQ(function, M.getFunction("ax.vptrs.test")); + ASSERT_EQ(function, test->create(M)); // // Test creation with builder methods // @note These methods may be moved to the constructor in the future - CPPUNIT_ASSERT(test->dependencies().empty()); - CPPUNIT_ASSERT(!test->hasParamAttribute(0, llvm::Attribute::ReadOnly)); - CPPUNIT_ASSERT(!test->hasParamAttribute(-1, llvm::Attribute::ReadOnly)); + ASSERT_TRUE(test->dependencies().empty()); + ASSERT_TRUE(!test->hasParamAttribute(0, llvm::Attribute::ReadOnly)); + ASSERT_TRUE(!test->hasParamAttribute(-1, llvm::Attribute::ReadOnly)); test->setDependencies({"dep"}); - CPPUNIT_ASSERT_EQUAL(size_t(1), test->dependencies().size()); - CPPUNIT_ASSERT_EQUAL(std::string("dep"), std::string(test->dependencies().front())); + ASSERT_EQ(size_t(1), test->dependencies().size()); + ASSERT_EQ(std::string("dep"), std::string(test->dependencies().front())); test->setDependencies({}); - CPPUNIT_ASSERT(test->dependencies().empty()); + ASSERT_TRUE(test->dependencies().empty()); test->setFnAttributes({llvm::Attribute::ReadOnly}); test->setRetAttributes({llvm::Attribute::NoAlias}); test->setParamAttributes(1, {llvm::Attribute::WriteOnly}); test->setParamAttributes(-1, {llvm::Attribute::WriteOnly}); - CPPUNIT_ASSERT(!test->hasParamAttribute(0, llvm::Attribute::WriteOnly)); - CPPUNIT_ASSERT(!test->hasParamAttribute(2, llvm::Attribute::WriteOnly)); - CPPUNIT_ASSERT(test->hasParamAttribute(1, llvm::Attribute::WriteOnly)); - CPPUNIT_ASSERT(test->hasParamAttribute(-1, llvm::Attribute::WriteOnly)); + ASSERT_TRUE(!test->hasParamAttribute(0, llvm::Attribute::WriteOnly)); + ASSERT_TRUE(!test->hasParamAttribute(2, llvm::Attribute::WriteOnly)); + ASSERT_TRUE(test->hasParamAttribute(1, llvm::Attribute::WriteOnly)); + ASSERT_TRUE(test->hasParamAttribute(-1, llvm::Attribute::WriteOnly)); function = test->create(C); - CPPUNIT_ASSERT(function); + ASSERT_TRUE(function); llvm::AttributeList list = function->getAttributes(); - CPPUNIT_ASSERT(!list.isEmpty()); - CPPUNIT_ASSERT(!list.hasParamAttrs(0)); - CPPUNIT_ASSERT(!list.hasParamAttrs(2)); - CPPUNIT_ASSERT(list.hasParamAttr(1, llvm::Attribute::WriteOnly)); + ASSERT_TRUE(!list.isEmpty()); + ASSERT_TRUE(!list.hasParamAttrs(0)); + ASSERT_TRUE(!list.hasParamAttrs(2)); + ASSERT_TRUE(list.hasParamAttr(1, llvm::Attribute::WriteOnly)); #if LLVM_VERSION_MAJOR <= 13 - CPPUNIT_ASSERT(list.hasFnAttribute(llvm::Attribute::ReadOnly)); - CPPUNIT_ASSERT(list.hasAttribute(llvm::AttributeList::ReturnIndex, llvm::Attribute::NoAlias)); + ASSERT_TRUE(list.hasFnAttribute(llvm::Attribute::ReadOnly)); + ASSERT_TRUE(list.hasAttribute(llvm::AttributeList::ReturnIndex, llvm::Attribute::NoAlias)); #else - CPPUNIT_ASSERT(list.hasFnAttr(llvm::Attribute::ReadOnly)); - CPPUNIT_ASSERT(list.hasRetAttr(llvm::Attribute::NoAlias)); + ASSERT_TRUE(list.hasFnAttr(llvm::Attribute::ReadOnly)); + ASSERT_TRUE(list.hasRetAttr(llvm::Attribute::NoAlias)); #endif delete function; } -void -TestFunctionTypes::testFunctionCall() +// Test Function::call +TEST_F(TestFunctionTypes, testFunctionCall) { using openvdb::ax::codegen::Function; using openvdb::ax::codegen::LLVMType; @@ -723,14 +686,14 @@ TestFunctionTypes::testFunctionCall() llvm::Function* function = test->create(M); llvm::Value* arg = B.getInt32(1); llvm::Value* result = test->call({arg}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); llvm::CallInst* call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(arg, call->getArgOperand(0)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); + ASSERT_EQ(arg, call->getArgOperand(0)); // Test the builder is pointing to the correct location - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); // add a ret void to the current function and to the created function, // then check the IR is valid (this will check the function arguments @@ -757,14 +720,14 @@ TestFunctionTypes::testFunctionCall() llvm::Value* arg = B.getInt32(1); llvm::Value* result = test->call({arg}, B, /*cast*/false); llvm::Function* function = test->create(M); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); llvm::CallInst* call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(arg, call->getArgOperand(0)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); + ASSERT_EQ(arg, call->getArgOperand(0)); // Test the builder is pointing to the correct location - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); // add a ret void to the current function and to the created function, // then check the IR is valid (this will check the function arguments @@ -826,33 +789,33 @@ TestFunctionTypes::testFunctionCall() // test no casting needed for valid IR llvm::Value* result = test->call(args, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); llvm::CallInst* call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(6u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(args[0], call->getArgOperand(0)); - CPPUNIT_ASSERT_EQUAL(args[1], call->getArgOperand(1)); - CPPUNIT_ASSERT_EQUAL(args[2], call->getArgOperand(2)); - CPPUNIT_ASSERT_EQUAL(args[3], call->getArgOperand(3)); - CPPUNIT_ASSERT_EQUAL(args[4], call->getArgOperand(4)); - CPPUNIT_ASSERT_EQUAL(args[5], call->getArgOperand(5)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(6u, getNumArgFromCallInst(call)); + ASSERT_EQ(args[0], call->getArgOperand(0)); + ASSERT_EQ(args[1], call->getArgOperand(1)); + ASSERT_EQ(args[2], call->getArgOperand(2)); + ASSERT_EQ(args[3], call->getArgOperand(3)); + ASSERT_EQ(args[4], call->getArgOperand(4)); + ASSERT_EQ(args[5], call->getArgOperand(5)); VERIFY_MODULE_IR(&M); // test no casting needed for valid IR, even with cast=true result = test->call(args, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(6u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(args[0], call->getArgOperand(0)); - CPPUNIT_ASSERT_EQUAL(args[1], call->getArgOperand(1)); - CPPUNIT_ASSERT_EQUAL(args[2], call->getArgOperand(2)); - CPPUNIT_ASSERT_EQUAL(args[3], call->getArgOperand(3)); - CPPUNIT_ASSERT_EQUAL(args[4], call->getArgOperand(4)); - CPPUNIT_ASSERT_EQUAL(args[5], call->getArgOperand(5)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(6u, getNumArgFromCallInst(call)); + ASSERT_EQ(args[0], call->getArgOperand(0)); + ASSERT_EQ(args[1], call->getArgOperand(1)); + ASSERT_EQ(args[2], call->getArgOperand(2)); + ASSERT_EQ(args[3], call->getArgOperand(3)); + ASSERT_EQ(args[4], call->getArgOperand(4)); + ASSERT_EQ(args[5], call->getArgOperand(5)); VERIFY_MODULE_IR(&M); // @@ -879,23 +842,23 @@ TestFunctionTypes::testFunctionCall() argsToCast.emplace_back(i1c0); // bool result = test->call(argsToCast, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(6u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(argsToCast[0] != call->getArgOperand(0)); - CPPUNIT_ASSERT(argsToCast[1] != call->getArgOperand(1)); - CPPUNIT_ASSERT(argsToCast[2] != call->getArgOperand(2)); - CPPUNIT_ASSERT(argsToCast[3] != call->getArgOperand(3)); - CPPUNIT_ASSERT(argsToCast[4] != call->getArgOperand(4)); - CPPUNIT_ASSERT(argsToCast[5] != call->getArgOperand(5)); - CPPUNIT_ASSERT(expected[0] == call->getArgOperand(0)->getType()); - CPPUNIT_ASSERT(expected[1] == call->getArgOperand(1)->getType()); - CPPUNIT_ASSERT(expected[2] == call->getArgOperand(2)->getType()); - CPPUNIT_ASSERT(expected[3] == call->getArgOperand(3)->getType()); - CPPUNIT_ASSERT(expected[4] == call->getArgOperand(4)->getType()); - CPPUNIT_ASSERT(expected[5] == call->getArgOperand(5)->getType()); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(6u, getNumArgFromCallInst(call)); + ASSERT_TRUE(argsToCast[0] != call->getArgOperand(0)); + ASSERT_TRUE(argsToCast[1] != call->getArgOperand(1)); + ASSERT_TRUE(argsToCast[2] != call->getArgOperand(2)); + ASSERT_TRUE(argsToCast[3] != call->getArgOperand(3)); + ASSERT_TRUE(argsToCast[4] != call->getArgOperand(4)); + ASSERT_TRUE(argsToCast[5] != call->getArgOperand(5)); + ASSERT_TRUE(expected[0] == call->getArgOperand(0)->getType()); + ASSERT_TRUE(expected[1] == call->getArgOperand(1)->getType()); + ASSERT_TRUE(expected[2] == call->getArgOperand(2)->getType()); + ASSERT_TRUE(expected[3] == call->getArgOperand(3)->getType()); + ASSERT_TRUE(expected[4] == call->getArgOperand(4)->getType()); + ASSERT_TRUE(expected[5] == call->getArgOperand(5)->getType()); VERIFY_MODULE_IR(&M); // @@ -909,21 +872,21 @@ TestFunctionTypes::testFunctionCall() argsToCast.emplace_back(f32c0); // float - no cast required result = test->call(argsToCast, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(6u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(argsToCast[0] != call->getArgOperand(0)); - CPPUNIT_ASSERT(argsToCast[1] != call->getArgOperand(1)); - CPPUNIT_ASSERT_EQUAL(args[2], call->getArgOperand(2)); - CPPUNIT_ASSERT(argsToCast[3] != call->getArgOperand(3)); - CPPUNIT_ASSERT(argsToCast[4] != call->getArgOperand(4)); - CPPUNIT_ASSERT_EQUAL(args[5], call->getArgOperand(5)); - CPPUNIT_ASSERT(expected[0] == call->getArgOperand(0)->getType()); - CPPUNIT_ASSERT(expected[1] == call->getArgOperand(1)->getType()); - CPPUNIT_ASSERT(expected[3] == call->getArgOperand(3)->getType()); - CPPUNIT_ASSERT(expected[4] == call->getArgOperand(4)->getType()); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(6u, getNumArgFromCallInst(call)); + ASSERT_TRUE(argsToCast[0] != call->getArgOperand(0)); + ASSERT_TRUE(argsToCast[1] != call->getArgOperand(1)); + ASSERT_EQ(args[2], call->getArgOperand(2)); + ASSERT_TRUE(argsToCast[3] != call->getArgOperand(3)); + ASSERT_TRUE(argsToCast[4] != call->getArgOperand(4)); + ASSERT_EQ(args[5], call->getArgOperand(5)); + ASSERT_TRUE(expected[0] == call->getArgOperand(0)->getType()); + ASSERT_TRUE(expected[1] == call->getArgOperand(1)->getType()); + ASSERT_TRUE(expected[3] == call->getArgOperand(3)->getType()); + ASSERT_TRUE(expected[4] == call->getArgOperand(4)->getType()); VERIFY_MODULE_IR(&M); // @@ -937,19 +900,19 @@ TestFunctionTypes::testFunctionCall() argsToCast.emplace_back(i64c1); // int64 result = test->call(argsToCast, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(6u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(args[0], call->getArgOperand(0)); - CPPUNIT_ASSERT_EQUAL(args[1], call->getArgOperand(1)); - CPPUNIT_ASSERT_EQUAL(args[2], call->getArgOperand(2)); - CPPUNIT_ASSERT(argsToCast[3] != call->getArgOperand(3)); - CPPUNIT_ASSERT_EQUAL(args[4], call->getArgOperand(4)); - CPPUNIT_ASSERT(argsToCast[5] != call->getArgOperand(5)); - CPPUNIT_ASSERT(expected[3] == call->getArgOperand(3)->getType()); - CPPUNIT_ASSERT(expected[5] == call->getArgOperand(5)->getType()); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(6u, getNumArgFromCallInst(call)); + ASSERT_EQ(args[0], call->getArgOperand(0)); + ASSERT_EQ(args[1], call->getArgOperand(1)); + ASSERT_EQ(args[2], call->getArgOperand(2)); + ASSERT_TRUE(argsToCast[3] != call->getArgOperand(3)); + ASSERT_EQ(args[4], call->getArgOperand(4)); + ASSERT_TRUE(argsToCast[5] != call->getArgOperand(5)); + ASSERT_TRUE(expected[3] == call->getArgOperand(3)->getType()); + ASSERT_TRUE(expected[5] == call->getArgOperand(5)->getType()); VERIFY_MODULE_IR(&M); // @@ -961,13 +924,13 @@ TestFunctionTypes::testFunctionCall() // unchanged and IR is invalid due to signature size result = test->call({vec3f}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); // should be the same as cast is false - CPPUNIT_ASSERT(vec3f == call->getArgOperand(0)); + ASSERT_TRUE(vec3f == call->getArgOperand(0)); VERIFY_MODULE_IR_INVALID(&M); // Remove the bad instruction (and re-verify to double check) @@ -978,14 +941,14 @@ TestFunctionTypes::testFunctionCall() // due to signature size result = test->call({vec3f}, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); // shouldn't be the same as it should have been cast - CPPUNIT_ASSERT(vec3f != call->getArgOperand(0)); - CPPUNIT_ASSERT(expected[0] == call->getArgOperand(0)->getType()); + ASSERT_TRUE(vec3f != call->getArgOperand(0)); + ASSERT_TRUE(expected[0] == call->getArgOperand(0)->getType()); VERIFY_MODULE_IR_INVALID(&M); // Remove the bad instruction (and re-verify to double check) @@ -996,18 +959,18 @@ TestFunctionTypes::testFunctionCall() // Test IR is invalid due to cast being off result = test->call(argsToCast, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(6u, getNumArgFromCallInst(call)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(6u, getNumArgFromCallInst(call)); // no casting, args should match operands - CPPUNIT_ASSERT(argsToCast[0] == call->getArgOperand(0)); - CPPUNIT_ASSERT(argsToCast[1] == call->getArgOperand(1)); - CPPUNIT_ASSERT(argsToCast[2] == call->getArgOperand(2)); - CPPUNIT_ASSERT(argsToCast[3] == call->getArgOperand(3)); - CPPUNIT_ASSERT(argsToCast[4] == call->getArgOperand(4)); - CPPUNIT_ASSERT(argsToCast[5] == call->getArgOperand(5)); + ASSERT_TRUE(argsToCast[0] == call->getArgOperand(0)); + ASSERT_TRUE(argsToCast[1] == call->getArgOperand(1)); + ASSERT_TRUE(argsToCast[2] == call->getArgOperand(2)); + ASSERT_TRUE(argsToCast[3] == call->getArgOperand(3)); + ASSERT_TRUE(argsToCast[4] == call->getArgOperand(4)); + ASSERT_TRUE(argsToCast[5] == call->getArgOperand(5)); VERIFY_MODULE_IR_INVALID(&M); // Remove the bad instruction (and re-verify to double check) @@ -1038,24 +1001,24 @@ TestFunctionTypes::testFunctionCall() VERIFY_FUNCTION_IR(function); result = test->call(stringArgs, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(stringArgs[0] == call->getArgOperand(0)); - CPPUNIT_ASSERT(stringArgs[1] == call->getArgOperand(1)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(stringArgs[0] == call->getArgOperand(0)); + ASSERT_TRUE(stringArgs[1] == call->getArgOperand(1)); // result = test->call(stringArgs, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(stringArgs[0] == call->getArgOperand(0)); - CPPUNIT_ASSERT(stringArgs[1] == call->getArgOperand(1)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(stringArgs[0] == call->getArgOperand(0)); + ASSERT_TRUE(stringArgs[1] == call->getArgOperand(1)); // Test openvdb::ax::codegen::String -> char* @@ -1063,14 +1026,14 @@ TestFunctionTypes::testFunctionCall() stringArgs[1] = strptr; result = test->call(stringArgs, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(stringArgs[0] == call->getArgOperand(0)); - CPPUNIT_ASSERT(stringArgs[1] != call->getArgOperand(1)); - CPPUNIT_ASSERT(chars == call->getArgOperand(1)->getType()); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(stringArgs[0] == call->getArgOperand(0)); + ASSERT_TRUE(stringArgs[1] != call->getArgOperand(1)); + ASSERT_TRUE(chars == call->getArgOperand(1)->getType()); VERIFY_MODULE_IR(&M); @@ -1080,14 +1043,14 @@ TestFunctionTypes::testFunctionCall() stringArgs[1] = chararray; result = test->call(stringArgs, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); // no valid casting - CPPUNIT_ASSERT(stringArgs[0] == call->getArgOperand(0)); - CPPUNIT_ASSERT(stringArgs[1] == call->getArgOperand(1)); + ASSERT_TRUE(stringArgs[0] == call->getArgOperand(0)); + ASSERT_TRUE(stringArgs[1] == call->getArgOperand(1)); VERIFY_MODULE_IR_INVALID(&M); @@ -1113,40 +1076,40 @@ TestFunctionTypes::testFunctionCall() llvm::Value* dptr = B.CreateAlloca(llvm::Type::getDoubleTy(C)->getPointerTo()); result = test->call({fptr, dptr}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(fptr == call->getArgOperand(0)); - CPPUNIT_ASSERT(dptr == call->getArgOperand(1)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(fptr == call->getArgOperand(0)); + ASSERT_TRUE(dptr == call->getArgOperand(1)); VERIFY_MODULE_IR(&M); // result = test->call({fptr, dptr}, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(fptr == call->getArgOperand(0)); - CPPUNIT_ASSERT(dptr == call->getArgOperand(1)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(fptr == call->getArgOperand(0)); + ASSERT_TRUE(dptr == call->getArgOperand(1)); VERIFY_MODULE_IR(&M); // switch the points, check no valid casting result = test->call({dptr, fptr}, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); // args unaltered as casting is invalid - CPPUNIT_ASSERT(dptr == call->getArgOperand(0)); - CPPUNIT_ASSERT(fptr == call->getArgOperand(1)); + ASSERT_TRUE(dptr == call->getArgOperand(0)); + ASSERT_TRUE(fptr == call->getArgOperand(1)); VERIFY_MODULE_IR_INVALID(&M); @@ -1171,36 +1134,36 @@ TestFunctionTypes::testFunctionCall() llvm::Value* vptr = openvdb::ax::codegen::ir_load(B, vptrptr); result = test->call({vptr}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(vptr == call->getArgOperand(0)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); + ASSERT_TRUE(vptr == call->getArgOperand(0)); VERIFY_MODULE_IR(&M); // result = test->call({vptr}, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(vptr == call->getArgOperand(0)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); + ASSERT_TRUE(vptr == call->getArgOperand(0)); VERIFY_MODULE_IR(&M); // verify no cast from other pointers to void* result = test->call({fptr}, B, /*cast*/true); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(1u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT(fptr == call->getArgOperand(0)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(1u, getNumArgFromCallInst(call)); + ASSERT_TRUE(fptr == call->getArgOperand(0)); VERIFY_MODULE_IR_INVALID(&M); @@ -1209,8 +1172,8 @@ TestFunctionTypes::testFunctionCall() VERIFY_MODULE_IR(&M); } -void -TestFunctionTypes::testFunctionMatch() +// Test Function::match +TEST_F(TestFunctionTypes, testFunctionMatch) { using openvdb::ax::codegen::Function; using openvdb::ax::codegen::LLVMType; @@ -1265,7 +1228,7 @@ TestFunctionTypes::testFunctionMatch() Function::Ptr test(new TestFunction({}, llvm::Type::getVoidTy(C), "ax.test")); match = test->match({}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); // @@ -1279,7 +1242,7 @@ TestFunctionTypes::testFunctionMatch() types.insert(types.end(), LLVMType::get(C)); // check types are unique - CPPUNIT_ASSERT_EQUAL(std::set(types.begin(), types.end()).size(), types.size()); + ASSERT_EQ(std::set(types.begin(), types.end()).size(), types.size()); // @@ -1311,7 +1274,7 @@ TestFunctionTypes::testFunctionMatch() "ax.test")); match = test->match(types, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); // test size match @@ -1319,16 +1282,16 @@ TestFunctionTypes::testFunctionMatch() test.reset(new TestFunction({i32t}, llvm::Type::getVoidTy(C), "ax.test")); match = test->match({llvm::ArrayType::get(i32t, 1)->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Size); + ASSERT_EQ(match, Function::Size); match = test->match({i32t->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Size); + ASSERT_EQ(match, Function::Size); // test no match match = test->match({}, C); - CPPUNIT_ASSERT_EQUAL(Function::None, match); + ASSERT_EQ(Function::None, match); match = test->match({i32t, i32t}, C); - CPPUNIT_ASSERT_EQUAL(Function::None, match); + ASSERT_EQ(Function::None, match); // test scalar matches @@ -1337,13 +1300,13 @@ TestFunctionTypes::testFunctionMatch() std::vector copy(scalars); std::swap(copy[i], copy.back()); copy.pop_back(); - CPPUNIT_ASSERT_EQUAL(size_t(5), copy.size()); - CPPUNIT_ASSERT_EQUAL(Function::Explicit, test->match({scalars[i]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[0]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[1]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[2]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[3]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[4]}, C)); + ASSERT_EQ(size_t(5), copy.size()); + ASSERT_EQ(Function::Explicit, test->match({scalars[i]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[0]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[1]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[2]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[3]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[4]}, C)); } // @@ -1356,16 +1319,16 @@ TestFunctionTypes::testFunctionMatch() std::vector copy(types); std::swap(copy[i], copy.back()); copy.pop_back(); - CPPUNIT_ASSERT_EQUAL(size_t(2), copy.size()); - CPPUNIT_ASSERT_EQUAL(Function::Explicit, test->match({types[i]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Size, test->match({copy[0]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Size, test->match({copy[1]}, C)); + ASSERT_EQ(size_t(2), copy.size()); + ASSERT_EQ(Function::Explicit, test->match({types[i]}, C)); + ASSERT_EQ(Function::Size, test->match({copy[0]}, C)); + ASSERT_EQ(Function::Size, test->match({copy[1]}, C)); // test non matching size arrays for (const std::vector& inputs : arrays) { if (&types == &inputs) continue; for (size_t i = 0; i < inputs.size(); ++i) { - CPPUNIT_ASSERT_EQUAL(Function::Size, test->match({inputs[i]}, C)); + ASSERT_EQ(Function::Size, test->match({inputs[i]}, C)); } } } @@ -1382,16 +1345,16 @@ TestFunctionTypes::testFunctionMatch() std::vector copy(types); std::swap(copy[i], copy.back()); copy.pop_back(); - CPPUNIT_ASSERT_EQUAL(size_t(2), copy.size()); - CPPUNIT_ASSERT_EQUAL(Function::Explicit, test->match({types[i]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[0]}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, test->match({copy[1]}, C)); + ASSERT_EQ(size_t(2), copy.size()); + ASSERT_EQ(Function::Explicit, test->match({types[i]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[0]}, C)); + ASSERT_EQ(Function::Implicit, test->match({copy[1]}, C)); // test non matching size arrays for (const std::vector& inputs : arrays) { if (&types == &inputs) continue; for (size_t i = 0; i < inputs.size(); ++i) { - CPPUNIT_ASSERT_EQUAL(Function::Size, test->match({inputs[i]}, C)); + ASSERT_EQ(Function::Size, test->match({inputs[i]}, C)); } } } @@ -1401,18 +1364,18 @@ TestFunctionTypes::testFunctionMatch() test.reset(new TestFunction({LLVMType::get(C)}, llvm::Type::getVoidTy(C), "ax.test")); - CPPUNIT_ASSERT_EQUAL(Function::Size, + ASSERT_EQ(Function::Size, test->match({LLVMType::get(C)}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Explicit, + ASSERT_EQ(Function::Explicit, test->match({LLVMType::get(C)}, C)); test->setParamAttributes(0, {llvm::Attribute::ReadOnly}); - CPPUNIT_ASSERT_EQUAL(Function::Implicit, + ASSERT_EQ(Function::Implicit, test->match({LLVMType::get(C)}, C)); test.reset(new TestFunction({LLVMType::get(C)}, llvm::Type::getVoidTy(C), "ax.test")); - CPPUNIT_ASSERT_EQUAL(Function::Size, + ASSERT_EQ(Function::Size, test->match({LLVMType::get(C)}, C)); // test pointers @@ -1424,21 +1387,21 @@ TestFunctionTypes::testFunctionMatch() llvm::Type::getVoidTy(C), "ax.ptrs.test")); - CPPUNIT_ASSERT_EQUAL(Function::Explicit, + ASSERT_EQ(Function::Explicit, test->match({fss, dss}, C)); - CPPUNIT_ASSERT_EQUAL(Function::Size, + ASSERT_EQ(Function::Size, test->match({fss, fss}, C)); // Even if pointers are marked as readonly, casting is not supported test->setParamAttributes(0, {llvm::Attribute::ReadOnly}); test->setParamAttributes(1, {llvm::Attribute::ReadOnly}); - CPPUNIT_ASSERT_EQUAL(Function::Size, + ASSERT_EQ(Function::Size, test->match({fss, fss}, C)); } -void -TestFunctionTypes::testCFunctions() +// Test derived CFunctions, mainly CFunction::create and CFunction::types +TEST_F(TestFunctionTypes, testCFunctions) { using openvdb::ax::codegen::CFunction; @@ -1462,50 +1425,50 @@ TestFunctionTypes::testCFunctions() // test static void function - CPPUNIT_ASSERT_EQUAL(size_t(0), voidfunc.size()); - CPPUNIT_ASSERT_EQUAL(reinterpret_cast(&CBindings::voidfunc), + ASSERT_EQ(size_t(0), voidfunc.size()); + ASSERT_EQ(reinterpret_cast(&CBindings::voidfunc), voidfunc.address()); - CPPUNIT_ASSERT_EQUAL(std::string("voidfunc"), + ASSERT_EQ(std::string("voidfunc"), std::string(voidfunc.symbol())); // test scalar arguments - CPPUNIT_ASSERT_EQUAL(size_t(6), scalars.size()); - CPPUNIT_ASSERT_EQUAL(reinterpret_cast(&CBindings::scalarfunc), + ASSERT_EQ(size_t(6), scalars.size()); + ASSERT_EQ(reinterpret_cast(&CBindings::scalarfunc), scalars.address()); - CPPUNIT_ASSERT_EQUAL(std::string("scalarfunc"), + ASSERT_EQ(std::string("scalarfunc"), std::string(scalars.symbol())); // test scalar ptr arguments - CPPUNIT_ASSERT_EQUAL(size_t(6), scalarptrs.size()); - CPPUNIT_ASSERT_EQUAL(reinterpret_cast(&CBindings::scalatptsfunc), + ASSERT_EQ(size_t(6), scalarptrs.size()); + ASSERT_EQ(reinterpret_cast(&CBindings::scalatptsfunc), scalarptrs.address()); - CPPUNIT_ASSERT_EQUAL(std::string("scalatptsfunc"), + ASSERT_EQ(std::string("scalatptsfunc"), std::string(scalarptrs.symbol())); // test array ptr arguments - CPPUNIT_ASSERT_EQUAL(size_t(6), arrayptrs.size()); - CPPUNIT_ASSERT_EQUAL(reinterpret_cast(&CBindings::arrayfunc), + ASSERT_EQ(size_t(6), arrayptrs.size()); + ASSERT_EQ(reinterpret_cast(&CBindings::arrayfunc), arrayptrs.address()); - CPPUNIT_ASSERT_EQUAL(std::string("arrayfunc"), + ASSERT_EQ(std::string("arrayfunc"), std::string(arrayptrs.symbol())); // test selected template functions - CPPUNIT_ASSERT_EQUAL(size_t(0), select.size()); - CPPUNIT_ASSERT_EQUAL(reinterpret_cast(&CBindings::tmplfunc), + ASSERT_EQ(size_t(0), select.size()); + ASSERT_EQ(reinterpret_cast(&CBindings::tmplfunc), select.address()); - CPPUNIT_ASSERT_EQUAL(std::string("tmplfunc"), + ASSERT_EQ(std::string("tmplfunc"), std::string(select.symbol())); // test multiple indirection layers - CPPUNIT_ASSERT_EQUAL(size_t(6), mindirect.size()); - CPPUNIT_ASSERT_EQUAL(reinterpret_cast(&CBindings::multiptrfunc), + ASSERT_EQ(size_t(6), mindirect.size()); + ASSERT_EQ(reinterpret_cast(&CBindings::multiptrfunc), mindirect.address()); - CPPUNIT_ASSERT_EQUAL(std::string("multiptrfunc"), + ASSERT_EQ(std::string("multiptrfunc"), std::string(mindirect.symbol())); // @@ -1514,42 +1477,42 @@ TestFunctionTypes::testCFunctions() // test scalar arguments returnType = scalars.types(types, C); - CPPUNIT_ASSERT(returnType->isIntegerTy(16)); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0]->isIntegerTy(1)); - CPPUNIT_ASSERT(types[1]->isIntegerTy(16)); - CPPUNIT_ASSERT(types[2]->isIntegerTy(32)); - CPPUNIT_ASSERT(types[3]->isIntegerTy(64)); - CPPUNIT_ASSERT(types[4]->isFloatTy()); - CPPUNIT_ASSERT(types[5]->isDoubleTy()); + ASSERT_TRUE(returnType->isIntegerTy(16)); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0]->isIntegerTy(1)); + ASSERT_TRUE(types[1]->isIntegerTy(16)); + ASSERT_TRUE(types[2]->isIntegerTy(32)); + ASSERT_TRUE(types[3]->isIntegerTy(64)); + ASSERT_TRUE(types[4]->isFloatTy()); + ASSERT_TRUE(types[5]->isDoubleTy()); types.clear(); // test scalar ptr arguments returnType = scalarptrs.types(types, C); - CPPUNIT_ASSERT(returnType->isIntegerTy(32)); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::Type::getInt1Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[1] == llvm::Type::getInt16Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::Type::getInt32Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::Type::getInt64Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::Type::getDoubleTy(C)->getPointerTo()); + ASSERT_TRUE(returnType->isIntegerTy(32)); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0] == llvm::Type::getInt1Ty(C)->getPointerTo()); + ASSERT_TRUE(types[1] == llvm::Type::getInt16Ty(C)->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::Type::getInt32Ty(C)->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::Type::getInt64Ty(C)->getPointerTo()); + ASSERT_TRUE(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::Type::getDoubleTy(C)->getPointerTo()); types.clear(); // test array ptr arguments returnType = arrayptrs.types(types, C); - CPPUNIT_ASSERT(returnType->isIntegerTy(64)); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::ArrayType::get(llvm::Type::getInt1Ty(C), 1)->getPointerTo()); - CPPUNIT_ASSERT(types[1] == llvm::ArrayType::get(llvm::Type::getInt16Ty(C), 2)->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::ArrayType::get(llvm::Type::getInt64Ty(C), 4)->getPointerTo()); - CPPUNIT_ASSERT(types[4] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 5)->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 6)->getPointerTo()); + ASSERT_TRUE(returnType->isIntegerTy(64)); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0] == llvm::ArrayType::get(llvm::Type::getInt1Ty(C), 1)->getPointerTo()); + ASSERT_TRUE(types[1] == llvm::ArrayType::get(llvm::Type::getInt16Ty(C), 2)->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::ArrayType::get(llvm::Type::getInt64Ty(C), 4)->getPointerTo()); + ASSERT_TRUE(types[4] == llvm::ArrayType::get(llvm::Type::getFloatTy(C), 5)->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 6)->getPointerTo()); types.clear(); @@ -1557,18 +1520,18 @@ TestFunctionTypes::testCFunctions() // void* are inferred as int8_t* types returnType = mindirect.types(types, C); - CPPUNIT_ASSERT(returnType->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::Type::getInt8PtrTy(C)); - CPPUNIT_ASSERT(types[1] == llvm::Type::getInt8PtrTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::Type::getInt8PtrTy(C)->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); + ASSERT_TRUE(returnType->isVoidTy()); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0] == llvm::Type::getInt8PtrTy(C)); + ASSERT_TRUE(types[1] == llvm::Type::getInt8PtrTy(C)->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::Type::getInt8PtrTy(C)->getPointerTo()->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::Type::getFloatTy(C)->getPointerTo()->getPointerTo()->getPointerTo()); } -void -TestFunctionTypes::testCFunctionCF() +// Test C constant folding +TEST_F(TestFunctionTypes, testCFunctionCF) { using openvdb::ax::codegen::CFunction; using openvdb::ax::codegen::LLVMType; @@ -1588,26 +1551,26 @@ TestFunctionTypes::testCFunctionCF() CFunction test1("ax.test1", cftest1); // off by default - CPPUNIT_ASSERT(!test1.hasConstantFold()); - CPPUNIT_ASSERT(test1.fold({B.getInt32(1)}, C) == nullptr); + ASSERT_TRUE(!test1.hasConstantFold()); + ASSERT_TRUE(test1.fold({B.getInt32(1)}, C) == nullptr); test1.setConstantFold(true); llvm::Value* result = test1.fold({B.getInt32(1)}, C); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); llvm::ConstantInt* constant = llvm::dyn_cast(result); - CPPUNIT_ASSERT(constant); - CPPUNIT_ASSERT_EQUAL(uint64_t(10), constant->getLimitedValue()); + ASSERT_TRUE(constant); + ASSERT_EQ(uint64_t(10), constant->getLimitedValue()); // test with scalar arg CFunction test2("ax.test2", cftest2); test2.setConstantFold(true); result = test2.fold({LLVMType::get(C, -3.2f)}, C); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); llvm::ConstantFP* constantfp = llvm::dyn_cast(result); - CPPUNIT_ASSERT(constantfp); + ASSERT_TRUE(constantfp); const llvm::APFloat& apf = constantfp->getValueAPF(); - CPPUNIT_ASSERT_EQUAL(-3.2f, apf.convertToFloat()); + ASSERT_EQ(-3.2f, apf.convertToFloat()); // test unsupported @@ -1619,9 +1582,9 @@ TestFunctionTypes::testCFunctionCF() // its impossible to have a constant ptr, use this for now as this will most // likely be the way we support folding for arrays in the future llvm::Value* arg = LLVMType::get(C, {1,2,3}); - CPPUNIT_ASSERT(llvm::isa(arg)); + ASSERT_TRUE(llvm::isa(arg)); // check fold fails - CPPUNIT_ASSERT(test3.fold({arg}, C) == nullptr); + ASSERT_TRUE(test3.fold({arg}, C) == nullptr); // @@ -1631,13 +1594,13 @@ TestFunctionTypes::testCFunctionCF() llvm::Value* nullfloat = llvm::ConstantPointerNull::get(LLVMType::get(C)); std::vector types; test4.types(types, C); - CPPUNIT_ASSERT_EQUAL(size_t(1), types.size()); - CPPUNIT_ASSERT(nullfloat->getType() == types.front()); - CPPUNIT_ASSERT(test4.fold({nullfloat}, C) == nullptr); + ASSERT_EQ(size_t(1), types.size()); + ASSERT_TRUE(nullfloat->getType() == types.front()); + ASSERT_TRUE(test4.fold({nullfloat}, C) == nullptr); } -void -TestFunctionTypes::testIRFunctions() +// Test derived IR Function, IRFunctionBase::create and IRFunctionBase::call +TEST_F(TestFunctionTypes, testIRFunctions) { using openvdb::ax::codegen::LLVMType; using openvdb::ax::codegen::Function; @@ -1664,19 +1627,19 @@ TestFunctionTypes::testIRFunctions() double(*)[2])> mix("mix", generate); - CPPUNIT_ASSERT_EQUAL(std::string("mix"), + ASSERT_EQ(std::string("mix"), std::string(mix.symbol())); std::vector types; llvm::Type* returnType = mix.types(types, C); - CPPUNIT_ASSERT(returnType->isDoubleTy()); - CPPUNIT_ASSERT_EQUAL(size_t(6), types.size()); - CPPUNIT_ASSERT(types[0] == llvm::Type::getInt1Ty(C)); - CPPUNIT_ASSERT(types[1] == llvm::Type::getInt16Ty(C)->getPointerTo()); - CPPUNIT_ASSERT(types[2] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 1)->getPointerTo()); - CPPUNIT_ASSERT(types[3] == llvm::Type::getInt64Ty(C)); - CPPUNIT_ASSERT(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()); - CPPUNIT_ASSERT(types[5] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)->getPointerTo()); + ASSERT_TRUE(returnType->isDoubleTy()); + ASSERT_EQ(size_t(6), types.size()); + ASSERT_TRUE(types[0] == llvm::Type::getInt1Ty(C)); + ASSERT_TRUE(types[1] == llvm::Type::getInt16Ty(C)->getPointerTo()); + ASSERT_TRUE(types[2] == llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 1)->getPointerTo()); + ASSERT_TRUE(types[3] == llvm::Type::getInt64Ty(C)); + ASSERT_TRUE(types[4] == llvm::Type::getFloatTy(C)->getPointerTo()); + ASSERT_TRUE(types[5] == llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)->getPointerTo()); } llvm::Module& M = state.module(); @@ -1699,29 +1662,43 @@ TestFunctionTypes::testIRFunctions() (const std::vector& args, llvm::IRBuilder<>& _B) -> llvm::Value* { + // NOTE: GTest's ASSERT_* macros create a 'return;' statement + // which errors here. Exceptions are being used instead to + // exit early. + // test the builder is pointing to the correct location - CPPUNIT_ASSERT(&B != &_B); + if (&B == &_B) + { + throw std::runtime_error("Builder should be different"); + } llvm::BasicBlock* Block = _B.GetInsertBlock(); - CPPUNIT_ASSERT(Block); - CPPUNIT_ASSERT(Block->empty()); + if (!Block || !Block->empty()) + { + throw std::runtime_error("Basic block should exist and be empty"); + } llvm::Function* F = Block->getParent(); - CPPUNIT_ASSERT(F); - CPPUNIT_ASSERT_EQUAL(expectedName, std::string(F->getName())); + if (!F) + { + throw std::runtime_error("Function should exist"); + } + EXPECT_EQ(expectedName, std::string(F->getName())); llvm::Module* _M = F->getParent(); - CPPUNIT_ASSERT_EQUAL(&M, _M); + EXPECT_EQ(&M, _M); - CPPUNIT_ASSERT_EQUAL(size_t(2), args.size()); - CPPUNIT_ASSERT(args[0] == llvm::cast(F->arg_begin())); - CPPUNIT_ASSERT(args[1] == llvm::cast(F->arg_begin()+1)); - CPPUNIT_ASSERT(args[0]->getType()->isFloatTy()); - CPPUNIT_ASSERT(args[1]->getType()->isFloatTy()); + if (args.size() != 2) + { + throw std::runtime_error("Function should take two arguments"); + } + EXPECT_TRUE(args[0] == llvm::cast(F->arg_begin())); + EXPECT_TRUE(args[1] == llvm::cast(F->arg_begin()+1)); + EXPECT_TRUE(args[0]->getType()->isFloatTy()); + EXPECT_TRUE(args[1]->getType()->isFloatTy()); llvm::Value* result = _B.CreateFAdd(args[0], args[1]); if (termMode == 0) return _B.CreateRet(result); if (termMode == 1) return result; if (termMode == 2) return nullptr; - CPPUNIT_ASSERT(false); - return nullptr; + throw std::runtime_error("Should be unreachable"); }; llvm::Function* function = nullptr; @@ -1735,59 +1712,59 @@ TestFunctionTypes::testIRFunctions() expectedName, generate)); // Test function prototype creation - CPPUNIT_ASSERT(!M.getFunction("ax.ir.test")); + ASSERT_TRUE(!M.getFunction("ax.ir.test")); // detached function = test->create(C); llvm::Function* function2 = test->create(C); - CPPUNIT_ASSERT(!M.getFunction("ax.ir.test")); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT(function != function2); - CPPUNIT_ASSERT(!function->isVarArg()); - CPPUNIT_ASSERT_EQUAL(size_t(2), function->arg_size()); + ASSERT_TRUE(!M.getFunction("ax.ir.test")); + ASSERT_TRUE(function); + ASSERT_TRUE(function->empty()); + ASSERT_TRUE(function != function2); + ASSERT_TRUE(!function->isVarArg()); + ASSERT_EQ(size_t(2), function->arg_size()); llvm::FunctionType* ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isFloatTy()); - CPPUNIT_ASSERT_EQUAL(2u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0)->isFloatTy()); - CPPUNIT_ASSERT(ftype->getParamType(1)->isFloatTy()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isFloatTy()); + ASSERT_EQ(2u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0)->isFloatTy()); + ASSERT_TRUE(ftype->getParamType(1)->isFloatTy()); + ASSERT_TRUE(function->getAttributes().isEmpty()); delete function; delete function2; // Test function creation with module and IR generation - CPPUNIT_ASSERT(!M.getFunction("ax.ir.test")); + ASSERT_TRUE(!M.getFunction("ax.ir.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.ir.test")); - CPPUNIT_ASSERT(!function->empty()); + ASSERT_TRUE(function); + ASSERT_EQ(function, M.getFunction("ax.ir.test")); + ASSERT_TRUE(!function->empty()); llvm::BasicBlock* BB = &(function->getEntryBlock()); // two instructions - the add and return - CPPUNIT_ASSERT_EQUAL(size_t(2), BB->size()); + ASSERT_EQ(size_t(2), BB->size()); auto iter = BB->begin(); llvm::BinaryOperator* binary = llvm::dyn_cast(iter); - CPPUNIT_ASSERT(binary); - CPPUNIT_ASSERT_EQUAL(llvm::Instruction::FAdd, binary->getOpcode()); - CPPUNIT_ASSERT_EQUAL(llvm::cast(function->arg_begin()), + ASSERT_TRUE(binary); + ASSERT_EQ(llvm::Instruction::FAdd, binary->getOpcode()); + ASSERT_EQ(llvm::cast(function->arg_begin()), binary->getOperand(0)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(function->arg_begin()+1), + ASSERT_EQ(llvm::cast(function->arg_begin()+1), binary->getOperand(1)); ++iter; llvm::ReturnInst* ret = llvm::dyn_cast(iter); - CPPUNIT_ASSERT(ret); + ASSERT_TRUE(ret); llvm::Value* rvalue = ret->getReturnValue(); - CPPUNIT_ASSERT(rvalue); - CPPUNIT_ASSERT(rvalue->getType()->isFloatTy()); + ASSERT_TRUE(rvalue); + ASSERT_TRUE(rvalue->getType()->isFloatTy()); // the return is the result of the bin op - CPPUNIT_ASSERT_EQUAL(rvalue, llvm::cast(binary)); + ASSERT_EQ(rvalue, llvm::cast(binary)); ++iter; - CPPUNIT_ASSERT(BB->end() == iter); + ASSERT_TRUE(BB->end() == iter); // additional call should match - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); + ASSERT_EQ(function, test->create(M)); // verify IR VERIFY_FUNCTION_IR(function); @@ -1796,16 +1773,16 @@ TestFunctionTypes::testIRFunctions() llvm::Value* fp1 = LLVMType::get(C, 1.0f); llvm::Value* fp2 = LLVMType::get(C, 2.0f); llvm::Value* result = test->call({fp1, fp2}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); llvm::CallInst* call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(fp1, call->getArgOperand(0)); - CPPUNIT_ASSERT_EQUAL(fp2, call->getArgOperand(1)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_EQ(fp1, call->getArgOperand(0)); + ASSERT_EQ(fp2, call->getArgOperand(1)); // Test the builder is pointing to the correct location - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); - CPPUNIT_ASSERT_EQUAL(llvm::cast(call), + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_EQ(llvm::cast(call), llvm::cast(--B.GetInsertPoint())); // verify IR @@ -1827,45 +1804,45 @@ TestFunctionTypes::testIRFunctions() llvm::Type::getFloatTy(C), expectedName, generate)); - CPPUNIT_ASSERT(!M.getFunction("ax.ir.autoret.test")); + ASSERT_TRUE(!M.getFunction("ax.ir.autoret.test")); result = test->call({fp1, fp2}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); + ASSERT_TRUE(call); function = M.getFunction("ax.ir.autoret.test"); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(fp1, call->getArgOperand(0)); - CPPUNIT_ASSERT_EQUAL(fp2, call->getArgOperand(1)); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_EQ(fp1, call->getArgOperand(0)); + ASSERT_EQ(fp2, call->getArgOperand(1)); - CPPUNIT_ASSERT(!function->empty()); + ASSERT_TRUE(!function->empty()); BB = &(function->getEntryBlock()); // two instructions - the add and return - CPPUNIT_ASSERT_EQUAL(size_t(2), BB->size()); + ASSERT_EQ(size_t(2), BB->size()); iter = BB->begin(); binary = llvm::dyn_cast(iter); - CPPUNIT_ASSERT(binary); - CPPUNIT_ASSERT_EQUAL(llvm::Instruction::FAdd, binary->getOpcode()); - CPPUNIT_ASSERT_EQUAL(llvm::cast(function->arg_begin()), + ASSERT_TRUE(binary); + ASSERT_EQ(llvm::Instruction::FAdd, binary->getOpcode()); + ASSERT_EQ(llvm::cast(function->arg_begin()), binary->getOperand(0)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(function->arg_begin()+1), + ASSERT_EQ(llvm::cast(function->arg_begin()+1), binary->getOperand(1)); ++iter; ret = llvm::dyn_cast(iter); - CPPUNIT_ASSERT(ret); + ASSERT_TRUE(ret); rvalue = ret->getReturnValue(); - CPPUNIT_ASSERT(rvalue); - CPPUNIT_ASSERT(rvalue->getType()->isFloatTy()); + ASSERT_TRUE(rvalue); + ASSERT_TRUE(rvalue->getType()->isFloatTy()); // the return is the result of the bin op - CPPUNIT_ASSERT_EQUAL(rvalue, llvm::cast(binary)); + ASSERT_EQ(rvalue, llvm::cast(binary)); ++iter; - CPPUNIT_ASSERT(BB->end() == iter); + ASSERT_TRUE(BB->end() == iter); // Test the builder is pointing to the correct location - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); - CPPUNIT_ASSERT_EQUAL(llvm::cast(call), + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_EQ(llvm::cast(call), llvm::cast(--B.GetInsertPoint())); // verify @@ -1884,45 +1861,45 @@ TestFunctionTypes::testIRFunctions() llvm::Type::getFloatTy(C), expectedName, generate)); - CPPUNIT_ASSERT(!M.getFunction("ax.ir.retnull.test")); + ASSERT_TRUE(!M.getFunction("ax.ir.retnull.test")); // will throw as the function expects a float ret, not void or null // NOTE: The function will still be created, but be in an invaid state - CPPUNIT_ASSERT_THROW(test->create(M), openvdb::AXCodeGenError); + ASSERT_THROW(test->create(M), openvdb::AXCodeGenError); function = M.getFunction("ax.ir.retnull.test"); - CPPUNIT_ASSERT(function); + ASSERT_TRUE(function); result = test->call({fp1, fp2}, B, /*cast*/false); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); call = llvm::dyn_cast(result); - CPPUNIT_ASSERT(call); - CPPUNIT_ASSERT_EQUAL(function, call->getCalledFunction()); - CPPUNIT_ASSERT_EQUAL(2u, getNumArgFromCallInst(call)); - CPPUNIT_ASSERT_EQUAL(fp1, call->getArgOperand(0)); - CPPUNIT_ASSERT_EQUAL(fp2, call->getArgOperand(1)); + ASSERT_TRUE(call); + ASSERT_EQ(function, call->getCalledFunction()); + ASSERT_EQ(2u, getNumArgFromCallInst(call)); + ASSERT_EQ(fp1, call->getArgOperand(0)); + ASSERT_EQ(fp2, call->getArgOperand(1)); BB = &(function->getEntryBlock()); // two instructions - the add and return - CPPUNIT_ASSERT_EQUAL(size_t(2), BB->size()); + ASSERT_EQ(size_t(2), BB->size()); iter = BB->begin(); binary = llvm::dyn_cast(iter); - CPPUNIT_ASSERT(binary); - CPPUNIT_ASSERT_EQUAL(llvm::Instruction::FAdd, binary->getOpcode()); - CPPUNIT_ASSERT_EQUAL(llvm::cast(function->arg_begin()), + ASSERT_TRUE(binary); + ASSERT_EQ(llvm::Instruction::FAdd, binary->getOpcode()); + ASSERT_EQ(llvm::cast(function->arg_begin()), binary->getOperand(0)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(function->arg_begin()+1), + ASSERT_EQ(llvm::cast(function->arg_begin()+1), binary->getOperand(1)); ++iter; ret = llvm::dyn_cast(iter); - CPPUNIT_ASSERT(ret); - CPPUNIT_ASSERT(!ret->getReturnValue()); + ASSERT_TRUE(ret); + ASSERT_TRUE(!ret->getReturnValue()); ++iter; - CPPUNIT_ASSERT(BB->end() == iter); + ASSERT_TRUE(BB->end() == iter); // Test the builder is pointing to the correct location - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); - CPPUNIT_ASSERT_EQUAL(llvm::cast(call), + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_EQ(llvm::cast(call), llvm::cast(--B.GetInsertPoint())); // verify - function is invalid as it returns void but the @@ -1938,19 +1915,34 @@ TestFunctionTypes::testIRFunctions() (const std::vector& args, llvm::IRBuilder<>& _B) -> llvm::Value* { + // NOTE: GTest's ASSERT_* macros create a 'return;' statement + // which errors here. Exceptions are being used instead to + // exit early. + // test the builder is pointing to the correct location // note, for embedded IR, the same builder will be used - CPPUNIT_ASSERT_EQUAL(&B, &_B); + if (&B != &_B) + { + throw std::runtime_error("Builders should be the same"); + } llvm::BasicBlock* Block = _B.GetInsertBlock(); - CPPUNIT_ASSERT(Block); - CPPUNIT_ASSERT(!Block->empty()); + if (!Block || Block->empty()) + { + throw std::runtime_error("Basic block should exist and be populated"); + } llvm::Function* F = Block->getParent(); - CPPUNIT_ASSERT(F); - CPPUNIT_ASSERT_EQUAL(std::string("TestFunction"), std::string(F->getName())); - CPPUNIT_ASSERT_EQUAL(&M, F->getParent()); - CPPUNIT_ASSERT_EQUAL(size_t(2), args.size()); - CPPUNIT_ASSERT(args[0]->getType()->isFloatTy()); - CPPUNIT_ASSERT(args[1]->getType()->isFloatTy()); + if (!F) + { + throw std::runtime_error("Function should exist"); + } + EXPECT_EQ(std::string("TestFunction"), std::string(F->getName())); + EXPECT_EQ(&M, F->getParent()); + if (args.size() != 2) + { + throw std::runtime_error("Function should take two arguments"); + } + EXPECT_TRUE(args[0]->getType()->isFloatTy()); + EXPECT_TRUE(args[1]->getType()->isFloatTy()); // Can't just do a CreateFAdd as the IR builder won't actually even // write the instruction as its const and unused - so store in a new // alloc @@ -1968,25 +1960,25 @@ TestFunctionTypes::testIRFunctions() static_cast(*test).setEmbedIR(true); // test create does nothing - CPPUNIT_ASSERT(test->create(C) == nullptr); - CPPUNIT_ASSERT(test->create(M) == nullptr); + ASSERT_TRUE(test->create(C) == nullptr); + ASSERT_TRUE(test->create(M) == nullptr); // test call - CPPUNIT_ASSERT(!M.getFunction("ax.ir.embed.test")); + ASSERT_TRUE(!M.getFunction("ax.ir.embed.test")); result = test->call({fp1, fp2}, B, /*cast*/false); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(!M.getFunction("ax.ir.embed.test")); + ASSERT_TRUE(result); + ASSERT_TRUE(!M.getFunction("ax.ir.embed.test")); auto IP = B.GetInsertPoint(); // check the prev instructions are as expected - CPPUNIT_ASSERT(llvm::isa(--IP)); - CPPUNIT_ASSERT(llvm::isa(--IP)); - CPPUNIT_ASSERT(llvm::isa(--IP)); + ASSERT_TRUE(llvm::isa(--IP)); + ASSERT_TRUE(llvm::isa(--IP)); + ASSERT_TRUE(llvm::isa(--IP)); // Test the builder is pointing to the correct location - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); } -void -TestFunctionTypes::testSRETFunctions() +// Test SRET methods for both C and IR functions +TEST_F(TestFunctionTypes, testSRETFunctions) { using openvdb::ax::codegen::LLVMType; using openvdb::ax::codegen::Function; @@ -2017,50 +2009,50 @@ TestFunctionTypes::testSRETFunctions() // test types llvm::Type* vec3f = llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3); type = test->types(types, C); - CPPUNIT_ASSERT_EQUAL(size_t(1), types.size()); - CPPUNIT_ASSERT(types[0] == vec3f->getPointerTo(0)); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isVoidTy()); + ASSERT_EQ(size_t(1), types.size()); + ASSERT_TRUE(types[0] == vec3f->getPointerTo(0)); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isVoidTy()); // test various getters - CPPUNIT_ASSERT_EQUAL(std::string("ax.c.test"), std::string(test->symbol())); - CPPUNIT_ASSERT_EQUAL(size_t(1), test->size()); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(0))); + ASSERT_EQ(std::string("ax.c.test"), std::string(test->symbol())); + ASSERT_EQ(size_t(1), test->size()); + ASSERT_EQ(std::string(""), std::string(test->argName(0))); // test printing os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("vec3f name()"), os.str()); + ASSERT_EQ(std::string("vec3f name()"), os.str()); // test match match = test->match({vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::None); + ASSERT_EQ(match, Function::None); match = test->match({}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); match = test->Function::match({vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); // test create - CPPUNIT_ASSERT(!M.getFunction("ax.c.test")); + ASSERT_TRUE(!M.getFunction("ax.c.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.c.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(1), function->arg_size()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.c.test")); + ASSERT_EQ(function, test->create(M)); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(1), function->arg_size()); + ASSERT_TRUE(function->getAttributes().isEmpty()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(1u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0) == vec3f->getPointerTo()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(1u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0) == vec3f->getPointerTo()); // test call - sret function do not return the CallInst as the value result = test->call({}, B, /*cast*/false); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(!llvm::dyn_cast(result)); - CPPUNIT_ASSERT(result->getType() == vec3f->getPointerTo()); - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_TRUE(result); + ASSERT_TRUE(!llvm::dyn_cast(result)); + ASSERT_TRUE(result->getType() == vec3f->getPointerTo()); + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); VERIFY_FUNCTION_IR(function); VERIFY_MODULE_IR(&M); @@ -2075,57 +2067,57 @@ TestFunctionTypes::testSRETFunctions() // test types type = test->types(types, C); - CPPUNIT_ASSERT_EQUAL(size_t(2), types.size()); - CPPUNIT_ASSERT(types[0] == vec3f->getPointerTo(0)); - CPPUNIT_ASSERT(types[1] == vec3f->getPointerTo(0)); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isVoidTy()); + ASSERT_EQ(size_t(2), types.size()); + ASSERT_TRUE(types[0] == vec3f->getPointerTo(0)); + ASSERT_TRUE(types[1] == vec3f->getPointerTo(0)); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isVoidTy()); // test various getters - CPPUNIT_ASSERT_EQUAL(std::string("ax.c2.test"), std::string(test->symbol())); - CPPUNIT_ASSERT_EQUAL(size_t(2), test->size()); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(0))); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(1))); + ASSERT_EQ(std::string("ax.c2.test"), std::string(test->symbol())); + ASSERT_EQ(size_t(2), test->size()); + ASSERT_EQ(std::string(""), std::string(test->argName(0))); + ASSERT_EQ(std::string(""), std::string(test->argName(1))); // test printing os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("vec3f name(vec3f)"), os.str()); + ASSERT_EQ(std::string("vec3f name(vec3f)"), os.str()); // test match match = test->match({vec3f->getPointerTo(),vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::None); + ASSERT_EQ(match, Function::None); match = test->match({vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); match = test->match({}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::None); + ASSERT_EQ(match, Function::None); match = test->Function::match({vec3f->getPointerTo(),vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); // test create - CPPUNIT_ASSERT(!M.getFunction("ax.c2.test")); + ASSERT_TRUE(!M.getFunction("ax.c2.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT(M.getFunction("ax.c2.test")); - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); - CPPUNIT_ASSERT(function->empty()); - CPPUNIT_ASSERT_EQUAL(size_t(2), function->arg_size()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_TRUE(function); + ASSERT_TRUE(M.getFunction("ax.c2.test")); + ASSERT_EQ(function, test->create(M)); + ASSERT_TRUE(function->empty()); + ASSERT_EQ(size_t(2), function->arg_size()); + ASSERT_TRUE(function->getAttributes().isEmpty()); ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(2u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0) == vec3f->getPointerTo()); - CPPUNIT_ASSERT(ftype->getParamType(1) == vec3f->getPointerTo()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(2u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0) == vec3f->getPointerTo()); + ASSERT_TRUE(ftype->getParamType(1) == vec3f->getPointerTo()); // test call - sret function do not return the CallInst as the value llvm::Value* f32c0 = LLVMType::get(C, 0.0f); // float llvm::Value* vec3fv = openvdb::ax::codegen::arrayPack({f32c0,f32c0,f32c0}, B); // vec3f result = test->call({vec3fv}, B, /*cast*/false); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(!llvm::dyn_cast(result)); - CPPUNIT_ASSERT(result->getType() == vec3f->getPointerTo()); - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_TRUE(result); + ASSERT_TRUE(!llvm::dyn_cast(result)); + ASSERT_TRUE(result->getType() == vec3f->getPointerTo()); + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); VERIFY_FUNCTION_IR(function); VERIFY_MODULE_IR(&M); @@ -2145,20 +2137,33 @@ TestFunctionTypes::testSRETFunctions() (const std::vector& args, llvm::IRBuilder<>& _B) -> llvm::Value* { + // NOTE: GTest's ASSERT_* macros create a 'return;' statement + // which errors here. Exceptions are being used instead to + // exit early. + // test the builder is pointing to the correct location - CPPUNIT_ASSERT(&B != &_B); + if (&B == &_B) + { + throw std::runtime_error("Builders should be different"); + } llvm::BasicBlock* Block = _B.GetInsertBlock(); - CPPUNIT_ASSERT(Block); - CPPUNIT_ASSERT(Block->empty()); + if (!Block || !Block->empty()) { + throw std::runtime_error("Basic block should exist and be empty"); + } llvm::Function* F = Block->getParent(); - CPPUNIT_ASSERT(F); - CPPUNIT_ASSERT_EQUAL(std::string("ax.ir.test"), std::string(F->getName())); + if (!F) + { + throw std::runtime_error("Function should exist"); + } + EXPECT_EQ(std::string("ax.ir.test"), std::string(F->getName())); llvm::Module* _M = F->getParent(); - CPPUNIT_ASSERT_EQUAL(&M, _M); + EXPECT_EQ(&M, _M); - CPPUNIT_ASSERT_EQUAL(size_t(1), args.size()); - CPPUNIT_ASSERT(args[0] == llvm::cast(F->arg_begin())); - CPPUNIT_ASSERT(args[0]->getType() == + if (args.size() != 1){ + throw std::runtime_error("Function should take one argument"); + } + EXPECT_TRUE(args[0] == llvm::cast(F->arg_begin())); + EXPECT_TRUE(args[0]->getType() == llvm::ArrayType::get(llvm::Type::getFloatTy(_B.getContext()), 3)->getPointerTo()); llvm::Value* e0 = openvdb::ax::codegen::ir_constgep2_64(_B, args[0], 0, 0); @@ -2171,63 +2176,63 @@ TestFunctionTypes::testSRETFunctions() // test types type = test->types(types, C); - CPPUNIT_ASSERT_EQUAL(size_t(1), types.size()); - CPPUNIT_ASSERT(types[0] == vec3f->getPointerTo(0)); - CPPUNIT_ASSERT(type); - CPPUNIT_ASSERT(type->isVoidTy()); + ASSERT_EQ(size_t(1), types.size()); + ASSERT_TRUE(types[0] == vec3f->getPointerTo(0)); + ASSERT_TRUE(type); + ASSERT_TRUE(type->isVoidTy()); // test various getters - CPPUNIT_ASSERT_EQUAL(std::string("ax.ir.test"), std::string(test->symbol())); - CPPUNIT_ASSERT_EQUAL(size_t(1), test->size()); - CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(test->argName(0))); + ASSERT_EQ(std::string("ax.ir.test"), std::string(test->symbol())); + ASSERT_EQ(size_t(1), test->size()); + ASSERT_EQ(std::string(""), std::string(test->argName(0))); // test printing os.str(""); test->print(C, os, "name", /*axtypes=*/true); - CPPUNIT_ASSERT_EQUAL(std::string("vec3f name()"), os.str()); + ASSERT_EQ(std::string("vec3f name()"), os.str()); // test match match = test->match({vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::None); + ASSERT_EQ(match, Function::None); match = test->match({}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); match = test->Function::match({vec3f->getPointerTo()}, C); - CPPUNIT_ASSERT_EQUAL(match, Function::Explicit); + ASSERT_EQ(match, Function::Explicit); // test create - CPPUNIT_ASSERT(!M.getFunction("ax.ir.test")); + ASSERT_TRUE(!M.getFunction("ax.ir.test")); function = test->create(M); - CPPUNIT_ASSERT(function); - CPPUNIT_ASSERT_EQUAL(function, M.getFunction("ax.ir.test")); - CPPUNIT_ASSERT(!function->empty()); + ASSERT_TRUE(function); + ASSERT_EQ(function, M.getFunction("ax.ir.test")); + ASSERT_TRUE(!function->empty()); // test instructions llvm::BasicBlock* BB = &(function->getEntryBlock()); - CPPUNIT_ASSERT_EQUAL(size_t(3), BB->size()); + ASSERT_EQ(size_t(3), BB->size()); auto iter = BB->begin(); - CPPUNIT_ASSERT(llvm::isa(iter++)); - CPPUNIT_ASSERT(llvm::isa(iter++)); - CPPUNIT_ASSERT(llvm::isa(iter++)); - CPPUNIT_ASSERT(BB->end() == iter); + ASSERT_TRUE(llvm::isa(iter++)); + ASSERT_TRUE(llvm::isa(iter++)); + ASSERT_TRUE(llvm::isa(iter++)); + ASSERT_TRUE(BB->end() == iter); // additional call should match - CPPUNIT_ASSERT_EQUAL(function, test->create(M)); - CPPUNIT_ASSERT_EQUAL(size_t(1), function->arg_size()); - CPPUNIT_ASSERT(function->getAttributes().isEmpty()); + ASSERT_EQ(function, test->create(M)); + ASSERT_EQ(size_t(1), function->arg_size()); + ASSERT_TRUE(function->getAttributes().isEmpty()); // check function type ftype = function->getFunctionType(); - CPPUNIT_ASSERT(ftype); - CPPUNIT_ASSERT(ftype->getReturnType()->isVoidTy()); - CPPUNIT_ASSERT_EQUAL(1u, ftype->getNumParams()); - CPPUNIT_ASSERT(ftype->getParamType(0) == vec3f->getPointerTo()); + ASSERT_TRUE(ftype); + ASSERT_TRUE(ftype->getReturnType()->isVoidTy()); + ASSERT_EQ(1u, ftype->getNumParams()); + ASSERT_TRUE(ftype->getParamType(0) == vec3f->getPointerTo()); // test call - sret function do not return the CallInst as the value result = test->call({}, B, /*cast*/false); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT(!llvm::dyn_cast(result)); - CPPUNIT_ASSERT(result->getType() == vec3f->getPointerTo()); - CPPUNIT_ASSERT_EQUAL(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); + ASSERT_TRUE(result); + ASSERT_TRUE(!llvm::dyn_cast(result)); + ASSERT_TRUE(result->getType() == vec3f->getPointerTo()); + ASSERT_EQ(&(BaseFunction->getEntryBlock()), B.GetInsertBlock()); VERIFY_FUNCTION_IR(function); VERIFY_MODULE_IR(&M); From b90ea238ec7b4a175c1609ec98185f6f902e4325 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 17:18:17 -0700 Subject: [PATCH 10/21] Convert TestLogger.cc from cppunit to gtest; add gtest friend declarations to Logger Signed-off-by: Tim Straubinger --- openvdb_ax/openvdb_ax/compiler/Logger.h | 6 +- .../openvdb_ax/test/backend/TestLogger.cc | 204 ++++++++---------- 2 files changed, 99 insertions(+), 111 deletions(-) diff --git a/openvdb_ax/openvdb_ax/compiler/Logger.h b/openvdb_ax/openvdb_ax/compiler/Logger.h index 850d8b45e1..67bd6a915b 100644 --- a/openvdb_ax/openvdb_ax/compiler/Logger.h +++ b/openvdb_ax/openvdb_ax/compiler/Logger.h @@ -16,6 +16,8 @@ #include +#include // FRIEND_TEST, see TestLogger.cc + #include #include #include @@ -197,7 +199,9 @@ class OPENVDB_AX_API Logger private: - friend class ::TestLogger; + FRIEND_TEST(TestLogger, testParseSetsTree); + FRIEND_TEST(TestLogger, testAddError); + FRIEND_TEST(TestLogger, testAddWarning); OutputFunction mErrorOutput; OutputFunction mWarningOutput; diff --git a/openvdb_ax/openvdb_ax/test/backend/TestLogger.cc b/openvdb_ax/openvdb_ax/test/backend/TestLogger.cc index c58a670c5f..226b8046d0 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestLogger.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestLogger.cc @@ -6,32 +6,19 @@ #include #include -#include +#include -class TestLogger : public CppUnit::TestCase +// namespace must be the same as where Logger is defined in order +// to access private fields. See also +//https://google.github.io/googletest/advanced.html#testing-private-code + +namespace openvdb { +namespace OPENVDB_VERSION_NAME { +namespace ax { +class TestLogger : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestLogger); - //CPPUNIT_TEST(testParseNewNode); - CPPUNIT_TEST(testParseSetsTree); - CPPUNIT_TEST(testAddError); - CPPUNIT_TEST(testAddWarning); - CPPUNIT_TEST(testWarningsAsErrors); - CPPUNIT_TEST(testMaxErrors); - - CPPUNIT_TEST_SUITE_END(); - - //void testParseNewNode(); - void testParseSetsTree(); - void testAddError(); - void testAddWarning(); - void testWarningsAsErrors(); - void testMaxErrors(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestLogger); - /* extern openvdb::ax::Logger* axlog; /// @note We don't deploy the grammar c files as part of the AX install. @@ -40,8 +27,7 @@ extern openvdb::ax::Logger* axlog; /// access to newNode. It's tested through other methods, but we /// should restructure how this code is shared by perhaps moving it to /// a shared header (including the definition of AXLTYPE) -void -TestLogger::testParseNewNode() +TEST_F(TestLogger, testParseNewNode) { openvdb::ax::Logger logger; axlog = &logger;// setting global Logger* used in parser @@ -49,207 +35,205 @@ TestLogger::testParseNewNode() location.first_line = 100; location.first_column = 65; const auto& nodeToLineColMap = logger.mNodeToLineColMap; - CPPUNIT_ASSERT(nodeToLineColMap.empty()); + ASSERT_TRUE(nodeToLineColMap.empty()); const openvdb::ax::ast::Local* testLocal = newNode(&location, "test"); - CPPUNIT_ASSERT_EQUAL(nodeToLineColMap.size(),static_cast(1)); + ASSERT_EQ(nodeToLineColMap.size(),static_cast(1)); openvdb::ax::Logger::CodeLocation lineCol = nodeToLineColMap.at(testLocal); - CPPUNIT_ASSERT_EQUAL(lineCol.first, static_cast(100)); - CPPUNIT_ASSERT_EQUAL(lineCol.second, static_cast(65)); + ASSERT_EQ(lineCol.first, static_cast(100)); + ASSERT_EQ(lineCol.second, static_cast(65)); } */ -void -TestLogger::testParseSetsTree() +TEST_F(TestLogger, testParseSetsTree) { openvdb::ax::Logger logger; - CPPUNIT_ASSERT(!logger.mTreePtr); + ASSERT_TRUE(!logger.mTreePtr); std::string code(""); openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(code.c_str(), logger); - CPPUNIT_ASSERT(tree); - CPPUNIT_ASSERT_EQUAL(tree, logger.mTreePtr); + ASSERT_TRUE(tree); + ASSERT_EQ(tree, logger.mTreePtr); } -void -TestLogger::testAddError() +TEST_F(TestLogger, testAddError) { std::vector messages; openvdb::ax::Logger logger([&messages](const std::string& message) { messages.emplace_back(message); }); - CPPUNIT_ASSERT(!logger.hasError()); - CPPUNIT_ASSERT_EQUAL(logger.errors(), messages.size()); + ASSERT_TRUE(!logger.hasError()); + ASSERT_EQ(logger.errors(), messages.size()); openvdb::ax::Logger::CodeLocation codeLocation(1,1); std::string message("test"); logger.error(message, codeLocation); - CPPUNIT_ASSERT(logger.hasError()); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(logger.errors(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] error: test 1:1"), 0); + ASSERT_TRUE(logger.hasError()); + ASSERT_EQ(messages.size(), static_cast(1)); + ASSERT_EQ(logger.errors(), static_cast(1)); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] error: test 1:1"), 0); logger.error(message, codeLocation); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(2)); - CPPUNIT_ASSERT_EQUAL(logger.errors(), static_cast(2)); + ASSERT_EQ(messages.size(), static_cast(2)); + ASSERT_EQ(logger.errors(), static_cast(2)); logger.clear(); - CPPUNIT_ASSERT(!logger.hasError()); - CPPUNIT_ASSERT_EQUAL(logger.errors(), static_cast(0)); + ASSERT_TRUE(!logger.hasError()); + ASSERT_EQ(logger.errors(), static_cast(0)); openvdb::ax::ast::Local testLocal("name"); logger.error(message, &testLocal); - CPPUNIT_ASSERT(logger.hasError()); - CPPUNIT_ASSERT_EQUAL(logger.errors(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(3)); + ASSERT_TRUE(logger.hasError()); + ASSERT_EQ(logger.errors(), static_cast(1)); + ASSERT_EQ(messages.size(), static_cast(3)); - CPPUNIT_ASSERT(!logger.mTreePtr); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] error: test"), 0); + ASSERT_TRUE(!logger.mTreePtr); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] error: test"), 0); logger.clear(); - CPPUNIT_ASSERT(!logger.hasError()); + ASSERT_TRUE(!logger.hasError()); // test that add error finds code location { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(" a;", logger); const openvdb::ax::ast::Node* local = tree->child(0)->child(0); - CPPUNIT_ASSERT(local); + ASSERT_TRUE(local); logger.error(message, local); - CPPUNIT_ASSERT(logger.hasError()); - CPPUNIT_ASSERT_EQUAL(logger.errors(), static_cast(1)); - CPPUNIT_ASSERT(logger.mTreePtr); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] error: test 1:2"), 0); + ASSERT_TRUE(logger.hasError()); + ASSERT_EQ(logger.errors(), static_cast(1)); + ASSERT_TRUE(logger.mTreePtr); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] error: test 1:2"), 0); } logger.clear(); - CPPUNIT_ASSERT(!logger.hasError()); + ASSERT_TRUE(!logger.hasError()); // test add error finds code location even when node is deep copy { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("a;", logger); openvdb::ax::ast::Tree::ConstPtr treeCopy(tree->copy()); const openvdb::ax::ast::Node* local = tree->child(0)->child(0); - CPPUNIT_ASSERT(local); + ASSERT_TRUE(local); const openvdb::ax::ast::Node* localCopy = treeCopy->child(0)->child(0); - CPPUNIT_ASSERT(localCopy); + ASSERT_TRUE(localCopy); // add referring to copy logger.error(message, localCopy); - CPPUNIT_ASSERT(logger.hasError()); - CPPUNIT_ASSERT_EQUAL(logger.errors(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(5)); + ASSERT_TRUE(logger.hasError()); + ASSERT_EQ(logger.errors(), static_cast(1)); + ASSERT_EQ(messages.size(), static_cast(5)); - CPPUNIT_ASSERT(logger.mTreePtr); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] error: test 1:1"), 0); + ASSERT_TRUE(logger.mTreePtr); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] error: test 1:1"), 0); } } -void -TestLogger::testAddWarning() +TEST_F(TestLogger, testAddWarning) { std::vector messages; openvdb::ax::Logger logger([](const std::string&) {}, [&messages](const std::string& message) { messages.emplace_back(message); }); - CPPUNIT_ASSERT(!logger.hasWarning()); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), messages.size()); + ASSERT_TRUE(!logger.hasWarning()); + ASSERT_EQ(logger.warnings(), messages.size()); openvdb::ax::Logger::CodeLocation codeLocation(1,1); std::string message("test"); logger.warning(message, codeLocation); - CPPUNIT_ASSERT(logger.hasWarning()); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] warning: test 1:1"), 0); + ASSERT_TRUE(logger.hasWarning()); + ASSERT_EQ(messages.size(), static_cast(1)); + ASSERT_EQ(logger.warnings(), static_cast(1)); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] warning: test 1:1"), 0); logger.warning(message, codeLocation); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(2)); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), static_cast(2)); + ASSERT_EQ(messages.size(), static_cast(2)); + ASSERT_EQ(logger.warnings(), static_cast(2)); logger.clear(); - CPPUNIT_ASSERT(!logger.hasWarning()); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), static_cast(0)); + ASSERT_TRUE(!logger.hasWarning()); + ASSERT_EQ(logger.warnings(), static_cast(0)); openvdb::ax::ast::Local testLocal("name"); logger.warning(message, &testLocal); - CPPUNIT_ASSERT(logger.hasWarning()); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(3)); + ASSERT_TRUE(logger.hasWarning()); + ASSERT_EQ(logger.warnings(), static_cast(1)); + ASSERT_EQ(messages.size(), static_cast(3)); - CPPUNIT_ASSERT(!logger.mTreePtr); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] warning: test"), 0); + ASSERT_TRUE(!logger.mTreePtr); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] warning: test"), 0); logger.clear(); - CPPUNIT_ASSERT(!logger.hasWarning()); + ASSERT_TRUE(!logger.hasWarning()); // test that add warning finds code location { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(" a;", logger); const openvdb::ax::ast::Node* local = tree->child(0)->child(0); - CPPUNIT_ASSERT(local); + ASSERT_TRUE(local); logger.warning(message, local); - CPPUNIT_ASSERT(logger.hasWarning()); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), static_cast(1)); - CPPUNIT_ASSERT(logger.mTreePtr); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] warning: test 1:2"), 0); + ASSERT_TRUE(logger.hasWarning()); + ASSERT_EQ(logger.warnings(), static_cast(1)); + ASSERT_TRUE(logger.mTreePtr); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] warning: test 1:2"), 0); } logger.clear(); - CPPUNIT_ASSERT(!logger.hasWarning()); + ASSERT_TRUE(!logger.hasWarning()); // test add warning finds code location even when node is deep copy { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("a;", logger); openvdb::ax::ast::Tree::ConstPtr treeCopy(tree->copy()); const openvdb::ax::ast::Node* local = tree->child(0)->child(0); - CPPUNIT_ASSERT(local); + ASSERT_TRUE(local); const openvdb::ax::ast::Node* localCopy = treeCopy->child(0)->child(0); - CPPUNIT_ASSERT(localCopy); + ASSERT_TRUE(localCopy); // add referring to copy logger.warning(message, localCopy); - CPPUNIT_ASSERT(logger.hasWarning()); - CPPUNIT_ASSERT_EQUAL(logger.warnings(), static_cast(1)); - CPPUNIT_ASSERT_EQUAL(messages.size(), static_cast(5)); + ASSERT_TRUE(logger.hasWarning()); + ASSERT_EQ(logger.warnings(), static_cast(1)); + ASSERT_EQ(messages.size(), static_cast(5)); - CPPUNIT_ASSERT(logger.mTreePtr); - CPPUNIT_ASSERT_EQUAL(strcmp(messages.back().c_str(), "[1] warning: test 1:1"), 0); + ASSERT_TRUE(logger.mTreePtr); + ASSERT_EQ(strcmp(messages.back().c_str(), "[1] warning: test 1:1"), 0); } } -void -TestLogger::testWarningsAsErrors() +TEST_F(TestLogger, testWarningsAsErrors) { openvdb::ax::Logger logger([](const std::string&) {}); const std::string message("test"); const openvdb::ax::Logger::CodeLocation location(10,20); logger.setWarningsAsErrors(true); - CPPUNIT_ASSERT(!logger.hasError()); - CPPUNIT_ASSERT(!logger.hasWarning()); + ASSERT_TRUE(!logger.hasError()); + ASSERT_TRUE(!logger.hasWarning()); logger.warning(message, location); - CPPUNIT_ASSERT(logger.hasError()); - CPPUNIT_ASSERT(!logger.hasWarning()); + ASSERT_TRUE(logger.hasError()); + ASSERT_TRUE(!logger.hasWarning()); } -void -TestLogger::testMaxErrors() +TEST_F(TestLogger, testMaxErrors) { openvdb::ax::Logger logger([](const std::string&) {}); const std::string message("test"); const openvdb::ax::Logger::CodeLocation location(10,20); - CPPUNIT_ASSERT(logger.error(message, location)); - CPPUNIT_ASSERT(logger.error(message, location)); - CPPUNIT_ASSERT(logger.error(message, location)); + ASSERT_TRUE(logger.error(message, location)); + ASSERT_TRUE(logger.error(message, location)); + ASSERT_TRUE(logger.error(message, location)); logger.clear(); logger.setMaxErrors(2); - CPPUNIT_ASSERT(logger.error(message, location)); - CPPUNIT_ASSERT(!logger.error(message, location)); - CPPUNIT_ASSERT(!logger.error(message, location)); + ASSERT_TRUE(logger.error(message, location)); + ASSERT_TRUE(!logger.error(message, location)); + ASSERT_TRUE(!logger.error(message, location)); // setMaxErrors doesn't limit the error counter - CPPUNIT_ASSERT_EQUAL(size_t(3), logger.errors()); + ASSERT_EQ(size_t(3), logger.errors()); } +} // namespace ax +} // namespace OPENVDB_VERSION_NAME +} // namespace openvdb From e7d8515afdc6664bd170f3c7dad34414714aca38 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 17:26:47 -0700 Subject: [PATCH 11/21] Convert TestStringIR.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/backend/TestStringIR.cc | 618 +++++++++--------- 1 file changed, 299 insertions(+), 319 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestStringIR.cc b/openvdb_ax/openvdb_ax/test/backend/TestStringIR.cc index 78f29628e3..86eb4b90de 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestStringIR.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestStringIR.cc @@ -10,33 +10,16 @@ #include -#include +#include #include // iota using String = openvdb::ax::codegen::String; -class TestStringIR : public CppUnit::TestCase +class TestStringIR : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestStringIR); - CPPUNIT_TEST(testStringImpl); - CPPUNIT_TEST(testStringStringIR); - CPPUNIT_TEST(testStringAssignIR); - CPPUNIT_TEST(testStringAddIR); - CPPUNIT_TEST(testStringClearIR); - CPPUNIT_TEST_SUITE_END(); - - void testStringImpl(); - void testStringStringIR(); - void testStringAssignIR(); - void testStringAddIR(); - void testStringClearIR(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestStringIR); - template inline std::array fillCharArray(char c) { @@ -55,8 +38,7 @@ inline std::array fillCharArrayIota(char c = char(1)) return arr; } -void -TestStringIR::testStringImpl() +TEST_F(TestStringIR, testStringImpl) { // Test the C++ implementation @@ -65,83 +47,83 @@ TestStringIR::testStringImpl() { String a; const char* c(a); - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); - CPPUNIT_ASSERT_EQUAL(std::string(""), a.str()); + ASSERT_TRUE(a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ('\0', a.c_str()[0]); + ASSERT_EQ(std::string(""), a.str()); } { String a(""); const char* c(a); - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); - CPPUNIT_ASSERT_EQUAL(std::string(""), a.str()); + ASSERT_TRUE(a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ('\0', a.c_str()[0]); + ASSERT_EQ(std::string(""), a.str()); } { auto arr = fillCharArray('0'); String a(arr.data()); const char* c(a); - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH-1), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT(a.c_str() != arr.data()); - CPPUNIT_ASSERT_EQUAL(std::string(arr.data(), String::SSO_LENGTH-1), a.str()); + ASSERT_TRUE(a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH-1), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_TRUE(a.c_str() != arr.data()); + ASSERT_EQ(std::string(arr.data(), String::SSO_LENGTH-1), a.str()); } { auto arr = fillCharArray('0'); String a(arr.data()); const char* c(a); - CPPUNIT_ASSERT(!a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT(a.c_str() != arr.data()); - CPPUNIT_ASSERT_EQUAL(std::string(arr.data(), String::SSO_LENGTH), a.str()); + ASSERT_TRUE(!a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_TRUE(a.c_str() != arr.data()); + ASSERT_EQ(std::string(arr.data(), String::SSO_LENGTH), a.str()); } { const char* arr = "foo"; String a(arr); const char* c(a); - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(3), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT(a.c_str() != arr); - CPPUNIT_ASSERT_EQUAL(std::string(arr), a.str()); + ASSERT_TRUE(a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(3), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_TRUE(a.c_str() != arr); + ASSERT_EQ(std::string(arr), a.str()); } { const std::string s(String::SSO_LENGTH-1, '0'); String a(s); const char* c(a); - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH-1), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT(a.c_str() != s.c_str()); - CPPUNIT_ASSERT_EQUAL(s, a.str()); + ASSERT_TRUE(a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH-1), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_TRUE(a.c_str() != s.c_str()); + ASSERT_EQ(s, a.str()); } { const std::string s(String::SSO_LENGTH, '0'); String a(s); const char* c(a); - CPPUNIT_ASSERT(!a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT(a.c_str() != s.c_str()); - CPPUNIT_ASSERT_EQUAL(s, a.str()); + ASSERT_TRUE(!a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_TRUE(a.c_str() != s.c_str()); + ASSERT_EQ(s, a.str()); } // Copy/Assign @@ -150,16 +132,16 @@ TestStringIR::testStringImpl() String a("foo"); String b(a); const char* c(b); - CPPUNIT_ASSERT(b.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(3), b.size()); - CPPUNIT_ASSERT_EQUAL(c, b.c_str()); - CPPUNIT_ASSERT(b.c_str() != a.c_str()); - CPPUNIT_ASSERT_EQUAL('f', b.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', b.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', b.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', b.c_str()[3]); - CPPUNIT_ASSERT_EQUAL(std::string("foo"), b.str()); + ASSERT_TRUE(b.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(3), b.size()); + ASSERT_EQ(c, b.c_str()); + ASSERT_TRUE(b.c_str() != a.c_str()); + ASSERT_EQ('f', b.c_str()[0]); + ASSERT_EQ('o', b.c_str()[1]); + ASSERT_EQ('o', b.c_str()[2]); + ASSERT_EQ('\0', b.c_str()[3]); + ASSERT_EQ(std::string("foo"), b.str()); } { @@ -167,36 +149,36 @@ TestStringIR::testStringImpl() String a(arr.data()); String b(a); const char* c(b); - CPPUNIT_ASSERT(!b.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), b.size()); - CPPUNIT_ASSERT_EQUAL(c, b.c_str()); - CPPUNIT_ASSERT(b.c_str() != a.c_str()); + ASSERT_TRUE(!b.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH), b.size()); + ASSERT_EQ(c, b.c_str()); + ASSERT_TRUE(b.c_str() != a.c_str()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH); ++i) { - CPPUNIT_ASSERT_EQUAL('a', b.c_str()[i]); + ASSERT_EQ('a', b.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', b.c_str()[int64_t(String::SSO_LENGTH)]); - CPPUNIT_ASSERT_EQUAL(std::string(arr.data(), String::SSO_LENGTH), b.str()); + ASSERT_EQ('\0', b.c_str()[int64_t(String::SSO_LENGTH)]); + ASSERT_EQ(std::string(arr.data(), String::SSO_LENGTH), b.str()); } { auto arr = fillCharArray('a'); String a(arr.data()); String b(""); - CPPUNIT_ASSERT(b.isLocal()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), b.size()); + ASSERT_TRUE(b.isLocal()); + ASSERT_EQ(int64_t(0), b.size()); b = a; const char* c(b); - CPPUNIT_ASSERT(!b.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), b.size()); - CPPUNIT_ASSERT_EQUAL(c, b.c_str()); - CPPUNIT_ASSERT(b.c_str() != a.c_str()); + ASSERT_TRUE(!b.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH), b.size()); + ASSERT_EQ(c, b.c_str()); + ASSERT_TRUE(b.c_str() != a.c_str()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH); ++i) { - CPPUNIT_ASSERT_EQUAL('a', b.c_str()[i]); + ASSERT_EQ('a', b.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', b.c_str()[int64_t(String::SSO_LENGTH)]); - CPPUNIT_ASSERT_EQUAL(std::string(arr.data(), String::SSO_LENGTH), b.str()); + ASSERT_EQ('\0', b.c_str()[int64_t(String::SSO_LENGTH)]); + ASSERT_EQ(std::string(arr.data(), String::SSO_LENGTH), b.str()); } // From std::string @@ -205,14 +187,14 @@ TestStringIR::testStringImpl() String a(""); a = std::string("foo"); const char* c(a); - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(3), a.size()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL('f', a.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', a.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', a.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[3]); + ASSERT_TRUE(a.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(3), a.size()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ('f', a.c_str()[0]); + ASSERT_EQ('o', a.c_str()[1]); + ASSERT_EQ('o', a.c_str()[2]); + ASSERT_EQ('\0', a.c_str()[3]); } { @@ -220,15 +202,15 @@ TestStringIR::testStringImpl() String a(""); a = s; const char* c(a); - CPPUNIT_ASSERT(!a.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT(c != s.c_str()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), a.size()); + ASSERT_TRUE(!a.isLocal()); + ASSERT_TRUE(c); + ASSERT_TRUE(c != s.c_str()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH), a.size()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH); ++i) { - CPPUNIT_ASSERT_EQUAL('a', a.c_str()[i]); + ASSERT_EQ('a', a.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[int64_t(String::SSO_LENGTH)]); + ASSERT_EQ('\0', a.c_str()[int64_t(String::SSO_LENGTH)]); } // Add @@ -236,56 +218,55 @@ TestStringIR::testStringImpl() { String a(""), b(""); a = b + b; - CPPUNIT_ASSERT(a.isLocal()); + ASSERT_TRUE(a.isLocal()); const char* c(a); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT(c != b.c_str()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); + ASSERT_TRUE(c); + ASSERT_TRUE(c != b.c_str()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ('\0', a.c_str()[0]); } { - CPPUNIT_ASSERT(String::SSO_LENGTH >= 2); + ASSERT_TRUE(String::SSO_LENGTH >= 2); auto arr = fillCharArray('a'); String a(""), b1(arr.data()), b2("b"); a = b1 + b2; - CPPUNIT_ASSERT(a.isLocal()); + ASSERT_TRUE(a.isLocal()); const char* c(a); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT(c != b1.c_str()); - CPPUNIT_ASSERT(c != b2.c_str()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH-1), a.size()); + ASSERT_TRUE(c); + ASSERT_TRUE(c != b1.c_str()); + ASSERT_TRUE(c != b2.c_str()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH-1), a.size()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH-2); ++i) { - CPPUNIT_ASSERT_EQUAL('a', a.c_str()[i]); + ASSERT_EQ('a', a.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('b', a.c_str()[int64_t(String::SSO_LENGTH-2)]); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[int64_t(String::SSO_LENGTH-1)]); + ASSERT_EQ('b', a.c_str()[int64_t(String::SSO_LENGTH-2)]); + ASSERT_EQ('\0', a.c_str()[int64_t(String::SSO_LENGTH-1)]); } { - CPPUNIT_ASSERT(String::SSO_LENGTH >= 2); + ASSERT_TRUE(String::SSO_LENGTH >= 2); auto arr = fillCharArray('a'); String a(""), b1(arr.data()), b2("b"); a = b1 + b2; - CPPUNIT_ASSERT(!a.isLocal()); + ASSERT_TRUE(!a.isLocal()); const char* c(a); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT(c != b1.c_str()); - CPPUNIT_ASSERT(c != b2.c_str()); - CPPUNIT_ASSERT_EQUAL(c, a.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), a.size()); + ASSERT_TRUE(c); + ASSERT_TRUE(c != b1.c_str()); + ASSERT_TRUE(c != b2.c_str()); + ASSERT_EQ(c, a.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH), a.size()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH-1); ++i) { - CPPUNIT_ASSERT_EQUAL('a', a.c_str()[i]); + ASSERT_EQ('a', a.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('b', a.c_str()[int64_t(String::SSO_LENGTH-1)]); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[int64_t(String::SSO_LENGTH)]); + ASSERT_EQ('b', a.c_str()[int64_t(String::SSO_LENGTH-1)]); + ASSERT_EQ('\0', a.c_str()[int64_t(String::SSO_LENGTH)]); } } -void -TestStringIR::testStringStringIR() +TEST_F(TestStringIR, testStringStringIR) { static auto setInvalidString = [](String& S) { #if defined(__GNUC__) && !defined(__clang__) @@ -315,37 +296,37 @@ TestStringIR::testStringStringIR() // used as the function addressed wont be linked into the EE. // @todo Expose the global function address binding in Compiler.cc (without // exposing LLVM headers) - CPPUNIT_ASSERT(opts.mPrioritiseIR); + ASSERT_TRUE(opts.mPrioritiseIR); openvdb::ax::codegen::FunctionRegistry::UniquePtr reg = openvdb::ax::codegen::createDefaultRegistry(&opts); // insert all the string::string functions into a module const openvdb::ax::codegen::FunctionGroup* FG = reg->getOrInsert("string::string", opts, true); - CPPUNIT_ASSERT(FG); + ASSERT_TRUE(FG); for (auto& F : FG->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // also insert string::clear for the malloc tests const openvdb::ax::codegen::FunctionGroup* SC = reg->getOrInsert("string::clear", opts, true); - CPPUNIT_ASSERT(SC); + ASSERT_TRUE(SC); for (auto& F : SC->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // JIT gen the functions auto EE = state.EE(); - CPPUNIT_ASSERT(EE); + ASSERT_TRUE(EE); // get the string::clear function for later - CPPUNIT_ASSERT(!SC->list().empty()); + ASSERT_TRUE(!SC->list().empty()); const int64_t addressOfClear = EE->getFunctionAddress(SC->list()[0]->symbol()); - CPPUNIT_ASSERT(addressOfClear); + ASSERT_TRUE(addressOfClear); auto freeString = reinterpret_cast::type>(addressOfClear); @@ -357,33 +338,33 @@ TestStringIR::testStringStringIR() // Test string::string - CPPUNIT_ASSERT_EQUAL(size_t(2), FG->list().size()); // expects 2 signatures + ASSERT_EQ(size_t(2), FG->list().size()); // expects 2 signatures // init string to default address = EE->getFunctionAddress(FG->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); { auto F = reinterpret_cast::type>(address); - CPPUNIT_ASSERT(F); + ASSERT_TRUE(F); /// @note the IR version of string::string should handle the case where /// the string memory is completely uninitialized String input; setInvalidString(input); // uninit string, invalid class memory F(&input); // run function - CPPUNIT_ASSERT(input.isLocal()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), input.size()); - CPPUNIT_ASSERT_EQUAL('\0', input.c_str()[0]); + ASSERT_TRUE(input.isLocal()); + ASSERT_EQ(int64_t(0), input.size()); + ASSERT_EQ('\0', input.c_str()[0]); } // init string from char* address = EE->getFunctionAddress(FG->list()[1]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); { // This test requires SSO_LENGTH > 2 - CPPUNIT_ASSERT(String::SSO_LENGTH >= 2); + ASSERT_TRUE(String::SSO_LENGTH >= 2); auto F = reinterpret_cast::type>(address); - CPPUNIT_ASSERT(F); + ASSERT_TRUE(F); // test to SSO storage { @@ -393,20 +374,20 @@ TestStringIR::testStringStringIR() setInvalidString(input); // uninit string, invalid class memory auto arr = fillCharArrayIota(); const char* data = arr.data(); - CPPUNIT_ASSERT_EQUAL(std::size_t(String::SSO_LENGTH-1), std::strlen(data)); + ASSERT_EQ(std::size_t(String::SSO_LENGTH-1), std::strlen(data)); F(&input, data); // run function const char* c(input); - CPPUNIT_ASSERT(input.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH-1), input.size()); - CPPUNIT_ASSERT_EQUAL(c, input.c_str()); - CPPUNIT_ASSERT(input.c_str() != data); + ASSERT_TRUE(input.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH-1), input.size()); + ASSERT_EQ(c, input.c_str()); + ASSERT_TRUE(input.c_str() != data); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH-1); ++i) { - CPPUNIT_ASSERT_EQUAL(char(i+1), input.c_str()[i]); + ASSERT_EQ(char(i+1), input.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', input.c_str()[String::SSO_LENGTH-1]); + ASSERT_EQ('\0', input.c_str()[String::SSO_LENGTH-1]); } // test malloc @@ -422,20 +403,20 @@ TestStringIR::testStringStringIR() setInvalidString(input); // uninit string, invalid class memory auto arr = fillCharArrayIota(); const char* data = arr.data(); - CPPUNIT_ASSERT_EQUAL(std::size_t(String::SSO_LENGTH), std::strlen(data)); + ASSERT_EQ(std::size_t(String::SSO_LENGTH), std::strlen(data)); F(&input, data); // run function const char* c(input); - CPPUNIT_ASSERT(!input.isLocal()); - CPPUNIT_ASSERT(c); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), input.size()); - CPPUNIT_ASSERT_EQUAL(c, input.c_str()); - CPPUNIT_ASSERT(input.c_str() != data); + ASSERT_TRUE(!input.isLocal()); + ASSERT_TRUE(c); + ASSERT_EQ(int64_t(String::SSO_LENGTH), input.size()); + ASSERT_EQ(c, input.c_str()); + ASSERT_TRUE(input.c_str() != data); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH); ++i) { - CPPUNIT_ASSERT_EQUAL(char(i+1), input.c_str()[i]); + ASSERT_EQ(char(i+1), input.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', input.c_str()[String::SSO_LENGTH]); + ASSERT_EQ('\0', input.c_str()[String::SSO_LENGTH]); // free through string::clear freeString(&input); @@ -444,8 +425,7 @@ TestStringIR::testStringStringIR() } -void -TestStringIR::testStringAssignIR() +TEST_F(TestStringIR, testStringAssignIR) { // Test the String IR in StringFunctions.cc @@ -456,37 +436,37 @@ TestStringIR::testStringAssignIR() // used as the function addressed wont be linked into the EE. // @todo Expose the global function address binding in Compiler.cc (without // exposing LLVM headers) - CPPUNIT_ASSERT(opts.mPrioritiseIR); + ASSERT_TRUE(opts.mPrioritiseIR); openvdb::ax::codegen::FunctionRegistry::UniquePtr reg = openvdb::ax::codegen::createDefaultRegistry(&opts); // insert all the string::op= functions into a module const openvdb::ax::codegen::FunctionGroup* FG = reg->getOrInsert("string::op=", opts, true); - CPPUNIT_ASSERT(FG); + ASSERT_TRUE(FG); for (auto& F : FG->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // also insert string::clear for the malloc tests const openvdb::ax::codegen::FunctionGroup* SC = reg->getOrInsert("string::clear", opts, true); - CPPUNIT_ASSERT(SC); + ASSERT_TRUE(SC); for (auto& F : SC->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // JIT gen the functions auto EE = state.EE(); - CPPUNIT_ASSERT(EE); + ASSERT_TRUE(EE); // get the string::clear function for later - CPPUNIT_ASSERT(!SC->list().empty()); + ASSERT_TRUE(!SC->list().empty()); const int64_t addressOfClear = EE->getFunctionAddress(SC->list()[0]->symbol()); - CPPUNIT_ASSERT(addressOfClear); + ASSERT_TRUE(addressOfClear); auto freeString = reinterpret_cast::type>(addressOfClear); @@ -495,34 +475,34 @@ TestStringIR::testStringAssignIR() // Test string::op= - CPPUNIT_ASSERT_EQUAL(size_t(1), FG->list().size()); // expects 1 signature + ASSERT_EQ(size_t(1), FG->list().size()); // expects 1 signature const int64_t address = EE->getFunctionAddress(FG->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); auto F = reinterpret_cast::type>(address); - CPPUNIT_ASSERT(F); + ASSERT_TRUE(F); // copy from null string { String dest("foo"), src(""); F(&dest, &src); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != src.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), dest.size()); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[0]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != src.c_str()); + ASSERT_EQ(int64_t(0), dest.size()); + ASSERT_EQ('\0', dest.c_str()[0]); } // copy to null string { String dest(""), src("foo"); F(&dest, &src); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != src.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(3), dest.size()); - CPPUNIT_ASSERT_EQUAL('f', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[3]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != src.c_str()); + ASSERT_EQ(int64_t(3), dest.size()); + ASSERT_EQ('f', dest.c_str()[0]); + ASSERT_EQ('o', dest.c_str()[1]); + ASSERT_EQ('o', dest.c_str()[2]); + ASSERT_EQ('\0', dest.c_str()[3]); } @@ -530,13 +510,13 @@ TestStringIR::testStringAssignIR() { String dest("bar"), src("foo"); F(&dest, &src); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != src.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(3), dest.size()); - CPPUNIT_ASSERT_EQUAL('f', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[3]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != src.c_str()); + ASSERT_EQ(int64_t(3), dest.size()); + ASSERT_EQ('f', dest.c_str()[0]); + ASSERT_EQ('o', dest.c_str()[1]); + ASSERT_EQ('o', dest.c_str()[2]); + ASSERT_EQ('\0', dest.c_str()[3]); } // copy to malloced @@ -548,17 +528,17 @@ TestStringIR::testStringAssignIR() { auto arr = fillCharArrayIota(); String dest(arr.data()), src("foo"); - CPPUNIT_ASSERT(!dest.isLocal()); - CPPUNIT_ASSERT(src.isLocal()); + ASSERT_TRUE(!dest.isLocal()); + ASSERT_TRUE(src.isLocal()); F(&dest, &src); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != src.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(3), dest.size()); - CPPUNIT_ASSERT_EQUAL('f', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[3]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != src.c_str()); + ASSERT_EQ(int64_t(3), dest.size()); + ASSERT_EQ('f', dest.c_str()[0]); + ASSERT_EQ('o', dest.c_str()[1]); + ASSERT_EQ('o', dest.c_str()[2]); + ASSERT_EQ('\0', dest.c_str()[3]); } */ @@ -571,17 +551,17 @@ TestStringIR::testStringAssignIR() { auto arr = fillCharArrayIota(); String dest("foo"), src(arr.data()); - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(!src.isLocal()); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(!src.isLocal()); F(&dest, &src); // run function - CPPUNIT_ASSERT(!dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != src.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH), dest.size()); + ASSERT_TRUE(!dest.isLocal()); + ASSERT_TRUE(dest.c_str() != src.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH), dest.size()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH-1); ++i) { - CPPUNIT_ASSERT_EQUAL(char(i+1), dest.c_str()[i]); + ASSERT_EQ(char(i+1), dest.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[int64_t(String::SSO_LENGTH)]); + ASSERT_EQ('\0', dest.c_str()[int64_t(String::SSO_LENGTH)]); // free through string::clear freeString(&dest); @@ -589,7 +569,7 @@ TestStringIR::testStringAssignIR() } -void TestStringIR::testStringAddIR() +TEST_F(TestStringIR, testStringAddIR) { // Test the String IR in StringFunctions.cc @@ -602,30 +582,30 @@ void TestStringIR::testStringAddIR() // insert all the string::op+ functions into a module const openvdb::ax::codegen::FunctionGroup* FG = reg->getOrInsert("string::op+", opts, true); - CPPUNIT_ASSERT(FG); + ASSERT_TRUE(FG); for (auto& F : FG->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // also insert string::clear for the malloc tests const openvdb::ax::codegen::FunctionGroup* SC = reg->getOrInsert("string::clear", opts, true); - CPPUNIT_ASSERT(SC); + ASSERT_TRUE(SC); for (auto& F : SC->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // JIT gen the functions auto EE = state.EE(); - CPPUNIT_ASSERT(EE); + ASSERT_TRUE(EE); // get the string::clear function for later - CPPUNIT_ASSERT(!SC->list().empty()); + ASSERT_TRUE(!SC->list().empty()); const int64_t addressOfClear = EE->getFunctionAddress(SC->list()[0]->symbol()); - CPPUNIT_ASSERT(addressOfClear); + ASSERT_TRUE(addressOfClear); auto freeString = reinterpret_cast::type>(addressOfClear); @@ -636,70 +616,70 @@ void TestStringIR::testStringAddIR() // @note the binary ad op sets the first argument which it expects to // already be initialized correctly. - CPPUNIT_ASSERT_EQUAL(size_t(1), FG->list().size()); // expects 1 signature + ASSERT_EQ(size_t(1), FG->list().size()); // expects 1 signature const int64_t address = EE->getFunctionAddress(FG->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); auto F = reinterpret_cast::type>(address); - CPPUNIT_ASSERT(F); + ASSERT_TRUE(F); // add from null strings { String dest("foo"), rhs(""), lhs(""); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), dest.size()); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[0]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(0), dest.size()); + ASSERT_EQ('\0', dest.c_str()[0]); } // add from lhs null string { String dest(""), lhs(""), rhs("foo"); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(3), dest.size()); - CPPUNIT_ASSERT_EQUAL('f', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[3]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(3), dest.size()); + ASSERT_EQ('f', dest.c_str()[0]); + ASSERT_EQ('o', dest.c_str()[1]); + ASSERT_EQ('o', dest.c_str()[2]); + ASSERT_EQ('\0', dest.c_str()[3]); } // add from rhs null string { String dest(""), lhs("foo"), rhs(""); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(3), dest.size()); - CPPUNIT_ASSERT_EQUAL('f', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[3]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(3), dest.size()); + ASSERT_EQ('f', dest.c_str()[0]); + ASSERT_EQ('o', dest.c_str()[1]); + ASSERT_EQ('o', dest.c_str()[2]); + ASSERT_EQ('\0', dest.c_str()[3]); } // add from both local strings { String dest(""), lhs("foo"), rhs(" bar"); - CPPUNIT_ASSERT(lhs.isLocal()); - CPPUNIT_ASSERT(rhs.isLocal()); + ASSERT_TRUE(lhs.isLocal()); + ASSERT_TRUE(rhs.isLocal()); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(7), dest.size()); - CPPUNIT_ASSERT_EQUAL('f', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('o', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL(' ', dest.c_str()[3]); - CPPUNIT_ASSERT_EQUAL('b', dest.c_str()[4]); - CPPUNIT_ASSERT_EQUAL('a', dest.c_str()[5]); - CPPUNIT_ASSERT_EQUAL('r', dest.c_str()[6]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[7]); + ASSERT_TRUE(dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(7), dest.size()); + ASSERT_EQ('f', dest.c_str()[0]); + ASSERT_EQ('o', dest.c_str()[1]); + ASSERT_EQ('o', dest.c_str()[2]); + ASSERT_EQ(' ', dest.c_str()[3]); + ASSERT_EQ('b', dest.c_str()[4]); + ASSERT_EQ('a', dest.c_str()[5]); + ASSERT_EQ('r', dest.c_str()[6]); + ASSERT_EQ('\0', dest.c_str()[7]); } // add from local rhs, malloced lhs @@ -710,22 +690,22 @@ void TestStringIR::testStringAddIR() { auto arr = fillCharArrayIota(); String dest(""), lhs(arr.data()), rhs(" bar"); - CPPUNIT_ASSERT(!lhs.isLocal()); - CPPUNIT_ASSERT(rhs.isLocal()); + ASSERT_TRUE(!lhs.isLocal()); + ASSERT_TRUE(rhs.isLocal()); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(!dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH+4), dest.size()); + ASSERT_TRUE(!dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH+4), dest.size()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH-1); ++i) { - CPPUNIT_ASSERT_EQUAL(char(i+1), dest.c_str()[i]); + ASSERT_EQ(char(i+1), dest.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL(' ', dest.c_str()[int64_t(String::SSO_LENGTH+0)]); - CPPUNIT_ASSERT_EQUAL('b', dest.c_str()[int64_t(String::SSO_LENGTH+1)]); - CPPUNIT_ASSERT_EQUAL('a', dest.c_str()[int64_t(String::SSO_LENGTH+2)]); - CPPUNIT_ASSERT_EQUAL('r', dest.c_str()[int64_t(String::SSO_LENGTH+3)]); - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[int64_t(String::SSO_LENGTH+4)]); + ASSERT_EQ(' ', dest.c_str()[int64_t(String::SSO_LENGTH+0)]); + ASSERT_EQ('b', dest.c_str()[int64_t(String::SSO_LENGTH+1)]); + ASSERT_EQ('a', dest.c_str()[int64_t(String::SSO_LENGTH+2)]); + ASSERT_EQ('r', dest.c_str()[int64_t(String::SSO_LENGTH+3)]); + ASSERT_EQ('\0', dest.c_str()[int64_t(String::SSO_LENGTH+4)]); // free through string::clear freeString(&dest); } @@ -738,23 +718,23 @@ void TestStringIR::testStringAddIR() { auto arr = fillCharArrayIota(); String dest(""), lhs(" bar"), rhs(arr.data()); - CPPUNIT_ASSERT(lhs.isLocal()); - CPPUNIT_ASSERT(!rhs.isLocal()); + ASSERT_TRUE(lhs.isLocal()); + ASSERT_TRUE(!rhs.isLocal()); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(!dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH+4), dest.size()); - - CPPUNIT_ASSERT_EQUAL(' ', dest.c_str()[0]); - CPPUNIT_ASSERT_EQUAL('b', dest.c_str()[1]); - CPPUNIT_ASSERT_EQUAL('a', dest.c_str()[2]); - CPPUNIT_ASSERT_EQUAL('r', dest.c_str()[3]); + ASSERT_TRUE(!dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH+4), dest.size()); + + ASSERT_EQ(' ', dest.c_str()[0]); + ASSERT_EQ('b', dest.c_str()[1]); + ASSERT_EQ('a', dest.c_str()[2]); + ASSERT_EQ('r', dest.c_str()[3]); for (int64_t i = 4; i < int64_t(String::SSO_LENGTH+4); ++i) { - CPPUNIT_ASSERT_EQUAL(char(i-3), dest.c_str()[i]); // i=3 as we start iterating at 4 + ASSERT_EQ(char(i-3), dest.c_str()[i]); // i=3 as we start iterating at 4 } - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[int64_t(String::SSO_LENGTH+4)]); + ASSERT_EQ('\0', dest.c_str()[int64_t(String::SSO_LENGTH+4)]); // free through string::clear freeString(&dest); } @@ -769,29 +749,29 @@ void TestStringIR::testStringAddIR() auto arr2 = fillCharArrayIota(char(1+String::SSO_LENGTH)); String lhs(arr1.data()); String rhs(arr2.data()); - CPPUNIT_ASSERT(!lhs.isLocal()); - CPPUNIT_ASSERT(!rhs.isLocal()); + ASSERT_TRUE(!lhs.isLocal()); + ASSERT_TRUE(!rhs.isLocal()); arr1.fill('0'); arr2.fill('0'); String dest(""); F(&dest, &lhs, &rhs); // run function - CPPUNIT_ASSERT(!dest.isLocal()); - CPPUNIT_ASSERT(dest.c_str() != rhs.c_str()); - CPPUNIT_ASSERT(dest.c_str() != lhs.c_str()); - CPPUNIT_ASSERT_EQUAL(int64_t(String::SSO_LENGTH*2), dest.size()); + ASSERT_TRUE(!dest.isLocal()); + ASSERT_TRUE(dest.c_str() != rhs.c_str()); + ASSERT_TRUE(dest.c_str() != lhs.c_str()); + ASSERT_EQ(int64_t(String::SSO_LENGTH*2), dest.size()); for (int64_t i = 0; i < int64_t(String::SSO_LENGTH*2); ++i) { - CPPUNIT_ASSERT_EQUAL(char(i+1), dest.c_str()[i]); + ASSERT_EQ(char(i+1), dest.c_str()[i]); } - CPPUNIT_ASSERT_EQUAL('\0', dest.c_str()[int64_t(String::SSO_LENGTH*2)]); + ASSERT_EQ('\0', dest.c_str()[int64_t(String::SSO_LENGTH*2)]); // free through string::clear freeString(&dest); } } -void TestStringIR::testStringClearIR() +TEST_F(TestStringIR, testStringClearIR) { // Test the String IR in StringFunctions.cc @@ -804,55 +784,55 @@ void TestStringIR::testStringClearIR() // insert all the string::clear functions into a module const openvdb::ax::codegen::FunctionGroup* FG = reg->getOrInsert("string::clear", opts, true); - CPPUNIT_ASSERT(FG); + ASSERT_TRUE(FG); for (auto& F : FG->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // insert all the string::string functions into a module // for the malloc clear tests const openvdb::ax::codegen::FunctionGroup* MFG = reg->getOrInsert("string::string", opts, true); - CPPUNIT_ASSERT(MFG); + ASSERT_TRUE(MFG); for (auto& F : MFG->list()) { llvm::Function* LF = F->create(M); - CPPUNIT_ASSERT(LF); + ASSERT_TRUE(LF); } // JIT gen the functions auto EE = state.EE(); - CPPUNIT_ASSERT(EE); + ASSERT_TRUE(EE); // Test the IR for each string function. These match the signatures // defined in StringFunctions.cc // Test string::clear - CPPUNIT_ASSERT_EQUAL(size_t(1), FG->list().size()); // expects 1 signature + ASSERT_EQ(size_t(1), FG->list().size()); // expects 1 signature const int64_t address = EE->getFunctionAddress(FG->list()[0]->symbol()); - CPPUNIT_ASSERT(address); + ASSERT_TRUE(address); auto F = reinterpret_cast::type>(address); - CPPUNIT_ASSERT(F); + ASSERT_TRUE(F); // clear empty { String a; F(&a); // run function - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); + ASSERT_TRUE(a.isLocal()); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ('\0', a.c_str()[0]); } // clear local { String a("foo"); - CPPUNIT_ASSERT(a.isLocal()); + ASSERT_TRUE(a.isLocal()); F(&a); // run function - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); + ASSERT_TRUE(a.isLocal()); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ('\0', a.c_str()[0]); } // clear malloced @@ -864,11 +844,11 @@ void TestStringIR::testStringClearIR() { auto arr = fillCharArray('0'); String a(arr.data()); - CPPUNIT_ASSERT(!a.isLocal()); + ASSERT_TRUE(!a.isLocal()); F(&a); // run function - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); + ASSERT_TRUE(a.isLocal()); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ('\0', a.c_str()[0]); } */ @@ -878,10 +858,10 @@ void TestStringIR::testStringClearIR() // LLVM binding then free. { // get the string::clear function which takes a char* initializer - CPPUNIT_ASSERT(!MFG->list().empty()); + ASSERT_TRUE(!MFG->list().empty()); const int64_t addressOfStringCtr = EE->getFunctionAddress(MFG->list()[1]->symbol()); - CPPUNIT_ASSERT(addressOfStringCtr); + ASSERT_TRUE(addressOfStringCtr); auto createString = reinterpret_cast::type>(addressOfStringCtr); @@ -889,10 +869,10 @@ void TestStringIR::testStringClearIR() String a; createString(&a, arr.data()); - CPPUNIT_ASSERT(!a.isLocal()); + ASSERT_TRUE(!a.isLocal()); F(&a); // run function - CPPUNIT_ASSERT(a.isLocal()); - CPPUNIT_ASSERT_EQUAL(int64_t(0), a.size()); - CPPUNIT_ASSERT_EQUAL('\0', a.c_str()[0]); + ASSERT_TRUE(a.isLocal()); + ASSERT_EQ(int64_t(0), a.size()); + ASSERT_EQ('\0', a.c_str()[0]); } } From f27fcf9edf7a3a0a6df376041a439d45861f59f2 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 17:35:20 -0700 Subject: [PATCH 12/21] Convert TestSymbolTable.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../test/backend/TestSymbolTable.cc | 107 ++++++++---------- 1 file changed, 47 insertions(+), 60 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestSymbolTable.cc b/openvdb_ax/openvdb_ax/test/backend/TestSymbolTable.cc index 062fe89937..1cbfde65a7 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestSymbolTable.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestSymbolTable.cc @@ -5,28 +5,16 @@ #include -#include +#include template using LLVMType = openvdb::ax::codegen::LLVMType; -class TestSymbolTable : public CppUnit::TestCase +class TestSymbolTable : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestSymbolTable); - CPPUNIT_TEST(testSingleTable); - CPPUNIT_TEST(testTableBlocks); - CPPUNIT_TEST_SUITE_END(); - - void testSingleTable(); - void testTableBlocks(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestSymbolTable); - -void -TestSymbolTable::testSingleTable() +TEST_F(TestSymbolTable, testSingleTable) { unittest_util::LLVMState state; llvm::IRBuilder<> builder(state.scratchBlock()); @@ -35,34 +23,33 @@ TestSymbolTable::testSingleTable() llvm::Value* value1 = builder.CreateAlloca(type); llvm::Value* value2 = builder.CreateAlloca(type); - CPPUNIT_ASSERT(value1); - CPPUNIT_ASSERT(value2); + ASSERT_TRUE(value1); + ASSERT_TRUE(value2); openvdb::ax::codegen::SymbolTable table; - CPPUNIT_ASSERT(table.map().empty()); + ASSERT_TRUE(table.map().empty()); - CPPUNIT_ASSERT(table.insert("test", value1)); - CPPUNIT_ASSERT(!table.insert("test", nullptr)); - CPPUNIT_ASSERT(table.exists("test")); - CPPUNIT_ASSERT_EQUAL(value1, table.get("test")); + ASSERT_TRUE(table.insert("test", value1)); + ASSERT_TRUE(!table.insert("test", nullptr)); + ASSERT_TRUE(table.exists("test")); + ASSERT_EQ(value1, table.get("test")); table.clear(); - CPPUNIT_ASSERT(table.map().empty()); - CPPUNIT_ASSERT(!table.exists("test")); + ASSERT_TRUE(table.map().empty()); + ASSERT_TRUE(!table.exists("test")); - CPPUNIT_ASSERT(table.insert("test", value1)); - CPPUNIT_ASSERT(table.replace("test", value2)); - CPPUNIT_ASSERT(!table.replace("other", value2)); + ASSERT_TRUE(table.insert("test", value1)); + ASSERT_TRUE(table.replace("test", value2)); + ASSERT_TRUE(!table.replace("other", value2)); - CPPUNIT_ASSERT(table.exists("test")); - CPPUNIT_ASSERT(table.exists("other")); + ASSERT_TRUE(table.exists("test")); + ASSERT_TRUE(table.exists("other")); - CPPUNIT_ASSERT_EQUAL(value2, table.get("test")); - CPPUNIT_ASSERT_EQUAL(value2, table.get("other")); + ASSERT_EQ(value2, table.get("test")); + ASSERT_EQ(value2, table.get("other")); } -void -TestSymbolTable::testTableBlocks() +TEST_F(TestSymbolTable, testTableBlocks) { unittest_util::LLVMState state; llvm::IRBuilder<> builder(state.scratchBlock()); @@ -73,31 +60,31 @@ TestSymbolTable::testTableBlocks() llvm::Value* value2 = builder.CreateAlloca(type); llvm::Value* value3 = builder.CreateAlloca(type); llvm::Value* value4 = builder.CreateAlloca(type); - CPPUNIT_ASSERT(value1); - CPPUNIT_ASSERT(value2); - CPPUNIT_ASSERT(value3); - CPPUNIT_ASSERT(value4); + ASSERT_TRUE(value1); + ASSERT_TRUE(value2); + ASSERT_TRUE(value3); + ASSERT_TRUE(value4); // test table insertion and erase openvdb::ax::codegen::SymbolTableBlocks tables; openvdb::ax::codegen::SymbolTable* table1 = &(tables.globals()); openvdb::ax::codegen::SymbolTable* table2 = tables.getOrInsert(0); - CPPUNIT_ASSERT_EQUAL(table1, table2); + ASSERT_EQ(table1, table2); table2 = tables.get(0); - CPPUNIT_ASSERT_EQUAL(table1, table2); + ASSERT_EQ(table1, table2); - CPPUNIT_ASSERT_THROW(tables.erase(0), std::runtime_error); + ASSERT_THROW(tables.erase(0), std::runtime_error); tables.getOrInsert(1); tables.getOrInsert(2); tables.getOrInsert(4); - CPPUNIT_ASSERT(tables.get(3) == nullptr); - CPPUNIT_ASSERT(tables.erase(4)); - CPPUNIT_ASSERT(tables.erase(2)); - CPPUNIT_ASSERT(tables.erase(1)); + ASSERT_TRUE(tables.get(3) == nullptr); + ASSERT_TRUE(tables.erase(4)); + ASSERT_TRUE(tables.erase(2)); + ASSERT_TRUE(tables.erase(1)); tables.globals().insert("global1", value1); tables.globals().insert("global2", value2); @@ -105,9 +92,9 @@ TestSymbolTable::testTableBlocks() // test find methods llvm::Value* result = tables.find("global1"); - CPPUNIT_ASSERT_EQUAL(value1, result); + ASSERT_EQ(value1, result); result = tables.find("global2"); - CPPUNIT_ASSERT_EQUAL(value2, result); + ASSERT_EQ(value2, result); table1 = tables.getOrInsert(2); table2 = tables.getOrInsert(4); @@ -121,48 +108,48 @@ TestSymbolTable::testTableBlocks() // test find second nested value result = tables.find("table_level_2", 0); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(!result); result = tables.find("table_level_2", 1); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(!result); result = tables.find("table_level_2", 2); - CPPUNIT_ASSERT_EQUAL(value3, result); + ASSERT_EQ(value3, result); // test find fourth nested value result = tables.find("table_level_4", 0); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(!result); result = tables.find("table_level_4", 3); - CPPUNIT_ASSERT(!result); + ASSERT_TRUE(!result); result = tables.find("table_level_4", 4); - CPPUNIT_ASSERT_EQUAL(value4, result); + ASSERT_EQ(value4, result); result = tables.find("table_level_4", 10000); - CPPUNIT_ASSERT_EQUAL(value4, result); + ASSERT_EQ(value4, result); // test find fourth nested value with matching global name tables.globals().insert("table_level_4", value1); result = tables.find("table_level_4"); - CPPUNIT_ASSERT_EQUAL(value4, result); + ASSERT_EQ(value4, result); result = tables.find("table_level_4", 4); - CPPUNIT_ASSERT_EQUAL(value4, result); + ASSERT_EQ(value4, result); result = tables.find("table_level_4", 3); - CPPUNIT_ASSERT_EQUAL(value1, result); + ASSERT_EQ(value1, result); // test replace - CPPUNIT_ASSERT(tables.replace("table_level_4", value2)); + ASSERT_TRUE(tables.replace("table_level_4", value2)); result = tables.find("table_level_4"); - CPPUNIT_ASSERT_EQUAL(value2, result); + ASSERT_EQ(value2, result); // test global was not replaced result = tables.find("table_level_4", 0); - CPPUNIT_ASSERT_EQUAL(value1, result); + ASSERT_EQ(value1, result); - CPPUNIT_ASSERT(!tables.replace("empty", nullptr)); + ASSERT_TRUE(!tables.replace("empty", nullptr)); } From 883727aaeed51c4e6a79ed78bd42da36093cce5f Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 17:39:11 -0700 Subject: [PATCH 13/21] Convert TestTypes.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/backend/TestTypes.cc | 124 ++++++++---------- 1 file changed, 54 insertions(+), 70 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/backend/TestTypes.cc b/openvdb_ax/openvdb_ax/test/backend/TestTypes.cc index c37217d66d..fe44355699 100644 --- a/openvdb_ax/openvdb_ax/test/backend/TestTypes.cc +++ b/openvdb_ax/openvdb_ax/test/backend/TestTypes.cc @@ -12,27 +12,13 @@ #include #include -#include +#include -class TestTypes : public CppUnit::TestCase +class TestTypes : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestTypes); - CPPUNIT_TEST(testTypes); - CPPUNIT_TEST(testVDBTypes); - CPPUNIT_TEST(testString); - CPPUNIT_TEST_SUITE_END(); - - void testTypes(); - void testVDBTypes(); - void testString(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestTypes); - -void -TestTypes::testTypes() +TEST_F(TestTypes, testTypes) { using openvdb::ax::codegen::LLVMType; @@ -41,127 +27,125 @@ TestTypes::testTypes() // scalar types - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getInt1Ty(C)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getInt8Ty(C)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getInt16Ty(C)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getInt32Ty(C)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getInt64Ty(C)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getFloatTy(C)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getDoubleTy(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getInt1Ty(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getInt8Ty(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getInt16Ty(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getInt32Ty(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getInt64Ty(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getFloatTy(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getDoubleTy(C)), LLVMType::get(C)); // scalar values - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt1Ty(C), true)), + ASSERT_EQ(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt1Ty(C), true)), LLVMType::get(C, true)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt8Ty(C), int8_t(1))), + ASSERT_EQ(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt8Ty(C), int8_t(1))), LLVMType::get(C, int8_t(1))); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt16Ty(C), int16_t(2))), + ASSERT_EQ(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt16Ty(C), int16_t(2))), LLVMType::get(C, int16_t(2))); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt32Ty(C), int32_t(3))), + ASSERT_EQ(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt32Ty(C), int32_t(3))), LLVMType::get(C, int32_t(3))); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt64Ty(C), int64_t(4))), + ASSERT_EQ(llvm::cast(llvm::ConstantInt::get(llvm::Type::getInt64Ty(C), int64_t(4))), LLVMType::get(C, int64_t(4))); // array types #if LLVM_VERSION_MAJOR > 6 - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt1Ty(C), 1)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt1Ty(C), 1)), LLVMType::get(C)); #endif - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt8Ty(C), 2)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt8Ty(C), 2)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt16Ty(C), 3)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt16Ty(C), 3)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt64Ty(C), 5)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt64Ty(C), 5)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 6)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 6)), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 7)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 7)), LLVMType::get(C)); // array values #if LLVM_VERSION_MAJOR > 6 - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, {true})), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, {true})), LLVMType::get(C, {true})); #endif const std::vector veci8{1,2}; - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, veci8)), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, veci8)), LLVMType::get(C, {1,2})); const std::vector veci16{1,2,3}; - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, veci16)), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, veci16)), LLVMType::get(C, {1,2,3})); const std::vector veci32{1,2,3,4}; - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, veci32)), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, veci32)), LLVMType::get(C, {1,2,3,4})); const std::vector veci64{1,2,3,4,5}; - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, veci64)), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, veci64)), LLVMType::get(C, {1,2,3,4,5})); const std::vector vecf{.0f,.1f,.2f,.3f,.4f,.5f}; - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, vecf)), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, vecf)), LLVMType::get(C, {.0f,.1f,.2f,.3f,.4f,.5f})); const std::vector vecd{.0,.1,.2,.3,.4,.5,.6}; - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ConstantDataArray::get(C, vecd)), + ASSERT_EQ(llvm::cast(llvm::ConstantDataArray::get(C, vecd)), LLVMType::get(C, {.0,.1,.2,.3,.4,.5,.6})); // void - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getVoidTy(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getVoidTy(C)), LLVMType::get(C)); // some special cases we alias - CPPUNIT_ASSERT_EQUAL(llvm::Type::getInt8PtrTy(C), LLVMType::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::Type::getInt8Ty(C)), LLVMType::get(C)); + ASSERT_EQ(llvm::Type::getInt8PtrTy(C), LLVMType::get(C)); + ASSERT_EQ(llvm::cast(llvm::Type::getInt8Ty(C)), LLVMType::get(C)); } -void -TestTypes::testVDBTypes() +TEST_F(TestTypes, testVDBTypes) { using openvdb::ax::codegen::LLVMType; unittest_util::LLVMState state; llvm::LLVMContext& C = state.context(); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 2)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 2)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 2)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 2)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 3)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 3)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 3)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 3)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getInt32Ty(C), 4)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 4)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 4)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 4)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 4)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 9)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 9)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 9)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 9)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 16)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getFloatTy(C), 16)), LLVMType>::get(C)); - CPPUNIT_ASSERT_EQUAL(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 16)), + ASSERT_EQ(llvm::cast(llvm::ArrayType::get(llvm::Type::getDoubleTy(C), 16)), LLVMType>::get(C)); } -void -TestTypes::testString() +TEST_F(TestTypes, testString) { using openvdb::ax::codegen::LLVMType; @@ -169,13 +153,13 @@ TestTypes::testString() llvm::LLVMContext& C = state.context(); llvm::Type* type = LLVMType::get(C); - CPPUNIT_ASSERT(type->isAggregateType()); - CPPUNIT_ASSERT_EQUAL(llvm::Type::StructTyID, type->getTypeID()); - CPPUNIT_ASSERT_EQUAL(unsigned(3), type->getNumContainedTypes()); // char*, SSO, len - CPPUNIT_ASSERT_EQUAL(unsigned(3), type->getStructNumElements()); // char*, SSO, len + ASSERT_TRUE(type->isAggregateType()); + ASSERT_EQ(llvm::Type::StructTyID, type->getTypeID()); + ASSERT_EQ(unsigned(3), type->getNumContainedTypes()); // char*, SSO, len + ASSERT_EQ(unsigned(3), type->getStructNumElements()); // char*, SSO, len // Check members - CPPUNIT_ASSERT_EQUAL((llvm::Type*)LLVMType::get(C), type->getContainedType(0)); - CPPUNIT_ASSERT_EQUAL(LLVMType::get(C), type->getContainedType(1)); - CPPUNIT_ASSERT_EQUAL(LLVMType::get(C), type->getContainedType(2)); + ASSERT_EQ((llvm::Type*)LLVMType::get(C), type->getContainedType(0)); + ASSERT_EQ(LLVMType::get(C), type->getContainedType(1)); + ASSERT_EQ(LLVMType::get(C), type->getContainedType(2)); } From f668ee2e7e9e17ebf32d4e5166deab4673329986 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 18:22:28 -0700 Subject: [PATCH 14/21] Convert TestAXRun.cc from cppunit to gtest Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/compiler/TestAXRun.cc | 112 ++++++++---------- 1 file changed, 48 insertions(+), 64 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/compiler/TestAXRun.cc b/openvdb_ax/openvdb_ax/test/compiler/TestAXRun.cc index 90c666e9e6..f120cd1ce0 100644 --- a/openvdb_ax/openvdb_ax/test/compiler/TestAXRun.cc +++ b/openvdb_ax/openvdb_ax/test/compiler/TestAXRun.cc @@ -8,37 +8,23 @@ #include #include -#include +#include -class TestAXRun : public CppUnit::TestCase +class TestAXRun : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestAXRun); - CPPUNIT_TEST(singleRun); - CPPUNIT_TEST(multiRun); - CPPUNIT_TEST(regressions); - CPPUNIT_TEST_SUITE_END(); - - void singleRun(); - void multiRun(); - void regressions(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestAXRun); - -void -TestAXRun::singleRun() +TEST_F(TestAXRun, singleRun) { openvdb::FloatGrid f; f.setName("a"); f.tree().setValueOn({0,0,0}, 0.0f); openvdb::ax::run("@a = 1.0f;", f); - CPPUNIT_ASSERT_EQUAL(1.0f, f.tree().getValue({0,0,0})); + ASSERT_EQ(1.0f, f.tree().getValue({0,0,0})); openvdb::ax::run("@b = 2.0f;", f, {{"b", "a"}}); - CPPUNIT_ASSERT_EQUAL(2.0f, f.tree().getValue({0,0,0})); + ASSERT_EQ(2.0f, f.tree().getValue({0,0,0})); openvdb::math::Transform::Ptr defaultTransform = openvdb::math::Transform::createLinearTransform(); const std::vector singlePointZero = {openvdb::Vec3d::zero()}; @@ -50,20 +36,19 @@ TestAXRun::singleRun() const auto leafIter = points->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); - CPPUNIT_ASSERT_EQUAL(size_t(2), descriptor.size()); + ASSERT_EQ(size_t(2), descriptor.size()); const size_t idx = descriptor.find("a"); - CPPUNIT_ASSERT(idx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(idx) == openvdb::typeNameAsString()); + ASSERT_TRUE(idx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(idx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(idx)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); openvdb::ax::run("@b = 2.0f;", *points, {{"b","a"}}); - CPPUNIT_ASSERT_EQUAL(2.0f, handle.get(0)); + ASSERT_EQ(2.0f, handle.get(0)); } -void -TestAXRun::multiRun() +TEST_F(TestAXRun, multiRun) { { // multi volumes @@ -76,12 +61,12 @@ TestAXRun::multiRun() std::vector v { f1, f2 }; openvdb::ax::run("@a = @b = 1;", v); - CPPUNIT_ASSERT_EQUAL(1.0f, f1->tree().getValue({0,0,0})); - CPPUNIT_ASSERT_EQUAL(1.0f, f2->tree().getValue({0,0,0})); + ASSERT_EQ(1.0f, f1->tree().getValue({0,0,0})); + ASSERT_EQ(1.0f, f2->tree().getValue({0,0,0})); openvdb::ax::run("@c = @d = 2;", v, {{"c","a"}, {"d","b"}}); - CPPUNIT_ASSERT_EQUAL(2.0f, f1->tree().getValue({0,0,0})); - CPPUNIT_ASSERT_EQUAL(2.0f, f2->tree().getValue({0,0,0})); + ASSERT_EQ(2.0f, f1->tree().getValue({0,0,0})); + ASSERT_EQ(2.0f, f2->tree().getValue({0,0,0})); } { @@ -104,45 +89,44 @@ TestAXRun::multiRun() const auto& descriptor1 = leafIter1->attributeSet().descriptor(); const auto& descriptor2 = leafIter1->attributeSet().descriptor(); - CPPUNIT_ASSERT_EQUAL(size_t(3), descriptor1.size()); - CPPUNIT_ASSERT_EQUAL(size_t(3), descriptor2.size()); + ASSERT_EQ(size_t(3), descriptor1.size()); + ASSERT_EQ(size_t(3), descriptor2.size()); const size_t idx1 = descriptor1.find("a"); - CPPUNIT_ASSERT_EQUAL(idx1, descriptor2.find("a")); + ASSERT_EQ(idx1, descriptor2.find("a")); const size_t idx2 = descriptor1.find("b"); - CPPUNIT_ASSERT_EQUAL(idx2, descriptor2.find("b")); - CPPUNIT_ASSERT(idx1 != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(idx2 != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_EQ(idx2, descriptor2.find("b")); + ASSERT_TRUE(idx1 != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(idx2 != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor1.valueType(idx1) == openvdb::typeNameAsString()); - CPPUNIT_ASSERT(descriptor1.valueType(idx2) == openvdb::typeNameAsString()); - CPPUNIT_ASSERT(descriptor2.valueType(idx1) == openvdb::typeNameAsString()); - CPPUNIT_ASSERT(descriptor2.valueType(idx2) == openvdb::typeNameAsString()); + ASSERT_TRUE(descriptor1.valueType(idx1) == openvdb::typeNameAsString()); + ASSERT_TRUE(descriptor1.valueType(idx2) == openvdb::typeNameAsString()); + ASSERT_TRUE(descriptor2.valueType(idx1) == openvdb::typeNameAsString()); + ASSERT_TRUE(descriptor2.valueType(idx2) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter1->constAttributeArray(idx1)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); handle = openvdb::points::AttributeHandle(leafIter1->constAttributeArray(idx2)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); handle = openvdb::points::AttributeHandle(leafIter2->constAttributeArray(idx1)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); handle = openvdb::points::AttributeHandle(leafIter2->constAttributeArray(idx2)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); openvdb::ax::run("@c = @d = 2;", v, {{"c","a"}, {"d","b"}}); handle = openvdb::points::AttributeHandle(leafIter1->constAttributeArray(idx1)); - CPPUNIT_ASSERT_EQUAL(2.0f, handle.get(0)); + ASSERT_EQ(2.0f, handle.get(0)); handle = openvdb::points::AttributeHandle(leafIter1->constAttributeArray(idx2)); - CPPUNIT_ASSERT_EQUAL(2.0f, handle.get(0)); + ASSERT_EQ(2.0f, handle.get(0)); handle = openvdb::points::AttributeHandle(leafIter2->constAttributeArray(idx1)); - CPPUNIT_ASSERT_EQUAL(2.0f, handle.get(0)); + ASSERT_EQ(2.0f, handle.get(0)); handle = openvdb::points::AttributeHandle(leafIter2->constAttributeArray(idx2)); - CPPUNIT_ASSERT_EQUAL(2.0f, handle.get(0)); + ASSERT_EQ(2.0f, handle.get(0)); } } -void -TestAXRun::regressions() +TEST_F(TestAXRun, regressions) { openvdb::points::PointDataGrid::Ptr p1(new openvdb::points::PointDataGrid); openvdb::points::PointDataGrid::Ptr p2(new openvdb::points::PointDataGrid); @@ -155,22 +139,22 @@ TestAXRun::regressions() // test error on points and volumes std::vector v1 { f1, p1 }; std::vector v2 { p1, f1 }; - CPPUNIT_ASSERT_THROW(openvdb::ax::run("@a = 1.0f;", v1), openvdb::AXCompilerError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("@a = 1.0f;", v2), openvdb::AXCompilerError); + ASSERT_THROW(openvdb::ax::run("@a = 1.0f;", v1), openvdb::AXCompilerError); + ASSERT_THROW(openvdb::ax::run("@a = 1.0f;", v2), openvdb::AXCompilerError); } // Various tests which have been caught during developement - CPPUNIT_ASSERT_THROW(openvdb::ax::run("{} =", g1), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("{} =", g2), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("{} =", *f1), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("{} =", *p1), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("@c = 1.0f", g1), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("@c = 1.0f", g2), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("@c = 1.0f", *f1), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("@c = 1.0f", *p1), openvdb::AXSyntaxError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("if (v@v) {}", g1), openvdb::AXCompilerError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("if (v@v) {}", g2), openvdb::AXCompilerError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("if (v@v) {}", *f1), openvdb::AXCompilerError); - CPPUNIT_ASSERT_THROW(openvdb::ax::run("if (v@v) {}", *p1), openvdb::AXCompilerError); + ASSERT_THROW(openvdb::ax::run("{} =", g1), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("{} =", g2), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("{} =", *f1), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("{} =", *p1), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("@c = 1.0f", g1), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("@c = 1.0f", g2), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("@c = 1.0f", *f1), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("@c = 1.0f", *p1), openvdb::AXSyntaxError); + ASSERT_THROW(openvdb::ax::run("if (v@v) {}", g1), openvdb::AXCompilerError); + ASSERT_THROW(openvdb::ax::run("if (v@v) {}", g2), openvdb::AXCompilerError); + ASSERT_THROW(openvdb::ax::run("if (v@v) {}", *f1), openvdb::AXCompilerError); + ASSERT_THROW(openvdb::ax::run("if (v@v) {}", *p1), openvdb::AXCompilerError); } From 892cfa5167349ee55265e55a23a6972337f8986a Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 18:23:22 -0700 Subject: [PATCH 15/21] Convert TestPointExecutable.cc from cppunit to gtest; add gtest friend declarations to PointExecutable Signed-off-by: Tim Straubinger --- .../openvdb_ax/compiler/PointExecutable.h | 6 +- .../test/compiler/TestPointExecutable.cc | 539 +++++++++--------- 2 files changed, 265 insertions(+), 280 deletions(-) diff --git a/openvdb_ax/openvdb_ax/compiler/PointExecutable.h b/openvdb_ax/openvdb_ax/compiler/PointExecutable.h index 0e0a5a4e21..d4cea4925e 100644 --- a/openvdb_ax/openvdb_ax/compiler/PointExecutable.h +++ b/openvdb_ax/openvdb_ax/compiler/PointExecutable.h @@ -20,6 +20,8 @@ #include #include +#include // FRIEND_TEST, see TestPointExecutable.cc + #include class TestPointExecutable; @@ -167,7 +169,9 @@ class OPENVDB_AX_API PointExecutable private: friend class Compiler; - friend class ::TestPointExecutable; + + FRIEND_TEST(TestPointExecutable, testConstructionDestruction); + FRIEND_TEST(TestPointExecutable, testAttributeCodecs); /// @brief Private method used in the unit tests bool usesAcceleratedKernel(const points::PointDataTree& tree) const; diff --git a/openvdb_ax/openvdb_ax/test/compiler/TestPointExecutable.cc b/openvdb_ax/openvdb_ax/test/compiler/TestPointExecutable.cc index 6ad0d932ba..516245ce32 100644 --- a/openvdb_ax/openvdb_ax/test/compiler/TestPointExecutable.cc +++ b/openvdb_ax/openvdb_ax/test/compiler/TestPointExecutable.cc @@ -10,39 +10,22 @@ #include #include -#include +#include #include -using namespace openvdb; +// namespace must be the same as where PointExecutable is defined in order +// to access private methods. See also +//https://google.github.io/googletest/advanced.html#testing-private-code +namespace openvdb { +namespace OPENVDB_VERSION_NAME { +namespace ax { -class TestPointExecutable : public CppUnit::TestCase +class TestPointExecutable : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestPointExecutable); - CPPUNIT_TEST(testConstructionDestruction); - CPPUNIT_TEST(testCreateMissingAttributes); - CPPUNIT_TEST(testGroupExecution); - CPPUNIT_TEST(testCompilerCases); - CPPUNIT_TEST(testExecuteBindings); - CPPUNIT_TEST(testAttributeCodecs); - CPPUNIT_TEST(testCLI); - CPPUNIT_TEST_SUITE_END(); - - void testConstructionDestruction(); - void testCreateMissingAttributes(); - void testGroupExecution(); - void testCompilerCases(); - void testExecuteBindings(); - void testAttributeCodecs(); - void testCLI(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestPointExecutable); - -void -TestPointExecutable::testConstructionDestruction() +TEST_F(TestPointExecutable, testConstructionDestruction) { // Test the building and teardown of executable objects. This is primarily to test // the destruction of Context and ExecutionEngine LLVM objects. These must be destructed @@ -51,7 +34,7 @@ TestPointExecutable::testConstructionDestruction() // must be initialized, otherwise construction/destruction of llvm objects won't // exhibit correct behaviour - CPPUNIT_ASSERT(openvdb::ax::isInitialized()); + ASSERT_TRUE(openvdb::ax::isInitialized()); std::shared_ptr C(new llvm::LLVMContext); std::unique_ptr M(new llvm::Module("test_module", *C)); @@ -59,8 +42,8 @@ TestPointExecutable::testConstructionDestruction() .setEngineKind(llvm::EngineKind::JIT) .create()); - CPPUNIT_ASSERT(!M); - CPPUNIT_ASSERT(E); + ASSERT_TRUE(!M); + ASSERT_TRUE(E); std::weak_ptr wC = C; std::weak_ptr wE = E; @@ -73,25 +56,24 @@ TestPointExecutable::testConstructionDestruction() openvdb::ax::PointExecutable::Ptr pointExecutable (new openvdb::ax::PointExecutable(C, E, emptyReg, nullptr, {}, tree)); - CPPUNIT_ASSERT_EQUAL(2, int(wE.use_count())); - CPPUNIT_ASSERT_EQUAL(2, int(wC.use_count())); + ASSERT_EQ(2, int(wE.use_count())); + ASSERT_EQ(2, int(wC.use_count())); C.reset(); E.reset(); - CPPUNIT_ASSERT_EQUAL(1, int(wE.use_count())); - CPPUNIT_ASSERT_EQUAL(1, int(wC.use_count())); + ASSERT_EQ(1, int(wE.use_count())); + ASSERT_EQ(1, int(wC.use_count())); // test destruction pointExecutable.reset(); - CPPUNIT_ASSERT_EQUAL(0, int(wE.use_count())); - CPPUNIT_ASSERT_EQUAL(0, int(wC.use_count())); + ASSERT_EQ(0, int(wE.use_count())); + ASSERT_EQ(0, int(wC.use_count())); } -void -TestPointExecutable::testCreateMissingAttributes() +TEST_F(TestPointExecutable, testCreateMissingAttributes) { openvdb::math::Transform::Ptr defaultTransform = openvdb::math::Transform::createLinearTransform(); @@ -104,10 +86,10 @@ TestPointExecutable::testCreateMissingAttributes() openvdb::ax::Compiler::UniquePtr compiler = openvdb::ax::Compiler::create(); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@a=v@b.x;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); executable->setCreateMissing(false); - CPPUNIT_ASSERT_THROW(executable->execute(*grid), openvdb::AXExecutionError); + ASSERT_THROW(executable->execute(*grid), openvdb::AXExecutionError); executable->setCreateMissing(true); executable->execute(*grid); @@ -115,24 +97,23 @@ TestPointExecutable::testCreateMissingAttributes() const auto leafIter = grid->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); - CPPUNIT_ASSERT_EQUAL(size_t(3), descriptor.size()); + ASSERT_EQ(size_t(3), descriptor.size()); const size_t bIdx = descriptor.find("b"); - CPPUNIT_ASSERT(bIdx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(bIdx) == openvdb::typeNameAsString()); + ASSERT_TRUE(bIdx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(bIdx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle::Ptr bHandle = openvdb::points::AttributeHandle::create(leafIter->constAttributeArray(bIdx)); - CPPUNIT_ASSERT(bHandle->get(0) == openvdb::Vec3f::zero()); + ASSERT_TRUE(bHandle->get(0) == openvdb::Vec3f::zero()); const size_t aIdx = descriptor.find("a"); - CPPUNIT_ASSERT(aIdx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(aIdx) == openvdb::typeNameAsString()); + ASSERT_TRUE(aIdx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(aIdx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle::Ptr aHandle = openvdb::points::AttributeHandle::create(leafIter->constAttributeArray(aIdx)); - CPPUNIT_ASSERT(aHandle->get(0) == 0.0f); + ASSERT_TRUE(aHandle->get(0) == 0.0f); } -void -TestPointExecutable::testGroupExecution() +TEST_F(TestPointExecutable, testGroupExecution) { openvdb::math::Transform::Ptr defaultTransform = openvdb::math::Transform::createLinearTransform(0.1); @@ -154,16 +135,16 @@ TestPointExecutable::testGroupExecution() auto checkValues = [&](const int expected) { auto leafIter = grid->tree().cbeginLeaf(); - CPPUNIT_ASSERT(leafIter); + ASSERT_TRUE(leafIter); const auto& descriptor = leafIter->attributeSet().descriptor(); const size_t aIdx = descriptor.find("a"); - CPPUNIT_ASSERT(aIdx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(aIdx != openvdb::points::AttributeSet::INVALID_POS); for (; leafIter; ++leafIter) { openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(aIdx)); - CPPUNIT_ASSERT(handle.size() == 1); - CPPUNIT_ASSERT_EQUAL(expected, handle.get(0)); + ASSERT_TRUE(handle.size() == 1); + ASSERT_EQ(expected, handle.get(0)); } }; @@ -172,13 +153,13 @@ TestPointExecutable::testGroupExecution() openvdb::ax::Compiler::UniquePtr compiler = openvdb::ax::Compiler::create(); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("i@a=1;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); const std::string group = "test"; // non existent group executable->setGroupExecution(group); - CPPUNIT_ASSERT_THROW(executable->execute(*grid), openvdb::AXExecutionError); + ASSERT_THROW(executable->execute(*grid), openvdb::AXExecutionError); checkValues(0); openvdb::points::appendGroup(grid->tree(), group); @@ -194,19 +175,18 @@ TestPointExecutable::testGroupExecution() checkValues(1); } -void -TestPointExecutable::testCompilerCases() +TEST_F(TestPointExecutable, testCompilerCases) { openvdb::ax::Compiler::UniquePtr compiler = openvdb::ax::Compiler::create(); - CPPUNIT_ASSERT(compiler); + ASSERT_TRUE(compiler); { // with string only - CPPUNIT_ASSERT(static_cast(compiler->compile("int i;"))); - CPPUNIT_ASSERT_THROW(compiler->compile("i;"), openvdb::AXCompilerError); - CPPUNIT_ASSERT_THROW(compiler->compile("i"), openvdb::AXSyntaxError); + ASSERT_TRUE(static_cast(compiler->compile("int i;"))); + ASSERT_THROW(compiler->compile("i;"), openvdb::AXCompilerError); + ASSERT_THROW(compiler->compile("i"), openvdb::AXSyntaxError); // with AST only auto ast = openvdb::ax::ast::parse("i;"); - CPPUNIT_ASSERT_THROW(compiler->compile(*ast), openvdb::AXCompilerError); + ASSERT_THROW(compiler->compile(*ast), openvdb::AXCompilerError); } openvdb::ax::Logger logger([](const std::string&) {}); @@ -215,68 +195,68 @@ TestPointExecutable::testCompilerCases() { openvdb::ax::PointExecutable::Ptr executable = compiler->compile("", logger); // empty - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); } logger.clear(); { openvdb::ax::PointExecutable::Ptr executable = compiler->compile("i;", logger); // undeclared variable error - CPPUNIT_ASSERT(!executable); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable); + ASSERT_TRUE(logger.hasError()); logger.clear(); openvdb::ax::PointExecutable::Ptr executable2 = compiler->compile("i", logger); // expected ; error (parser) - CPPUNIT_ASSERT(!executable2); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable2); + ASSERT_TRUE(logger.hasError()); } logger.clear(); { openvdb::ax::PointExecutable::Ptr executable = compiler->compile("int i = 18446744073709551615;", logger); // warning - CPPUNIT_ASSERT(executable); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable); + ASSERT_TRUE(logger.hasWarning()); } // using syntax tree and logger logger.clear(); { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("", logger); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); openvdb::ax::PointExecutable::Ptr executable = compiler->compile(*tree, logger); // empty - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); logger.clear(); // no tree for line col numbers openvdb::ax::PointExecutable::Ptr executable2 = compiler->compile(*tree, logger); // empty - CPPUNIT_ASSERT(executable2); + ASSERT_TRUE(executable2); } logger.clear(); { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("i;", logger); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); openvdb::ax::PointExecutable::Ptr executable = compiler->compile(*tree, logger); // undeclared variable error - CPPUNIT_ASSERT(!executable); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable); + ASSERT_TRUE(logger.hasError()); logger.clear(); // no tree for line col numbers openvdb::ax::PointExecutable::Ptr executable2 = compiler->compile(*tree, logger); // undeclared variable error - CPPUNIT_ASSERT(!executable2); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable2); + ASSERT_TRUE(logger.hasError()); } logger.clear(); { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("int i = 18446744073709551615;", logger); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); openvdb::ax::PointExecutable::Ptr executable = compiler->compile(*tree, logger); // warning - CPPUNIT_ASSERT(executable); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable); + ASSERT_TRUE(logger.hasWarning()); logger.clear(); // no tree for line col numbers openvdb::ax::PointExecutable::Ptr executable2 = compiler->compile(*tree, logger); // warning - CPPUNIT_ASSERT(executable2); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable2); + ASSERT_TRUE(logger.hasWarning()); } logger.clear(); @@ -286,7 +266,7 @@ TestPointExecutable::testCompilerCases() std::unique_ptr copy(tree->copy()); openvdb::ax::PointExecutable::Ptr executable = compiler->compile(*copy, logger); // empty - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); } logger.clear(); { @@ -294,7 +274,7 @@ TestPointExecutable::testCompilerCases() std::unique_ptr copy(tree->copy()); openvdb::ax::PointExecutable::Ptr executable = compiler->compile(*copy, logger); // undeclared variable error - CPPUNIT_ASSERT(!executable); + ASSERT_TRUE(!executable); } logger.clear(); { @@ -302,13 +282,12 @@ TestPointExecutable::testCompilerCases() std::unique_ptr copy(tree->copy()); openvdb::ax::PointExecutable::Ptr executable = compiler->compile(*copy, logger); // warning - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); } logger.clear(); } -void -TestPointExecutable::testExecuteBindings() +TEST_F(TestPointExecutable, testExecuteBindings) { openvdb::math::Transform::Ptr defaultTransform = openvdb::math::Transform::createLinearTransform(); @@ -324,23 +303,23 @@ TestPointExecutable::testExecuteBindings() openvdb::points::appendAttribute(points->tree(), "a"); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b", "a"); // bind @b to attribute a executable->setAttributeBindings(bindings); executable->setCreateMissing(false); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->execute(*points)); const auto leafIter = points->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); // check value set via binding is correct - CPPUNIT_ASSERT_EQUAL(size_t(2), descriptor.size()); + ASSERT_EQ(size_t(2), descriptor.size()); const size_t aidx = descriptor.find("a"); - CPPUNIT_ASSERT(aidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(aidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(aidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(aidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(aidx)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); } // binding to existing attribute AND default bind other attribute @@ -352,30 +331,30 @@ TestPointExecutable::testExecuteBindings() openvdb::points::appendAttribute(points->tree(), "c"); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","a"); // bind b to a executable->setAttributeBindings(bindings); executable->setCreateMissing(false); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->execute(*points)); const auto leafIter = points->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); // check value set via binding - CPPUNIT_ASSERT_EQUAL(size_t(3), descriptor.size()); + ASSERT_EQ(size_t(3), descriptor.size()); const size_t aidx = descriptor.find("a"); - CPPUNIT_ASSERT(aidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(aidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(aidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(aidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(aidx)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); // check value set not using binding const size_t cidx = descriptor.find("c"); - CPPUNIT_ASSERT(cidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(cidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(cidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(cidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle2(leafIter->constAttributeArray(cidx)); - CPPUNIT_ASSERT_EQUAL(2.0f, handle2.get(0)); + ASSERT_EQ(2.0f, handle2.get(0)); } // bind to created attribute AND not binding to created attribute @@ -385,29 +364,29 @@ TestPointExecutable::testExecuteBindings() (singlePointZero, *defaultTransform); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b", "a"); // bind b to a executable->setAttributeBindings(bindings); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->execute(*points)); const auto leafIter = points->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); // check value set via binding - CPPUNIT_ASSERT_EQUAL(size_t(3), descriptor.size()); + ASSERT_EQ(size_t(3), descriptor.size()); const size_t aidx = descriptor.find("a"); - CPPUNIT_ASSERT(aidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(aidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(aidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(aidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(aidx)); - CPPUNIT_ASSERT_EQUAL(1.0f, handle.get(0)); + ASSERT_EQ(1.0f, handle.get(0)); // check value set not using binding const size_t cidx = descriptor.find("c"); - CPPUNIT_ASSERT(cidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(cidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(cidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(cidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle2(leafIter->constAttributeArray(cidx)); - CPPUNIT_ASSERT_EQUAL(2.0f, handle2.get(0)); + ASSERT_EQ(2.0f, handle2.get(0)); } // binding to non existent attribute, error @@ -417,13 +396,13 @@ TestPointExecutable::testExecuteBindings() (singlePointZero, *defaultTransform); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","a"); // bind b to a executable->setAttributeBindings(bindings); executable->setCreateMissing(false); - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); - CPPUNIT_ASSERT_THROW(executable->execute(*points), openvdb::AXExecutionError); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_THROW(executable->execute(*points), openvdb::AXExecutionError); } // trying to bind to an attribute and use the original attribute name at same time @@ -433,10 +412,10 @@ TestPointExecutable::testExecuteBindings() (singlePointZero, *defaultTransform); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f; @a = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","a"); // bind b to a - CPPUNIT_ASSERT_THROW(executable->setAttributeBindings(bindings), openvdb::AXExecutionError); + ASSERT_THROW(executable->setAttributeBindings(bindings), openvdb::AXExecutionError); } // swap ax and data attributes with bindings @@ -446,13 +425,13 @@ TestPointExecutable::testExecuteBindings() (singlePointZero, *defaultTransform); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f; @a = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","a"); // bind b to a bindings.set("a","b"); // bind a to b - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->execute(*points)); } @@ -463,23 +442,23 @@ TestPointExecutable::testExecuteBindings() (singlePointZero, *defaultTransform); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("f@P = 1.25f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("P","a"); // bind float a to P - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->execute(*points)); const auto leafIter = points->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); // check value set via binding - CPPUNIT_ASSERT_EQUAL(size_t(2), descriptor.size()); + ASSERT_EQ(size_t(2), descriptor.size()); const size_t aidx = descriptor.find("a"); - CPPUNIT_ASSERT(aidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(aidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(aidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(aidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(aidx)); - CPPUNIT_ASSERT_EQUAL(1.25f, handle.get(0)); + ASSERT_EQ(1.25f, handle.get(0)); } // bind P away from world space position to some other attribute, defaulting to vec3f (as P does) @@ -489,49 +468,48 @@ TestPointExecutable::testExecuteBindings() (singlePointZero, *defaultTransform); openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@P = 1.25f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("P","a"); // bind float a to P - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->execute(*points)); const auto leafIter = points->tree().cbeginLeaf(); const auto& descriptor = leafIter->attributeSet().descriptor(); // check value set via binding - CPPUNIT_ASSERT_EQUAL(size_t(2), descriptor.size()); + ASSERT_EQ(size_t(2), descriptor.size()); const size_t aidx = descriptor.find("a"); - CPPUNIT_ASSERT(aidx != openvdb::points::AttributeSet::INVALID_POS); - CPPUNIT_ASSERT(descriptor.valueType(aidx) == openvdb::typeNameAsString()); + ASSERT_TRUE(aidx != openvdb::points::AttributeSet::INVALID_POS); + ASSERT_TRUE(descriptor.valueType(aidx) == openvdb::typeNameAsString()); openvdb::points::AttributeHandle handle(leafIter->constAttributeArray(aidx)); - CPPUNIT_ASSERT_EQUAL(openvdb::Vec3f(1.25f), handle.get(0)); + ASSERT_EQ(openvdb::Vec3f(1.25f), handle.get(0)); } // test setting bindings and then resetting some of those bindings on the same executable { openvdb::ax::PointExecutable::Ptr executable = compiler->compile("@b = 1.0f; @a = 2.0f; @c = 3.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","a"); // bind b to a bindings.set("c","b"); // bind c to b bindings.set("a","c"); // bind a to c - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); bindings.set("a","b"); // bind a to b bindings.set("b","a"); // bind a to b - CPPUNIT_ASSERT(!bindings.dataNameBoundTo("c")); // c should be unbound + ASSERT_TRUE(!bindings.dataNameBoundTo("c")); // c should be unbound // check that the set call resets c to c - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); const openvdb::ax::AttributeBindings& bindingsOnExecutable = executable->getAttributeBindings(); - CPPUNIT_ASSERT(bindingsOnExecutable.isBoundAXName("c")); - CPPUNIT_ASSERT_EQUAL(*bindingsOnExecutable.dataNameBoundTo("c"), std::string("c")); + ASSERT_TRUE(bindingsOnExecutable.isBoundAXName("c")); + ASSERT_EQ(*bindingsOnExecutable.dataNameBoundTo("c"), std::string("c")); } } -void -TestPointExecutable::testAttributeCodecs() +TEST_F(TestPointExecutable, testAttributeCodecs) { math::Transform::Ptr defaultTransform = math::Transform::createLinearTransform(5.0f); @@ -545,7 +523,7 @@ TestPointExecutable::testAttributeCodecs() points = points::createPointDataGrid (twoPoints, *defaultTransform); - CPPUNIT_ASSERT_EQUAL(points->tree().leafCount(), Index32(1)); + ASSERT_EQ(points->tree().leafCount(), Index32(1)); // collapsed uniform 0 attributes points::appendAttribute(points->tree(), "f"); @@ -560,20 +538,20 @@ TestPointExecutable::testAttributeCodecs() points::AttributeHandle handle1(leafIter->constAttributeArray("t")); points::AttributeHandle handle2(leafIter->constAttributeArray("i")); points::AttributeHandle handle3(leafIter->constAttributeArray("vu")); - CPPUNIT_ASSERT(handle0.isUniform()); - CPPUNIT_ASSERT(handle1.isUniform()); - CPPUNIT_ASSERT(handle2.isUniform()); - CPPUNIT_ASSERT(handle3.isUniform()); - CPPUNIT_ASSERT_EQUAL(0.0f, handle0.get(0)); - CPPUNIT_ASSERT_EQUAL(float(math::half(0.0f)), handle1.get(0)); - CPPUNIT_ASSERT_EQUAL(int32_t(0), handle2.get(0)); - CPPUNIT_ASSERT_EQUAL(Vec3f(math::half(0)), handle3.get(0)); + ASSERT_TRUE(handle0.isUniform()); + ASSERT_TRUE(handle1.isUniform()); + ASSERT_TRUE(handle2.isUniform()); + ASSERT_TRUE(handle3.isUniform()); + ASSERT_EQ(0.0f, handle0.get(0)); + ASSERT_EQ(float(math::half(0.0f)), handle1.get(0)); + ASSERT_EQ(int32_t(0), handle2.get(0)); + ASSERT_EQ(Vec3f(math::half(0)), handle3.get(0)); // non uniform codec compressed inputs points::AttributeWriteHandle handle4(leafIter->attributeArray("vnu")); handle4.set(0, Vec3f(1.0f)); handle4.set(1, Vec3f(2.0f)); - CPPUNIT_ASSERT(!handle4.isUniform()); + ASSERT_TRUE(!handle4.isUniform()); openvdb::ax::PointExecutable::Ptr executable = compiler->compile @@ -592,37 +570,37 @@ TestPointExecutable::testAttributeCodecs() if (openvdb::ax::x86::CheckX86Feature("f16c") == openvdb::ax::x86::CpuFlagStatus::Unsupported) { - CPPUNIT_ASSERT(!executable->usesAcceleratedKernel(points->tree())); + ASSERT_TRUE(!executable->usesAcceleratedKernel(points->tree())); } else { - CPPUNIT_ASSERT(executable->usesAcceleratedKernel(points->tree())); + ASSERT_TRUE(executable->usesAcceleratedKernel(points->tree())); } #else - CPPUNIT_ASSERT(executable->usesAcceleratedKernel(points->tree())); + ASSERT_TRUE(executable->usesAcceleratedKernel(points->tree())); #endif - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->execute(*points)); - CPPUNIT_ASSERT_EQUAL(3.245e-7f, handle0.get(0)); - CPPUNIT_ASSERT_EQUAL(9.28e-12f, handle0.get(1)); - CPPUNIT_ASSERT_EQUAL(float(math::half(3.245e-7f)), handle1.get(0)); - CPPUNIT_ASSERT_EQUAL(float(math::half(0.0f)), handle1.get(1)); - CPPUNIT_ASSERT_EQUAL(int32_t(3), handle2.get(0)); - CPPUNIT_ASSERT_EQUAL(int32_t(0), handle2.get(1)); + ASSERT_EQ(3.245e-7f, handle0.get(0)); + ASSERT_EQ(9.28e-12f, handle0.get(1)); + ASSERT_EQ(float(math::half(3.245e-7f)), handle1.get(0)); + ASSERT_EQ(float(math::half(0.0f)), handle1.get(1)); + ASSERT_EQ(int32_t(3), handle2.get(0)); + ASSERT_EQ(int32_t(0), handle2.get(1)); - CPPUNIT_ASSERT_EQUAL(float(math::half(3.245e-7f)), handle3.get(0).x()); - CPPUNIT_ASSERT_EQUAL(float(math::half(100000.0f)), handle3.get(0).y()); - CPPUNIT_ASSERT_EQUAL(float(math::half(-1e-2f)), handle3.get(0).z()); - CPPUNIT_ASSERT_EQUAL(float(math::half(6.1e-3f)), handle3.get(1).x()); - CPPUNIT_ASSERT_EQUAL(float(math::half(0.0f)), handle3.get(1).y()); - CPPUNIT_ASSERT_EQUAL(float(math::half(-9.367e-6f)), handle3.get(1).z()); + ASSERT_EQ(float(math::half(3.245e-7f)), handle3.get(0).x()); + ASSERT_EQ(float(math::half(100000.0f)), handle3.get(0).y()); + ASSERT_EQ(float(math::half(-1e-2f)), handle3.get(0).z()); + ASSERT_EQ(float(math::half(6.1e-3f)), handle3.get(1).x()); + ASSERT_EQ(float(math::half(0.0f)), handle3.get(1).y()); + ASSERT_EQ(float(math::half(-9.367e-6f)), handle3.get(1).z()); - CPPUNIT_ASSERT_EQUAL(float(math::half(7.135e-7f)), handle4.get(0).x()); - CPPUNIT_ASSERT_EQUAL(float(math::half(200000.0f)), handle4.get(0).y()); - CPPUNIT_ASSERT_EQUAL(float(math::half(-5e-3f)), handle4.get(0).z()); - CPPUNIT_ASSERT_EQUAL(float(math::half(-1.0f)), handle4.get(1).x()); - CPPUNIT_ASSERT_EQUAL(float(math::half(80123.14f)), handle4.get(1).y()); - CPPUNIT_ASSERT_EQUAL(float(math::half(9019.53123f)), handle4.get(1).z()); + ASSERT_EQ(float(math::half(7.135e-7f)), handle4.get(0).x()); + ASSERT_EQ(float(math::half(200000.0f)), handle4.get(0).y()); + ASSERT_EQ(float(math::half(-5e-3f)), handle4.get(0).z()); + ASSERT_EQ(float(math::half(-1.0f)), handle4.get(1).x()); + ASSERT_EQ(float(math::half(80123.14f)), handle4.get(1).y()); + ASSERT_EQ(float(math::half(9019.53123f)), handle4.get(1).z()); } // compress/decompress val according to op and return it as the same type as val @@ -641,7 +619,7 @@ TestPointExecutable::testAttributeCodecs() points = points::createPointDataGrid (twoPoints, *defaultTransform); - CPPUNIT_ASSERT_EQUAL(points->tree().leafCount(), Index32(1)); + ASSERT_EQ(points->tree().leafCount(), Index32(1)); // collapsed uniform 0 attributes points::appendAttribute>(points->tree(), "fpu8"); @@ -656,22 +634,22 @@ TestPointExecutable::testAttributeCodecs() points::AttributeHandle handle1(leafIter->constAttributeArray("f")); points::AttributeHandle handle2(leafIter->constAttributeArray("fpr8")); points::AttributeHandle handle3(leafIter->constAttributeArray("fpu16")); - CPPUNIT_ASSERT(handle0.isUniform()); - CPPUNIT_ASSERT(handle1.isUniform()); - CPPUNIT_ASSERT(handle2.isUniform()); - CPPUNIT_ASSERT(handle3.isUniform()); + ASSERT_TRUE(handle0.isUniform()); + ASSERT_TRUE(handle1.isUniform()); + ASSERT_TRUE(handle2.isUniform()); + ASSERT_TRUE(handle3.isUniform()); const float fpr8zero = compress(points::FixedPointCodec(), 0.0f); - CPPUNIT_ASSERT_EQUAL(Vec3f(0.0f), handle0.get(0)); - CPPUNIT_ASSERT_EQUAL(float(0.0f), handle1.get(0)); - CPPUNIT_ASSERT_EQUAL(Vec3f(fpr8zero), handle2.get(0)); - CPPUNIT_ASSERT_EQUAL(Vec3f(0.0f), handle3.get(0)); + ASSERT_EQ(Vec3f(0.0f), handle0.get(0)); + ASSERT_EQ(float(0.0f), handle1.get(0)); + ASSERT_EQ(Vec3f(fpr8zero), handle2.get(0)); + ASSERT_EQ(Vec3f(0.0f), handle3.get(0)); // non uniform codec compressed inputs points::AttributeWriteHandle handle4(leafIter->attributeArray("fpr16")); handle4.set(0, Vec3f(0.49f)); handle4.set(1, Vec3f(1e-9f)); - CPPUNIT_ASSERT(!handle4.isUniform()); + ASSERT_TRUE(!handle4.isUniform()); openvdb::ax::PointExecutable::Ptr executable = compiler->compile @@ -686,40 +664,40 @@ TestPointExecutable::testAttributeCodecs() "if (v@P.x > 0.5) { v@fpr16[0] = 7.135e-7f; v@fpr16[1] = 200000.0f; v@fpr16[2] = -5e-3f; }" "else { v@fpr16[0] = -0.5f; v@fpr16[1] = 0.0f; v@fpr16[2] = 0.5f; }"); - CPPUNIT_ASSERT(executable->usesAcceleratedKernel(points->tree())); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_TRUE(executable->usesAcceleratedKernel(points->tree())); + ASSERT_NO_THROW(executable->execute(*points)); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.924599f), handle0.get(0).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.0f), handle0.get(0).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -7e-2f), handle0.get(0).z()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 9.9e-9f), handle0.get(1).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -0.9999f), handle0.get(1).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 7.2134e-4f), handle0.get(1).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.924599f), handle0.get(0).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.0f), handle0.get(0).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), -7e-2f), handle0.get(0).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), 9.9e-9f), handle0.get(1).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), -0.9999f), handle0.get(1).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), 7.2134e-4f), handle0.get(1).z()); - CPPUNIT_ASSERT_EQUAL(float(3.245e-7f), handle1.get(0)); - CPPUNIT_ASSERT_EQUAL(float(0.0f), handle1.get(1)); + ASSERT_EQ(float(3.245e-7f), handle1.get(0)); + ASSERT_EQ(float(0.0f), handle1.get(1)); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 3.245e-7f), handle2.get(0).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.0f), handle2.get(0).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -1e-12f), handle2.get(0).z()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -1.245e-9f), handle2.get(1).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -0.49f), handle2.get(1).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.078918f), handle2.get(1).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), 3.245e-7f), handle2.get(0).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.0f), handle2.get(0).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), -1e-12f), handle2.get(0).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), -1.245e-9f), handle2.get(1).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), -0.49f), handle2.get(1).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.078918f), handle2.get(1).z()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.999999f), handle3.get(0).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -0.0f), handle3.get(0).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 7.66e-2f), handle3.get(0).z()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.0f), handle3.get(1).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -0.999999f), handle3.get(1).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 5.9811e-14f), handle3.get(1).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.999999f), handle3.get(0).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), -0.0f), handle3.get(0).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), 7.66e-2f), handle3.get(0).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.0f), handle3.get(1).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), -0.999999f), handle3.get(1).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), 5.9811e-14f), handle3.get(1).z()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 7.135e-7f), handle4.get(0).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 200000.0f), handle4.get(0).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -5e-3f), handle4.get(0).z()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), -0.5f), handle4.get(1).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.0f), handle4.get(1).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), 0.5f), handle4.get(1).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), 7.135e-7f), handle4.get(0).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), 200000.0f), handle4.get(0).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), -5e-3f), handle4.get(0).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), -0.5f), handle4.get(1).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.0f), handle4.get(1).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), 0.5f), handle4.get(1).z()); } // finally test position (uint8_t compression) and different codecs together @@ -728,7 +706,7 @@ TestPointExecutable::testAttributeCodecs() points = points::createPointDataGrid , points::PointDataGrid> (twoPoints, *defaultTransform); - CPPUNIT_ASSERT_EQUAL(points->tree().leafCount(), Index32(1)); + ASSERT_EQ(points->tree().leafCount(), Index32(1)); points::appendAttribute(points->tree(), "t"); points::appendAttribute>(points->tree(), "f"); @@ -746,16 +724,16 @@ TestPointExecutable::testAttributeCodecs() if (openvdb::ax::x86::CheckX86Feature("f16c") == openvdb::ax::x86::CpuFlagStatus::Unsupported) { - CPPUNIT_ASSERT(!executable->usesAcceleratedKernel(points->tree())); + ASSERT_TRUE(!executable->usesAcceleratedKernel(points->tree())); } else { - CPPUNIT_ASSERT(executable->usesAcceleratedKernel(points->tree())); + ASSERT_TRUE(executable->usesAcceleratedKernel(points->tree())); } #else - CPPUNIT_ASSERT(executable->usesAcceleratedKernel(points->tree())); + ASSERT_TRUE(executable->usesAcceleratedKernel(points->tree())); #endif - CPPUNIT_ASSERT_NO_THROW(executable->execute(*points)); + ASSERT_NO_THROW(executable->execute(*points)); const auto leafIter = points->tree().cbeginLeaf(); points::AttributeHandle handle0(leafIter->constAttributeArray("P")); @@ -771,17 +749,16 @@ TestPointExecutable::testAttributeCodecs() pos = Vec3f(defaultTransform->worldToIndex(pos)); pos -= coord.asVec3s(); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), pos.x()), handle0.get(0).x()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), pos.y()), handle0.get(0).y()); - CPPUNIT_ASSERT_EQUAL(compress(points::FixedPointCodec(), pos.z()), handle0.get(0).z()); + ASSERT_EQ(compress(points::FixedPointCodec(), pos.x()), handle0.get(0).x()); + ASSERT_EQ(compress(points::FixedPointCodec(), pos.y()), handle0.get(0).y()); + ASSERT_EQ(compress(points::FixedPointCodec(), pos.z()), handle0.get(0).z()); - CPPUNIT_ASSERT_EQUAL(float(math::half(8908410.12384910f)), handle1.get(0)); - CPPUNIT_ASSERT_EQUAL(Vec3f(compress(points::FixedPointCodec(), 245e-9f)), handle2.get(0)); + ASSERT_EQ(float(math::half(8908410.12384910f)), handle1.get(0)); + ASSERT_EQ(Vec3f(compress(points::FixedPointCodec(), 245e-9f)), handle2.get(0)); } } -void -TestPointExecutable::testCLI() +TEST_F(TestPointExecutable, testCLI) { using CLI = openvdb::ax::PointExecutable::CLI; @@ -829,77 +806,77 @@ TestPointExecutable::testCLI() const auto defaultGrain = defaultExe->getGrainSize(); const auto defaultBindings = defaultExe->getAttributeBindings(); - CPPUNIT_ASSERT_THROW(CreateCLI("--unknown"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("-unknown"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("-"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("--"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("-- "), UnusedCLIParam); + ASSERT_THROW(CreateCLI("--unknown"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("-unknown"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("-"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("--"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("-- "), UnusedCLIParam); { CLI cli = CreateCLI(""); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(defaultGroup, exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(defaultGroup, exe->getGroupExecution()); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --create-missing { - CPPUNIT_ASSERT_THROW(CreateCLI("--create-missing"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--create-missing invalid"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--create-missing --group test"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--create-missing"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--create-missing invalid"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--create-missing --group test"), openvdb::CLIError); CLI cli = CreateCLI("--create-missing ON"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(true, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultGroup, exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(true, exe->getCreateMissing()); + ASSERT_EQ(defaultGroup, exe->getGroupExecution()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --group { - CPPUNIT_ASSERT_THROW(CreateCLI("--group"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--group --create-missing ON"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--group"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--group --create-missing ON"), openvdb::CLIError); CLI cli = CreateCLI("--group test"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(std::string("test"), exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(std::string("test"), exe->getGroupExecution()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --grain { - CPPUNIT_ASSERT_THROW(CreateCLI("--points-grain"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--points-grain nan"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--points-grain -1"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--points-grain --create-missing ON"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--points-grain"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--points-grain nan"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--points-grain -1"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--points-grain --create-missing ON"), openvdb::CLIError); CLI cli = CreateCLI("--points-grain 0"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultGroup, exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(size_t(0), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultGroup, exe->getGroupExecution()); + ASSERT_EQ(size_t(0), exe->getGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --bindings { - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings :"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings ,"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings a:"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings a,b"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings :b"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings ,a:b"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings --create-missing ON"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings :"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings ,"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings a:"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings a,b"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings :b"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings ,a:b"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings --create-missing ON"), openvdb::CLIError); CLI cli = CreateCLI("--bindings a:b,c:d,12:13"); ax::AttributeBindings bindings; @@ -908,22 +885,22 @@ TestPointExecutable::testCLI() bindings.set("12", "13"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultGroup, exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(bindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultGroup, exe->getGroupExecution()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(bindings, exe->getAttributeBindings()); } // multiple { CLI cli = CreateCLI("--points-grain 5 --create-missing OFF"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(false, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultGroup, exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(size_t(5), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(false, exe->getCreateMissing()); + ASSERT_EQ(defaultGroup, exe->getGroupExecution()); + ASSERT_EQ(size_t(5), exe->getGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } { @@ -932,10 +909,14 @@ TestPointExecutable::testCLI() bindings.set("a", "b"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); - CPPUNIT_ASSERT_EQUAL(false, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(std::string("123"), exe->getGroupExecution()); - CPPUNIT_ASSERT_EQUAL(size_t(128), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(bindings, exe->getAttributeBindings()); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_EQ(false, exe->getCreateMissing()); + ASSERT_EQ(std::string("123"), exe->getGroupExecution()); + ASSERT_EQ(size_t(128), exe->getGrainSize()); + ASSERT_EQ(bindings, exe->getAttributeBindings()); } } + +} // namespace ax +} // namespace OPENVDB_VERSION_NAME +} // namespace openvdb From a7bb428e453c6baa63057d5836cb860a41120df9 Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 4 Oct 2024 18:24:29 -0700 Subject: [PATCH 16/21] Convert TestVolumeExecutable.cc from cppunit to gtest; add gtest friend declarations to VolumeExecutable Signed-off-by: Tim Straubinger --- .../openvdb_ax/compiler/VolumeExecutable.h | 5 +- .../test/compiler/TestVolumeExecutable.cc | 908 +++++++++--------- 2 files changed, 449 insertions(+), 464 deletions(-) diff --git a/openvdb_ax/openvdb_ax/compiler/VolumeExecutable.h b/openvdb_ax/openvdb_ax/compiler/VolumeExecutable.h index fc119af51f..d851a3a419 100644 --- a/openvdb_ax/openvdb_ax/compiler/VolumeExecutable.h +++ b/openvdb_ax/openvdb_ax/compiler/VolumeExecutable.h @@ -19,6 +19,8 @@ #include #include +#include // FRIEND_TEST, see TestVolumeExecutable.cc + #include class TestVolumeExecutable; @@ -293,7 +295,8 @@ class OPENVDB_AX_API VolumeExecutable private: friend class Compiler; - friend class ::TestVolumeExecutable; + + FRIEND_TEST(TestVolumeExecutable, testConstructionDestruction); /// @brief Constructor, expected to be invoked by the compiler. Should not /// be invoked directly. diff --git a/openvdb_ax/openvdb_ax/test/compiler/TestVolumeExecutable.cc b/openvdb_ax/openvdb_ax/test/compiler/TestVolumeExecutable.cc index 87faf11228..2a3dacf209 100644 --- a/openvdb_ax/openvdb_ax/test/compiler/TestVolumeExecutable.cc +++ b/openvdb_ax/openvdb_ax/test/compiler/TestVolumeExecutable.cc @@ -5,37 +5,22 @@ #include #include -#include +#include #include -class TestVolumeExecutable : public CppUnit::TestCase +// namespace must be the same as where VolumeExecutable is defined in order +// to access private methods. See also +//https://google.github.io/googletest/advanced.html#testing-private-code +namespace openvdb { +namespace OPENVDB_VERSION_NAME { +namespace ax { + +class TestVolumeExecutable : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestVolumeExecutable); - CPPUNIT_TEST(testConstructionDestruction); - CPPUNIT_TEST(testCreateMissingGrids); - CPPUNIT_TEST(testTreeExecutionLevel); - CPPUNIT_TEST(testActiveTileStreaming); - CPPUNIT_TEST(testCompilerCases); - CPPUNIT_TEST(testExecuteBindings); - CPPUNIT_TEST(testCLI); - CPPUNIT_TEST_SUITE_END(); - - void testConstructionDestruction(); - void testCreateMissingGrids(); - void testTreeExecutionLevel(); - void testActiveTileStreaming(); - void testCompilerCases(); - void testExecuteBindings(); - void testCLI(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestVolumeExecutable); - -void -TestVolumeExecutable::testConstructionDestruction() +TEST_F(TestVolumeExecutable, testConstructionDestruction) { // Test the building and teardown of executable objects. This is primarily to test // the destruction of Context and ExecutionEngine LLVM objects. These must be destructed @@ -44,7 +29,7 @@ TestVolumeExecutable::testConstructionDestruction() // must be initialized, otherwise construction/destruction of llvm objects won't // exhibit correct behaviour - CPPUNIT_ASSERT(openvdb::ax::isInitialized()); + ASSERT_TRUE(openvdb::ax::isInitialized()); std::shared_ptr C(new llvm::LLVMContext); #if LLVM_VERSION_MAJOR >= 15 @@ -58,8 +43,8 @@ TestVolumeExecutable::testConstructionDestruction() .setEngineKind(llvm::EngineKind::JIT) .create()); - CPPUNIT_ASSERT(!M); - CPPUNIT_ASSERT(E); + ASSERT_TRUE(!M); + ASSERT_TRUE(E); std::weak_ptr wC = C; std::weak_ptr wE = E; @@ -72,37 +57,36 @@ TestVolumeExecutable::testConstructionDestruction() openvdb::ax::VolumeExecutable::Ptr volumeExecutable (new openvdb::ax::VolumeExecutable(C, E, emptyReg, nullptr, {}, tree)); - CPPUNIT_ASSERT_EQUAL(2, int(wE.use_count())); - CPPUNIT_ASSERT_EQUAL(2, int(wC.use_count())); + ASSERT_EQ(2, int(wE.use_count())); + ASSERT_EQ(2, int(wC.use_count())); C.reset(); E.reset(); - CPPUNIT_ASSERT_EQUAL(1, int(wE.use_count())); - CPPUNIT_ASSERT_EQUAL(1, int(wC.use_count())); + ASSERT_EQ(1, int(wE.use_count())); + ASSERT_EQ(1, int(wC.use_count())); // test destruction volumeExecutable.reset(); - CPPUNIT_ASSERT_EQUAL(0, int(wE.use_count())); - CPPUNIT_ASSERT_EQUAL(0, int(wC.use_count())); + ASSERT_EQ(0, int(wE.use_count())); + ASSERT_EQ(0, int(wC.use_count())); } -void -TestVolumeExecutable::testCreateMissingGrids() +TEST_F(TestVolumeExecutable, testCreateMissingGrids) { openvdb::ax::Compiler::UniquePtr compiler = openvdb::ax::Compiler::create(); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@a=v@b.x;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); executable->setCreateMissing(false); executable->setValueIterator(openvdb::ax::VolumeExecutable::IterType::ON); openvdb::GridPtrVec grids; - CPPUNIT_ASSERT_THROW(executable->execute(grids), openvdb::AXExecutionError); - CPPUNIT_ASSERT(grids.empty()); + ASSERT_THROW(executable->execute(grids), openvdb::AXExecutionError); + ASSERT_TRUE(grids.empty()); executable->setCreateMissing(true); executable->setValueIterator(openvdb::ax::VolumeExecutable::IterType::ON); @@ -111,20 +95,19 @@ TestVolumeExecutable::testCreateMissingGrids() openvdb::math::Transform::Ptr defaultTransform = openvdb::math::Transform::createLinearTransform(); - CPPUNIT_ASSERT_EQUAL(size_t(2), grids.size()); - CPPUNIT_ASSERT(grids[0]->getName() == "b"); - CPPUNIT_ASSERT(grids[0]->isType()); - CPPUNIT_ASSERT(grids[0]->empty()); - CPPUNIT_ASSERT(grids[0]->transform() == *defaultTransform); + ASSERT_EQ(size_t(2), grids.size()); + ASSERT_TRUE(grids[0]->getName() == "b"); + ASSERT_TRUE(grids[0]->isType()); + ASSERT_TRUE(grids[0]->empty()); + ASSERT_TRUE(grids[0]->transform() == *defaultTransform); - CPPUNIT_ASSERT(grids[1]->getName() == "a"); - CPPUNIT_ASSERT(grids[1]->isType()); - CPPUNIT_ASSERT(grids[1]->empty()); - CPPUNIT_ASSERT(grids[1]->transform() == *defaultTransform); + ASSERT_TRUE(grids[1]->getName() == "a"); + ASSERT_TRUE(grids[1]->isType()); + ASSERT_TRUE(grids[1]->empty()); + ASSERT_TRUE(grids[1]->transform() == *defaultTransform); } -void -TestVolumeExecutable::testTreeExecutionLevel() +TEST_F(TestVolumeExecutable, testTreeExecutionLevel) { openvdb::ax::CustomData::Ptr data = openvdb::ax::CustomData::create(); openvdb::FloatMetadata* const meta = @@ -134,8 +117,8 @@ TestVolumeExecutable::testTreeExecutionLevel() // generate an executable which does not stream active tiles openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("f@test = $value;", data); - CPPUNIT_ASSERT(executable); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(executable); + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming()); using NodeT0 = openvdb::FloatGrid::Accessor::template NodeTypeAtLevel<0>; @@ -149,178 +132,177 @@ TestVolumeExecutable::testTreeExecutionLevel() tree.addTile(2, openvdb::Coord(NodeT2::DIM), -1.0f, /*active*/true); // NodeT1 tile tree.addTile(1, openvdb::Coord(NodeT2::DIM+NodeT1::DIM), -1.0f, /*active*/true); // NodeT0 tile auto leaf = tree.touchLeaf(openvdb::Coord(NodeT2::DIM + NodeT1::DIM + NodeT0::DIM)); - CPPUNIT_ASSERT(leaf); + ASSERT_TRUE(leaf); leaf->fill(-1.0f, true); const openvdb::FloatTree copy = tree; // check config auto CHECK_CONFIG = [&]() { - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(1), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(3), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-4), tree.getValueDepth(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT_EQUAL(leaf, tree.probeLeaf(openvdb::Coord(NodeT2::DIM + NodeT1::DIM + NodeT0::DIM))); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(NodeT2::NUM_VOXELS) + + ASSERT_EQ(openvdb::Index32(1), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(3), tree.activeTileCount()); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-4), tree.getValueDepth(openvdb::Coord(0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_EQ(leaf, tree.probeLeaf(openvdb::Coord(NodeT2::DIM + NodeT1::DIM + NodeT0::DIM))); + ASSERT_EQ(openvdb::Index64(NodeT2::NUM_VOXELS) + openvdb::Index64(NodeT1::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS), // leaf tree.activeVoxelCount()); - CPPUNIT_ASSERT(copy.hasSameTopology(tree)); + ASSERT_TRUE(copy.hasSameTopology(tree)); }; float constant; bool active; CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(-1.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(-1.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(-1.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(-1.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(-1.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(-1.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(-1.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(-1.0f, constant); + ASSERT_TRUE(active); openvdb::Index min,max; // process default config, all should change executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); meta->setValue(-2.0f); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(-2.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(-2.0f, constant); + ASSERT_TRUE(active); // process level 0, only leaf change meta->setValue(1.0f); executable->setTreeExecutionLevel(0); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(0), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(1.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(1.0f, constant); + ASSERT_TRUE(active); // process level 1 meta->setValue(3.0f); executable->setTreeExecutionLevel(1); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(1), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(1), max); + ASSERT_EQ(openvdb::Index(1), min); + ASSERT_EQ(openvdb::Index(1), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(3.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(1.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(3.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(1.0f, constant); + ASSERT_TRUE(active); // process level 2 meta->setValue(5.0f); executable->setTreeExecutionLevel(2); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(2), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(2), max); + ASSERT_EQ(openvdb::Index(2), min); + ASSERT_EQ(openvdb::Index(2), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(-2.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(5.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(3.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(1.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(-2.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(5.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(3.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(1.0f, constant); + ASSERT_TRUE(active); // process level 3 meta->setValue(10.0f); executable->setTreeExecutionLevel(3); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(3), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(3), max); + ASSERT_EQ(openvdb::Index(3), min); + ASSERT_EQ(openvdb::Index(3), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(10.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(5.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(3.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(1.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(10.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(5.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(3.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(1.0f, constant); + ASSERT_TRUE(active); // test higher values throw - CPPUNIT_ASSERT_THROW(executable->setTreeExecutionLevel(4), openvdb::RuntimeError); + ASSERT_THROW(executable->setTreeExecutionLevel(4), openvdb::RuntimeError); // test level range 0-1 meta->setValue(-4.0f); executable->setTreeExecutionLevel(0,1); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(1), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(10.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(5.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(-4.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(-4.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(10.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(5.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(-4.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(-4.0f, constant); + ASSERT_TRUE(active); // test level range 1-2 meta->setValue(-6.0f); executable->setTreeExecutionLevel(1,2); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(1), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(2), max); + ASSERT_EQ(openvdb::Index(1), min); + ASSERT_EQ(openvdb::Index(2), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(10.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(-6.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(-6.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(-4.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(10.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(-6.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(-6.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(-4.0f, constant); + ASSERT_TRUE(active); // test level range 2-3 meta->setValue(-11.0f); executable->setTreeExecutionLevel(2,3); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(2), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(3), max); + ASSERT_EQ(openvdb::Index(2), min); + ASSERT_EQ(openvdb::Index(3), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(-11.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(-11.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(-6.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(-4.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(-11.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(-11.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(-6.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(-4.0f, constant); + ASSERT_TRUE(active); // test on complete range meta->setValue(20.0f); executable->setTreeExecutionLevel(0,3); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(3), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(3), max); executable->execute(grid); CHECK_CONFIG(); - CPPUNIT_ASSERT_EQUAL(20.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(20.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(20.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(20.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_EQ(20.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(20.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(20.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(20.0f, constant); + ASSERT_TRUE(active); } -void -TestVolumeExecutable::testActiveTileStreaming() +TEST_F(TestVolumeExecutable, testActiveTileStreaming) { using NodeT0 = openvdb::FloatGrid::Accessor::template NodeTypeAtLevel<0>; using NodeT1 = openvdb::FloatGrid::Accessor::template NodeTypeAtLevel<1>; @@ -341,41 +323,41 @@ TestVolumeExecutable::testActiveTileStreaming() tree.addTile(2, openvdb::Coord(NodeT2::DIM), -1.0f, /*active*/true); // NodeT1 tile tree.addTile(1, openvdb::Coord(NodeT2::DIM+NodeT1::DIM), -1.0f, /*active*/true); // NodeT0 tile auto leaf = tree.touchLeaf(openvdb::Coord(NodeT2::DIM + NodeT1::DIM + NodeT0::DIM)); - CPPUNIT_ASSERT(leaf); + ASSERT_TRUE(leaf); leaf->fill(-1.0f, true); executable = compiler->compile("f@test = 2.0f;"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); executable->execute(grid); - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(1), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(3), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-4), tree.getValueDepth(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-1), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM+NodeT0::DIM))); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(NodeT2::NUM_VOXELS) + + ASSERT_EQ(openvdb::Index32(1), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(3), tree.activeTileCount()); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-4), tree.getValueDepth(openvdb::Coord(0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-1), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM+NodeT0::DIM))); + ASSERT_EQ(openvdb::Index64(NodeT2::NUM_VOXELS) + openvdb::Index64(NodeT1::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS), tree.activeVoxelCount()); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT_EQUAL(leaf, tree.probeLeaf(openvdb::Coord(NodeT2::DIM + NodeT1::DIM + NodeT0::DIM))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(0))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_EQ(leaf, tree.probeLeaf(openvdb::Coord(NodeT2::DIM + NodeT1::DIM + NodeT0::DIM))); float constant; bool active; - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(2.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(2.0f, constant); + ASSERT_TRUE(active); } // test getvoxelpws which densifies everything @@ -387,16 +369,16 @@ TestVolumeExecutable::testActiveTileStreaming() tree.addTile(1, openvdb::Coord(NodeT1::DIM), -1.0f, /*active*/true); // NodeT0 tile executable = compiler->compile("vec3d p = getvoxelpws(); f@test = p.x;"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); executable->execute(grid); @@ -404,11 +386,11 @@ TestVolumeExecutable::testActiveTileStreaming() openvdb::Index64(NodeT1::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS); - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(voxels / openvdb::FloatTree::LeafNodeType::NUM_VOXELS), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(0), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-1), tree.getValueDepth(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-1), tree.getValueDepth(openvdb::Coord(NodeT1::DIM))); - CPPUNIT_ASSERT_EQUAL(voxels, tree.activeVoxelCount()); + ASSERT_EQ(openvdb::Index32(voxels / openvdb::FloatTree::LeafNodeType::NUM_VOXELS), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(0), tree.activeTileCount()); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-1), tree.getValueDepth(openvdb::Coord(0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-1), tree.getValueDepth(openvdb::Coord(NodeT1::DIM))); + ASSERT_EQ(voxels, tree.activeVoxelCount()); // test values - this isn't strictly necessary for this group of tests // as we really just want to check topology results @@ -416,7 +398,7 @@ TestVolumeExecutable::testActiveTileStreaming() openvdb::tools::foreach(tree.cbeginValueOn(), [&](const auto& it) { const openvdb::Coord& coord = it.getCoord(); const double pos = grid.indexToWorld(coord).x(); - CPPUNIT_ASSERT_EQUAL(*it, float(pos)); + ASSERT_EQ(*it, float(pos)); }); } @@ -432,16 +414,16 @@ TestVolumeExecutable::testActiveTileStreaming() // sets all x == 0 coordinates to 2.0f. These all reside in the NodeT2 tile executable = compiler->compile("int x = getcoordx(); if (x == 0) f@test = 2.0f;"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); executable->execute(grid); @@ -463,18 +445,18 @@ TestVolumeExecutable::testActiveTileStreaming() ((n1ChildCount * (n2ChildAxisCount * n2ChildAxisCount)) - leafs) // NodeT1 face tiles (NodeT0) - leafs + 1 /*NodeT1*/ + 1 /*NodeT0*/; - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(leafs), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(tiles), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(NodeT2::NUM_VOXELS) + + ASSERT_EQ(openvdb::Index32(leafs), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(tiles), tree.activeTileCount()); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM+NodeT1::DIM))); + ASSERT_EQ(openvdb::Index64(NodeT2::NUM_VOXELS) + openvdb::Index64(NodeT1::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS), tree.activeVoxelCount()); openvdb::tools::foreach(tree.cbeginValueOn(), [&](const auto& it) { const openvdb::Coord& coord = it.getCoord(); - if (coord.x() == 0) CPPUNIT_ASSERT_EQUAL(*it, 2.0f); - else CPPUNIT_ASSERT_EQUAL(*it, -1.0f); + if (coord.x() == 0) ASSERT_EQ(*it, 2.0f); + else ASSERT_EQ(*it, -1.0f); }); } @@ -490,43 +472,43 @@ TestVolumeExecutable::testActiveTileStreaming() tree.addTile(1, openvdb::Coord(NodeT2::DIM), -1.0f, /*active*/true); // NodeT0 tile executable = compiler->compile("f@test = 2.0f;"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); // force stream executable->setActiveTileStreaming(openvdb::ax::VolumeExecutable::Streaming::ON); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); executable->execute(grid); - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(0), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(5), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*0, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*1, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*2, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*3, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL((openvdb::Index64(NodeT1::NUM_VOXELS)*4) + + ASSERT_EQ(openvdb::Index32(0), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(5), tree.activeTileCount()); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*0, 0, 0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*1, 0, 0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*2, 0, 0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*3, 0, 0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ((openvdb::Index64(NodeT1::NUM_VOXELS)*4) + openvdb::Index64(NodeT0::NUM_VOXELS), tree.activeVoxelCount()); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*0, 0, 0))); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*1, 0, 0))); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*2, 0, 0))); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*3, 0, 0))); - CPPUNIT_ASSERT_EQUAL(2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*0, 0, 0))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*1, 0, 0))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*2, 0, 0))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT1::DIM*3, 0, 0))); + ASSERT_EQ(2.0f, tree.getValue(openvdb::Coord(NodeT2::DIM))); } // test spatially varying voxelization for bool grids which use specialized implementations @@ -542,15 +524,15 @@ TestVolumeExecutable::testActiveTileStreaming() // sets all x == 0 coordinates to 2.0f. These all reside in the NodeT2 tile executable = compiler->compile("int x = getcoordx(); if (x == 0) bool@test = false;"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::BOOL)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::BoolTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::BoolTree::DEPTH-1), max); executable->execute(grid); @@ -567,19 +549,19 @@ TestVolumeExecutable::testActiveTileStreaming() (n1ChildCount - leafs) // NodeT1 face tiles (NodeT0) - leafs + 3 /*NodeT1*/ + 1 /*NodeT0*/; - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(leafs), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(tiles), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(openvdb::BoolTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*1, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::BoolTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*2, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::BoolTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*3, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::BoolTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL((openvdb::Index64(NodeT1::NUM_VOXELS)*4) + + ASSERT_EQ(openvdb::Index32(leafs), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(tiles), tree.activeTileCount()); + ASSERT_EQ(int(openvdb::BoolTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*1, 0, 0))); + ASSERT_EQ(int(openvdb::BoolTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*2, 0, 0))); + ASSERT_EQ(int(openvdb::BoolTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*3, 0, 0))); + ASSERT_EQ(int(openvdb::BoolTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ((openvdb::Index64(NodeT1::NUM_VOXELS)*4) + openvdb::Index64(NodeT0::NUM_VOXELS), tree.activeVoxelCount()); openvdb::tools::foreach(tree.cbeginValueOn(), [&](const auto& it) { const openvdb::Coord& coord = it.getCoord(); - if (coord.x() == 0) CPPUNIT_ASSERT_EQUAL(*it, false); - else CPPUNIT_ASSERT_EQUAL(*it, true); + if (coord.x() == 0) ASSERT_EQ(*it, false); + else ASSERT_EQ(*it, true); }); } @@ -599,15 +581,15 @@ TestVolumeExecutable::testActiveTileStreaming() // sets all x == 0 coordinates to 2.0f. These all reside in the NodeT2 tile executable = compiler->compile("int x = getcoordx(); if (x == 0) s@test = \"bar\";"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::STRING)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(StringTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(StringTree::DEPTH-1), max); executable->execute(grid); @@ -624,19 +606,19 @@ TestVolumeExecutable::testActiveTileStreaming() (n1ChildCount - leafs) // NodeT1 face tiles (NodeT0) - leafs + 3 /*NodeT1*/ + 1 /*NodeT0*/; - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(leafs), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(tiles), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(int(StringTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*1, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(StringTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*2, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(StringTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*3, 0, 0))); - CPPUNIT_ASSERT_EQUAL(int(StringTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); - CPPUNIT_ASSERT_EQUAL((openvdb::Index64(NodeT1::NUM_VOXELS)*4) + + ASSERT_EQ(openvdb::Index32(leafs), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(tiles), tree.activeTileCount()); + ASSERT_EQ(int(StringTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*1, 0, 0))); + ASSERT_EQ(int(StringTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*2, 0, 0))); + ASSERT_EQ(int(StringTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(NodeT1::DIM*3, 0, 0))); + ASSERT_EQ(int(StringTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT2::DIM))); + ASSERT_EQ((openvdb::Index64(NodeT1::NUM_VOXELS)*4) + openvdb::Index64(NodeT0::NUM_VOXELS), tree.activeVoxelCount()); openvdb::tools::foreach(tree.cbeginValueOn(), [&](const auto& it) { const openvdb::Coord& coord = it.getCoord(); - if (coord.x() == 0) CPPUNIT_ASSERT_EQUAL(*it, std::string("bar")); - else CPPUNIT_ASSERT_EQUAL(*it, std::string("foo")); + if (coord.x() == 0) ASSERT_EQ(*it, std::string("bar")); + else ASSERT_EQ(*it, std::string("foo")); }); } @@ -648,7 +630,7 @@ TestVolumeExecutable::testActiveTileStreaming() tree.addTile(2, openvdb::Coord(0), -1.0f, /*active*/true); // NodeT1 tile tree.addTile(1, openvdb::Coord(NodeT1::DIM), -1.0f, /*active*/true); // NodeT0 tile auto leaf = tree.touchLeaf(openvdb::Coord(NodeT1::DIM + NodeT0::DIM)); - CPPUNIT_ASSERT(leaf); + ASSERT_TRUE(leaf); leaf->fill(-1.0f, true); openvdb::FloatTree copy = tree; @@ -656,35 +638,35 @@ TestVolumeExecutable::testActiveTileStreaming() executable = compiler->compile("f@test = float(getcoordx());"); executable->setValueIterator(openvdb::ax::VolumeExecutable::IterType::OFF); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::STRING)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); executable->execute(grid); - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(1), tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(2), tree.activeTileCount()); - CPPUNIT_ASSERT(tree.hasSameTopology(copy)); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(0))); - CPPUNIT_ASSERT_EQUAL(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT1::DIM))); - CPPUNIT_ASSERT_EQUAL(leaf, tree.probeLeaf(openvdb::Coord(NodeT1::DIM + NodeT0::DIM))); + ASSERT_EQ(openvdb::Index32(1), tree.leafCount()); + ASSERT_EQ(openvdb::Index64(2), tree.activeTileCount()); + ASSERT_TRUE(tree.hasSameTopology(copy)); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-3), tree.getValueDepth(openvdb::Coord(0))); + ASSERT_EQ(int(openvdb::FloatTree::DEPTH-2), tree.getValueDepth(openvdb::Coord(NodeT1::DIM))); + ASSERT_EQ(leaf, tree.probeLeaf(openvdb::Coord(NodeT1::DIM + NodeT0::DIM))); float constant; bool active; - CPPUNIT_ASSERT(leaf->isConstant(constant, active)); - CPPUNIT_ASSERT_EQUAL(-1.0f, constant); - CPPUNIT_ASSERT(active); + ASSERT_TRUE(leaf->isConstant(constant, active)); + ASSERT_EQ(-1.0f, constant); + ASSERT_TRUE(active); openvdb::tools::foreach(tree.cbeginValueOff(), [&](const auto& it) { - CPPUNIT_ASSERT_EQUAL(*it, float(it.getCoord().x())); + ASSERT_EQ(*it, float(it.getCoord().x())); }); openvdb::tools::foreach(tree.cbeginValueOn(), [&](const auto& it) { - CPPUNIT_ASSERT_EQUAL(*it, -1.0f); + ASSERT_EQ(*it, -1.0f); }); // test IterType::ALL @@ -693,21 +675,21 @@ TestVolumeExecutable::testActiveTileStreaming() tree.addTile(2, openvdb::Coord(0), -1.0f, /*active*/true); // NodeT1 tile tree.addTile(1, openvdb::Coord(NodeT1::DIM), -1.0f, /*active*/true); // NodeT0 tile leaf = tree.touchLeaf(openvdb::Coord(NodeT1::DIM + NodeT0::DIM)); - CPPUNIT_ASSERT(leaf); + ASSERT_TRUE(leaf); leaf->fill(-1.0f, /*inactive*/false); executable = compiler->compile("f@test = float(getcoordy());"); executable->setValueIterator(openvdb::ax::VolumeExecutable::IterType::ALL); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::STRING)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); executable->getTreeExecutionLevel(min,max); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(0), min); - CPPUNIT_ASSERT_EQUAL(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); + ASSERT_EQ(openvdb::Index(0), min); + ASSERT_EQ(openvdb::Index(openvdb::FloatTree::DEPTH-1), max); executable->execute(grid); @@ -715,72 +697,70 @@ TestVolumeExecutable::testActiveTileStreaming() openvdb::Index64(NodeT1::NUM_VOXELS) + openvdb::Index64(NodeT0::NUM_VOXELS); - CPPUNIT_ASSERT_EQUAL(openvdb::Index32(voxels / openvdb::FloatTree::LeafNodeType::NUM_VOXELS) + 1, tree.leafCount()); - CPPUNIT_ASSERT_EQUAL(openvdb::Index64(0), tree.activeTileCount()); - CPPUNIT_ASSERT_EQUAL(voxels, tree.activeVoxelCount()); - CPPUNIT_ASSERT_EQUAL(leaf, tree.probeLeaf(openvdb::Coord(NodeT1::DIM + NodeT0::DIM))); - CPPUNIT_ASSERT(leaf->getValueMask().isOff()); + ASSERT_EQ(openvdb::Index32(voxels / openvdb::FloatTree::LeafNodeType::NUM_VOXELS) + 1, tree.leafCount()); + ASSERT_EQ(openvdb::Index64(0), tree.activeTileCount()); + ASSERT_EQ(voxels, tree.activeVoxelCount()); + ASSERT_EQ(leaf, tree.probeLeaf(openvdb::Coord(NodeT1::DIM + NodeT0::DIM))); + ASSERT_TRUE(leaf->getValueMask().isOff()); openvdb::tools::foreach(tree.cbeginValueAll(), [&](const auto& it) { - CPPUNIT_ASSERT_EQUAL(*it, float(it.getCoord().y())); + ASSERT_EQ(*it, float(it.getCoord().y())); }); } // test auto streaming { executable = compiler->compile("f@test = f@other; v@test2 = 1; v@test3 = v@test2;"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::AUTO == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::AUTO == executable->getActiveTileStreaming()); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming("other", openvdb::ax::ast::tokens::CoreType::FLOAT)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::OFF == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::OFF == executable->getActiveTileStreaming("test2", openvdb::ax::ast::tokens::CoreType::VEC3F)); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming("test3", openvdb::ax::ast::tokens::CoreType::VEC3F)); // - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::AUTO == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::AUTO == executable->getActiveTileStreaming("empty", openvdb::ax::ast::tokens::CoreType::FLOAT)); } // test that some particular functions cause streaming to turn on executable = compiler->compile("f@test = rand();"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); executable = compiler->compile("v@test = getcoord();"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); executable = compiler->compile("f@test = getcoordx();"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); executable = compiler->compile("f@test = getcoordy();"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); executable = compiler->compile("f@test = getcoordz();"); - CPPUNIT_ASSERT(openvdb::ax::VolumeExecutable::Streaming::ON == + ASSERT_TRUE(openvdb::ax::VolumeExecutable::Streaming::ON == executable->getActiveTileStreaming()); } - -void -TestVolumeExecutable::testCompilerCases() +TEST_F(TestVolumeExecutable, testCompilerCases) { openvdb::ax::Compiler::UniquePtr compiler = openvdb::ax::Compiler::create(); - CPPUNIT_ASSERT(compiler); + ASSERT_TRUE(compiler); { // with string only - CPPUNIT_ASSERT(static_cast(compiler->compile("int i;"))); - CPPUNIT_ASSERT_THROW(compiler->compile("i;"), openvdb::AXCompilerError); - CPPUNIT_ASSERT_THROW(compiler->compile("i"), openvdb::AXSyntaxError); + ASSERT_TRUE(static_cast(compiler->compile("int i;"))); + ASSERT_THROW(compiler->compile("i;"), openvdb::AXCompilerError); + ASSERT_THROW(compiler->compile("i"), openvdb::AXSyntaxError); // with AST only auto ast = openvdb::ax::ast::parse("i;"); - CPPUNIT_ASSERT_THROW(compiler->compile(*ast), openvdb::AXCompilerError); + ASSERT_THROW(compiler->compile(*ast), openvdb::AXCompilerError); } openvdb::ax::Logger logger([](const std::string&) {}); @@ -789,68 +769,68 @@ TestVolumeExecutable::testCompilerCases() { openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("", logger); // empty - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); } logger.clear(); { openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("i;", logger); // undeclared variable error - CPPUNIT_ASSERT(!executable); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable); + ASSERT_TRUE(logger.hasError()); logger.clear(); openvdb::ax::VolumeExecutable::Ptr executable2 = compiler->compile("i", logger); // expected ; error (parser) - CPPUNIT_ASSERT(!executable2); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable2); + ASSERT_TRUE(logger.hasError()); } logger.clear(); { openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("int i = 18446744073709551615;", logger); // warning - CPPUNIT_ASSERT(executable); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable); + ASSERT_TRUE(logger.hasWarning()); } // using syntax tree and logger logger.clear(); { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("", logger); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile(*tree, logger); // empty - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); logger.clear(); // no tree for line col numbers openvdb::ax::VolumeExecutable::Ptr executable2 = compiler->compile(*tree, logger); // empty - CPPUNIT_ASSERT(executable2); + ASSERT_TRUE(executable2); } logger.clear(); { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("i;", logger); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile(*tree, logger); // undeclared variable error - CPPUNIT_ASSERT(!executable); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable); + ASSERT_TRUE(logger.hasError()); logger.clear(); // no tree for line col numbers openvdb::ax::VolumeExecutable::Ptr executable2 = compiler->compile(*tree, logger); // undeclared variable error - CPPUNIT_ASSERT(!executable2); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable2); + ASSERT_TRUE(logger.hasError()); } logger.clear(); { openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse("int i = 18446744073709551615;", logger); - CPPUNIT_ASSERT(tree); + ASSERT_TRUE(tree); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile(*tree, logger); // warning - CPPUNIT_ASSERT(executable); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable); + ASSERT_TRUE(logger.hasWarning()); logger.clear(); // no tree for line col numbers openvdb::ax::VolumeExecutable::Ptr executable2 = compiler->compile(*tree, logger); // warning - CPPUNIT_ASSERT(executable2); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable2); + ASSERT_TRUE(logger.hasWarning()); } logger.clear(); @@ -860,7 +840,7 @@ TestVolumeExecutable::testCompilerCases() std::unique_ptr copy(tree->copy()); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile(*copy, logger); // empty - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); } logger.clear(); { @@ -868,8 +848,8 @@ TestVolumeExecutable::testCompilerCases() std::unique_ptr copy(tree->copy()); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile(*copy, logger); // undeclared variable error - CPPUNIT_ASSERT(!executable); - CPPUNIT_ASSERT(logger.hasError()); + ASSERT_TRUE(!executable); + ASSERT_TRUE(logger.hasError()); } logger.clear(); { @@ -877,14 +857,13 @@ TestVolumeExecutable::testCompilerCases() std::unique_ptr copy(tree->copy()); openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile(*copy, logger); // warning - CPPUNIT_ASSERT(executable); - CPPUNIT_ASSERT(logger.hasWarning()); + ASSERT_TRUE(executable); + ASSERT_TRUE(logger.hasWarning()); } logger.clear(); } -void -TestVolumeExecutable::testExecuteBindings() +TEST_F(TestVolumeExecutable, testExecuteBindings) { openvdb::ax::Compiler::UniquePtr compiler = openvdb::ax::Compiler::create(); @@ -900,11 +879,11 @@ TestVolumeExecutable::testExecuteBindings() openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); executable->setAttributeBindings(bindings); executable->setCreateMissing(false); - CPPUNIT_ASSERT_NO_THROW(executable->execute(v)); - CPPUNIT_ASSERT_EQUAL(1.0f, f1->tree().getValue({0,0,0})); + ASSERT_NO_THROW(executable->execute(v)); + ASSERT_EQ(1.0f, f1->tree().getValue({0,0,0})); } // binding to existing attribute AND not binding to attribute @@ -919,12 +898,12 @@ TestVolumeExecutable::testExecuteBindings() openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); executable->setAttributeBindings(bindings); executable->setCreateMissing(false); - CPPUNIT_ASSERT_NO_THROW(executable->execute(v)); - CPPUNIT_ASSERT_EQUAL(1.0f, f1->tree().getValue({0,0,0})); - CPPUNIT_ASSERT_EQUAL(2.0f, f2->tree().getValue({0,0,0})); + ASSERT_NO_THROW(executable->execute(v)); + ASSERT_EQ(1.0f, f1->tree().getValue({0,0,0})); + ASSERT_EQ(2.0f, f2->tree().getValue({0,0,0})); } // binding to new created attribute AND not binding to new created attribute @@ -936,11 +915,11 @@ TestVolumeExecutable::testExecuteBindings() openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); executable->setAttributeBindings(bindings); - CPPUNIT_ASSERT_NO_THROW(executable->execute(v)); - CPPUNIT_ASSERT_EQUAL(2.0f, f2->tree().getValue({0,0,0})); - CPPUNIT_ASSERT_EQUAL(size_t(2), v.size()); + ASSERT_NO_THROW(executable->execute(v)); + ASSERT_EQ(2.0f, f2->tree().getValue({0,0,0})); + ASSERT_EQ(size_t(2), v.size()); } // binding to non existent attribute, not creating, error @@ -952,10 +931,10 @@ TestVolumeExecutable::testExecuteBindings() openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); executable->setAttributeBindings(bindings); executable->setCreateMissing(false); - CPPUNIT_ASSERT_THROW(executable->execute(v), openvdb::AXExecutionError); + ASSERT_THROW(executable->execute(v), openvdb::AXExecutionError); } // trying to bind to an attribute and use the original attribute name at same time @@ -966,10 +945,10 @@ TestVolumeExecutable::testExecuteBindings() std::vector v { f2 }; openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","c"); // bind b to c - CPPUNIT_ASSERT_THROW(executable->setAttributeBindings(bindings), openvdb::AXExecutionError); + ASSERT_THROW(executable->setAttributeBindings(bindings), openvdb::AXExecutionError); } // swap ax and data attributes with bindings @@ -980,40 +959,39 @@ TestVolumeExecutable::testExecuteBindings() std::vector v { f2 }; openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f; @c = 2.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","c"); // bind b to c bindings.set("c","b"); // bind c to b - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); - CPPUNIT_ASSERT_NO_THROW(executable->execute(v)); - CPPUNIT_ASSERT_EQUAL(1.0f, f2->tree().getValue({0,0,0})); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->execute(v)); + ASSERT_EQ(1.0f, f2->tree().getValue({0,0,0})); } // test setting bindings and then resetting some of those bindings on the same executable { openvdb::ax::VolumeExecutable::Ptr executable = compiler->compile("@b = 1.0f; @a = 2.0f; @c = 3.0f;"); - CPPUNIT_ASSERT(executable); + ASSERT_TRUE(executable); openvdb::ax::AttributeBindings bindings; bindings.set("b","a"); // bind b to a bindings.set("c","b"); // bind c to b bindings.set("a","c"); // bind a to c - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); bindings.set("a","b"); // bind a to b bindings.set("b","a"); // bind a to b - CPPUNIT_ASSERT(!bindings.dataNameBoundTo("c")); // c should be unbound + ASSERT_TRUE(!bindings.dataNameBoundTo("c")); // c should be unbound // check that the set call resets c to c - CPPUNIT_ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); + ASSERT_NO_THROW(executable->setAttributeBindings(bindings)); const openvdb::ax::AttributeBindings& bindingsOnExecutable = executable->getAttributeBindings(); - CPPUNIT_ASSERT(bindingsOnExecutable.isBoundAXName("c")); - CPPUNIT_ASSERT_EQUAL(*bindingsOnExecutable.dataNameBoundTo("c"), std::string("c")); + ASSERT_TRUE(bindingsOnExecutable.isBoundAXName("c")); + ASSERT_EQ(*bindingsOnExecutable.dataNameBoundTo("c"), std::string("c")); } } -void -TestVolumeExecutable::testCLI() +TEST_F(TestVolumeExecutable, testCLI) { using namespace openvdb; using CLI = openvdb::ax::VolumeExecutable::CLI; @@ -1066,175 +1044,175 @@ TestVolumeExecutable::testCLI() const auto defaultTileGrain = defaultExe->getActiveTileStreamingGrainSize(); const auto defaultBindings = defaultExe->getAttributeBindings(); - CPPUNIT_ASSERT_THROW(CreateCLI("--unknown"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("-unknown"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("-"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("--"), UnusedCLIParam); - CPPUNIT_ASSERT_THROW(CreateCLI("-- "), UnusedCLIParam); + ASSERT_THROW(CreateCLI("--unknown"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("-unknown"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("-"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("--"), UnusedCLIParam); + ASSERT_THROW(CreateCLI("-- "), UnusedCLIParam); { CLI cli = CreateCLI(""); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --create-missing { - CPPUNIT_ASSERT_THROW(CreateCLI("--create-missing"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--create-missing invalid"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--create-missing --group test"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--create-missing"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--create-missing invalid"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--create-missing --group test"), openvdb::CLIError); CLI cli = CreateCLI("--create-missing ON"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(true, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(true, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --tile-stream { - CPPUNIT_ASSERT_THROW(CreateCLI("--tile-stream"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--tile-stream invalid"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--tile-stream --group test"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--tile-stream"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--tile-stream invalid"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--tile-stream --group test"), openvdb::CLIError); CLI cli = CreateCLI("--tile-stream ON"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(openvdb::ax::VolumeExecutable::Streaming::ON, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(openvdb::ax::VolumeExecutable::Streaming::ON, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --node-iter { - CPPUNIT_ASSERT_THROW(CreateCLI("--node-iter"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--node-iter invalid"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--node-iter --group test"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--node-iter"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--node-iter invalid"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--node-iter --group test"), openvdb::CLIError); CLI cli = CreateCLI("--node-iter ALL"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(openvdb::ax::VolumeExecutable::IterType::ALL, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(openvdb::ax::VolumeExecutable::IterType::ALL, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --tree-level { - CPPUNIT_ASSERT_THROW(CreateCLI("--tree-level"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--tree-level invalid"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--tree-level --group test"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--tree-level"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--tree-level invalid"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--tree-level --group test"), openvdb::CLIError); CLI cli = CreateCLI("--tree-level 0"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(min, Index(0)); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(min, Index(0)); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); cli = CreateCLI("--tree-level 1:2"); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(min, Index(1)); - CPPUNIT_ASSERT_EQUAL(max, Index(2)); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(min, Index(1)); + ASSERT_EQ(max, Index(2)); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --tree-level { - CPPUNIT_ASSERT_THROW(CreateCLI("--volume-grain"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--volume-grain invalid"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--volume-grain --group test"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--volume-grain"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--volume-grain invalid"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--volume-grain --group test"), openvdb::CLIError); CLI cli = CreateCLI("--volume-grain 0"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(size_t(0), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(size_t(0), exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); cli = CreateCLI("--volume-grain 1:2"); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(size_t(1), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(size_t(2), exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(size_t(1), exe->getGrainSize()); + ASSERT_EQ(size_t(2), exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); } // --bindings { - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings :"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings ,"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings a:"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings a,b"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings :b"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings ,a:b"), openvdb::CLIError); - CPPUNIT_ASSERT_THROW(CreateCLI("--bindings --create-missing ON"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings :"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings ,"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings a:"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings a,b"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings :b"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings ,a:b"), openvdb::CLIError); + ASSERT_THROW(CreateCLI("--bindings --create-missing ON"), openvdb::CLIError); CLI cli = CreateCLI("--bindings a:b,c:d,12:13"); ax::AttributeBindings bindings; @@ -1243,50 +1221,54 @@ TestVolumeExecutable::testCLI() bindings.set("12", "13"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(defaultCreateMissing, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(defaultGrain, exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(bindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(defaultCreateMissing, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(defaultGrain, exe->getGrainSize()); + ASSERT_EQ(defaultTileGrain, exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(bindings, exe->getAttributeBindings()); } // multiple { CLI cli = CreateCLI("--volume-grain 5:10 --create-missing OFF"); auto exe = compiler->compile(""); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); Index min,max; exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(defaultMinLevel, min); - CPPUNIT_ASSERT_EQUAL(defaultMaxLevel, max); - CPPUNIT_ASSERT_EQUAL(false, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(defaultTileStream, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(defaultValueIter, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(size_t(5), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(size_t(10), exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(defaultBindings, exe->getAttributeBindings()); + ASSERT_EQ(defaultMinLevel, min); + ASSERT_EQ(defaultMaxLevel, max); + ASSERT_EQ(false, exe->getCreateMissing()); + ASSERT_EQ(defaultTileStream, exe->getActiveTileStreaming()); + ASSERT_EQ(defaultValueIter, exe->getValueIterator()); + ASSERT_EQ(size_t(5), exe->getGrainSize()); + ASSERT_EQ(size_t(10), exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(defaultBindings, exe->getAttributeBindings()); cli = CreateCLI("--tile-stream ON --node-iter OFF --tree-level 2:3 --volume-grain 10:20 --create-missing ON --bindings a:b"); ax::AttributeBindings bindings; bindings.set("a", "b"); - CPPUNIT_ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); + ASSERT_NO_THROW(exe->setSettingsFromCLI(cli)); exe->getTreeExecutionLevel(min, max); - CPPUNIT_ASSERT_EQUAL(Index(2), min); - CPPUNIT_ASSERT_EQUAL(Index(3), max); - CPPUNIT_ASSERT_EQUAL(true, exe->getCreateMissing()); - CPPUNIT_ASSERT_EQUAL(openvdb::ax::VolumeExecutable::Streaming::ON, exe->getActiveTileStreaming()); - CPPUNIT_ASSERT_EQUAL(openvdb::ax::VolumeExecutable::IterType::OFF, exe->getValueIterator()); - CPPUNIT_ASSERT_EQUAL(size_t(10), exe->getGrainSize()); - CPPUNIT_ASSERT_EQUAL(size_t(20), exe->getActiveTileStreamingGrainSize()); - CPPUNIT_ASSERT_EQUAL(bindings, exe->getAttributeBindings()); + ASSERT_EQ(Index(2), min); + ASSERT_EQ(Index(3), max); + ASSERT_EQ(true, exe->getCreateMissing()); + ASSERT_EQ(openvdb::ax::VolumeExecutable::Streaming::ON, exe->getActiveTileStreaming()); + ASSERT_EQ(openvdb::ax::VolumeExecutable::IterType::OFF, exe->getValueIterator()); + ASSERT_EQ(size_t(10), exe->getGrainSize()); + ASSERT_EQ(size_t(20), exe->getActiveTileStreamingGrainSize()); + ASSERT_EQ(bindings, exe->getAttributeBindings()); } } + +} // namespace ax +} // namespace OPENVDB_VERSION_NAME +} // namespace openvdb From 4ca8cc0240b5e069c06557d061f6ec55c90e933d Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 18 Oct 2024 13:18:56 -0700 Subject: [PATCH 17/21] Convert TestArrayPack.cc to use gtest; add temporary support for both gtest and cppunit to test/util.h Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/frontend/TestArrayPack.cc | 27 ++++++--------- openvdb_ax/openvdb_ax/test/util.h | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc b/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc index 51adcf113c..138ae9f415 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -116,34 +116,29 @@ static const unittest_util::CodeTests tests = } -class TestArrayPack : public CppUnit::TestCase +class TestArrayPack : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestArrayPack); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - void testSyntax() { TEST_SYNTAX_PASSES(tests); } void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestArrayPack); +TEST_F(TestArrayPack, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestArrayPack::testASTNode() +TEST_F(TestArrayPack, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::ArrayPackNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::ArrayPackNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -155,7 +150,7 @@ void TestArrayPack::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Array Pack code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Array Pack code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/util.h b/openvdb_ax/openvdb_ax/test/util.h index 0494944460..8b0e5b5519 100644 --- a/openvdb_ax/openvdb_ax/test/util.h +++ b/openvdb_ax/openvdb_ax/test/util.h @@ -27,6 +27,38 @@ #define ERROR_MSG(Msg, Code) Msg + std::string(": \"") + Code + std::string("\"") +// TEMPORARY transitional measure to switch from +// CPPUnit to GoogleTest incrementally. If gtest +// has been included, use its assertion macros, +// otherwise, fallback to CPPUnit macros. +// TODO: replace with just gtest macros once CPPUnit is unused +#ifdef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ // gtest.h has been included + +#define TEST_SYNTAX_PASSES(Tests) \ +{ \ + openvdb::ax::Logger logger;\ + for (const auto& test : Tests) { \ + logger.clear();\ + const std::string& code = test.first; \ + openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(code.c_str(), logger);\ + std::stringstream str; \ + ASSERT_TRUE(tree && !logger.hasError()) << ERROR_MSG("Unexpected parsing error(s)\n", str.str());\ + } \ +} \ + +#define TEST_SYNTAX_FAILS(Tests) \ +{ \ + openvdb::ax::Logger logger([](const std::string&) {});\ + for (const auto& test : Tests) { \ + logger.clear();\ + const std::string& code = test.first; \ + openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(code.c_str(), logger);\ + ASSERT_TRUE(!tree && logger.hasError()) << ERROR_MSG("Expected parsing error", code); \ + } \ +} \ + +#else // if gtest.h has not been included + #define TEST_SYNTAX_PASSES(Tests) \ { \ openvdb::ax::Logger logger;\ @@ -50,6 +82,8 @@ } \ } \ +#endif // gtest.h has not been included + namespace unittest_util { // Use shared pointers rather than unique pointers so initializer lists can easily From c032483378bd97ca9de9c3358109a947d672725d Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Fri, 18 Oct 2024 14:24:35 -0700 Subject: [PATCH 18/21] Convert all of AX frontend test suite to use gtest; remove temporary cppunit dual support from utils.h Signed-off-by: Tim Straubinger --- .../test/frontend/TestArrayUnpackNode.cc | 29 ++++++--------- .../test/frontend/TestAssignExpressionNode.cc | 29 ++++++--------- .../test/frontend/TestAttributeNode.cc | 29 ++++++--------- .../test/frontend/TestBinaryOperatorNode.cc | 29 ++++++--------- .../openvdb_ax/test/frontend/TestCastNode.cc | 29 ++++++--------- .../test/frontend/TestCommaOperator.cc | 29 ++++++--------- .../frontend/TestConditionalStatementNode.cc | 29 ++++++--------- .../test/frontend/TestCrementNode.cc | 29 ++++++--------- .../test/frontend/TestDeclareLocalNode.cc | 29 ++++++--------- .../test/frontend/TestExternalVariableNode.cc | 29 ++++++--------- .../test/frontend/TestFunctionCallNode.cc | 29 ++++++--------- .../test/frontend/TestKeywordNode.cc | 31 +++++++--------- .../openvdb_ax/test/frontend/TestLocalNode.cc | 29 ++++++--------- .../openvdb_ax/test/frontend/TestLoopNode.cc | 29 ++++++--------- .../test/frontend/TestStatementListNode.cc | 29 ++++++--------- .../test/frontend/TestSyntaxFailures.cc | 15 ++------ .../test/frontend/TestTernaryOperatorNode.cc | 29 ++++++--------- .../test/frontend/TestUnaryOperatorNode.cc | 29 ++++++--------- .../openvdb_ax/test/frontend/TestValueNode.cc | 35 +++++++------------ openvdb_ax/openvdb_ax/test/util.h | 34 ------------------ 20 files changed, 204 insertions(+), 375 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestArrayUnpackNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestArrayUnpackNode.cc index dcc4a60661..cd387813a5 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestArrayUnpackNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestArrayUnpackNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -107,34 +107,27 @@ static const unittest_util::CodeTests tests = } -class TestArrayUnpackNode : public CppUnit::TestCase +class TestArrayUnpackNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestArrayUnpackNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestArrayUnpackNode); +TEST_F(TestArrayUnpackNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestArrayUnpackNode::testASTNode() +TEST_F(TestArrayUnpackNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::ArrayUnpackNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::ArrayUnpackNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -146,7 +139,7 @@ void TestArrayUnpackNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Array Unpack code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Array Unpack code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestAssignExpressionNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestAssignExpressionNode.cc index b6ab887619..f128fbd453 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestAssignExpressionNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestAssignExpressionNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -226,34 +226,27 @@ unittest_util::CodeTests tests = } -class TestAssignExpressionNode : public CppUnit::TestCase +class TestAssignExpressionNode : public ::testing::Test { - public: - - CPPUNIT_TEST_SUITE(TestAssignExpressionNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestAssignExpressionNode); +TEST_F(TestAssignExpressionNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestAssignExpressionNode::testASTNode() +TEST_F(TestAssignExpressionNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::AssignExpressionNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::AssignExpressionNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -265,7 +258,7 @@ void TestAssignExpressionNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Assign Expression code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Assign Expression code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestAttributeNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestAttributeNode.cc index 5e4e06b233..94b4ed6dd1 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestAttributeNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestAttributeNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -49,34 +49,27 @@ static const unittest_util::CodeTests tests = } -class TestAttributeNode : public CppUnit::TestCase +class TestAttributeNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestAttributeNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestAttributeNode); +TEST_F(TestAttributeNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestAttributeNode::testASTNode() +TEST_F(TestAttributeNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::AttributeNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::AttributeNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -88,7 +81,7 @@ void TestAttributeNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Attribute code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Attribute code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestBinaryOperatorNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestBinaryOperatorNode.cc index 15a904df83..410c908b41 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestBinaryOperatorNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestBinaryOperatorNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -295,34 +295,27 @@ static const unittest_util::CodeTests tests = } -class TestBinaryOperatorNode : public CppUnit::TestCase +class TestBinaryOperatorNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestBinaryOperatorNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestBinaryOperatorNode); +TEST_F(TestBinaryOperatorNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestBinaryOperatorNode::testASTNode() +TEST_F(TestBinaryOperatorNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::BinaryOperatorNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::BinaryOperatorNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -334,7 +327,7 @@ void TestBinaryOperatorNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Binary Operator code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Binary Operator code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestCastNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestCastNode.cc index 37b9438fbe..bbe664f0bb 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestCastNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestCastNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -49,34 +49,27 @@ static const unittest_util::CodeTests tests = } -class TestCastNode : public CppUnit::TestCase +class TestCastNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestCastNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestCastNode); +TEST_F(TestCastNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestCastNode::testASTNode() +TEST_F(TestCastNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::CastNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::CastNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -88,7 +81,7 @@ void TestCastNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Cast code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Cast code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestCommaOperator.cc b/openvdb_ax/openvdb_ax/test/frontend/TestCommaOperator.cc index 6c56b59f17..2d003c5160 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestCommaOperator.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestCommaOperator.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -113,34 +113,27 @@ static const unittest_util::CodeTests tests = } -class TestCommaOperator : public CppUnit::TestCase +class TestCommaOperator : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestCommaOperator); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestCommaOperator); +TEST_F(TestCommaOperator, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestCommaOperator::testASTNode() +TEST_F(TestCommaOperator, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::CommaOperatorNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::CommaOperatorNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -152,7 +145,7 @@ void TestCommaOperator::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Comma Operator code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Comma Operator code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestConditionalStatementNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestConditionalStatementNode.cc index 7f0d4149cf..7a7d4a09f5 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestConditionalStatementNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestConditionalStatementNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -286,34 +286,27 @@ static const unittest_util::CodeTests tests = } -class TestConditionalStatementNode : public CppUnit::TestCase +class TestConditionalStatementNode : public ::testing::Test { - public: - - CPPUNIT_TEST_SUITE(TestConditionalStatementNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestConditionalStatementNode); +TEST_F(TestConditionalStatementNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestConditionalStatementNode::testASTNode() +TEST_F(TestConditionalStatementNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::ConditionalStatementNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::ConditionalStatementNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -325,7 +318,7 @@ void TestConditionalStatementNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Conditional Statement code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Conditional Statement code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestCrementNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestCrementNode.cc index 9c8903feef..15faed444a 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestCrementNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestCrementNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -31,34 +31,27 @@ static const unittest_util::CodeTests tests = } -class TestCrementNode : public CppUnit::TestCase +class TestCrementNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestCrementNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests) }; - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestCrementNode); +TEST_F(TestCrementNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +}; -void TestCrementNode::testASTNode() +TEST_F(TestCrementNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::CrementNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::CrementNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -70,7 +63,7 @@ void TestCrementNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Crement code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Crement code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestDeclareLocalNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestDeclareLocalNode.cc index 73b91f732e..a81c91f3c9 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestDeclareLocalNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestDeclareLocalNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -69,34 +69,27 @@ static const unittest_util::CodeTests tests = } -class TestDeclareLocalNode : public CppUnit::TestCase +class TestDeclareLocalNode : public ::testing::Test { - public: - - CPPUNIT_TEST_SUITE(TestDeclareLocalNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestDeclareLocalNode); +TEST_F(TestDeclareLocalNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestDeclareLocalNode::testASTNode() +TEST_F(TestDeclareLocalNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::DeclareLocalNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::DeclareLocalNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -108,7 +101,7 @@ void TestDeclareLocalNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Declaration code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Declaration code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestExternalVariableNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestExternalVariableNode.cc index 5776fa0094..730d36ce14 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestExternalVariableNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestExternalVariableNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -38,34 +38,27 @@ static const unittest_util::CodeTests tests = } -class TestExternalVariableNode : public CppUnit::TestCase +class TestExternalVariableNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestExternalVariableNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestExternalVariableNode); +TEST_F(TestExternalVariableNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestExternalVariableNode::testASTNode() +TEST_F(TestExternalVariableNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::ExternalVariableNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::ExternalVariableNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -77,7 +70,7 @@ void TestExternalVariableNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for External Variable code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for External Variable code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestFunctionCallNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestFunctionCallNode.cc index 0a08083c29..24138029d8 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestFunctionCallNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestFunctionCallNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -111,34 +111,27 @@ static const unittest_util::CodeTests tests = } -class TestFunctionCallNode : public CppUnit::TestCase +class TestFunctionCallNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestFunctionCallNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestFunctionCallNode); +TEST_F(TestFunctionCallNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestFunctionCallNode::testASTNode() +TEST_F(TestFunctionCallNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::FunctionCallNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::FunctionCallNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -150,7 +143,7 @@ void TestFunctionCallNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Function Call code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Function Call code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestKeywordNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestKeywordNode.cc index 8834282233..f22ae5fce4 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestKeywordNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestKeywordNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -26,36 +26,29 @@ static const unittest_util::CodeTests tests = } -class TestKeywordNode : public CppUnit::TestCase +class TestKeywordNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestKeywordNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestKeywordNode); +TEST_F(TestKeywordNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestKeywordNode::testASTNode() +TEST_F(TestKeywordNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); + ASSERT_TRUE(result); const Keyword* resultAsKeyword = static_cast(result); - CPPUNIT_ASSERT(resultAsKeyword); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::KeywordNode == result->nodetype()); + ASSERT_TRUE(resultAsKeyword); + ASSERT_TRUE(Node::KeywordNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -67,7 +60,7 @@ void TestKeywordNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Return code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Return code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestLocalNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestLocalNode.cc index 3cf6bd2a6e..6cf9b28269 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestLocalNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestLocalNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -34,34 +34,27 @@ static const unittest_util::CodeTests tests = } -class TestLocalNode : public CppUnit::TestCase +class TestLocalNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestLocalNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestLocalNode); +TEST_F(TestLocalNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestLocalNode::testASTNode() +TEST_F(TestLocalNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::LocalNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::LocalNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -73,7 +66,7 @@ void TestLocalNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Local code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Local code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestLoopNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestLoopNode.cc index 7a10818527..b0012a16ae 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestLoopNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestLoopNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -308,34 +308,27 @@ static const unittest_util::CodeTests tests = } -class TestLoopNode : public CppUnit::TestCase +class TestLoopNode : public ::testing::Test { - public: - - CPPUNIT_TEST_SUITE(TestLoopNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestLoopNode); +TEST_F(TestLoopNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestLoopNode::testASTNode() +TEST_F(TestLoopNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::LoopNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::LoopNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -347,7 +340,7 @@ void TestLoopNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Loop code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Loop code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestStatementListNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestStatementListNode.cc index ee8a47af31..318d1cdad6 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestStatementListNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestStatementListNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -66,34 +66,27 @@ static const unittest_util::CodeTests tests = } -class TestStatementList : public CppUnit::TestCase +class TestStatementList : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestStatementList); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestStatementList); +TEST_F(TestStatementList, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestStatementList::testASTNode() +TEST_F(TestStatementList, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::StatementListNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::StatementListNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -105,7 +98,7 @@ void TestStatementList::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Statement List code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Statement List code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestSyntaxFailures.cc b/openvdb_ax/openvdb_ax/test/frontend/TestSyntaxFailures.cc index 6179df57f1..2b920f9871 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestSyntaxFailures.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestSyntaxFailures.cc @@ -11,7 +11,7 @@ #include #include -#include +#include namespace { @@ -590,20 +590,11 @@ static const std::vector tests { } -class TestSyntaxFailures : public CppUnit::TestCase +class TestSyntaxFailures : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestSyntaxFailures); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestSyntaxFailures); - -void TestSyntaxFailures::testSyntax() +TEST_F(TestSyntaxFailures, testSyntax) { // Quickly check the above doesn't have multiple occurrence // store multiple in a hash map diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestTernaryOperatorNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestTernaryOperatorNode.cc index 641c4f9549..6a8ba05899 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestTernaryOperatorNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestTernaryOperatorNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -82,34 +82,27 @@ static const unittest_util::CodeTests tests = } -class TestTernaryOperatorNode : public CppUnit::TestCase +class TestTernaryOperatorNode : public ::testing::Test { - public: - - CPPUNIT_TEST_SUITE(TestTernaryOperatorNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestTernaryOperatorNode); +TEST_F(TestTernaryOperatorNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestTernaryOperatorNode::testASTNode() +TEST_F(TestTernaryOperatorNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::TernaryOperatorNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::TernaryOperatorNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -121,7 +114,7 @@ void TestTernaryOperatorNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Ternary Operator code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Ternary Operator code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestUnaryOperatorNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestUnaryOperatorNode.cc index 7c8999fbc6..2aec206c60 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestUnaryOperatorNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestUnaryOperatorNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include @@ -88,34 +88,27 @@ static const unittest_util::CodeTests tests = } -class TestUnaryOperatorNode : public CppUnit::TestCase +class TestUnaryOperatorNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestUnaryOperatorNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestUnaryOperatorNode); +TEST_F(TestUnaryOperatorNode, testSyntax) +{ + TEST_SYNTAX_PASSES(tests); +} -void TestUnaryOperatorNode::testASTNode() +TEST_F(TestUnaryOperatorNode, testASTNode) { for (const auto& test : tests) { const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - Node::UnaryOperatorNode == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(Node::UnaryOperatorNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -127,7 +120,7 @@ void TestUnaryOperatorNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Unary Operator code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Unary Operator code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestValueNode.cc b/openvdb_ax/openvdb_ax/test/frontend/TestValueNode.cc index 3c7597ea14..2c016aada6 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestValueNode.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestValueNode.cc @@ -8,7 +8,7 @@ #include "../util.h" -#include +#include #include #include @@ -157,26 +157,18 @@ static const CodeTestMap value_tests = } -class TestValueNode : public CppUnit::TestCase +class TestValueNode : public ::testing::Test { -public: - - CPPUNIT_TEST_SUITE(TestValueNode); - CPPUNIT_TEST(testSyntax); - CPPUNIT_TEST(testASTNode); - CPPUNIT_TEST_SUITE_END(); - - void testSyntax() { - for (const auto& tests : value_tests) { - TEST_SYNTAX_PASSES(tests.second); - } - } - void testASTNode(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestValueNode); +TEST_F(TestValueNode, testSyntax) +{ + for (const auto& tests : value_tests) { + TEST_SYNTAX_PASSES(tests.second); + } +} -void TestValueNode::testASTNode() +TEST_F(TestValueNode, testASTNode) { for (const auto& tests : value_tests) { const Node::NodeType nodeType = tests.first; @@ -184,13 +176,12 @@ void TestValueNode::testASTNode() const std::string& code = test.first; const Node* expected = test.second.get(); const Tree::ConstPtr tree = parse(code.c_str()); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast(tree)); + ASSERT_TRUE(static_cast(tree)) << ERROR_MSG("No AST returned", code); // get the first statement const Node* result = tree->child(0)->child(0); - CPPUNIT_ASSERT(result); - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code), - nodeType == result->nodetype()); + ASSERT_TRUE(result); + ASSERT_TRUE(nodeType == result->nodetype()) << ERROR_MSG("Invalid AST node", code); std::vector resultList, expectedList; linearize(*result, resultList); @@ -202,7 +193,7 @@ void TestValueNode::testASTNode() openvdb::ax::ast::print(*expected, true, os); os << "Result:\n"; openvdb::ax::ast::print(*result, true, os); - CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Value (literal) code", code) + os.str()); + FAIL() << ERROR_MSG("Mismatching Trees for Value (literal) code", code) + os.str(); } } } diff --git a/openvdb_ax/openvdb_ax/test/util.h b/openvdb_ax/openvdb_ax/test/util.h index 8b0e5b5519..f621f088d1 100644 --- a/openvdb_ax/openvdb_ax/test/util.h +++ b/openvdb_ax/openvdb_ax/test/util.h @@ -27,13 +27,6 @@ #define ERROR_MSG(Msg, Code) Msg + std::string(": \"") + Code + std::string("\"") -// TEMPORARY transitional measure to switch from -// CPPUnit to GoogleTest incrementally. If gtest -// has been included, use its assertion macros, -// otherwise, fallback to CPPUnit macros. -// TODO: replace with just gtest macros once CPPUnit is unused -#ifdef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ // gtest.h has been included - #define TEST_SYNTAX_PASSES(Tests) \ { \ openvdb::ax::Logger logger;\ @@ -57,33 +50,6 @@ } \ } \ -#else // if gtest.h has not been included - -#define TEST_SYNTAX_PASSES(Tests) \ -{ \ - openvdb::ax::Logger logger;\ - for (const auto& test : Tests) { \ - logger.clear();\ - const std::string& code = test.first; \ - openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(code.c_str(), logger);\ - std::stringstream str; \ - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Unexpected parsing error(s)\n", str.str()), tree && !logger.hasError()); \ - } \ -} \ - -#define TEST_SYNTAX_FAILS(Tests) \ -{ \ - openvdb::ax::Logger logger([](const std::string&) {});\ - for (const auto& test : Tests) { \ - logger.clear();\ - const std::string& code = test.first; \ - openvdb::ax::ast::Tree::ConstPtr tree = openvdb::ax::ast::parse(code.c_str(), logger);\ - CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Expected parsing error", code), !tree && logger.hasError()); \ - } \ -} \ - -#endif // gtest.h has not been included - namespace unittest_util { // Use shared pointers rather than unique pointers so initializer lists can easily From 81ce1acee0e711d891f2f02367a6f3d29390a5af Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Mon, 28 Oct 2024 16:14:56 -0700 Subject: [PATCH 19/21] Convert all of AX integration test suite to use gtest Signed-off-by: Tim Straubinger --- .../openvdb_ax/test/frontend/TestArrayPack.cc | 2 - .../test/integration/TestArrayUnpack.cc | 23 +- .../openvdb_ax/test/integration/TestAssign.cc | 60 +--- .../openvdb_ax/test/integration/TestBinary.cc | 110 ++---- .../openvdb_ax/test/integration/TestCast.cc | 13 +- .../test/integration/TestConditional.cc | 35 +- .../test/integration/TestCrement.cc | 17 +- .../test/integration/TestDeclare.cc | 76 +---- .../openvdb_ax/test/integration/TestEmpty.cc | 13 +- .../test/integration/TestExternals.cc | 12 +- .../openvdb_ax/test/integration/TestHarness.h | 34 +- .../test/integration/TestKeyword.cc | 43 +-- .../openvdb_ax/test/integration/TestLoop.cc | 34 +- .../test/integration/TestStandardFunctions.cc | 317 ++++-------------- .../openvdb_ax/test/integration/TestString.cc | 42 +-- .../test/integration/TestTernary.cc | 24 +- .../openvdb_ax/test/integration/TestUnary.cc | 27 +- .../test/integration/TestVDBFunctions.cc | 141 ++++---- .../integration/TestWorldSpaceAccessors.cc | 113 +++---- 19 files changed, 279 insertions(+), 857 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc b/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc index 138ae9f415..4329a7bdd1 100644 --- a/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc +++ b/openvdb_ax/openvdb_ax/test/frontend/TestArrayPack.cc @@ -118,8 +118,6 @@ static const unittest_util::CodeTests tests = class TestArrayPack : public ::testing::Test { - void testSyntax() { TEST_SYNTAX_PASSES(tests); } - void testASTNode(); }; TEST_F(TestArrayPack, testSyntax) diff --git a/openvdb_ax/openvdb_ax/test/integration/TestArrayUnpack.cc b/openvdb_ax/openvdb_ax/test/integration/TestArrayUnpack.cc index 71c1b00509..ad4ef9ac45 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestArrayUnpack.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestArrayUnpack.cc @@ -9,29 +9,15 @@ #include #include -#include - using namespace openvdb::points; class TestArrayUnpack : public unittest_util::AXTestCase { public: - std::string dir() const override { return GET_TEST_DIRECTORY(); } - - CPPUNIT_TEST_SUITE(TestArrayUnpack); - CPPUNIT_TEST(componentVectorAssignment); - CPPUNIT_TEST(componentMatrixAssignment); - CPPUNIT_TEST_SUITE_END(); - - void componentVectorAssignment(); - void componentMatrixAssignment(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestArrayUnpack); - -void -TestArrayUnpack::componentVectorAssignment() +TEST_F(TestArrayUnpack, componentVectorAssignment) { const std::string code = R"( vec2@test1[0] = vec2@test2[1]; @@ -51,7 +37,7 @@ vec4@test6[1] = vec4@test6[0]; for (const auto& s : suffixes) { std::string repl = code; const std::string type = (s == 'i' ? "int" : (s == 'f' ? "float" : (s == 'd' ? "double" : ""))); - CPPUNIT_ASSERT(!type.empty()); + ASSERT_TRUE(!type.empty()); unittest_util::replace(repl, "vec2", std::string("vec2").append(1, s)); unittest_util::replace(repl, "vec3", std::string("vec3").append(1, s)); @@ -113,8 +99,7 @@ vec4@test6[1] = vec4@test6[0]; } } -void -TestArrayUnpack::componentMatrixAssignment() +TEST_F(TestArrayUnpack, componentMatrixAssignment) { const std::string code = R"( mat3@test1[0] = mat3@test2[4]; @@ -178,7 +163,7 @@ mat4@test8[3,3] = mat4@test7[2,1]; unittest_util::replace(repl, "mat3", std::string("mat3").append(1,s)); unittest_util::replace(repl, "mat4", std::string("mat4").append(1,s)); const std::string type = s == 'f' ? "float" : s == 'd' ? "double" : ""; - CPPUNIT_ASSERT(!type.empty()); + ASSERT_TRUE(!type.empty()); this->registerTest(repl, "array_unpack.mat." + type + ".ax"); } }; diff --git a/openvdb_ax/openvdb_ax/test/integration/TestAssign.cc b/openvdb_ax/openvdb_ax/test/integration/TestAssign.cc index 1f5aed6eda..bbd008c700 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestAssign.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestAssign.cc @@ -9,8 +9,6 @@ #include #include -#include - using namespace openvdb::points; // Configuration values for assignment code @@ -73,36 +71,9 @@ class TestAssign : public unittest_util::AXTestCase public: std::string dir() const override { return GET_TEST_DIRECTORY(); } - - CPPUNIT_TEST_SUITE(TestAssign); - CPPUNIT_TEST(directAssignment); - CPPUNIT_TEST(compoundIntegralAssignment); - CPPUNIT_TEST(compoundFloatingAssignment); - CPPUNIT_TEST(compoundVectorAssignment); - CPPUNIT_TEST(compoundMatrixAssignment); - CPPUNIT_TEST(compoundStringAssignment); - CPPUNIT_TEST(implicitScalarAssignment); - CPPUNIT_TEST(implicitContainerAssignment); - CPPUNIT_TEST(implicitContainerScalarAssignment); - CPPUNIT_TEST(scopedAssign); - CPPUNIT_TEST_SUITE_END(); - - void directAssignment(); - void compoundIntegralAssignment(); - void compoundFloatingAssignment(); - void compoundVectorAssignment(); - void compoundMatrixAssignment(); - void compoundStringAssignment(); - void implicitScalarAssignment(); - void implicitContainerAssignment(); - void implicitContainerScalarAssignment(); - void scopedAssign(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestAssign); - -void -TestAssign::directAssignment() +TEST_F(TestAssign, directAssignment) { const std::string code = R"( _T1_@test1 = _l1_; @@ -354,8 +325,7 @@ _T1_@test8 = _l1_; } } -void -TestAssign::compoundIntegralAssignment() +TEST_F(TestAssign, compoundIntegralAssignment) { const std::string code = R"( _T1_@test1 += _l1_; @@ -436,8 +406,7 @@ _T1_@test14 += local2; } } -void -TestAssign::compoundFloatingAssignment() +TEST_F(TestAssign, compoundFloatingAssignment) { const std::string code = R"( _T1_@test1 += _l1_; @@ -508,8 +477,7 @@ _T1_@test9 += local2; } -void -TestAssign::compoundVectorAssignment() +TEST_F(TestAssign, compoundVectorAssignment) { const std::string code = R"( _T1_@test1 += _l1_; @@ -870,8 +838,7 @@ _T1_@test9 += local2; } -void -TestAssign::compoundMatrixAssignment() +TEST_F(TestAssign, compoundMatrixAssignment) { const std::string code = R"( _T1_@test1 += _l1_; @@ -1051,8 +1018,7 @@ _T1_@test7 += local2; } -void -TestAssign::compoundStringAssignment() +TEST_F(TestAssign, compoundStringAssignment) { const std::string code = R"( _T1_@test1 += _l1_; @@ -1111,8 +1077,7 @@ _T1_@test5 += local2; } -void -TestAssign::implicitScalarAssignment() +TEST_F(TestAssign, implicitScalarAssignment) { auto generate = [this](const auto& source, const auto& targets) { for (const auto& t1 : source) { @@ -1185,8 +1150,7 @@ TestAssign::implicitScalarAssignment() } -void -TestAssign::implicitContainerAssignment() +TEST_F(TestAssign, implicitContainerAssignment) { auto generate = [this](const auto& source, const auto& target) { for (const auto& t1 : source) { @@ -1304,8 +1268,7 @@ TestAssign::implicitContainerAssignment() } -void -TestAssign::implicitContainerScalarAssignment() +TEST_F(TestAssign, implicitContainerScalarAssignment) { auto generate = [this](const auto& source, const auto& targets) { for (const auto& t1 : source) { @@ -1440,8 +1403,7 @@ TestAssign::implicitContainerScalarAssignment() } -void -TestAssign::scopedAssign() +TEST_F(TestAssign, scopedAssign) { const std::string code = R"( float var = 30.0f; @@ -1488,6 +1450,6 @@ float@test1 = var; mHarness.addAttributes(names, {30.0f, 1.0f, -10.0f, -15.0f, 50.0f, 50.0f, 1.0f}); this->execute("assign_scoped.float.ax"); - CPPUNIT_ASSERT(mHarness.mLogger.hasWarning()); + ASSERT_TRUE(mHarness.mLogger.hasWarning()); } diff --git a/openvdb_ax/openvdb_ax/test/integration/TestBinary.cc b/openvdb_ax/openvdb_ax/test/integration/TestBinary.cc index 483af60e30..f7c4bbc30a 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestBinary.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestBinary.cc @@ -5,8 +5,6 @@ #include "../util.h" -#include - using namespace openvdb::points; // Configuration values for binary code @@ -69,53 +67,10 @@ class TestBinary : public unittest_util::AXTestCase public: std::string dir() const override { return GET_TEST_DIRECTORY(); } - - CPPUNIT_TEST_SUITE(TestBinary); - CPPUNIT_TEST(plus); - CPPUNIT_TEST(minus); - CPPUNIT_TEST(mult); - CPPUNIT_TEST(div); - CPPUNIT_TEST(mod); - CPPUNIT_TEST(btand); - CPPUNIT_TEST(btor); - CPPUNIT_TEST(btxor); - CPPUNIT_TEST(logicaland); - CPPUNIT_TEST(logicalor); - CPPUNIT_TEST(equalsequals); - CPPUNIT_TEST(notequals); - CPPUNIT_TEST(greaterthan); - CPPUNIT_TEST(lessthan); - CPPUNIT_TEST(greaterthanequals); - CPPUNIT_TEST(lessthanequals); - CPPUNIT_TEST(shiftleft); - CPPUNIT_TEST(shiftright); - CPPUNIT_TEST_SUITE_END(); - - void plus(); - void minus(); - void mult(); - void div(); - void mod(); - void btand(); - void btor(); - void btxor(); - void logicaland(); - void logicalor(); - void equalsequals(); - void notequals(); - void greaterthan(); - void lessthan(); - void greaterthanequals(); - void lessthanequals(); - void shiftleft(); - void shiftright(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestBinary); - -void -TestBinary::plus() +TEST_F(TestBinary, plus) { const std::string code = R"( _T1_@_A1_ = _L1_ + _L2_;)"; @@ -185,8 +140,7 @@ _T1_@_A1_ = _L1_ + _L2_;)"; } -void -TestBinary::minus() +TEST_F(TestBinary, minus) { const std::string code = R"( _T1_@_A1_ = _L1_ - _L2_;)"; @@ -253,8 +207,7 @@ _T1_@_A1_ = _L1_ - _L2_;)"; this->execute("binary_minus.ax"); } -void -TestBinary::mult() +TEST_F(TestBinary, mult) { const std::string code = R"( _T1_@_A1_ = _L1_ * _L2_;)"; @@ -322,8 +275,7 @@ _T1_@_A1_ = _L1_ * _L2_;)"; } -void -TestBinary::div() +TEST_F(TestBinary, div) { // @note reverses L1 and L2 as L2 is usually larger const std::string code = R"( @@ -374,8 +326,7 @@ _T1_@_A1_ = _L2_ / _L1_;)"; } -void -TestBinary::mod() +TEST_F(TestBinary, mod) { // @note reverses L1 and L2 as L2 is usually larger const std::string code = R"( @@ -426,8 +377,7 @@ _T1_@_A1_ = _L2_ % _L1_;)"; } -void -TestBinary::btand() +TEST_F(TestBinary, btand) { const std::string code = R"( _T1_@_A1_ = _L1_ & _L2_;)"; @@ -462,8 +412,7 @@ _T1_@_A1_ = _L1_ & _L2_;)"; } -void -TestBinary::btor() +TEST_F(TestBinary, btor) { const std::string code = R"( _T1_@_A1_ = _L1_ | _L2_;)"; @@ -498,8 +447,7 @@ _T1_@_A1_ = _L1_ | _L2_;)"; } -void -TestBinary::btxor() +TEST_F(TestBinary, btxor) { const std::string code = R"( _T1_@_A1_ = _L1_ ^ _L2_;)"; @@ -534,8 +482,7 @@ _T1_@_A1_ = _L1_ ^ _L2_;)"; } -void -TestBinary::logicaland() +TEST_F(TestBinary, logicaland) { const std::string code = R"( _T1_@_A1_ = _L1_ && _L2_;)"; @@ -591,8 +538,7 @@ false && int@scircuit5 = 2;)", } -void -TestBinary::logicalor() +TEST_F(TestBinary, logicalor) { const std::string code = R"( _T1_@_A1_ = _L1_ || _L2_;)"; @@ -648,8 +594,7 @@ false || int@scircuit5 = 2;)", } -void -TestBinary::equalsequals() +TEST_F(TestBinary, equalsequals) { const std::string code = R"( bool@_A1_ = _L1_ == _L2_; @@ -678,7 +623,7 @@ bool@_A2_ = _L2_ == _L2_;)"; generate(mat4); this->registerTest(repl, "binary_relational_equalsequals.ax"); - CPPUNIT_ASSERT(idx != 0); + ASSERT_TRUE(idx != 0); const auto names = unittest_util::nameSequence("test", idx-1); std::vector results; @@ -691,8 +636,7 @@ bool@_A2_ = _L2_ == _L2_;)"; } -void -TestBinary::notequals() +TEST_F(TestBinary, notequals) { const std::string code = R"( bool@_A1_ = _L1_ != _L2_; @@ -721,7 +665,7 @@ bool@_A2_ = _L2_ != _L2_;)"; generate(mat4); this->registerTest(repl, "binary_relational_notequals.ax"); - CPPUNIT_ASSERT(idx != 0); + ASSERT_TRUE(idx != 0); const auto names = unittest_util::nameSequence("test", idx-1); std::vector results; @@ -734,8 +678,7 @@ bool@_A2_ = _L2_ != _L2_;)"; } -void -TestBinary::greaterthan() +TEST_F(TestBinary, greaterthan) { const std::string code = R"( bool@_A1_ = _L1_ > _L2_; @@ -761,7 +704,7 @@ bool@_A3_ = _L2_ > _L2_;)"; generate(floating); this->registerTest(repl, "binary_relational_greaterthan.ax"); - CPPUNIT_ASSERT(idx != 0); + ASSERT_TRUE(idx != 0); const auto names = unittest_util::nameSequence("test", idx-1); @@ -792,8 +735,7 @@ bool@_A3_ = _L2_ > _L2_;)"; } -void -TestBinary::lessthan() +TEST_F(TestBinary, lessthan) { const std::string code = R"( bool@_A1_ = _L1_ < _L2_; @@ -819,7 +761,7 @@ bool@_A3_ = _L2_ < _L2_;)"; generate(floating); this->registerTest(repl, "binary_relational_lessthan.ax"); - CPPUNIT_ASSERT(idx != 0); + ASSERT_TRUE(idx != 0); const auto names = unittest_util::nameSequence("test", idx-1); @@ -851,8 +793,7 @@ bool@_A3_ = _L2_ < _L2_;)"; -void -TestBinary::greaterthanequals() +TEST_F(TestBinary, greaterthanequals) { const std::string code = R"( bool@_A1_ = _L1_ >= _L2_; @@ -878,7 +819,7 @@ bool@_A3_ = _L2_ >= _L2_;)"; generate(floating); this->registerTest(repl, "binary_relational_greaterthanequals.ax"); - CPPUNIT_ASSERT(idx != 0); + ASSERT_TRUE(idx != 0); const auto names = unittest_util::nameSequence("test", idx-1); @@ -909,8 +850,7 @@ bool@_A3_ = _L2_ >= _L2_;)"; } -void -TestBinary::lessthanequals() +TEST_F(TestBinary, lessthanequals) { const std::string code = R"( bool@_A1_ = _L1_ <= _L2_; @@ -936,7 +876,7 @@ bool@_A3_ = _L2_ <= _L2_;)"; generate(floating); this->registerTest(repl, "binary_relational_lessthanequals.ax"); - CPPUNIT_ASSERT(idx != 0); + ASSERT_TRUE(idx != 0); const auto names = unittest_util::nameSequence("test", idx-1); @@ -967,8 +907,7 @@ bool@_A3_ = _L2_ <= _L2_;)"; } -void -TestBinary::shiftleft() +TEST_F(TestBinary, shiftleft) { const std::string code = R"( _T1_@_A1_ = _L1_ << _L2_; @@ -1021,8 +960,7 @@ _T1_@_A2_ = _L2_ << _L1_;)"; } -void -TestBinary::shiftright() +TEST_F(TestBinary, shiftright) { const std::string code = R"( _T1_@_A1_ = _L1_ >> _L2_; diff --git a/openvdb_ax/openvdb_ax/test/integration/TestCast.cc b/openvdb_ax/openvdb_ax/test/integration/TestCast.cc index 237a1102cf..05901c1332 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestCast.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestCast.cc @@ -5,27 +5,16 @@ #include "../util.h" -#include - using namespace openvdb::points; class TestCast : public unittest_util::AXTestCase { public: std::string dir() const override { return GET_TEST_DIRECTORY(); } - - CPPUNIT_TEST_SUITE(TestCast); - CPPUNIT_TEST(explicitScalar); - CPPUNIT_TEST_SUITE_END(); - - void explicitScalar(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestCast); - -void -TestCast::explicitScalar() +TEST_F(TestCast, explicitScalar) { auto generate = [this](const auto& types) { for (const auto& t1 : types) { diff --git a/openvdb_ax/openvdb_ax/test/integration/TestConditional.cc b/openvdb_ax/openvdb_ax/test/integration/TestConditional.cc index c3f261ec7e..d0878be3d5 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestConditional.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestConditional.cc @@ -3,32 +3,13 @@ #include "TestHarness.h" -#include - using namespace openvdb::points; class TestConditional : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestConditional); - CPPUNIT_TEST(testConditionalIfWithinElse); - CPPUNIT_TEST(testConditionalScopingStatement); - CPPUNIT_TEST(testConditionalSimpleStatement); - CPPUNIT_TEST(testConditionalSimpleElseIf); - CPPUNIT_TEST(testConditionalErrors); - CPPUNIT_TEST_SUITE_END(); - - void testConditionalIfWithinElse(); - void testConditionalSimpleStatement(); - void testConditionalScopingStatement(); - void testConditionalSimpleElseIf(); - void testConditionalErrors(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestConditional); - -void -TestConditional::testConditionalIfWithinElse() +TEST_F(TestConditional, testConditionalIfWithinElse) { mHarness.addAttribute("bool_test", true); mHarness.executeCode("test/snippets/conditional/conditionalIfWithinElse"); @@ -36,8 +17,7 @@ TestConditional::testConditionalIfWithinElse() AXTESTS_STANDARD_ASSERT(); } -void -TestConditional::testConditionalSimpleStatement() +TEST_F(TestConditional, testConditionalSimpleStatement) { mHarness.addAttribute("bool_test", true); mHarness.addAttribute("float_test", 1.0f); @@ -47,8 +27,7 @@ TestConditional::testConditionalSimpleStatement() AXTESTS_STANDARD_ASSERT(); } -void -TestConditional::testConditionalScopingStatement() +TEST_F(TestConditional, testConditionalScopingStatement) { mHarness.addAttribute("int_test", 1); mHarness.executeCode("test/snippets/conditional/conditionalScopingStatement"); @@ -56,8 +35,7 @@ TestConditional::testConditionalScopingStatement() AXTESTS_STANDARD_ASSERT(); } -void -TestConditional::testConditionalSimpleElseIf() +TEST_F(TestConditional, testConditionalSimpleElseIf) { mHarness.addAttribute("bool_test", true); mHarness.addAttribute("int_test", 2); @@ -67,11 +45,10 @@ TestConditional::testConditionalSimpleElseIf() AXTESTS_STANDARD_ASSERT(); } -void -TestConditional::testConditionalErrors() +TEST_F(TestConditional, testConditionalErrors) { const bool success = mHarness.executeCode("test/snippets/conditional/conditionalErrors"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } diff --git a/openvdb_ax/openvdb_ax/test/integration/TestCrement.cc b/openvdb_ax/openvdb_ax/test/integration/TestCrement.cc index 273e580291..4d0f4f6f28 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestCrement.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestCrement.cc @@ -9,8 +9,6 @@ #include #include -#include - using namespace openvdb::points; class TestCrement : public unittest_util::AXTestCase @@ -18,20 +16,10 @@ class TestCrement : public unittest_util::AXTestCase public: std::string dir() const override { return GET_TEST_DIRECTORY(); } - - CPPUNIT_TEST_SUITE(TestCrement); - CPPUNIT_TEST(crementScalar); - CPPUNIT_TEST(crementComponent); - CPPUNIT_TEST_SUITE_END(); - - void crementScalar(); - void crementComponent(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestCrement); -void -TestCrement::crementScalar() +TEST_F(TestCrement, crementScalar) { const std::string code = R"( _T1_@test1 = ++_T1_@test2; @@ -159,8 +147,7 @@ _T1_@test8 = (++_T1_@test6, ++_T1_@test7, _T1_@test6++); } -void -TestCrement::crementComponent() +TEST_F(TestCrement, crementComponent) { // Just tests the first two components of every container const std::string code = R"( diff --git a/openvdb_ax/openvdb_ax/test/integration/TestDeclare.cc b/openvdb_ax/openvdb_ax/test/integration/TestDeclare.cc index 100d19c7f4..1878107b2e 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestDeclare.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestDeclare.cc @@ -7,46 +7,13 @@ #include -#include - using namespace openvdb::points; class TestDeclare : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestDeclare); - CPPUNIT_TEST(testLocalVariables); - CPPUNIT_TEST(testLocalVectorVariables); - CPPUNIT_TEST(testAttributes); - CPPUNIT_TEST(testVectorAttributes); - CPPUNIT_TEST(testNewAttributes); - CPPUNIT_TEST(testNewVectorAttributes); - CPPUNIT_TEST(testVectorAttributeImplicit); - CPPUNIT_TEST(testAmbiguousScalarAttributes); - CPPUNIT_TEST(testAmbiguousVectorAttributes); - CPPUNIT_TEST(testAmbiguousScalarExternals); - CPPUNIT_TEST(testAmbiguousVectorExternals); - CPPUNIT_TEST(testAttributesVolume); - CPPUNIT_TEST_SUITE_END(); - - void testLocalVariables(); - void testAttributes(); - void testNewAttributes(); - void testNewVectorAttributes(); - void testLocalVectorVariables(); - void testVectorAttributes(); - void testVectorAttributeImplicit(); - void testAmbiguousScalarAttributes(); - void testAmbiguousVectorAttributes(); - void testAmbiguousScalarExternals(); - void testAmbiguousVectorExternals(); - void testAttributesVolume(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestDeclare); - -void -TestDeclare::testLocalVariables() +TEST_F(TestDeclare, testLocalVariables) { mHarness.executeCode("test/snippets/declare/declareLocalVariables"); @@ -54,16 +21,14 @@ TestDeclare::testLocalVariables() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testLocalVectorVariables() +TEST_F(TestDeclare, testLocalVectorVariables) { mHarness.executeCode("test/snippets/declare/declareLocalVectorVariables"); AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testAttributes() +TEST_F(TestDeclare, testAttributes) { mHarness.addAttributes(unittest_util::nameSequence("float_test", 4), {0.0f, 0.2f, 10.0f, 10.0f}); @@ -79,8 +44,7 @@ TestDeclare::testAttributes() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testAttributesVolume() +TEST_F(TestDeclare, testAttributesVolume) { mHarness.addAttributes(unittest_util::nameSequence("float_test", 4), {0.0f, 0.2f, 10.0f, 10.0f}); @@ -95,8 +59,7 @@ TestDeclare::testAttributesVolume() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testNewAttributes() +TEST_F(TestDeclare, testNewAttributes) { mHarness.addExpectedAttributes(unittest_util::nameSequence("float_test", 4), {0.0f, 0.2f, 10.0f, 10.0f}); @@ -121,8 +84,7 @@ TestDeclare::testNewAttributes() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testNewVectorAttributes() +TEST_F(TestDeclare, testNewVectorAttributes) { mHarness.addExpectedAttributes({"vec_float_test", "vec_float_test2"}, {openvdb::Vec3f::zero(), openvdb::Vec3f(0.2f, 0.3f, 0.4f)}); @@ -142,8 +104,7 @@ TestDeclare::testNewVectorAttributes() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testVectorAttributes() +TEST_F(TestDeclare, testVectorAttributes) { mHarness.addAttribute("vec_double_test", openvdb::Vec3d(0.3, 0.4, 0.5)); mHarness.addAttributes({"vec_float_test", "vec_float_test2"}, @@ -156,8 +117,7 @@ TestDeclare::testVectorAttributes() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testVectorAttributeImplicit() +TEST_F(TestDeclare, testVectorAttributeImplicit) { mHarness.addAttribute("vec_double_test", openvdb::Vec3d(1.0, 0.3, 0.4)); mHarness.executeCode("test/snippets/declare/declareVectorAttributeImplicit"); @@ -165,31 +125,27 @@ TestDeclare::testVectorAttributeImplicit() AXTESTS_STANDARD_ASSERT(); } -void -TestDeclare::testAmbiguousScalarAttributes() +TEST_F(TestDeclare, testAmbiguousScalarAttributes) { const bool success = mHarness.executeCode("test/snippets/declare/declareAmbiguousScalarAttributes"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } -void -TestDeclare::testAmbiguousVectorAttributes() +TEST_F(TestDeclare, testAmbiguousVectorAttributes) { const bool success = mHarness.executeCode("test/snippets/declare/declareAmbiguousVectorAttributes"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } -void -TestDeclare::testAmbiguousScalarExternals() +TEST_F(TestDeclare, testAmbiguousScalarExternals) { const bool success = mHarness.executeCode("test/snippets/declare/declareAmbiguousScalarExternals"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } -void -TestDeclare::testAmbiguousVectorExternals() +TEST_F(TestDeclare, testAmbiguousVectorExternals) { const bool success = mHarness.executeCode("test/snippets/declare/declareAmbiguousVectorExternals"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } diff --git a/openvdb_ax/openvdb_ax/test/integration/TestEmpty.cc b/openvdb_ax/openvdb_ax/test/integration/TestEmpty.cc index 45db3bfb0c..f2575f9616 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestEmpty.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestEmpty.cc @@ -5,24 +5,13 @@ #include -#include - using namespace openvdb::points; class TestEmpty : public unittest_util::AXTestCase { - -public: - CPPUNIT_TEST_SUITE(TestEmpty); - CPPUNIT_TEST(testEmpty); - CPPUNIT_TEST_SUITE_END(); - void testEmpty(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestEmpty); - -void -TestEmpty::testEmpty() +TEST_F(TestEmpty, testEmpty) { unittest_util::AXTestHarness harness; harness.executeCode("test/snippets/empty/empty"); diff --git a/openvdb_ax/openvdb_ax/test/integration/TestExternals.cc b/openvdb_ax/openvdb_ax/test/integration/TestExternals.cc index d97b9fc983..4a6296e5f2 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestExternals.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestExternals.cc @@ -10,8 +10,6 @@ #include #include -#include - using namespace openvdb::points; class TestExternals : public unittest_util::AXTestCase @@ -19,18 +17,10 @@ class TestExternals : public unittest_util::AXTestCase public: std::string dir() const override { return GET_TEST_DIRECTORY(); } - - CPPUNIT_TEST_SUITE(TestExternals); - CPPUNIT_TEST(assignFrom); - CPPUNIT_TEST_SUITE_END(); - - void assignFrom(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestExternals); -void -TestExternals::assignFrom() +TEST_F(TestExternals, assignFrom) { const std::string code = R"( _T1_@test1 = _T1_$ext1;)"; diff --git a/openvdb_ax/openvdb_ax/test/integration/TestHarness.h b/openvdb_ax/openvdb_ax/test/integration/TestHarness.h index ebdcf10a10..cbf0783b08 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestHarness.h +++ b/openvdb_ax/openvdb_ax/test/integration/TestHarness.h @@ -19,8 +19,9 @@ #include #include -#include +#include +#include #include extern int sGenerateAX; @@ -214,17 +215,16 @@ struct AXTestHarness openvdb::ax::Logger mLogger; }; -class AXTestCase : public CppUnit::TestCase +class AXTestCase : public ::testing::Test { public: - void tearDown() override + void TearDown() override { std::string out; for (auto& test : mTestFiles) { if (!test.second) out += test.first + "\n"; } - CPPUNIT_ASSERT_MESSAGE("unused tests left in test case:\n" + out, - out.empty()); + ASSERT_TRUE(out.empty()) << ("unused tests left in test case:\n" + out); } // @todo make pure @@ -238,15 +238,13 @@ class AXTestCase : public CppUnit::TestCase const std::ios_base::openmode flags = std::ios_base::out) { if (flags & std::ios_base::out) { - CPPUNIT_ASSERT_MESSAGE( - "duplicate test file found during test setup:\n" + filename, - mTestFiles.find(filename) == mTestFiles.end()); + ASSERT_TRUE(mTestFiles.find(filename) == mTestFiles.end()) + << ("duplicate test file found during test setup:\n" + filename); mTestFiles[filename] = false; } if (flags & std::ios_base::app) { - CPPUNIT_ASSERT_MESSAGE( - "test not found during ofstream append:\n" + filename, - mTestFiles.find(filename) != mTestFiles.end()); + ASSERT_TRUE(mTestFiles.find(filename) != mTestFiles.end()) + << ("test not found during ofstream append:\n" + filename); } if (sGenerateAX) { @@ -260,21 +258,19 @@ class AXTestCase : public CppUnit::TestCase template void execute(const std::string& filename, Args&&... args) { - CPPUNIT_ASSERT_MESSAGE( - "test not found during execution:\n" + this->dir() + "/" + filename, - mTestFiles.find(filename) != mTestFiles.end()); + ASSERT_TRUE(mTestFiles.find(filename) != mTestFiles.end()) + << ("test not found during execution:\n" + this->dir() + "/" + filename); mTestFiles[filename] = true; // has been used // execute const bool success = mHarness.executeCode(this->dir() + "/" + filename, args...); - CPPUNIT_ASSERT_MESSAGE("error thrown during test: " + filename + "\n" + mHarness.errors(), - success); + ASSERT_TRUE(success) + << ("error thrown during test: " + filename + "\n" + mHarness.errors()); // check std::stringstream out; const bool correct = mHarness.checkAgainstExpected(out); - //CPPUNIT_ASSERT(correct); - CPPUNIT_ASSERT_MESSAGE(out.str(), correct); + ASSERT_TRUE(correct) << out.str(); } protected: @@ -291,7 +287,7 @@ class AXTestCase : public CppUnit::TestCase #define AXTESTS_STANDARD_ASSERT_HARNESS(harness) \ { std::stringstream out; \ const bool correct = harness.checkAgainstExpected(out); \ - CPPUNIT_ASSERT_MESSAGE(out.str(), correct); } + ASSERT_TRUE(correct) << out.str(); } #define AXTESTS_STANDARD_ASSERT() \ AXTESTS_STANDARD_ASSERT_HARNESS(mHarness); diff --git a/openvdb_ax/openvdb_ax/test/integration/TestKeyword.cc b/openvdb_ax/openvdb_ax/test/integration/TestKeyword.cc index 6eabe623b6..d8e0f2515f 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestKeyword.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestKeyword.cc @@ -3,37 +3,14 @@ #include "TestHarness.h" -#include - using namespace openvdb::points; class TestKeyword : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestKeyword); - CPPUNIT_TEST(testKeywordSimpleReturn); - CPPUNIT_TEST(testKeywordReturnBranchIf); - CPPUNIT_TEST(testKeywordReturnBranchLoop); - CPPUNIT_TEST(testKeywordConditionalReturn); - CPPUNIT_TEST(testKeywordForLoopKeywords); - CPPUNIT_TEST(testKeywordWhileLoopKeywords); - CPPUNIT_TEST(testKeywordDoWhileLoopKeywords); - CPPUNIT_TEST_SUITE_END(); - - void testKeywordSimpleReturn(); - void testKeywordReturnBranchIf(); - void testKeywordReturnBranchLoop(); - void testKeywordConditionalReturn(); - void testKeywordForLoopKeywords(); - void testKeywordWhileLoopKeywords(); - void testKeywordDoWhileLoopKeywords(); - }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestKeyword); -void -TestKeyword::testKeywordSimpleReturn() +TEST_F(TestKeyword, testKeywordSimpleReturn) { mHarness.addAttribute("return_test0", 0); mHarness.executeCode("test/snippets/keyword/simpleReturn"); @@ -41,8 +18,7 @@ TestKeyword::testKeywordSimpleReturn() AXTESTS_STANDARD_ASSERT(); } -void -TestKeyword::testKeywordReturnBranchIf() +TEST_F(TestKeyword, testKeywordReturnBranchIf) { mHarness.addAttribute("return_test1", 1); mHarness.executeCode("test/snippets/keyword/returnBranchIf"); @@ -50,8 +26,7 @@ TestKeyword::testKeywordReturnBranchIf() AXTESTS_STANDARD_ASSERT(); } -void -TestKeyword::testKeywordReturnBranchLoop() +TEST_F(TestKeyword, testKeywordReturnBranchLoop) { mHarness.addAttribute("return_test2", 1); mHarness.executeCode("test/snippets/keyword/returnBranchLoop"); @@ -59,8 +34,7 @@ TestKeyword::testKeywordReturnBranchLoop() AXTESTS_STANDARD_ASSERT(); } -void -TestKeyword::testKeywordConditionalReturn() +TEST_F(TestKeyword, testKeywordConditionalReturn) { mHarness.addAttribute("return_test3", 3); mHarness.executeCode("test/snippets/keyword/conditionalReturn"); @@ -68,8 +42,7 @@ TestKeyword::testKeywordConditionalReturn() AXTESTS_STANDARD_ASSERT(); } -void -TestKeyword::testKeywordForLoopKeywords() +TEST_F(TestKeyword, testKeywordForLoopKeywords) { mHarness.addAttribute("loop_test4", openvdb::Vec3f(1.0,0.0,0.0)); mHarness.addAttribute("loop_test5", openvdb::Vec3f(1.0,0.0,3.0)); @@ -88,8 +61,7 @@ TestKeyword::testKeywordForLoopKeywords() AXTESTS_STANDARD_ASSERT(); } -void -TestKeyword::testKeywordWhileLoopKeywords() +TEST_F(TestKeyword, testKeywordWhileLoopKeywords) { mHarness.addAttribute("loop_test10", openvdb::Vec3f(1.0,0.0,0.0)); mHarness.addAttribute("loop_test11", openvdb::Vec3f(0.0,0.0,2.0)); @@ -100,8 +72,7 @@ TestKeyword::testKeywordWhileLoopKeywords() } -void -TestKeyword::testKeywordDoWhileLoopKeywords() +TEST_F(TestKeyword, testKeywordDoWhileLoopKeywords) { mHarness.addAttribute("loop_test13", openvdb::Vec3f(1.0,0.0,0.0)); mHarness.addAttribute("loop_test14", openvdb::Vec3f(0.0,0.0,2.0)); diff --git a/openvdb_ax/openvdb_ax/test/integration/TestLoop.cc b/openvdb_ax/openvdb_ax/test/integration/TestLoop.cc index 6b53b50f71..b09b32e4b9 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestLoop.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestLoop.cc @@ -3,32 +3,14 @@ #include "TestHarness.h" -#include - using namespace openvdb::points; class TestLoop : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestLoop); - CPPUNIT_TEST(testLoopForLoop); - CPPUNIT_TEST(testLoopWhileLoop); - CPPUNIT_TEST(testLoopDoWhileLoop); - CPPUNIT_TEST(testLoopOverflow); - CPPUNIT_TEST(testLoopErrors); - CPPUNIT_TEST_SUITE_END(); - - void testLoopForLoop(); - void testLoopWhileLoop(); - void testLoopDoWhileLoop(); - void testLoopOverflow(); - void testLoopErrors(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestLoop); -void -TestLoop::testLoopForLoop() +TEST_F(TestLoop, testLoopForLoop) { mHarness.addAttribute("loop_test1", openvdb::Vec3f(1.0,2.0,3.0)); mHarness.addAttribute("loop_test2", openvdb::Vec3f(1.0,2.0,3.0)); @@ -46,8 +28,7 @@ TestLoop::testLoopForLoop() AXTESTS_STANDARD_ASSERT(); } -void -TestLoop::testLoopWhileLoop() +TEST_F(TestLoop, testLoopWhileLoop) { mHarness.addAttribute("loop_test9", openvdb::Vec3f(1.0,2.0,3.0)); mHarness.addAttribute("loop_test16", openvdb::Vec3f(0.0,0.0,0.0)); @@ -58,8 +39,7 @@ TestLoop::testLoopWhileLoop() AXTESTS_STANDARD_ASSERT(); } -void -TestLoop::testLoopDoWhileLoop() +TEST_F(TestLoop, testLoopDoWhileLoop) { mHarness.addAttribute("loop_test12", openvdb::Vec3f(1.0,2.0,3.0)); mHarness.addAttribute("loop_test17", openvdb::Vec3f(1.0,0.0,0.0)); @@ -70,8 +50,7 @@ TestLoop::testLoopDoWhileLoop() AXTESTS_STANDARD_ASSERT(); } -void -TestLoop::testLoopOverflow() +TEST_F(TestLoop, testLoopOverflow) { // Disable all optimizations to force the loop to not remove the interior // allocation. The loop should generate its allocas in the function prologue @@ -82,10 +61,9 @@ TestLoop::testLoopOverflow() mHarness.executeCode("test/snippets/loop/loopOverflow"); } -void -TestLoop::testLoopErrors() +TEST_F(TestLoop, testLoopErrors) { const bool success = mHarness.executeCode("test/snippets/loop/loopErrors"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } diff --git a/openvdb_ax/openvdb_ax/test/integration/TestStandardFunctions.cc b/openvdb_ax/openvdb_ax/test/integration/TestStandardFunctions.cc index 65cf0dc93b..d67418258f 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestStandardFunctions.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestStandardFunctions.cc @@ -13,8 +13,6 @@ #include #include -#include - #include #include #include @@ -28,136 +26,13 @@ class TestStandardFunctions : public unittest_util::AXTestCase { public: #ifdef PROFILE - void setUp() override { + void SetUp() override { // if PROFILE, generate more data for each test mHarness.reset(/*ppv*/8, openvdb::CoordBBox({0,0,0},{50,50,50})); } #endif - - CPPUNIT_TEST_SUITE(TestStandardFunctions); - CPPUNIT_TEST(abs); - CPPUNIT_TEST(acos); - CPPUNIT_TEST(adjoint); - CPPUNIT_TEST(argsort); - CPPUNIT_TEST(asin); - CPPUNIT_TEST(atan); - CPPUNIT_TEST(atan2); - CPPUNIT_TEST(atof); - CPPUNIT_TEST(atoi); - CPPUNIT_TEST(cbrt); - CPPUNIT_TEST(clamp); - CPPUNIT_TEST(cofactor); - CPPUNIT_TEST(cosh); - CPPUNIT_TEST(cross); - CPPUNIT_TEST(curlsimplexnoise); - CPPUNIT_TEST(degrees); - CPPUNIT_TEST(determinant); - CPPUNIT_TEST(diag); - CPPUNIT_TEST(dot); - CPPUNIT_TEST(euclideanmod); - CPPUNIT_TEST(external); - CPPUNIT_TEST(fit); - CPPUNIT_TEST(floormod); - CPPUNIT_TEST(hash); - CPPUNIT_TEST(hsvtorgb); - CPPUNIT_TEST(identity3); - CPPUNIT_TEST(identity4); - CPPUNIT_TEST(intrinsic); - CPPUNIT_TEST(inverse); - CPPUNIT_TEST(isfinite); - CPPUNIT_TEST(isinf); - CPPUNIT_TEST(isnan); - CPPUNIT_TEST(length); - CPPUNIT_TEST(lengthsq); - CPPUNIT_TEST(lerp); - CPPUNIT_TEST(max); - CPPUNIT_TEST(min); - CPPUNIT_TEST(normalize); - CPPUNIT_TEST(polardecompose); - CPPUNIT_TEST(postscale); - CPPUNIT_TEST(pow); - CPPUNIT_TEST(prescale); - CPPUNIT_TEST(pretransform); - CPPUNIT_TEST(print); - CPPUNIT_TEST(radians); - CPPUNIT_TEST(rand); - CPPUNIT_TEST(rand32); - CPPUNIT_TEST(rgbtohsv); - CPPUNIT_TEST(sign); - CPPUNIT_TEST(signbit); - CPPUNIT_TEST(simplexnoise); - CPPUNIT_TEST(sinh); - CPPUNIT_TEST(sort); - CPPUNIT_TEST(tan); - CPPUNIT_TEST(tanh); - CPPUNIT_TEST(trace); - CPPUNIT_TEST(transform); - CPPUNIT_TEST(transpose); - CPPUNIT_TEST(truncatemod); - CPPUNIT_TEST_SUITE_END(); - - void abs(); - void acos(); - void adjoint(); - void argsort(); - void asin(); - void atan(); - void atan2(); - void atof(); - void atoi(); - void cbrt(); - void clamp(); - void cofactor(); - void cosh(); - void cross(); - void curlsimplexnoise(); - void degrees(); - void determinant(); - void diag(); - void dot(); - void euclideanmod(); - void external(); - void fit(); - void floormod(); - void hash(); - void hsvtorgb(); - void identity3(); - void identity4(); - void intrinsic(); - void inverse(); - void isfinite(); - void isinf(); - void isnan(); - void length(); - void lengthsq(); - void lerp(); - void max(); - void min(); - void normalize(); - void polardecompose(); - void postscale(); - void pow(); - void prescale(); - void pretransform(); - void print(); - void radians(); - void rand(); - void rand32(); - void rgbtohsv(); - void sign(); - void signbit(); - void simplexnoise(); - void sinh(); - void sort(); - void tan(); - void tanh(); - void trace(); - void transform(); - void transpose(); - void truncatemod(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestStandardFunctions); inline void testFunctionOptions(unittest_util::AXTestHarness& harness, const std::string& name, @@ -173,7 +48,7 @@ inline void testFunctionOptions(unittest_util::AXTestHarness& harness, const ast::Tree::Ptr syntaxTree = ast::parse(code.c_str()); timer.stop(); - CPPUNIT_ASSERT_MESSAGE(syntaxTree, "Invalid AX passed to testFunctionOptions."); + ASSERT_TRUE(syntaxTree) << "Invalid AX passed to testFunctionOptions."; // @warning the first execution can take longer due to some llvm startup // so if you're profiling a single function be aware of this. @@ -231,8 +106,7 @@ inline void testFunctionOptions(unittest_util::AXTestHarness& harness, harness.mOpts = opts; harness.mCustomData = data; bool success = harness.executeCode(file); - CPPUNIT_ASSERT_MESSAGE("error thrown during test: " + file + "\n" + harness.errors(), - success); + ASSERT_TRUE(success) << ("error thrown during test: " + file + "\n" + harness.errors()); AXTESTS_STANDARD_ASSERT_HARNESS(harness); #endif @@ -247,8 +121,7 @@ inline void testFunctionOptions(unittest_util::AXTestHarness& harness, harness.mOpts = opts; harness.mCustomData = data; success = harness.executeCode(file); - CPPUNIT_ASSERT_MESSAGE("error thrown during test: " + file + "\n" + harness.errors(), - success); + ASSERT_TRUE(success) << ("error thrown during test: " + file + "\n" + harness.errors()); AXTESTS_STANDARD_ASSERT_HARNESS(harness); #endif @@ -263,14 +136,12 @@ inline void testFunctionOptions(unittest_util::AXTestHarness& harness, harness.mOpts = opts; harness.mCustomData = data; success = harness.executeCode(file); - CPPUNIT_ASSERT_MESSAGE("error thrown during test: " + file + "\n" + harness.errors(), - success); + ASSERT_TRUE(success) << ("error thrown during test: " + file + "\n" + harness.errors()); AXTESTS_STANDARD_ASSERT_HARNESS(harness); #endif } -void -TestStandardFunctions::abs() +TEST_F(TestStandardFunctions, abs) { mHarness.addAttributes(unittest_util::nameSequence("test", 3), { std::abs(-3), std::abs(3), std::abs(0) @@ -283,8 +154,7 @@ TestStandardFunctions::abs() testFunctionOptions(mHarness, "abs"); } -void -TestStandardFunctions::acos() +TEST_F(TestStandardFunctions, acos) { volatile double arg = 0.5; volatile float argf = 0.5f; @@ -293,8 +163,7 @@ TestStandardFunctions::acos() testFunctionOptions(mHarness, "acos"); } -void -TestStandardFunctions::adjoint() +TEST_F(TestStandardFunctions, adjoint) { const openvdb::math::Mat3 inputd( 1.0, -1.0, 0.0, @@ -315,8 +184,7 @@ TestStandardFunctions::adjoint() testFunctionOptions(mHarness, "adjoint"); } -void -TestStandardFunctions::argsort() +TEST_F(TestStandardFunctions, argsort) { // const openvdb::Vec3d input3d(1.0, -1.0, 0.0); // const openvdb::Vec3f input3f(1.0f, -1.0f, 0.0f); @@ -345,32 +213,28 @@ TestStandardFunctions::argsort() } -void -TestStandardFunctions::asin() +TEST_F(TestStandardFunctions, asin) { mHarness.addAttribute("test1", std::asin(-0.5)); mHarness.addAttribute("test2", std::asin(-0.5f)); testFunctionOptions(mHarness, "asin"); } -void -TestStandardFunctions::atan() +TEST_F(TestStandardFunctions, atan) { mHarness.addAttribute("test1", std::atan(1.0)); mHarness.addAttribute("test2", std::atan(1.0f)); testFunctionOptions(mHarness, "atan"); } -void -TestStandardFunctions::atan2() +TEST_F(TestStandardFunctions, atan2) { mHarness.addAttribute("test1", std::atan2(1.0, 1.0)); mHarness.addAttribute("test2", std::atan2(1.0f, 1.0f)); testFunctionOptions(mHarness, "atan2"); } -void -TestStandardFunctions::atoi() +TEST_F(TestStandardFunctions, atoi) { const std::vector values { std::atoi(""), @@ -392,8 +256,7 @@ TestStandardFunctions::atoi() testFunctionOptions(mHarness, "atoi"); } -void -TestStandardFunctions::atof() +TEST_F(TestStandardFunctions, atof) { const std::vector values { std::atof(""), @@ -415,8 +278,7 @@ TestStandardFunctions::atof() testFunctionOptions(mHarness, "atof"); } -void -TestStandardFunctions::cbrt() +TEST_F(TestStandardFunctions, cbrt) { volatile double arg = 729.0; volatile float argf = 729.0f; @@ -425,15 +287,13 @@ TestStandardFunctions::cbrt() testFunctionOptions(mHarness, "cbrt"); } -void -TestStandardFunctions::clamp() +TEST_F(TestStandardFunctions, clamp) { mHarness.addAttributes(unittest_util::nameSequence("double_test", 3), {-1.5, 0.0, 1.5}); testFunctionOptions(mHarness, "clamp"); } -void -TestStandardFunctions::cofactor() +TEST_F(TestStandardFunctions, cofactor) { const openvdb::math::Mat3 inputd( 1.0, -1.0, 0.0, @@ -454,8 +314,7 @@ TestStandardFunctions::cofactor() testFunctionOptions(mHarness, "cofactor"); } -void -TestStandardFunctions::cosh() +TEST_F(TestStandardFunctions, cosh) { volatile float arg = 1.0f; mHarness.addAttribute("test1", std::cosh(1.0)); @@ -463,8 +322,7 @@ TestStandardFunctions::cosh() testFunctionOptions(mHarness, "cosh"); } -void -TestStandardFunctions::cross() +TEST_F(TestStandardFunctions, cross) { const openvdb::Vec3d ad(1.0,2.2,3.4), bd(4.1,5.3,6.2); const openvdb::Vec3f af(1.0f,2.2f,3.4f), bf(4.1f,5.3f,6.2f); @@ -475,8 +333,7 @@ TestStandardFunctions::cross() testFunctionOptions(mHarness, "cross"); } -void -TestStandardFunctions::curlsimplexnoise() +TEST_F(TestStandardFunctions, curlsimplexnoise) { struct Local { static inline double noise(double x, double y, double z) { @@ -495,16 +352,14 @@ TestStandardFunctions::curlsimplexnoise() testFunctionOptions(mHarness, "curlsimplexnoise"); } -void -TestStandardFunctions::degrees() +TEST_F(TestStandardFunctions, degrees) { mHarness.addAttribute("test1", 1.5708 * (180.0 / openvdb::math::pi())); mHarness.addAttribute("test2", -1.1344f * (180.0f / openvdb::math::pi())); testFunctionOptions(mHarness, "degrees"); } -void -TestStandardFunctions::determinant() +TEST_F(TestStandardFunctions, determinant) { mHarness.addAttribute("det3_float", 600.0f); mHarness.addAttribute("det3_double", 600.0); @@ -513,8 +368,7 @@ TestStandardFunctions::determinant() testFunctionOptions(mHarness, "determinant"); } -void -TestStandardFunctions::diag() +TEST_F(TestStandardFunctions, diag) { mHarness.addAttribute> ("test1", openvdb::math::Mat3(-1,0,0, 0,-2,0, 0,0,-3)); @@ -531,8 +385,7 @@ TestStandardFunctions::diag() testFunctionOptions(mHarness, "diag"); } -void -TestStandardFunctions::dot() +TEST_F(TestStandardFunctions, dot) { const openvdb::Vec3d ad(1.0,2.2,3.4), bd(4.1,5.3,6.2); const openvdb::Vec3f af(1.0f,2.2f,3.4f), bf(4.1f,5.3f,6.2f); @@ -543,8 +396,7 @@ TestStandardFunctions::dot() testFunctionOptions(mHarness, "dot"); } -void -TestStandardFunctions::euclideanmod() +TEST_F(TestStandardFunctions, euclideanmod) { static auto emod = [](auto D, auto d) -> auto { using ValueType = decltype(D); @@ -561,8 +413,7 @@ TestStandardFunctions::euclideanmod() testFunctionOptions(mHarness, "euclideanmod"); } -void -TestStandardFunctions::external() +TEST_F(TestStandardFunctions, external) { mHarness.addAttribute("foo", 2.0f); mHarness.addAttribute("v", openvdb::Vec3f(1.0f, 2.0f, 3.0f)); @@ -610,8 +461,7 @@ TestStandardFunctions::external() AXTESTS_STANDARD_ASSERT() } -void -TestStandardFunctions::fit() +TEST_F(TestStandardFunctions, fit) { std::vector values{23.0, -23.0, -25.0, -15.0, -15.0, -18.0, -24.0, 0.0, 10.0, -5.0, 0.0, -1.0, 4.5, 4.5, 4.5, 4.5, 4.5}; @@ -619,8 +469,7 @@ TestStandardFunctions::fit() testFunctionOptions(mHarness, "fit"); } -void -TestStandardFunctions::floormod() +TEST_F(TestStandardFunctions, floormod) { auto axmod = [](auto D, auto d) -> auto { auto r = std::fmod(D, d); @@ -646,8 +495,7 @@ TestStandardFunctions::floormod() testFunctionOptions(mHarness, "floormod"); } -void -TestStandardFunctions::hash() +TEST_F(TestStandardFunctions, hash) { const std::vector values{ static_cast(std::hash{}("")), @@ -659,8 +507,7 @@ TestStandardFunctions::hash() testFunctionOptions(mHarness, "hash"); } -void -TestStandardFunctions::hsvtorgb() +TEST_F(TestStandardFunctions, hsvtorgb) { auto axmod = [](auto D, auto d) -> auto { auto r = std::fmod(D, d); @@ -730,22 +577,19 @@ TestStandardFunctions::hsvtorgb() testFunctionOptions(mHarness, "hsvtorgb"); } -void -TestStandardFunctions::identity3() +TEST_F(TestStandardFunctions, identity3) { mHarness.addAttribute("test", openvdb::Mat3d::identity()); testFunctionOptions(mHarness, "identity3"); } -void -TestStandardFunctions::identity4() +TEST_F(TestStandardFunctions, identity4) { mHarness.addAttribute("test", openvdb::Mat4d::identity()); testFunctionOptions(mHarness, "identity4"); } -void -TestStandardFunctions::intrinsic() +TEST_F(TestStandardFunctions, intrinsic) { mHarness.addAttributes(unittest_util::nameSequence("dtest", 12), { std::sqrt(9.0), @@ -780,8 +624,7 @@ TestStandardFunctions::intrinsic() testFunctionOptions(mHarness, "intrinsic"); } -void -TestStandardFunctions::inverse() +TEST_F(TestStandardFunctions, inverse) { const openvdb::math::Mat3 inputd( 1.0, -1.0, 0.0, @@ -816,8 +659,7 @@ TestStandardFunctions::inverse() testFunctionOptions(mHarness, "inverse"); } -void -TestStandardFunctions::isfinite() +TEST_F(TestStandardFunctions, isfinite) { mHarness.addAttributes( {"test1","test2","test3","test4","test5","test6","test7","test8","test9","test10", "test11","test12", @@ -828,8 +670,7 @@ TestStandardFunctions::isfinite() testFunctionOptions(mHarness, "isfinite"); } -void -TestStandardFunctions::isinf() +TEST_F(TestStandardFunctions, isinf) { mHarness.addAttributes( {"test1","test2","test3","test4","test5","test6","test7","test8","test9","test10", "test11","test12", @@ -840,8 +681,7 @@ TestStandardFunctions::isinf() testFunctionOptions(mHarness, "isinf"); } -void -TestStandardFunctions::isnan() +TEST_F(TestStandardFunctions, isnan) { mHarness.addAttributes( {"test1","test2","test3","test4","test5","test6","test7","test8","test9","test10", "test11","test12", @@ -853,8 +693,7 @@ TestStandardFunctions::isnan() } -void -TestStandardFunctions::length() +TEST_F(TestStandardFunctions, length) { mHarness.addAttribute("test1", openvdb::Vec2d(2.2, 3.3).length()); mHarness.addAttribute("test2", openvdb::Vec2f(2.2f, 3.3f).length()); @@ -870,8 +709,7 @@ TestStandardFunctions::length() testFunctionOptions(mHarness, "length"); } -void -TestStandardFunctions::lengthsq() +TEST_F(TestStandardFunctions, lengthsq) { mHarness.addAttribute("test1", openvdb::Vec2d(2.2, 3.3).lengthSqr()); mHarness.addAttribute("test2", openvdb::Vec2f(2.2f, 3.3f).lengthSqr()); @@ -887,8 +725,7 @@ TestStandardFunctions::lengthsq() testFunctionOptions(mHarness, "lengthsq"); } -void -TestStandardFunctions::lerp() +TEST_F(TestStandardFunctions, lerp) { mHarness.addAttributes(unittest_util::nameSequence("test", 9), {-1.1, 1.0000001, 1.0000001, -1.0000001, 1.1, -1.1, 6.0, 21.0, -19.0}); @@ -896,8 +733,7 @@ TestStandardFunctions::lerp() testFunctionOptions(mHarness, "lerp"); } -void -TestStandardFunctions::max() +TEST_F(TestStandardFunctions, max) { mHarness.addAttribute("test1", std::max(-1.5, 1.5)); mHarness.addAttribute("test2", std::max(-1.5f, 1.5f)); @@ -905,8 +741,7 @@ TestStandardFunctions::max() testFunctionOptions(mHarness, "max"); } -void -TestStandardFunctions::min() +TEST_F(TestStandardFunctions, min) { mHarness.addAttribute("test1", std::min(-1.5, 1.5)); mHarness.addAttribute("test2", std::min(-1.5f, 1.5f)); @@ -914,8 +749,7 @@ TestStandardFunctions::min() testFunctionOptions(mHarness, "min"); } -void -TestStandardFunctions::normalize() +TEST_F(TestStandardFunctions, normalize) { openvdb::Vec3f expected3f(1.f, 2.f, 3.f); openvdb::Vec3d expected3d(1., 2., 3.); @@ -941,8 +775,7 @@ TestStandardFunctions::normalize() testFunctionOptions(mHarness, "normalize"); } -void -TestStandardFunctions::polardecompose() +TEST_F(TestStandardFunctions, polardecompose) { // See snippet/polardecompose for details const openvdb::Mat3d composite( @@ -958,8 +791,7 @@ TestStandardFunctions::polardecompose() testFunctionOptions(mHarness, "polardecompose"); } -void -TestStandardFunctions::postscale() +TEST_F(TestStandardFunctions, postscale) { mHarness.addAttributes> @@ -1003,8 +835,7 @@ TestStandardFunctions::postscale() testFunctionOptions(mHarness, "postscale"); } -void -TestStandardFunctions::pow() +TEST_F(TestStandardFunctions, pow) { mHarness.addAttributes(unittest_util::nameSequence("float_test", 5),{ 1.0f, @@ -1018,8 +849,7 @@ TestStandardFunctions::pow() testFunctionOptions(mHarness, "pow"); } -void -TestStandardFunctions::prescale() +TEST_F(TestStandardFunctions, prescale) { mHarness.addAttributes> @@ -1063,8 +893,7 @@ TestStandardFunctions::prescale() testFunctionOptions(mHarness, "prescale"); } -void -TestStandardFunctions::pretransform() +TEST_F(TestStandardFunctions, pretransform) { mHarness.addAttributes> ({"test1", "test3", "test7"}, { @@ -1089,8 +918,7 @@ TestStandardFunctions::pretransform() testFunctionOptions(mHarness, "pretransform"); } -void -TestStandardFunctions::print() +TEST_F(TestStandardFunctions, print) { openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform(); @@ -1123,7 +951,7 @@ TestStandardFunctions::print() expected += openvdb::Vec4i(3,4,5,6).str() + "\n"; expected += "bcd\n"; - CPPUNIT_ASSERT_EQUAL(expected, result); + ASSERT_EQ(expected, result); } catch (...) { std::cout.rdbuf(sbuf); @@ -1133,16 +961,14 @@ TestStandardFunctions::print() std::cout.rdbuf(sbuf); } -void -TestStandardFunctions::radians() +TEST_F(TestStandardFunctions, radians) { mHarness.addAttribute("test1", 90.0 * (openvdb::math::pi() / 180.0)); mHarness.addAttribute("test2", -65.0f * (openvdb::math::pi() / 180.0f )); testFunctionOptions(mHarness, "radians"); } -void -TestStandardFunctions::rand() +TEST_F(TestStandardFunctions, rand) { std::mt19937_64 engine; std::uniform_real_distribution uniform(0.0,1.0); @@ -1163,8 +989,7 @@ TestStandardFunctions::rand() testFunctionOptions(mHarness, "rand"); } -void -TestStandardFunctions::rand32() +TEST_F(TestStandardFunctions, rand32) { auto hashToSeed = [](uint64_t hash) -> std::mt19937::result_type @@ -1195,8 +1020,7 @@ TestStandardFunctions::rand32() testFunctionOptions(mHarness, "rand32"); } -void -TestStandardFunctions::rgbtohsv() +TEST_F(TestStandardFunctions, rgbtohsv) { // RGB to HSV conversion. Taken from OpenEXR's ImathColorAlgo auto convert = [](const openvdb::Vec3d& rgb) { @@ -1235,23 +1059,20 @@ TestStandardFunctions::rgbtohsv() testFunctionOptions(mHarness, "rgbtohsv"); } -void -TestStandardFunctions::sign() +TEST_F(TestStandardFunctions, sign) { mHarness.addAttributes(unittest_util::nameSequence("test", 13), { 0,0,0,0,0,0,0, -1,-1,-1, 1,1,1 }); testFunctionOptions(mHarness, "sign"); } -void -TestStandardFunctions::signbit() +TEST_F(TestStandardFunctions, signbit) { mHarness.addAttributes(unittest_util::nameSequence("test", 5), {true,false,true,false,false}); testFunctionOptions(mHarness, "signbit"); } -void -TestStandardFunctions::simplexnoise() +TEST_F(TestStandardFunctions, simplexnoise) { const OSN::OSNoise noiseGenerator; @@ -1268,16 +1089,14 @@ TestStandardFunctions::simplexnoise() testFunctionOptions(mHarness, "simplexnoise"); } -void -TestStandardFunctions::sinh() +TEST_F(TestStandardFunctions, sinh) { mHarness.addAttribute("test1", std::sinh(1.0)); mHarness.addAttribute("test2", std::sinh(1.0f)); testFunctionOptions(mHarness, "sinh"); } -void -TestStandardFunctions::sort() +TEST_F(TestStandardFunctions, sort) { // const openvdb::Vec3d input3d(1.0, -1.0, 0.0); // const openvdb::Vec3f input3f(1.0f, -1.0f, 0.0f); @@ -1305,32 +1124,28 @@ TestStandardFunctions::sort() testFunctionOptions(mHarness, "sort"); } -void -TestStandardFunctions::tan() +TEST_F(TestStandardFunctions, tan) { mHarness.addAttribute("test1", std::tan(1.0)); mHarness.addAttribute("test2", std::tan(1.0f)); testFunctionOptions(mHarness, "tan"); } -void -TestStandardFunctions::tanh() +TEST_F(TestStandardFunctions, tanh) { mHarness.addAttribute("test1", std::tanh(1.0)); mHarness.addAttribute("test2", std::tanh(1.0f)); testFunctionOptions(mHarness, "tanh"); } -void -TestStandardFunctions::trace() +TEST_F(TestStandardFunctions, trace) { mHarness.addAttribute("test1", 6.0); mHarness.addAttribute("test2", 6.0f); testFunctionOptions(mHarness, "trace"); } -void -TestStandardFunctions::truncatemod() +TEST_F(TestStandardFunctions, truncatemod) { // @note these also test that these match % op const std::vector ivalues{ 2,-2,2,-2, }; @@ -1342,8 +1157,7 @@ TestStandardFunctions::truncatemod() testFunctionOptions(mHarness, "truncatemod"); } -void -TestStandardFunctions::transform() +TEST_F(TestStandardFunctions, transform) { mHarness.addAttributes> ({"test1", "test3", "test7"}, { @@ -1368,8 +1182,7 @@ TestStandardFunctions::transform() testFunctionOptions(mHarness, "transform"); } -void -TestStandardFunctions::transpose() +TEST_F(TestStandardFunctions, transpose) { mHarness.addAttribute("test1", diff --git a/openvdb_ax/openvdb_ax/test/integration/TestString.cc b/openvdb_ax/openvdb_ax/test/integration/TestString.cc index 3cb32509f2..aa70a1d1ee 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestString.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestString.cc @@ -5,38 +5,13 @@ #include "../util.h" -#include - using namespace openvdb::points; class TestString : public unittest_util::AXTestCase { -public: - void setUp() override { - unittest_util::AXTestCase::setUp(); - } - - CPPUNIT_TEST_SUITE(TestString); - CPPUNIT_TEST(testAssignCompound); - CPPUNIT_TEST(testAssignFromAttributes); - CPPUNIT_TEST(testAssignFromLocals); - CPPUNIT_TEST(testAssignNewOverwrite); - CPPUNIT_TEST(testBinaryConcat); - CPPUNIT_TEST(testDeclare); - CPPUNIT_TEST_SUITE_END(); - - void testAssignCompound(); - void testAssignFromAttributes(); - void testAssignFromLocals(); - void testAssignNewOverwrite(); - void testBinaryConcat(); - void testDeclare(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestString); - -void -TestString::testAssignCompound() +TEST_F(TestString, testAssignCompound) { mHarness.addAttributes(unittest_util::nameSequence("test", 3), {"foo", "foobar", "aaaaaaaaaa"}); @@ -44,8 +19,7 @@ TestString::testAssignCompound() AXTESTS_STANDARD_ASSERT(); } -void -TestString::testAssignFromAttributes() +TEST_F(TestString, testAssignFromAttributes) { mHarness.addInputPtAttributes({"string_test1"}, {"test"}); mHarness.addExpectedAttributes(unittest_util::nameSequence("string_test", 6), @@ -58,8 +32,7 @@ TestString::testAssignFromAttributes() AXTESTS_STANDARD_ASSERT(); } -void -TestString::testAssignFromLocals() +TEST_F(TestString, testAssignFromLocals) { mHarness.addAttributes(unittest_util::nameSequence("string_test", 4), {"test", "test", "new string size", ""}); @@ -67,8 +40,7 @@ TestString::testAssignFromLocals() AXTESTS_STANDARD_ASSERT(); } -void -TestString::testAssignNewOverwrite() +TEST_F(TestString, testAssignNewOverwrite) { mHarness.addExpectedAttributes({"string_test1", "string_test2"}, {"next_value", "new_value"}); @@ -80,8 +52,7 @@ TestString::testAssignNewOverwrite() AXTESTS_STANDARD_ASSERT(); } -void -TestString::testBinaryConcat() +TEST_F(TestString, testBinaryConcat) { mHarness.addExpectedAttributes(unittest_util::nameSequence("string_test", 6), {"test new value", "test new value", "test new value", "test new value", "", "test new value"}); @@ -93,8 +64,7 @@ TestString::testBinaryConcat() AXTESTS_STANDARD_ASSERT(); } -void -TestString::testDeclare() +TEST_F(TestString, testDeclare) { mHarness.addAttribute("string_test", "test"); mHarness.executeCode("test/snippets/string/declare"); diff --git a/openvdb_ax/openvdb_ax/test/integration/TestTernary.cc b/openvdb_ax/openvdb_ax/test/integration/TestTernary.cc index 334f755f91..2774f437ef 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestTernary.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestTernary.cc @@ -3,28 +3,14 @@ #include "TestHarness.h" -#include - using namespace openvdb::points; class TestTernary : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestTernary); - CPPUNIT_TEST(testTernary); - CPPUNIT_TEST(testTernaryVoid); - CPPUNIT_TEST(testTernaryErrors); - CPPUNIT_TEST_SUITE_END(); - - void testTernary(); - void testTernaryVoid(); - void testTernaryErrors(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestTernary); -void -TestTernary::testTernary() +TEST_F(TestTernary, testTernary) { mHarness.addAttribute("ternary_test1", true); mHarness.addAttribute("ternary_test2", true); @@ -79,8 +65,7 @@ TestTernary::testTernary() AXTESTS_STANDARD_ASSERT(); } -void -TestTernary::testTernaryVoid() +TEST_F(TestTernary, testTernaryVoid) { mHarness.testVolumes(false); mHarness.addExpectedGroups({"notdead"}, {true}); @@ -89,10 +74,9 @@ TestTernary::testTernaryVoid() AXTESTS_STANDARD_ASSERT(); } -void -TestTernary::testTernaryErrors() +TEST_F(TestTernary, testTernaryErrors) { const bool success = mHarness.executeCode("test/snippets/ternary/ternaryErrors"); - CPPUNIT_ASSERT(!success); + ASSERT_TRUE(!success); } diff --git a/openvdb_ax/openvdb_ax/test/integration/TestUnary.cc b/openvdb_ax/openvdb_ax/test/integration/TestUnary.cc index aa34c1063f..16d23e503e 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestUnary.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestUnary.cc @@ -4,29 +4,13 @@ #include "TestHarness.h" #include "../util.h" -#include - class TestUnary : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestUnary); - CPPUNIT_TEST(testBitwiseNot); - CPPUNIT_TEST(testNegate); - CPPUNIT_TEST(testNot); - CPPUNIT_TEST(testUnaryVector); - CPPUNIT_TEST_SUITE_END(); - - void testBitwiseNot(); - void testNegate(); - void testNot(); - void testUnaryVector(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestUnary); -void -TestUnary::testBitwiseNot() +TEST_F(TestUnary, testBitwiseNot) { mHarness.addAttributes({"int_test", "int_test2"}, {-9, -8}); @@ -35,8 +19,7 @@ TestUnary::testBitwiseNot() AXTESTS_STANDARD_ASSERT(); } -void -TestUnary::testNegate() +TEST_F(TestUnary, testNegate) { mHarness.addAttribute("int_test", -3); mHarness.addAttribute("float_test", -5.5f); @@ -46,8 +29,7 @@ TestUnary::testNegate() AXTESTS_STANDARD_ASSERT(); } -void -TestUnary::testNot() +TEST_F(TestUnary, testNot) { mHarness.addAttributes({"bool_test", "bool_test2"}, {false, true}); @@ -56,8 +38,7 @@ TestUnary::testNot() AXTESTS_STANDARD_ASSERT(); } -void -TestUnary::testUnaryVector() +TEST_F(TestUnary, testUnaryVector) { // vec3 diff --git a/openvdb_ax/openvdb_ax/test/integration/TestVDBFunctions.cc b/openvdb_ax/openvdb_ax/test/integration/TestVDBFunctions.cc index 723bb837fb..15a68a81c0 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestVDBFunctions.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestVDBFunctions.cc @@ -16,34 +16,13 @@ #include #include -#include class TestVDBFunctions : public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestVDBFunctions); - CPPUNIT_TEST(addremovefromgroup); - CPPUNIT_TEST(deletepoint); - CPPUNIT_TEST(getcoord); - CPPUNIT_TEST(getvoxelpws); - CPPUNIT_TEST(ingroupOrder); - CPPUNIT_TEST(ingroup); - CPPUNIT_TEST(testValidContext); - CPPUNIT_TEST_SUITE_END(); - - void addremovefromgroup(); - void deletepoint(); - void getcoord(); - void getvoxelpws(); - void ingroupOrder(); - void ingroup(); - void testValidContext(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestVDBFunctions); -void -TestVDBFunctions::addremovefromgroup() +TEST_F(TestVDBFunctions, addremovefromgroup) { const std::vector positions = { {1, 1, 1}, @@ -89,65 +68,64 @@ TestVDBFunctions::addremovefromgroup() for (size_t i = 1; i <= 9; i++) { const std::string groupName = "newTestGroup" + std::to_string(i); - CPPUNIT_ASSERT_MESSAGE(groupName + " doesn't exist", desc.hasGroup(groupName)); + ASSERT_TRUE(desc.hasGroup(groupName)) << (groupName + " doesn't exist"); } openvdb::points::GroupHandle newTestGroupHandle = leafIter->groupHandle("newTestGroup9"); - CPPUNIT_ASSERT(!newTestGroupHandle.get(0)); - CPPUNIT_ASSERT(newTestGroupHandle.get(1)); - CPPUNIT_ASSERT(!newTestGroupHandle.get(2)); - CPPUNIT_ASSERT(newTestGroupHandle.get(3)); + ASSERT_TRUE(!newTestGroupHandle.get(0)); + ASSERT_TRUE(newTestGroupHandle.get(1)); + ASSERT_TRUE(!newTestGroupHandle.get(2)); + ASSERT_TRUE(newTestGroupHandle.get(3)); // other new groups should be untouched for (size_t i = 1; i <= 8; i++) { openvdb::points::GroupHandle handle = leafIter->groupHandle("newTestGroup" + std::to_string(i)); - CPPUNIT_ASSERT(handle.get(0)); - CPPUNIT_ASSERT(handle.get(1)); - CPPUNIT_ASSERT(handle.get(2)); - CPPUNIT_ASSERT(handle.get(3)); + ASSERT_TRUE(handle.get(0)); + ASSERT_TRUE(handle.get(1)); + ASSERT_TRUE(handle.get(2)); + ASSERT_TRUE(handle.get(3)); } openvdb::points::GroupHandle existingTestGroupHandle = leafIter->groupHandle("existingTestGroup"); - CPPUNIT_ASSERT(existingTestGroupHandle.get(0)); - CPPUNIT_ASSERT(!existingTestGroupHandle.get(1)); - CPPUNIT_ASSERT(existingTestGroupHandle.get(2)); - CPPUNIT_ASSERT(!existingTestGroupHandle.get(3)); + ASSERT_TRUE(existingTestGroupHandle.get(0)); + ASSERT_TRUE(!existingTestGroupHandle.get(1)); + ASSERT_TRUE(existingTestGroupHandle.get(2)); + ASSERT_TRUE(!existingTestGroupHandle.get(3)); // membership of this group should now mirror exisingTestGroup openvdb::points::GroupHandle existingTestGroup2Handle = leafIter->groupHandle("existingTestGroup2"); - CPPUNIT_ASSERT(existingTestGroup2Handle.get(0)); - CPPUNIT_ASSERT(!existingTestGroup2Handle.get(1)); - CPPUNIT_ASSERT(existingTestGroup2Handle.get(2)); - CPPUNIT_ASSERT(!existingTestGroup2Handle.get(3)); + ASSERT_TRUE(existingTestGroup2Handle.get(0)); + ASSERT_TRUE(!existingTestGroup2Handle.get(1)); + ASSERT_TRUE(existingTestGroup2Handle.get(2)); + ASSERT_TRUE(!existingTestGroup2Handle.get(3)); // check that "nonExistentGroup" was _not_ added to the tree, as it is removed from but not present - CPPUNIT_ASSERT(!desc.hasGroup("nonExistentGroup")); + ASSERT_TRUE(!desc.hasGroup("nonExistentGroup")); // now check 2 new attributes added to tree openvdb::points::AttributeHandle testResultAttributeHandle1(*attributeSet.get("newTestAttribute1")); openvdb::points::AttributeHandle testResultAttributeHandle2(*attributeSet.get("newTestAttribute2")); for (openvdb::Index i = 0;i < 4; i++) { - CPPUNIT_ASSERT(testResultAttributeHandle1.get(i)); + ASSERT_TRUE(testResultAttributeHandle1.get(i)); } // should match "existingTestGroup" - CPPUNIT_ASSERT(testResultAttributeHandle2.get(0)); - CPPUNIT_ASSERT(!testResultAttributeHandle2.get(1)); - CPPUNIT_ASSERT(testResultAttributeHandle2.get(2)); - CPPUNIT_ASSERT(!testResultAttributeHandle2.get(3)); + ASSERT_TRUE(testResultAttributeHandle2.get(0)); + ASSERT_TRUE(!testResultAttributeHandle2.get(1)); + ASSERT_TRUE(testResultAttributeHandle2.get(2)); + ASSERT_TRUE(!testResultAttributeHandle2.get(3)); // pre-existing attribute should still be present with the correct value for (; leafIter; ++leafIter) { openvdb::points::AttributeHandle handle(leafIter->attributeArray("existingTestAttribute")); - CPPUNIT_ASSERT(handle.isUniform()); - CPPUNIT_ASSERT_EQUAL(2, handle.get(0)); + ASSERT_TRUE(handle.isUniform()); + ASSERT_EQ(2, handle.get(0)); } } -void -TestVDBFunctions::deletepoint() +TEST_F(TestVDBFunctions, deletepoint) { // run first, should not modify grid as attribute doesn't exist // @todo - need to massively improve this test @@ -166,8 +144,7 @@ TestVDBFunctions::deletepoint() AXTESTS_STANDARD_ASSERT(); } -void -TestVDBFunctions::getcoord() +TEST_F(TestVDBFunctions, getcoord) { // create 3 test grids std::vector testGrids(3); @@ -229,11 +206,10 @@ TestVDBFunctions::getcoord() if (!check) outMessage << stream.str() << std::endl; } - CPPUNIT_ASSERT_MESSAGE(outMessage.str(), check); + ASSERT_TRUE(check) << outMessage.str(); } -void -TestVDBFunctions::getvoxelpws() +TEST_F(TestVDBFunctions, getvoxelpws) { mHarness.testPoints(false); mHarness.testSparseVolumes(false); // disable as getvoxelpws will densify @@ -244,8 +220,7 @@ TestVDBFunctions::getvoxelpws() AXTESTS_STANDARD_ASSERT(); } -void -TestVDBFunctions::ingroupOrder() +TEST_F(TestVDBFunctions, ingroupOrder) { // Test that groups inserted in a different alphabetical order are inferred // correctly (a regression test for a previous issue) @@ -259,11 +234,10 @@ TestVDBFunctions::ingroupOrder() AXTESTS_STANDARD_ASSERT(); } -void -TestVDBFunctions::ingroup() +TEST_F(TestVDBFunctions, ingroup) { // test a tree with no groups - CPPUNIT_ASSERT(mHarness.mInputPointGrids.size() > 0); + ASSERT_TRUE(mHarness.mInputPointGrids.size() > 0); openvdb::points::PointDataGrid::Ptr pointDataGrid1 = mHarness.mInputPointGrids.back(); openvdb::points::PointDataTree& pointTree = pointDataGrid1->tree(); @@ -274,7 +248,7 @@ TestVDBFunctions::ingroup() openvdb::ax::PointExecutable::Ptr executable = compiler.compile(code); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*pointDataGrid1)); + ASSERT_NO_THROW(executable->execute(*pointDataGrid1)); // the snippet of code adds "groupTest" and groupTest2 attributes which should both have the values // "1" everywhere @@ -283,8 +257,8 @@ TestVDBFunctions::ingroup() openvdb::points::AttributeHandle handle1(leafIter->attributeArray("groupTest")); openvdb::points::AttributeHandle handle2(leafIter->attributeArray("groupTest2")); for (auto iter = leafIter->beginIndexAll(); iter; ++iter) { - CPPUNIT_ASSERT_EQUAL(1, handle1.get(*iter)); - CPPUNIT_ASSERT_EQUAL(1, handle2.get(*iter)); + ASSERT_EQ(1, handle1.get(*iter)); + ASSERT_EQ(1, handle2.get(*iter)); } } @@ -292,21 +266,21 @@ TestVDBFunctions::ingroup() auto leafIter = pointTree.cbeginLeaf(); const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet(); const openvdb::points::AttributeSet::Descriptor& descriptor1 = attributeSet.descriptor(); - CPPUNIT_ASSERT_EQUAL(static_cast(0), descriptor1.groupMap().size()); + ASSERT_EQ(static_cast(0), descriptor1.groupMap().size()); // now we add a single group and run the test again openvdb::points::appendGroup(pointTree, "testGroup"); setGroup(pointTree, "testGroup", false); executable = compiler.compile(code); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*pointDataGrid1)); + ASSERT_NO_THROW(executable->execute(*pointDataGrid1)); for (auto leafIter = pointTree.cbeginLeaf(); leafIter; ++leafIter) { openvdb::points::AttributeHandle handle1(leafIter->attributeArray("groupTest")); openvdb::points::AttributeHandle handle2(leafIter->attributeArray("groupTest2")); for (auto iter = leafIter->beginIndexAll(); iter; ++iter) { - CPPUNIT_ASSERT_EQUAL(1, handle1.get(*iter)); - CPPUNIT_ASSERT_EQUAL(1, handle2.get(*iter)); + ASSERT_EQ(1, handle1.get(*iter)); + ASSERT_EQ(1, handle2.get(*iter)); } } @@ -343,29 +317,28 @@ TestVDBFunctions::ingroup() openvdb::points::setGroup(*pointDataTree2, pointIndexGrid->tree(), membershipTestGroup2, "testGroup2"); executable = compiler.compile(code); - CPPUNIT_ASSERT_NO_THROW(executable->execute(*pointDataGrid2)); + ASSERT_NO_THROW(executable->execute(*pointDataGrid2)); auto leafIter2 = pointDataTree2->cbeginLeaf(); const openvdb::points::AttributeSet& attributeSet2 = leafIter2->attributeSet(); openvdb::points::AttributeHandle testResultAttributeHandle(*attributeSet2.get("groupTest2")); // these should line up with the defined membership - CPPUNIT_ASSERT_EQUAL(testResultAttributeHandle.get(0), 1); - CPPUNIT_ASSERT_EQUAL(testResultAttributeHandle.get(1), 1); - CPPUNIT_ASSERT_EQUAL(testResultAttributeHandle.get(2), 2); - CPPUNIT_ASSERT_EQUAL(testResultAttributeHandle.get(3), 1); + ASSERT_EQ(testResultAttributeHandle.get(0), 1); + ASSERT_EQ(testResultAttributeHandle.get(1), 1); + ASSERT_EQ(testResultAttributeHandle.get(2), 2); + ASSERT_EQ(testResultAttributeHandle.get(3), 1); // check that no new groups have been created or deleted const openvdb::points::AttributeSet::Descriptor& descriptor2 = attributeSet2.descriptor(); - CPPUNIT_ASSERT_EQUAL(static_cast(9), descriptor2.groupMap().size()); + ASSERT_EQ(static_cast(9), descriptor2.groupMap().size()); for (size_t i = 0; i < 9; i++) { - CPPUNIT_ASSERT(descriptor2.hasGroup("testGroup" + std::to_string(i))); + ASSERT_TRUE(descriptor2.hasGroup("testGroup" + std::to_string(i))); } } -void -TestVDBFunctions::testValidContext() +TEST_F(TestVDBFunctions, testValidContext) { std::shared_ptr C(new llvm::LLVMContext); #if LLVM_VERSION_MAJOR >= 15 @@ -414,9 +387,9 @@ TestVDBFunctions::testValidContext() if (func.second.isInternal()) continue; const openvdb::ax::codegen::FunctionGroup* const ptr = func.second.function(); - CPPUNIT_ASSERT(ptr); + ASSERT_TRUE(ptr); const auto& signatures = ptr->list(); - CPPUNIT_ASSERT(!signatures.empty()); + ASSERT_TRUE(!signatures.empty()); // Don't check C bindings const auto F = signatures.front(); @@ -424,9 +397,10 @@ TestVDBFunctions::testValidContext() const std::string code = generate(F, func.first); - CPPUNIT_ASSERT_THROW_MESSAGE(ERROR_MSG("Expected Compiler Error", code), + ASSERT_THROW( compiler.compile(code), - openvdb::AXCompilerError); + openvdb::AXCompilerError + ) << ERROR_MSG("Expected Compiler Error", code); } } @@ -441,9 +415,9 @@ TestVDBFunctions::testValidContext() if (func.second.isInternal()) continue; const openvdb::ax::codegen::FunctionGroup* const ptr = func.second.function(); - CPPUNIT_ASSERT(ptr); + ASSERT_TRUE(ptr); const auto& signatures = ptr->list(); - CPPUNIT_ASSERT(!signatures.empty()); + ASSERT_TRUE(!signatures.empty()); // Don't check C bindings const auto F = signatures.front(); @@ -451,9 +425,10 @@ TestVDBFunctions::testValidContext() const std::string code = generate(F, func.first); - CPPUNIT_ASSERT_THROW_MESSAGE(ERROR_MSG("Expected Compiler Error", code), + ASSERT_THROW( compiler.compile(code), - openvdb::AXCompilerError); + openvdb::AXCompilerError + ) << ERROR_MSG("Expected Compiler Error", code); } } } diff --git a/openvdb_ax/openvdb_ax/test/integration/TestWorldSpaceAccessors.cc b/openvdb_ax/openvdb_ax/test/integration/TestWorldSpaceAccessors.cc index 1565cc6e19..ae6bc9a07a 100644 --- a/openvdb_ax/openvdb_ax/test/integration/TestWorldSpaceAccessors.cc +++ b/openvdb_ax/openvdb_ax/test/integration/TestWorldSpaceAccessors.cc @@ -13,31 +13,16 @@ #include #include -#include - #include using namespace openvdb::points; class TestWorldSpaceAccessors: public unittest_util::AXTestCase { -public: - CPPUNIT_TEST_SUITE(TestWorldSpaceAccessors); - CPPUNIT_TEST(testWorldSpaceAssign); - CPPUNIT_TEST(testWorldSpaceAssignComponent); - CPPUNIT_TEST(testWorldSpaceAssignBound); - - CPPUNIT_TEST_SUITE_END(); - - void testWorldSpaceAssign(); - void testWorldSpaceAssignComponent(); - void testWorldSpaceAssignBound(); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestWorldSpaceAccessors); -void -TestWorldSpaceAccessors::testWorldSpaceAssign() +TEST_F(TestWorldSpaceAccessors, testWorldSpaceAssign) { std::vector positions = {openvdb::Vec3d(0.0, 0.0, 0.0), @@ -45,20 +30,20 @@ TestWorldSpaceAccessors::testWorldSpaceAssign() openvdb::Vec3d(0.0, 1.0, 0.0), openvdb::Vec3d(1.0, 1.0, 0.0)}; - CPPUNIT_ASSERT(mHarness.mInputPointGrids.size() > 0); + ASSERT_TRUE(mHarness.mInputPointGrids.size() > 0); PointDataGrid::Ptr grid = mHarness.mInputPointGrids.back(); openvdb::points::PointDataTree* tree = &(grid->tree()); // @note snippet moves all points to a single leaf node - CPPUNIT_ASSERT_EQUAL(openvdb::points::pointCount(*tree), openvdb::Index64(4)); + ASSERT_EQ(openvdb::points::pointCount(*tree), openvdb::Index64(4)); const std::string code = unittest_util::loadText("test/snippets/worldspace/worldSpaceAssign"); - CPPUNIT_ASSERT_NO_THROW(openvdb::ax::run(code.c_str(), *grid)); + ASSERT_NO_THROW(openvdb::ax::run(code.c_str(), *grid)); // Tree is modified if points are moved tree = &(grid->tree()); - CPPUNIT_ASSERT_EQUAL(openvdb::points::pointCount(*tree), openvdb::Index64(4)); + ASSERT_EQ(openvdb::points::pointCount(*tree), openvdb::Index64(4)); // test that P_original has the world-space value of the P attribute prior to running this snippet. // test that P_new has the expected world-space P value @@ -67,7 +52,7 @@ TestWorldSpaceAccessors::testWorldSpaceAssign() const openvdb::math::Transform& transform = grid->transform(); for (; leaf; ++leaf) { - CPPUNIT_ASSERT(leaf->pointCount() == 4); + ASSERT_TRUE(leaf->pointCount() == 4); AttributeHandle::Ptr pOriginalHandle = AttributeHandle::create(leaf->attributeArray("P_original")); AttributeHandle::Ptr pNewHandle = AttributeHandle::create(leaf->attributeArray("P_new")); @@ -84,40 +69,39 @@ TestWorldSpaceAccessors::testWorldSpaceAssign() const openvdb::Vec3f& oldPosition = positions[idx]; const openvdb::Vec3f& pOriginal = pOriginalHandle->get(idx); - CPPUNIT_ASSERT_EQUAL(oldPosition.x(), pOriginal.x()); - CPPUNIT_ASSERT_EQUAL(oldPosition.y(), pOriginal.y()); - CPPUNIT_ASSERT_EQUAL(oldPosition.z(), pOriginal.z()); + ASSERT_EQ(oldPosition.x(), pOriginal.x()); + ASSERT_EQ(oldPosition.y(), pOriginal.y()); + ASSERT_EQ(oldPosition.z(), pOriginal.z()); // test that the value for P_new, which should be the world space value of the points const openvdb::Vec3f newPosition = openvdb::Vec3f(2.22f, 3.33f, 4.44f); const openvdb::Vec3f& pNew = pNewHandle->get(idx); - CPPUNIT_ASSERT_EQUAL(newPosition.x(), pNew.x()); - CPPUNIT_ASSERT_EQUAL(newPosition.y(), pNew.y()); - CPPUNIT_ASSERT_EQUAL(newPosition.z(), pNew.z()); + ASSERT_EQ(newPosition.x(), pNew.x()); + ASSERT_EQ(newPosition.y(), pNew.y()); + ASSERT_EQ(newPosition.z(), pNew.z()); // test that the value for P, which should be the updated voxel space value of the points const openvdb::Vec3f voxelSpacePosition = openvdb::Vec3f(0.2f, 0.3f, 0.4f); const openvdb::Vec3f& pVoxelSpace = pHandle->get(idx); // @todo: look at improving precision - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.x(), pVoxelSpace.x(), 1e-5); - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.y(), pVoxelSpace.y(), 1e-5); - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.z(), pVoxelSpace.z(), 1e-5); + ASSERT_NEAR(voxelSpacePosition.x(), pVoxelSpace.x(), 1e-5); + ASSERT_NEAR(voxelSpacePosition.y(), pVoxelSpace.y(), 1e-5); + ASSERT_NEAR(voxelSpacePosition.z(), pVoxelSpace.z(), 1e-5); // test that the value for P, which should be the updated world space value of the points const openvdb::Vec3f positionWS = openvdb::Vec3f(2.22f, 3.33f, 4.44f); const openvdb::Vec3f pWS = transform.indexToWorld(coord.asVec3d() + pHandle->get(idx)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.x(), pWS.x(), std::numeric_limits::epsilon()); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.y(), pWS.y(), std::numeric_limits::epsilon()); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.z(), pWS.z(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWS.x(), pWS.x(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWS.y(), pWS.y(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWS.z(), pWS.z(), std::numeric_limits::epsilon()); } } } } -void -TestWorldSpaceAccessors::testWorldSpaceAssignComponent() +TEST_F(TestWorldSpaceAccessors, testWorldSpaceAssignComponent) { std::vector positions = {openvdb::Vec3d(0.0, 0.0, 0.0), @@ -125,16 +109,16 @@ TestWorldSpaceAccessors::testWorldSpaceAssignComponent() openvdb::Vec3d(0.0, 1.0, 0.0), openvdb::Vec3d(1.0, 1.0, 0.0)}; - CPPUNIT_ASSERT(mHarness.mInputPointGrids.size() > 0); + ASSERT_TRUE(mHarness.mInputPointGrids.size() > 0); PointDataGrid::Ptr grid = mHarness.mInputPointGrids.back(); openvdb::points::PointDataTree& tree = grid->tree(); const openvdb::Index64 originalCount = pointCount(tree); - CPPUNIT_ASSERT(originalCount > 0); + ASSERT_TRUE(originalCount > 0); const std::string code = unittest_util::loadText("test/snippets/worldspace/worldSpaceAssignComponent"); - CPPUNIT_ASSERT_NO_THROW(openvdb::ax::run(code.c_str(), *grid)); + ASSERT_NO_THROW(openvdb::ax::run(code.c_str(), *grid)); // test that P_original has the world-space value of the P attribute prior to running this snippet. // test that P_new has the expected world-space P value @@ -158,37 +142,36 @@ TestWorldSpaceAccessors::testWorldSpaceAssignComponent() // const float oldPosition = positions[idx].x(); // const float pXOriginal = pXOriginalHandle->get(idx); - // CPPUNIT_ASSERT_EQUAL(oldPosition, pOriginal.x()); + // ASSERT_EQ(oldPosition, pOriginal.x()); // test that the value for P_new, which should be the world space value of the points const float newX = 5.22f; const float pNewX = pNewHandle->get(idx); - CPPUNIT_ASSERT_EQUAL(newX, pNewX); + ASSERT_EQ(newX, pNewX); // test that the value for P, which should be the updated voxel space value of the points const float voxelSpacePosition = 0.2f; const openvdb::Vec3f& pVoxelSpace = pHandle->get(idx); // @todo: look at improving precision - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition, pVoxelSpace.x(), 1e-5); + ASSERT_NEAR(voxelSpacePosition, pVoxelSpace.x(), 1e-5); //@todo: requiring point order, check the y and z components are unchanged - // CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.y(), pVoxelSpace.y(), 1e-6); - // CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.z(), pVoxelSpace.z(), 1e-6); + // ASSERT_NEAR(voxelSpacePosition.y(), pVoxelSpace.y(), 1e-6); + // ASSERT_NEAR(voxelSpacePosition.z(), pVoxelSpace.z(), 1e-6); // test that the value for P, which should be the updated world space value of the points const float positionWSX = 5.22f; const openvdb::Vec3f pWS = transform.indexToWorld(coord.asVec3d() + pHandle->get(idx)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWSX, pWS.x(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWSX, pWS.x(), std::numeric_limits::epsilon()); //@todo: requiring point order, check the y and z components are unchanged - // CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.y(), pWS.y(), std::numeric_limits::epsilon()); - // CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.z(), pWS.z(), std::numeric_limits::epsilon()); + // ASSERT_NEAR(positionWS.y(), pWS.y(), std::numeric_limits::epsilon()); + // ASSERT_NEAR(positionWS.z(), pWS.z(), std::numeric_limits::epsilon()); } } } } -void -TestWorldSpaceAccessors::testWorldSpaceAssignBound() +TEST_F(TestWorldSpaceAccessors, testWorldSpaceAssignBound) { std::vector positions = {openvdb::Vec3d(0.0, 0.0, 0.0), @@ -196,20 +179,20 @@ TestWorldSpaceAccessors::testWorldSpaceAssignBound() openvdb::Vec3d(0.0, 1.0, 0.0), openvdb::Vec3d(1.0, 1.0, 0.0)}; - CPPUNIT_ASSERT(mHarness.mInputPointGrids.size() > 0); + ASSERT_TRUE(mHarness.mInputPointGrids.size() > 0); PointDataGrid::Ptr grid = mHarness.mInputPointGrids.back(); openvdb::points::PointDataTree* tree = &(grid->tree()); // @note snippet moves all points to a single leaf node - CPPUNIT_ASSERT_EQUAL(openvdb::points::pointCount(*tree), openvdb::Index64(4)); + ASSERT_EQ(openvdb::points::pointCount(*tree), openvdb::Index64(4)); const std::string code = unittest_util::loadText("test/snippets/worldspace/worldSpaceAssignBound"); - CPPUNIT_ASSERT_NO_THROW(openvdb::ax::run(code.c_str(), *grid, {{"pos","P"}})); + ASSERT_NO_THROW(openvdb::ax::run(code.c_str(), *grid, {{"pos","P"}})); // Tree is modified if points are moved tree = &(grid->tree()); - CPPUNIT_ASSERT_EQUAL(openvdb::points::pointCount(*tree), openvdb::Index64(4)); + ASSERT_EQ(openvdb::points::pointCount(*tree), openvdb::Index64(4)); // test that P_original has the world-space value of the P attribute prior to running this snippet. // test that P_new has the expected world-space P value @@ -218,7 +201,7 @@ TestWorldSpaceAccessors::testWorldSpaceAssignBound() const openvdb::math::Transform& transform = grid->transform(); for (; leaf; ++leaf) { - CPPUNIT_ASSERT(leaf->pointCount() == 4); + ASSERT_TRUE(leaf->pointCount() == 4); AttributeHandle::Ptr pOriginalHandle = AttributeHandle::create(leaf->attributeArray("P_original")); AttributeHandle::Ptr pNewHandle = AttributeHandle::create(leaf->attributeArray("P_new")); @@ -235,32 +218,32 @@ TestWorldSpaceAccessors::testWorldSpaceAssignBound() const openvdb::Vec3f& oldPosition = positions[idx]; const openvdb::Vec3f& pOriginal = pOriginalHandle->get(idx); - CPPUNIT_ASSERT_EQUAL(oldPosition.x(), pOriginal.x()); - CPPUNIT_ASSERT_EQUAL(oldPosition.y(), pOriginal.y()); - CPPUNIT_ASSERT_EQUAL(oldPosition.z(), pOriginal.z()); + ASSERT_EQ(oldPosition.x(), pOriginal.x()); + ASSERT_EQ(oldPosition.y(), pOriginal.y()); + ASSERT_EQ(oldPosition.z(), pOriginal.z()); // test that the value for P_new, which should be the world space value of the points const openvdb::Vec3f newPosition = openvdb::Vec3f(2.22f, 3.33f, 4.44f); const openvdb::Vec3f& pNew = pNewHandle->get(idx); - CPPUNIT_ASSERT_EQUAL(newPosition.x(), pNew.x()); - CPPUNIT_ASSERT_EQUAL(newPosition.y(), pNew.y()); - CPPUNIT_ASSERT_EQUAL(newPosition.z(), pNew.z()); + ASSERT_EQ(newPosition.x(), pNew.x()); + ASSERT_EQ(newPosition.y(), pNew.y()); + ASSERT_EQ(newPosition.z(), pNew.z()); // test that the value for P, which should be the updated voxel space value of the points const openvdb::Vec3f voxelSpacePosition = openvdb::Vec3f(0.2f, 0.3f, 0.4f); const openvdb::Vec3f& pVoxelSpace = pHandle->get(idx); // @todo: look at improving precision - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.x(), pVoxelSpace.x(), 1e-5); - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.y(), pVoxelSpace.y(), 1e-5); - CPPUNIT_ASSERT_DOUBLES_EQUAL(voxelSpacePosition.z(), pVoxelSpace.z(), 1e-5); + ASSERT_NEAR(voxelSpacePosition.x(), pVoxelSpace.x(), 1e-5); + ASSERT_NEAR(voxelSpacePosition.y(), pVoxelSpace.y(), 1e-5); + ASSERT_NEAR(voxelSpacePosition.z(), pVoxelSpace.z(), 1e-5); // test that the value for P, which should be the updated world space value of the points const openvdb::Vec3f positionWS = openvdb::Vec3f(2.22f, 3.33f, 4.44f); const openvdb::Vec3f pWS = transform.indexToWorld(coord.asVec3d() + pHandle->get(idx)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.x(), pWS.x(), std::numeric_limits::epsilon()); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.y(), pWS.y(), std::numeric_limits::epsilon()); - CPPUNIT_ASSERT_DOUBLES_EQUAL(positionWS.z(), pWS.z(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWS.x(), pWS.x(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWS.y(), pWS.y(), std::numeric_limits::epsilon()); + ASSERT_NEAR(positionWS.z(), pWS.z(), std::numeric_limits::epsilon()); } } } From f5276dbb9acb11d2e22c245cda94b0209dd5847a Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Mon, 28 Oct 2024 17:03:32 -0700 Subject: [PATCH 20/21] Remove cppunit utilities from main AX test runner Signed-off-by: Tim Straubinger --- openvdb_ax/openvdb_ax/test/main.cc | 240 +---------------------------- 1 file changed, 1 insertion(+), 239 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/main.cc b/openvdb_ax/openvdb_ax/test/main.cc index fa3bce1bdc..cb5f4be1f4 100644 --- a/openvdb_ax/openvdb_ax/test/main.cc +++ b/openvdb_ax/openvdb_ax/test/main.cc @@ -4,33 +4,9 @@ #include #include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include #include -#include // for std::shuffle() -#include // for std::round() -#include // for EXIT_SUCCESS -#include // for strrchr() -#include -#include -#include -#include -#include -#include - - /// @note Global unit test flag enabled with -g which symbolises the integration /// tests to auto-generate their AX tests. Any previous tests will be /// overwritten. @@ -39,218 +15,6 @@ int sGenerateAX = false; namespace { -using StringVec = std::vector; - - -void -usage(const char* progName, std::ostream& ostrm) -{ - ostrm << -"Usage: " << progName << " [options]\n" << -"Which: runs OpenVDB AX library unit tests\n" << -"Options:\n" << -" -f file read whitespace-separated names of tests to be run\n" << -" from the given file (\"#\" comments are supported)\n" << -" -l list all available tests\n" << -" -shuffle run tests in random order\n" << -" -t test specific suite or test to run, e.g., \"-t TestGrid\"\n" << -" or \"-t TestGrid::testGetGrid\" (default: run all tests)\n" << -" -v verbose output\n" << -" -g As well as testing, auto-generate any integration tests\n"; -#ifdef OPENVDB_USE_LOG4CPLUS - ostrm << -"\n" << -" -error log fatal and non-fatal errors (default: log only fatal errors)\n" << -" -warn log warnings and errors\n" << -" -info log info messages, warnings and errors\n" << -" -debug log debugging messages, info messages, warnings and errors\n"; -#endif -} - - -void -getTestNames(StringVec& nameVec, const CppUnit::Test* test) -{ - if (test) { - const int numChildren = test->getChildTestCount(); - if (numChildren == 0) { - nameVec.push_back(test->getName()); - } else { - for (int i = 0; i < test->getChildTestCount(); ++i) { - getTestNames(nameVec, test->getChildTestAt(i)); - } - } - } -} - - -/// Listener that prints the name, elapsed time, and error status of each test -class TimedTestProgressListener: public CppUnit::TestListener -{ -public: - void startTest(CppUnit::Test* test) override - { - mFailed = false; - std::cout << test->getName() << std::flush; - mTimer.start(); - } - - void addFailure(const CppUnit::TestFailure& failure) override - { - std::cout << " : " << (failure.isError() ? "error" : "assertion"); - mFailed = true; - } - - void endTest(CppUnit::Test*) override - { - if (!mFailed) { - // Print elapsed time only for successful tests. - const double msec = std::round(mTimer.milliseconds()); - if (msec > 1.0) { - openvdb::util::printTime(std::cout, msec, " : OK (", ")", - /*width=*/0, /*precision=*/(msec > 1000.0 ? 1 : 0), /*verbose=*/0); - } else { - std::cout << " : OK (<1ms)"; - } - } - std::cout << std::endl; - } - -private: - openvdb::util::CpuTimer mTimer; - bool mFailed = false; -}; - - -int -run(int argc, char* argv[]) -{ - const char* progName = argv[0]; - if (const char* ptr = ::strrchr(progName, '/')) progName = ptr + 1; - - bool shuffle = false, verbose = false; - StringVec tests; - for (int i = 1; i < argc; ++i) { - const std::string arg = argv[i]; - if (arg == "-l") { - StringVec allTests; - const CppUnit::Test* tests = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - getTestNames(allTests, tests); - delete tests; - for (const auto& name: allTests) { std::cout << name << "\n"; } - return EXIT_SUCCESS; - } else if (arg == "-shuffle") { - shuffle = true; - } else if (arg == "-v") { - verbose = true; - } else if (arg == "-g") { - sGenerateAX = true; - } else if (arg == "-t") { - if (i + 1 < argc) { - ++i; - tests.push_back(argv[i]); - } else { - OPENVDB_LOG_FATAL("missing test name after \"-t\""); - usage(progName, std::cerr); - return EXIT_FAILURE; - } - } else if (arg == "-f") { - if (i + 1 < argc) { - ++i; - std::ifstream file{argv[i]}; - if (file.fail()) { - OPENVDB_LOG_FATAL("unable to read file " << argv[i]); - return EXIT_FAILURE; - } - while (file) { - // Read a whitespace-separated string from the file. - std::string test; - file >> test; - if (!test.empty()) { - if (test[0] != '#') { - tests.push_back(test); - } else { - // If the string starts with a comment symbol ("#"), - // skip it and jump to the end of the line. - while (file) { if (file.get() == '\n') break; } - } - } - } - } else { - OPENVDB_LOG_FATAL("missing filename after \"-f\""); - usage(progName, std::cerr); - return EXIT_FAILURE; - } - } else if (arg == "-h" || arg == "-help" || arg == "--help") { - usage(progName, std::cout); - return EXIT_SUCCESS; - } else { - OPENVDB_LOG_FATAL("unrecognized option \"" << arg << "\""); - usage(progName, std::cerr); - return EXIT_FAILURE; - } - } - - try { - CppUnit::TestFactoryRegistry& registry = - CppUnit::TestFactoryRegistry::getRegistry(); - - auto* root = registry.makeTest(); - if (!root) { - throw std::runtime_error( - "CppUnit test registry was not initialized properly"); - } - - if (!shuffle) { - if (tests.empty()) tests.push_back(""); - } else { - // Get the names of all selected tests and their children. - StringVec allTests; - if (tests.empty()) { - getTestNames(allTests, root); - } else { - for (const auto& name: tests) { - getTestNames(allTests, root->findTest(name)); - } - } - // Randomly shuffle the list of names. - std::random_device randDev; - std::mt19937 generator(randDev()); - std::shuffle(allTests.begin(), allTests.end(), generator); - tests.swap(allTests); - } - - CppUnit::TestRunner runner; - runner.addTest(root); - - CppUnit::TestResult controller; - - CppUnit::TestResultCollector result; - controller.addListener(&result); - - CppUnit::TextTestProgressListener progress; - TimedTestProgressListener vProgress; - if (verbose) { - controller.addListener(&vProgress); - } else { - controller.addListener(&progress); - } - - for (size_t i = 0; i < tests.size(); ++i) { - runner.run(controller, tests[i]); - } - - CppUnit::CompilerOutputter outputter(&result, std::cerr); - outputter.write(); - - return result.wasSuccessful() ? EXIT_SUCCESS : EXIT_FAILURE; - - } catch (std::exception& e) { - OPENVDB_LOG_FATAL(e.what()); - return EXIT_FAILURE; - } -} - } // anonymous namespace template @@ -276,14 +40,12 @@ main(int argc, char *argv[]) registerType>(); registerType>(); - auto cppunit_result = run(argc, argv); - ::testing::InitGoogleTest(&argc, argv); auto gtest_result = RUN_ALL_TESTS(); openvdb::ax::uninitialize(); openvdb::uninitialize(); - return (cppunit_result == 0 ? gtest_result : cppunit_result); + return gtest_result; } From 1de8690a3693b22833390353664b80fea067df6f Mon Sep 17 00:00:00 2001 From: Tim Straubinger Date: Mon, 28 Oct 2024 17:12:00 -0700 Subject: [PATCH 21/21] Remove CppUnit from AX test CMake requirements Signed-off-by: Tim Straubinger --- openvdb_ax/openvdb_ax/test/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/openvdb_ax/openvdb_ax/test/CMakeLists.txt b/openvdb_ax/openvdb_ax/test/CMakeLists.txt index af59537680..5357d6e0ca 100644 --- a/openvdb_ax/openvdb_ax/test/CMakeLists.txt +++ b/openvdb_ax/openvdb_ax/test/CMakeLists.txt @@ -49,9 +49,6 @@ elseif(CONCURRENT_MALLOC STREQUAL "Tbbmalloc") list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS TBB::tbbmalloc) endif() -find_package(CppUnit ${MINIMUM_CPPUNIT_VERSION} REQUIRED) -list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS CppUnit::cppunit) - find_package(GTest ${MINIMUM_GOOGLETEST_VERSION} REQUIRED) if(TARGET GTest::gtest_main)