GCC Code Coverage Report


Directory: ./
File: openvdb_ax/openvdb_ax/test/frontend/TestAttributeNode.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 17 23 73.9%
Functions: 4 4 100.0%
Branches: 76 178 42.7%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb_ax/ast/AST.h>
5 #include <openvdb_ax/ast/Scanners.h>
6 #include <openvdb_ax/ast/PrintTree.h>
7 #include <openvdb_ax/Exceptions.h>
8
9 #include "../util.h"
10
11 #include <cppunit/extensions/HelperMacros.h>
12
13 #include <string>
14
15 using namespace openvdb::ax::ast;
16 using namespace openvdb::ax::ast::tokens;
17
18 namespace {
19
20 static const unittest_util::CodeTests tests =
21 {
22 { "bool@_a;", Node::Ptr(new Attribute("_a", CoreType::BOOL)) },
23 { "int16@a_;", Node::Ptr(new Attribute("a_", CoreType::INT16)) },
24 { "i@a1;", Node::Ptr(new Attribute("a1", CoreType::INT32)) },
25 { "int@abc;", Node::Ptr(new Attribute("abc", CoreType::INT32)) },
26 { "int32@abc;", Node::Ptr(new Attribute("abc", CoreType::INT32)) },
27 { "int64@a;", Node::Ptr(new Attribute("a", CoreType::INT64)) },
28 { "@a;", Node::Ptr(new Attribute("a", CoreType::FLOAT, true)) },
29 { "f@a;", Node::Ptr(new Attribute("a", CoreType::FLOAT)) },
30 { "float@a;", Node::Ptr(new Attribute("a", CoreType::FLOAT)) },
31 { "double@a;", Node::Ptr(new Attribute("a", CoreType::DOUBLE)) },
32 { "vec2i@a;", Node::Ptr(new Attribute("a", CoreType::VEC2I)) },
33 { "vec2f@a;", Node::Ptr(new Attribute("a", CoreType::VEC2F)) },
34 { "vec2d@a;", Node::Ptr(new Attribute("a", CoreType::VEC2D)) },
35 { "vec3i@a;", Node::Ptr(new Attribute("a", CoreType::VEC3I)) },
36 { "v@a;", Node::Ptr(new Attribute("a", CoreType::VEC3F)) },
37 { "vec3f@a;", Node::Ptr(new Attribute("a", CoreType::VEC3F)) },
38 { "vec3d@a;", Node::Ptr(new Attribute("a", CoreType::VEC3D)) },
39 { "vec4i@a;", Node::Ptr(new Attribute("a", CoreType::VEC4I)) },
40 { "vec4f@a;", Node::Ptr(new Attribute("a", CoreType::VEC4F)) },
41 { "vec4d@a;", Node::Ptr(new Attribute("a", CoreType::VEC4D)) },
42 { "mat3f@a;", Node::Ptr(new Attribute("a", CoreType::MAT3F)) },
43 { "mat3d@a;", Node::Ptr(new Attribute("a", CoreType::MAT3D)) },
44 { "mat4f@a;", Node::Ptr(new Attribute("a", CoreType::MAT4F)) },
45 { "mat4d@a;", Node::Ptr(new Attribute("a", CoreType::MAT4D)) },
46 { "string@a;", Node::Ptr(new Attribute("a", CoreType::STRING)) },
47 { "s@a;", Node::Ptr(new Attribute("a", CoreType::STRING)) },
48 };
49
50 }
51
52
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 class TestAttributeNode : public CppUnit::TestCase
53 {
54 public:
55
56
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
4 CPPUNIT_TEST_SUITE(TestAttributeNode);
57
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testSyntax);
58
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
6 CPPUNIT_TEST(testASTNode);
59
4/8
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
4 CPPUNIT_TEST_SUITE_END();
60
61
20/40
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 26 times.
✓ Branch 8 taken 1 times.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 26 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 26 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 26 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 26 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 26 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 26 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 26 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 26 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 26 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 26 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 26 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 26 times.
✓ Branch 53 taken 26 times.
✗ Branch 54 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
81 void testSyntax() { TEST_SYNTAX_PASSES(tests); }
62 void testASTNode();
63 };
64
65 CPPUNIT_TEST_SUITE_REGISTRATION(TestAttributeNode);
66
67 1 void TestAttributeNode::testASTNode()
68 {
69
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1 times.
27 for (const auto& test : tests) {
70
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 const std::string& code = test.first;
71 const Node* expected = test.second.get();
72
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 const Tree::ConstPtr tree = parse(code.c_str());
73
11/22
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 26 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 26 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 26 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 26 times.
✗ Branch 29 not taken.
✓ Branch 41 taken 26 times.
✗ Branch 42 not taken.
78 CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
74
75 // get the first statement
76 const Node* result = tree->child(0)->child(0);
77
6/12
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
26 CPPUNIT_ASSERT(result);
78
12/24
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 26 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 26 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 26 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 26 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 26 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 26 times.
✗ Branch 32 not taken.
✓ Branch 45 taken 26 times.
✗ Branch 46 not taken.
78 CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
79 Node::AttributeNode == result->nodetype());
80
81 std::vector<const Node*> resultList, expectedList;
82
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 linearize(*result, resultList);
83
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 linearize(*expected, expectedList);
84
85
2/4
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 26 times.
26 if (!unittest_util::compareLinearTrees(expectedList, resultList)) {
86 std::ostringstream os;
87 os << "\nExpected:\n";
88 openvdb::ax::ast::print(*expected, true, os);
89 os << "Result:\n";
90 openvdb::ax::ast::print(*result, true, os);
91 CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Attribute code", code) + os.str());
92 }
93 }
94 1 }
95
96