< Summary - Igor Pro Universal Testing Framework

Information
Class: tests.UnitTests.Tracing.ComplexityTests
Assembly: Tracing
File(s): /builds/mirror/igortest/tests/UnitTests/Tracing/ComplexityTests.ipf
Tag: 74147b3
Line coverage
100%
Covered lines: 55
Uncovered lines: 0
Coverable lines: 55
Total lines: 80
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/builds/mirror/igortest/tests/UnitTests/Tracing/ComplexityTests.ipf

#LineLine coverage
 1#pragma rtGlobals=3
 2#pragma TextEncoding="UTF-8"
 3#pragma rtFunctionErrors=1
 4#pragma version=1.10
 5#pragma ModuleName=TEST_Tracing_Complexity
 6
 7#undef UTF_ALLOW_TRACING
 8#if Exists("TUFXOP_Version")
 9
 10#if IgorVersion() >= 10.00
 11#define UTF_ALLOW_TRACING
 12#elif (IgorVersion() >= 9.00) && (NumberByKey("BUILD", IgorInfo(0)) >= 38812)
 13#define UTF_ALLOW_TRACING
 14#endif
 15
 16#endif
 17
 18#ifdef UTF_ALLOW_TRACING
 19
 120static Function Test_Complexity_Simple()
 121  // statements that have no influence into the complexity
 122  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("#pragma ModuleName=abc"))
 123  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("#if (IgorVersion() >= 9.00)"))
 124  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity(""))
 125  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("string abc = \"def\""))
 126  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("\t\tFoo#Bar(42)"))
 127  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("\tswitch(foo)"))
 128  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("\ttry"))
 29
 130  // statements that have an influence of 1
 131  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("static Function Test()"))
 132  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("\tif(a < b)"))
 133  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("\telseif(a < b)"))
 134  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("while(1)"))
 135  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("for(i = 0; i < length; i += 1)"))
 136  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("case MAGIC_CONSTANT:"))
 137  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("SelectString(ParamIsDefault(op), op, \"\")"))
 138  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("SelectNumber(a < b, b, a)"))
 139  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("\tcatch"))
 140  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("variable a = mode1 || mode2"))
 141  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("variable a = mode1 && mode2"))
 142  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("variable op = ParamIsDefault(op) ? 0 : op"))
 143End
 44
 145static Function Test_Complexity_Faulty()
 146  // malicious code that shouldn't match
 147  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("FunctionCaller"))
 148  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("CallFunction"))
 149  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("awhile"))
 150  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("while_constant"))
 151  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("for0"))
 152  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("WrongCase"))
 153  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("MySelectString"))
 154  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("CustomSelectNumber"))
 155  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("string mode = \"a || b\""))
 156  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("printf \"check if okay\""))
 157  CHECK_EQUAL_VAR(0, IUTF_Tracing#GetCyclomaticComplexity("// wrong case"))
 158End
 59
 160static Function Test_Complexity_Combined()
 161  // combined keywords that increase the complexity
 162  CHECK_EQUAL_VAR(2, IUTF_Tracing#GetCyclomaticComplexity("if(a || b < 5)"))
 163  CHECK_EQUAL_VAR(3, IUTF_Tracing#GetCyclomaticComplexity("if(a || (b < 5 && !error))"))
 164  CHECK_EQUAL_VAR(2, IUTF_Tracing#GetCyclomaticComplexity("try; Call(err); catch; if(err)"))
 165End
 66
 167static Function Test_Complexity_Casing()
 168  // Igor is case insensitive
 169  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("static FunCtion Test()"))
 170  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("\tIF(a < b)"))
 171  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("\tElsEIF(a < b)"))
 172  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("whILE(1)"))
 173  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("FOr(i = 0; i < length; i += 1)"))
 174  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("cASe MAGIC_CONSTANT:"))
 175  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("selectstring(ParamIsDefault(op), op, \"\")"))
 176  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("selectnumber(a < b, b, a)"))
 177  CHECK_EQUAL_VAR(1, IUTF_Tracing#GetCyclomaticComplexity("\tcatcH"))
 178End
 79
 80#endif // UTF_ALLOW_TRACING