Пример #1
0
int main()
{
	std::string dir_name = "/tmp/1/1/1";
	native_dir dir(dir_name);
	assert(!dir.exist());
	assert(!dir.create_dir(false));
	assert(dir.create_dir(true));

	printf("press a key to continue the test of delete function.\n");
	getchar();
	native_dir dir2("/tmp/1");
	assert(!dir2.delete_dir(false));
	assert(dir2.delete_dir(true));

	dir_name = "1/1/1";
	native_dir dir3(dir_name);
	assert(!dir3.exist());
	assert(!dir3.create_dir(false));
	assert(dir3.create_dir(true));

	printf("press a key to continue the test of delete function.\n");
	getchar();
	native_dir dir4("1");
	assert(!dir4.delete_dir(false));
	assert(dir4.delete_dir(true));
}
    void TestQueueRemovesAndCreatesDirectories() throw (Exception)
    {
        FileFinder checkpoints("checkpoints2", RelativeTo::ChasteTestOutput);
        // Remove directory in case it was there from previous executions.
        PetscTools::Barrier("TestQueueRemovesAndCreatesDirectories-0");
        if (PetscTools::AmMaster())
        {
            ABORT_IF_THROWS(checkpoints.Remove());
        }
        PetscTools::Barrier("TestQueueRemovesAndCreatesDirectories-1");
        TS_ASSERT(!checkpoints.Exists());
        PetscTools::Barrier("TestQueueRemovesAndCreatesDirectories-2");

        OutputDirectoryFifoQueue fifo_queue("checkpoints2", 2);
        TS_ASSERT(checkpoints.IsDir());

        fifo_queue.CreateNextDir("0.1");
        FileFinder dir1("0.1", checkpoints);
        TS_ASSERT(dir1.IsDir());

        fifo_queue.CreateNextDir("0.2");
        FileFinder dir2("0.2", checkpoints);
        TS_ASSERT(dir2.IsDir());
        TS_ASSERT(dir1.IsDir());

        PetscTools::Barrier("TestQueueRemovesAndCreatesDirectories-3");
        fifo_queue.CreateNextDir("0.3");
        FileFinder dir3("0.3", checkpoints);
        TS_ASSERT(dir3.IsDir());
        TS_ASSERT(dir2.IsDir());
        TS_ASSERT(!dir1.Exists());

        PetscTools::Barrier("TestQueueRemovesAndCreatesDirectories-4");
        fifo_queue.CreateNextDir("0.4");
        FileFinder dir4("0.4", checkpoints);
        TS_ASSERT(dir4.IsDir());
        TS_ASSERT(dir3.IsDir());
        TS_ASSERT(!dir2.Exists());
        TS_ASSERT(!dir1.Exists());
    }
Пример #3
0
char tileray::dir_symbol (char sym)
{
    switch (sym)
    {
    case 'j':
        switch (dir4())
        {
        default:
        case 0: return 'h';
        case 1: return 'j';
        case 2: return 'h';
        case 3: return 'j';
        }
    case 'h':
        switch (dir4())
        {
        default:
        case 0: return 'j';
        case 1: return 'h';
        case 2: return 'j';
        case 3: return 'h';
        }
    case 'y':
        switch (dir4())
        {
        default:
        case 0: return 'u';
        case 1: return 'n';
        case 2: return 'b';
        case 3: return 'y';
        }
    case 'u':
        switch (dir4())
        {
        default:
        case 0: return 'n';
        case 1: return 'b';
        case 2: return 'y';
        case 3: return 'u';
        }
    case 'n':
        switch (dir4())
        {
        default:
        case 0: return 'b';
        case 1: return 'y';
        case 2: return 'u';
        case 3: return 'n';
        }
    case 'b':
        switch (dir4())
        {
        default:
        case 0: return 'y';
        case 1: return 'u';
        case 2: return 'n';
        case 3: return 'b';
        }
    case '^':
        switch (dir4())
        {
        default:
        case 0: return '>';
        case 1: return 'v';
        case 2: return '<';
        case 3: return '^';
        }
    case '[':
        switch (dir4())
        {
        default:
        case 0: return '-';
        case 1: return '[';
        case 2: return '-';
        case 3: return '[';
        }
    case ']':
        switch (dir4())
        {
        default:
        case 0: return '-';
        case 1: return ']';
        case 2: return '-';
        case 3: return ']';
        }
    case '|':
        switch (dir4())
        {
        default:
        case 0: return '-';
        case 1: return '|';
        case 2: return '-';
        case 3: return '|';
        }
    case '-':
        switch (dir4())
        {
        default:
        case 0: return '|';
        case 1: return '-';
        case 2: return '|';
        case 3: return '-';
        }
    case '=':
        switch (dir4())
        {
        default:
        case 0: return 'H';
        case 1: return '=';
        case 2: return 'H';
        case 3: return '=';
        }
    case 'H':
        switch (dir4())
        {
        default:
        case 0: return '=';
        case 1: return 'H';
        case 2: return '=';
        case 3: return 'H';
        }
    case '\\':
        switch (dir4())
        {
        default:
        case 0: return '/';
        case 1: return '\\';
        case 2: return '/';
        case 3: return '\\';
        }
    case '/':
        switch (dir4())
        {
        default:
        case 0: return '\\';
        case 1: return '/';
        case 2: return '\\';
        case 3: return '/';
        }
    default:;
    }
    return sym;
}
Пример #4
0
void TsDataAccessorFile::testGetFoldersList()
{
  // Valid folders
  QTemporaryDir dir(QDir::tempPath() + QString::fromStdString("/2016"));

  QTemporaryDir subdir1(dir.path() + QString::fromStdString("/10"));
  QTemporaryDir subdir2(dir.path() + QString::fromStdString("/11"));
  QTemporaryDir subdir3(dir.path() + QString::fromStdString("/12"));

  QTemporaryDir subdir4(subdir1.path() + QString::fromStdString("/03"));
  QTemporaryDir subdir5(subdir3.path() + QString::fromStdString("/11"));

  QTemporaryDir subdir6(subdir4.path() + QString::fromStdString("/final"));
  QTemporaryDir subdir7(subdir4.path() + QString::fromStdString("/final"));

  QTemporaryDir subdir8(subdir5.path() + QString::fromStdString("/final"));

  // Invalid folders

  QTemporaryDir dir2(QDir::tempPath() + QString::fromStdString("/2016"));

  QTemporaryDir subdir9(dir2.path() + QString::fromStdString("/03"));
  QTemporaryDir subdir10(subdir9.path() + QString::fromStdString("/aa"));

  QTemporaryDir dir3(QDir::tempPath() + QString::fromStdString("/2020"));
  QTemporaryDir dir4(QDir::tempPath() + QString::fromStdString("/folder"));

  terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
  terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);

  terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
  terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);

  TestDataAccessorFile da(dataProviderPtr, dataSeriesPtr);

  std::vector<std::string> fileList;

  fileList.push_back(QDir::tempPath().toStdString());

  {
    auto foldersList = da.getFoldersList(fileList, "/%YYYY*/%MM*/%DD*/final*");

    if(foldersList.size() < 3)
      QFAIL("Wrong number of folders matched!");
  }

  {
    auto foldersList = da.getFoldersList(fileList, "%YYYY*/%MM*/%DD*/final*");

    if(foldersList.size() < 3)
      QFAIL("Wrong number of folders matched!");
  }

  // empty mask
  {
    auto foldersList = da.getFoldersList(fileList, "");

    if(foldersList.size() != 1)
      QFAIL("Wrong number of folders matched!");
  }

  // considered as empty mask
  {
    auto foldersList = da.getFoldersList(fileList, "/");

    if(foldersList.size() != 1)
      QFAIL("Wrong number of folders matched!");
  }

  // considered as empty mask
  {
    auto foldersList = da.getFoldersList(fileList, "//");

    if(foldersList.size() != 1)
      QFAIL("Wrong number of folders matched!");
  }

  // ignore the extras '/'
  {
    auto foldersList = da.getFoldersList(fileList, "%YYYY*//%MM*/%DD*//final*");

    if(foldersList.size() < 3)
      QFAIL("Wrong number of folders matched!");
  }

  // the folders doesn't match
  {
    auto foldersList = da.getFoldersList(fileList, "%YYYY*/nonexistent/%DD*");

    if(!foldersList.empty())
      QFAIL("Wrong number of folders matched!");
  }
}
Пример #5
0
void TsDataAccessorFile::testGetFilesList()
{
  // Valid folders
  QTemporaryDir dir(QDir::tempPath() + QString::fromStdString("/2016"));

  QTemporaryDir subdir1(dir.path() + QString::fromStdString("/10"));
  QTemporaryDir subdir2(dir.path() + QString::fromStdString("/11"));
  QTemporaryDir subdir3(dir.path() + QString::fromStdString("/12"));

  QTemporaryDir subdir4(subdir1.path() + QString::fromStdString("/03"));
  QTemporaryDir subdir5(subdir3.path() + QString::fromStdString("/11"));

  QTemporaryDir subdir6(subdir2.path() + QString::fromStdString("/final"));
  QTemporaryDir subdir7(subdir4.path() + QString::fromStdString("/final"));

  QTemporaryDir subdir8(subdir5.path() + QString::fromStdString("/final"));

  // Invalid folders

  QTemporaryDir subdir9(dir.path() + QString::fromStdString("/03"));
  QTemporaryDir subdir10(subdir9.path() + QString::fromStdString("/aa"));

  QTemporaryDir dir3(QDir::tempPath() + QString::fromStdString("/2020"));
  QTemporaryDir dir4(QDir::tempPath() + QString::fromStdString("/folder"));

  terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
  terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);

  terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries();
  terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries);

  TestDataAccessorFile da(dataProviderPtr, dataSeriesPtr);

  std::vector<std::string> baseDirList;

  baseDirList.push_back(QDir::tempPath().toStdString());

  QTemporaryFile file1(subdir7.path() + QString::fromStdString("/file_2017_06_01_14:40_XXXXXX.file"));
  QTemporaryFile file2(subdir7.path() + QString::fromStdString("/file_2017_06_01_14:41_XXXXXX.file"));
  QTemporaryFile file3(subdir8.path() + QString::fromStdString("/file_2017_06_02_12:00_XXXXXX.file"));

  file1.open();
  file2.open();
  file3.open();

  {
    std::string fileMask = "file_%YYYY_%MM_%DD_%hh:%mm_*.file";
    std::string foldermask = "/%YYYY*/%MM*/%DD*/final*/";

    terrama2::core::Filter filter;
    std::string timezone = "03";
    auto remover = std::make_shared<terrama2::core::FileRemover>();

    QFileInfoList fileList;

    for(auto& baseDir : baseDirList)
      fileList.append(da.getFilesList(baseDir, fileMask, foldermask, filter, timezone, remover));

    if(fileList.size() < 3)
      QFAIL("Wrong number of folders matched!");
  }

}