Skip to content

Commit 8309b33

Browse files
committed
Added func 'convertVoidToULong' and 'getPointerAsHex' and renamed unit tests
1 parent 582b42e commit 8309b33

23 files changed

+69
-46
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
Basic utils for wsjcpp
66

77
*included helpers functions, logger and etc.*
8+
9+
## List of function:
10+
11+
* createUuid

src.wsjcpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Automaticly generated by wsjcpp@v0.0.1
22
cmake_minimum_required(VERSION 3.0)
33

4-
add_definitions(-DWSJCPP_VERSION="v0.0.4")
4+
add_definitions(-DWSJCPP_VERSION="v0.0.5")
55
add_definitions(-DWSJCPP_NAME="wsjcpp-core")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

src/wsjcpp_core.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,22 @@ bool WSJCppCore::isIPv6(const std::string& str) {
457457
return isValid;
458458
}
459459

460+
// ---------------------------------------------------------------------
461+
462+
unsigned long WSJCppCore::convertVoidToULong(void *p) {
463+
unsigned long ret = *(unsigned long *)p;
464+
return ret;
465+
}
466+
467+
// ---------------------------------------------------------------------
468+
469+
std::string WSJCppCore::getPointerAsHex(void *p) {
470+
std::uintptr_t i = reinterpret_cast<std::uintptr_t>(p);
471+
std::stringstream stream;
472+
stream << std::hex << i;
473+
return "0x" + std::string(stream.str());
474+
}
475+
460476
// ---------------------------------------------------------------------
461477
// WSJCppLog
462478

src/wsjcpp_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class WSJCppCore {
5151
static std::string createUuid();
5252
static bool isIPv4(const std::string& str);
5353
static bool isIPv6(const std::string& str);
54+
55+
static unsigned long convertVoidToULong(void *p);
56+
static std::string getPointerAsHex(void *p);
5457
};
5558

5659

src/wsjcpp_unit_tests.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "wsjcpp_unit_tests.h"
22

3-
UnitTestBase::UnitTestBase(const std::string &sTestName) {
3+
WSJCppUnitTestBase::WSJCppUnitTestBase(const std::string &sTestName) {
44
m_sTestName = sTestName;
55
TAG = m_sTestName;
6-
UnitTests::addUnitTest(sTestName, this);
6+
WSJCppUnitTests::addUnitTest(sTestName, this);
77
}
88

99
// ---------------------------------------------------------------------
1010

11-
std::string UnitTestBase::name() {
11+
std::string WSJCppUnitTestBase::name() {
1212
return m_sTestName;
1313
}
1414

1515
// ---------------------------------------------------------------------
1616

17-
void UnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint,
17+
void WSJCppUnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint,
1818
const std::string &sValue, const std::string &sExpected) {
1919
if (sValue != sExpected) {
2020
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + sExpected + "', but got '" + sValue + "'");
@@ -24,7 +24,7 @@ void UnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint,
2424

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

27-
bool UnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) {
27+
bool WSJCppUnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) {
2828
if (nValue != nExpected) {
2929
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
3030
bTestSuccess = false;
@@ -35,7 +35,7 @@ bool UnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int n
3535

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

38-
bool UnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) {
38+
bool WSJCppUnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) {
3939
if (nValue != nExpected) {
4040
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
4141
bTestSuccess = false;
@@ -46,7 +46,7 @@ bool UnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, doubl
4646

4747
// ---------------------------------------------------------------------
4848

49-
void UnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) {
49+
void WSJCppUnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) {
5050
if (bValue != bExpected) {
5151
WSJCppLog::err(TAG, " {" + sPoint + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'");
5252
bTestSuccess = false;
@@ -55,22 +55,22 @@ void UnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool
5555

5656
// ---------------------------------------------------------------------
5757

58-
std::vector<UnitTestBase*> *g_pUnitTests = NULL;
58+
std::vector<WSJCppUnitTestBase*> *g_pUnitTests = NULL;
5959

60-
void UnitTests::initGlobalVariables() {
60+
void WSJCppUnitTests::initGlobalVariables() {
6161
if (g_pUnitTests == NULL) {
6262
// Log::info(std::string(), "Create handlers map");
63-
g_pUnitTests = new std::vector<UnitTestBase*>();
63+
g_pUnitTests = new std::vector<WSJCppUnitTestBase*>();
6464
}
6565
}
6666

6767
// ---------------------------------------------------------------------
6868

69-
void UnitTests::addUnitTest(const std::string &sTestName, UnitTestBase* pUnitTest) {
70-
UnitTests::initGlobalVariables();
69+
void WSJCppUnitTests::addUnitTest(const std::string &sTestName, WSJCppUnitTestBase* pUnitTest) {
70+
WSJCppUnitTests::initGlobalVariables();
7171
bool bFound = false;
7272
for (int i = 0; i < g_pUnitTests->size(); i++) {
73-
UnitTestBase* p = g_pUnitTests->at(i);
73+
WSJCppUnitTestBase* p = g_pUnitTests->at(i);
7474
if (p->name() == sTestName) {
7575
bFound = true;
7676
}
@@ -86,13 +86,13 @@ void UnitTests::addUnitTest(const std::string &sTestName, UnitTestBase* pUnitTes
8686

8787
// ---------------------------------------------------------------------
8888

89-
bool UnitTests::runUnitTests() {
90-
UnitTests::initGlobalVariables();
89+
bool WSJCppUnitTests::runUnitTests() {
90+
WSJCppUnitTests::initGlobalVariables();
9191
int nAll = g_pUnitTests->size();
9292
WSJCppLog::info("runUnitTests", "All tests count " + std::to_string(nAll));
9393
int nSuccess = 0;
9494
for (int i = 0; i < g_pUnitTests->size(); i++) {
95-
UnitTestBase* pUnitTest = g_pUnitTests->at(i);
95+
WSJCppUnitTestBase* pUnitTest = g_pUnitTests->at(i);
9696
std::string sTestName = pUnitTest->name();
9797
WSJCppLog::info("runUnitTests", "Run test " + sTestName);
9898
if (pUnitTest->run()) {
@@ -102,7 +102,7 @@ bool UnitTests::runUnitTests() {
102102
WSJCppLog::err(sTestName, "Test failed");
103103
}
104104
}
105-
WSJCppLog::info("runUnitTests", "Passed tests " + std::to_string(nSuccess) + " / " + std::to_string(nAll));
105+
WSJCppLog::info("WSJCpp::runUnitTests", "Passed tests " + std::to_string(nSuccess) + " / " + std::to_string(nAll));
106106
return nSuccess == nAll;
107107
}
108108

src/wsjcpp_unit_tests.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#ifndef UNIT_TESTS_H
2-
#define UNIT_TESTS_H
1+
#ifndef WSJCPP_UNIT_TESTS_H
2+
#define WSJCPP_UNIT_TESTS_H
33

44
#include <map>
55
#include <vector>
66
#include <wsjcpp_core.h>
77

8-
class UnitTestBase {
8+
class WSJCppUnitTestBase {
99
public:
10-
UnitTestBase(const std::string &sTestName);
10+
WSJCppUnitTestBase(const std::string &sTestName);
1111
std::string name();
1212
virtual void init() = 0;
1313
virtual bool run() = 0;
@@ -23,18 +23,18 @@ class UnitTestBase {
2323
std::string m_sTestName;
2424
};
2525

26-
extern std::vector<UnitTestBase*> *g_pUnitTests;
26+
extern std::vector<WSJCppUnitTestBase*> *g_pUnitTests;
2727

28-
class UnitTests {
28+
class WSJCppUnitTests {
2929
public:
3030
static void initGlobalVariables();
31-
static void addUnitTest(const std::string &sTestName, UnitTestBase* pCmdHandler);
31+
static void addUnitTest(const std::string &sTestName, WSJCppUnitTestBase* pCmdHandler);
3232
static bool runUnitTests();
3333
};
3434

3535
// RegistryCmdHandler
3636
#define REGISTRY_UNIT_TEST( classname ) \
37-
static classname * pRegistryUnitTest ## classname = new classname(); \
37+
static classname * pRegistryWSJCppUnitTest ## classname = new classname(); \
3838

3939

40-
#endif // UNIT_TESTS_H
40+
#endif // WSJCPP_UNIT_TESTS_H

src/wsjcpp_unit_tests_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char** argv) {
1616
return -1;
1717
}
1818

19-
if (!UnitTests::runUnitTests()) {
19+
if (!WSJCppUnitTests::runUnitTests()) {
2020
WSJCppLog::err(TAG, "Some unit tests failed");
2121
return -1;
2222
}

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set (WSJCPP_LIBRARIES "")
1414
set (WSJCPP_INCLUDE_DIRS "")
1515
set (WSJCPP_SOURCES "")
1616

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

unit-tests.wsjcpp/src/unit_test_core_extract_filename.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
REGISTRY_UNIT_TEST(UnitTestCoreExtractFilename)
77

88
UnitTestCoreExtractFilename::UnitTestCoreExtractFilename()
9-
: UnitTestBase("UnitTestCoreExtractFilename") {
9+
: WSJCppUnitTestBase("UnitTestCoreExtractFilename") {
1010
//
1111
}
1212

unit-tests.wsjcpp/src/unit_test_core_extract_filename.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <wsjcpp_unit_tests.h>
55

6-
class UnitTestCoreExtractFilename : public UnitTestBase {
6+
class UnitTestCoreExtractFilename : public WSJCppUnitTestBase {
77
public:
88
UnitTestCoreExtractFilename();
99
virtual void init();

0 commit comments

Comments
 (0)