int main(int argc, char** argv) { // set global variable g_testDirectory setTestDirectory(); // the following statement will be printed at beginning of job // and before a death test // printf("Test directory: %s.\n", (*g_testDirectory).c_str()); // parse command line BEFORE InitGoogleTest bool useTersePrinter = true; // ALWAYS true (for testing only) bool useTerseOutput = false; // option for terse (true) or all (false) bool useColor = true; bool noClose = false; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--terse_output") == 0) useTerseOutput = true; else if (strcmp(argv[i], "--no_close") == 0) noClose = true; else if (strcmp(argv[i], "--gtest_color=no") == 0) useColor = false; } // do this after parsing the command line but before changing printer testing::InitGoogleTest(&argc, argv); // change to TersePrinter if (useTersePrinter) { UnitTest& unit_test = *UnitTest::GetInstance(); testing::TestEventListeners& listeners = unit_test.listeners(); delete listeners.Release(listeners.default_result_printer()); listeners.Append(new TersePrinter(useTerseOutput, useColor)); } // Begin unit testing. // The default options file is renamed to avoid errors in testing. createTestDirectory(getTestDirectory()); renameDefaultOptionsFile(); int retval = RUN_ALL_TESTS(); restoreDefaultOptionsFile(); // Print verification if terse_printer. // Verify that all tests were run. This can occur if a source file // is missing from the project. The UnitTest reflection API in // example 9 will not work here because of user modifications. if (g_isI18nTest) // Change the following value to the number of tests (within 20). TersePrinter::PrintTestTotals(40, __FILE__, __LINE__); else // Change the following value to the number of tests (within 20). TersePrinter::PrintTestTotals(140, __FILE__, __LINE__); if (g_isI18nTest) printI18nMessage(); #ifdef _WIN32 printf("%c", '\n'); #endif // end of unit testing removeTestDirectory(getTestDirectory()); if (noClose) // command line option systemPause(); return retval; }
TEST_F(FSTestFixture, getAllFiles_with_extsfiler) { std::vector<Path> content; std::vector<std::string> filter; filter.push_back("txt"); Path path((getTestDirectory() / "0").string(), "", false); getAllFiles(path, content, &filter); ASSERT_EQ(content.size(), 1); ASSERT_EQ(content[0].getFullPath(), (getTestDirectory() / "0" / "1.txt").string()); }
void createTestFile(const string& testFilePath, const char* testFileText, int size /*0*/) // write a test file to the test directory // the size option is for 16 and 32 bit UTF files with NULs in the text { // verify test directory string testDir = getTestDirectory(); if (testFilePath.compare(0, testDir.length(), testDir) != 0 || !(testFilePath[testDir.length()] == '/' || testFilePath[testDir.length()] == '\\')) ASTYLE_ABORT("File not written to test directory: " + testFilePath); // write the output file ofstream fout(testFilePath.c_str(), ios::binary | ios::trunc); if (!fout) { #ifdef _WIN32 displayLastError(); #endif ASTYLE_ABORT("Cannot open output file: " + testFilePath); } if (size == 0) fout << testFileText; else fout.write(testFileText, size); fout.close(); }
/* * this will create the following directory tree: * ./0/0 * ./0/1.txt * ./0/2.png * ./0/UNICODE_EXAMPLE_FILE */ void fillWithTestData() { const fs::path &testDir = getTestDirectory(); fs::create_directories(testDir); std::vector<std::string> firstLevel; firstLevel.push_back("0"); std::vector<std::string> secondLevel; secondLevel.push_back("0"); secondLevel.push_back("1.txt"); secondLevel.push_back("2.png"); secondLevel.push_back( UNICODE_EXAMPLE_FILE ); for (const std::string& i : firstLevel) { fs::create_directory(testDir / i); for (const std::string& j : secondLevel) { fs::path newFilePath = testDir / i; UTIL::FS::Path filePath( newFilePath.string(), j, false ); std::filebuf fb; std::wstring nameW = std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes( filePath.getFullPath() ); fb.open( nameW, std::ios::out ); std::ostream os( &fb ); os << "this is a test file" << std::endl; fb.close(); } } }
string createLocaleDirectory(wstring subDirectory) // create a directory in the language of the current locale // the locale must be set before calling this function { string subdir = convertToMultiByte(subDirectory); string dirpath = getTestDirectory() + subdir; standardizePath(subdir); // create directory createTestDirectory(dirpath); return subdir; }
TEST_F(FSTestFixture, getAllFiles_without_extsFilter) { std::vector<Path> content; std::vector<Path> content0; Path path(getTestDirectory().string(), "", false); Path path0((getTestDirectory() / "0").string(), "", false); getAllFiles(path, content, nullptr); getAllFiles(path0, content0, nullptr); ASSERT_EQ(content.size(), 0); ASSERT_EQ(content0.size(), 4); ASSERT_TRUE(isInVector(Path((getTestDirectory() / "0" / "0").string(), "", true), content0)); ASSERT_TRUE(isInVector(Path((getTestDirectory() / "0" / "1.txt").string(), "", true), content0)); ASSERT_TRUE(isInVector(Path((getTestDirectory() / "0" / "2.png").string(), "", true), content0)); ASSERT_TRUE(isInVector(Path((getTestDirectory() / "0" / UNICODE_EXAMPLE_FILE).string(), "", true), content0)); }
vector<string> generateListOfMXOptimFiles() { vector<string> testdirs {"minimization/"}; return getAllFilesInDirs(getTestDirectory() + "mx/", testdirs); }
std::vector<std::string> generateListOfMXTotalnbFiles(){ std::vector<std::string> testdirs { "simplemx/", "numberknown/", "outputvoc_large/" }; return getAllFilesInDirs(getTestDirectory() + "mx/", testdirs); }
void deleteTestDirectory() { fs::remove_all(getTestDirectory()); }
void createTestDirectory() { fs::create_directories(getTestDirectory()); fillWithTestData(); }