"function C(){C()};\n" +
"A();\n";
CallGraph callgraph = compileAndRunBackward(source);
Function main = callgraph.getMainFunction();
Function functionA = callgraph.getUniqueFunctionWithName("A");
Function functionB = callgraph.getUniqueFunctionWithName("B");
Function functionC = callgraph.getUniqueFunctionWithName("C");
assertEquals(0, main.getCallsitesPossiblyTargetingFunction().size());
Collection<Callsite> callsitesTargetingA =
functionA.getCallsitesPossiblyTargetingFunction();
// A is called only from the main function
assertEquals(1, callsitesTargetingA.size());
assertEquals(main,
callsitesTargetingA.iterator().next().getContainingFunction());
Collection<Callsite> callsitesTargetingB =
functionB.getCallsitesPossiblyTargetingFunction();
// B is called only from A
assertEquals(1, callsitesTargetingB.size());
assertEquals(functionA,
callsitesTargetingB.iterator().next().getContainingFunction());
Collection<Callsite> callsitesTargetingC =
functionC.getCallsitesPossiblyTargetingFunction();
// C is called 3 times: twice from B and once from C
assertEquals(3, callsitesTargetingC.size());
Collection<Callsite> expectedFunctionsCallingC =
Sets.newHashSet(functionB.getCallsitesInFunction());
expectedFunctionsCallingC.addAll(functionC.getCallsitesInFunction());
assertTrue(callsitesTargetingC.containsAll(expectedFunctionsCallingC));
}