diff --git a/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.cpp b/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.cpp new file mode 100644 index 000000000000..dacbdc797eee --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.cpp @@ -0,0 +1,86 @@ +void complex_block() { + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + } + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + } + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + } + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + } + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + } +} // $ Alert + +void not_complex_block() { + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + } + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + } + while (true) { + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + } +} diff --git a/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.expected b/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.expected new file mode 100644 index 000000000000..6243b3a32fa7 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.expected @@ -0,0 +1 @@ +| BlockWithTooManyStatements.cpp:1:22:62:1 | { ... } | Block with too many statements (5 complex statements in the block). | diff --git a/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.qlref b/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.qlref new file mode 100644 index 000000000000..95e8a2612635 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/BlockWithTooManyStatements/BlockWithTooManyStatements.qlref @@ -0,0 +1,2 @@ +query: Best Practices/BlockWithTooManyStatements.ql +postprocess: utils/test/InlineExpectationsTestQuery.ql diff --git a/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.cpp b/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.cpp new file mode 100644 index 000000000000..0322cddc2d7a --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.cpp @@ -0,0 +1,10 @@ +void complex_condition(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h, bool i, bool j, + bool k, bool l, bool m, bool n, bool o) { + if (a || b && c || d && e || f && g || h && i || j && k || l && m || n && o) { // $ Alert + } +} + +void not_complex_condition(bool a, bool b, bool c, bool d, bool e, bool f) { + if (a && b || c && d || e && f) { + } +} diff --git a/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.expected b/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.expected new file mode 100644 index 000000000000..fc3d8570dc71 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.expected @@ -0,0 +1 @@ +| ComplexCondition.cpp:3:7:3:77 | ... \|\| ... | Complex condition: too many logical operations in this expression. | diff --git a/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.qlref b/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.qlref new file mode 100644 index 000000000000..156d845994c3 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/ComplexCondition/ComplexCondition.qlref @@ -0,0 +1,2 @@ +query: Best Practices/ComplexCondition.ql +postprocess: utils/test/InlineExpectationsTestQuery.ql diff --git a/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.cpp b/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.cpp new file mode 100644 index 000000000000..0902ea72ff90 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.cpp @@ -0,0 +1,25 @@ +bool cond(); + +void multiple_forward_and_backward_goto() { // $ Alert +backward_one: + if (cond()) goto forward_one; +backward_two: + if (cond()) goto forward_two; +forward_one: + if (cond()) goto backward_one; +forward_two: + if (cond()) goto backward_two; +} + +void only_forward_goto() { + if (cond()) goto end; + + // ... + + if (cond()) goto end; + + // ... + +end: + // ... +} diff --git a/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.expected b/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.expected new file mode 100644 index 000000000000..9d4c90b7b389 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.expected @@ -0,0 +1 @@ +| UseOfGoto.cpp:3:6:3:39 | definition of multiple_forward_and_backward_goto | Multiple forward and backward goto statements may make function multiple_forward_and_backward_goto hard to understand. | diff --git a/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.qlref b/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.qlref new file mode 100644 index 000000000000..82c5d4f08266 --- /dev/null +++ b/cpp/ql/test/query-tests/Best Practices/UseOfGoto/UseOfGoto.qlref @@ -0,0 +1,2 @@ +query: Best Practices/UseOfGoto.ql +postprocess: utils/test/InlineExpectationsTestQuery.ql