Skip to content

Commit 5df8871

Browse files
committed
Convert all of AX frontend test suite to use gtest; remove temporary cppunit dual support from utils.h
Signed-off-by: Tim Straubinger <[email protected]>
1 parent 748ace4 commit 5df8871

20 files changed

+204
-375
lines changed

openvdb_ax/openvdb_ax/test/frontend/TestArrayUnpackNode.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../util.h"
1010

11-
#include <cppunit/extensions/HelperMacros.h>
11+
#include <gtest/gtest.h>
1212

1313
#include <string>
1414

@@ -107,34 +107,27 @@ static const unittest_util::CodeTests tests =
107107

108108
}
109109

110-
class TestArrayUnpackNode : public CppUnit::TestCase
110+
class TestArrayUnpackNode : public ::testing::Test
111111
{
112-
public:
113-
114-
CPPUNIT_TEST_SUITE(TestArrayUnpackNode);
115-
CPPUNIT_TEST(testSyntax);
116-
CPPUNIT_TEST(testASTNode);
117-
CPPUNIT_TEST_SUITE_END();
118-
119-
void testSyntax() { TEST_SYNTAX_PASSES(tests); }
120-
void testASTNode();
121112
};
122113

123-
CPPUNIT_TEST_SUITE_REGISTRATION(TestArrayUnpackNode);
114+
TEST_F(TestArrayUnpackNode, testSyntax)
115+
{
116+
TEST_SYNTAX_PASSES(tests);
117+
}
124118

125-
void TestArrayUnpackNode::testASTNode()
119+
TEST_F(TestArrayUnpackNode, testASTNode)
126120
{
127121
for (const auto& test : tests) {
128122
const std::string& code = test.first;
129123
const Node* expected = test.second.get();
130124
const Tree::ConstPtr tree = parse(code.c_str());
131-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
125+
ASSERT_TRUE(static_cast<bool>(tree)) << ERROR_MSG("No AST returned", code);
132126

133127
// get the first statement
134128
const Node* result = tree->child(0)->child(0);
135-
CPPUNIT_ASSERT(result);
136-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
137-
Node::ArrayUnpackNode == result->nodetype());
129+
ASSERT_TRUE(result);
130+
ASSERT_TRUE(Node::ArrayUnpackNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code);
138131

139132
std::vector<const Node*> resultList, expectedList;
140133
linearize(*result, resultList);
@@ -146,7 +139,7 @@ void TestArrayUnpackNode::testASTNode()
146139
openvdb::ax::ast::print(*expected, true, os);
147140
os << "Result:\n";
148141
openvdb::ax::ast::print(*result, true, os);
149-
CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Array Unpack code", code) + os.str());
142+
FAIL() << ERROR_MSG("Mismatching Trees for Array Unpack code", code) + os.str();
150143
}
151144
}
152145
}

openvdb_ax/openvdb_ax/test/frontend/TestAssignExpressionNode.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../util.h"
1010

11-
#include <cppunit/extensions/HelperMacros.h>
11+
#include <gtest/gtest.h>
1212

1313
#include <string>
1414

@@ -226,34 +226,27 @@ unittest_util::CodeTests tests =
226226

227227
}
228228

229-
class TestAssignExpressionNode : public CppUnit::TestCase
229+
class TestAssignExpressionNode : public ::testing::Test
230230
{
231-
public:
232-
233-
CPPUNIT_TEST_SUITE(TestAssignExpressionNode);
234-
CPPUNIT_TEST(testSyntax);
235-
CPPUNIT_TEST(testASTNode);
236-
CPPUNIT_TEST_SUITE_END();
237-
238-
void testSyntax() { TEST_SYNTAX_PASSES(tests); }
239-
void testASTNode();
240231
};
241232

242-
CPPUNIT_TEST_SUITE_REGISTRATION(TestAssignExpressionNode);
233+
TEST_F(TestAssignExpressionNode, testSyntax)
234+
{
235+
TEST_SYNTAX_PASSES(tests);
236+
}
243237

244-
void TestAssignExpressionNode::testASTNode()
238+
TEST_F(TestAssignExpressionNode, testASTNode)
245239
{
246240
for (const auto& test : tests) {
247241
const std::string& code = test.first;
248242
const Node* expected = test.second.get();
249243
const Tree::ConstPtr tree = parse(code.c_str());
250-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
244+
ASSERT_TRUE(static_cast<bool>(tree)) << ERROR_MSG("No AST returned", code);
251245

252246
// get the first statement
253247
const Node* result = tree->child(0)->child(0);
254-
CPPUNIT_ASSERT(result);
255-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
256-
Node::AssignExpressionNode == result->nodetype());
248+
ASSERT_TRUE(result);
249+
ASSERT_TRUE(Node::AssignExpressionNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code);
257250

258251
std::vector<const Node*> resultList, expectedList;
259252
linearize(*result, resultList);
@@ -265,7 +258,7 @@ void TestAssignExpressionNode::testASTNode()
265258
openvdb::ax::ast::print(*expected, true, os);
266259
os << "Result:\n";
267260
openvdb::ax::ast::print(*result, true, os);
268-
CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Assign Expression code", code) + os.str());
261+
FAIL() << ERROR_MSG("Mismatching Trees for Assign Expression code", code) + os.str();
269262
}
270263
}
271264
}

openvdb_ax/openvdb_ax/test/frontend/TestAttributeNode.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../util.h"
1010

11-
#include <cppunit/extensions/HelperMacros.h>
11+
#include <gtest/gtest.h>
1212

1313
#include <string>
1414

@@ -49,34 +49,27 @@ static const unittest_util::CodeTests tests =
4949

5050
}
5151

52-
class TestAttributeNode : public CppUnit::TestCase
52+
class TestAttributeNode : public ::testing::Test
5353
{
54-
public:
55-
56-
CPPUNIT_TEST_SUITE(TestAttributeNode);
57-
CPPUNIT_TEST(testSyntax);
58-
CPPUNIT_TEST(testASTNode);
59-
CPPUNIT_TEST_SUITE_END();
60-
61-
void testSyntax() { TEST_SYNTAX_PASSES(tests); }
62-
void testASTNode();
6354
};
6455

65-
CPPUNIT_TEST_SUITE_REGISTRATION(TestAttributeNode);
56+
TEST_F(TestAttributeNode, testSyntax)
57+
{
58+
TEST_SYNTAX_PASSES(tests);
59+
}
6660

67-
void TestAttributeNode::testASTNode()
61+
TEST_F(TestAttributeNode, testASTNode)
6862
{
6963
for (const auto& test : tests) {
7064
const std::string& code = test.first;
7165
const Node* expected = test.second.get();
7266
const Tree::ConstPtr tree = parse(code.c_str());
73-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
67+
ASSERT_TRUE(static_cast<bool>(tree)) << ERROR_MSG("No AST returned", code);
7468

7569
// get the first statement
7670
const Node* result = tree->child(0)->child(0);
77-
CPPUNIT_ASSERT(result);
78-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
79-
Node::AttributeNode == result->nodetype());
71+
ASSERT_TRUE(result);
72+
ASSERT_TRUE(Node::AttributeNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code);
8073

8174
std::vector<const Node*> resultList, expectedList;
8275
linearize(*result, resultList);
@@ -88,7 +81,7 @@ void TestAttributeNode::testASTNode()
8881
openvdb::ax::ast::print(*expected, true, os);
8982
os << "Result:\n";
9083
openvdb::ax::ast::print(*result, true, os);
91-
CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Attribute code", code) + os.str());
84+
FAIL() << ERROR_MSG("Mismatching Trees for Attribute code", code) + os.str();
9285
}
9386
}
9487
}

openvdb_ax/openvdb_ax/test/frontend/TestBinaryOperatorNode.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../util.h"
1010

11-
#include <cppunit/extensions/HelperMacros.h>
11+
#include <gtest/gtest.h>
1212

1313
#include <string>
1414

@@ -295,34 +295,27 @@ static const unittest_util::CodeTests tests =
295295

296296
}
297297

298-
class TestBinaryOperatorNode : public CppUnit::TestCase
298+
class TestBinaryOperatorNode : public ::testing::Test
299299
{
300-
public:
301-
302-
CPPUNIT_TEST_SUITE(TestBinaryOperatorNode);
303-
CPPUNIT_TEST(testSyntax);
304-
CPPUNIT_TEST(testASTNode);
305-
CPPUNIT_TEST_SUITE_END();
306-
307-
void testSyntax() { TEST_SYNTAX_PASSES(tests); }
308-
void testASTNode();
309300
};
310301

311-
CPPUNIT_TEST_SUITE_REGISTRATION(TestBinaryOperatorNode);
302+
TEST_F(TestBinaryOperatorNode, testSyntax)
303+
{
304+
TEST_SYNTAX_PASSES(tests);
305+
}
312306

313-
void TestBinaryOperatorNode::testASTNode()
307+
TEST_F(TestBinaryOperatorNode, testASTNode)
314308
{
315309
for (const auto& test : tests) {
316310
const std::string& code = test.first;
317311
const Node* expected = test.second.get();
318312
const Tree::ConstPtr tree = parse(code.c_str());
319-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
313+
ASSERT_TRUE(static_cast<bool>(tree)) << ERROR_MSG("No AST returned", code);
320314

321315
// get the first statement
322316
const Node* result = tree->child(0)->child(0);
323-
CPPUNIT_ASSERT(result);
324-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
325-
Node::BinaryOperatorNode == result->nodetype());
317+
ASSERT_TRUE(result);
318+
ASSERT_TRUE(Node::BinaryOperatorNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code);
326319

327320
std::vector<const Node*> resultList, expectedList;
328321
linearize(*result, resultList);
@@ -334,7 +327,7 @@ void TestBinaryOperatorNode::testASTNode()
334327
openvdb::ax::ast::print(*expected, true, os);
335328
os << "Result:\n";
336329
openvdb::ax::ast::print(*result, true, os);
337-
CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Binary Operator code", code) + os.str());
330+
FAIL() << ERROR_MSG("Mismatching Trees for Binary Operator code", code) + os.str();
338331
}
339332
}
340333
}

openvdb_ax/openvdb_ax/test/frontend/TestCastNode.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../util.h"
1010

11-
#include <cppunit/extensions/HelperMacros.h>
11+
#include <gtest/gtest.h>
1212

1313
#include <string>
1414

@@ -49,34 +49,27 @@ static const unittest_util::CodeTests tests =
4949

5050
}
5151

52-
class TestCastNode : public CppUnit::TestCase
52+
class TestCastNode : public ::testing::Test
5353
{
54-
public:
55-
56-
CPPUNIT_TEST_SUITE(TestCastNode);
57-
CPPUNIT_TEST(testSyntax);
58-
CPPUNIT_TEST(testASTNode);
59-
CPPUNIT_TEST_SUITE_END();
60-
61-
void testSyntax() { TEST_SYNTAX_PASSES(tests); }
62-
void testASTNode();
6354
};
6455

65-
CPPUNIT_TEST_SUITE_REGISTRATION(TestCastNode);
56+
TEST_F(TestCastNode, testSyntax)
57+
{
58+
TEST_SYNTAX_PASSES(tests);
59+
}
6660

67-
void TestCastNode::testASTNode()
61+
TEST_F(TestCastNode, testASTNode)
6862
{
6963
for (const auto& test : tests) {
7064
const std::string& code = test.first;
7165
const Node* expected = test.second.get();
7266
const Tree::ConstPtr tree = parse(code.c_str());
73-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
67+
ASSERT_TRUE(static_cast<bool>(tree)) << ERROR_MSG("No AST returned", code);
7468

7569
// get the first statement
7670
const Node* result = tree->child(0)->child(0);
77-
CPPUNIT_ASSERT(result);
78-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
79-
Node::CastNode == result->nodetype());
71+
ASSERT_TRUE(result);
72+
ASSERT_TRUE(Node::CastNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code);
8073

8174
std::vector<const Node*> resultList, expectedList;
8275
linearize(*result, resultList);
@@ -88,7 +81,7 @@ void TestCastNode::testASTNode()
8881
openvdb::ax::ast::print(*expected, true, os);
8982
os << "Result:\n";
9083
openvdb::ax::ast::print(*result, true, os);
91-
CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Cast code", code) + os.str());
84+
FAIL() << ERROR_MSG("Mismatching Trees for Cast code", code) + os.str();
9285
}
9386
}
9487
}

openvdb_ax/openvdb_ax/test/frontend/TestCommaOperator.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "../util.h"
1010

11-
#include <cppunit/extensions/HelperMacros.h>
11+
#include <gtest/gtest.h>
1212

1313
#include <string>
1414

@@ -113,34 +113,27 @@ static const unittest_util::CodeTests tests =
113113

114114
}
115115

116-
class TestCommaOperator : public CppUnit::TestCase
116+
class TestCommaOperator : public ::testing::Test
117117
{
118-
public:
119-
120-
CPPUNIT_TEST_SUITE(TestCommaOperator);
121-
CPPUNIT_TEST(testSyntax);
122-
CPPUNIT_TEST(testASTNode);
123-
CPPUNIT_TEST_SUITE_END();
124-
125-
void testSyntax() { TEST_SYNTAX_PASSES(tests); }
126-
void testASTNode();
127118
};
128119

129-
CPPUNIT_TEST_SUITE_REGISTRATION(TestCommaOperator);
120+
TEST_F(TestCommaOperator, testSyntax)
121+
{
122+
TEST_SYNTAX_PASSES(tests);
123+
}
130124

131-
void TestCommaOperator::testASTNode()
125+
TEST_F(TestCommaOperator, testASTNode)
132126
{
133127
for (const auto& test : tests) {
134128
const std::string& code = test.first;
135129
const Node* expected = test.second.get();
136130
const Tree::ConstPtr tree = parse(code.c_str());
137-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
131+
ASSERT_TRUE(static_cast<bool>(tree)) << ERROR_MSG("No AST returned", code);
138132

139133
// get the first statement
140134
const Node* result = tree->child(0)->child(0);
141-
CPPUNIT_ASSERT(result);
142-
CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
143-
Node::CommaOperatorNode == result->nodetype());
135+
ASSERT_TRUE(result);
136+
ASSERT_TRUE(Node::CommaOperatorNode == result->nodetype()) << ERROR_MSG("Invalid AST node", code);
144137

145138
std::vector<const Node*> resultList, expectedList;
146139
linearize(*result, resultList);
@@ -152,7 +145,7 @@ void TestCommaOperator::testASTNode()
152145
openvdb::ax::ast::print(*expected, true, os);
153146
os << "Result:\n";
154147
openvdb::ax::ast::print(*result, true, os);
155-
CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Comma Operator code", code) + os.str());
148+
FAIL() << ERROR_MSG("Mismatching Trees for Comma Operator code", code) + os.str();
156149
}
157150
}
158151
}

0 commit comments

Comments
 (0)