Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,19 @@ namespace Test
std::cout << " -e=test - exclude test filter." << std::endl << std::endl;
std::cout << " -ll=1 - a log level." << std::endl << std::endl;
std::cout << " -lf=test.log - a log file name." << std::endl << std::endl;
std::cout << " -o=out - an output folder for test artifacts." << std::endl << std::endl;
std::cout << " -h or -? - to print this help message." << std::endl << std::endl;
return 0;
}

int MakeTests(const Groups& groups, const Options& options)
{
if (!Cpl::CreatePath(options.output))
{
CPL_LOG_SS(Error, "Can't create output folder '" << options.output << "' !");
return 1;
}

for (size_t t = 0; t < groups.size(); ++t)
{
const Group& group = groups[t];
Expand Down
1 change: 1 addition & 0 deletions src/Test/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "Cpl/Defs.h"
#include "Cpl/Args.h"
#include "Cpl/File.h"
#include "Cpl/Log.h"
#include "Cpl/Performance.h"

Expand Down
127 changes: 53 additions & 74 deletions src/Test/TestFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern "C" {
/* Test file hierarchy

FOR LINUX:
----/tmp/cpl/1
----<output>/cpl/1
/2
f 22222.js
/zero0
Expand All @@ -67,79 +67,58 @@ namespace Test
return a + '\\' + b;
#endif
}
#ifdef __linux__
static const std::string testPath = "/tmp/cpl";
#elif _WIN32
static const std::string testPath = ".\\cpl";
#endif
static std::string testPath;
static const std::string testString = "123456789876543210";

const static std::set<std::string> all_folders = [](){
std::set<std::string> temp;
temp.insert(joinPath(testPath, "1"));
temp.insert(joinPath(testPath, "2"));
temp.insert(joinPath(testPath, "zero0"));
temp.insert(joinPath(testPath, joinPath("zero0", "test")));
return temp;
}();

const static std::set<std::string> not_exist_folders = [](){
std::set<std::string> temp;
temp.insert(joinPath(testPath, "999"));
temp.insert(joinPath(testPath, joinPath("zxcb", "999")));
temp.insert(joinPath(testPath, "8"));
return temp;
}();

const static std::set<std::string> existance_files = [](){
std::set<std::string> temp;
temp.insert(joinPath(testPath, "emptyFile.js"));
temp.insert(joinPath(testPath, joinPath("2", "22222.js")));
temp.insert(joinPath(testPath, "notempty.txt"));
temp.insert(joinPath(testPath, "notemptyx2"));
return temp;
}();

const static std::set<std::string> not_existance_files = [](){
std::set<std::string> temp;
temp.insert(joinPath(testPath, "bemptyFile.js"));
temp.insert(joinPath(testPath, joinPath("2", "b22222.js")));
temp.insert(joinPath(testPath, "bnotempty.txt"));
temp.insert(joinPath(testPath, "bnotemptyx2"));
return temp;
}();

const static std::set<std::string> empty_files = [](){
std::set<std::string> temp;
temp.insert(joinPath(testPath, "emptyFile.js"));
temp.insert(joinPath(testPath, joinPath("2", "22222.js")));
return temp;
}();

//Every file have at least test string testString
const static std::vector<std::pair<std::string, size_t>> not_empty_files = [](){
std::vector<std::pair<std::string, size_t>> temp;
temp.push_back({joinPath(testPath, "notempty.txt"), testString.size()});
temp.push_back({joinPath(testPath, "notemptyx2"), 2*testString.size()});
return temp;
}();

bool initializeTree() {
#ifdef __linux__
auto p = mkdir(testPath.c_str(), 0777);
p |= mkdir(joinPath(testPath, "1").c_str(), 0777);
p |= mkdir(joinPath(testPath, "2").c_str(), 0777);
p |= mkdir(joinPath(testPath, "zero0").c_str(), 0777);
p |= mkdir(joinPath(testPath, joinPath("zero0", "test")).c_str(), 0777);
#elif _WIN32
auto p = _mkdir(testPath.c_str());
p |= _mkdir(joinPath(testPath, "1").c_str());
p |= _mkdir(joinPath(testPath, "2").c_str());
p |= _mkdir(joinPath(testPath, "zero0").c_str());
p |= _mkdir(joinPath(testPath, joinPath("zero0", "test")).c_str());
#endif
static std::set<std::string> all_folders;
static std::set<std::string> not_exist_folders;
static std::set<std::string> existance_files;
static std::set<std::string> not_existance_files;
static std::set<std::string> empty_files;
static std::vector<std::pair<std::string, size_t>> not_empty_files;

void initTestPaths(const Options& options)
{
testPath = options.OutputPath("cpl");

all_folders.clear();
all_folders.insert(joinPath(testPath, "1"));
all_folders.insert(joinPath(testPath, "2"));
all_folders.insert(joinPath(testPath, "zero0"));
all_folders.insert(joinPath(testPath, joinPath("zero0", "test")));

not_exist_folders.clear();
not_exist_folders.insert(joinPath(testPath, "999"));
not_exist_folders.insert(joinPath(testPath, joinPath("zxcb", "999")));
not_exist_folders.insert(joinPath(testPath, "8"));

existance_files.clear();
existance_files.insert(joinPath(testPath, "emptyFile.js"));
existance_files.insert(joinPath(testPath, joinPath("2", "22222.js")));
existance_files.insert(joinPath(testPath, "notempty.txt"));
existance_files.insert(joinPath(testPath, "notemptyx2"));

not_existance_files.clear();
not_existance_files.insert(joinPath(testPath, "bemptyFile.js"));
not_existance_files.insert(joinPath(testPath, joinPath("2", "b22222.js")));
not_existance_files.insert(joinPath(testPath, "bnotempty.txt"));
not_existance_files.insert(joinPath(testPath, "bnotemptyx2"));

empty_files.clear();
empty_files.insert(joinPath(testPath, "emptyFile.js"));
empty_files.insert(joinPath(testPath, joinPath("2", "22222.js")));

not_empty_files.clear();
not_empty_files.push_back({joinPath(testPath, "notempty.txt"), testString.size()});
not_empty_files.push_back({joinPath(testPath, "notemptyx2"), 2*testString.size()});
}

bool initializeTree(const Options& options) {
initTestPaths(options);

if (p)
if (!Cpl::CreatePath(joinPath(testPath, "1")) ||
!Cpl::CreatePath(joinPath(testPath, "2")) ||
!Cpl::CreatePath(joinPath(testPath, joinPath("zero0", "test"))))
return false;

std::ofstream f1(joinPath(testPath, "emptyFile.js"));
Expand Down Expand Up @@ -827,7 +806,7 @@ namespace Test
CPL_LOG_SS(Info, "Filesystem " << Cpl::FilesystemType());
CPL_LOG_SS(Info, "Compiler type " << Cpl::CompilerType());

initializeTree();
initializeTree(options);
ok &= COMPARE_RESULT(Modify::folders(), 1);
ok &= COMPARE_RESULT(Modify::createFiles(), 1);
ok &= COMPARE_RESULT(Modify::readFormatsTest(), 1);
Expand All @@ -846,7 +825,7 @@ namespace Test
CPL_LOG_SS(Info, "Filesystem " << Cpl::FilesystemType());
CPL_LOG_SS(Info, "Compiler type " << Cpl::CompilerType());

initializeTree();
initializeTree(options);
ok &= COMPARE_RESULT(Existance::testFileExists(), 1);
ok &= COMPARE_RESULT(Existance::testFolderExists(), 1);

Expand All @@ -864,7 +843,7 @@ namespace Test
CPL_LOG_SS(Info, "Filesystem " << Cpl::FilesystemType());
CPL_LOG_SS(Info, "Compiler type " << Cpl::CompilerType());

initializeTree();
initializeTree(options);
ok &= COMPARE_RESULT(Info::fileList(), 1);
ok &= COMPARE_RESULT(Info::naming(), 1);
ok &= COMPARE_RESULT(Info::extension(), 1);
Expand Down
8 changes: 4 additions & 4 deletions src/Test/TestLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Test

bool LogCallbackTest(const Options& options)
{
std::ofstream ofs("custom_log.txt");
std::ofstream ofs(options.OutputPath("custom_log.txt"));
int id = Cpl::Log::Global().AddWriter(Log::Debug, CustomFileWriter, &ofs);

CPL_LOG(Debug, "debug log message");
Expand All @@ -59,7 +59,7 @@ namespace Test

bool LogCallbackRawTest(const Options& options)
{
std::ofstream ofs("custom_raw_log.txt");
std::ofstream ofs(options.OutputPath("custom_raw_log.txt"));
int id = Cpl::Log::Global().AddWriter(Log::Debug, CustomRawFileWriter, &ofs);

CPL_LOG(Debug, "raw debug log message");
Expand Down Expand Up @@ -98,10 +98,10 @@ namespace Test

bool LogIdTest(const Options& options)
{
std::ofstream ofs1("log_1.txt");
std::ofstream ofs1(options.OutputPath("log_1.txt"));
int id1 = Cpl::Log::Global().AddWriter(Log::Debug, CustomFileWriter, &ofs1);

std::ofstream ofs2("log_2.txt");
std::ofstream ofs2(options.OutputPath("log_2.txt"));
int id2 = Cpl::Log::Global().AddWriter(Log::Debug, CustomFileWriter, &ofs2);

CPL_LOG_ID(Debug, "log 1 message", id1);
Expand Down
7 changes: 7 additions & 0 deletions src/Test/TestOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Test
bool help;
Log::Level logLevel;
String logFile;
String output;
Strings include, exclude;

Options(int argc, char* argv[])
Expand All @@ -44,10 +45,16 @@ namespace Test
help = HasArg("-h", "-?");
logLevel = (Log::Level)Cpl::ToVal<Int>(GetArg2("-ll", "--logLevel", "4", false));
logFile = GetArg2("-lf", "--logFile", "", false);
output = GetArg("-o", "out", false);
include = GetArgs("-i", Strings(), false);
exclude = GetArgs("-e", Strings(), false);
}

bool Required(const Group& group);

String OutputPath(const String& name) const
{
return Cpl::MakePath(output, name);
}
};
}
62 changes: 31 additions & 31 deletions src/Test/TestParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ namespace Test

test().value() = 9;

test.Save("simple_short.xml", false);
test.Save("simple_full.xml", true);
test.Save(options.OutputPath("simple_short.xml"), false);
test.Save(options.OutputPath("simple_full.xml"), true);

if (!loaded.Load("simple_short.xml"))
if (!loaded.Load(options.OutputPath("simple_short.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -99,10 +99,10 @@ namespace Test

test().child().name() = "Horse";

test.Save("struct_short.xml", false);
test.Save("struct_full.xml", true);
test.Save(options.OutputPath("struct_short.xml"), false);
test.Save(options.OutputPath("struct_full.xml"), true);

if (!loaded.Load("struct_full.xml"))
if (!loaded.Load(options.OutputPath("struct_full.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -144,10 +144,10 @@ namespace Test

TestParamHolder test, loaded;

test.Save("struct_mod_short.xml", false);
test.Save("struct_mod_full.xml", true);
test.Save(options.OutputPath("struct_mod_short.xml"), false);
test.Save(options.OutputPath("struct_mod_full.xml"), true);

if (!loaded.Load("struct_mod_full.xml"))
if (!loaded.Load(options.OutputPath("struct_mod_full.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -177,10 +177,10 @@ namespace Test
test().children().resize(2);
test().children()[0].value() = 5;

test.Save("vector_short.xml", false);
test.Save("vector_full.xml", true);
test.Save(options.OutputPath("vector_short.xml"), false);
test.Save(options.OutputPath("vector_full.xml"), true);

if (!loaded.Load("vector_short.xml"))
if (!loaded.Load(options.OutputPath("vector_short.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -234,10 +234,10 @@ namespace Test
test().enum2() = A::B::Enum2;
test().enum3() = A::B::C::Enum1;

test.Save("enum_short.xml", false);
test.Save("enum_full.xml", true);
test.Save(options.OutputPath("enum_short.xml"), false);
test.Save(options.OutputPath("enum_full.xml"), true);

if (!loaded.Load("enum_full.xml"))
if (!loaded.Load(options.OutputPath("enum_full.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -269,10 +269,10 @@ namespace Test

copy.Clone(test);

test.Save("map_short.xml", false);
copy.Save("map_copy_full.xml", true);
test.Save(options.OutputPath("map_short.xml"), false);
copy.Save(options.OutputPath("map_copy_full.xml"), true);

if (!loaded.Load("map_copy_full.xml"))
if (!loaded.Load(options.OutputPath("map_copy_full.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -340,10 +340,10 @@ namespace Test

copy.Clone(test);

test.Save("map_short.xml", false);
copy.Save("map_copy_full.xml", true);
test.Save(options.OutputPath("map_short.xml"), false);
copy.Save(options.OutputPath("map_copy_full.xml"), true);

if (!loaded.Load("map_copy_full.xml"))
if (!loaded.Load(options.OutputPath("map_copy_full.xml")))
return false;

return loaded.Equal(test);
Expand All @@ -370,10 +370,10 @@ namespace Test

test().value() = 9;

test.Save("limited_short.xml", false);
test.Save("limited_full.xml", true);
test.Save(options.OutputPath("limited_short.xml"), false);
test.Save(options.OutputPath("limited_full.xml"), true);

if (!loaded.Load("limited_full.xml"))
if (!loaded.Load(options.OutputPath("limited_full.xml")))
return false;

return loaded.Equal(test);
Expand Down Expand Up @@ -409,20 +409,20 @@ namespace Test
test().strProp().value() = "string";


test.Save("template_short.yml", false);
test.Save("template_full.yml", true);
test.Save(options.OutputPath("template_short.yml"), false);
test.Save(options.OutputPath("template_full.yml"), true);

test.Save("template_short.xml", false);
test.Save("template_full.xml", true);
test.Save(options.OutputPath("template_short.xml"), false);
test.Save(options.OutputPath("template_full.xml"), true);

if (!loaded.Load("template_full.yml"))
if (!loaded.Load(options.OutputPath("template_full.yml")))
return false;

if (!loaded.Equal(test))
{
CPL_LOG_SS(Error, "loaded full != original");
loaded.Save("template_short_loaded.yml", false);
loaded.Save("template_full_loaded.yml", true);
loaded.Save(options.OutputPath("template_short_loaded.yml"), false);
loaded.Save(options.OutputPath("template_full_loaded.yml"), true);
return false;
}

Expand Down
Loading