GCC Code Coverage Report


Directory: ./
File: openvdb_ax/openvdb_ax/test/frontend/TestFunctionCallNode.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 { "func();", Node::Ptr(new FunctionCall("func")) },
23 { "_();", Node::Ptr(new FunctionCall("_")) },
24 { "_1();", Node::Ptr(new FunctionCall("_1")) },
25 { "a_();", Node::Ptr(new FunctionCall("a_")) },
26 { "_a();", Node::Ptr(new FunctionCall("_a")) },
27 { "A();", Node::Ptr(new FunctionCall("A")) },
28 { "D1f();", Node::Ptr(new FunctionCall("D1f")) },
29 { "f(a);", Node::Ptr(new FunctionCall("f", new Local("a"))) },
30 { "a(a,1);", Node::Ptr(new FunctionCall("a", {
31 new Local("a"),
32 new Value<int32_t>(1)
33 }))
34 },
35 { "func(1);", Node::Ptr(new FunctionCall("func",
36 new Value<int32_t>(1)
37 ))
38 },
39 { "func(\"string\");", Node::Ptr(new FunctionCall("func",
40 new Value<std::string>("string")
41 ))
42 },
43 { "func(true);", Node::Ptr(new FunctionCall("func",
44 new Value<bool>(true)
45 ))
46 },
47 { "func({a,b,c});", Node::Ptr(new FunctionCall("func",
48 new ArrayPack({
49 new Local("a"),
50 new Local("b"),
51 new Local("c")
52 })
53 ))
54 },
55 { "func((a,b,c));", Node::Ptr(new FunctionCall("func",
56 new CommaOperator({
57 new Local("a"),
58 new Local("b"),
59 new Local("c")
60 })
61 ))
62 },
63 { "func(@a);", Node::Ptr(new FunctionCall("func",
64 new Attribute("a", CoreType::FLOAT, true)
65 ))
66 },
67 { "func(++a);", Node::Ptr(new FunctionCall("func",
68 new Crement(new Local("a"), Crement::Operation::Increment, false)
69 ))
70 },
71 { "func(~a);", Node::Ptr(new FunctionCall("func",
72 new UnaryOperator(new Local("a"), OperatorToken::BITNOT)
73 ))
74 },
75 { "func((a));", Node::Ptr(new FunctionCall("func",
76 new Local("a")
77 ))
78 },
79 { "func1(func2());", Node::Ptr(new FunctionCall("func1",
80 new FunctionCall("func2")
81 ))
82 },
83 { "func(a=b);", Node::Ptr(new FunctionCall("func",
84 new AssignExpression(new Local("a"), new Local("b"))
85 ))
86 },
87 { "func(a==b);", Node::Ptr(new FunctionCall("func",
88 new BinaryOperator(new Local("a"), new Local("b"), OperatorToken::EQUALSEQUALS)
89 ))
90 },
91 { "func(a.x);", Node::Ptr(new FunctionCall("func",
92 new ArrayUnpack(new Local("a"), new Value<int32_t>(0))
93 ))
94 },
95 { "func(bool(a));", Node::Ptr(new FunctionCall("func",
96 new Cast(new Local("a"), CoreType::BOOL)
97 ))
98 },
99 { "func(a,b,c,d,e,f);", Node::Ptr(new FunctionCall("func", {
100 new Local("a"), new Local("b"), new Local("c"),
101 new Local("d"), new Local("e"), new Local("f")
102 }
103 ))
104 },
105 { "func((a, b), c);", Node::Ptr(new FunctionCall("func", {
106 new CommaOperator({ new Local("a"), new Local("b") }),
107 new Local("c")
108 }))
109 }
110 };
111
112 }
113
114
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 class TestFunctionCallNode : public CppUnit::TestCase
115 {
116 public:
117
118
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(TestFunctionCallNode);
119
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);
120
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);
121
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();
122
123
20/40
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 25 times.
✓ Branch 8 taken 1 times.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 25 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 25 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 25 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 25 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 25 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 25 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 25 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 25 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 25 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 25 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 25 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 25 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 25 times.
✓ Branch 53 taken 25 times.
✗ Branch 54 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
78 void testSyntax() { TEST_SYNTAX_PASSES(tests); }
124 void testASTNode();
125 };
126
127 CPPUNIT_TEST_SUITE_REGISTRATION(TestFunctionCallNode);
128
129 1 void TestFunctionCallNode::testASTNode()
130 {
131
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1 times.
26 for (const auto& test : tests) {
132
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 const std::string& code = test.first;
133 const Node* expected = test.second.get();
134
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 const Tree::ConstPtr tree = parse(code.c_str());
135
11/22
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 25 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 25 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 25 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 25 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 25 times.
✗ Branch 29 not taken.
✓ Branch 41 taken 25 times.
✗ Branch 42 not taken.
75 CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("No AST returned", code), static_cast<bool>(tree));
136
137 // get the first statement
138 const Node* result = tree->child(0)->child(0);
139
6/12
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 25 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
25 CPPUNIT_ASSERT(result);
140
12/24
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 25 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 25 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 25 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 25 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 25 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 25 times.
✗ Branch 32 not taken.
✓ Branch 45 taken 25 times.
✗ Branch 46 not taken.
75 CPPUNIT_ASSERT_MESSAGE(ERROR_MSG("Invalid AST node", code),
141 Node::FunctionCallNode == result->nodetype());
142
143 std::vector<const Node*> resultList, expectedList;
144
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 linearize(*result, resultList);
145
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 linearize(*expected, expectedList);
146
147
2/4
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
25 if (!unittest_util::compareLinearTrees(expectedList, resultList)) {
148 std::ostringstream os;
149 os << "\nExpected:\n";
150 openvdb::ax::ast::print(*expected, true, os);
151 os << "Result:\n";
152 openvdb::ax::ast::print(*result, true, os);
153 CPPUNIT_FAIL(ERROR_MSG("Mismatching Trees for Function Call code", code) + os.str());
154 }
155 }
156 1 }
157
158