void mitk::USImageLoggingFilter::SaveImages(std::string path, std::vector<std::string>& filenames, std::string& csvFileName) { filenames = std::vector<std::string>(); //test if path is valid Poco::Path testPath(path); if(!testPath.isDirectory()) { mitkThrow() << "Attemting to write to directory " << path << " which is not valid! Aborting!"; } //generate a unique ID which is used as part of the filenames, so we avoid to overwrite old files by mistake. mitk::UIDGenerator myGen = mitk::UIDGenerator("",5); std::string uniqueID = myGen.GetUID(); //first: write the images for(size_t i=0; i<m_LoggedImages.size(); i++) { std::stringstream name; name << path << uniqueID << "_Image_" << i << m_ImageExtension; mitk::IOUtil::SaveImage(m_LoggedImages.at(i),name.str()); filenames.push_back(name.str()); } //then: write a csv file which contains comments to all the images //open file std::stringstream csvFilenameStream; csvFilenameStream << path << uniqueID << "_ImageMessages.csv"; csvFileName = csvFilenameStream.str(); std::filebuf fb; fb.open (csvFileName.c_str(),std::ios::out); std::ostream os(&fb); os.precision(15); //set high precision to avoid loss of digits //write header os << "image filename; MITK system timestamp; message\n"; //write data for(size_t i=0; i<m_LoggedImages.size(); i++) { std::map<int, std::string>::iterator it = m_LoggedMessages.find(i); if (m_LoggedMessages.empty() || (it == m_LoggedMessages.end())) os << filenames.at(i) << ";" << m_LoggedMITKSystemTimes.at(i) << ";" << "" << "\n"; else os << filenames.at(i) << ";" << m_LoggedMITKSystemTimes.at(i) << ";" << it->second << "\n"; } //close file fb.close(); }
void PathAppendTest() { CTSVNPath testPath(L"c:/test/"); testPath.AppendPathString(L"/Hello"); ATLASSERT(testPath.GetWinPathString() == L"c:\\test\\Hello"); testPath.AppendPathString(L"T2"); ATLASSERT(testPath.GetWinPathString() == L"c:\\test\\Hello\\T2"); CTSVNPath testFilePath(L"C:\\windows\\win.ini"); CTSVNPath testBasePath(L"c:/temp/myfile.txt"); // You wouldn't want to do this in real life - you'd use append-raw testBasePath.AppendPathString(testFilePath.GetFileExtension()); ATLASSERT(testBasePath.GetWinPathString() == L"c:\\temp\\myfile.txt\\.ini"); }
//#include <interrupt_tasks.h> int main(int argc, char *argv[]) { int nthreads, source, target; char *graphFileName; FILE *graphFile; tg graph; char *argNames[3] = { "source_node_num", "target_node_num", "graph_file" }; char *defaultValues[3] = { "1", "29", "software/benchmarks/data/exampleGraph_01.gph" }; char *timerNames[1] = { "EXE_TIME" }; //SETUP_ISR; nthreads = omp_get_max_threads(); OSCR_init( nthreads, "Check if there is a path on a directed graph.", NULL, 3, argNames, defaultValues, 1, 1, timerNames, argc, argv ); /* 1. GET PARAMETERS */ source = OSCR_getarg_int(1); target = OSCR_getarg_int(2); graphFileName = OSCR_getarg_string(3); /* 2. READ GRAPH */ graphFile = fopen(graphFileName,"r"); if (graphFile==NULL) { fprintf(stderr,"Imposible to open graph file: %s\n",graphFileName); exit(-1); } graph = tg_read(graphFile); fclose(graphFile); /* 3. CALL COMPUTATION */ testPath(nthreads, source, target, graph); /* 4. REPORT */ OSCR_report(); exit(0); return 0; }
bool StartupTests::perform() { LogContext log("StartupTests"); log.log(1, "Running startup tests..."); bool testRes = testLogging() && testPath() && testNICsHwAddr() && testNICs(); log.log(1, "Startup tests complete"); return testRes; }
TEST_F(ClangdVFSTest, SearchLibDir) { // Checks that searches for GCC installation is done through vfs. MockFSProvider FS; ErrorCheckingDiagConsumer DiagConsumer; MockCompilationDatabase CDB; CDB.ExtraClangFlags.insert(CDB.ExtraClangFlags.end(), {"-xc++", "-target", "x86_64-linux-unknown", "-m64", "--gcc-toolchain=/randomusr", "-stdlib=libstdc++"}); ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest()); // Just a random gcc version string SmallString<8> Version("4.9.3"); // A lib dir for gcc installation SmallString<64> LibDir("/randomusr/lib/gcc/x86_64-linux-gnu"); llvm::sys::path::append(LibDir, Version); // Put crtbegin.o into LibDir/64 to trick clang into thinking there's a gcc // installation there. SmallString<64> DummyLibFile; llvm::sys::path::append(DummyLibFile, LibDir, "64", "crtbegin.o"); FS.Files[DummyLibFile] = ""; SmallString<64> IncludeDir("/randomusr/include/c++"); llvm::sys::path::append(IncludeDir, Version); SmallString<64> StringPath; llvm::sys::path::append(StringPath, IncludeDir, "string"); FS.Files[StringPath] = "class mock_string {};"; auto FooCpp = testPath("foo.cpp"); const auto SourceContents = R"cpp( #include <string> mock_string x; )cpp"; FS.Files[FooCpp] = SourceContents; runAddDocument(Server, FooCpp, SourceContents); EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags()); const auto SourceContentsWithError = R"cpp( #include <string> std::string x; )cpp";
void TSessionTest::RunTests() // // Run tests on iFs file server session // { testDriveList(); testDriveInfo(); testVolumeInfo(); testSetVolume(); testPath(); CreateTestDirectory(_L("\\SESSION_TEST\\TFSRV\\")); testInitialisation(); testSubst(); CopyFileToTestDirectory(); MakeAndDeleteFiles(); }
void ProtoBufWebSocketRequestMessageTest::testConstructor() { std::string testVerb("hfhfhfh"); std::string testPath("feuhehefhd"); std::string testBody("body body body"); google::protobuf::uint64 testId(3745646212); textsecure::WebSocketRequestMessage tsRequestMessage; tsRequestMessage.set_verb(testVerb); tsRequestMessage.set_path(testPath); tsRequestMessage.set_body(testBody); tsRequestMessage.set_id(testId); ProtoBufWebSocketRequestMessage requestMessage(tsRequestMessage); QVERIFY2(requestMessage.verb() == QString::fromStdString(testVerb), "Verb wasn't set."); QVERIFY2(requestMessage.path() == QString::fromStdString(testPath), "Path wasn't set."); QVERIFY2(requestMessage.body() == QString::fromStdString(testBody), "Body wasn't set."); QVERIFY2(requestMessage.requestId() == testId, "Test id wasn't set."); }
static JSValueRef runTest(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { JSRetainPtr<JSStringRef> stringValue(Adopt, JSValueToStringCopy(context, arguments[0], nullptr)); g_assert(stringValue); size_t testPathLength = JSStringGetMaximumUTF8CStringSize(stringValue.get()); GUniquePtr<char> testPath(static_cast<char*>(g_malloc(testPathLength))); JSStringGetUTF8CString(stringValue.get(), testPath.get(), testPathLength); WebKitWebPage* webPage = WEBKIT_WEB_PAGE(JSObjectGetPrivate(thisObject)); g_assert(WEBKIT_IS_WEB_PAGE(webPage)); // Test /WebKitDOMNode/dom-cache is an exception, because it's called 3 times, so // the WebPage is destroyed after the third time. if (g_str_equal(testPath.get(), "WebKitDOMNode/dom-cache")) { static unsigned domCacheTestRunCount = 0; if (++domCacheTestRunCount == 3) WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage)); } else WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage)); std::unique_ptr<WebProcessTest> test = WebProcessTest::create(String::fromUTF8(testPath.get())); return JSValueMakeBoolean(context, test->runTest(g_strrstr(testPath.get(), "/") + 1, webPage)); }
const char * resolveDeviceName (const char *const *names, const char *description) { const char *first = *names; const char *device = NULL; const char *name; while ((name = *names++)) { char *path = getDevicePath(name); if (!path) break; logMessage(LOG_DEBUG, "checking %s device: %s", description, path); if (testPath(path)) { device = name; free(path); break; } logMessage(LOG_DEBUG, "%s device access error: %s: %s", description, path, strerror(errno)); if (errno != ENOENT) if (!device) device = name; free(path); } if (!device) { if (first) { device = first; } else { logMessage(LOG_ERR, "%s device names not defined", description); } } if (device) logMessage(LOG_INFO, "%s device: %s", description, device); return device; }
TEST_F(ClangdVFSTest, ReparseOnHeaderChange) { MockFSProvider FS; ErrorCheckingDiagConsumer DiagConsumer; MockCompilationDatabase CDB; ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest()); const auto SourceContents = R"cpp( #include "foo.h" int b = a; )cpp"; auto FooCpp = testPath("foo.cpp"); auto FooH = testPath("foo.h"); FS.Files[FooH] = "int a;"; FS.Files[FooCpp] = SourceContents; Server.addDocument(FooCpp, SourceContents); auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp); ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics"; EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags()); FS.Files[FooH] = ""; Server.addDocument(FooCpp, SourceContents); auto DumpParseDifferent = dumpASTWithoutMemoryLocs(Server, FooCpp); ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics"; EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags()); FS.Files[FooH] = "int a;"; Server.addDocument(FooCpp, SourceContents); auto DumpParse2 = dumpASTWithoutMemoryLocs(Server, FooCpp); ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for diagnostics"; EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags()); EXPECT_EQ(DumpParse1, DumpParse2); EXPECT_NE(DumpParse1, DumpParseDifferent); }
SortServiceModel::SortServiceModel(QObject *parent) : QSortFilterProxyModel(parent) { /* testing purpose */ QString testPath(getenv("SERVICES_PRIORITY")); if (!testPath.isEmpty()) { QDir testDir(testPath); QStringList testPriorityList = testDir.entryList(QDir::Files); foreach(QString filename, testPriorityList) createPriorities(testDir.filePath(filename)); } else { QDir etc(QDir::rootPath() + QLatin1String("/etc/accounts-ui/service-sorting.d")); QDir home(QDir::homePath() + QLatin1String("/.config/accounts-ui/service-sorting.d")); QStringList etcPriorityList = etc.entryList(QDir::Files); foreach(QString filename, etcPriorityList) createPriorities(etc.filePath(filename)); QStringList homePriorityList = home.entryList(QDir::Files); foreach(QString filename, homePriorityList) createPriorities(home.filePath(filename)); } }
void testPaths() { std::string path; path = "/usr/lib"; testPath(path); path = "/usr/"; testPath(path); path = "usr"; testPath(path); path = "/"; testPath(path); path = "."; testPath(path); path = ".."; testPath(path); path = "///"; testPath(path); path = "/usr/.emacs"; testPath(path); path = "/usr/.emacs/"; testPath(path); path = "/usr/.emacs//"; testPath(path); path = "usr/.emacs"; testPath(path); path = ".emacs"; testPath(path); path = ".emacs.gz"; testPath(path); path = "/tmp/image.jpg"; testPath(path); path = "/tmp/.image.jpg"; testPath(path); path = "/image.jpg"; testPath(path); path = "image.jpg"; testPath(path); path = "image.jpg//"; testPath(path); path = "/////image.jpg"; testPath(path); path = "/foo.bar/image"; testPath(path); path = "/foo.bar/images.tar.gz"; testPath(path); path = "d:\\foo.bar\\images.tar.gz"; testPath(path); }
int main(int argc, char **argv) { //testReg(); testPath(); return 0; }
void IWORKPathTest::testConstruction() { { const string src = "M 0.0 0.0"; IWORKPath refPath; refPath.appendMoveTo(0, 0); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } { const string src = "L 0.0 0.0"; IWORKPath refPath; refPath.appendLineTo(0, 0); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } { const string src = "C 0.5 0.5 0 0 1 1"; IWORKPath refPath; refPath.appendCurveTo(0.5, 0.5, 0, 0, 1, 1); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } { const string src = "Z"; IWORKPath refPath; refPath.appendClose(); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } { const string src = "M 0 0 L 1 1"; IWORKPath refPath; refPath.appendMoveTo(0, 0); refPath.appendLineTo(1, 1); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } { const string src = "M 0 0 L 1 0 L 1 1 L 0 1 Z L 0 0"; IWORKPath refPath; refPath.appendMoveTo(0, 0); refPath.appendLineTo(1, 0); refPath.appendLineTo(1, 1); refPath.appendLineTo(0, 1); refPath.appendClose(); refPath.appendLineTo(0, 0); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } { const string src = "M 0.0 0.0 L 0 1 C 1 1 0.5 0.5 0 0 Z"; IWORKPath refPath; refPath.appendMoveTo(0, 0); refPath.appendLineTo(0, 1); refPath.appendCurveTo(1, 1, 0.5, 0.5, 0, 0); refPath.appendClose(); IWORKPath testPath(src); CPPUNIT_ASSERT(refPath == testPath); } }
/*********************************************************************************************************************************** Test Run ***********************************************************************************************************************************/ void testRun(void) { // Create default storage object for testing Storage *storageTest = storagePosixNew( strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL); // ***************************************************************************************************************************** if (testBegin("infoNewLoad(), infoFileName(), infoIni()")) { // Initialize test variables //-------------------------------------------------------------------------------------------------------------------------- String *content = NULL; String *fileName = strNewFmt("%s/test.ini", testPath()); String *fileNameCopy = strNewFmt("%s/test.ini.copy", testPath()); Info *info = NULL; content = strNew ( "[backrest]\n" "backrest-checksum=\"1efa53e0611604ad7d833c5547eb60ff716e758c\"\n" "backrest-format=5\n" "backrest-version=\"2.04\"\n" "\n" "[db]\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.4\"\n" "\n" "[db:history]\n" "1={\"db-id\":6569239123849665679,\"db-version\":\"9.4\"}\n" ); // Info files missing and at least one is required //-------------------------------------------------------------------------------------------------------------------------- TEST_ERROR_FMT( infoNewLoad(storageLocal(), fileName, cipherTypeNone, NULL, NULL), FileMissingError, "unable to load info file '%s/test.ini' or '%s/test.ini.copy':\n" "FileMissingError: " STORAGE_ERROR_READ_MISSING "\n" "FileMissingError: " STORAGE_ERROR_READ_MISSING, testPath(), testPath(), strPtr(strNewFmt("%s/test.ini", testPath())), strPtr(strNewFmt("%s/test.ini.copy", testPath()))); // Only copy exists and one is required //-------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileNameCopy), BUFSTR(content)), "put info.copy to file"); TEST_ASSIGN(info, infoNewLoad(storageLocal(), fileName, cipherTypeNone, NULL, NULL), "load copy file"); TEST_RESULT_PTR(infoCipherPass(info), NULL, " cipherPass is not set"); // Remove the copy and store only the main info file and encrypt it. One is required. //-------------------------------------------------------------------------------------------------------------------------- StorageWrite *infoWrite = storageNewWriteNP(storageLocalWrite(), fileName); ioWriteFilterGroupSet( storageWriteIo(infoWrite), ioFilterGroupAdd( ioFilterGroupNew(), cipherBlockNew(cipherModeEncrypt, cipherTypeAes256Cbc, BUFSTRDEF("12345678"), NULL))); storageRemoveNP(storageLocalWrite(), fileNameCopy); storagePutNP( infoWrite, BUFSTRDEF( "[backrest]\n" "backrest-checksum=\"9d2f6dce339751e1a056187fad67d2834b3d4ab3\"\n" "backrest-format=5\n" "backrest-version=\"2.04\"\n" "\n" "[cipher]\n" "cipher-pass=\"ABCDEFGH\"\n" "\n" "[db]\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.4\"\n" "\n" "[db:history]\n" "1={\"db-id\":6569239123849665679,\"db-version\":\"9.4\"}\n")); // Only main info exists and is required Ini *ini = NULL; TEST_ASSIGN(info, infoNewLoad(storageLocal(), fileName, cipherTypeAes256Cbc, strNew("12345678"), &ini), "load file"); TEST_RESULT_STR(strPtr(iniGet(ini, strNew("cipher"), strNew("cipher-pass"))), "\"ABCDEFGH\"", " check ini"); TEST_RESULT_STR(strPtr(infoCipherPass(info)), "ABCDEFGH", " cipherPass is set"); // Invalid format //-------------------------------------------------------------------------------------------------------------------------- storageRemoveNP(storageLocalWrite(), fileName); content = strNew ( "[backrest]\n" "backrest-checksum=\"14617b089cb5c9b3224e739bb794e865b9bcdf4b\"\n" "backrest-format=4\n" "backrest-version=\"2.04\"\n" "\n" "[db]\n" "db-catalog-version=201409291\n" "db-control-version=942\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.4\"\n" "\n" "[db:history]\n" "1={\"db-catalog-version\":201409291,\"db-control-version\":942,\"db-system-id\":6569239123849665679," "\"db-version\":\"9.4\"}\n" ); // Only main file exists but the backrest-format is invalid TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put invalid br format to file"); TEST_ERROR_FMT( infoNewLoad(storageLocal(), fileName, cipherTypeNone, NULL, NULL), FormatError, "unable to load info file '%s/test.ini' or '%s/test.ini.copy':\n" "FormatError: invalid format in '%s/test.ini', expected 5 but found 4\n" "FileMissingError: " STORAGE_ERROR_READ_MISSING, testPath(), testPath(), testPath(), strPtr(strNewFmt("%s/test.ini.copy", testPath()))); content = strNew ( "[backrest]\n" "backrest-checksum=\"14617b089cb5c9b3224e739bb794e865b9bcdf4b\"\n" "backrest-format=4\n" "backrest-version=\"2.05\"\n" "\n" "[db]\n" "db-catalog-version=201409291\n" "db-control-version=942\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.4\"\n" "\n" "[db:history]\n" "1={\"db-catalog-version\":201409291,\"db-control-version\":942,\"db-system-id\":6569239123849665679," "\"db-version\":\"9.4\"}\n" ); TEST_RESULT_VOID( storagePutNP( storageNewWriteNP(storageLocalWrite(), fileNameCopy), BUFSTR(content)), "put invalid info to copy file"); TEST_ERROR( infoNewLoad(storageLocal(), fileName, cipherTypeNone, NULL, NULL), FileOpenError, strPtr( strNewFmt( "unable to load info file '%s/test.ini' or '%s/test.ini.copy':\n" "FormatError: invalid format in '%s/test.ini', expected 5 but found 4\n" "ChecksumError: invalid checksum in '%s/test.ini.copy', expected 'af92308095d6141bcda6b2df6d574f98d1115163'" " but found '14617b089cb5c9b3224e739bb794e865b9bcdf4b'", testPath(), testPath(), testPath(), testPath()))); // Invalid checksum //-------------------------------------------------------------------------------------------------------------------------- storageRemoveNP(storageLocalWrite(), fileName); storageRemoveNP(storageLocalWrite(), fileNameCopy); // change the checksum content = strNew ( "[backrest]\n" "backrest-checksum=\"4306ec205f71417c301e403c4714090e61c8a999\"\n" "backrest-format=5\n" "backrest-version=\"1.23\"\n" "\n" "[db]\n" "db-id=1\n" "db-system-id=6455618988686438683\n" "db-version=\"9.6\"\n" "\n" "[db:history]\n" "1={\"db-id\":6455618988686438683,\"db-version\":\"9.6\"}\n" "2={\"db-id\":6457457208275135411,\"db-version\":\"9.6\"}\n" ); TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileNameCopy), BUFSTR(content)), "put invalid checksum to copy"); // Empty checksum for main file content = strNew ( "[backrest]\n" "backrest-checksum=\n" "backrest-format=5\n" "backrest-version=\"1.23\"\n" "\n" "[db]\n" "db-id=1\n" "db-system-id=6455618988686438683\n" "db-version=\"9.6\"\n" "\n" "[db:history]\n" "1={\"db-id\":6455618988686438683,\"db-version\":\"9.6\"}\n" "2={\"db-id\":6457457208275135411,\"db-version\":\"9.6\"}\n" ); TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put empty checksum to file"); // Copy file error TEST_ERROR( infoNewLoad(storageLocal(), fileName, cipherTypeNone, NULL, NULL), ChecksumError, strPtr( strNewFmt( "unable to load info file '%s/test.ini' or '%s/test.ini.copy':\n" "ChecksumError: invalid checksum in '%s/test.ini', expected '4306ec205f71417c301e403c4714090e61c8a736' but" " no checksum found\n" "ChecksumError: invalid checksum in '%s/test.ini.copy', expected '4306ec205f71417c301e403c4714090e61c8a736'" " but found '4306ec205f71417c301e403c4714090e61c8a999'", testPath(), testPath(), testPath(), testPath()))); // Encryption error //-------------------------------------------------------------------------------------------------------------------------- storageRemoveNP(storageLocalWrite(), fileName); TEST_ERROR_FMT( infoNewLoad(storageLocal(), fileName, cipherTypeAes256Cbc, strNew("12345678"), NULL), CryptoError, "unable to load info file '%s/test.ini' or '%s/test.ini.copy':\n" "FileMissingError: " STORAGE_ERROR_READ_MISSING "\n" "CryptoError: '%s/test.ini.copy' cipher header invalid\n" "HINT: Is or was the repo encrypted?", testPath(), testPath(), strPtr(strNewFmt("%s/test.ini", testPath())), testPath()); storageRemoveNP(storageLocalWrite(), fileNameCopy); // infoFree() //-------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_VOID(infoFree(info), "infoFree() - free info memory context"); } // ***************************************************************************************************************************** if (testBegin("infoSave()")) { const String *fileName = strNew("test.info"); const String *cipherPass = strNew("12345"); Ini *ini = iniNew(); iniSet(ini, strNew("section1"), strNew("key1"), strNew("value1")); TEST_RESULT_VOID(infoSave(infoNew(), ini, storageTest, fileName, cipherTypeNone, NULL), "save info"); ini = NULL; TEST_RESULT_VOID(infoNewLoad(storageTest, fileName, cipherTypeNone, NULL, &ini), " reload info"); TEST_RESULT_STR(strPtr(iniGet(ini, strNew("section1"), strNew("key1"))), "value1", " check ini"); TEST_RESULT_BOOL(storageExistsNP(storageTest, fileName), true, "check main exists"); TEST_RESULT_BOOL(storageExistsNP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strPtr(fileName))), true, "check main exists"); // Add encryption // ------------------------------------------------------------------------------------------------------------------------- ini = iniNew(); iniSet(ini, strNew("section1"), strNew("key1"), strNew("value4")); Info *info = infoNew(); info->cipherPass = strNew("/badpass"); TEST_RESULT_VOID(infoSave(info, ini, storageTest, fileName, cipherTypeAes256Cbc, cipherPass), "save encrypted info"); ini = NULL; TEST_RESULT_VOID(infoNewLoad(storageTest, fileName, cipherTypeAes256Cbc, cipherPass, &ini), " reload info"); TEST_RESULT_STR(strPtr(iniGet(ini, strNew("section1"), strNew("key1"))), "value4", " check ini"); TEST_RESULT_STR(strPtr(iniGet(ini, strNew("cipher"), strNew("cipher-pass"))), "\"/badpass\"", " check cipher-pass"); } }
SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(2), SkIntToScalar(1)); static SkMatrix testMatrix() { SkMatrix matrix; matrix.reset(); matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); return matrix; } const SkMatrix kTestMatrix = testMatrix(); static SkPath testPath() { SkPath path; path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(2), SkIntToScalar(1))); return path; } const SkPath kTestPath = testPath(); static SkRegion testRegion() { SkRegion region; SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); region.setRect(rect); return region; } const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1); const SkRegion kTestRegion = testRegion(); const SkColor kTestColor = 0x01020304; const SkPaint kTestPaint; const SkPoint kTestPoints[3] = { {SkIntToScalar(0), SkIntToScalar(0)}, {SkIntToScalar(2), SkIntToScalar(1)}, {SkIntToScalar(0), SkIntToScalar(2)} };
TEST(URITest, Platform) { auto Path = testPath("x"); auto U = URI::create(Path, "file"); EXPECT_TRUE(static_cast<bool>(U)); EXPECT_THAT(resolveOrDie(*U), Path); }
/*********************************************************************************************************************************** Test Run ***********************************************************************************************************************************/ void testRun(void) { FUNCTION_HARNESS_VOID(); // ***************************************************************************************************************************** if (testBegin("cfgExecParam()")) { StringList *argList = strLstNew(); strLstAddZ(argList, "pgbackrest"); strLstAddZ(argList, "--stanza=test1"); strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath())); strLstAdd(argList, strNewFmt("--pg1-path=%s/db path", testPath())); strLstAddZ(argList, "--log-subprocess"); strLstAddZ(argList, "--no-config"); strLstAddZ(argList, "--reset-neutral-umask"); strLstAddZ(argList, "--repo-cipher-type=aes-256-cbc"); strLstAddZ(argList, "archive-get"); harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); // Set repo1-cipher-pass to make sure it is not passed on the command line cfgOptionValidSet(cfgOptRepoCipherPass, true); cfgOptionSet(cfgOptRepoCipherPass, cfgSourceConfig, varNewStrZ("1234")); TEST_RESULT_STR( strPtr(strLstJoin(cfgExecParam(cfgCmdLocal, NULL), "|")), strPtr( strNewFmt( "--no-config|--log-subprocess|--pg1-path=\"%s/db path\"|--repo1-cipher-type=aes-256-cbc|--repo1-path=%s/repo" "|--stanza=test1|local", testPath(), testPath())), "exec archive-get -> local"); // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAddZ(argList, "pgbackrest"); strLstAddZ(argList, "--stanza=test1"); strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath())); strLstAdd(argList, strNewFmt("--pg1-path=%s/db", testPath())); strLstAddZ(argList, "--db-include=1"); strLstAddZ(argList, "--db-include=2"); strLstAddZ(argList, "--recovery-option=a=b"); strLstAddZ(argList, "--recovery-option=c=d"); strLstAddZ(argList, "restore"); harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); KeyValue *optionReplace = kvNew(); kvPut(optionReplace, varNewStr(strNew("repo1-path")), varNewStr(strNew("/replace/path"))); kvPut(optionReplace, varNewStr(strNew("stanza")), NULL); TEST_RESULT_STR( strPtr(strLstJoin(cfgExecParam(cfgCmdRestore, optionReplace), "|")), strPtr( strNewFmt( "--db-include=1|--db-include=2|--pg1-path=%s/db|--recovery-option=a=b|--recovery-option=c=d" "|--repo1-path=/replace/path|restore", testPath())), "exec restore -> restore"); } FUNCTION_HARNESS_RESULT_VOID(); }
/*********************************************************************************************************************************** Test Run ***********************************************************************************************************************************/ void testRun(void) { // ***************************************************************************************************************************** if (testBegin("infoPgNewLoad(), infoPgFree(), infoPgDataCurrent(), infoPgDataToLog(), infoPgAdd(), infoPgIni()")) { String *content = NULL; String *fileName = strNewFmt("%s/test.ini", testPath()); String *fileName2 = strNewFmt("%s/test2.ini", testPath()); // Archive info //-------------------------------------------------------------------------------------------------------------------------- content = strNew ( "[db]\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.4\"\n" "\n" "[db:history]\n" "1={\"db-id\":6569239123849665679,\"db-version\":\"9.4\"}\n" ); TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put info to file"); InfoPg *infoPg = NULL; Ini *ini = NULL; TEST_ASSIGN( infoPg, infoPgNewLoad(storageLocal(), fileName, infoPgArchive, cipherTypeNone, NULL, &ini), "load file"); TEST_RESULT_STR(strPtr(iniGet(ini, strNew("db"), strNew("db-id"))), "1", " check ini"); TEST_RESULT_INT(lstSize(infoPg->history), 1, " history record added"); InfoPgData infoPgData = infoPgDataCurrent(infoPg); TEST_RESULT_INT(infoPgData.id, 1, " id set"); TEST_RESULT_INT(infoPgData.version, PG_VERSION_94, " version set"); TEST_RESULT_INT(infoPgData.systemId, 6569239123849665679, " system-id set"); TEST_RESULT_INT(infoPgData.catalogVersion, 0, " catalog-version not set"); TEST_RESULT_INT(infoPgData.controlVersion, 0, " control-version not set"); TEST_RESULT_INT(infoPgDataTotal(infoPg), 1, " check pg data total"); TEST_RESULT_STR(strPtr(infoPgArchiveId(infoPg, 0)), "9.4-1", " check pg archive id"); TEST_RESULT_PTR(infoPgCipherPass(infoPg), NULL, " no cipher passphrase"); // Backup info //-------------------------------------------------------------------------------------------------------------------------- content = strNew ( "[db]\n" "db-catalog-version=201409291\n" "db-control-version=942\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.4\"\n" "\n" "[db:history]\n" "1={\"db-catalog-version\":201409291,\"db-control-version\":942,\"db-system-id\":6569239123849665679," "\"db-version\":\"9.4\"}\n" ); TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put info to file"); TEST_ASSIGN( infoPg, infoPgNewLoad(storageLocal(), fileName, infoPgBackup, cipherTypeNone, NULL, NULL), "load file"); TEST_RESULT_INT(lstSize(infoPg->history), 1, " history record added"); infoPgData = infoPgDataCurrent(infoPg); TEST_RESULT_INT(infoPgData.id, 1, " id set"); TEST_RESULT_INT(infoPgData.version, PG_VERSION_94, " version set"); TEST_RESULT_INT(infoPgData.systemId, 6569239123849665679, " system-id set"); TEST_RESULT_INT(infoPgData.catalogVersion, 201409291, " catalog-version set"); TEST_RESULT_INT(infoPgData.controlVersion, 942, " control-version set"); // Manifest info //-------------------------------------------------------------------------------------------------------------------------- content = strNew ( "[db]\n" "db-catalog-version=201510051\n" "db-control-version=942\n" "db-id=2\n" "db-system-id=6365925855999999999\n" "db-version=\"9.5\"\n" "\n" "[db:history]\n" "1={\"db-catalog-version\":201409291,\"db-control-version\":942,\"db-system-id\":6569239123849665679," "\"db-version\":\"9.4\"}\n" "2={\"db-catalog-version\":201510051,\"db-control-version\":942,\"db-system-id\":6365925855999999999," "\"db-version\":\"9.5\"}\n" ); // Put the file and load it TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put info to file"); TEST_ASSIGN( infoPg, infoPgNewLoad(storageLocal(), fileName, infoPgManifest, cipherTypeNone, NULL, NULL), "load file"); // Save the file and verify it ini = iniNew(); TEST_RESULT_VOID(infoPgSave(infoPg, ini, storageLocalWrite(), fileName2, cipherTypeNone, NULL), "save file"); TEST_RESULT_BOOL( bufEq( storageGetNP(storageNewReadNP(storageLocal(), fileName)), storageGetNP(storageNewReadNP(storageLocal(), fileName2))), true, "files are equal"); TEST_RESULT_INT(lstSize(infoPg->history), 2, "history record added"); infoPgData = infoPgDataCurrent(infoPg); TEST_RESULT_INT(infoPgData.id, 2, " id set"); TEST_RESULT_INT(infoPgData.version, PG_VERSION_95, " version set"); TEST_RESULT_INT(infoPgData.systemId, 6365925855999999999, " system-id set"); TEST_RESULT_INT(infoPgData.catalogVersion, 201510051, " catalog-version set"); TEST_RESULT_INT(infoPgData.controlVersion, 942, " control-version set"); // infoPgAdd //-------------------------------------------------------------------------------------------------------------------------- infoPgData.id = 3; infoPgData.version = PG_VERSION_96; infoPgData.systemId = 6399999999999999999; infoPgData.catalogVersion = 201608131; infoPgData.controlVersion = 960; TEST_RESULT_VOID(infoPgAdd(infoPg, &infoPgData), "infoPgAdd"); InfoPgData infoPgDataTest = infoPgDataCurrent(infoPg); TEST_RESULT_INT(infoPgDataTest.id, 3, " id set"); TEST_RESULT_INT(infoPgDataTest.version, PG_VERSION_96, " version set"); TEST_RESULT_INT(infoPgDataTest.systemId, 6399999999999999999, " system-id set"); TEST_RESULT_INT(infoPgDataTest.catalogVersion, 201608131, " catalog-version set"); TEST_RESULT_INT(infoPgDataTest.controlVersion, 960, " control-version set"); // Errors //-------------------------------------------------------------------------------------------------------------------------- TEST_ERROR(infoPgNewLoad(storageLocal(), fileName, 10, cipherTypeNone, NULL, NULL), AssertError, "invalid InfoPg type 10"); TEST_ERROR( infoPgNewLoad(storageLocal(), NULL, infoPgManifest, cipherTypeNone, NULL, NULL), AssertError, "assertion 'fileName != NULL' failed"); TEST_ERROR(infoPgDataCurrent(NULL), AssertError, "assertion 'this != NULL' failed"); TEST_ERROR(infoPgAdd(NULL, &infoPgData), AssertError, "assertion 'this != NULL' failed"); TEST_ERROR(infoPgAdd(infoPg, NULL), AssertError, "assertion 'infoPgData != NULL' failed"); // infoPgFree //-------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_VOID(infoPgFree(infoPg), "infoPgFree() - free infoPg"); // infoPgDataToLog //-------------------------------------------------------------------------------------------------------------------------- // test max values infoPgDataTest.id = (unsigned int)4294967295; infoPgDataTest.version = (unsigned int)4294967295; infoPgDataTest.systemId = 18446744073709551615U; infoPgDataTest.catalogVersion = (uint32_t)4294967295; infoPgDataTest.controlVersion = (uint32_t)4294967295; TEST_RESULT_STR( strPtr(infoPgDataToLog(&infoPgDataTest)), "{id: 4294967295, version: 4294967295, systemId: 18446744073709551615, catalogVersion: 4294967295, controlVersion:" " 4294967295}", " check max format"); } }
/*********************************************************************************************************************************** testBegin - should this test run? ***********************************************************************************************************************************/ bool testBegin(const char *name) { FUNCTION_HARNESS_BEGIN(); FUNCTION_HARNESS_PARAM(STRINGZ, name); FUNCTION_HARNESS_ASSERT(name != NULL); FUNCTION_HARNESS_END(); bool result = false; testRun++; if (testList[testRun - 1].selected) { if (testFirst) { // Set test user const char *testUserTemp = getpwuid(getuid())->pw_name; if (strlen(testUserTemp) > sizeof(testUserData) - 1) THROW_FMT(AssertError, "test user name must be less than %zu characters", sizeof(testUserData) - 1); strcpy(testUserData, testUserTemp); // Set test group const char *testGroupTemp = getgrgid(getgid())->gr_name; if (strlen(testGroupTemp) > sizeof(testGroupData) - 1) THROW_FMT(AssertError, "test group name must be less than %zu characters", sizeof(testGroupData) - 1); strcpy(testGroupData, testGroupTemp); } #ifndef NO_LOG if (!testFirst) { // Make sure there is nothing untested left in the log harnessLogFinal(); // Clear out the test directory so the next test starts clean char buffer[2048]; snprintf(buffer, sizeof(buffer), "sudo rm -rf %s/" "*", testPath()); if (system(buffer) != 0) { fprintf(stderr, "ERROR: unable to clear test path '%s'\n", testPath()); fflush(stderr); exit(255); } } #endif // No longer the first test testFirst = false; if (testRun != 1) printf("\n"); printf("run %03d - %s\n", testRun, name); fflush(stdout); timeMSecBegin = testTimeMSec(); #ifndef NO_LOG // Initialize logging harnessLogInit(); #endif result = true; } FUNCTION_HARNESS_RESULT(BOOL, result); }
/*********************************************************************************************************************************** Test run ***********************************************************************************************************************************/ void testRun(void) { FUNCTION_HARNESS_VOID(); // ***************************************************************************************************************************** if (testBegin("cfgLoadLogSetting()")) { cfgInit(); TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings all defaults"); TEST_RESULT_INT(logLevelStdOut, logLevelOff, "console logging is off"); TEST_RESULT_INT(logLevelStdErr, logLevelOff, "stderr logging is off"); TEST_RESULT_INT(logLevelFile, logLevelOff, "file logging is off"); TEST_RESULT_BOOL(logTimestamp, true, "timestamp logging is on"); // ------------------------------------------------------------------------------------------------------------------------- cfgInit(); cfgCommandSet(cfgCmdLocal); cfgOptionValidSet(cfgOptLogLevelConsole, true); cfgOptionSet(cfgOptLogLevelConsole, cfgSourceParam, varNewStrZ("info")); cfgOptionValidSet(cfgOptLogLevelStderr, true); cfgOptionSet(cfgOptLogLevelStderr, cfgSourceParam, varNewStrZ("error")); cfgOptionValidSet(cfgOptLogLevelFile, true); cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, varNewStrZ("debug")); cfgOptionValidSet(cfgOptLogTimestamp, true); cfgOptionSet(cfgOptLogTimestamp, cfgSourceParam, varNewBool(false)); TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings no defaults"); TEST_RESULT_INT(logLevelStdOut, logLevelInfo, "console logging is info"); TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error"); TEST_RESULT_INT(logLevelFile, logLevelDebug, "file logging is debugging"); TEST_RESULT_BOOL(logTimestamp, false, "timestamp logging is off"); // ------------------------------------------------------------------------------------------------------------------------- cfgInit(); cfgCommandSet(cfgCmdLocal); cfgOptionValidSet(cfgOptLogLevelStderr, true); cfgOptionSet(cfgOptLogLevelStderr, cfgSourceParam, varNewStrZ("info")); TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings reset stderr"); TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error"); } // ***************************************************************************************************************************** if (testBegin("cfgLoadUpdateOption()")) { String *exe = strNew("/path/to/pgbackrest"); String *exeOther = strNew("/other/path/to/pgbackrest"); cfgInit(); cfgCommandSet(cfgCmdBackup); cfgExeSet(exe); cfgOptionValidSet(cfgOptRepoHost, true); cfgOptionValidSet(cfgOptPgHost, true); TEST_RESULT_VOID(cfgLoadUpdateOption(), "hosts are not set so don't update commands"); cfgOptionSet(cfgOptRepoHost, cfgSourceParam, varNewStrZ("repo-host")); TEST_RESULT_VOID(cfgLoadUpdateOption(), "repo remote command is updated"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoHostCmd)), strPtr(exe), " check repo1-host-cmd"); cfgOptionSet(cfgOptRepoHostCmd, cfgSourceParam, varNewStr(exeOther)); TEST_RESULT_VOID(cfgLoadUpdateOption(), "repo remote command was already set"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoHostCmd)), strPtr(exeOther), " check repo1-host-cmd"); cfgOptionSet(cfgOptRepoHost, cfgSourceParam, NULL); // ------------------------------------------------------------------------------------------------------------------------- cfgOptionValidSet(cfgOptPgHostCmd, true); cfgOptionSet(cfgOptPgHost, cfgSourceParam, varNewStrZ("pg1-host")); cfgOptionValidSet(cfgOptPgHost + 1, true); cfgOptionSet(cfgOptPgHost + 1, cfgSourceParam, varNewStrZ("pg2-host")); cfgOptionValidSet(cfgOptPgHostCmd + 1, true); cfgOptionSet(cfgOptPgHostCmd + 1, cfgSourceParam, varNewStr(exeOther)); cfgOptionValidSet(cfgOptPgHost + cfgOptionIndexTotal(cfgOptPgHost) - 1, true); cfgOptionSet(cfgOptPgHost + cfgOptionIndexTotal(cfgOptPgHost) - 1, cfgSourceParam, varNewStrZ("pgX-host")); TEST_RESULT_VOID(cfgLoadUpdateOption(), "pg remote command is updated"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgHostCmd)), strPtr(exe), " check pg1-host-cmd"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgHostCmd + 1)), strPtr(exeOther), " check pg2-host-cmd is already set"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgHostCmd + 2)), NULL, " check pg3-host-cmd is not set"); TEST_RESULT_STR( strPtr(cfgOptionStr(cfgOptPgHostCmd + cfgOptionIndexTotal(cfgOptPgHost) - 1)), strPtr(exe), " check pgX-host-cmd"); // ------------------------------------------------------------------------------------------------------------------------- cfgInit(); cfgOptionValidSet(cfgOptDbTimeout, true); cfgOptionSet(cfgOptDbTimeout, cfgSourceParam, varNewDbl(100)); TEST_RESULT_VOID(cfgLoadUpdateOption(), "pg timeout set but not protocol timeout"); cfgOptionValidSet(cfgOptProtocolTimeout, true); cfgOptionSet(cfgOptProtocolTimeout, cfgSourceDefault, varNewDbl(101)); TEST_RESULT_VOID(cfgLoadUpdateOption(), "protocol timeout > pg timeout"); cfgOptionSet(cfgOptDbTimeout, cfgSourceParam, varNewDbl(100000)); TEST_RESULT_VOID(cfgLoadUpdateOption(), "protocol timeout set automatically"); TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 100030, " check protocol timeout"); cfgOptionValidSet(cfgOptProtocolTimeout, true); cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(50.5)); TEST_ERROR( cfgLoadUpdateOption(), OptionInvalidValueError, "'50.5' is not valid for 'protocol-timeout' option\n" "HINT 'protocol-timeout' option (50.5) should be greater than 'db-timeout' option (100000)."); cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(45)); cfgOptionSet(cfgOptDbTimeout, cfgSourceDefault, varNewDbl(3600)); TEST_RESULT_VOID(cfgLoadUpdateOption(), "set default pg timeout to be less than protocol timeout"); TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 45, " check protocol timeout"); TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 15, " check db timeout"); cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(11)); cfgOptionSet(cfgOptDbTimeout, cfgSourceDefault, varNewDbl(3600)); TEST_RESULT_VOID(cfgLoadUpdateOption(), "set default pg timeout to be less than test protocol timeout"); TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 11, " check protocol timeout"); TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 5.5, " check db timeout"); // ------------------------------------------------------------------------------------------------------------------------- cfgInit(); cfgCommandSet(cfgCmdBackup); cfgExeSet(exe); cfgOptionValidSet(cfgOptPgHost, true); TEST_RESULT_VOID(cfgLoadUpdateOption(), "only repo-host is valid"); cfgOptionValidSet(cfgOptRepoHost, true); cfgOptionSet(cfgOptRepoHost, cfgSourceParam, varNewStrZ("repo-host")); cfgOptionValidSet(cfgOptPgHost + 4, true); cfgOptionSet(cfgOptPgHost + 4, cfgSourceParam, varNewStrZ("pg5-host")); TEST_ERROR(cfgLoadUpdateOption(), ConfigError, "pg and repo hosts cannot both be configured as remote"); // ------------------------------------------------------------------------------------------------------------------------- StringList *argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("help")); strLstAdd(argList, strNew("backup")); strLstAdd(argList, strNew("process-max")); harnessLogLevelSet(logLevelWarn); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load help config -- no retention warning"); TEST_RESULT_BOOL(cfgCommandHelp(), true, " command is help"); argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--no-log-timestamp")); strLstAdd(argList, strNew("expire")); harnessLogLevelSet(logLevelWarn); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning"); harnessLogResult( "P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n" " HINT: to retain full backups indefinitely (without warning), set option" " 'repo1-retention-full' to the maximum."); TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set"); strLstAdd(argList, strNew("--repo1-retention-full=1")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config no retention warning"); TEST_RESULT_INT(cfgOptionInt(cfgOptRepoRetentionArchive), 1, " repo1-retention-archive set"); // Munge repo-type for coverage. This will go away when there are multiple repos. cfgOptionSet(cfgOptRepoType, cfgSourceParam, NULL); TEST_RESULT_VOID(cfgLoadUpdateOption(), "load config no repo-type"); argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--no-log-timestamp")); strLstAdd(argList, strNew("--repo1-retention-archive-type=incr")); strLstAdd(argList, strNew("expire")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning"); harnessLogResult( "P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n" " HINT: to retain full backups indefinitely (without warning), set option 'repo1-retention-full'" " to the maximum.\n" "P00 WARN: WAL segments will not be expired: option 'repo1-retention-archive-type=incr' but option" " 'repo1-retention-archive' is not set"); TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set"); argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--no-log-timestamp")); strLstAdd(argList, strNew("--repo1-retention-archive-type=diff")); strLstAdd(argList, strNew("expire")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning"); harnessLogResult( "P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n" " HINT: to retain full backups indefinitely (without warning), set option" " 'repo1-retention-full' to the maximum.\n" "P00 WARN: WAL segments will not be expired: option 'repo1-retention-archive-type=diff' but neither option" " 'repo1-retention-archive' nor option 'repo1-retention-diff' is set"); TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set"); strLstAdd(argList, strNew("--repo1-retention-diff=2")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning"); harnessLogResult( "P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n" " HINT: to retain full backups indefinitely (without warning), set option" " 'repo1-retention-full' to the maximum."); TEST_RESULT_INT(cfgOptionInt(cfgOptRepoRetentionArchive), 2, " repo1-retention-archive set to retention-diff"); argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--no-log-timestamp")); strLstAdd(argList, strNew("--repo1-retention-archive-type=diff")); strLstAdd(argList, strNew("--repo1-retention-archive=3")); strLstAdd(argList, strNew("--repo1-retention-full=1")); strLstAdd(argList, strNew("expire")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning"); harnessLogResult( "P00 WARN: option 'repo1-retention-diff' is not set for 'repo1-retention-archive-type=diff'\n" " HINT: to retain differential backups indefinitely (without warning), set option 'repo1-retention-diff'" " to the maximum."); // ------------------------------------------------------------------------------------------------------------------------- setenv("PGBACKREST_REPO1_S3_KEY", "mykey", true); setenv("PGBACKREST_REPO1_S3_KEY_SECRET", "mysecretkey", true); // Invalid bucket name with verification enabled fails argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--repo1-type=s3")); strLstAdd(argList, strNew("--repo1-s3-bucket=bogus.bucket")); strLstAdd(argList, strNew("--repo1-s3-region=region")); strLstAdd(argList, strNew("--repo1-s3-endpoint=endpoint")); strLstAdd(argList, strNew("--repo1-path=/repo")); strLstAdd(argList, strNew("archive-get")); TEST_ERROR( harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), OptionInvalidValueError, "'bogus.bucket' is not valid for option 'repo1-s3-bucket'" "\nHINT: RFC-2818 forbids dots in wildcard matches" "\nHINT: TLS/SSL verification cannot proceed with this bucket name" "\nHINT: remove dots from the bucket name"); // Invalid bucket name with verification disabled succeeds argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--repo1-type=s3")); strLstAdd(argList, strNew("--repo1-s3-bucket=bogus.bucket")); strLstAdd(argList, strNew("--repo1-s3-region=region")); strLstAdd(argList, strNew("--repo1-s3-endpoint=endpoint")); strLstAdd(argList, strNew("--no-repo1-s3-verify-ssl")); strLstAdd(argList, strNew("--repo1-path=/repo")); strLstAdd(argList, strNew("archive-get")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "invalid bucket with no verification"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoS3Bucket)), "bogus.bucket", " check bucket value"); // Valid bucket name argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--repo1-type=s3")); strLstAdd(argList, strNew("--repo1-s3-bucket=cool-bucket")); strLstAdd(argList, strNew("--repo1-s3-region=region")); strLstAdd(argList, strNew("--repo1-s3-endpoint=endpoint")); strLstAdd(argList, strNew("--repo1-path=/repo")); strLstAdd(argList, strNew("archive-get")); TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "valid bucket name"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoS3Bucket)), "cool-bucket", " check bucket value"); unsetenv("PGBACKREST_REPO1_S3_KEY"); unsetenv("PGBACKREST_REPO1_S3_KEY_SECRET"); } // ***************************************************************************************************************************** if (testBegin("cfgLoadLogFile()")) { cfgInit(); cfgOptionValidSet(cfgOptLogLevelFile, true); cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, varNewStrZ("detail")); // On the error case is tested here, success is tested in cfgLoad() TEST_RESULT_VOID(cfgLoadLogFile(strNew("/BOGUS")), "attempt to open bogus log file"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptLogLevelFile)), "off", "log-level-file should now be off"); } // ***************************************************************************************************************************** if (testBegin("cfgLoad()")) { // Command does not have umask // ------------------------------------------------------------------------------------------------------------------------- StringList *argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("info")); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config and don't set umask"); // Set a distinct umask value and test that the umask is reset by configLoad since default for neutral-umask=y // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--log-level-console=off")); strLstAdd(argList, strNew("--log-level-stderr=off")); strLstAdd(argList, strNew("--log-level-file=off")); strLstAdd(argList, strNew("archive-get")); umask(0111); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for neutral-umask"); TEST_RESULT_INT(umask(0111), 0000, " umask was reset"); // Set a distinct umask value and test that the umask is not reset by configLoad with option --no-neutral-umask // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--no-neutral-umask")); strLstAdd(argList, strNew("--log-level-console=off")); strLstAdd(argList, strNew("--log-level-stderr=off")); strLstAdd(argList, strNew("--log-level-file=off")); strLstAdd(argList, strNew("archive-get")); umask(0111); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for no-neutral-umask"); TEST_RESULT_INT(umask(0), 0111, " umask was not reset"); // No command // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "no command"); // Help command only // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("help")); ioBufferSizeSet(333); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "help command"); TEST_RESULT_SIZE(ioBufferSize(), 333, "buffer size not updated by help command"); // Help command for backup // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("help")); strLstAdd(argList, strNew("backup")); strLstAdd(argList, strNew("--log-level-console=off")); strLstAdd(argList, strNew("--log-level-stderr=off")); strLstAdd(argList, strNew("--log-level-file=off")); strLstAdd(argList, strNew("--repo1-retention-full=2")); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "help command for backup"); TEST_RESULT_SIZE(ioBufferSize(), 4 * 1024 * 1024, "buffer size set to option default"); // Command takes lock and opens log file // ------------------------------------------------------------------------------------------------------------------------- struct stat statLog; argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--pg1-path=/path")); strLstAdd(argList, strNew("--repo1-retention-full=1")); strLstAdd(argList, strNewFmt("--log-path=%s", testPath())); strLstAdd(argList, strNew("--log-level-console=off")); strLstAdd(argList, strNew("--log-level-stderr=off")); strLstAdd(argList, strNew("--log-level-file=warn")); strLstAdd(argList, strNew("backup")); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "lock and open log file"); TEST_RESULT_INT(lstat(strPtr(strNewFmt("%s/db-backup.log", testPath())), &statLog), 0, " check log file exists"); // Local command opens log file with special filename // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew("--command=backup")); strLstAdd(argList, strNewFmt("--log-path=%s", testPath())); strLstAdd(argList, strNew("--process=1")); strLstAdd(argList, strNew("--host-id=1")); strLstAdd(argList, strNew("--type=backup")); strLstAdd(argList, strNew("--log-level-file=warn")); strLstAdd(argList, strNew("local")); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "open log file"); TEST_RESULT_INT( lstat(strPtr(strNewFmt("%s/db-backup-local-001.log", testPath())), &statLog), 0, " check log file exists"); // Remote command opens log file with special filename // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); strLstAdd(argList, strNew("--command=backup")); strLstAdd(argList, strNewFmt("--log-path=%s", testPath())); strLstAdd(argList, strNew("--type=backup")); strLstAdd(argList, strNew("--log-level-file=warn")); strLstAdd(argList, strNew("--process=0")); strLstAdd(argList, strNew("remote")); TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "open log file"); TEST_RESULT_INT( lstat(strPtr(strNewFmt("%s/all-backup-remote-000.log", testPath())), &statLog), 0, " check log file exists"); } FUNCTION_HARNESS_RESULT_VOID(); }
int main(int argc, char* argv[]) { ScopedXPCOM xpcom("NtPathToDosPath"); if (xpcom.failed()) { fail("XPCOM Startup"); return 1; } nsAutoString cDrive; if (!DriveToNtPath(L'C', cDrive)) { fail("Querying for this machine's C:"); return 1; } int result = 0; // empty string if (!TestNtPathToDosPath(L"", L"")) { fail("Empty string"); result = 1; } // non-existent device, must fail if (TestNtPathToDosPath(L"\\Device\\ThisDeviceDoesNotExist\\Foo", nullptr)) { fail("Non-existent device"); result = 1; } // base case nsAutoString testPath(cDrive); testPath.Append(L"\\Foo"); if (!TestNtPathToDosPath(testPath.get(), L"C:\\Foo")) { fail("Base case"); result = 1; } // drive letters as symbolic links (NtCreateFile uses these) if (!TestNtPathToDosPath(L"\\??\\C:\\Foo", L"C:\\Foo")) { fail("Path specified as symbolic link"); result = 1; } // other symbolic links (should fail) if (TestNtPathToDosPath(L"\\??\\MountPointManager", nullptr)) { fail("Other symbolic link"); result = 1; } // socket (should fail) if (TestNtPathToDosPath(L"\\Device\\Afd\\Endpoint", nullptr)) { fail("Socket"); result = 1; } // currently UNC paths that are not mapped to drive letters are unsupported, // so this should fail if (TestNtPathToDosPath(L"\\Device\\Mup\\127.0.0.1\\C$", nullptr)) { fail("Unmapped UNC path"); result = 1; } DriveMapping drvMapping(NS_LITERAL_STRING("\\\\127.0.0.1\\C$")); // Only run these tests if we were able to map; some machines don't have perms if (drvMapping.Init()) { wchar_t expected[] = L" :\\"; expected[0] = drvMapping.GetDriveLetter(); nsAutoString networkPath; if (!DriveToNtPath(drvMapping.GetDriveLetter(), networkPath)) { fail("Querying network drive"); return 1; } networkPath += L"\\"; if (!TestNtPathToDosPath(networkPath.get(), expected)) { fail("Mapped UNC path"); result = 1; } // NtPathToDosPath must correctly handle paths whose drive letter mapping has // changed. We need to test this because the APIs called by NtPathToDosPath // return different info if this has happened. if (!drvMapping.ChangeDriveLetter()) { fail("Change drive letter"); return 1; } expected[0] = drvMapping.GetDriveLetter(); if (!DriveToNtPath(drvMapping.GetDriveLetter(), networkPath)) { fail("Querying second network drive"); return 1; } networkPath += L"\\"; if (!TestNtPathToDosPath(networkPath.get(), expected)) { fail("Re-mapped UNC path"); result = 1; } } return result; }