#pragma warning(disable:4800) #include "tests_macros.h" #include "DConsole.h" #include "DStringUtils.h" #include "Providers/DMySQLDataProvider.h" #include "Model/DDirectory.h" #include "DWorkUtils.h" #include "DStopWatch.h" using namespace std; using namespace ccdb; /********************************************************************* ** * @brief Test of directories work * * @return true if test passed */ bool test_DMySQLDataProviderDirectories() { TESTS_INIT("") DMySQLDataProvider *prov = new DMySQLDataProvider(); if(!prov->Connect(gConnectionString)) return false; //Directories gConsole.WriteLine(DConsole::cBrightWhite, "\n[ Directories testing ]"); //List of directories gConsole.Write(DConsole::cBrightCyan, "\nCheck list of directories"); PrintDirectoryTree(prov->GetRootDirectory(), false); gConsole.WriteLine(); //get directory by path TITLE("Get Directory by path "); DDirectory *dir=prov->GetDirectory("/test/subtest"); TEST(dir!=NULL); //Search directories by pattern TITLE("Search directory by parent in parent "); vector dirs = prov->SearchDirectories(static_cast("t??t_va*"), "/test"); TEST_STEP(dirs.size()>0); //Ok, lets check if directory for the next text exists... if(dir=prov->GetDirectory("/test/testdir")) { delete dir; //ok we havent test it, but have to use it... prov->DeleteDirectory("/test/testdir"); } //Create test directory structure TITLE("MakeDirectory"); TEST(prov->MakeDirectory("testdir", "/test")); //create subdirectory TITLE("Create SubDirectory 1"); TEST(prov->MakeDirectory("constants","/test/testdir","My constants")); //refuse to create existing directory TITLE("Refuse to create existing directory"); TEST(!prov->MakeDirectory("constants","/test/testdir","My constants")); //create subdirectory TITLE("Create second subdirectory"); TEST(prov->MakeDirectory("variables","/test/testdir","")); //create third subdirectory TITLE("Create third subdirectory"); TEST(prov->MakeDirectory("my_vars","/test/testdir","")); //list what we have gConsole.Write(DConsole::cBrightCyan,"\nCheck list of directories"); PrintDirectoryTree(prov->GetRootDirectory(), false); gConsole.WriteLine(); TITLE("Delete subdirectory"); TEST(prov->DeleteDirectory("/test/testdir/constants")); TITLE("Delete non emty directory prohibit"); TEST(!prov->DeleteDirectory("/test/testdir")); TITLE("Delete subdirectory 2"); TEST(prov->DeleteDirectory("/test/testdir/my_vars")); TITLE("Delete subdirectory 3"); TEST(prov->DeleteDirectory("/test/testdir/variables")); TITLE("Delete subdirectory 4"); TEST(prov->DeleteDirectory("/test/testdir")); gConsole.Write(DConsole::cBrightCyan,"\nCheck list of directories"); PrintDirectoryTree(prov->GetRootDirectory(), false); gConsole.WriteLine(); return true; }