Skip to content

Commit ccac2dc

Browse files
committed
Removed .wsjcpp/* and updated wsjcpp-core
1 parent 0a58f2f commit ccac2dc

File tree

12 files changed

+79
-78
lines changed

12 files changed

+79
-78
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
wsjcpp-geoip
22
tmp/*
3+
.wsjcpp/*
34

45
# Prerequisites
56
*.d

.wsjcpp/cache/https___github_com_wsjcpp_wsjcpp_core_master/wsjcpp.hold.yml

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

.wsjcpp/logs/wsjcpp_20200126_152547.log

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

.wsjcpp/logs/wsjcpp_20200126_152555.log

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

.wsjcpp/logs/wsjcpp_20200126_152829.log

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

src.wsjcpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cmake_minimum_required(VERSION 3.0)
33

44
add_definitions(-DWSJCPP_VERSION="v0.0.1")
5-
add_definitions(-DWSJCPP_NAME="wsjcpp-storages")
5+
add_definitions(-DWSJCPP_NAME="wsjcpp-geoip")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
88
set(MACOSX TRUE)
@@ -14,7 +14,7 @@ set (WSJCPP_LIBRARIES "")
1414
set (WSJCPP_INCLUDE_DIRS "")
1515
set (WSJCPP_SOURCES "")
1616

17-
# wsjcpp/wsjcpp-core:v0.0.3
17+
# wsjcpp/wsjcpp-core:v0.0.4
1818
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_wsjcpp_core/")
1919
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.cpp")
2020
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.h")

src.wsjcpp/wsjcpp_wsjcpp_core/unit_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ 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
}
2424

2525
// ---------------------------------------------------------------------
2626

27-
bool UnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) {
27+
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) + "'");
3030
bTestSuccess = false;
3131
return false;
3232
}
@@ -35,9 +35,9 @@ bool UnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, doubl
3535

3636
// ---------------------------------------------------------------------
3737

38-
bool UnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) {
38+
bool UnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) {
3939
if (nValue != nExpected) {
40-
WSJCppLog::err(TAG, " {" + sPoint + "} Expeceted '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
40+
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
4141
bTestSuccess = false;
4242
return false;
4343
}
@@ -48,7 +48,7 @@ bool UnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int n
4848

4949
void UnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) {
5050
if (bValue != bExpected) {
51-
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") + "'");
5252
bTestSuccess = false;
5353
}
5454
}
@@ -59,7 +59,7 @@ std::vector<UnitTestBase*> *g_pUnitTests = NULL;
5959

6060
void UnitTests::initGlobalVariables() {
6161
if (g_pUnitTests == NULL) {
62-
// WSJCppLog::info(std::string(), "Create handlers map");
62+
// Log::info(std::string(), "Create handlers map");
6363
g_pUnitTests = new std::vector<UnitTestBase*>();
6464
}
6565
}
@@ -80,7 +80,7 @@ void UnitTests::addUnitTest(const std::string &sTestName, UnitTestBase* pUnitTes
8080
WSJCppLog::err(sTestName, "Already registered");
8181
} else {
8282
g_pUnitTests->push_back(pUnitTest);
83-
// WSJCppLog::info(sCmd, "Registered");
83+
// Log::info(sCmd, "Registered");
8484
}
8585
}
8686

src.wsjcpp/wsjcpp_wsjcpp_core/unit_tests_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <string>
2+
#include <wsjcpp_core.h>
23
#include <unit_tests.h>
34

45
int main(int argc, char** argv) {

src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp.hold.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_cxx_standard: 11
33
cmake_minimum_required: 3.0
44

55
name: wsjcpp/wsjcpp-core
6-
version: v0.0.3
6+
version: v0.0.4
77
description: Basic Utils for wsjcpp
88
issues: https://github.com/wsjcpp/wsjcpp-core/issues
99
repositories:
@@ -29,15 +29,28 @@ distribution:
2929
target-file: wsjcpp_core.h
3030
sha1: "1d76447c6880f43f9afeca89111ec64d3574ccb7"
3131
type: "source-code"
32-
- source-file: unit-tests.wsjcpp/src/unit_tests.h
33-
target-file: unit_tests.h
34-
sha1: ""
32+
- source-file: "src/unit_tests.cpp"
33+
target-file: "unit_tests.cpp"
3534
type: "unit-tests"
36-
- source-file: unit-tests.wsjcpp/src/unit_tests.cpp
37-
target-file: unit_tests.cpp
38-
sha1: ""
35+
sha1: "a36d71646ddd6041346909c0481a59299f01f898"
36+
- source-file: "src/unit_tests.h"
37+
target-file: "unit_tests.h"
3938
type: "unit-tests"
40-
- source-file: unit-tests.wsjcpp/src/unit_tests_main.cpp
41-
target-file: unit_tests_main.cpp
42-
sha1: ""
39+
sha1: "a20248c9801c53519ad847aa19d80460289a5dd1"
40+
- source-file: "src/unit_tests_main.cpp"
41+
target-file: "unit_tests_main.cpp"
4342
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

Lines changed: 41 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

@@ -408,6 +411,44 @@ std::string WSJCppCore::createUuid() {
408411
return sRet;
409412
}
410413

414+
// ---------------------------------------------------------------------
415+
416+
bool WSJCppCore::isIPv4(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(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+
411452
// ---------------------------------------------------------------------
412453
// WSJCppLog
413454

0 commit comments

Comments
 (0)