From dadacec64327972d757678ca6436e38cf1e7b845 Mon Sep 17 00:00:00 2001 From: Evgenii Sopov Date: Sun, 5 Apr 2020 18:30:40 +0700 Subject: [PATCH] Updated wsjcpp-core --- src.wsjcpp/CMakeLists.txt | 4 +- src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml | 32 +- src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp | 401 +++++++++++++----- src.wsjcpp/wsjcpp_core/wsjcpp_core.h | 40 +- src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp | 66 +-- src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h | 15 +- .../wsjcpp_core/wsjcpp_unit_tests_main.cpp | 88 +++- unit-tests.wsjcpp/CMakeLists.txt | 8 +- unit-tests.wsjcpp/CMakeLists.user-custom.txt | 2 + wsjcpp.yml | 6 +- 10 files changed, 469 insertions(+), 193 deletions(-) create mode 100644 unit-tests.wsjcpp/CMakeLists.user-custom.txt diff --git a/src.wsjcpp/CMakeLists.txt b/src.wsjcpp/CMakeLists.txt index acc2c00..48f6f69 100644 --- a/src.wsjcpp/CMakeLists.txt +++ b/src.wsjcpp/CMakeLists.txt @@ -1,7 +1,7 @@ # Automaticly generated by wsjcpp@v0.0.1 cmake_minimum_required(VERSION 3.0) -add_definitions(-DWSJCPP_VERSION="v0.0.1") +add_definitions(-DWSJCPP_VERSION="v0.1.0") add_definitions(-DWSJCPP_NAME="wsjcpp-print-tree") 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.0.5 +# wsjcpp-core:v0.1.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/wsjcpp.hold.yml b/src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml index cfb813f..1d20668 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.0.5 +version: v0.1.1 description: Basic Utils for wsjcpp issues: https://github.com/wsjcpp/wsjcpp-core/issues repositories: @@ -17,30 +17,22 @@ authors: - name: Evgenii Sopov email: mrseakg@gmail.com -required-libraries: - - pthread - distribution: - source-file: src/wsjcpp_core.cpp target-file: wsjcpp_core.cpp - sha1: "d892bfee196af88dcada57b39bc6bd65ce2ce075" type: "source-code" - source-file: src/wsjcpp_core.h target-file: wsjcpp_core.h - sha1: "8f5e7b7ada06814ed123a08e49acffe2e12d398a" type: "source-code" # todo must be header-file - source-file: "src/wsjcpp_unit_tests.cpp" target-file: "wsjcpp_unit_tests.cpp" type: "unit-tests" - sha1: "4208e039ec2923636655b3ada79ec223cca7bae2" - source-file: "src/wsjcpp_unit_tests.h" target-file: "wsjcpp_unit_tests.h" type: "unit-tests" - sha1: "8d2ec886f23161a639bb2419bb5e4af48278f18b" - source-file: "src/wsjcpp_unit_tests_main.cpp" target-file: "wsjcpp_unit_tests_main.cpp" type: "unit-tests" - sha1: "2c02fb58f51687eeac2076096b7df698cc246c9d" unit-tests: cases: @@ -54,3 +46,25 @@ unit-tests: description: "String to upper" - name: "CreateUuid" description: "Test generation uuids" + - name: "GetEnv" + description: "Test getEnv function" + - name: "ToLower" + description: "Test toLower" + - name: "ReplaceAll" + description: "Test replace all" + - name: "DecodeUriComponent" + description: "Check decoding" + - name: "EncodeUriComponent" + description: "Check encoding" + - name: "Uint2HexString" + description: "Test convert unsigned int to hex string" + - name: "Split" + description: "Test split function" + - name: "CreateEmptyFile" + description: "Test create empty file" + - name: "ReadFileToBuffer" + description: "test for readFileToBuffer" + - name: "Join" + description: "Test join function" + - name: "getHumanSizeBytes" + description: "Test function get human size in bytes" diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp b/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp index c2c23c1..0256d53 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp @@ -18,30 +18,27 @@ #include #include #include +#include // --------------------------------------------------------------------- +// WsjcppCore -bool WSJCppCore::init(int argc, const char** argv, bool bInitLogDir = true) { - std::string appName = std::string(WSJCPP_NAME); - std::string appVersion = std::string(WSJCPP_VERSION); - // std::string appAuthor = std::string(WSJCPP_AUTHORS); - - if (bInitLogDir) { - std::string appLogPath = ".logs"; - if (!WSJCppCore::dirExists(appLogPath)) { - WSJCppCore::makeDir(appLogPath); - } - WSJCppLog::setPrefixLogFile(appName); - WSJCppLog::setLogDirectory(".logs"); - } +bool WsjcppCore::init( + int argc, char** argv, + const std::string &sApplicationName, + const std::string &sApplicationVersion, + const std::string &sApplicationAuthor, + const std::string &sLibraryNameForExports +) { // init random std::srand(std::rand() + std::time(0)); + // WsjcppCore::initRandom(); return true; } // --------------------------------------------------------------------- -std::string WSJCppCore::doNormalizePath(const std::string & sPath) { +std::string WsjcppCore::doNormalizePath(const std::string & sPath) { // split path by / std::vector vNames; std::string s = ""; @@ -103,7 +100,7 @@ std::string WSJCppCore::doNormalizePath(const std::string & sPath) { // --------------------------------------------------------------------- -std::string WSJCppCore::extractFilename(const std::string &sPath) { +std::string WsjcppCore::extractFilename(const std::string &sPath) { // split path by / std::vector vNames; std::string s = ""; @@ -131,32 +128,32 @@ std::string WSJCppCore::extractFilename(const std::string &sPath) { // --------------------------------------------------------------------- -std::string WSJCppCore::getCurrentDirectory() { +std::string WsjcppCore::getCurrentDirectory() { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == NULL) { - WSJCppLog::throw_err("getCurrentDirectory", "Could not get current directory"); + WsjcppLog::throw_err("getCurrentDirectory", "Could not get current directory"); } return std::string(cwd) + "/"; } // --------------------------------------------------------------------- -long WSJCppCore::currentTime_milliseconds() { +long WsjcppCore::currentTime_milliseconds() { long nTimeStart = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); return nTimeStart; } // --------------------------------------------------------------------- -long WSJCppCore::currentTime_seconds() { +long WsjcppCore::currentTime_seconds() { 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::currentTime_logformat() { + long nTimeStart = WsjcppCore::currentTime_milliseconds(); std::string sMilliseconds = std::to_string(int(nTimeStart % 1000)); nTimeStart = nTimeStart / 1000; @@ -173,7 +170,7 @@ std::string WSJCppCore::currentTime_logformat() { // --------------------------------------------------------------------- -std::string WSJCppCore::threadId() { +std::string WsjcppCore::threadId() { std::thread::id this_id = std::this_thread::get_id(); std::stringstream stream; stream << std::hex << this_id; @@ -182,7 +179,7 @@ std::string WSJCppCore::threadId() { // --------------------------------------------------------------------- -std::string WSJCppCore::formatTimeForWeb(long nTimeInSec) { +std::string WsjcppCore::formatTimeForWeb(long nTimeInSec) { std::time_t tm_ = long(nTimeInSec); // struct tm tstruct = *localtime(&tm_); struct tm tstruct = *gmtime ( &tm_ ); @@ -198,14 +195,14 @@ std::string WSJCppCore::formatTimeForWeb(long nTimeInSec) { // --------------------------------------------------------------------- -std::string WSJCppCore::currentTime_forFilename() { - long nTimeStart = WSJCppCore::currentTime_seconds(); - return WSJCppCore::formatTimeForFilename(nTimeStart); +std::string WsjcppCore::currentTime_forFilename() { + long nTimeStart = WsjcppCore::currentTime_seconds(); + return WsjcppCore::formatTimeForFilename(nTimeStart); } // --------------------------------------------------------------------- -std::string WSJCppCore::formatTimeForFilename(long nTimeInSec) { +std::string WsjcppCore::formatTimeForFilename(long nTimeInSec) { std::time_t tm_ = long(nTimeInSec); // struct tm tstruct = *localtime(&tm_); struct tm tstruct = *gmtime ( &tm_ ); @@ -219,7 +216,7 @@ std::string WSJCppCore::formatTimeForFilename(long nTimeInSec) { // --------------------------------------------------------------------- -std::string WSJCppCore::formatTimeUTC(int nTimeInSec) { +std::string WsjcppCore::formatTimeUTC(int nTimeInSec) { // datetime std::time_t tm_ = long(nTimeInSec); // struct tm tstruct = *localtime(&tm_); @@ -234,7 +231,7 @@ std::string WSJCppCore::formatTimeUTC(int nTimeInSec) { // --------------------------------------------------------------------- -bool WSJCppCore::fileExists(const std::string &sFilename) { +bool WsjcppCore::fileExists(const std::string &sFilename) { struct stat st; bool bExists = (stat(sFilename.c_str(), &st) == 0); if (bExists) { @@ -245,7 +242,7 @@ bool WSJCppCore::fileExists(const std::string &sFilename) { // --------------------------------------------------------------------- -bool WSJCppCore::dirExists(const std::string &sDirname) { +bool WsjcppCore::dirExists(const std::string &sDirname) { struct stat st; bool bExists = (stat(sDirname.c_str(), &st) == 0); if (bExists) { @@ -256,9 +253,9 @@ bool WSJCppCore::dirExists(const std::string &sDirname) { // --------------------------------------------------------------------- -std::vector WSJCppCore::listOfDirs(const std::string &sDirname) { +std::vector WsjcppCore::listOfDirs(const std::string &sDirname) { std::vector vDirs; - if (!WSJCppCore::dirExists(sDirname)) { + if (!WsjcppCore::dirExists(sDirname)) { return vDirs; } DIR *dir = opendir(sDirname.c_str()); @@ -278,9 +275,9 @@ std::vector WSJCppCore::listOfDirs(const std::string &sDirname) { // --------------------------------------------------------------------- -std::vector WSJCppCore::listOfFiles(const std::string &sDirname) { +std::vector WsjcppCore::listOfFiles(const std::string &sDirname) { std::vector vFiles; - if (!WSJCppCore::dirExists(sDirname)) { + if (!WsjcppCore::dirExists(sDirname)) { return vFiles; } DIR *dir = opendir(sDirname.c_str()); @@ -300,7 +297,7 @@ std::vector WSJCppCore::listOfFiles(const std::string &sDirname) { // --------------------------------------------------------------------- -bool WSJCppCore::makeDir(const std::string &sDirname) { +bool WsjcppCore::makeDir(const std::string &sDirname) { struct stat st; int nStatus = mkdir(sDirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (nStatus == 0) { @@ -316,12 +313,12 @@ bool WSJCppCore::makeDir(const std::string &sDirname) { // --------------------------------------------------------------------- -bool WSJCppCore::writeFile(const std::string &sFilename, const std::string &sContent) { +bool WsjcppCore::writeFile(const std::string &sFilename, const std::string &sContent) { // std::ofstream f(sFilename, std::ifstream::in); std::ofstream f(sFilename, std::ios::out); if (!f) { - WSJCppLog::err("WSJCppCore", "Could not create file to write '" + sFilename + "'"); + WsjcppLog::err("WsjcppCore", "Could not create file to write '" + sFilename + "'"); return false; } f << sContent << std::endl; @@ -331,7 +328,7 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const std::string &sCon // --------------------------------------------------------------------- -bool WSJCppCore::readTextFile(const std::string &sFilename, std::string &sContent) { +bool WsjcppCore::readTextFile(const std::string &sFilename, std::string &sContent) { std::ifstream f(sFilename); if (!f) { @@ -349,7 +346,34 @@ bool WSJCppCore::readTextFile(const std::string &sFilename, std::string &sConten // --------------------------------------------------------------------- -bool WSJCppCore::writeFile(const std::string &sFilename, const char *pBuffer, const int nBufferSize) { +bool WsjcppCore::readFileToBuffer(const std::string &sFilename, char *pBuffer[], int &nBufferSize) { + std::ifstream f(sFilename, std::ifstream::binary); + if (!f) { + return false; + } + + // get length of file: + f.seekg (0, f.end); + nBufferSize = f.tellg(); + f.seekg (0, f.beg); + + *pBuffer = new char [nBufferSize]; + + // read data as a block: + f.read (*pBuffer, nBufferSize); + if (!f) { + WsjcppLog::err("WsjcppCore::readFileToBuffer", "Only " + std::to_string(f.gcount()) + " could be read"); + delete[] pBuffer; + f.close(); + return false; + } + f.close(); + return true; +} + +// --------------------------------------------------------------------- + +bool WsjcppCore::writeFile(const std::string &sFilename, const char *pBuffer, const int nBufferSize) { std::ofstream f(sFilename, std::ios::out | std::ios::binary); if (!f) { std::cout << "FAILED could not create file to wtite " << sFilename << std::endl; @@ -362,41 +386,58 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const char *pBuffer, co // --------------------------------------------------------------------- -bool WSJCppCore::removeFile(const std::string &sFilename) { +bool WsjcppCore::removeFile(const std::string &sFilename) { return remove(sFilename.c_str()) == 0; } // --------------------------------------------------------------------- -std::string& WSJCppCore::ltrim(std::string& str, const std::string& chars) { +bool WsjcppCore::createEmptyFile(const std::string &sFilename) { + if (WsjcppCore::fileExists(sFilename)) { + return false; + } + std::ofstream f(sFilename, std::ios::out | std::ios::binary); + if (!f) { + std::cout << "FAILED could not create file to wtite " << sFilename << std::endl; + return false; + } + f.close(); + return true; +} + +// --------------------------------------------------------------------- + +std::string& WsjcppCore::ltrim(std::string& str, const std::string& chars) { str.erase(0, str.find_first_not_of(chars)); return str; } // --------------------------------------------------------------------- -std::string& WSJCppCore::rtrim(std::string& str, const std::string& chars) { +std::string& WsjcppCore::rtrim(std::string& str, const std::string& chars) { str.erase(str.find_last_not_of(chars) + 1); return str; } // --------------------------------------------------------------------- -std::string& WSJCppCore::trim(std::string& str, const std::string& chars) { - return WSJCppCore::ltrim(WSJCppCore::rtrim(str, chars), chars); +std::string& WsjcppCore::trim(std::string& str, const std::string& chars) { + return WsjcppCore::ltrim(WsjcppCore::rtrim(str, chars), chars); } // --------------------------------------------------------------------- +// will worked only with latin -std::string& WSJCppCore::to_lower(std::string& str) { - std::transform(str.begin(), str.end(), str.begin(), ::tolower); - return str; +std::string WsjcppCore::toLower(const std::string& str) { + std::string sRet = str; + std::transform(sRet.begin(), sRet.end(), sRet.begin(), ::tolower); + return sRet; } // --------------------------------------------------------------------- // will worked only with latin -std::string WSJCppCore::toUpper(const std::string& str) { +std::string WsjcppCore::toUpper(const std::string& str) { std::string sRet = str; std::transform(sRet.begin(), sRet.end(), sRet.begin(), ::toupper); return sRet; @@ -404,13 +445,64 @@ std::string WSJCppCore::toUpper(const std::string& str) { // --------------------------------------------------------------------- -void WSJCppCore::initRandom() { +void WsjcppCore::replaceAll(std::string& str, const std::string& sFrom, const std::string& sTo) { + if (sFrom.empty()) { + return; + } + size_t start_pos = 0; + while ((start_pos = str.find(sFrom, start_pos)) != std::string::npos) { + str.replace(start_pos, sFrom.length(), sTo); + start_pos += sTo.length(); // In case 'to' contains 'sFrom', like replacing 'x' with 'yx' + } +} + +// --------------------------------------------------------------------- + +std::vector WsjcppCore::split(const std::string& sWhat, const std::string& sDelim) { + std::vector vRet; + int nPos = 0; + int nLen = sWhat.length(); + int nDelimLen = sDelim.length(); + while (nPos < nLen) { + std::size_t nFoundPos = sWhat.find(sDelim, nPos); + if (nFoundPos != std::string::npos) { + std::string sToken = sWhat.substr(nPos, nFoundPos - nPos); + vRet.push_back(sToken); + nPos = nFoundPos + nDelimLen; + if (nFoundPos + nDelimLen == nLen) { // last delimiter + vRet.push_back(""); + } + } else { + std::string sToken = sWhat.substr(nPos, nLen - nPos); + vRet.push_back(sToken); + break; + } + } + return vRet; +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::join(const std::vector &vWhat, const std::string& sDelim) { + std::string sRet; + for (int i = 0; i < vWhat.size(); i++) { + if (i != 0) { + sRet += sDelim; + } + sRet += vWhat[i]; + } + return sRet; +} + +// --------------------------------------------------------------------- + +void WsjcppCore::initRandom() { std::srand(std::rand() + std::time(0)); } // --------------------------------------------------------------------- -std::string WSJCppCore::createUuid() { +std::string WsjcppCore::createUuid() { std::string sRet = "00000000-0000-0000-0000-000000000000"; const std::string sAlphabet = "0123456789abcdef"; // unsigned t = std::time(0); @@ -425,14 +517,25 @@ std::string WSJCppCore::createUuid() { // --------------------------------------------------------------------- -unsigned long WSJCppCore::convertVoidToULong(void *p) { - unsigned long ret = *(unsigned long *)p; - return ret; +std::string WsjcppCore::uint2hexString(unsigned int n) { + std::string sRet; + for (int i = 0; i < 8; i++) { + sRet += "0123456789abcdef"[n % 16]; + n >>= 4; + } + return std::string(sRet.rbegin(), sRet.rend()); +} + +// --------------------------------------------------------------------- + +unsigned long WsjcppCore::convertVoidToULong(void *p) { + std::uintptr_t ret = reinterpret_cast(p); + return (unsigned long)ret; } // --------------------------------------------------------------------- -std::string WSJCppCore::getPointerAsHex(void *p) { +std::string WsjcppCore::getPointerAsHex(void *p) { std::uintptr_t i = reinterpret_cast(p); std::stringstream stream; stream << std::hex << i; @@ -440,70 +543,162 @@ std::string WSJCppCore::getPointerAsHex(void *p) { } // --------------------------------------------------------------------- -// WSJCppLog + +std::string WsjcppCore::extractURLProtocol(const std::string& sValue) { + std::string sRet = ""; + int nPosProtocol = sValue.find("://"); + if (nPosProtocol == std::string::npos) { + return sRet; + } + sRet = sValue.substr(0, nPosProtocol); + return sRet; +} + +// --------------------------------------------------------------------- + +bool WsjcppCore::getEnv(const std::string& sName, std::string& sValue) { + if (const char* env_p = std::getenv(sName.c_str())) { + sValue = std::string(env_p); + return true; + } + return false; +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::encodeUriComponent(const std::string& sValue) { + std::stringstream ssRet; + for (int i = 0; i < sValue.length(); i++) { + char c = sValue[i]; + if ( + c == '-' || c == '_' || c == '.' || c == '!' + || c == '~' || c == '*' || c == '\'' + || c == '(' || c == ')' || (c >= '0' && c <= '9') + || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') + ) { + ssRet << c; + } else { + ssRet << '%' << std::uppercase << std::hex << (int)c; + } + } + return ssRet.str(); +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::decodeUriComponent(const std::string& sValue) { + std::string sRet = ""; + std::string sHex = ""; + int nLen = sValue.length(); + for (int i = 0; i < sValue.length(); i++) { + char c = sValue[i]; + if (c == '%') { + if (i+2 >= nLen) { + WsjcppLog::throw_err("WsjcppCore::decodeUriElement", "Wrong format of string"); + } + sHex = "0x"; + sHex += sValue[i+1]; + sHex += sValue[i+2]; + i = i + 2; + char c1 = std::stoul(sHex, nullptr, 16); + sRet += c1; + } else { + sRet += c; + } + } + return sRet; +} + +// --------------------------------------------------------------------- + +std::string WsjcppCore::getHumanSizeBytes(long nBytes) { + if (nBytes == 0) { + return "0B"; + } + std::string arrPrefix[] = {"B", "KB", "MB", "GB", "TB", "PB"}; + long n0 = nBytes; + long n1 = 0; + for (int i = 0; i < 6; i++) { + if (n0 >= 1 && n0 < 1000) { + return std::to_string(n0) + arrPrefix[i]; + } + n0 = nBytes / 1000; + n1 = nBytes - n0 * 1000; + n0 += n1 >= 500 ? 1 : 0; + + nBytes = nBytes / 1000; + if (n0 == 0 && n1 == 0) { + return "fuck"; + } + } + return std::to_string(nBytes) + "PB"; +} + +// --------------------------------------------------------------------- +// 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; +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; // --------------------------------------------------------------------- -void WSJCppLog::doLogRotateUpdateFilename(bool bForce) { - long t = WSJCppCore::currentTime_seconds(); +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"; + + WsjcppLog::g_WSJCPP_LOG_PREFIX_FILE + "_" + + WsjcppCore::formatTimeForFilename(g_WSJCPP_LOG_START_TIME) + ".log"; } } // --------------------------------------------------------------------- -void WSJCppLog::info(const std::string & sTag, const std::string &sMessage) { - WSJCppColorModifier def(WSJCppColorCode::FG_DEFAULT); - WSJCppLog::add(def, "INFO", sTag, sMessage); +void WsjcppLog::info(const std::string & sTag, const std::string &sMessage) { + WsjcppColorModifier def(WsjcppColorCode::FG_DEFAULT); + WsjcppLog::add(def, "INFO", sTag, sMessage); } // --------------------------------------------------------------------- -void WSJCppLog::err(const std::string & sTag, const std::string &sMessage) { - WSJCppColorModifier red(WSJCppColorCode::FG_RED); - WSJCppLog::add(red, "ERR", sTag, sMessage); +void WsjcppLog::err(const std::string & sTag, const std::string &sMessage) { + WsjcppColorModifier red(WsjcppColorCode::FG_RED); + WsjcppLog::add(red, "ERR", sTag, sMessage); } // --------------------------------------------------------------------- -void WSJCppLog::throw_err(const std::string &sTag, const std::string &sMessage) { - WSJCppColorModifier red(WSJCppColorCode::FG_RED); - WSJCppLog::add(red, "ERR", sTag, sMessage); +void WsjcppLog::throw_err(const std::string &sTag, const std::string &sMessage) { + WsjcppColorModifier red(WsjcppColorCode::FG_RED); + WsjcppLog::add(red, "ERR", sTag, sMessage); throw std::runtime_error(sMessage); } // --------------------------------------------------------------------- -void WSJCppLog::warn(const std::string & sTag, const std::string &sMessage) { - WSJCppColorModifier yellow(WSJCppColorCode::FG_YELLOW); - WSJCppLog::add(yellow, "WARN",sTag, sMessage); +void WsjcppLog::warn(const std::string & sTag, const std::string &sMessage) { + WsjcppColorModifier yellow(WsjcppColorCode::FG_YELLOW); + WsjcppLog::add(yellow, "WARN",sTag, sMessage); } // --------------------------------------------------------------------- -void WSJCppLog::ok(const std::string &sTag, const std::string &sMessage) { - WSJCppColorModifier green(WSJCppColorCode::FG_GREEN); - WSJCppLog::add(green, "OK", sTag, sMessage); +void WsjcppLog::ok(const std::string &sTag, const std::string &sMessage) { + WsjcppColorModifier green(WsjcppColorCode::FG_GREEN); + WsjcppLog::add(green, "OK", sTag, sMessage); } // --------------------------------------------------------------------- -std::vector WSJCppLog::getLastLogMessages() { - WSJCppLog::initGlobalVariables(); - std::lock_guard lock(*WSJCppLog::g_WSJCPP_LOG_MUTEX); +std::vector WsjcppLog::getLastLogMessages() { + WsjcppLog::initGlobalVariables(); + std::lock_guard lock(*WsjcppLog::g_WSJCPP_LOG_MUTEX); 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)); @@ -513,43 +708,43 @@ std::vector WSJCppLog::getLastLogMessages() { // --------------------------------------------------------------------- -void WSJCppLog::setLogDirectory(const std::string &sDirectoryPath) { - WSJCppLog::g_WSJCPP_LOG_DIR = sDirectoryPath; - WSJCppLog::doLogRotateUpdateFilename(true); +void WsjcppLog::setLogDirectory(const std::string &sDirectoryPath) { + WsjcppLog::g_WSJCPP_LOG_DIR = sDirectoryPath; + WsjcppLog::doLogRotateUpdateFilename(true); } // --------------------------------------------------------------------- -void WSJCppLog::setPrefixLogFile(const std::string &sPrefixLogFile) { - WSJCppLog::g_WSJCPP_LOG_PREFIX_FILE = sPrefixLogFile; - WSJCppLog::doLogRotateUpdateFilename(true); +void WsjcppLog::setPrefixLogFile(const std::string &sPrefixLogFile) { + WsjcppLog::g_WSJCPP_LOG_PREFIX_FILE = sPrefixLogFile; + WsjcppLog::doLogRotateUpdateFilename(true); } // --------------------------------------------------------------------- -void WSJCppLog::initGlobalVariables() { +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"; + 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"; + 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::add(WSJCppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage) { - WSJCppLog::initGlobalVariables(); - WSJCppLog::doLogRotateUpdateFilename(); +void WsjcppLog::add(WsjcppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage) { + WsjcppLog::initGlobalVariables(); + WsjcppLog::doLogRotateUpdateFilename(); - std::lock_guard lock(*WSJCppLog::g_WSJCPP_LOG_MUTEX); - WSJCppColorModifier def(WSJCppColorCode::FG_DEFAULT); + std::lock_guard lock(*WsjcppLog::g_WSJCPP_LOG_MUTEX); + WsjcppColorModifier def(WsjcppColorCode::FG_DEFAULT); - std::string sLogMessage = WSJCppCore::currentTime_logformat() + ", " + WSJCppCore::threadId() + std::string sLogMessage = WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::threadId() + " [" + sType + "] " + sTag + ": " + sMessage; std::cout << clr << sLogMessage << def << std::endl; @@ -558,7 +753,7 @@ void WSJCppLog::add(WSJCppColorModifier &clr, const std::string &sType, const st g_WSJCPP_LOG_LAST_MESSAGES->pop_back(); } // TODO try create global variable - std::ofstream logFile(WSJCppLog::g_WSJCPP_LOG_FILE, std::ios::app); + std::ofstream logFile(WsjcppLog::g_WSJCPP_LOG_FILE, std::ios::app); if (!logFile) { std::cout << "Error Opening File" << std::endl; return; diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_core.h b/src.wsjcpp/wsjcpp_core/wsjcpp_core.h index 74ed6b5..4884467 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_core.h +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_core.h @@ -8,9 +8,15 @@ #include #include -class WSJCppCore { +class WsjcppCore { public: - static bool init(int argc, const char** argv, bool bInitLogDir); + static bool init( + int argc, char** argv, + const std::string &sApplicationName, + const std::string &sApplicationVersion, + const std::string &sApplicationAuthor, + const std::string &sLibraryNameForExports + ); static std::string doNormalizePath(const std::string &sPath); static std::string extractFilename(const std::string &sPath); @@ -32,26 +38,38 @@ class WSJCppCore { 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 createEmptyFile(const std::string &sFilename); static std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); static std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); static std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r "); - static std::string& to_lower(std::string& str); + static std::string toLower(const std::string &str); static std::string toUpper(const std::string& str); + static void replaceAll(std::string& str, const std::string& from, const std::string& to); + static std::vector split(const std::string& sWhat, const std::string& sDelim); + static std::string join(const std::vector &vWhat, const std::string& sDelim); static void initRandom(); static std::string createUuid(); - + static std::string uint2hexString(unsigned int n); static unsigned long convertVoidToULong(void *p); static std::string getPointerAsHex(void *p); + static std::string extractURLProtocol(const std::string& sValue); + static bool getEnv(const std::string& sName, std::string& sValue); + + static std::string encodeUriComponent(const std::string& sValue); + static std::string decodeUriComponent(const std::string& sValue); + + static std::string getHumanSizeBytes(long nBytes); }; // --------------------------------------------------------------------- -enum WSJCppColorCode { +enum WsjcppColorCode { FG_RED = 31, FG_GREEN = 32, FG_YELLOW = 93, @@ -65,19 +83,19 @@ enum WSJCppColorCode { // --------------------------------------------------------------------- -class WSJCppColorModifier { - WSJCppColorCode code; +class WsjcppColorModifier { + WsjcppColorCode code; public: - WSJCppColorModifier(WSJCppColorCode pCode) : code(pCode) {} + WsjcppColorModifier(WsjcppColorCode pCode) : code(pCode) {} friend std::ostream& - operator<<(std::ostream& os, const WSJCppColorModifier& mod) { + operator<<(std::ostream& os, const WsjcppColorModifier& mod) { return os << "\033[" << mod.code << "m"; } }; // --------------------------------------------------------------------- -class WSJCppLog { +class WsjcppLog { public: static std::string g_WSJCPP_LOG_DIR; static std::string g_WSJCPP_LOG_PREFIX_FILE; @@ -98,7 +116,7 @@ class WSJCppLog { static void initGlobalVariables(); private: - static void add(WSJCppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage); + static void add(WsjcppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage); }; #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 645833a..d675dac 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp @@ -1,32 +1,32 @@ #include "wsjcpp_unit_tests.h" -WSJCppUnitTestBase::WSJCppUnitTestBase(const std::string &sTestName) { +WsjcppUnitTestBase::WsjcppUnitTestBase(const std::string &sTestName) { m_sTestName = sTestName; TAG = m_sTestName; - WSJCppUnitTests::addUnitTest(sTestName, this); + WsjcppUnitTests::addUnitTest(sTestName, this); } // --------------------------------------------------------------------- -std::string WSJCppUnitTestBase::name() { +std::string WsjcppUnitTestBase::name() { return m_sTestName; } // --------------------------------------------------------------------- -void WSJCppUnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint, +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 + "'"); + WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + sExpected + "', but got '" + sValue + "'"); bTestSuccess = false; } } // --------------------------------------------------------------------- -bool WSJCppUnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) { +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) + "'"); + WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'"); bTestSuccess = false; return false; } @@ -35,9 +35,9 @@ bool WSJCppUnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, // --------------------------------------------------------------------- -bool WSJCppUnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) { +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) + "'"); + WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'"); bTestSuccess = false; return false; } @@ -46,64 +46,42 @@ bool WSJCppUnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, // --------------------------------------------------------------------- -void WSJCppUnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) { +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") + "'"); + WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'"); bTestSuccess = false; } } // --------------------------------------------------------------------- -std::vector *g_pUnitTests = NULL; +std::vector *g_pWsjcppUnitTests = nullptr; -void WSJCppUnitTests::initGlobalVariables() { - if (g_pUnitTests == NULL) { - // Log::info(std::string(), "Create handlers map"); - g_pUnitTests = new std::vector(); +void WsjcppUnitTests::initGlobalVariables() { + if (g_pWsjcppUnitTests == nullptr) { + // WsjcppLog::info(std::string(), "Create handlers map"); + g_pWsjcppUnitTests = new std::vector(); } } // --------------------------------------------------------------------- -void WSJCppUnitTests::addUnitTest(const std::string &sTestName, WSJCppUnitTestBase* pUnitTest) { - WSJCppUnitTests::initGlobalVariables(); +void WsjcppUnitTests::addUnitTest(const std::string &sTestName, WsjcppUnitTestBase* pUnitTest) { + WsjcppUnitTests::initGlobalVariables(); bool bFound = false; - for (int i = 0; i < g_pUnitTests->size(); i++) { - WSJCppUnitTestBase* p = g_pUnitTests->at(i); + for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) { + WsjcppUnitTestBase* p = g_pWsjcppUnitTests->at(i); if (p->name() == sTestName) { bFound = true; } } if (bFound) { - WSJCppLog::err(sTestName, "Already registered"); + WsjcppLog::err(sTestName, "Already registered"); } else { - g_pUnitTests->push_back(pUnitTest); + g_pWsjcppUnitTests->push_back(pUnitTest); // Log::info(sCmd, "Registered"); } } -// --------------------------------------------------------------------- - -bool WSJCppUnitTests::runUnitTests() { - WSJCppUnitTests::initGlobalVariables(); - int nAll = g_pUnitTests->size(); - WSJCppLog::info("runUnitTests", "All tests count " + std::to_string(nAll)); - int nSuccess = 0; - for (int i = 0; i < g_pUnitTests->size(); i++) { - WSJCppUnitTestBase* pUnitTest = g_pUnitTests->at(i); - std::string sTestName = pUnitTest->name(); - WSJCppLog::info("runUnitTests", "Run test " + sTestName); - if (pUnitTest->run()) { - WSJCppLog::ok(sTestName, "Test passed"); - nSuccess++; - } else { - WSJCppLog::err(sTestName, "Test failed"); - } - } - WSJCppLog::info("WSJCpp::runUnitTests", "Passed tests " + std::to_string(nSuccess) + " / " + std::to_string(nAll)); - return nSuccess == nAll; -} - // --------------------------------------------------------------------- \ No newline at end of file diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h index 46d4192..b3213db 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h @@ -5,9 +5,9 @@ #include #include -class WSJCppUnitTestBase { +class WsjcppUnitTestBase { public: - WSJCppUnitTestBase(const std::string &sTestName); + WsjcppUnitTestBase(const std::string &sTestName); std::string name(); virtual void init() = 0; virtual bool run() = 0; @@ -23,18 +23,17 @@ class WSJCppUnitTestBase { std::string m_sTestName; }; -extern std::vector *g_pUnitTests; +extern std::vector *g_pWsjcppUnitTests; -class WSJCppUnitTests { +class WsjcppUnitTests { public: static void initGlobalVariables(); - static void addUnitTest(const std::string &sTestName, WSJCppUnitTestBase* pCmdHandler); - static bool runUnitTests(); + static void addUnitTest(const std::string &sTestName, WsjcppUnitTestBase* pUnitTest); }; // RegistryCmdHandler -#define REGISTRY_UNIT_TEST( classname ) \ - static classname * pRegistryWSJCppUnitTest ## classname = new classname(); \ +#define REGISTRY_WSJCPP_UNIT_TEST( classname ) \ + static classname * pRegistryWsjcppUnitTest ## classname = new classname(); \ #endif // WSJCPP_UNIT_TESTS_H \ No newline at end of file diff --git a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp index 32eb432..23fb13c 100644 --- a/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp +++ b/src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp @@ -2,23 +2,93 @@ #include #include +void printHelp(const std::string &sProgramName) { + std::string sOutput = "\nHelp:\n"; + sOutput += + " '" + sProgramName + "' - run all unit-tests\n" + " '" + sProgramName + " help' - print this help\n" + " '" + sProgramName + " list' - print list of unit-tests\n" + " '" + sProgramName + " run ' - run single unit-test\n" + ; + WsjcppLog::info("UnitTests", sOutput); +} + int main(int argc, char** argv) { - WSJCppCore::initRandom(); + WsjcppCore::initRandom(); std::string TAG = "UnitTests"; - WSJCppLog::setPrefixLogFile("unit-tests"); + WsjcppLog::setPrefixLogFile("unit-tests"); std::string sLogDir = "./logs"; - if (!WSJCppCore::dirExists(sLogDir)) { - WSJCppCore::makeDir(sLogDir); + if (!WsjcppCore::dirExists(sLogDir)) { + WsjcppCore::makeDir(sLogDir); } - WSJCppLog::setLogDirectory(sLogDir); - if (!WSJCppCore::dirExists(sLogDir)) { - WSJCppLog::err(TAG, "Directory '" + sLogDir + "' did'not exists"); + WsjcppLog::setLogDirectory(sLogDir); + if (!WsjcppCore::dirExists(sLogDir)) { + WsjcppLog::err(TAG, "Directory '" + sLogDir + "' did'not exists"); return -1; } - if (!WSJCppUnitTests::runUnitTests()) { - WSJCppLog::err(TAG, "Some unit tests failed"); + WsjcppUnitTests::initGlobalVariables(); + std::string sProgramName(argv[0]); + + if (argc == 1) { + int nAll = g_pWsjcppUnitTests->size(); + WsjcppLog::info("runUnitTests", "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"); + nSuccess++; + } else { + WsjcppLog::err(sTestName, "Test failed"); + } + } + WsjcppLog::info(TAG, "Passed tests " + std::to_string(nSuccess) + " / " + std::to_string(nAll)); + bool bResult = nSuccess == nAll; + return bResult ? 0 : -1; + } else if (argc == 2) { + std::string sArg2(argv[1]); + if (sArg2 == "list") { + 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"; + } + WsjcppLog::info(TAG, sOutput); + return -1; + } else if (sArg2 == "help") { + printHelp(sProgramName); + return -1; + } + } else if (argc == 3) { + std::string sArg2(argv[1]); + std::string sArg3(argv[2]); + if (sArg2 == "run") { + int nSuccess = 0; + bool bTestFound = false; + for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) { + WsjcppUnitTestBase* pUnitTest = g_pWsjcppUnitTests->at(i); + if (pUnitTest->name() == sArg3) { + bTestFound = true; + if (pUnitTest->run()) { + WsjcppLog::ok(TAG, pUnitTest->name() + " Test passed"); + nSuccess++; + } else { + WsjcppLog::err(TAG, pUnitTest->name() + " Test failed"); + } + } + } + if (!bTestFound) { + WsjcppLog::err(TAG, "Test not found try help"); + } + return -1; + } + printHelp(sProgramName); return -1; } + + printHelp(sProgramName); return 0; } \ No newline at end of file diff --git a/unit-tests.wsjcpp/CMakeLists.txt b/unit-tests.wsjcpp/CMakeLists.txt index 4e81a7f..9e1754b 100644 --- a/unit-tests.wsjcpp/CMakeLists.txt +++ b/unit-tests.wsjcpp/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(unit-tests C CXX) -add_definitions(-DWSJCPP_VERSION="ut-v0.0.1") +add_definitions(-DWSJCPP_VERSION="ut-v0.1.0") add_definitions(-DWSJCPP_NAME="unit-tests-wsjcpp-print-tree") 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.0.5 +# wsjcpp-core:v0.1.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-print-tree:v0.0.1 +# wsjcpp-print-tree:v0.1.0 list (APPEND WSJCPP_INCLUDE_DIRS "../src") list (APPEND WSJCPP_SOURCES "../src/wsjcpp_print_tree.h") list (APPEND WSJCPP_SOURCES "../src/wsjcpp_print_tree.cpp") @@ -37,6 +37,8 @@ list (APPEND WSJCPP_INCLUDE_DIRS "src") list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_tree_simple.h") list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_tree_simple.cpp") +include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt) + include_directories(${WSJCPP_INCLUDE_DIRS}) diff --git a/unit-tests.wsjcpp/CMakeLists.user-custom.txt b/unit-tests.wsjcpp/CMakeLists.user-custom.txt new file mode 100644 index 0000000..127f538 --- /dev/null +++ b/unit-tests.wsjcpp/CMakeLists.user-custom.txt @@ -0,0 +1,2 @@ +## You can here write some custom includes + diff --git a/wsjcpp.yml b/wsjcpp.yml index aea535e..3fa22cd 100644 --- a/wsjcpp.yml +++ b/wsjcpp.yml @@ -1,5 +1,5 @@ name: "wsjcpp-print-tree" -version: "v0.0.1" +version: "v0.1.0" description: "Helper class for print tree in console" cmake_minimum_required: 3.0 cmake_cxx_standard: 11 @@ -21,15 +21,13 @@ distribution: - source-file: "src/wsjcpp_print_tree.h" target-file: "wsjcpp_print_tree.h" type: "source-code" - sha1: "" - source-file: "src/wsjcpp_print_tree.cpp" target-file: "wsjcpp_print_tree.cpp" type: "source-code" - sha1: "" dependencies: - name: "wsjcpp-core" - version: "v0.0.5" + version: "v0.1.1" url: "https://github.com/wsjcpp/wsjcpp-core:master" origin: "https://github.com/" installation-dir: "./src.wsjcpp/wsjcpp_core"