-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_FilePathUtils.cxx
More file actions
111 lines (79 loc) · 3.67 KB
/
test_FilePathUtils.cxx
File metadata and controls
111 lines (79 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019-2022 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \author Gvozden Nešković, Frankfurt Institute for Advanced Studies and Goethe University Frankfurt
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE "Common"
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <boost/range.hpp>
#include <iostream>
#include <memory>
#include "FilePathUtils.h"
using namespace o2::DataDistribution;
using namespace std::string_literals;
using namespace boost::filesystem;
//____________________________________________________________________________//
struct MySetup {
MySetup()
{
mTmpPath = unique_path();
std::cout << "Global setup: Creting temp directory: " << mTmpPath.string() << '\n';
if (!create_directory(mTmpPath)) {
throw std::runtime_error("Can not create directory"s + mTmpPath.string());
}
}
~MySetup()
{
std::cout << "Global teardown: Deleting temp directory and its contents" << std::endl;
remove_all(mTmpPath);
}
static path mTmpPath;
};
path MySetup::mTmpPath;
//____________________________________________________________________________//
BOOST_GLOBAL_FIXTURE(MySetup);
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE(GetNextSeqNameTest)
{
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "0"s);
// create some dirs
create_directory(MySetup::mTmpPath / "dir");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "0"s);
create_directory(MySetup::mTmpPath / "dir0");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "dir1"s);
create_directory(MySetup::mTmpPath / "dir9");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "dir10"s);
create_directory(MySetup::mTmpPath / "dir09");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "dir10"s);
create_directory(MySetup::mTmpPath / "dir0009");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "dir0010"s);
create_directory(MySetup::mTmpPath / "dir0012.data");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "dir0013.data"s);
create_directory(MySetup::mTmpPath / "0013.data");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "0014.data"s);
create_directory(MySetup::mTmpPath / "-000014.data");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "-000015.data"s);
create_directory(MySetup::mTmpPath / "000015");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "000016"s);
}
BOOST_AUTO_TEST_CASE(GetNextSeqNameTest_noMatch)
{
// remove all tests
for (auto& entry : boost::make_iterator_range(directory_iterator(MySetup::mTmpPath), {}))
remove_all(entry.path());
// create some dirs
create_directory(MySetup::mTmpPath / "dir");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "0"s);
create_directory(MySetup::mTmpPath / "-");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "0"s);
create_directory(MySetup::mTmpPath / "00005");
BOOST_CHECK(FilePathUtils::getNextSeqName(MySetup::mTmpPath.string()) == "00006"s);
}