Skip to content

Commit a3955e9

Browse files
committed
Updated wsjcpp-core and implemeneted createElementMap
1 parent e0d9988 commit a3955e9

32 files changed

+226
-91
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ C++ Write/Reader yaml files
99

1010
include files:
1111

12-
- src.wsjcpp/wsjcpp-core/wsjcpp_core.h
13-
- src.wsjcpp/wsjcpp-core/wsjcpp_core.cpp
12+
- src.wsjcpp/wsjcpp_core/wsjcpp_core.h
13+
- src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp
1414
- src/wsjcpp_yaml.cpp
1515
- src/wsjcpp_yaml.h
1616

src.wsjcpp/CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
# Automaticly generated by wsjcpp-yaml@0.0.2
1+
# Automaticly generated by wsjcpp@v0.0.1
2+
cmake_minimum_required(VERSION 3.0)
23

3-
add_definitions(-DWSJCPP_VERSION="0.0.2")
4+
add_definitions(-DWSJCPP_VERSION="v0.0.3")
45
add_definitions(-DWSJCPP_NAME="wsjcpp-yaml")
56

6-
# set(CMAKE_AUTOMOC ON)
7+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
8+
set(MACOSX TRUE)
9+
endif()
10+
711
set(CMAKE_CXX_STANDARD 11)
812

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

13-
# wsjcpp/wsjcpp-core
14-
list (APPEND WSJCPP_INCLUDE_DIRS "src.wsjcpp/wsjcpp_wsjcpp_core/")
15-
list (APPEND WSJCPP_SOURCES "src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.h")
16-
list (APPEND WSJCPP_SOURCES "src.wsjcpp/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+
# required-libraries
23+
list (APPEND WSJCPP_LIBRARIES "-lpthread")
24+
25+
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -48,7 +59,7 @@ std::vector<UnitTestBase*> *g_pUnitTests = NULL;
4859

4960
void UnitTests::initGlobalVariables() {
5061
if (g_pUnitTests == NULL) {
51-
// WSJCppLog::info(std::string(), "Create handlers map");
62+
// Log::info(std::string(), "Create handlers map");
5263
g_pUnitTests = new std::vector<UnitTestBase*>();
5364
}
5465
}
@@ -69,7 +80,7 @@ void UnitTests::addUnitTest(const std::string &sTestName, UnitTestBase* pUnitTes
6980
WSJCppLog::err(sTestName, "Already registered");
7081
} else {
7182
g_pUnitTests->push_back(pUnitTest);
72-
// WSJCppLog::info(sCmd, "Registered");
83+
// Log::info(sCmd, "Registered");
7384
}
7485
}
7586

Lines changed: 1 addition & 0 deletions
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:
File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
email: mrseakg@gmail.com
19+
20+
required-libraries:
21+
- pthread
22+
23+
distribution:
24+
- source-file: src/wsjcpp_core.cpp
25+
target-file: wsjcpp_core.cpp
26+
sha1: "04a9e3c6db3c7190c6589514a4b5957dbb4c366d"
27+
type: "source-code"
28+
- source-file: src/wsjcpp_core.h
29+
target-file: wsjcpp_core.h
30+
sha1: "1d76447c6880f43f9afeca89111ec64d3574ccb7"
31+
type: "source-code"
32+
- source-file: "src/unit_tests.cpp"
33+
target-file: "unit_tests.cpp"
34+
type: "unit-tests"
35+
sha1: "a36d71646ddd6041346909c0481a59299f01f898"
36+
- source-file: "src/unit_tests.h"
37+
target-file: "unit_tests.h"
38+
type: "unit-tests"
39+
sha1: "a20248c9801c53519ad847aa19d80460289a5dd1"
40+
- source-file: "src/unit_tests_main.cpp"
41+
target-file: "unit_tests_main.cpp"
42+
type: "unit-tests"
43+
sha1: "81a2b3d7328575c0087fa43000b05a96e278da07"
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

src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.cpp renamed to src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp

Lines changed: 45 additions & 0 deletions
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

@@ -353,7 +356,11 @@ bool WSJCppCore::writeFile(const std::string &sFilename, const char *pBuffer, co
353356
return true;
354357
}
355358

359+
// ---------------------------------------------------------------------
356360

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

358365
// ---------------------------------------------------------------------
359366

@@ -404,6 +411,44 @@ std::string WSJCppCore::createUuid() {
404411
return sRet;
405412
}
406413

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

src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.h renamed to src.wsjcpp/wsjcpp_core/wsjcpp_core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class WSJCppCore {
3939
static bool writeFile(const std::string &sFilename, const std::string &sContent);
4040
static bool readTextFile(const std::string &sFilename, std::string &sOutputContent);
4141
static bool writeFile(const std::string &sFilename, const char *pBuffer, const int nBufferSize);
42-
42+
static bool removeFile(const std::string &sFilename);
4343

4444
static std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
4545
static std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
@@ -48,6 +48,8 @@ class WSJCppCore {
4848

4949
static void initRandom();
5050
static std::string createUuid();
51+
static bool isIPv4(const std::string& str);
52+
static bool isIPv6(const std::string& str);
5153
};
5254

5355

src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp.hold.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)