Skip to content

Commit 4b1429b

Browse files
committed
SpecialMemberFunction from GoogleTest as entry pts
1 parent 2ffccb0 commit 4b1429b

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
| test.cpp:71:5:71:16 | ANestedClass | Special member function ANestedClass is never called. |
22
| test.cpp:82:5:82:22 | AnotherNestedClass | Special member function AnotherNestedClass is never called from a main function or entry point. |
3-
| test.cpp:155:1:157:37 | ~sample_test_called_from_google_test_function_Test | Special member function sample_test_called_from_google_test_function_Test::~sample_test_called_from_google_test_function_Test is never called. |

cpp/autosar/test/rules/M0-1-10/test.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,8 @@ int called_from_google_test_function(
152152
return something;
153153
}
154154

155-
TEST(
156-
sample_test,
157-
called_from_google_test_function) // COMPLIANT - False positive!
158-
// ~sample_test_called_from_google_test_function_Test
155+
TEST(sample_test,
156+
called_from_google_test_function) // COMPLIANT - Google Test function
159157
{
160158
bool pass = false;
161159
if (called_from_google_test_function(0) >= 10)

cpp/common/src/codingstandards/cpp/EncapsulatingFunctions.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import cpp
6+
import codingstandards.cpp.Class
67

78
/** A function which represents the entry point into a specific thread of execution in the program. */
89
abstract class MainLikeFunction extends Function { }
@@ -29,19 +30,22 @@ class MainFunction extends MainLikeFunction {
2930
class GoogleTestFunction extends MainLikeFunction {
3031
GoogleTestFunction() {
3132
// A GoogleTest function is named "TestBody" and
32-
this.hasName("TestBody") and
33+
(
34+
this.hasName("TestBody") or
35+
this instanceof SpecialMemberFunction
36+
) and
3337
// it's parent class inherits a base class
3438
exists(Class base |
3539
base = this.getEnclosingAccessHolder().(Class).getABaseClass+() and
36-
// with a name "Test" inside a namespace called "testing"
3740
(
41+
// with a name "Test" inside a namespace called "testing"
3842
base.hasName("Test") and
3943
base.getNamespace().hasName("testing")
44+
or
45+
// or at a location in a file called gtest.h (or gtest-internal.h,
46+
// gtest-typed-test.h etc).
47+
base.getDefinitionLocation().getFile().getBaseName().regexpMatch("gtest*.h")
4048
)
41-
or
42-
// or at a location in a file called gtest.h (or gtest-internal.h,
43-
// gtest-typed-test.h etc).
44-
base.getDefinitionLocation().getFile().getBaseName().regexpMatch("gtest*.h")
4549
)
4650
}
4751
}

0 commit comments

Comments
 (0)