Skip to content

Commit 78d6d38

Browse files
committed
Prepare test_insert
1 parent 26d3d7d commit 78d6d38

File tree

7 files changed

+136
-17
lines changed

7 files changed

+136
-17
lines changed

CMakeLists.txt

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
#
23+
# Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
24+
125
cmake_minimum_required(VERSION 3.0)
226

327
project(wsjcpp-sql-builder C CXX)
@@ -22,10 +46,14 @@ add_executable (wsjcpp-sql-builder ${WSJCPP_SOURCES})
2246

2347
target_link_libraries(wsjcpp-sql-builder ${WSJCPP_LIBRARIES})
2448

25-
install(
26-
TARGETS
27-
wsjcpp-sql-builder
28-
RUNTIME DESTINATION
29-
/usr/bin
30-
)
49+
# install(
50+
# TARGETS
51+
# wsjcpp-sql-builder
52+
# RUNTIME DESTINATION
53+
# /usr/bin
54+
# )
55+
56+
# enable testing functionality
57+
enable_testing()
58+
add_subdirectory(src/tests)
3159

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Evgenii Sopov <mrseakg@gmail.com>
3+
Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

build_simple.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ check_ret() {
1515
fi
1616
}
1717

18-
if [ ! -d tmp ]; then
19-
mkdir -p tmp
20-
fi
21-
22-
cd tmp
23-
cmake ..
18+
cmake -H. -B./tmp/release -DCMAKE_BUILD_TYPE=Release
2419
check_ret $? "configure"
2520

26-
make
27-
check_ret $? "make"
21+
cmake --build ./tmp/release --config Release
22+
check_ret $? "build"
2823

24+
cd ./tmp/release && ctest --output-on-failure

src/tests/CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
#
23+
# Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
24+
25+
file(GLOB ALL_TESTS
26+
"test_*.cpp"
27+
)
28+
29+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY tests)
30+
31+
list (APPEND TEST_YAML_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../wsjcpp_sql_builder.cpp")
32+
33+
foreach(_TEST ${ALL_TESTS})
34+
get_filename_component(TESTNAME ${_TEST} NAME_WE)
35+
add_executable(${TESTNAME}
36+
${_TEST}
37+
${TEST_YAML_SOURCES}
38+
)
39+
target_link_libraries(${TESTNAME} -lpthread ${WSJCPP_LIBRARIES})
40+
41+
add_test(
42+
NAME ${TESTNAME}
43+
COMMAND $<TARGET_FILE:${TESTNAME}>
44+
)
45+
message(${CMAKE_CURRENT_BINARY_DIR}/tests)
46+
set_target_properties (${TESTNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY tests)
47+
endforeach()

src/tests/test_insert.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
*all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
* Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
25+
*
26+
***********************************************************************************/
27+
28+
#include <iostream>
29+
#include <wsjcpp_sql_builder.h>
30+
31+
int main() {
32+
WsjcppSqlBuilderInsert sql("TABLE_NAME");
33+
sql.add("COL1", "val1"); // will be escaped
34+
sql.add("COL2", 1);
35+
// sql.add("COL3", 1.1);
36+
if (!sql.isValid()) {
37+
std::cerr << "Something wrong with query: " << sql.getErrorMessage() << std::endl;
38+
return -1;
39+
}
40+
if (sql.getTextQuery() != "INSERT INTO TABLE_NAME(COL1, COL2) VALUES ('val1', 1);") {
41+
return -1;
42+
}
43+
return 0;
44+
}

src/wsjcpp_sql_builder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************************
22
* MIT License
33
*
4-
* Copyright (c) 2025 Evgenii Sopov <mrseakg@gmail.com>
4+
* Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,8 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*
24+
* Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
25+
*
2426
***********************************************************************************/
2527

2628
#include "wsjcpp_sql_builder.h"

src/wsjcpp_sql_builder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************************
22
* MIT License
33
*
4-
* Copyright (c) 2025 Evgenii Sopov <mrseakg@gmail.com>
4+
* Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,8 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*
24+
* Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
25+
*
2426
***********************************************************************************/
2527

2628
#pragma once

0 commit comments

Comments
 (0)