Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b06b524

Browse files
committedSep 28, 2020
Updated wsjcpp-core to v0.2.1
1 parent 9cc1661 commit b06b524

12 files changed

+183
-264
lines changed
 

‎src.wsjcpp/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Automaticly generated by wsjcpp@v0.1.7
1+
# Automaticly generated by wsjcpp@v0.2.0
22
cmake_minimum_required(VERSION 3.0)
33

44
add_definitions(-DWSJCPP_APP_VERSION="v0.1.1")
@@ -17,11 +17,9 @@ set (WSJCPP_SOURCES "")
1717
find_package(Threads REQUIRED)
1818
list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
1919

20-
# wsjcpp-core:v0.2.0
20+
# wsjcpp-core:v0.2.1
2121
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_core/")
2222
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
2323
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.h")
24-
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.h")
25-
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.cpp")
2624

2725

‎src.wsjcpp/wsjcpp_core/generate.WsjcppUnitTest renamed to ‎src.wsjcpp/wsjcpp_core/generate.WsjcppUnitTest.wsjcpp-script

+11-44
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,21 @@
66
make_dir "./unit-tests.wsjcpp"
77
make_dir "./unit-tests.wsjcpp/src"
88

9-
var user_class_name
10-
set_value user_class_name arg1
11-
normalize_class_name user_class_name
129
var class_name
13-
set_value class_name "UnitTest"
14-
concat class_name user_class_name
15-
16-
var base_filename
17-
convert_CamelCase_to_snake_case class_name base_filename
18-
# log_info base_filename
10+
set_value class_name arg1
11+
normalize_class_name class_name
1912

2013
var filename_cpp
21-
concat filename_cpp "./unit-tests.wsjcpp/src/" base_filename ".cpp"
22-
23-
var filename_h
24-
concat filename_h "./unit-tests.wsjcpp/src/" base_filename ".h"
25-
26-
var ifndef_header
27-
set_value ifndef_header base_filename
28-
concat ifndef_header "_H"
29-
30-
to_upper_case ifndef_header
31-
32-
var content_header
33-
concat content_header "#ifndef " ifndef_header "
34-
#define " ifndef_header "
14+
set_value filename_cpp arg2
3515

16+
var content_source
17+
concat content_source "
18+
#include <wsjcpp_core.h>
3619
#include <wsjcpp_unit_tests.h>
3720

21+
// ---------------------------------------------------------------------
22+
// " class_name "
23+
3824
class " class_name " : public WsjcppUnitTestBase {
3925
public:
4026
" class_name "();
@@ -43,17 +29,6 @@ class " class_name " : public WsjcppUnitTestBase {
4329
virtual bool doAfterTest() override;
4430
};
4531

46-
#endif // " ifndef_header
47-
48-
49-
var content_source
50-
concat content_source "
51-
#include \"" base_filename ".h\"
52-
#include <wsjcpp_core.h>
53-
54-
// ---------------------------------------------------------------------
55-
// " class_name "
56-
5732
REGISTRY_WSJCPP_UNIT_TEST(" class_name ")
5833

5934
" class_name "::" class_name "()
@@ -63,7 +38,7 @@ REGISTRY_WSJCPP_UNIT_TEST(" class_name ")
6338
// ---------------------------------------------------------------------
6439

6540
bool " class_name "::doBeforeTest() {
66-
// nothing
41+
// do something before test
6742
return true;
6843
}
6944

@@ -77,27 +52,19 @@ void " class_name "::executeTest() {
7752
// ---------------------------------------------------------------------
7853

7954
bool " class_name "::doAfterTest() {
80-
// nothing
55+
// do somethig after test
8156
return true;
8257
}
8358

8459
"
8560

86-
var file_source
87-
concat file_source "src/" filename_cpp
88-
89-
write_file filename_h content_header
9061
write_file filename_cpp content_source
9162

9263
log_info "
9364
======
9465
Generated class:
9566
- " class_name "
9667
Generated files:
97-
- " filename_h "
9868
- " filename_cpp "
9969
======
10070
"
101-
102-
wsjcpp_yml_unit_test_add user_class_name filename_h
103-
wsjcpp_yml_unit_test_add user_class_name filename_cpp

‎src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml

+12-11
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-core
6-
version: v0.2.0
6+
version: v0.2.1
77
description: Basic Utils for wsjcpp
88
issues: https://github.com/wsjcpp/wsjcpp-core/issues
99
repositories:
@@ -21,30 +21,31 @@ distribution:
2121
- source-file: src/wsjcpp_core.cpp
2222
target-file: wsjcpp_core.cpp
2323
type: "source-code"
24+
sha1: "09ef821bbc090fc1cd8a15bc4a57a9a2ce8ae00d"
2425
- source-file: src/wsjcpp_core.h
2526
target-file: wsjcpp_core.h
2627
type: "source-code" # todo must be header-file
28+
sha1: "e6e4ab2067d3c942db08e3b79862486eaf851e4b"
2729
- source-file: "src/wsjcpp_unit_tests.cpp"
2830
target-file: "wsjcpp_unit_tests.cpp"
2931
type: "unit-tests"
32+
sha1: "fd5989d1a83c8b90bdc4d5e9bc9c3051eaa1e6d2"
3033
- source-file: "src/wsjcpp_unit_tests.h"
3134
target-file: "wsjcpp_unit_tests.h"
3235
type: "unit-tests"
36+
sha1: "83d4b6e046b6b58c42882ccae4be413e03c401c1"
3337
- source-file: "src/wsjcpp_unit_tests_main.cpp"
3438
target-file: "wsjcpp_unit_tests_main.cpp"
3539
type: "unit-tests"
36-
- source-file: "scripts.wsjcpp/generate.WsjcppUnitTest"
37-
target-file: "generate.WsjcppUnitTest"
40+
sha1: "388ae269b325c5e161f6c3a5c598575714a4bffc"
41+
- source-file: "scripts.wsjcpp/generate.WsjcppUnitTest.wsjcpp-script"
42+
target-file: "generate.WsjcppUnitTest.wsjcpp-script"
3843
type: "safe-scripting-generate"
39-
- source-file: "scripts.wsjcpp/generate.Class"
40-
target-file: "generate.Class"
44+
sha1: "a7c9c2d19bf81c5b00e659384b0b92a99319a4c1"
45+
- source-file: "scripts.wsjcpp/generate.Class.wsjcpp-script"
46+
target-file: "generate.Class.wsjcpp-script"
4147
type: "safe-scripting-generate"
42-
- source-file: "src/wsjcpp_resources_manager.h"
43-
target-file: "wsjcpp_resources_manager.h"
44-
type: "source-code"
45-
- source-file: "src/wsjcpp_resources_manager.cpp"
46-
target-file: "wsjcpp_resources_manager.cpp"
47-
type: "source-code"
48+
sha1: "de1799907c685d606b93e08b821b540c2faa2db1"
4849

4950
unit-tests:
5051
cases:

‎src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp

+118
Original file line numberDiff line numberDiff line change
@@ -1213,4 +1213,122 @@ void WsjcppLog::add(WsjcppColorModifier &clr, const std::string &sType, const st
12131213
}
12141214
}
12151215

1216+
// ---------------------------------------------------------------------
1217+
// WsjcppResourceFile
1218+
1219+
WsjcppResourceFile::WsjcppResourceFile() {
1220+
WsjcppResourcesManager::add(this);
1221+
}
1222+
1223+
// ---------------------------------------------------------------------
1224+
1225+
1226+
// ---------------------------------------------------------------------
1227+
// WsjcppResourcesManager
1228+
1229+
std::vector<WsjcppResourceFile*> *g_pWsjcppResourceFiles = nullptr;
1230+
1231+
void WsjcppResourcesManager::initGlobalVariables() {
1232+
if (g_pWsjcppResourceFiles == nullptr) {
1233+
g_pWsjcppResourceFiles = new std::vector<WsjcppResourceFile*>();
1234+
}
1235+
}
1236+
1237+
// ---------------------------------------------------------------------
1238+
1239+
void WsjcppResourcesManager::add(WsjcppResourceFile* pStorage) {
1240+
WsjcppResourcesManager::initGlobalVariables();
1241+
g_pWsjcppResourceFiles->push_back(pStorage);
1242+
}
1243+
1244+
// ---------------------------------------------------------------------
1245+
1246+
bool WsjcppResourcesManager::has(const std::string &sFilename) {
1247+
WsjcppResourcesManager::initGlobalVariables();
1248+
for (int i = 0; i < WsjcppResourcesManager::list().size(); i++) {
1249+
if (WsjcppResourcesManager::list()[i]->getFilename() == sFilename) {
1250+
return true;
1251+
}
1252+
}
1253+
return false;
1254+
}
1255+
1256+
// ---------------------------------------------------------------------
1257+
1258+
WsjcppResourceFile* WsjcppResourcesManager::get(const std::string &sFilename) {
1259+
WsjcppResourcesManager::initGlobalVariables();
1260+
for (int i = 0; i < WsjcppResourcesManager::list().size(); i++) {
1261+
if (WsjcppResourcesManager::list()[i]->getFilename() == sFilename) {
1262+
return WsjcppResourcesManager::list()[i];
1263+
}
1264+
}
1265+
return nullptr;
1266+
}
1267+
1268+
// ---------------------------------------------------------------------
1269+
1270+
const std::vector<WsjcppResourceFile*> &WsjcppResourcesManager::list() {
1271+
return *g_pWsjcppResourceFiles;
1272+
}
1273+
1274+
// ---------------------------------------------------------------------
1275+
1276+
/*
1277+
bool WsjcppResourcesManager::make(const std::string &sWorkspace) {
1278+
if (!WsjcppResourcesManager::createFolders(sWorkspace)) {
1279+
return false;
1280+
}
1281+
return WsjcppResourcesManager::extractFiles(sWorkspace);
1282+
}
1283+
1284+
// ---------------------------------------------------------------------
1285+
1286+
bool WsjcppResourcesManager::createFolders(const std::string &sWorkspace) {
1287+
// prepare folders
1288+
std::vector<std::string> vCreateDirs;
1289+
vCreateDirs.push_back(sWorkspace + "/logs");
1290+
vCreateDirs.push_back(sWorkspace + "/teams");
1291+
vCreateDirs.push_back(sWorkspace + "/checkers");
1292+
vCreateDirs.push_back(sWorkspace + "/html");
1293+
vCreateDirs.push_back(sWorkspace + "/html/css");
1294+
vCreateDirs.push_back(sWorkspace + "/html/js");
1295+
vCreateDirs.push_back(sWorkspace + "/html/images");
1296+
vCreateDirs.push_back(sWorkspace + "/html/images/teams");
1297+
vCreateDirs.push_back(sWorkspace + "/html/images/states");
1298+
1299+
for(int i = 0; i < vCreateDirs.size(); i++) {
1300+
std::string sPath = vCreateDirs[i];
1301+
// check dir existing
1302+
if (!FS::dirExists(sPath)) {
1303+
// try make dir
1304+
if (!FS::makeDir(sPath)) {
1305+
std::cout << "Could not create folder " << sPath << std::endl;
1306+
return false;
1307+
} else {
1308+
std::cout << "Created folder " << sPath << std::endl;
1309+
}
1310+
}
1311+
}
1312+
return true;
1313+
}
1314+
1315+
// ---------------------------------------------------------------------
1316+
1317+
bool WsjcppResourcesManager::extractFiles(const std::string &sWorkspace) {
1318+
// TODO mkdir -p for files
1319+
const std::vector<WsjcppResourceFile*> list = WsjcppResourcesManager::list();
1320+
for(int i = 0; i < list.size(); i++) {
1321+
std::string sFilename = sWorkspace + "/" + list[i]->filename();
1322+
if (!FS::fileExists(sFilename)) {
1323+
if (!FS::writeFile(sFilename, list[i]->buffer(), list[i]->bufferSize())) {
1324+
std::cout << "Could not write file " << sFilename << std::endl;
1325+
return false;
1326+
} else {
1327+
std::cout << "Created file " << sFilename << std::endl;
1328+
}
1329+
}
1330+
}
1331+
return true;
1332+
}
1333+
*/
12161334

‎src.wsjcpp/wsjcpp_core/wsjcpp_core.h

+36
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,42 @@ class WsjcppLog {
194194
static void add(WsjcppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage);
195195
};
196196

197+
// ---------------------------------------------------------------------
198+
// WsjcppResourceFile
199+
200+
class WsjcppResourceFile {
201+
public:
202+
WsjcppResourceFile();
203+
virtual const std::string &getFilename() const = 0;
204+
virtual const std::string &getPackAs() const = 0;
205+
virtual int getBufferSize() const = 0;
206+
virtual const char *getBuffer() const = 0;
207+
};
208+
209+
210+
// ---------------------------------------------------------------------
211+
// WsjcppResourcesManager
212+
213+
extern std::vector<WsjcppResourceFile*> *g_pWsjcppResourceFiles;
214+
215+
class WsjcppResourcesManager {
216+
public:
217+
static void initGlobalVariables();
218+
static void add(WsjcppResourceFile*);
219+
static const std::vector<WsjcppResourceFile*> &list();
220+
static bool has(const std::string &sFilename);
221+
static WsjcppResourceFile* get(const std::string &sFilename);
222+
static bool make(const std::string &sWorkspace);
223+
// static bool createFolders(const std::string &sWorkspace);
224+
// static bool extractFiles(const std::string &sWorkspace);
225+
};
226+
227+
// ---------------------------------------------------------------------
228+
// Registry WsjcppResourceFile
229+
#define REGISTRY_WSJCPP_RESOURCE_FILE( classname ) \
230+
static classname * pRegistryWsjcppResourceFile ## classname = new classname(); \
231+
232+
197233
#endif // WSJCPP_CORE_H
198234

199235

‎src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.cpp

-117
This file was deleted.

‎src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.h

-37
This file was deleted.

‎src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp

-31
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,6 @@ bool WsjcppUnitTestBase::runTest() {
6363

6464
// ---------------------------------------------------------------------
6565

66-
bool WsjcppUnitTestBase::compareS(const std::string &sMark,
67-
const std::string &sValue, const std::string &sExpected) {
68-
if (sValue != sExpected) {
69-
fail(" {" + sMark + "} Expected '" + sExpected + "', but got '" + sValue + "'");
70-
return false;
71-
}
72-
return true;
73-
}
74-
75-
// ---------------------------------------------------------------------
76-
77-
bool WsjcppUnitTestBase::compareN(const std::string &sMark, int nValue, int nExpected) {
78-
if (nValue != nExpected) {
79-
fail(" {" + sMark + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
80-
return false;
81-
}
82-
return true;
83-
}
84-
85-
// ---------------------------------------------------------------------
86-
8766
bool WsjcppUnitTestBase::compareD(const std::string &sMark, double nValue, double nExpected) {
8867
if (abs(nValue - nExpected) > std::numeric_limits<double>::epsilon()) {
8968
fail(" {" + sMark + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
@@ -94,16 +73,6 @@ bool WsjcppUnitTestBase::compareD(const std::string &sMark, double nValue, doubl
9473

9574
// ---------------------------------------------------------------------
9675

97-
bool WsjcppUnitTestBase::compareB(const std::string &sMark, bool bValue, bool bExpected) {
98-
if (bValue != bExpected) {
99-
fail(" {" + sMark + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'");
100-
return false;
101-
}
102-
return true;
103-
}
104-
105-
// ---------------------------------------------------------------------
106-
10776
std::vector<WsjcppUnitTestBase*> *g_pWsjcppUnitTests = nullptr;
10877

10978
void WsjcppUnitTests::initGlobalVariables() {

‎src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ class WsjcppUnitTestBase {
1717
virtual bool doAfterTest() = 0;
1818
protected:
1919
std::string TAG;
20-
21-
bool compareS(const std::string &sMark, const std::string &sValue, const std::string &sExpected);
22-
bool compareN(const std::string &sMark, int nValue, int nExpected);
20+
2321
bool compareD(const std::string &sMark, double nValue, double nExpected);
24-
bool compareB(const std::string &sMark, bool bValue, bool bExpected);
2522
template<typename T1, typename T2> bool compare(const std::string &sMark, T1 tGotValue, T2 tExpectedValue) {
2623
if (tGotValue != tExpectedValue) {
2724
std::stringstream ss;

‎unit-tests.wsjcpp/CMakeLists.txt

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Automaticly generated by wsjcpp@v0.1.7
1+
# Automaticly generated by wsjcpp@v0.2.0
22
cmake_minimum_required(VERSION 3.0)
33

44
project(unit-tests C CXX)
@@ -19,15 +19,13 @@ set (WSJCPP_SOURCES "")
1919
find_package(Threads REQUIRED)
2020
list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
2121

22-
# wsjcpp-core:v0.2.0
22+
# wsjcpp-core:v0.2.1
2323
list (APPEND WSJCPP_INCLUDE_DIRS "../src.wsjcpp/wsjcpp_core/")
2424
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
2525
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_core.h")
2626
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp")
2727
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h")
2828
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp")
29-
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.h")
30-
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_resources_manager.cpp")
3129

3230
# wsjcpp-safe-scripting:v0.1.1
3331
list (APPEND WSJCPP_INCLUDE_DIRS "../src")
@@ -36,11 +34,8 @@ list (APPEND WSJCPP_SOURCES "../src/wsjcpp_safe_scripting.cpp")
3634

3735
# unit-tests
3836
list (APPEND WSJCPP_INCLUDE_DIRS "src")
39-
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_variable.h")
4037
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_variable.cpp")
41-
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_procedure_concat.h")
4238
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_procedure_concat.cpp")
43-
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_procedure_set_value.h")
4439
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_procedure_set_value.cpp")
4540

4641
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt)
@@ -52,11 +47,3 @@ add_executable ("unit-tests" ${WSJCPP_SOURCES})
5247

5348
target_link_libraries("unit-tests" -lpthread ${WSJCPP_LIBRARIES} )
5449

55-
install(
56-
TARGETS
57-
"unit-tests"
58-
RUNTIME DESTINATION
59-
/usr/bin
60-
)
61-
62-

‎wsjcpp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ keywords:
2020

2121
dependencies:
2222
- name: "wsjcpp-core"
23-
version: "v0.2.0"
23+
version: "v0.2.1"
2424
url: "https://github.com/wsjcpp/wsjcpp-core:master"
2525
origin: "https://github.com/"
2626
installation-dir: "./src.wsjcpp/wsjcpp_core"

0 commit comments

Comments
 (0)
Please sign in to comment.