diff --git a/README.md b/README.md index be91915..75d78a2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # wsjcpp-arguments -[![Build Status](https://api.travis-ci.com/wsjcpp/wsjcpp-arguments.svg?branch=master)](https://travis-ci.com/wsjcpp/wsjcpp-arguments) [![Github Stars](https://img.shields.io/github/stars/wsjcpp/wsjcpp-arguments.svg?label=github%20%E2%98%85)](https://github.com/wsjcpp/wsjcpp-arguments/stargazers) [![Github Stars](https://img.shields.io/github/contributors/wsjcpp/wsjcpp-arguments.svg)](https://github.com/wsjcpp/wsjcpp-arguments/) [![Github Forks](https://img.shields.io/github/forks/wsjcpp/wsjcpp-arguments.svg?label=github%20forks)](https://github.com/wsjcpp/wsjcpp-arguments/network/members) +[![Build Status](https://api.travis-ci.com/wsjcpp/wsjcpp-arguments.svg?branch=master)](https://travis-ci.com/wsjcpp/wsjcpp-arguments) [![Github Stars](https://img.shields.io/github/stars/wsjcpp/wsjcpp-arguments.svg?label=github%20%E2%98%85)](https://github.com/wsjcpp/wsjcpp-arguments/stargazers) [![Github Stars](https://img.shields.io/github/contributors/wsjcpp/wsjcpp-arguments.svg)](https://github.com/wsjcpp/wsjcpp-arguments/) [![Github Forks](https://img.shields.io/github/forks/wsjcpp/wsjcpp-arguments.svg?label=github%20forks)](https://github.com/wsjcpp/wsjcpp-arguments/network/members) [![Total alerts](https://img.shields.io/lgtm/alerts/g/wsjcpp/wsjcpp-arguments.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/wsjcpp/wsjcpp-arguments/alerts/) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/wsjcpp/wsjcpp-arguments.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/wsjcpp/wsjcpp-arguments/context:cpp) Parsing and handling for application arguments diff --git a/src.wsjcpp/CMakeLists.txt b/src.wsjcpp/CMakeLists.txt index 731168b..ec93c2d 100644 --- a/src.wsjcpp/CMakeLists.txt +++ b/src.wsjcpp/CMakeLists.txt @@ -1,7 +1,7 @@ -# Automaticly generated by wsjcpp@v0.1.5 +# Automaticly generated by wsjcpp@v0.1.6 cmake_minimum_required(VERSION 3.0) -add_definitions(-DWSJCPP_APP_VERSION="v0.2.0") +add_definitions(-DWSJCPP_APP_VERSION="v0.2.1") add_definitions(-DWSJCPP_APP_NAME="wsjcpp-arguments") if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -17,7 +17,7 @@ set (WSJCPP_SOURCES "") find_package(Threads REQUIRED) list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) -# wsjcpp-core:v0.1.0 +# wsjcpp-core:v0.2.1 list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_core/") list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp") list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.h") diff --git a/src.wsjcpp/wsjcpp_core/generate.Class.wsjcpp-script b/src.wsjcpp/wsjcpp_core/generate.Class.wsjcpp-script new file mode 100644 index 0000000..4a0d11f --- /dev/null +++ b/src.wsjcpp/wsjcpp_core/generate.Class.wsjcpp-script @@ -0,0 +1,81 @@ +#!/usr/bin/wsjcpp-safe-scripting + +# log_info rootdir +# log_info script_filename + +make_dir "src" + +var user_class_name +set_value user_class_name arg1 +normalize_class_name user_class_name +convert_CamelCase_to_snake_case user_class_name user_class_name + +var class_name +set_value class_name arg1 +normalize_class_name class_name + +var base_filename +convert_CamelCase_to_snake_case class_name base_filename +# log_info base_filename + +var filename_cpp +concat filename_cpp "./src/" base_filename ".cpp" + +var filename_h +concat filename_h "./src/" base_filename ".h" + +var ifndef_header +set_value ifndef_header base_filename +concat ifndef_header "_H" + +to_upper_case ifndef_header + +var content_header +concat content_header "#ifndef " ifndef_header " +#define " ifndef_header " + +#include + +class " class_name " { + public: + " class_name "(); + + private: + std::string TAG; +}; + +#endif // " ifndef_header + + +var content_source +concat content_source " +#include \"" base_filename ".h\" +#include + +// --------------------------------------------------------------------- +// " class_name " + +" class_name "::" class_name "() { + TAG = \"" class_name "\"; +} + +" + +var file_source +concat file_source "src/" filename_cpp + +write_file filename_h content_header +write_file filename_cpp content_source + +log_info " +====== +Generated class: + - " class_name " +Generated files: + - " filename_h " + - " filename_cpp " +====== +" + +cmakelists_txt_append_wsjcpp filename_h +cmakelists_txt_append_wsjcpp filename_cpp \ No newline at end of file diff --git a/src.wsjcpp/wsjcpp_core/generate.WsjcppUnitTest.wsjcpp-script b/src.wsjcpp/wsjcpp_core/generate.WsjcppUnitTest.wsjcpp-script new file mode 100644 index 0000000..fdf4902 --- /dev/null +++ b/src.wsjcpp/wsjcpp_core/generate.WsjcppUnitTest.wsjcpp-script @@ -0,0 +1,70 @@ +#!/usr/bin/wsjcpp-safe-scripting + +# log_info rootdir +# log_info script_filename + +make_dir "./unit-tests.wsjcpp" +make_dir "./unit-tests.wsjcpp/src" + +var class_name +set_value class_name arg1 +normalize_class_name class_name + +var filename_cpp +set_value filename_cpp arg2 + +var content_source +concat content_source " +#include +#include + +// --------------------------------------------------------------------- +// " class_name " + +class " class_name " : public WsjcppUnitTestBase { + public: + " class_name "(); + virtual bool doBeforeTest() override; + virtual void executeTest() override; + virtual bool doAfterTest() override; +}; + +REGISTRY_WSJCPP_UNIT_TEST(" class_name ") + +" class_name "::" class_name "() + : WsjcppUnitTestBase(\"" class_name "\") { +} + +// --------------------------------------------------------------------- + +bool " class_name "::doBeforeTest() { + // do something before test + return true; +} + +// --------------------------------------------------------------------- + +void " class_name "::executeTest() { + compare(\"Not implemented\", true, false); + // TODO unit test source code here +} + +// --------------------------------------------------------------------- + +bool " class_name "::doAfterTest() { + // do somethig after test + return true; +} + +" + +write_file filename_cpp content_source + +log_info " +====== +Generated class: + - " class_name " +Generated files: + - " filename_cpp " +====== +" diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml b/src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml index 6a452b8..b8dcfeb 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml +++ b/src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml @@ -3,7 +3,7 @@ cmake_cxx_standard: 11 cmake_minimum_required: 3.0 name: wsjcpp-core -version: v0.1.0 +version: v0.2.1 description: Basic Utils for wsjcpp issues: https://github.com/wsjcpp/wsjcpp-core/issues repositories: @@ -33,13 +33,17 @@ distribution: - source-file: "src/wsjcpp_unit_tests_main.cpp" target-file: "wsjcpp_unit_tests_main.cpp" type: "unit-tests" + - source-file: "scripts.wsjcpp/generate.WsjcppUnitTest.wsjcpp-script" + target-file: "generate.WsjcppUnitTest.wsjcpp-script" + type: "safe-scripting-generate" + - source-file: "scripts.wsjcpp/generate.Class.wsjcpp-script" + target-file: "generate.Class.wsjcpp-script" + type: "safe-scripting-generate" unit-tests: cases: - name: CoreNormalizePath description: Check function normalizePath - - name: CoreUuid - description: Check test generate uuid function - name: CoreExtractFilename description: Check function extract filenane from path - name: "ToUpper" @@ -68,3 +72,13 @@ unit-tests: description: "Test join function" - name: "getHumanSizeBytes" description: "Test function get human size in bytes" + - name: "TestResources" + description: "Test basic resources" + - name: "ListOfDirs" + description: "Check list of directories" + - name: "FilePermissions" + description: "" + - name: "StringPadding" + description: "" + - name: "DateTimeFormat" + description: "" diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp b/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp index 0256d53..5e937f3 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp @@ -1,6 +1,7 @@ #include "wsjcpp_core.h" #include #include +#include #include #include #include @@ -16,9 +17,237 @@ #include #include #include -#include -#include +// #include #include +#include +#include + +// --------------------------------------------------------------------- +// WsjcppFilePermissions + +WsjcppFilePermissions::WsjcppFilePermissions() { + // default permissions + m_bOwnerReadFlag = true; + m_bOwnerWriteFlag = true; + m_bOwnerExecuteFlag = false; + m_bGroupReadFlag = false; + m_bGroupWriteFlag = false; + m_bGroupExecuteFlag = false; + m_bOtherReadFlag = true; + m_bOtherWriteFlag = false; + m_bOtherExecuteFlag = false; +} + +WsjcppFilePermissions::WsjcppFilePermissions( + bool bOwnerReadFlag, bool bOwnerWriteFlag, bool bOwnerExecuteFlag, + bool bGroupReadFlag, bool bGroupWriteFlag, bool bGroupExecuteFlag, + bool bOtherReadFlag, bool bOtherWriteFlag, bool bOtherExecuteFlag +) { + m_bOwnerReadFlag = bOwnerReadFlag; + m_bOwnerWriteFlag = bOwnerWriteFlag; + m_bOwnerExecuteFlag = bOwnerExecuteFlag; + m_bGroupReadFlag = bGroupReadFlag; + m_bGroupWriteFlag = bGroupWriteFlag; + m_bGroupExecuteFlag = bGroupExecuteFlag; + m_bOtherReadFlag = bOtherReadFlag; + m_bOtherWriteFlag = bOtherWriteFlag; + m_bOtherExecuteFlag = bOtherExecuteFlag; +} + +WsjcppFilePermissions::WsjcppFilePermissions(uint16_t nFilePermission) { + + // owner + m_bOwnerReadFlag = nFilePermission & 0x0400; + m_bOwnerWriteFlag = nFilePermission & 0x0200; + m_bOwnerExecuteFlag = nFilePermission & 0x0100; + + // group + m_bGroupReadFlag = nFilePermission & 0x0040; + m_bGroupWriteFlag = nFilePermission & 0x0020; + m_bGroupExecuteFlag = nFilePermission & 0x0010; + + // for other + m_bOtherReadFlag = nFilePermission & 0x0004; + m_bOtherWriteFlag = nFilePermission & 0x0002; + m_bOtherExecuteFlag = nFilePermission & 0x0001; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOwnerReadFlag(bool bOwnerReadFlag) { + m_bOwnerReadFlag = bOwnerReadFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getOwnerReadFlag() const { + return m_bOwnerReadFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOwnerWriteFlag(bool bOwnerWriteFlag) { + m_bOwnerWriteFlag = bOwnerWriteFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getOwnerWriteFlag() const { + return m_bOwnerWriteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOwnerExecuteFlag(bool bOwnerExecuteFlag) { + m_bOwnerExecuteFlag = bOwnerExecuteFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getOwnerExecuteFlag() const { + return m_bOwnerExecuteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOwnerFlags(bool bOwnerReadFlag, bool bOwnerWriteFlag, bool bOwnerExecuteFlag) { + m_bOwnerReadFlag = bOwnerReadFlag; + m_bOwnerWriteFlag = bOwnerWriteFlag; + m_bOwnerExecuteFlag = bOwnerExecuteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setGroupReadFlag(bool bGroupReadFlag) { + m_bGroupReadFlag = bGroupReadFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getGroupReadFlag() const { + return m_bGroupReadFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setGroupWriteFlag(bool bGroupWriteFlag) { + m_bGroupWriteFlag = bGroupWriteFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getGroupWriteFlag() const { + return m_bGroupWriteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setGroupExecuteFlag(bool bGroupExecuteFlag) { + m_bGroupExecuteFlag = bGroupExecuteFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getGroupExecuteFlag() const { + return m_bGroupExecuteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setGroupFlags(bool bGroupReadFlag, bool bGroupWriteFlag, bool bGroupExecuteFlag) { + m_bGroupReadFlag = bGroupReadFlag; + m_bGroupWriteFlag = bGroupWriteFlag; + m_bGroupExecuteFlag = bGroupExecuteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOtherReadFlag(bool bOtherReadFlag) { + m_bOtherReadFlag = bOtherReadFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getOtherReadFlag() const { + return m_bOtherReadFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOtherWriteFlag(bool bOtherWriteFlag) { + m_bOtherWriteFlag = bOtherWriteFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getOtherWriteFlag() const { + return m_bOtherWriteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOtherExecuteFlag(bool bOtherExecuteFlag) { + m_bOtherExecuteFlag = bOtherExecuteFlag; +} + +// --------------------------------------------------------------------- + +bool WsjcppFilePermissions::getOtherExecuteFlag() const { + return m_bOtherExecuteFlag; +} + +// --------------------------------------------------------------------- + +void WsjcppFilePermissions::setOtherFlags(bool bOtherReadFlag, bool bOtherWriteFlag, bool bOtherExecuteFlag) { + m_bOtherReadFlag = bOtherReadFlag; + m_bOtherWriteFlag = bOtherWriteFlag; + m_bOtherExecuteFlag = bOtherExecuteFlag; +} + +// --------------------------------------------------------------------- + +std::string WsjcppFilePermissions::toString() const { + std::string sRet = "-"; + + // owner + sRet += m_bOwnerReadFlag ? "r" : "-"; + sRet += m_bOwnerWriteFlag ? "w" : "-"; + sRet += m_bOwnerExecuteFlag ? "x" : "-"; + + // group + sRet += m_bGroupReadFlag ? "r" : "-"; + sRet += m_bGroupWriteFlag ? "w" : "-"; + sRet += m_bGroupExecuteFlag ? "x" : "-"; + + // for other + sRet += m_bOtherReadFlag ? "r" : "-"; + sRet += m_bOtherWriteFlag ? "w" : "-"; + sRet += m_bOtherExecuteFlag ? "x" : "-"; + + return sRet; +} + +// --------------------------------------------------------------------- + +uint16_t WsjcppFilePermissions::toUInt16() const { + uint16_t nRet = 0x0; + // owner + nRet |= m_bOwnerReadFlag ? 0x0400 : 0x0; + nRet |= m_bOwnerWriteFlag ? 0x0200 : 0x0; + nRet |= m_bOwnerExecuteFlag ? 0x0100 : 0x0; + + // group + nRet += m_bGroupReadFlag ? 0x0040 : 0x0; + nRet += m_bGroupWriteFlag ? 0x0020 : 0x0; + nRet += m_bGroupExecuteFlag ? 0x0010 : 0x0; + + // for other + nRet += m_bOtherReadFlag ? 0x0004 : 0x0; + nRet += m_bOtherWriteFlag ? 0x0002 : 0x0; + nRet += m_bOtherExecuteFlag ? 0x0001 : 0x0; + return nRet; +} + // --------------------------------------------------------------------- // WsjcppCore @@ -31,8 +260,8 @@ bool WsjcppCore::init( const std::string &sLibraryNameForExports ) { // init random - std::srand(std::rand() + std::time(0)); - // WsjcppCore::initRandom(); + // std::srand(std::time(0)); + WsjcppCore::initRandom(); return true; } @@ -138,28 +367,35 @@ std::string WsjcppCore::getCurrentDirectory() { // --------------------------------------------------------------------- -long WsjcppCore::currentTime_milliseconds() { +long WsjcppCore::getCurrentTimeInMilliseconds() { long nTimeStart = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); return nTimeStart; } // --------------------------------------------------------------------- -long WsjcppCore::currentTime_seconds() { +long WsjcppCore::getCurrentTimeInSeconds() { long nTimeStart = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); return nTimeStart; } // --------------------------------------------------------------------- -std::string WsjcppCore::currentTime_logformat() { - long nTimeStart = WsjcppCore::currentTime_milliseconds(); +std::string WsjcppCore::getCurrentTimeForFilename() { + long nTimeStart = WsjcppCore::getCurrentTimeInSeconds(); + return WsjcppCore::formatTimeForFilename(nTimeStart); +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::getCurrentTimeForLogFormat() { + long nTimeStart = WsjcppCore::getCurrentTimeInMilliseconds(); std::string sMilliseconds = std::to_string(int(nTimeStart % 1000)); nTimeStart = nTimeStart / 1000; std::time_t tm_ = long(nTimeStart); - // struct tm tstruct = *localtime(&tm_); - struct tm tstruct = *gmtime ( &tm_ ); + struct tm tstruct; + gmtime_r(&tm_, &tstruct); // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime // for more information about date/time format @@ -170,11 +406,14 @@ std::string WsjcppCore::currentTime_logformat() { // --------------------------------------------------------------------- -std::string WsjcppCore::threadId() { +std::string WsjcppCore::getThreadId() { + + static_assert(sizeof(std::thread::id)==sizeof(uint64_t),"this function only works if size of thead::id is equal to the size of uint_64"); std::thread::id this_id = std::this_thread::get_id(); + uint64_t val = *((uint64_t*) &this_id); std::stringstream stream; - stream << std::hex << this_id; - return "0x" + std::string(stream.str()); + stream << "0x" << std::setw(16) << std::setfill('0') << std::hex << val; + return std::string(stream.str()); } // --------------------------------------------------------------------- @@ -182,8 +421,8 @@ std::string WsjcppCore::threadId() { std::string WsjcppCore::formatTimeForWeb(long nTimeInSec) { std::time_t tm_ = long(nTimeInSec); // struct tm tstruct = *localtime(&tm_); - struct tm tstruct = *gmtime ( &tm_ ); - + struct tm tstruct; + gmtime_r(&tm_, &tstruct); // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime // for more information about date/time format @@ -193,19 +432,15 @@ std::string WsjcppCore::formatTimeForWeb(long nTimeInSec) { return std::string(buf); } -// --------------------------------------------------------------------- -std::string WsjcppCore::currentTime_forFilename() { - long nTimeStart = WsjcppCore::currentTime_seconds(); - return WsjcppCore::formatTimeForFilename(nTimeStart); -} // --------------------------------------------------------------------- std::string WsjcppCore::formatTimeForFilename(long nTimeInSec) { std::time_t tm_ = long(nTimeInSec); // struct tm tstruct = *localtime(&tm_); - struct tm tstruct = *gmtime ( &tm_ ); + struct tm tstruct; + gmtime_r(&tm_, &tstruct); // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime // for more information about date/time format @@ -220,7 +455,8 @@ std::string WsjcppCore::formatTimeUTC(int nTimeInSec) { // datetime std::time_t tm_ = long(nTimeInSec); // struct tm tstruct = *localtime(&tm_); - struct tm tstruct = *gmtime ( &tm_ ); + struct tm tstruct; + gmtime_r(&tm_, &tstruct); // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime // for more information about date/time format @@ -254,44 +490,63 @@ bool WsjcppCore::dirExists(const std::string &sDirname) { // --------------------------------------------------------------------- std::vector WsjcppCore::listOfDirs(const std::string &sDirname) { + WsjcppLog::warn("listOfDirs", "Deprecated. Use a WsjcppCore::getListOfDirs"); + return WsjcppCore::getListOfDirs(sDirname); +} + +// --------------------------------------------------------------------- + +std::vector WsjcppCore::getListOfDirs(const std::string &sDirname) { std::vector vDirs; if (!WsjcppCore::dirExists(sDirname)) { return vDirs; } DIR *dir = opendir(sDirname.c_str()); - struct dirent *entry = readdir(dir); - while (entry != NULL) { - if (entry->d_type == DT_DIR) { - std::string sDir(entry->d_name); - if (sDir != "." && sDir != "..") { - vDirs.push_back(sDir); + if (dir != NULL) { + struct dirent *entry = readdir(dir); + while (entry != NULL) { + if (entry->d_type == DT_DIR) { + std::string sDir(entry->d_name); + if (sDir != "." && sDir != "..") { + vDirs.push_back(sDir); + } } + entry = readdir(dir); } - entry = readdir(dir); + closedir(dir); } - closedir(dir); + std::sort(vDirs.begin(), vDirs.end()); return vDirs; } // --------------------------------------------------------------------- std::vector WsjcppCore::listOfFiles(const std::string &sDirname) { + WsjcppLog::warn("listOfFiles", "Deprecated. Use a WsjcppCore::getListOfFiles"); + return WsjcppCore::getListOfFiles(sDirname); +} + +// --------------------------------------------------------------------- + +std::vector WsjcppCore::getListOfFiles(const std::string &sDirname) { std::vector vFiles; if (!WsjcppCore::dirExists(sDirname)) { return vFiles; } DIR *dir = opendir(sDirname.c_str()); - struct dirent *entry = readdir(dir); - while (entry != NULL) { - if (entry->d_type != DT_DIR) { - std::string sDir(entry->d_name); - if (sDir != "." && sDir != "..") { - vFiles.push_back(sDir); + if (dir != NULL) { + struct dirent *entry = readdir(dir); + while (entry != NULL) { + if (entry->d_type != DT_DIR) { + std::string sDir(entry->d_name); + if (sDir != "." && sDir != "..") { + vFiles.push_back(sDir); + } } + entry = readdir(dir); } - entry = readdir(dir); + closedir(dir); } - closedir(dir); return vFiles; } @@ -392,6 +647,35 @@ bool WsjcppCore::removeFile(const std::string &sFilename) { // --------------------------------------------------------------------- +bool WsjcppCore::copyFile(const std::string &sSourceFilename, const std::string &sTargetFilename) { + if (!WsjcppCore::fileExists(sSourceFilename)) { + WsjcppLog::err("copyFile", "File '" + sSourceFilename + "' did not exists"); + return false; + } + + if (WsjcppCore::fileExists(sTargetFilename)) { + WsjcppLog::err("copyFile", "File '" + sTargetFilename + "' already exists"); + return false; + } + + std::ifstream src(sSourceFilename, std::ios::binary); + if (!src.is_open()) { + WsjcppLog::err("copyFile", "Could not open file '" + sSourceFilename + "' for read"); + return false; + } + + std::ofstream dst(sTargetFilename, std::ios::binary); + if (!dst.is_open()) { + WsjcppLog::err("copyFile", "Could not open file '" + sTargetFilename + "' for write"); + return false; + } + + dst << src.rdbuf(); + return true; +} + +// --------------------------------------------------------------------- + bool WsjcppCore::createEmptyFile(const std::string &sFilename) { if (WsjcppCore::fileExists(sFilename)) { return false; @@ -497,7 +781,7 @@ std::string WsjcppCore::join(const std::vector &vWhat, const std::s // --------------------------------------------------------------------- void WsjcppCore::initRandom() { - std::srand(std::rand() + std::time(0)); + std::srand(std::time(0)); } // --------------------------------------------------------------------- @@ -505,13 +789,11 @@ void WsjcppCore::initRandom() { std::string WsjcppCore::createUuid() { std::string sRet = "00000000-0000-0000-0000-000000000000"; const std::string sAlphabet = "0123456789abcdef"; - // unsigned t = std::time(0); for (int i = 0; i < 36; i++) { if (i != 8 && i != 13 && i != 18 && i != 23) { - sRet[i] = sAlphabet[std::rand() % sAlphabet.length()]; + sRet[i] = sAlphabet[rand() % sAlphabet.length()]; } } - // Fallen::initRandom(); return sRet; } @@ -634,30 +916,193 @@ std::string WsjcppCore::getHumanSizeBytes(long nBytes) { return std::to_string(nBytes) + "PB"; } +// --------------------------------------------------------------------- + +bool WsjcppCore::recoursiveCopyFiles(const std::string& sSourceDir, const std::string& sTargetDir) { + if (!WsjcppCore::dirExists(sSourceDir)) { + WsjcppLog::err("recoursiveCopyFiles", "Source Dir '" + sSourceDir + "' did not exists"); + return false; + } + + if (!WsjcppCore::dirExists(sTargetDir)) { + if (!WsjcppCore::makeDir(sTargetDir)) { + WsjcppLog::err("recoursiveCopyFiles", "Could not create target dir '" + sTargetDir + "'"); + return false; + } + } + + std::vector vFiles = WsjcppCore::getListOfFiles(sSourceDir); + for (int i = 0; i < vFiles.size(); i++) { + std::string sSourceFile = sSourceDir + "/" + vFiles[i]; + std::string sTargetFile = sTargetDir + "/" + vFiles[i]; + if (!WsjcppCore::copyFile(sSourceFile, sTargetFile)) { + return false; + } + } + + std::vector vDirs = WsjcppCore::getListOfDirs(sSourceDir); + for (int i = 0; i < vDirs.size(); i++) { + std::string sSourceDir2 = sSourceDir + "/" + vDirs[i]; + std::string sTargetDir2 = sTargetDir + "/" + vDirs[i]; + if (!WsjcppCore::dirExists(sTargetDir2)) { + if (!WsjcppCore::makeDir(sTargetDir2)) { + WsjcppLog::err("recoursiveCopyFiles", "Could not create target subdir '" + sTargetDir2 + "'"); + return false; + } + } + + if (!WsjcppCore::recoursiveCopyFiles(sSourceDir2, sTargetDir2)) { + return false; + } + } + return true; +} + +// --------------------------------------------------------------------- + +bool WsjcppCore::recoursiveRemoveDir(const std::string& sDir) { + if (!WsjcppCore::dirExists(sDir)) { + WsjcppLog::err("recoursiveCopyFiles", "Dir '" + sDir + "' did not exists"); + return false; + } + + std::vector vFiles = WsjcppCore::getListOfFiles(sDir); + for (int i = 0; i < vFiles.size(); i++) { + std::string sFile = sDir + "/" + vFiles[i]; + if (!WsjcppCore::removeFile(sFile)) { + return false; + } + } + + std::vector vDirs = WsjcppCore::getListOfDirs(sDir); + for (int i = 0; i < vDirs.size(); i++) { + std::string sDir2 = sDir + "/" + vDirs[i]; + if (!WsjcppCore::recoursiveRemoveDir(sDir2)) { + return false; + } + } + + if (!WsjcppCore::removeFile(sDir)) { + return false; + } + return true; +} + +// --------------------------------------------------------------------- + +bool WsjcppCore::setFilePermissions(const std::string& sFilePath, const WsjcppFilePermissions &filePermissions, std::string& sError) { + + mode_t m; + + // owner + m |= filePermissions.getOwnerReadFlag() ? S_IRUSR : 0x0; + m |= filePermissions.getOwnerWriteFlag() ? S_IWUSR : 0x0; + m |= filePermissions.getOwnerExecuteFlag() ? S_IXUSR : 0x0; + + // group + m |= filePermissions.getGroupReadFlag() ? S_IRGRP : 0x0; + m |= filePermissions.getGroupWriteFlag() ? S_IWGRP : 0x0; + m |= filePermissions.getGroupExecuteFlag() ? S_IXGRP : 0x0; + + // for other + m |= filePermissions.getOtherReadFlag() ? S_IROTH : 0x0; + m |= filePermissions.getOtherWriteFlag() ? S_IWOTH : 0x0; + m |= filePermissions.getOtherExecuteFlag() ? S_IXOTH : 0x0; + + if (chmod(sFilePath.c_str(), m) != 0) { + sError = "Could not change permissions for: '" + sFilePath + "'"; + return false; + } + return true; +} + +// --------------------------------------------------------------------- + +bool WsjcppCore::getFilePermissions(const std::string& sFilePath, WsjcppFilePermissions &filePermissions, std::string& sError) { + if (!WsjcppCore::fileExists(sFilePath)) { + sError = "File '" + sFilePath + "' - not found"; + return false; + } + + struct stat fileStat; + if (stat(sFilePath.c_str(), &fileStat) < 0) { + sError = "Could not get info about file '" + sFilePath + "'."; + return false; + } + + mode_t m = fileStat.st_mode; + + // S_ISDIR(fileStat.st_mode)) ? "d" : "-" + + // owner + filePermissions.setOwnerReadFlag(m & S_IRUSR); + filePermissions.setOwnerWriteFlag(m & S_IWUSR); + filePermissions.setOwnerExecuteFlag(m & S_IXUSR); + + + // group + filePermissions.setGroupReadFlag(m & S_IRGRP); + filePermissions.setGroupWriteFlag(m & S_IWGRP); + filePermissions.setGroupExecuteFlag(m & S_IXGRP); + + // for other + filePermissions.setOtherReadFlag(m & S_IROTH); + filePermissions.setOtherWriteFlag(m & S_IWOTH); + filePermissions.setOtherExecuteFlag(m & S_IXOTH); + + return true; +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::doPadLeft(const std::string& sIn, char cWhat, int nLength) { + std::string sRet; + int nPadLen = nLength - sIn.length(); + for (int i = 0; i < nPadLen; i++) { + sRet += cWhat; + } + return sRet + sIn; +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::doPadRight(const std::string& sIn, char cWhat, int nLength) { + std::string sRet; + int nPadLen = nLength - sIn.length(); + for (int i = 0; i < nPadLen; i++) { + sRet += cWhat; + } + return sIn + sRet; +} + // --------------------------------------------------------------------- // WsjcppLog -// Last log messages -std::deque * WsjcppLog::g_WSJCPP_LOG_LAST_MESSAGES = nullptr; -std::mutex * WsjcppLog::g_WSJCPP_LOG_MUTEX = nullptr; -std::string WsjcppLog::g_WSJCPP_LOG_DIR = "./"; -std::string WsjcppLog::g_WSJCPP_LOG_FILE = ""; -std::string WsjcppLog::g_WSJCPP_LOG_PREFIX_FILE = ""; -long WsjcppLog::g_WSJCPP_LOG_START_TIME = 0; +WsjcppLogGlobalConf::WsjcppLogGlobalConf() { + // + logDir = "./"; + logPrefixFile = ""; + logFile = ""; + enableLogFile = true; + logStartTime = 0; + logRotationPeriodInSeconds = 51000; +} // --------------------------------------------------------------------- -void WsjcppLog::doLogRotateUpdateFilename(bool bForce) { - long t = WsjcppCore::currentTime_seconds(); - long nEverySeconds = 51000; // rotate log if started now or if time left more then 1 day - if (g_WSJCPP_LOG_START_TIME == 0 || t - g_WSJCPP_LOG_START_TIME > nEverySeconds || bForce) { - g_WSJCPP_LOG_START_TIME = t; - g_WSJCPP_LOG_FILE = g_WSJCPP_LOG_DIR + "/" - + WsjcppLog::g_WSJCPP_LOG_PREFIX_FILE + "_" - + WsjcppCore::formatTimeForFilename(g_WSJCPP_LOG_START_TIME) + ".log"; +void WsjcppLogGlobalConf::doLogRotateUpdateFilename(bool bForce) { + long t = WsjcppCore::getCurrentTimeInSeconds(); + long nEverySeconds = logRotationPeriodInSeconds; // rotate log if started now or if time left more then 1 day + if (logStartTime == 0 || t - logStartTime > nEverySeconds || bForce) { + logStartTime = t; + logFile = logDir + "/" + + logPrefixFile + "_" + + WsjcppCore::formatTimeForFilename(logStartTime) + ".log"; } } +WsjcppLogGlobalConf WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF; + // --------------------------------------------------------------------- void WsjcppLog::info(const std::string & sTag, const std::string &sMessage) { @@ -697,11 +1142,10 @@ void WsjcppLog::ok(const std::string &sTag, const std::string &sMessage) { // --------------------------------------------------------------------- std::vector WsjcppLog::getLastLogMessages() { - WsjcppLog::initGlobalVariables(); - std::lock_guard lock(*WsjcppLog::g_WSJCPP_LOG_MUTEX); + std::lock_guard lock(WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logMutex); std::vector vRet; - for (int i = 0; i < g_WSJCPP_LOG_LAST_MESSAGES->size(); i++) { - vRet.push_back(g_WSJCPP_LOG_LAST_MESSAGES->at(i)); + for (int i = 0; i < WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logLastMessages.size(); i++) { + vRet.push_back(WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logLastMessages[i]); } return vRet; } @@ -709,58 +1153,182 @@ std::vector WsjcppLog::getLastLogMessages() { // --------------------------------------------------------------------- void WsjcppLog::setLogDirectory(const std::string &sDirectoryPath) { - WsjcppLog::g_WSJCPP_LOG_DIR = sDirectoryPath; - WsjcppLog::doLogRotateUpdateFilename(true); + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logDir = sDirectoryPath; + if (!WsjcppCore::dirExists(sDirectoryPath)) { + if (!WsjcppCore::makeDir(sDirectoryPath)) { + WsjcppLog::err("setLogDirectory", "Could not create log directory '" + sDirectoryPath + "'"); + } + } + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.doLogRotateUpdateFilename(true); } // --------------------------------------------------------------------- void WsjcppLog::setPrefixLogFile(const std::string &sPrefixLogFile) { - WsjcppLog::g_WSJCPP_LOG_PREFIX_FILE = sPrefixLogFile; - WsjcppLog::doLogRotateUpdateFilename(true); + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logPrefixFile = sPrefixLogFile; + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.doLogRotateUpdateFilename(true); } // --------------------------------------------------------------------- -void WsjcppLog::initGlobalVariables() { - // create deque if not created - if (WsjcppLog::g_WSJCPP_LOG_LAST_MESSAGES == nullptr) { - WsjcppLog::g_WSJCPP_LOG_LAST_MESSAGES = new std::deque(); - // std::cout << WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::threadId() + " Init last messages deque\r\n"; - } - // create mutex if not created - if (WsjcppLog::g_WSJCPP_LOG_MUTEX == nullptr) { - WsjcppLog::g_WSJCPP_LOG_MUTEX = new std::mutex(); - // std::cout << WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::threadId() + " Init mutex for log\r\n"; - } +void WsjcppLog::setEnableLogFile(bool bEnable) { + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.enableLogFile = bEnable; +} + +// --------------------------------------------------------------------- + +void WsjcppLog::setRotationPeriodInSec(long nRotationPeriodInSec) { + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logRotationPeriodInSeconds = nRotationPeriodInSec; } // --------------------------------------------------------------------- void WsjcppLog::add(WsjcppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage) { - WsjcppLog::initGlobalVariables(); - WsjcppLog::doLogRotateUpdateFilename(); + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.doLogRotateUpdateFilename(); - std::lock_guard lock(*WsjcppLog::g_WSJCPP_LOG_MUTEX); + std::lock_guard lock(WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logMutex); WsjcppColorModifier def(WsjcppColorCode::FG_DEFAULT); - std::string sLogMessage = WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::threadId() + std::string sLogMessage = WsjcppCore::getCurrentTimeForLogFormat() + ", " + WsjcppCore::getThreadId() + " [" + sType + "] " + sTag + ": " + sMessage; std::cout << clr << sLogMessage << def << std::endl; - g_WSJCPP_LOG_LAST_MESSAGES->push_front(sLogMessage); - while (g_WSJCPP_LOG_LAST_MESSAGES->size() > 50) { - g_WSJCPP_LOG_LAST_MESSAGES->pop_back(); + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logLastMessages.push_front(sLogMessage); + + + while (WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logLastMessages.size() > 50) { + WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logLastMessages.pop_back(); } - // TODO try create global variable - std::ofstream logFile(WsjcppLog::g_WSJCPP_LOG_FILE, std::ios::app); - if (!logFile) { - std::cout << "Error Opening File" << std::endl; - return; + + // log file + if (WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.enableLogFile) { + std::ofstream logFile(WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logFile, std::ios::app); + if (!logFile) { + std::cout << "Error Opening File" << std::endl; + return; + } + + logFile << sLogMessage << std::endl; + logFile.close(); } +} - logFile << sLogMessage << std::endl; - logFile.close(); +// --------------------------------------------------------------------- +// WsjcppResourceFile + +WsjcppResourceFile::WsjcppResourceFile() { + WsjcppResourcesManager::add(this); +} + +// --------------------------------------------------------------------- + + +// --------------------------------------------------------------------- +// WsjcppResourcesManager + +std::vector *g_pWsjcppResourceFiles = nullptr; + +void WsjcppResourcesManager::initGlobalVariables() { + if (g_pWsjcppResourceFiles == nullptr) { + g_pWsjcppResourceFiles = new std::vector(); + } +} + +// --------------------------------------------------------------------- + +void WsjcppResourcesManager::add(WsjcppResourceFile* pStorage) { + WsjcppResourcesManager::initGlobalVariables(); + g_pWsjcppResourceFiles->push_back(pStorage); } +// --------------------------------------------------------------------- + +bool WsjcppResourcesManager::has(const std::string &sFilename) { + WsjcppResourcesManager::initGlobalVariables(); + for (int i = 0; i < WsjcppResourcesManager::list().size(); i++) { + if (WsjcppResourcesManager::list()[i]->getFilename() == sFilename) { + return true; + } + } + return false; +} + +// --------------------------------------------------------------------- + +WsjcppResourceFile* WsjcppResourcesManager::get(const std::string &sFilename) { + WsjcppResourcesManager::initGlobalVariables(); + for (int i = 0; i < WsjcppResourcesManager::list().size(); i++) { + if (WsjcppResourcesManager::list()[i]->getFilename() == sFilename) { + return WsjcppResourcesManager::list()[i]; + } + } + return nullptr; +} + +// --------------------------------------------------------------------- + +const std::vector &WsjcppResourcesManager::list() { + return *g_pWsjcppResourceFiles; +} + +// --------------------------------------------------------------------- + +/* +bool WsjcppResourcesManager::make(const std::string &sWorkspace) { + if (!WsjcppResourcesManager::createFolders(sWorkspace)) { + return false; + } + return WsjcppResourcesManager::extractFiles(sWorkspace); +} + +// --------------------------------------------------------------------- + +bool WsjcppResourcesManager::createFolders(const std::string &sWorkspace) { + // prepare folders + std::vector vCreateDirs; + vCreateDirs.push_back(sWorkspace + "/logs"); + vCreateDirs.push_back(sWorkspace + "/teams"); + vCreateDirs.push_back(sWorkspace + "/checkers"); + vCreateDirs.push_back(sWorkspace + "/html"); + vCreateDirs.push_back(sWorkspace + "/html/css"); + vCreateDirs.push_back(sWorkspace + "/html/js"); + vCreateDirs.push_back(sWorkspace + "/html/images"); + vCreateDirs.push_back(sWorkspace + "/html/images/teams"); + vCreateDirs.push_back(sWorkspace + "/html/images/states"); + + for(int i = 0; i < vCreateDirs.size(); i++) { + std::string sPath = vCreateDirs[i]; + // check dir existing + if (!FS::dirExists(sPath)) { + // try make dir + if (!FS::makeDir(sPath)) { + std::cout << "Could not create folder " << sPath << std::endl; + return false; + } else { + std::cout << "Created folder " << sPath << std::endl; + } + } + } + return true; +} + +// --------------------------------------------------------------------- + +bool WsjcppResourcesManager::extractFiles(const std::string &sWorkspace) { + // TODO mkdir -p for files + const std::vector list = WsjcppResourcesManager::list(); + for(int i = 0; i < list.size(); i++) { + std::string sFilename = sWorkspace + "/" + list[i]->filename(); + if (!FS::fileExists(sFilename)) { + if (!FS::writeFile(sFilename, list[i]->buffer(), list[i]->bufferSize())) { + std::cout << "Could not write file " << sFilename << std::endl; + return false; + } else { + std::cout << "Created file " << sFilename << std::endl; + } + } + } + return true; +} +*/ diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_core.h b/src.wsjcpp/wsjcpp_core/wsjcpp_core.h index 4884467..249c693 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_core.h +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_core.h @@ -8,6 +8,58 @@ #include #include +class WsjcppFilePermissions { + public: + WsjcppFilePermissions(); + WsjcppFilePermissions( + bool bOwnerReadFlag, bool bOwnerWriteFlag, bool bOwnerExecuteFlag, + bool bGroupReadFlag, bool bGroupWriteFlag, bool bGroupExecuteFlag, + bool bOtherReadFlag, bool bOtherWriteFlag, bool bOtherExecuteFlag + ); + WsjcppFilePermissions(uint16_t nFilePermission); + + // owner flags + void setOwnerReadFlag(bool bOwnerReadFlag); + bool getOwnerReadFlag() const; + void setOwnerWriteFlag(bool bOwnerWriteFlag); + bool getOwnerWriteFlag() const; + void setOwnerExecuteFlag(bool bOwnerExecuteFlag); + bool getOwnerExecuteFlag() const; + void setOwnerFlags(bool bOwnerReadFlag, bool bOwnerWriteFlag, bool bOwnerExecuteFlag); + + // group flags + void setGroupReadFlag(bool bGroupReadFlag); + bool getGroupReadFlag() const; + void setGroupWriteFlag(bool bGroupWriteFlag); + bool getGroupWriteFlag() const; + void setGroupExecuteFlag(bool bGroupExecuteFlag); + bool getGroupExecuteFlag() const; + void setGroupFlags(bool bGroupReadFlag, bool bGroupWriteFlag, bool bGroupExecuteFlag); + + // for other flags + void setOtherReadFlag(bool bOtherReadFlag); + bool getOtherReadFlag() const; + void setOtherWriteFlag(bool bOtherWriteFlag); + bool getOtherWriteFlag() const; + void setOtherExecuteFlag(bool bOtherExecuteFlag); + bool getOtherExecuteFlag() const; + void setOtherFlags(bool bOtherReadFlag, bool bOtherWriteFlag, bool bOtherExecuteFlag); + + std::string toString() const; + uint16_t toUInt16() const; + + private: + bool m_bOwnerReadFlag; + bool m_bOwnerWriteFlag; + bool m_bOwnerExecuteFlag; + bool m_bGroupReadFlag; + bool m_bGroupWriteFlag; + bool m_bGroupExecuteFlag; + bool m_bOtherReadFlag; + bool m_bOtherWriteFlag; + bool m_bOtherExecuteFlag; +}; + class WsjcppCore { public: static bool init( @@ -22,11 +74,11 @@ class WsjcppCore { static std::string extractFilename(const std::string &sPath); static std::string getCurrentDirectory(); - static long currentTime_milliseconds(); - static long currentTime_seconds(); - static std::string currentTime_forFilename(); - static std::string currentTime_logformat(); - static std::string threadId(); + static long getCurrentTimeInMilliseconds(); + static long getCurrentTimeInSeconds(); + static std::string getCurrentTimeForFilename(); + static std::string getCurrentTimeForLogFormat(); + static std::string getThreadId(); static std::string formatTimeForWeb(long nTimeInSec); static std::string formatTimeForFilename(long nTimeInSec); static std::string formatTimeUTC(int nTimeInSec); @@ -34,13 +86,17 @@ class WsjcppCore { static bool dirExists(const std::string &sFilename); static bool fileExists(const std::string &sFilename); static std::vector listOfDirs(const std::string &sDirname); - static std::vector listOfFiles(const std::string &sDirname); + static std::vector getListOfDirs(const std::string &sDirname); + static std::vector listOfFiles(const std::string &sDirname); + static std::vector getListOfFiles(const std::string &sDirname); static bool makeDir(const std::string &sDirname); static bool writeFile(const std::string &sFilename, const std::string &sContent); static bool readTextFile(const std::string &sFilename, std::string &sOutputContent); static bool readFileToBuffer(const std::string &sFilename, char *pBuffer[], int &nBufferSize); static bool writeFile(const std::string &sFilename, const char *pBuffer, const int nBufferSize); static bool removeFile(const std::string &sFilename); + static bool copyFile(const std::string &sSourceFilename, const std::string &sTargetFilename); + static bool createEmptyFile(const std::string &sFilename); static std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); @@ -64,6 +120,16 @@ class WsjcppCore { static std::string decodeUriComponent(const std::string& sValue); static std::string getHumanSizeBytes(long nBytes); + + static bool recoursiveCopyFiles(const std::string& sSourceDir, const std::string& sTargetDir); + static bool recoursiveRemoveDir(const std::string& sDir); + + static bool setFilePermissions(const std::string& sFilePath, const WsjcppFilePermissions &filePermissions, std::string& sError); + static bool getFilePermissions(const std::string& sFilePath, WsjcppFilePermissions &filePermissions, std::string& sError); + + static std::string doPadLeft(const std::string& sIn, char cWhat, int nLength); + static std::string doPadRight(const std::string& sIn, char cWhat, int nLength); + }; @@ -95,15 +161,23 @@ class WsjcppColorModifier { // --------------------------------------------------------------------- +class WsjcppLogGlobalConf { + public: + WsjcppLogGlobalConf(); + void doLogRotateUpdateFilename(bool bForce = false); + std::mutex logMutex; + std::string logDir; + std::string logPrefixFile; + std::string logFile; + bool enableLogFile; + long logStartTime; + long logRotationPeriodInSeconds; + std::deque logLastMessages; +}; + class WsjcppLog { public: - static std::string g_WSJCPP_LOG_DIR; - static std::string g_WSJCPP_LOG_PREFIX_FILE; - static std::string g_WSJCPP_LOG_FILE; - static long g_WSJCPP_LOG_START_TIME; - static std::mutex * g_WSJCPP_LOG_MUTEX; - static std::deque * g_WSJCPP_LOG_LAST_MESSAGES; - static void doLogRotateUpdateFilename(bool bForce = false); + static WsjcppLogGlobalConf g_WSJCPP_LOG_GLOBAL_CONF; static void info(const std::string &sTag, const std::string &sMessage); static void err(const std::string &sTag, const std::string &sMessage); @@ -113,12 +187,49 @@ class WsjcppLog { static std::vector getLastLogMessages(); static void setLogDirectory(const std::string &sDirectoryPath); static void setPrefixLogFile(const std::string &sPrefixLogFile); - static void initGlobalVariables(); + static void setEnableLogFile(bool bEnable); + static void setRotationPeriodInSec(long nRotationPeriodInSec); private: static void add(WsjcppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage); }; +// --------------------------------------------------------------------- +// WsjcppResourceFile + +class WsjcppResourceFile { + public: + WsjcppResourceFile(); + virtual const std::string &getFilename() const = 0; + virtual const std::string &getPackAs() const = 0; + virtual int getBufferSize() const = 0; + virtual const char *getBuffer() const = 0; +}; + + +// --------------------------------------------------------------------- +// WsjcppResourcesManager + +extern std::vector *g_pWsjcppResourceFiles; + +class WsjcppResourcesManager { + public: + static void initGlobalVariables(); + static void add(WsjcppResourceFile*); + static const std::vector &list(); + static bool has(const std::string &sFilename); + static WsjcppResourceFile* get(const std::string &sFilename); + static bool make(const std::string &sWorkspace); + // static bool createFolders(const std::string &sWorkspace); + // static bool extractFiles(const std::string &sWorkspace); +}; + +// --------------------------------------------------------------------- +// Registry WsjcppResourceFile +#define REGISTRY_WSJCPP_RESOURCE_FILE( classname ) \ + static classname * pRegistryWsjcppResourceFile ## classname = new classname(); \ + + #endif // WSJCPP_CORE_H diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp index d675dac..bd00383 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp @@ -1,56 +1,74 @@ #include "wsjcpp_unit_tests.h" +#include + +// --------------------------------------------------------------------- +// WsjcppUnitTestBase WsjcppUnitTestBase::WsjcppUnitTestBase(const std::string &sTestName) { m_sTestName = sTestName; TAG = m_sTestName; + m_bTestResult = true; WsjcppUnitTests::addUnitTest(sTestName, this); } // --------------------------------------------------------------------- -std::string WsjcppUnitTestBase::name() { +std::string WsjcppUnitTestBase::getName() { return m_sTestName; } // --------------------------------------------------------------------- -void WsjcppUnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint, - const std::string &sValue, const std::string &sExpected) { - if (sValue != sExpected) { - WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + sExpected + "', but got '" + sValue + "'"); - bTestSuccess = false; - } +void WsjcppUnitTestBase::ok(const std::string &sSuccessMessage) { + // print obly success message + WsjcppLog::ok(TAG, sSuccessMessage); } // --------------------------------------------------------------------- -bool WsjcppUnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) { - if (nValue != nExpected) { - WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'"); - bTestSuccess = false; - return false; - } - return true; +void WsjcppUnitTestBase::fail(const std::string &sFailedMessage) { + WsjcppLog::err(TAG, sFailedMessage); + m_bTestResult = false; } // --------------------------------------------------------------------- -bool WsjcppUnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) { - if (nValue != nExpected) { - WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'"); - bTestSuccess = false; +bool WsjcppUnitTestBase::runTest() { + WsjcppLog::info(TAG, "Start unit-test"); + WsjcppLog::info(TAG, "Do before unit-test"); + if (!doBeforeTest()) { + fail("Problem with before unit-test"); return false; } - return true; + WsjcppLog::info(TAG, "Execute unit-test"); + try { + executeTest(); + } catch(const std::exception& e) { + fail(e.what()); + } catch(...) { + + } + if (m_bTestResult) { + ok("Test passed."); + } else { + fail("Test failed."); + } + WsjcppLog::info(TAG, "Do after unit-test"); + if (!doAfterTest()) { + fail("Problem with after unit-test"); + } + WsjcppLog::info(TAG, "End unit-test"); + return m_bTestResult; } // --------------------------------------------------------------------- -void WsjcppUnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) { - if (bValue != bExpected) { - WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'"); - bTestSuccess = false; +bool WsjcppUnitTestBase::compareD(const std::string &sMark, double nValue, double nExpected) { + if (abs(nValue - nExpected) > std::numeric_limits::epsilon()) { + fail(" {" + sMark + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'"); + return false; } + return true; } // --------------------------------------------------------------------- @@ -71,7 +89,7 @@ void WsjcppUnitTests::addUnitTest(const std::string &sTestName, WsjcppUnitTestBa bool bFound = false; for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) { WsjcppUnitTestBase* p = g_pWsjcppUnitTests->at(i); - if (p->name() == sTestName) { + if (p->getName() == sTestName) { bFound = true; } } diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h index 7892271..c2d8eff 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h @@ -1,25 +1,35 @@ #ifndef WSJCPP_UNIT_TESTS_H #define WSJCPP_UNIT_TESTS_H -#include -#include #include +#include class WsjcppUnitTestBase { public: WsjcppUnitTestBase(const std::string &sTestName); - std::string name(); - virtual void init() = 0; - virtual bool run() = 0; + std::string getName(); + void ok(const std::string &sSuccessMessage); + void fail(const std::string &sFailedMessage); + bool runTest(); + + virtual bool doBeforeTest() = 0; + virtual void executeTest() = 0; + virtual bool doAfterTest() = 0; protected: std::string TAG; - - void compareS(bool &bTestSuccess, const std::string &sPoint, const std::string &sValue, const std::string &sExpected); - bool compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected); - bool compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected); - void compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected); - + + bool compareD(const std::string &sMark, double nValue, double nExpected); + template bool compare(const std::string &sMark, T1 tGotValue, T2 tExpectedValue) { + if (tGotValue != tExpectedValue) { + std::stringstream ss; + ss << " {mark: " << sMark << "} Expected '" << tExpectedValue << "', but got '" << tGotValue << "'"; + fail(ss.str()); + return false; + } + return true; + } private: + bool m_bTestResult; std::string m_sTestName; }; @@ -32,7 +42,7 @@ class WsjcppUnitTests { }; // RegistryCmdHandler -#define REGISTRY_UNIT_TEST( classname ) \ +#define REGISTRY_WSJCPP_UNIT_TEST( classname ) \ static classname * pRegistryWsjcppUnitTest ## classname = new classname(); \ diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp index 23fb13c..c66e9d2 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp @@ -32,20 +32,21 @@ int main(int argc, char** argv) { if (argc == 1) { int nAll = g_pWsjcppUnitTests->size(); - WsjcppLog::info("runUnitTests", "All tests count " + std::to_string(nAll)); + WsjcppLog::info(TAG, "All tests count " + std::to_string(nAll)); int nSuccess = 0; for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) { WsjcppUnitTestBase* pUnitTest = g_pWsjcppUnitTests->at(i); - std::string sTestName = pUnitTest->name(); - WsjcppLog::info("runUnitTests", "Run test " + sTestName); - if (pUnitTest->run()) { - WsjcppLog::ok(sTestName, "Test passed"); + if (pUnitTest->runTest()) { nSuccess++; - } else { - WsjcppLog::err(sTestName, "Test failed"); } } - WsjcppLog::info(TAG, "Passed tests " + std::to_string(nSuccess) + " / " + std::to_string(nAll)); + if (nSuccess == nAll) { + WsjcppLog::ok(TAG, "All unit-tests passed " + std::to_string(nSuccess) + " / " + std::to_string(nAll)); + } else { + WsjcppLog::warn(TAG, "Passed unit-tests " + std::to_string(nSuccess) + " / " + std::to_string(nAll)); + WsjcppLog::err(TAG, std::to_string(nAll - nSuccess) + " unit-test(s) failed."); + } + bool bResult = nSuccess == nAll; return bResult ? 0 : -1; } else if (argc == 2) { @@ -54,7 +55,7 @@ int main(int argc, char** argv) { std::string sOutput = "\nList of unit-tests:\n"; for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) { WsjcppUnitTestBase* pUnitTest = g_pWsjcppUnitTests->at(i); - sOutput += " - " + pUnitTest->name() + "\n"; + sOutput += " - " + pUnitTest->getName() + "\n"; } WsjcppLog::info(TAG, sOutput); return -1; @@ -70,13 +71,11 @@ int main(int argc, char** argv) { bool bTestFound = false; for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) { WsjcppUnitTestBase* pUnitTest = g_pWsjcppUnitTests->at(i); - if (pUnitTest->name() == sArg3) { + if (pUnitTest->getName() == sArg3) { bTestFound = true; - if (pUnitTest->run()) { - WsjcppLog::ok(TAG, pUnitTest->name() + " Test passed"); + bool bResult = pUnitTest->runTest(); + if (bResult) { nSuccess++; - } else { - WsjcppLog::err(TAG, pUnitTest->name() + " Test failed"); } } } diff --git a/unit-tests.wsjcpp/CMakeLists.txt b/unit-tests.wsjcpp/CMakeLists.txt index e522503..ce5d14c 100644 --- a/unit-tests.wsjcpp/CMakeLists.txt +++ b/unit-tests.wsjcpp/CMakeLists.txt @@ -1,8 +1,8 @@ -# Automaticly generated by wsjcpp@v0.1.5 +# Automaticly generated by wsjcpp@v0.1.6 cmake_minimum_required(VERSION 3.0) project(unit-tests C CXX) -add_definitions(-DWSJCPP_APP_VERSION="ut-v0.2.0") +add_definitions(-DWSJCPP_APP_VERSION="ut-v0.2.1") add_definitions(-DWSJCPP_APP_NAME="unit-tests-wsjcpp-arguments") if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -19,7 +19,7 @@ set (WSJCPP_SOURCES "") find_package(Threads REQUIRED) list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) -# wsjcpp-core:v0.1.0 +# wsjcpp-core:v0.2.1 list (APPEND WSJCPP_INCLUDE_DIRS "../src.wsjcpp/wsjcpp_core/") list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp") list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_core.h") @@ -27,7 +27,7 @@ list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp") list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h") list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp") -# wsjcpp-arguments:v0.2.0 +# wsjcpp-arguments:v0.2.1 list (APPEND WSJCPP_INCLUDE_DIRS "../src") list (APPEND WSJCPP_SOURCES "../src/wsjcpp_arguments.cpp") list (APPEND WSJCPP_SOURCES "../src/wsjcpp_arguments.h") diff --git a/unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp b/unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp index a300db6..6413c46 100644 --- a/unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp +++ b/unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp @@ -3,16 +3,8 @@ #include #include -REGISTRY_UNIT_TEST(UnitTestArgumentsWithParams) - -UnitTestArgumentsWithParams::UnitTestArgumentsWithParams() - : WsjcppUnitTestBase("UnitTestArgumentsWithParams") { -} - -// --------------------------------------------------------------------- - - // --------------------------------------------------------------------- +// ArgumentProcessorUninstall class ArgumentProcessorUninstall : public WsjcppArgumentProcessor { public: @@ -61,14 +53,22 @@ class ArgumentProcessorUninstall : public WsjcppArgumentProcessor { // --------------------------------------------------------------------- -void UnitTestArgumentsWithParams::init() { +REGISTRY_WSJCPP_UNIT_TEST(UnitTestArgumentsWithParams) + +UnitTestArgumentsWithParams::UnitTestArgumentsWithParams() + : WsjcppUnitTestBase("UnitTestArgumentsWithParams") { +} + +// --------------------------------------------------------------------- + +bool UnitTestArgumentsWithParams::doBeforeTest() { // nothing + return true; } // --------------------------------------------------------------------- -bool UnitTestArgumentsWithParams::run() { - bool bTestSuccess = true; +void UnitTestArgumentsWithParams::executeTest() { const int argc1 = 5; const char *argv1[argc1] = {"./program", "-v", "uninstall", "1", "2"}; @@ -84,6 +84,12 @@ bool UnitTestArgumentsWithParams::run() { // compareB(bTestSuccess, "canHandle-2", args2.canHandle(), false); // compareN(bTestSuccess, "handle-2", args2.handle(), -1); - return bTestSuccess; +} + +// --------------------------------------------------------------------- + +bool UnitTestArgumentsWithParams::doAfterTest() { + // nothing + return true; } diff --git a/unit-tests.wsjcpp/src/unit_test_arguments_with_params.h b/unit-tests.wsjcpp/src/unit_test_arguments_with_params.h index dfc6ff7..f56d652 100644 --- a/unit-tests.wsjcpp/src/unit_test_arguments_with_params.h +++ b/unit-tests.wsjcpp/src/unit_test_arguments_with_params.h @@ -7,8 +7,9 @@ class UnitTestArgumentsWithParams : public WsjcppUnitTestBase { public: UnitTestArgumentsWithParams(); - virtual void init(); - virtual bool run(); + virtual bool doBeforeTest() override; + virtual void executeTest() override; + virtual bool doAfterTest() override; }; #endif // UNIT_TEST_ARGUMENTS_WITH_PARAMS_H diff --git a/unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp b/unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp index 6107fb3..2154cf6 100644 --- a/unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp +++ b/unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp @@ -3,20 +3,8 @@ #include #include -REGISTRY_UNIT_TEST(UnitTestSimpleArguments) - -UnitTestSimpleArguments::UnitTestSimpleArguments() - : WsjcppUnitTestBase("UnitTestSimpleArguments") { -} - -// --------------------------------------------------------------------- - -void UnitTestSimpleArguments::init() { - // nothing -} - - // --------------------------------------------------------------------- +// ArgumentProcessorInstall class ArgumentProcessorInstall : public WsjcppArgumentProcessor { public: @@ -180,28 +168,43 @@ int ArgumentProcessorProgram1::exec(const std::vector &vRoutes, con return 0; }; +// --------------------------------------------------------------------- +// UnitTestSimpleArguments + +REGISTRY_WSJCPP_UNIT_TEST(UnitTestSimpleArguments) + +UnitTestSimpleArguments::UnitTestSimpleArguments() + : WsjcppUnitTestBase("UnitTestSimpleArguments") { +} + +// --------------------------------------------------------------------- + +bool UnitTestSimpleArguments::doBeforeTest() { + // nothing + return true; +} + // --------------------------------------------------------------------- -bool UnitTestSimpleArguments::run() { - bool bTestSuccess = true; +void UnitTestSimpleArguments::executeTest() { const int argc1 = 8; const char *argv1[argc1] = {"./program", "--hello", "--hello2", "--hello3", "install", "--silent", "p1", "p2"}; ArgumentProcessorProgram1 *pProgram1 = new ArgumentProcessorProgram1(); WsjcppArguments args1(argc1, argv1, pProgram1); - compareN(bTestSuccess, "args1 exec", args1.exec(), 0); - compareB(bTestSuccess, "args1 --hello", pProgram1->hello, true); - compareB(bTestSuccess, "args1 --hello2", pProgram1->hello2, true); - compareB(bTestSuccess, "args1 --hello3", pProgram1->hello3, true); - - compareS(bTestSuccess, "args1 -param1", pProgram1->param1, ""); - compareS(bTestSuccess, "args1 -param2", pProgram1->param2, ""); - compareS(bTestSuccess, "args1 -h", pProgram1->h, ""); - - compareB(bTestSuccess, "args1 install --silent", pProgram1->pInstall->silent, true); - compareN(bTestSuccess, "args1 install arguments size", pProgram1->pInstall->vParams.size(), 2); - compareS(bTestSuccess, "args1 install argument 1", pProgram1->pInstall->vParams[0], "p1"); - compareS(bTestSuccess, "args1 install argument 2", pProgram1->pInstall->vParams[1], "p2"); + compare("args1 exec", args1.exec(), 0); + compare("args1 --hello", pProgram1->hello, true); + compare("args1 --hello2", pProgram1->hello2, true); + compare("args1 --hello3", pProgram1->hello3, true); + + compare("args1 -param1", pProgram1->param1, ""); + compare("args1 -param2", pProgram1->param2, ""); + compare("args1 -h", pProgram1->h, ""); + + compare("args1 install --silent", pProgram1->pInstall->silent, true); + compare("args1 install arguments size", pProgram1->pInstall->vParams.size(), 2); + compare("args1 install argument 1", pProgram1->pInstall->vParams[0], "p1"); + compare("args1 install argument 2", pProgram1->pInstall->vParams[1], "p2"); pProgram1->reset(); @@ -209,17 +212,17 @@ bool UnitTestSimpleArguments::run() { const char *argv2[argc2] = {"./program", "--hello", "-param1", "p1", "-param2", "p2", "arg1", "arg2"}; WsjcppArguments args2(argc2, argv2, pProgram1); - compareN(bTestSuccess, "args2 exec", args2.exec(), 0); - compareB(bTestSuccess, "args2 --hello", pProgram1->hello, true); - compareB(bTestSuccess, "args2 --hello2", pProgram1->hello2, false); - compareB(bTestSuccess, "args2 --hello3", pProgram1->hello3, false); - - compareS(bTestSuccess, "args2 -param1", pProgram1->param1, "p1"); - compareS(bTestSuccess, "args2 -param2", pProgram1->param2, "p2"); - compareS(bTestSuccess, "args2 -h", pProgram1->h, ""); - compareN(bTestSuccess, "args2 arguments size", pProgram1->vParams.size(), 2); - compareS(bTestSuccess, "args2 argument 2", pProgram1->vParams[0], "arg1"); - compareS(bTestSuccess, "args2 argument 2", pProgram1->vParams[1], "arg2"); + compare("args2 exec", args2.exec(), 0); + compare("args2 --hello", pProgram1->hello, true); + compare("args2 --hello2", pProgram1->hello2, false); + compare("args2 --hello3", pProgram1->hello3, false); + + compare("args2 -param1", pProgram1->param1, "p1"); + compare("args2 -param2", pProgram1->param2, "p2"); + compare("args2 -h", pProgram1->h, ""); + compare("args2 arguments size", pProgram1->vParams.size(), 2); + compare("args2 argument 2", pProgram1->vParams[0], "arg1"); + compare("args2 argument 2", pProgram1->vParams[1], "arg2"); pProgram1->reset(); @@ -227,23 +230,27 @@ bool UnitTestSimpleArguments::run() { const char *argv3[argc3] = {"./program", "--hello", "i", "--silent", "some1", "some2"}; WsjcppArguments args3(argc3, argv3, pProgram1); - compareN(bTestSuccess, "args3 exec", args3.exec(), 0); + compare("args3 exec", args3.exec(), 0); - compareB(bTestSuccess, "args3 --hello", pProgram1->hello, true); - compareB(bTestSuccess, "args3 --hello2", pProgram1->hello2, false); - compareB(bTestSuccess, "args3 --hello3", pProgram1->hello3, false); + compare("args3 --hello", pProgram1->hello, true); + compare("args3 --hello2", pProgram1->hello2, false); + compare("args3 --hello3", pProgram1->hello3, false); - compareS(bTestSuccess, "args3 -param1", pProgram1->param1, ""); - compareS(bTestSuccess, "args3 -param2", pProgram1->param2, ""); + compare("args3 -param1", pProgram1->param1, ""); + compare("args3 -param2", pProgram1->param2, ""); - compareB(bTestSuccess, "args3 install --silent", pProgram1->pInstall->silent, true); - compareN(bTestSuccess, "args3 install arguments size", pProgram1->pInstall->vParams.size(), 2); - compareS(bTestSuccess, "args3 install argument 1", pProgram1->pInstall->vParams[0], "some1"); - compareS(bTestSuccess, "args3 install argument 2", pProgram1->pInstall->vParams[1], "some2"); + compare("args3 install --silent", pProgram1->pInstall->silent, true); + compare("args3 install arguments size", pProgram1->pInstall->vParams.size(), 2); + compare("args3 install argument 1", pProgram1->pInstall->vParams[0], "some1"); + compare("args3 install argument 2", pProgram1->pInstall->vParams[1], "some2"); // WsjcppLog::info(TAG, "\r\n" + args2.help()); - - return bTestSuccess; } +// --------------------------------------------------------------------- + +bool UnitTestSimpleArguments::doAfterTest() { + // nothing + return true; +} diff --git a/unit-tests.wsjcpp/src/unit_test_simple_arguments.h b/unit-tests.wsjcpp/src/unit_test_simple_arguments.h index 43fcd69..fe6a32a 100644 --- a/unit-tests.wsjcpp/src/unit_test_simple_arguments.h +++ b/unit-tests.wsjcpp/src/unit_test_simple_arguments.h @@ -7,8 +7,9 @@ class UnitTestSimpleArguments : public WsjcppUnitTestBase { public: UnitTestSimpleArguments(); - virtual void init(); - virtual bool run(); + virtual bool doBeforeTest() override; + virtual void executeTest() override; + virtual bool doAfterTest() override; }; #endif // UNIT_TEST_SIMPLE_ARGUMENTS_H diff --git a/wsjcpp.yml b/wsjcpp.yml index 4cb3ec8..cfd94f8 100644 --- a/wsjcpp.yml +++ b/wsjcpp.yml @@ -3,7 +3,7 @@ cmake_cxx_standard: 11 cmake_minimum_required: 3.0 name: wsjcpp-arguments -version: v0.2.0 +version: v0.2.1 description: Helpful parser for parsing application arguments issues: https://github.com/wsjcpp/wsjcpp-arguments/issues @@ -25,7 +25,7 @@ required-libraries: dependencies: - name: "wsjcpp-core" - version: "v0.1.0" + version: "v0.2.1" url: "https://github.com/wsjcpp/wsjcpp-core:master" origin: "https://github.com/" installation-dir: "./src.wsjcpp/wsjcpp_core"