Skip to content

Commit b0cd4be

Browse files
committed
Improving testing
1 parent 80c91e6 commit b0cd4be

File tree

9 files changed

+913
-646
lines changed

9 files changed

+913
-646
lines changed

Makefile.am

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ bin_PROGRAMS = \
2626
render_speedtest
2727
noinst_PROGRAMS = \
2828
gen_tile_test \
29-
renderd_config_test_helper \
30-
renderd_config_test \
3129
renderd_test \
3230
render_expired_test \
3331
render_list_test \
3432
render_old_test \
35-
render_speedtest_test
33+
render_speedtest_test \
34+
unit_test_renderd_config
3635

3736
man_MANS = \
3837
docs/man/renderd.1 \
@@ -60,14 +59,14 @@ renderd_CXXFLAGS = $(MAPNIK_CFLAGS)
6059
renderd_DATA = etc/renderd/renderd.conf
6160
renderd_LDADD = $(PTHREAD_CFLAGS) $(MAPNIK_LDFLAGS) $(STORE_LDFLAGS) $(INIPARSER_LDFLAGS)
6261

63-
render_speedtest_SOURCES = \
64-
src/render_speedtest.cpp \
65-
src/g_logger.c \
62+
render_expired_SOURCES = \
63+
src/render_expired.c \
6664
src/protocol_helper.c \
6765
src/render_submit_queue.c \
6866
src/renderd_config.c \
69-
src/sys_utils.c
70-
render_speedtest_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS) $(INIPARSER_LDFLAGS)
67+
src/sys_utils.c \
68+
$(STORE_SOURCES)
69+
render_expired_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS) $(INIPARSER_LDFLAGS)
7170

7271
render_list_SOURCES = \
7372
src/render_list.c \
@@ -78,15 +77,6 @@ render_list_SOURCES = \
7877
$(STORE_SOURCES)
7978
render_list_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS) $(INIPARSER_LDFLAGS)
8079

81-
render_expired_SOURCES = \
82-
src/render_expired.c \
83-
src/protocol_helper.c \
84-
src/render_submit_queue.c \
85-
src/renderd_config.c \
86-
src/sys_utils.c \
87-
$(STORE_SOURCES)
88-
render_expired_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS) $(INIPARSER_LDFLAGS)
89-
9080
render_old_SOURCES = \
9181
src/render_old.c \
9282
src/g_logger.c \
@@ -97,6 +87,15 @@ render_old_SOURCES = \
9787
src/sys_utils.c
9888
render_old_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS) $(INIPARSER_LDFLAGS)
9989

90+
render_speedtest_SOURCES = \
91+
src/render_speedtest.cpp \
92+
src/g_logger.c \
93+
src/protocol_helper.c \
94+
src/render_submit_queue.c \
95+
src/renderd_config.c \
96+
src/sys_utils.c
97+
render_speedtest_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS) $(INIPARSER_LDFLAGS)
98+
10099
#convert_meta_SOURCES = src/dir_utils.c src/store.c src/convert_meta.c
101100

102101
noinst_LIBRARIES = catch_main.o catch_test_common.o
@@ -110,16 +109,6 @@ gen_tile_test_CFLAGS = -DMAIN_ALREADY_DEFINED
110109
gen_tile_test_CXXFLAGS = $(renderd_CXXFLAGS)
111110
gen_tile_test_LDADD = $(renderd_LDADD) catch_test_common.o
112111

113-
renderd_config_test_helper_SOURCES = \
114-
tests/renderd_config_test_helper.cpp \
115-
src/g_logger.c \
116-
src/renderd_config.c
117-
renderd_config_test_helper_LDADD = $(GLIB_LIBS) $(INIPARSER_LDFLAGS) catch_main.o
118-
119-
renderd_config_test_SOURCES = \
120-
tests/renderd_config_test.cpp
121-
renderd_config_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
122-
123112
renderd_test_SOURCES = \
124113
tests/renderd_test.cpp
125114
renderd_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
@@ -140,18 +129,23 @@ render_speedtest_test_SOURCES = \
140129
tests/render_speedtest_test.cpp
141130
render_speedtest_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
142131

132+
unit_test_renderd_config_SOURCES = \
133+
tests/unit_test_renderd_config.cpp
134+
unit_test_renderd_config_CXXFLAGS = -Isrc
135+
unit_test_renderd_config_LDADD = $(GLIB_LIBS) $(INIPARSER_LDFLAGS) catch_main.o catch_test_common.o
136+
143137
CLEANFILES=*.slo mod_tile.la stderr.out src/*.slo src/*.lo src/.libs/* src/*.la
144138

145139
COMMA=,
146140

147-
test: gen_tile_test renderd_config_test_helper renderd_config_test renderd_test render_expired_test render_list_test render_old_test render_speedtest_test
141+
test: gen_tile_test renderd_test render_expired_test render_list_test render_old_test render_speedtest_test unit_test_renderd_config
148142
./gen_tile_test
149-
./renderd_config_test
150143
./renderd_test
151144
./render_expired_test
152145
./render_list_test
153146
./render_old_test
154147
./render_speedtest_test
148+
./unit_test_renderd_config
155149

156150
all-local:
157151
$(APXS) -c $(DEF_LDLIBS) $(AM_CFLAGS) \

src/CMakeLists.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,27 @@ target_include_directories(gen_tile_test PRIVATE ${PROJECT_SOURCE_DIR}/tests)
219219
target_link_libraries(gen_tile_test ${gen_tile_test_LIBS})
220220
set_target_properties(gen_tile_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
221221

222+
222223
#-----------------------------------------------------------------------------
223224
#
224-
# renderd_config_test_helper
225+
# unit_test_renderd_config
225226
#
226227
#-----------------------------------------------------------------------------
227228

228-
set(renderd_config_test_helper_SRCS
229-
${PROJECT_SOURCE_DIR}/tests/renderd_config_test_helper.cpp
230-
g_logger.c
231-
renderd_config.c
229+
set(unit_test_renderd_config_SRCS
230+
$<TARGET_OBJECTS:catch_main_o>
231+
${PROJECT_SOURCE_DIR}/tests/unit_test_renderd_config.cpp
232232
)
233-
set(renderd_config_test_helper_LIBS
233+
set(unit_test_renderd_config_LIBS
234234
${GLIB_LIBRARIES}
235235
${INIPARSER_LIBRARIES}
236236
)
237-
add_executable(renderd_config_test_helper ${renderd_config_test_helper_SRCS})
238-
target_link_libraries(renderd_config_test_helper ${renderd_config_test_helper_LIBS})
239-
set_target_properties(renderd_config_test_helper PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
237+
add_executable(unit_test_renderd_config ${unit_test_renderd_config_SRCS})
238+
set_target_properties(unit_test_renderd_config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
239+
target_compile_definitions(unit_test_renderd_config PRIVATE
240+
RENDERD_CONF="${PROJECT_SOURCE_DIR}/etc/renderd/renderd.conf.examples"
241+
)
242+
target_include_directories(unit_test_renderd_config PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/tests)
243+
target_link_libraries(unit_test_renderd_config ${unit_test_renderd_config_LIBS})
240244

241245
endif()

src/renderd_config.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
* along with this program; If not, see http://www.gnu.org/licenses/.
1616
*/
1717

18+
#ifndef _GNU_SOURCE
1819
#define _GNU_SOURCE
20+
#endif
1921

2022
#include <sys/un.h>
2123
#include <unistd.h>
@@ -520,7 +522,7 @@ void process_config_file(const char *config_file_name, int active_renderd_sectio
520522
}
521523

522524
if (config.ipport > 0) {
523-
g_logger(log_level, "\trenderd: ip socket = '%s':%i", config.iphostname, config.ipport);
525+
g_logger(log_level, "\trenderd: ip socket = '%s:%i'", config.iphostname, config.ipport);
524526
} else {
525527
g_logger(log_level, "\trenderd: unix socketname = '%s'", config.socketname);
526528
}

tests/CMakeLists.txt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ add_test(
221221
)
222222

223223
add_test(
224-
NAME renderd_config_test
225-
COMMAND renderd_config_test
224+
NAME unit_test_renderd_config
225+
COMMAND unit_test_renderd_config
226226
)
227227

228228
foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
@@ -1252,15 +1252,6 @@ target_include_directories(catch_test_common_o PRIVATE ${GLIB_INCLUDE_DIRS})
12521252
# Added by ${PROJECT_SOURCE_DIR}/src/CMakeLists.txt
12531253
# (in order to reduce redundant source and library definitions)
12541254

1255-
#-----------------------------------------------------------------------------
1256-
#
1257-
# renderd_config_test_helper
1258-
#
1259-
#-----------------------------------------------------------------------------
1260-
1261-
# Added by ${PROJECT_SOURCE_DIR}/src/CMakeLists.txt
1262-
# (in order to reduce redundant source and library definitions)
1263-
12641255
#-----------------------------------------------------------------------------
12651256
#
12661257
# Additional options for targets added hereafter
@@ -1328,14 +1319,3 @@ add_executable(renderd_test
13281319
$<TARGET_OBJECTS:catch_main_o>
13291320
renderd_test.cpp
13301321
)
1331-
1332-
#-----------------------------------------------------------------------------
1333-
#
1334-
# renderd_config_test
1335-
#
1336-
#-----------------------------------------------------------------------------
1337-
1338-
add_executable(renderd_config_test
1339-
$<TARGET_OBJECTS:catch_main_o>
1340-
renderd_config_test.cpp
1341-
)

tests/catch_main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
#include "catch/catch.hpp"
2121
#include "catch_test_common.hpp"
2222

23-
int foreground = 1;
23+
extern "C" {
24+
int foreground = 1;
25+
}

tests/render_list_test.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,31 @@ TEST_CASE("render_list min/max int generator", "min/max int generator testing")
248248
int status = run_command(test_binary, argv);
249249
REQUIRE(WEXITSTATUS(status) == 0);
250250
}
251+
252+
SECTION(option + " option is negative", "should return 1") {
253+
std::vector<std::string> argv = {option, "-1"};
254+
255+
int status = run_command(test_binary, argv);
256+
REQUIRE(WEXITSTATUS(status) == 1);
257+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be >="));
258+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("(-1 was provided)"));
259+
}
260+
261+
SECTION(option + " option is float", "should return 1") {
262+
std::vector<std::string> argv = {option, "1.23456789"};
263+
264+
int status = run_command(test_binary, argv);
265+
REQUIRE(WEXITSTATUS(status) == 1);
266+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be an integer (1.23456789 was provided)"));
267+
}
268+
269+
SECTION(option + " option is not an integer", "should return 1") {
270+
std::vector<std::string> argv = {option, "invalid"};
271+
272+
int status = run_command(test_binary, argv);
273+
REQUIRE(WEXITSTATUS(status) == 1);
274+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be an integer (invalid was provided)"));
275+
}
251276
}
252277

253278
TEST_CASE("render_list min/max lat generator", "min/max double generator testing")
@@ -269,6 +294,51 @@ TEST_CASE("render_list min/max lat generator", "min/max double generator testing
269294
int status = run_command(test_binary, argv);
270295
REQUIRE(WEXITSTATUS(status) == 0);
271296
}
297+
298+
SECTION(option + " option is too large", "should return 1") {
299+
std::vector<std::string> argv = {option, std::to_string(max + .1)};
300+
301+
int status = run_command(test_binary, argv);
302+
REQUIRE(WEXITSTATUS(status) == 1);
303+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be <= 85.051100 (85.151100 was provided)"));
304+
}
305+
306+
SECTION(option + " option is too small", "should return 1") {
307+
std::vector<std::string> argv = {option, std::to_string(min - .1)};
308+
309+
int status = run_command(test_binary, argv);
310+
REQUIRE(WEXITSTATUS(status) == 1);
311+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be >= -85.051100 (-85.151100 was provided)"));
312+
}
313+
314+
SECTION(option + " option is not a double", "should return 1") {
315+
std::vector<std::string> argv = {option, "invalid"};
316+
317+
int status = run_command(test_binary, argv);
318+
REQUIRE(WEXITSTATUS(status) == 1);
319+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be a double (invalid was provided)"));
320+
}
321+
322+
SECTION(option + " option is positive with --help", "should return 0") {
323+
std::vector<std::string> argv = {option, std::to_string(max), "--help"};
324+
325+
int status = run_command(test_binary, argv);
326+
REQUIRE(WEXITSTATUS(status) == 0);
327+
}
328+
329+
SECTION(option + " option is negative with --help", "should return 0") {
330+
std::vector<std::string> argv = {option, std::to_string(min), "--help"};
331+
332+
int status = run_command(test_binary, argv);
333+
REQUIRE(WEXITSTATUS(status) == 0);
334+
}
335+
336+
SECTION(option + " option is double with --help", "should return 0") {
337+
std::vector<std::string> argv = {option, "1.23456789", "--help"};
338+
339+
int status = run_command(test_binary, argv);
340+
REQUIRE(WEXITSTATUS(status) == 0);
341+
}
272342
}
273343

274344
TEST_CASE("render_list min/max lon generator", "min/max double generator testing")
@@ -290,4 +360,49 @@ TEST_CASE("render_list min/max lon generator", "min/max double generator testing
290360
int status = run_command(test_binary, argv);
291361
REQUIRE(WEXITSTATUS(status) == 0);
292362
}
363+
364+
SECTION(option + " option is too large", "should return 1") {
365+
std::vector<std::string> argv = {option, std::to_string(max + .1)};
366+
367+
int status = run_command(test_binary, argv);
368+
REQUIRE(WEXITSTATUS(status) == 1);
369+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be <= 180.000000 (180.100000 was provided)"));
370+
}
371+
372+
SECTION(option + " option is too small", "should return 1") {
373+
std::vector<std::string> argv = {option, std::to_string(min - .1)};
374+
375+
int status = run_command(test_binary, argv);
376+
REQUIRE(WEXITSTATUS(status) == 1);
377+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be >= -180.000000 (-180.100000 was provided)"));
378+
}
379+
380+
SECTION(option + " option is not a double", "should return 1") {
381+
std::vector<std::string> argv = {option, "invalid"};
382+
383+
int status = run_command(test_binary, argv);
384+
REQUIRE(WEXITSTATUS(status) == 1);
385+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("must be a double (invalid was provided)"));
386+
}
387+
388+
SECTION(option + " option is positive with --help", "should return 0") {
389+
std::vector<std::string> argv = {option, std::to_string(max), "--help"};
390+
391+
int status = run_command(test_binary, argv);
392+
REQUIRE(WEXITSTATUS(status) == 0);
393+
}
394+
395+
SECTION(option + " option is negative with --help", "should return 0") {
396+
std::vector<std::string> argv = {option, std::to_string(min), "--help"};
397+
398+
int status = run_command(test_binary, argv);
399+
REQUIRE(WEXITSTATUS(status) == 0);
400+
}
401+
402+
SECTION(option + " option is double with --help", "should return 0") {
403+
std::vector<std::string> argv = {option, "1.23456789", "--help"};
404+
405+
int status = run_command(test_binary, argv);
406+
REQUIRE(WEXITSTATUS(status) == 0);
407+
}
293408
}

0 commit comments

Comments
 (0)