int MarketDefaultTest::Tester::testFilePresent(const TCHAR* file) { mStatus.message(kInfoMessage, _T("Starting testFilePresent %s\r\n"), file); // Now try again with a file that should exist TSTR path = getFactoryDefaultFilePath(file); DeleteFile(path); TSTR expected = getDefaultFilePath(file); DeleteFile(expected); if (!createFile(expected, &file1)) return 1; char* valueSrc; long lengthSrc; int foundSrc = getFileContents(expected, valueSrc, lengthSrc); int errors = 0; // Now copy it to the defaults directory TSTR newPath = GetMarketDefaultsFileName(file); if (newPath != expected) { mStatus.message(kErrorMessage, _T("%s was copied to the wrong file\r\n") _T(" Expected: %s\r\n") _T(" Got: %s\r\n"), path.data(), expected.data(), newPath.data()); ++errors; } char* valueDst; long lengthDst; int foundDst = getFileContents(expected, valueDst, lengthDst); if (!filesAreEqual(foundSrc, valueSrc, lengthSrc, foundDst, valueDst, lengthDst)) { mStatus.message(kErrorMessage, _T("%s was changed by copy\r\n"), expected.data()); ++errors; } // Clean up delete[] valueSrc; delete[] valueDst; DeleteFile(path); DeleteFile(expected); DeleteFile(newPath); mStatus.message(kInfoMessage, _T("Finished testFilePresent %s - %d error(s)\r\n\r\n"), file, errors); return errors; }
// Check whether two files are equal. Load the file into // memory and compare them. static bool filesAreEqual(const TCHAR* file1, const TCHAR* file2) { char* v1, * v2; long l1, l2; int f1, f2; f1 = getFileContents(file1, v1, l1); f2 = getFileContents(file2, v2, l2); bool e = filesAreEqual(f1, v1, l1, f2, v2, l2); delete[] v1; delete[] v2; return 1; }
bool Tester::ConfigHandlerTest2() { ConfigHandler testObj; testObj.directions = new list<Directions>; try { testObj.directionsFilePath = "directions_reference.xml"; testObj.readDirectionsFile(); testObj.directionsFilePath = "directions_test_result.xml"; testObj.writeDirectionsFile(); } catch(...) { return false; } return filesAreEqual("directions_reference.xml", "directions_test_result.xml"); }
bool Tester::ConfigHandlerTest1() { ConfigHandler testObj; testObj.guids = new map<string, set<string> >; try { testObj.guidsFilePath = "guids_reference.xml"; testObj.readGuidsFile(); testObj.guidsFilePath = "guids_test_result.xml"; testObj.writeGuidsFile(); } catch(...) { return false; } return filesAreEqual("guids_reference.xml", "guids_test_result.xml"); }
int MarketDefaultTest::Tester::testFileCopy(const TCHAR* file) { mStatus.message(kInfoMessage, _T("Starting testFileCopy %s\r\n"), file); // First create a file in the factory defaults TSTR path = getFactoryDefaultFilePath(file); if (!createFile(path, &file1)) return 1; TSTR expected = getDefaultFilePath(file); DeleteFile(expected); int errors = 0; // Now copy it to the defaults directory TSTR newPath = GetMarketDefaultsFileName(file); if (newPath != expected) { mStatus.message(kErrorMessage, _T("%s was copied to the wrong file\r\n") _T(" Expected: %s\r\n") _T(" Got: %s\r\n"), path.data(), expected.data(), newPath.data()); ++errors; } if (!filesAreEqual(path, newPath)) { mStatus.message(kErrorMessage, _T("%s was copied incorrectly\r\n"), newPath.data()); ++errors; } // Clean up DeleteFile(path); DeleteFile(expected); DeleteFile(newPath); mStatus.message(kInfoMessage, _T("Finished testFileCopy %s - %d error(s)\r\n\r\n"), file, errors); return errors; }