MCPcopy Create free account
hub / github.com/GameTechDev/PresentMon / TestBody

Method TestBody

Tests/GoldEtlCsvTests.cpp:21–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 }
20
21 void TestBody() override
22 {
23 // Open the gold CSV
24 PresentMonCsv goldCsv;
25 if (!goldCsv.CSVOPEN(goldCsv_)) {
26 return;
27 }
28
29 // Make sure output directory exists.
30 for (auto i = testCsv_.find_last_of(L"/\\"); i == std::wstring::npos || !EnsureDirectoryCreated(testCsv_.substr(0, i)); ) {
31 AddTestFailure(__FILE__, __LINE__, "Output directory does not exist!");
32 goldCsv.Close();
33 return;
34 }
35
36 // Generate command line, querying gold CSV to try and match expected
37 // data.
38 PresentMon pm;
39 pm.Add(L"--stop_existing_session");
40 pm.AddEtlPath(etl_);
41 pm.AddCsvPath(testCsv_);
42 for (auto param : goldCsv.params_) {
43 pm.Add(param);
44 }
45 pm.PMSTART();
46 pm.PMEXITED();
47
48 // Open test CSV file and check it has the same columns as gold
49 PresentMonCsv testCsv;
50 if (!testCsv.CSVOPEN(testCsv_)) {
51 goldCsv.Close();
52 return;
53 }
54
55 // Compare gold/test CSV data rows
56 for (;;) {
57 auto goldDone = !goldCsv.ReadRow();
58 auto testDone = !testCsv.ReadRow();
59 if (goldDone || testDone) {
60 if (!goldDone || !testDone) {
61 AddTestFailure(__FILE__, __LINE__, "GOLD and TEST CSV had different number of rows");
62 printf("GOLD = %ls\n", goldCsv_.c_str());
63 printf("TEST = %ls\n", testCsv_.c_str());
64 }
65 break;
66 }
67
68 auto rowOk = true;
69 for (size_t h = 0; h < PresentMonCsv::KnownHeaderCount; ++h) {
70 if (testCsv.headerColumnIndex_[h] != SIZE_MAX && goldCsv.headerColumnIndex_[h] != SIZE_MAX) {
71 // Need to protect against missing columns on each line as
72 // the file may be corrupted.
73 auto testColIdx = testCsv.headerColumnIndex_[h];
74 auto goldColIdx = goldCsv.headerColumnIndex_[h];
75 char const* a = testColIdx < testCsv.cols_.size() ? testCsv.cols_[testColIdx] : "<missing>";
76 char const* b = goldColIdx < goldCsv.cols_.size() ? goldCsv.cols_[goldColIdx] : "<missing>";
77 if (_stricmp(a, b) == 0) {
78 continue;

Callers

nothing calls this directly

Calls 10

EnsureDirectoryCreatedFunction · 0.85
AddTestFailureFunction · 0.85
AddMethod · 0.80
AddEtlPathMethod · 0.80
AddCsvPathMethod · 0.80
GetHeaderStringMethod · 0.80
emptyMethod · 0.80
CloseMethod · 0.45
ReadRowMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected