Follow up to #190 for render_list (#417)

* Fixed `render_list` build needs `libm`
* Added tests
* Updated man page
* Created function to set double
* Cleaned up / optimized a bit
* Removed `--dont-render` option
This commit is contained in:
Hummeltech
2024-03-21 13:22:02 -07:00
committed by GitHub
parent 3621428efd
commit 743cf651b1
11 changed files with 376 additions and 101 deletions

View File

@ -62,6 +62,7 @@ find_program(APXS_EXECUTABLE apxs REQUIRED)
include(CheckFunctionExists)
check_function_exists(daemon HAVE_DAEMON)
check_function_exists(getloadavg HAVE_GETLOADAVG)
check_function_exists(pow HAVE_POW)
# Include files
include(CheckIncludeFile)
@ -69,6 +70,13 @@ check_include_file(paths.h HAVE_PATHS_H)
check_include_file(sys/cdefs.h HAVE_SYS_CDEFS_H)
check_include_file(sys/loadavg.h HAVE_SYS_LOADAVG_H)
# Libraries
include(CheckLibraryExists)
if(NOT HAVE_POW)
check_library_exists(m pow "" HAVE_LIB_M)
find_library(MATH_LIBRARY m REQUIRED)
endif()
#-----------------------------------------------------------------------------
#
# Set variables

View File

@ -1,4 +1,4 @@
.TH RENDER_LIST "1" "2024-03-16" "mod_tile v0.7.1"
.TH RENDER_LIST "1" "2024-03-20" "mod_tile v0.7.1"
.\" Please adjust this date whenever revising the manpage.
.SH NAME
@ -75,13 +75,21 @@ If you are using \fB\-a\fR|\-\-all, you can restrict the tile range by adding th
.sp 0
(please note that tile coordinates must be positive integers and are not latitude and longitude values)
.PP
\fB\-x\fR|\-\-min-x=X minimum X tile coordinate
\fB\-g\fR|\-\-min-lat=LATITUDE minimum latitude
.BR
\fB\-X\fR|\-\-max-x=X maximum X tile coordinate
\fB\-G\fR|\-\-max-lat=LATITUDE maximum latitude
.BR
\fB\-y\fR|\-\-min-y=Y minimum Y tile coordinate
\fB\-w\fR|\-\-min-lon=LONGITUDE minimum longitude
.BR
\fB\-Y\fR|\-\-max-y=Y maximum Y tile coordinate
\fB\-W\fR|\-\-max-lon=LONGITUDE maximum longitude
.BR
\fB\-x\fR|\-\-min-x=X minimum X tile coordinate
.BR
\fB\-X\fR|\-\-max-x=X maximum X tile coordinate
.BR
\fB\-y\fR|\-\-min-y=Y minimum Y tile coordinate
.BR
\fB\-Y\fR|\-\-max-y=Y maximum Y tile coordinate
.PP
Without \fB\-a\fR|\-\-all, send a list of tiles to be rendered from STDIN in the format:
.BR

View File

@ -30,6 +30,7 @@ renderd_config config;
renderd_config config_slaves[MAX_SLAVES];
xmlconfigitem maps[XMLCONFIGS_MAX];
double min_max_double_opt(const char *opt_arg, const char *opt_type_name, double minimum, double maximum);
int min_max_int_opt(const char *opt_arg, const char *opt_type_name, int minimum, int maximum);
void free_map_section(xmlconfigitem map_section);
void free_map_sections(xmlconfigitem *map_sections);

View File

@ -29,6 +29,7 @@ set(COMMON_SRCS
)
set(COMMON_LIBRARIES
${GLIB_LIBRARIES}
${MATH_LIBRARY}
Threads::Threads
)

View File

@ -18,6 +18,7 @@
#include <getopt.h>
#include <glib.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -42,28 +43,15 @@ int main(int argc, char **argv)
}
#else
int
lon2tilex(float lon, unsigned int zoom)
int lon2tilex(double lon, int z)
{
if (zoom > 20) {
return -1;
}
return (int)((lon + 180) / 360 * pow(2, zoom));
return (int)(floor((lon + 180.0) / 360.0 * pow(2.0, z)));
}
static float
secf(float in)
int lat2tiley(double lat, int z)
{
return 1 / cosf(in);
}
int
lat2tiley(float lat, unsigned int zoom)
{
float lata = lat * M_PI / 180;
float ret = (1 - logf(tanf(lata) + secf(lata)) / M_PI) / 2 * pow(2, zoom);
return (int) ret;
double latrad = lat * M_PI / 180.0;
return (int)(floor((1.0 - log(tan(latrad) + (1.0 / cos(latrad))) / M_PI) / 2.0 * pow(2.0, z)));
}
void display_rate(struct timeval start, struct timeval end, int num)
@ -85,6 +73,10 @@ int main(int argc, char **argv)
const char *mapname_default = XMLCONFIG_DEFAULT;
const char *socketname_default = RENDERD_SOCKET;
const char *tile_dir_default = RENDERD_TILE_DIR;
double max_lat_default = -1;
double max_lon_default = -1;
double min_lat_default = -1;
double min_lon_default = -1;
int max_load_default = MAX_LOAD_OLD;
int max_x_default = -1;
int max_y_default = -1;
@ -98,6 +90,10 @@ int main(int argc, char **argv)
const char *mapname = mapname_default;
const char *socketname = socketname_default;
const char *tile_dir = tile_dir_default;
double max_lat = max_lat_default;
double max_lon = max_lon_default;
double min_lat = min_lat_default;
double min_lon = min_lon_default;
int max_load = max_load_default;
int max_x = max_x_default;
int max_y = max_y_default;
@ -111,6 +107,10 @@ int main(int argc, char **argv)
int mapname_passed = 0;
int socketname_passed = 0;
int tile_dir_passed = 0;
int max_lat_passed = 0;
int max_lon_passed = 0;
int min_lat_passed = 0;
int min_lon_passed = 0;
int max_load_passed = 0;
int max_x_passed = 0;
int max_y_passed = 0;
@ -128,8 +128,6 @@ int main(int argc, char **argv)
int verbose = 0;
struct storage_backend *store;
struct stat_info s;
float minLat = -1, minLon = -1, maxLat = -1, maxLon = -1;
int dontRender = 0;
foreground = 1;
@ -140,10 +138,14 @@ int main(int argc, char **argv)
{"config", required_argument, 0, 'c'},
{"force", no_argument, 0, 'f'},
{"map", required_argument, 0, 'm'},
{"max-lat", required_argument, 0, 'G'},
{"max-load", required_argument, 0, 'l'},
{"max-lon", required_argument, 0, 'W'},
{"max-x", required_argument, 0, 'X'},
{"max-y", required_argument, 0, 'Y'},
{"max-zoom", required_argument, 0, 'Z'},
{"min-lat", required_argument, 0, 'g'},
{"min-lon", required_argument, 0, 'w'},
{"min-x", required_argument, 0, 'x'},
{"min-y", required_argument, 0, 'y'},
{"min-zoom", required_argument, 0, 'z'},
@ -151,18 +153,13 @@ int main(int argc, char **argv)
{"socket", required_argument, 0, 's'},
{"tile-dir", required_argument, 0, 't'},
{"verbose", no_argument, 0, 'v'},
{"min-lat", required_argument, 0, 'A'},
{"min-lon", required_argument, 0, 'B'},
{"max-lat", required_argument, 0, 'C'},
{"max-lon", required_argument, 0, 'D'},
{"dont-render", no_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
int c = getopt_long(argc, argv, "ac:fm:l:X:Y:Z:x:y:z:n:s:t:vhVdA:B:C:D:", long_options, &option_index);
int c = getopt_long(argc, argv, "ac:fm:G:l:W:X:Y:Z:g:w:x:y:z:n:s:t:vhV", long_options, &option_index);
if (c == -1) {
break;
@ -195,11 +192,21 @@ int main(int argc, char **argv)
mapname_passed = 1;
break;
case 'G': /* -G, --max-lat */
max_lat = min_max_double_opt(optarg, "maximum latitute", -85.0511, 85.0511);
max_lat_passed = 1;
break;
case 'l': /* -l, --max-load */
max_load = min_max_int_opt(optarg, "maximum load", 0, -1);
max_load_passed = 1;
break;
case 'W': /* -W, --max-lon */
max_lon = min_max_double_opt(optarg, "maximum longitude", -180, 180);
max_lon_passed = 1;
break;
case 'X': /* -X, --max-x */
max_x = min_max_int_opt(optarg, "maximum X tile coordinate", 0, -1);
max_x_passed = 1;
@ -215,6 +222,16 @@ int main(int argc, char **argv)
max_zoom_passed = 1;
break;
case 'g': /* -g, --min-lat */
min_lat = min_max_double_opt(optarg, "minimum latitute", -85.0511, 85.0511);
min_lat_passed = 1;
break;
case 'w': /* -w, --min-lon */
min_lon = min_max_double_opt(optarg, "minimum longitude", -180, 180);
min_lon_passed = 1;
break;
case 'x': /* -x, --min-x */
min_x = min_max_int_opt(optarg, "minimum X tile coordinate", 0, -1);
min_x_passed = 1;
@ -249,26 +266,6 @@ int main(int argc, char **argv)
verbose = 1;
break;
case 'A':
minLat = atof(optarg);
break;
case 'B':
minLon = atof(optarg);
break;
case 'C':
maxLat = atof(optarg);
break;
case 'D':
maxLon = atof(optarg);
break;
case 'd':
dontRender = 1;
break;
case 'h': /* -h, --help */
fprintf(stderr, "Usage: render_list [OPTION] ...\n");
fprintf(stderr, " -a, --all render all tiles in given zoom level range instead of reading from STDIN\n");
@ -287,6 +284,10 @@ int main(int argc, char **argv)
fprintf(stderr, "\n");
fprintf(stderr, "If you are using --all, you can restrict the tile range by adding these options:\n");
fprintf(stderr, "(please note that tile coordinates must be positive integers and are not latitude and longitude values)\n");
fprintf(stderr, " -G, --max-lat=LATITUDE maximum latitude\n");
fprintf(stderr, " -g, --min-lat=LATITUDE minimum latitude\n");
fprintf(stderr, " -W, --max-lon=LONGITUDE maximum longitude\n");
fprintf(stderr, " -w, --min-lon=LONGITUDE minimum longitude\n");
fprintf(stderr, " -X, --max-x=X maximum X tile coordinate\n");
fprintf(stderr, " -x, --min-x=X minimum X tile coordinate\n");
fprintf(stderr, " -Y, --max-y=Y maximum Y tile coordinate\n");
@ -359,28 +360,56 @@ int main(int argc, char **argv)
}
if (all) {
if (((min_x != -1 || min_y != -1 || max_x != -1 || max_y != -1) &&
(minLat != 1 || minLon != -1 || maxLat != -1 || maxLon != -1)) && min_zoom != max_zoom) {
g_logger(G_LOG_LEVEL_CRITICAL, "min-zoom must be equal to max-zoom when using min-x, max-x, min-y, or max-y options");
return 1;
if (min_lat_passed && min_lon_passed && max_lat_passed && max_lon_passed) {
if (min_x_passed || min_y_passed || max_x_passed || max_y_passed) {
g_logger(G_LOG_LEVEL_CRITICAL, "min-lat, min-lon, max-lat & max-lon cannot be used together with min-x, max-x, min-y, or max-y");
return 1;
}
if (max_lat < min_lat) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min-lat (%f) is larger than max-lat (%f).", min_lat, max_lat);
return 1;
}
if (max_lon < min_lon) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min-lon (%f) is larger than max-lon (%f).", min_lon, max_lon);
return 1;
}
}
if (min_x == -1) {
if (min_x_passed || min_y_passed || max_x_passed || max_y_passed) {
if (min_zoom != max_zoom) {
g_logger(G_LOG_LEVEL_CRITICAL, "min-zoom must be equal to max-zoom when using min-x, max-x, min-y, or max-y options");
return 1;
}
if (min_x_passed && max_x_passed && max_x < min_x) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min-x (%i) is larger than max-x (%i).", min_x, max_x);
return 1;
}
if (min_y_passed && max_y_passed && max_y < min_y) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min-y (%i) is larger than max-x (%i).", min_y, max_y);
return 1;
}
}
if (!min_x_passed) {
min_x = 0;
}
if (min_y == -1) {
if (!min_y_passed) {
min_y = 0;
}
int lz = (1 << min_zoom) - 1;
if (min_zoom == max_zoom) {
if (max_x == -1) {
if (!max_x_passed) {
max_x = lz;
}
if (max_y == -1) {
if (!max_y_passed) {
max_y = lz;
}
@ -389,11 +418,6 @@ int main(int argc, char **argv)
return 1;
}
}
if (min_x < 0 || min_y < 0 || max_x < -1 || max_y < -1) {
g_logger(G_LOG_LEVEL_CRITICAL, "Invalid range, x and y values must be >= 0");
return 1;
}
}
store = init_storage_backend(tile_dir);
@ -425,41 +449,34 @@ int main(int argc, char **argv)
g_logger(G_LOG_LEVEL_MESSAGE, "Rendering all tiles from zoom %d to zoom %d", min_zoom, max_zoom);
for (z = min_zoom; z <= max_zoom; z++) {
int current_max_x = (max_x == -1) ? (1 << z) - 1 : max_x;
int current_max_y = (max_y == -1) ? (1 << z) - 1 : max_y;
int current_max_x = max_x_passed ? max_x : (1 << z) - 1;
int current_max_y = max_y_passed ? max_y : (1 << z) - 1;
if (minLon != -1 && minLat != -1 && maxLon != -1 && maxLat != -1) {
// printf("using koords\n");
// exit(0);
int minX_tmp = lon2tilex(minLon, z);
int minY_tmp = lat2tiley(minLat, z);
int maxX_tmp = lon2tilex(maxLon, z);
int maxY_tmp = lat2tiley(maxLat, z);
min_x = minX_tmp > maxX_tmp ? maxX_tmp : minX_tmp;
current_max_x = minX_tmp > maxX_tmp ? minX_tmp : maxX_tmp;
min_y = minY_tmp > maxY_tmp ? maxY_tmp : minY_tmp;
current_max_y = minY_tmp > maxY_tmp ? minY_tmp : maxY_tmp;
} else {
current_max_x = (max_x == -1) ? (1 << z) - 1 : max_x;
current_max_y = (max_y == -1) ? (1 << z) - 1 : max_y;
if (min_lat_passed && min_lon_passed && max_lat_passed && max_lon_passed) {
int max_x_tmp = lon2tilex(max_lon, z);
int max_y_tmp = lat2tiley(min_lat, z);
int min_x_tmp = lon2tilex(min_lon, z);
int min_y_tmp = lat2tiley(max_lat, z);
current_max_x = max_x_tmp ? max_x_tmp - 1 : max_x_tmp;
current_max_y = max_y_tmp;
min_x = min_x_tmp;
min_y = min_y_tmp;
}
g_logger(G_LOG_LEVEL_MESSAGE, "Rendering all tiles for zoom %d from (%d, %d) to (%d, %d)", z, min_x, min_y, current_max_x, current_max_y);
g_logger(G_LOG_LEVEL_MESSAGE, "Rendering all tiles for zoom %i from (%i, %i) to (%i, %i)", z, min_x, min_y, current_max_x, current_max_y);
if (dontRender == 0) {
for (x = min_x; x <= current_max_x; x += METATILE) {
for (y = min_y; y <= current_max_y; y += METATILE) {
if (!force) {
s = store->tile_stat(store, mapname, "", x, y, z);
}
if (force || (s.size < 0) || (s.expired)) {
enqueue(mapname, x, y, z);
num_render++;
}
num_all++;
for (x = min_x; x <= current_max_x; x += METATILE) {
for (y = min_y; y <= current_max_y; y += METATILE) {
if (!force) {
s = store->tile_stat(store, mapname, "", x, y, z);
}
if (force || (s.size < 0) || (s.expired)) {
enqueue(mapname, x, y, z);
num_render++;
}
num_all++;
}
}
}

View File

@ -153,6 +153,25 @@ void free_renderd_sections(renderd_config *renderd_sections)
}
}
double min_max_double_opt(const char *opt_arg, const char *opt_type_name, double minimum, double maximum)
{
char *endptr;
double opt = strtod(opt_arg, &endptr);
if (endptr == opt_arg) {
g_logger(G_LOG_LEVEL_CRITICAL, "Invalid %s, must be a double (%s was provided)", opt_type_name, opt_arg);
exit(1);
} else if (minimum != -1 && opt < minimum) {
g_logger(G_LOG_LEVEL_CRITICAL, "Invalid %s, must be >= %f (%s was provided)", opt_type_name, minimum, opt_arg);
exit(1);
} else if (maximum != -1 && opt > maximum) {
g_logger(G_LOG_LEVEL_CRITICAL, "Invalid %s, must be <= %f (%s was provided)", opt_type_name, maximum, opt_arg);
exit(1);
}
return opt;
}
int min_max_int_opt(const char *opt_arg, const char *opt_type_name, int minimum, int maximum)
{
char *endptr, *endptr_float;

View File

@ -429,7 +429,13 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
COMMAND ${BASH} -c "
$<TARGET_FILE:render_list> \
--all \
--config ${RENDERD_CONF}
--config ${RENDERD_CONF} \
--max-lat 85.0511 \
--max-lon 180 \
--max-zoom 5 \
--min-lat -85.0511 \
--min-lon -180 \
--min-zoom 5
"
WORKING_DIRECTORY tests
)
@ -440,7 +446,7 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
)
add_test(NAME render_list_stdin_${SOCKET_TYPE}_${STORAGE_BACKEND}
COMMAND ${BASH} -c "
echo '0 0 0' | $<TARGET_FILE:render_list> \
printf '0 0 0\n%.0s' {0..10} | $<TARGET_FILE:render_list> \
--force \
--map ${DEFAULT_MAP_NAME} \
--max-zoom 5 \
@ -460,7 +466,8 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
add_test(NAME render_list_stdin_config_${SOCKET_TYPE}_${STORAGE_BACKEND}
COMMAND ${BASH} -c "
echo '0 0 0' | $<TARGET_FILE:render_list> \
--config ${RENDERD_CONF}
--config ${RENDERD_CONF} \
--verbose
"
WORKING_DIRECTORY tests
)

View File

@ -193,7 +193,7 @@ TEST_CASE("render_expired specific", "specific testing")
}
}
TEST_CASE("render_expired generator", "generator testing")
TEST_CASE("render_expired min/max int generator", "min/max int generator testing")
{
std::string option = GENERATE("--delete-from", "--max-load", "--max-zoom", "--min-zoom", "--num-threads", "--touch-from");
@ -223,4 +223,13 @@ TEST_CASE("render_expired generator", "generator testing")
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is not an integer", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}

View File

@ -157,6 +157,26 @@ TEST_CASE("render_list specific", "specific testing")
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--all --min-x exceeds --max-x", "should return 1") {
std::string option = "--all --max-x 1 --max-zoom 1 --min-x 2 --min-zoom 1";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--all --min-y exceeds --max-y", "should return 1") {
std::string option = "--all --max-y 1 --max-zoom 1 --min-y 2 --min-zoom 1";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--config without maps", "should return 1") {
std::string option = "--config " + (std::string)RENDERD_CONF;
std::string command = test_binary + " " + option;
@ -234,9 +254,49 @@ TEST_CASE("render_list specific", "specific testing")
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--all --max-lat --max-lon --min-lat --min-lon with --max-x", "should return 1") {
std::string option = "--all --max-lat 0 --max-lon 0 --min-lat 0 --min-lon 0 --max-x 0";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--all --max-lat --max-lon --min-lat --min-lon with --max-y", "should return 1") {
std::string option = "--all --max-lat 0 --max-lon 0 --min-lat 0 --min-lon 0 --max-y 0";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--all --min-lat exceeds --max-lat", "should return 1") {
std::string option = "--all --max-lat 0 --max-lon 0 --min-lat 1 --min-lon 0";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--all --min-lon exceeds --max-lon", "should return 1") {
std::string option = "--all --max-lat 0 --max-lon 0 --min-lat 0 --min-lon 1";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}
TEST_CASE("render_list generator", "generator testing")
TEST_CASE("render_list min/max int generator", "min/max int generator testing")
{
std::string option = GENERATE("--max-load", "--max-x", "--max-y", "--max-zoom", "--min-x", "--min-y", "--min-zoom", "--num-threads");
@ -266,4 +326,131 @@ TEST_CASE("render_list generator", "generator testing")
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is not an integer", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}
TEST_CASE("render_list min/max lat generator", "min/max lat generator testing")
{
std::string option = GENERATE("--max-lat", "--min-lat");
SECTION("option is too large", "should return 1") {
std::string command = test_binary + " " + option + " 85.05111";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is too small", "should return 1") {
std::string command = test_binary + " " + option + " -85.05111";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is positive with --help", "should return 0") {
std::string command = test_binary + " " + option + " 85.0511 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is negative with --help", "should return 0") {
std::string command = test_binary + " " + option + " -85.0511 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is float with --help", "should return 0") {
std::string command = test_binary + " " + option + " 1.23456789 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is not a float", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}
TEST_CASE("render_list min/max lon generator", "min/max lon generator testing")
{
std::string option = GENERATE("--max-lon", "--min-lon");
SECTION("option is too large", "should return 1") {
std::string command = test_binary + " " + option + " 180.1";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is too small", "should return 1") {
std::string command = test_binary + " " + option + " -180.1";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is positive with --help", "should return 0") {
std::string command = test_binary + " " + option + " 180 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is negative with --help", "should return 0") {
std::string command = test_binary + " " + option + " -180 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is float with --help", "should return 0") {
std::string command = test_binary + " " + option + " 1.23456789 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is not a float", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}

View File

@ -179,7 +179,7 @@ TEST_CASE("render_old specific", "specific testing")
}
}
TEST_CASE("render_old generator", "generator testing")
TEST_CASE("render_old min/max int generator", "min/max int generator testing")
{
std::string option = GENERATE("--max-load", "--max-zoom", "--min-zoom", "--num-threads");
@ -209,4 +209,13 @@ TEST_CASE("render_old generator", "generator testing")
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is not an integer", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}

View File

@ -180,7 +180,7 @@ TEST_CASE("render_speedtest specific", "specific testing")
}
}
TEST_CASE("render_speedtest generator", "generator testing")
TEST_CASE("render_speedtest min/max int generator", "min/max int generator testing")
{
std::string option = GENERATE("--max-zoom", "--min-zoom", "--num-threads");
@ -210,4 +210,13 @@ TEST_CASE("render_speedtest generator", "generator testing")
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is not an integer", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}