Skip to content

Commit ea1acde

Browse files
committed
updated yaml file
1 parent ec2f48d commit ea1acde

19 files changed

+258
-132
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
wsjcpp-hashes
2+
.wsjcpp/*
23
tmp/*
34
.vscode/*
45

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ addons:
1717
# Build steps
1818
script:
1919
- ./build_simple.sh
20-
- cd unit-tests
20+
- cd unit-tests.wsjcpp
2121
- ./build_simple.sh
2222
- ./unit-tests

src.wsjcpp/CMakeLists.txt

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# Automaticly generated by [email protected]
1+
# Automaticly generated by [email protected]
2+
cmake_minimum_required(VERSION 3.0)
23

3-
add_definitions(-DWSJCPP_VERSION="0.0.1")
4-
add_definitions(-DWSJCPP_NAME="wsjcpp-hashes")
4+
add_definitions(-DWSJCPP_VERSION="v0.0.1")
5+
add_definitions(-DWSJCPP_NAME="wsjcpp/wsjcpp-hashes")
6+
7+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
8+
set(MACOSX TRUE)
9+
endif()
510

6-
# set(CMAKE_AUTOMOC ON)
711
set(CMAKE_CXX_STANDARD 11)
812

913
set (WSJCPP_LIBRARIES "")
1014
set (WSJCPP_INCLUDE_DIRS "")
1115
set (WSJCPP_SOURCES "")
1216

13-
# wsjcpp-core
14-
list (APPEND WSJCPP_INCLUDE_DIRS "src.wsjcpp/wsjcpp-core/")
15-
list (APPEND WSJCPP_SOURCES "src.wsjcpp/wsjcpp-core/wsjcpp_core.h")
16-
list (APPEND WSJCPP_SOURCES "src.wsjcpp/wsjcpp-core/wsjcpp_core.cpp")
17+
# wsjcpp-core:v0.0.4
18+
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_core/")
19+
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
20+
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.h")
21+
22+

src.wsjcpp/wsjcpp-core/wsjcpp.hold.yml

-38
This file was deleted.
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
wsjcpp_version: v0.0.1
2+
cmake_cxx_standard: 11
3+
cmake_minimum_required: 3.0
4+
5+
name: wsjcpp-core
6+
version: v0.0.4
7+
description: Basic Utils for wsjcpp
8+
issues: https://github.com/wsjcpp/wsjcpp-core/issues
9+
repositories:
10+
- type: main
11+
url: "https://github.com/wsjcpp/wsjcpp-core"
12+
keywords:
13+
- c++
14+
- wsjcpp
15+
16+
authors:
17+
- name: Evgenii Sopov
18+
19+
20+
required-libraries:
21+
- pthread
22+
23+
distribution:
24+
- source-file: src/wsjcpp_core.cpp
25+
target-file: wsjcpp_core.cpp
26+
sha1: "a80af85d404179f9514990e59696287810ead4eb"
27+
type: "source-code"
28+
- source-file: src/wsjcpp_core.h
29+
target-file: wsjcpp_core.h
30+
sha1: "a8a5197a0b6f6230cd8f75ee536bb590ed61125a"
31+
type: "source-code"
32+
- source-file: "src/wsjcpp_unit_tests.cpp"
33+
target-file: "wsjcpp_unit_tests.cpp"
34+
type: "unit-tests"
35+
sha1: "4208e039ec2923636655b3ada79ec223cca7bae2"
36+
- source-file: "src/wsjcpp_unit_tests.h"
37+
target-file: "wsjcpp_unit_tests.h"
38+
type: "unit-tests"
39+
sha1: "8d2ec886f23161a639bb2419bb5e4af48278f18b"
40+
- source-file: "src/wsjcpp_unit_tests_main.cpp"
41+
target-file: "wsjcpp_unit_tests_main.cpp"
42+
type: "unit-tests"
43+
sha1: "2c02fb58f51687eeac2076096b7df698cc246c9d"
44+
45+
unit-tests:
46+
cases:
47+
- name: CoreNormalizePath
48+
description: Check function normalizePath
49+
- name: CoreUuid
50+
description: Check test generate uuid function
51+
- name: CoreExtractFilename
52+
description: Check function extract filenane from path
53+
- name: IpV4
54+
description: Check function isIPv4
55+
- name: IpV6
56+
description: Check function isIPv6
57+
- name: "ToUpper"
58+
description: "String to upper"

src.wsjcpp/wsjcpp-core/wsjcpp_core.cpp renamed to src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp

+87-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <cstdint>
1717
#include <unistd.h>
1818
#include <streambuf>
19+
#include <sys/types.h>
20+
#include <sys/socket.h>
21+
#include <arpa/inet.h>
1922

2023
// ---------------------------------------------------------------------
2124

@@ -96,6 +99,34 @@ std::string WSJCppCore::doNormalizePath(const std::string & sPath) {
9699

97100
// ---------------------------------------------------------------------
98101

102+
std::string WSJCppCore::extractFilename(const std::string &sPath) {
103+
// split path by /
104+
std::vector<std::string> vNames;
105+
std::string s = "";
106+
int nStrLen = sPath.length();
107+
for (int i = 0; i < sPath.length(); i++) {
108+
if (sPath[i] == '/') {
109+
vNames.push_back(s);
110+
s = "";
111+
if (i == nStrLen-1) {
112+
vNames.push_back("");
113+
}
114+
} else {
115+
s += sPath[i];
116+
}
117+
}
118+
if (s != "") {
119+
vNames.push_back(s);
120+
}
121+
std::string sRet;
122+
if (vNames.size() > 0) {
123+
sRet = vNames[vNames.size()-1];
124+
}
125+
return sRet;
126+
}
127+
128+
// ---------------------------------------------------------------------
129+
99130
std::string WSJCppCore::getCurrentDirectory() {
100131
char cwd[PATH_MAX];
101132
if (getcwd(cwd, sizeof(cwd)) == NULL) {
@@ -275,20 +306,20 @@ bool WSJCppCore::makeDir(const std::string &sDirname) {
275306
std::cout << "FAILED create folder " << sDirname << std::endl;
276307
return false;
277308
}
278-
std::cout << "nStatus: " << nStatus << std::endl;
309+
// std::cout << "nStatus: " << nStatus << std::endl;
279310
return true;
280311
}
281312

282313
// ---------------------------------------------------------------------
283314

284315
bool WSJCppCore::writeFile(const std::string &sFilename, const std::string &sContent) {
285316

286-
std::ofstream f(sFilename, std::ifstream::in);
317+
// std::ofstream f(sFilename, std::ifstream::in);
318+
std::ofstream f(sFilename, std::ios::out);
287319
if (!f) {
288-
std::cout << "FAILED could not create file to wtite " << sFilename << std::endl;
320+
WSJCppLog::err("WSJCppCore", "Could not create file to write '" + sFilename + "'");
289321
return false;
290322
}
291-
292323
f << sContent << std::endl;
293324
f.close();
294325
return true;
@@ -325,7 +356,11 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const char *pBuffer, co
325356
return true;
326357
}
327358

359+
// ---------------------------------------------------------------------
328360

361+
bool WSJCppCore::removeFile(const std::string &sFilename) {
362+
return remove(sFilename.c_str()) == 0;
363+
}
329364

330365
// ---------------------------------------------------------------------
331366

@@ -354,6 +389,14 @@ std::string& WSJCppCore::to_lower(std::string& str) {
354389
return str;
355390
}
356391

392+
// ---------------------------------------------------------------------
393+
// will worked only with latin
394+
395+
std::string WSJCppCore::toUpper(const std::string& str) {
396+
std::string sRet = str;
397+
std::transform(sRet.begin(), sRet.end(), sRet.begin(), ::toupper);
398+
return sRet;
399+
}
357400

358401
// ---------------------------------------------------------------------
359402

@@ -376,6 +419,44 @@ std::string WSJCppCore::createUuid() {
376419
return sRet;
377420
}
378421

422+
// ---------------------------------------------------------------------
423+
424+
bool WSJCppCore::isIPv4(const std::string& str) {
425+
int n = 0;
426+
std::string s[4] = {"", "", "", ""};
427+
for (int i = 0; i < str.length(); i++) {
428+
char c = str[i];
429+
if (n > 3) {
430+
return false;
431+
}
432+
if (c >= '0' && c <= '9') {
433+
s[n] += c;
434+
} else if (c == '.') {
435+
n++;
436+
} else {
437+
return false;
438+
}
439+
}
440+
for (int i = 0; i < 4; i++) {
441+
if (s[i].length() > 3) {
442+
return false;
443+
}
444+
int p = std::stoi(s[i]);
445+
if (p > 255 || p < 0) {
446+
return false;
447+
}
448+
}
449+
return true;
450+
}
451+
452+
// ---------------------------------------------------------------------
453+
454+
bool WSJCppCore::isIPv6(const std::string& str) {
455+
unsigned char buf[sizeof(struct in6_addr)];
456+
bool isValid = inet_pton(AF_INET6, str.c_str(), buf);
457+
return isValid;
458+
}
459+
379460
// ---------------------------------------------------------------------
380461
// WSJCppLog
381462

@@ -492,3 +573,5 @@ void WSJCppLog::add(WSJCppColorModifier &clr, const std::string &sType, const st
492573
logFile << sLogMessage << std::endl;
493574
logFile.close();
494575
}
576+
577+

src.wsjcpp/wsjcpp-core/wsjcpp_core.h renamed to src.wsjcpp/wsjcpp_core/wsjcpp_core.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class WSJCppCore {
1818
const std::string &sLibraryNameForExports
1919
);
2020

21-
static std::string doNormalizePath(const std::string & sPath);
21+
static std::string doNormalizePath(const std::string &sPath);
22+
static std::string extractFilename(const std::string &sPath);
2223
static std::string getCurrentDirectory();
2324

2425
static long currentTime_milliseconds();
@@ -38,15 +39,18 @@ class WSJCppCore {
3839
static bool writeFile(const std::string &sFilename, const std::string &sContent);
3940
static bool readTextFile(const std::string &sFilename, std::string &sOutputContent);
4041
static bool writeFile(const std::string &sFilename, const char *pBuffer, const int nBufferSize);
41-
42+
static bool removeFile(const std::string &sFilename);
4243

4344
static std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
4445
static std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
4546
static std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
4647
static std::string& to_lower(std::string& str);
48+
static std::string toUpper(const std::string& str);
4749

4850
static void initRandom();
4951
static std::string createUuid();
52+
static bool isIPv4(const std::string& str);
53+
static bool isIPv6(const std::string& str);
5054
};
5155

5256

@@ -95,11 +99,12 @@ class WSJCppLog {
9599
static void ok(const std::string &sTag, const std::string &sMessage);
96100
static void setLogDirectory(const std::string &sDirectoryPath);
97101
static void setPrefixLogFile(const std::string &sPrefixLogFile);
98-
// static nlohmann::json getLastLogs();
99102
static void initGlobalVariables();
100103

101104
private:
102105
static void add(WSJCppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage);
103106
};
104107

105-
#endif // WSJCPP_CORE_H
108+
#endif // WSJCPP_CORE_H
109+
110+

unit-tests/src/unit_tests.cpp renamed to src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "unit_tests.h"
1+
#include "wsjcpp_unit_tests.h"
22

33
UnitTestBase::UnitTestBase(const std::string &sTestName) {
44
m_sTestName = sTestName;
@@ -17,7 +17,7 @@ std::string UnitTestBase::name() {
1717
void UnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint,
1818
const std::string &sValue, const std::string &sExpected) {
1919
if (sValue != sExpected) {
20-
WSJCppLog::err(TAG, sPoint + ", expeceted '" + sExpected + "', but got '" + sValue + "'");
20+
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + sExpected + "', but got '" + sValue + "'");
2121
bTestSuccess = false;
2222
}
2323
}
@@ -26,7 +26,18 @@ void UnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint,
2626

2727
bool UnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) {
2828
if (nValue != nExpected) {
29-
WSJCppLog::err(TAG, " {" + sPoint + "} Expeceted '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
29+
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
30+
bTestSuccess = false;
31+
return false;
32+
}
33+
return true;
34+
}
35+
36+
// ---------------------------------------------------------------------
37+
38+
bool UnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) {
39+
if (nValue != nExpected) {
40+
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
3041
bTestSuccess = false;
3142
return false;
3243
}
@@ -37,7 +48,7 @@ bool UnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int n
3748

3849
void UnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) {
3950
if (bValue != bExpected) {
40-
WSJCppLog::err(TAG, sPoint + ", expeceted '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'");
51+
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'");
4152
bTestSuccess = false;
4253
}
4354
}

unit-tests/src/unit_tests.h renamed to src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class UnitTestBase {
1616

1717
void compareS(bool &bTestSuccess, const std::string &sPoint, const std::string &sValue, const std::string &sExpected);
1818
bool compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected);
19+
bool compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected);
1920
void compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected);
2021

2122
private:

0 commit comments

Comments
 (0)