Files
mod_tile/tests/render_old_test.cpp
Hummeltech 7389b160bf Add renderd_config.c usage into render_* targets (#400)
* Add support for reading `renderd.conf` to `render_expired`
* Add support for reading `renderd.conf` to `render_list`
* Add support for reading `renderd.conf` to `render_old`
* Add support for reading `renderd.conf` to `render_speedtest`
* Move renderd/render_* execution tests to own files
* Reduce variable scope & minor clean up
* Use `stat` rather than `access` to check if file exists
2024-03-04 12:03:16 -07:00

213 lines
6.3 KiB
C++

/*
* Copyright (c) 2007 - 2023 by mod_tile contributors (see AUTHORS file)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; If not, see http://www.gnu.org/licenses/.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "catch/catch.hpp"
#include "config.h"
#include "render_config.h"
#ifdef __FreeBSD__
#include <sys/wait.h>
#endif
#ifndef PROJECT_BINARY_DIR
#define PROJECT_BINARY_DIR "."
#endif
#ifndef RENDERD_CONF
#define RENDERD_CONF "./etc/renderd/renderd.conf"
#endif
std::string test_binary = (std::string)PROJECT_BINARY_DIR + "/" + "render_old";
TEST_CASE("render_old common", "common testing")
{
SECTION("invalid long option", "should return 1") {
std::string option = "--doesnotexist";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("invalid short options", "should return 1") {
std::string option = "-doesnotexist";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--help", "should return 0") {
std::string option = "--help";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("--version", "should show version number") {
std::string option = "--version";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
std::string output;
char buffer[sizeof(VERSION)];
fgets(buffer, sizeof(buffer), pipe);
output += buffer;
REQUIRE(output == VERSION);
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("--config invalid file", "should return 1") {
std::string option = "--config /path/is/invalid";
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_old specific", "specific testing")
{
SECTION("--num-threads subceeds minimum of 1", "should return 1") {
std::string option = "--num-threads 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("--min-zoom/--max-zoom exceeds maximum of MAX_ZOOM", "should return 1") {
std::string option = GENERATE("--max-zoom", "--min-zoom");
std::string command = test_binary + " " + option + " " + std::to_string(MAX_ZOOM + 1);
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--min-zoom exceeds --max-zoom", "should return 1") {
std::string option = "--max-zoom " + std::to_string(MAX_ZOOM - 2) + " --min-zoom " + std::to_string(MAX_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("--timestamp is not an integer", "should return 1") {
std::string option = "--timestamp invalid";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--timestamp is a date with --help", "should return 0") {
std::string option = GENERATE("--timestamp 01/01/01", "--timestamp 01/01/1901");
std::string command = test_binary + " " + option + " --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("--timestamp is an integer with --help", "should return 0") {
std::string option = "--timestamp 111 --help";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("--config without maps", "should return 1") {
std::string option = "--config " + (std::string)RENDERD_CONF;
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 with invalid --map", "should return 1") {
std::string renderd_conf_examples = (std::string)RENDERD_CONF + ".examples";
std::string option = "--config " + renderd_conf_examples + " --map invalid";
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_old generator", "generator testing")
{
std::string option = GENERATE("--max-load", "--max-zoom", "--min-zoom", "--num-threads");
SECTION("option is positive with --help", "should return 0") {
std::string command = test_binary + " " + option + " 1 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is negative", "should return 1") {
std::string command = test_binary + " " + option + " -1";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is float", "should return 1") {
std::string command = test_binary + " " + option + " 1.23456789";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}