| | 1 | | #pragma rtGlobals=3 |
| | 2 | | #pragma TextEncoding="UTF-8" |
| | 3 | | #pragma rtFunctionErrors=1 |
| | 4 | | #pragma version=1.10 |
| | 5 | | #pragma ModuleName=TEST_Tracing_Cobertura |
| | 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 | |
|
| 1 | 20 | | static Function Test_FilePathToXml() |
| 1 | 21 | | string result, expect |
| | 22 | |
|
| 1 | 23 | | expect = "abc/def/ghi" |
| 1 | 24 | | result = IUTF_Tracing_Cobertura#FilePathToXml("abc\\def\\ghi") |
| 1 | 25 | | CHECK_EQUAL_STR(expect, result) |
| 1 | 26 | | End |
| | 27 | |
|
| 1 | 28 | | static Function Test_GetClassName() |
| 1 | 29 | | string result, expect |
| | 30 | |
|
| 1 | 31 | | expect = "abc.def.ghi.jkl" |
| 1 | 32 | | result = IUTF_Tracing_Cobertura#GetClassName("abc\\def\\ghi\\jkl.txt") |
| 1 | 33 | | CHECK_EQUAL_STR(expect, result) |
| | 34 | |
|
| 1 | 35 | | expect = "abc" |
| 1 | 36 | | result = IUTF_Tracing_Cobertura#GetClassName("abc.txt") |
| 1 | 37 | | CHECK_EQUAL_STR(expect, result) |
| | 38 | |
|
| 1 | 39 | | expect = "abc.def.ghi.jkl" |
| 1 | 40 | | result = IUTF_Tracing_Cobertura#GetClassName("abc\\def\\ghi\\jkl") |
| 1 | 41 | | CHECK_EQUAL_STR(expect, result) |
| | 42 | |
|
| 1 | 43 | | expect = "" |
| 1 | 44 | | result = IUTF_Tracing_Cobertura#GetClassName("") |
| 1 | 45 | | CHECK_EQUAL_STR(expect, result) |
| 1 | 46 | | End |
| | 47 | |
|
| 4 | 48 | | static Function CheckProcInfo(string infoStr, STRUCT IUTF_Cobertura_ProcInfo &procInfo, string sourcePath, string packag |
| 4 | 49 | | string value |
| | 50 | |
|
| 4 | 51 | | value = procInfo.sourcePath |
| 4 | 52 | | INFO(infoStr) |
| 4 | 53 | | INFO("Source Path") |
| 4 | 54 | | CHECK_EQUAL_STR(sourcePath, value) |
| | 55 | |
|
| 4 | 56 | | value = procInfo.packageName |
| 4 | 57 | | INFO(infoStr) |
| 4 | 58 | | INFO("Package Name") |
| 4 | 59 | | CHECK_EQUAL_STR(packageName, value) |
| | 60 | |
|
| 4 | 61 | | value = procInfo.classFileName |
| 4 | 62 | | INFO(infoStr) |
| 4 | 63 | | INFO("Class File Name") |
| 4 | 64 | | CHECK_EQUAL_STR(classFileName, value) |
| | 65 | |
|
| 4 | 66 | | value = procInfo.className |
| 4 | 67 | | INFO(infoStr) |
| 4 | 68 | | INFO("Class Name") |
| 4 | 69 | | CHECK_EQUAL_STR(className, value) |
| 4 | 70 | | End |
| | 71 | |
|
| 1 | 72 | | static Function Test_GetProcInfo() |
| 1 | 73 | | string infoStr |
| 1 | 74 | | STRUCT IUTF_Cobertura_ProcInfo procInfo |
| | 75 | |
|
| 1 | 76 | | infoStr = "path is directly inside first path" |
| 1 | 77 | | Make/FREE=1/T sources = {"foo\\bar\\"} |
| 1 | 78 | | [procInfo] = IUTF_Tracing_Cobertura#GetProcInfo("foo\\bar\\baz.txt", sources) |
| 1 | 79 | | CheckProcInfo(infoStr, procInfo, "foo\\bar", "", "baz.txt", "baz") |
| | 80 | |
|
| 1 | 81 | | infoStr = "path is directly inside second path" |
| 1 | 82 | | Make/FREE=1/T sources = {"abc\\", "foo\\bar\\"} |
| 1 | 83 | | [procInfo] = IUTF_Tracing_Cobertura#GetProcInfo("foo\\bar\\baz.txt", sources) |
| 1 | 84 | | CheckProcInfo(infoStr, procInfo, "foo\\bar", "", "baz.txt", "baz") |
| | 85 | |
|
| 1 | 86 | | infoStr = "path is somewhere in a subdirectory of a path" |
| 1 | 87 | | Make/FREE=1/T sources = {"abc\\", "foo\\bar\\"} |
| 1 | 88 | | [procInfo] = IUTF_Tracing_Cobertura#GetProcInfo("foo\\bar\\abc\\def\\baz.txt", sources) |
| 1 | 89 | | CheckProcInfo(infoStr, procInfo, "foo\\bar", "abc\\def", "abc\\def\\baz.txt", "abc.def.baz") |
| | 90 | |
|
| 1 | 91 | | infoStr = "path is not included in sources" |
| 1 | 92 | | Make/FREE=1/T sources = {"abc\\"} |
| 1 | 93 | | [procInfo] = IUTF_Tracing_Cobertura#GetProcInfo("foo\\bar\\baz.txt", sources) |
| 1 | 94 | | CheckProcInfo(infoStr, procInfo, "foo\\bar", "", "baz.txt", "baz") |
| 1 | 95 | | End |
| | 96 | |
|
| 1 | 97 | | static Function Test_GetLinesReport_NoBranch() |
| 1 | 98 | | STRUCT IUTF_Cobertura_Metrics metrics |
| 1 | 99 | | string result |
| | 100 | |
|
| 1 | 101 | | string indent = "" |
| 1 | 102 | | variable lineStart = 0 |
| 1 | 103 | | variable lineEnd = 2 |
| 1 | 104 | | variable procIndex = 1 |
| 1 | 105 | | string expected = "<lines>\n" + \ |
| 1 | 106 | | "\t<line number=\"1\" hits=\"1\" branch=\"false\"/>\n" + \ |
| 1 | 107 | | "\t<line number=\"2\" hits=\"2\" branch=\"false\"/>\n" + \ |
| 1 | 108 | | "</lines>\n" |
| | 109 | |
|
| 1 | 110 | | Make/FREE=1/N=(3, 3, 2) totals |
| 1 | 111 | | totals[][0][procIndex] = p + 1 |
| | 112 | |
|
| 1 | 113 | | WAVE marker = IUTF_Tracing#GetNewMarkerWave(3) |
| 1 | 114 | | marker[][%INSTR] = 1 |
| | 115 | |
|
| 1 | 116 | | [result, metrics] = IUTF_Tracing_Cobertura#GetLinesReport(indent, lineStart, lineEnd, procIndex, totals, marker) |
| | 117 | |
|
| 1 | 118 | | INFO("xml output") |
| 1 | 119 | | CHECK_EQUAL_STR(expected, result) |
| | 120 | |
|
| 1 | 121 | | CHECK_EQUAL_VAR(1, metrics.lineRate) |
| 1 | 122 | | CHECK_EQUAL_VAR(2, metrics.lineCovered) |
| 1 | 123 | | CHECK_EQUAL_VAR(2, metrics.lineValid) |
| 1 | 124 | | CHECK_EQUAL_VAR(1, metrics.branchRate) |
| 1 | 125 | | CHECK_EQUAL_VAR(0, metrics.branchCovered) |
| 1 | 126 | | CHECK_EQUAL_VAR(0, metrics.branchValid) |
| 1 | 127 | | End |
| | 128 | |
|
| 1 | 129 | | static Function Test_GetLinesReport_SingleBranch() |
| 1 | 130 | | STRUCT IUTF_Cobertura_Metrics metrics |
| 1 | 131 | | string result |
| | 132 | |
|
| 1 | 133 | | string indent = "" |
| 1 | 134 | | variable lineStart = 0 |
| 1 | 135 | | variable lineEnd = 4 |
| 1 | 136 | | variable procIndex = 1 |
| 1 | 137 | | string expected = "<lines>\n" + \ |
| 1 | 138 | | "\t<line number=\"1\" hits=\"1\" branch=\"false\"/>\n" + \ |
| 1 | 139 | | "\t<line number=\"2\" hits=\"1\" branch=\"true\" condition-coverage=\"50% (1/2)\">\n" + \ |
| 1 | 140 | | "\t\t<conditions>\n" + \ |
| 1 | 141 | | "\t\t\t<condition number=\"0\" type=\"jump\" coverage=\"50%\"/>\n" + \ |
| 1 | 142 | | "\t\t</conditions>\n" + \ |
| 1 | 143 | | "\t</line>\n" + \ |
| 1 | 144 | | "\t<line number=\"3\" hits=\"0\" branch=\"false\"/>\n" + \ |
| 1 | 145 | | "\t<line number=\"4\" hits=\"1\" branch=\"false\"/>\n" + \ |
| 1 | 146 | | "</lines>\n" |
| | 147 | |
|
| 1 | 148 | | Make/FREE=1/N=(5, 3, 2) totals |
| 1 | 149 | | totals[][0][procIndex] = 1 |
| 1 | 150 | | totals[2][0][procIndex] = 0 |
| 1 | 151 | | totals[1][1][procIndex] = 1 |
| | 152 | |
|
| 1 | 153 | | WAVE marker = IUTF_Tracing#GetNewMarkerWave(5) |
| 1 | 154 | | marker[][%INSTR] = 1 |
| | 155 | |
|
| 1 | 156 | | [result, metrics] = IUTF_Tracing_Cobertura#GetLinesReport(indent, lineStart, lineEnd, procIndex, totals, marker) |
| | 157 | |
|
| 1 | 158 | | INFO("xml output") |
| 1 | 159 | | CHECK_EQUAL_STR(expected, result) |
| | 160 | |
|
| 1 | 161 | | CHECK_EQUAL_VAR(0.75, metrics.lineRate) |
| 1 | 162 | | CHECK_EQUAL_VAR(3, metrics.lineCovered) |
| 1 | 163 | | CHECK_EQUAL_VAR(4, metrics.lineValid) |
| 1 | 164 | | CHECK_EQUAL_VAR(0.5, metrics.branchRate) |
| 1 | 165 | | CHECK_EQUAL_VAR(1, metrics.branchCovered) |
| 1 | 166 | | CHECK_EQUAL_VAR(2, metrics.branchValid) |
| 1 | 167 | | End |
| | 168 | |
|
| 1 | 169 | | static Function Test_GetLinesReport_Empty() |
| 1 | 170 | | STRUCT IUTF_Cobertura_Metrics metrics |
| 1 | 171 | | string result |
| | 172 | |
|
| 1 | 173 | | string indent = "" |
| 1 | 174 | | variable lineStart = 0 |
| 1 | 175 | | variable lineEnd = 2 |
| 1 | 176 | | variable procIndex = 1 |
| 1 | 177 | | string expected = "<lines>\n" + \ |
| 1 | 178 | | "</lines>\n" |
| | 179 | |
|
| 1 | 180 | | Make/FREE=1/N=(3, 3, 2) totals |
| 1 | 181 | | totals[][0][procIndex] = p + 1 |
| | 182 | |
|
| 1 | 183 | | WAVE marker = IUTF_Tracing#GetNewMarkerWave(3) |
| 1 | 184 | | marker[][%INSTR] = 0 |
| | 185 | |
|
| 1 | 186 | | [result, metrics] = IUTF_Tracing_Cobertura#GetLinesReport(indent, lineStart, lineEnd, procIndex, totals, marker) |
| | 187 | |
|
| 1 | 188 | | INFO("xml output") |
| 1 | 189 | | CHECK_EQUAL_STR(expected, result) |
| | 190 | |
|
| 1 | 191 | | CHECK_EQUAL_VAR(1, metrics.lineRate) |
| 1 | 192 | | CHECK_EQUAL_VAR(0, metrics.lineCovered) |
| 1 | 193 | | CHECK_EQUAL_VAR(0, metrics.lineValid) |
| 1 | 194 | | CHECK_EQUAL_VAR(1, metrics.branchRate) |
| 1 | 195 | | CHECK_EQUAL_VAR(0, metrics.branchCovered) |
| 1 | 196 | | CHECK_EQUAL_VAR(0, metrics.branchValid) |
| 1 | 197 | | End |
| | 198 | |
|
| | 199 | | #endif // UTF_ALLOW_TRACING |