Package com.google.test.metric.cpp.dom

Examples of com.google.test.metric.cpp.dom.TranslationUnit


    ElseStatement elseStatement = functionFoo.getChild(1);
    assertNotNull(elseStatement);
  }

  public void testIfElseAndLoopStatements() throws Exception {
    TranslationUnit unit = parse("void foo() { if (true) { for(;;); } else { while(true); } }");
    FunctionDefinition functionFoo = unit.getChild(0);
    IfStatement ifStatement = functionFoo.getChild(0);
    LoopStatement forStatement = ifStatement.getChild(0);
    assertNotNull(forStatement);
    ElseStatement elseStatement = functionFoo.getChild(1);
    LoopStatement whileStatement = elseStatement.getChild(0);
View Full Code Here


    LoopStatement whileStatement = elseStatement.getChild(0);
    assertNotNull(whileStatement);
  }

  public void testSwitchStatement() throws Exception {
    TranslationUnit unit = parse("void foo() { switch (a) { case 1: break; } }");
    FunctionDefinition functionFoo = unit.getChild(0);
    SwitchStatement switchStatement = functionFoo.getChild(0);
    CaseStatement caseStatement = switchStatement.getChild(0);
    assertNotNull(caseStatement);
  }
View Full Code Here

    CaseStatement caseStatement = switchStatement.getChild(0);
    assertNotNull(caseStatement);
  }

  public void testSwitchStatementWithDefault() throws Exception {
    TranslationUnit unit = parse("void foo() { switch (a) { case 1: break; default: break; } }");
    FunctionDefinition functionFoo = unit.getChild(0);
    SwitchStatement switchStatement = functionFoo.getChild(0);
    CaseStatement caseStatement = switchStatement.getChild(0);
    BreakStatement breakStatement = caseStatement.getChild(0);
    assertNotNull(breakStatement);
    DefaultStatement defaultStatement = switchStatement.getChild(1);
View Full Code Here

    breakStatement = defaultStatement.getChild(0);
    assertNotNull(breakStatement);
  }

  public void testTernaryOperator() throws Exception {
    TranslationUnit unit = parse("int foo(int a, int b) { return a ? 0 : b; }");
    FunctionDefinition functionFoo = unit.getChild(0);
    ReturnStatement returnStatement = functionFoo.getChild(0);
    TernaryOperation ternaryOperation = returnStatement.getExpression(0);
    assertNotNull(ternaryOperation);
  }
View Full Code Here

    TernaryOperation ternaryOperation = returnStatement.getExpression(0);
    assertNotNull(ternaryOperation);
  }

  public void testNestedTernaryOperator() throws Exception {
    TranslationUnit unit = parse("int foo(int a, int b) { int c = a ? 0 : (b ? 1 : 2); }");
    FunctionDefinition functionFoo = unit.getChild(0);
    VariableDeclaration variableC = functionFoo.getChild(0);
    TernaryOperation ternaryOperation = variableC.getExpression(0);
    TernaryOperation nestedTernaryOperation = ternaryOperation.getExpression(1);
    assertNotNull(nestedTernaryOperation);
  }
View Full Code Here

    TernaryOperation nestedTernaryOperation = ternaryOperation.getExpression(1);
    assertNotNull(nestedTernaryOperation);
  }

  public void testFunctionCall() throws Exception {
    TranslationUnit unit = parse("void foo(int) {} void bar(int) { foo(5); }");
    FunctionDefinition functionBar = unit.getChild(1);
    ExpressionStatement expressionStatement = functionBar.getChild(0);
    FunctionInvocation callFoo = expressionStatement.getExpression(0);
    assertEquals("foo", callFoo.getName());
  }
View Full Code Here

    FunctionInvocation callFoo = expressionStatement.getExpression(0);
    assertEquals("foo", callFoo.getName());
  }

  public void testNestedFunctionCall() throws Exception {
    TranslationUnit unit = parse(
        "int foo(int a) { return a; }             " +
        "int bar(int b) { return foo(foo(b)); }   ");
    FunctionDefinition functionBar = unit.getChild(1);
    assertEquals("bar", functionBar.getName());
    ReturnStatement returnStatement = functionBar.getChild(0);
    FunctionInvocation callFoo = returnStatement.getExpression(0);
    assertEquals("foo", callFoo.getName());
    NodeList parameters = callFoo.getParameters();
View Full Code Here

    assertEquals("foo", callFooAgain.getName());
    assertEquals(0, callFooAgain.getChildren().size());
  }

  public void testSequentialFunctionCalls() throws Exception {
    TranslationUnit unit = parse(
        "class A { public: void foo() {} };     " +
        "A bar() { A a; return a; }             " +
        "void main() { bar().foo(); }           ");
    FunctionDefinition functionMain = unit.getChild(2);
    assertEquals("main", functionMain.getName());
    ExpressionStatement expressionStatement = functionMain.getChild(0);
    FunctionInvocation callBar = expressionStatement.getExpression(0);
    assertEquals("bar", callBar.getName());
    FunctionInvocation callFoo = callBar.getChild(0);
View Full Code Here

    assertEquals("foo", callFoo.getName());
    assertEquals(0, callFoo.getChildren().size());
  }

  public void testLocalVariable() throws Exception {
    TranslationUnit unit = parse(
        "void main() { int a = 0, b = 0; a += 1; }");
    FunctionDefinition functionMain = unit.getChild(0);
    assertEquals("main", functionMain.getName());
    VariableDeclaration variableA = functionMain.getChild(0);
    assertEquals("a", variableA.getName());
    VariableDeclaration variableB = functionMain.getChild(1);
    assertEquals("b", variableB.getName());
View Full Code Here

    VariableDeclaration variableB = functionMain.getChild(1);
    assertEquals("b", variableB.getName());
  }

  public void testPrivateAccessSpecifier() throws Exception {
    TranslationUnit unit = parse(
        "class A { private: void foo(); };");
    ClassDeclaration classA = unit.getChild(0);
    FunctionDeclaration functionFoo = classA.getChild(0);
    Visibility visibility = functionFoo.getVisibility();
    assertEquals(Visibility.PRIVATE, visibility);
  }
View Full Code Here

TOP

Related Classes of com.google.test.metric.cpp.dom.TranslationUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.