コード例 #1
0
TEST(ParameterReassignmentRuleTest, MultipleParameterReassignments)
{
    testRuleOnCode(new ParameterReassignmentRule(), "void m(int a) { a = 1; a = 2; }",
        0, 1, 17, 1, 21);
    testRuleOnCode(new ParameterReassignmentRule(), "void m(int a) { a = 1; a = 2; }",
        1, 1, 24, 1, 28);
}
コード例 #2
0
TEST_F(NestedBlockDepthRuleTest, TwoLevelBlock)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() {{}}",
        0, 1, 10, 1, 13, "Block depth of 2 exceeds limit of 0");
    testRuleOnCode(new NestedBlockDepthRule(), "void m() {{}}",
        1, 1, 11, 1, 12, "Block depth of 1 exceeds limit of 0");
}
コード例 #3
0
TEST(GotoStatementRuleTest, TwoGotos)
{
    testRuleOnCode(new GotoStatementRule(), "void a(); void m() { goto A; goto B; A:\na();\nB:\na(); }",
        0, 1, 22, 1, 27);
    testRuleOnCode(new GotoStatementRule(), "void a(); void m() { goto A; goto B; A:\na();\nB:\na(); }",
        1, 1, 30, 1, 35);
}
コード例 #4
0
TEST(ParameterReassignmentRuleTest, MultipleParametersBeingReassigned)
{
    testRuleOnCode(new ParameterReassignmentRule(), "void m(int a, int b, int c) { a = 1; c = 3; }",
        0, 1, 31, 1, 35);
    testRuleOnCode(new ParameterReassignmentRule(), "void m(int a, int b, int c) { a = 1; c = 3; }",
        1, 1, 38, 1, 42);
}
コード例 #5
0
TEST_F(LongLineRuleTest, GetNumberOfCharactersForThreeLines)
{
    testRuleOnCode(new LongLineRule(), "void m() {\n  \n}",
        0, 1, 1, 1, 10, "Line with 10 characters exceeds limit of 0");
    testRuleOnCode(new LongLineRule(), "void m() {\n  \n}",
        1, 2, 1, 2, 2, "Line with 2 characters exceeds limit of 0");
    testRuleOnCode(new LongLineRule(), "void m() {\n  \n}",
        2, 3, 1, 3, 1, "Line with 1 characters exceeds limit of 0");
}
コード例 #6
0
TEST_F(PreferEarlyExitRuleTest, LongIfAndReturnInsideBlock)
{
    std::string code = "int test(int a) {\n";
    code += "  int i = 2;\n";
    code += "  if (a) {\n";
    code += filler("i *= 2;\n", 2);
    code += "  }\n";
    code += "  return i;\n";
    code += "}\n";
    testRuleOnCode(new PreferEarlyExitRule(), code, 0, 3, 3, 6, 3,
                   PreferEarlyExitRule::getMessage());
}
コード例 #7
0
TEST_F(LongMethodRuleTest, TweLines)
{
    testRuleOnCode(new LongMethodRule(), "void aMethod() {\n}",
                   0, 1, 1, 2, 1, "Method with 2 lines exceeds limit of 0");
}
コード例 #8
0
TEST_F(NestedBlockDepthRuleTest, DoStatement)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() { do {} while(1); }",
        0, 1, 10, 1, 28, "Block depth of 2 exceeds limit of 1");
}
コード例 #9
0
TEST_F(LongMethodRuleTest, OneLine)
{
    testRuleOnCode(new LongMethodRule(), "void aMethod() { }",
                   0, 1, 1, 1, 18, "Method with 1 lines exceeds limit of 0");
}
コード例 #10
0
TEST_F(NestedBlockDepthRuleTest, ForStatement)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() { for(;;) {} }",
        0, 1, 10, 1, 23, "Block depth of 2 exceeds limit of 1");
}
コード例 #11
0
TEST_F(NestedBlockDepthRuleTest, WhileStatement)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() { while(1) {} }",
        0, 1, 10, 1, 24, "Block depth of 2 exceeds limit of 1");
}
コード例 #12
0
TEST(RedundantIfStatementRuleTest, CIntDeclaration)
{
    testRuleOnCode(new RedundantIfStatementRule(),
        "void aMethod() { int b; if (1) { b = 6; } else b = 0; }");
}
コード例 #13
0
TEST_F(NestedBlockDepthRuleTest, IfStatementWithElse)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() { if (1) {} else {{{}}} }",
        0, 1, 10, 1, 34, "Block depth of 4 exceeds limit of 1");
}
コード例 #14
0
TEST(ParameterReassignmentRuleTest, ReassignParameter)
{
    testRuleOnCode(new ParameterReassignmentRule(), "void m(int a) { a = 1; }",
        0, 1, 17, 1, 21);
}
コード例 #15
0
TEST(RedundantIfStatementRuleTest, ZeroThenAndOneElse)
{
    testRuleOnCode(new RedundantIfStatementRule(),
        "int aMethod() { if (1) return 0; else { return 1; } }");
}
コード例 #16
0
TEST(UnusedMethodParameterRuleTest, FunctionDeclarationWithoutDefincationShouldBeIgnored)
{
    testRuleOnCode(new UnusedMethodParameterRule(), "int aMethod(int a);");
}
コード例 #17
0
TEST_F(NestedBlockDepthRuleTest, OneCaseStatement)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() { int i = 1; switch (i) { case 1: break; } }",
        0, 1, 10, 1, 53, "Block depth of 2 exceeds limit of 1");
}
コード例 #18
0
TEST(UnusedMethodParameterRuleTest, MethodWithUnusedParameter)
{
    testRuleOnCode(new UnusedMethodParameterRule(), "void aMethod(int a) { }",
        0, 1, 14, 1, 18);
}
コード例 #19
0
TEST(UnusedMethodParameterRuleTest, MethodWithUsedParameter)
{
    testRuleOnCode(new UnusedMethodParameterRule(), "void aMethod() { int a; a = 1; }");
}
コード例 #20
0
TEST(RedundantIfStatementRuleTest, OneThenAndZeroElse)
{
    testRuleOnCode(new RedundantIfStatementRule(),
        "int aMethod() { if (1) { return 1; } else return 0; }");
}
コード例 #21
0
TEST(RedundantConditionalOperatorRuleTest, GoodConditionalOperator)
{
    testRuleOnCode(new RedundantConditionalOperatorRule(), "void m(int a, int b) { int c = a > b ? a : b; }");
}
コード例 #22
0
TEST(ConstantIfExpressionRuleTest, testOnlyEvaluateTheNecessaryCondition)
{
    testRuleOnCode(new ConstantIfExpressionRule(), "int foo() { return 1; } void aMethod() { if (1 ? 0 : foo()) {;} }",
        0, 1, 46, 1, 58);
}
コード例 #23
0
TEST(ParameterReassignmentRuleTest, UseParameter)
{
    testRuleOnCode(new ParameterReassignmentRule(), "void useInt(int i); void m(int a) { useInt(a); }");
}
コード例 #24
0
TEST(RedundantIfStatementRuleTest, GoodIfStatement)
{
    testRuleOnCode(new RedundantIfStatementRule(), "void aMethod() { if (1) {;} }");
}
コード例 #25
0
TEST_F(NestedBlockDepthRuleTest, TwoCaseStatementsAndDefault)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() { int i = 1; switch (i) { case 1: i = 2; break; case 2: break; default: break; } }",
        0, 1, 10, 1, 91, "Block depth of 2 exceeds limit of 1");
}
コード例 #26
0
TEST(EmptyForStatementRuleTest, ForStatementWithEmptyComponent)
{
    testRuleOnCode(new EmptyForStatementRule(), "void aMethod() { for (;;) {} }",
        0, 1, 27, 1, 28);
}
コード例 #27
0
TEST(EmptyForStatementRuleTest, GoodForStatement)
{
    testRuleOnCode(new EmptyForStatementRule(), "void aMethod() { for (;;) {;} }");
}
コード例 #28
0
TEST_F(NestedBlockDepthRuleTest, EmptyFunction)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() {}");
}
コード例 #29
0
TEST(EmptyForStatementRuleTest, ForStatementWithNullStmt)
{
    testRuleOnCode(new EmptyForStatementRule(), "void aMethod() { for (;;) \n; }",
        0, 2, 1, 2, 1);
}
コード例 #30
0
TEST_F(NestedBlockDepthRuleTest, ChooseTheDeepest)
{
    testRuleOnCode(new NestedBlockDepthRule(), "void m() {{}{{{}}}{{}}}",
        0, 1, 10, 1, 23, "Block depth of 4 exceeds limit of 1");
}