From 7fc7e2fba8c63ad3da9b10d835a001e218649dcf Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 15 May 2017 09:18:11 +0100 Subject: [PATCH] Remove test-only stuff that is not necessary anymore. Env reads environment variables from the list it receives from main(), so I can also pass it a forged list now without needing extra classes with sometimes-virtual methods or other cruft. --- src/tawashiConfig.h.in | 7 --- src/tawashi_implem/cgi_env.hpp | 39 ++++++------ test/unit/CMakeLists.txt | 1 - test/unit/fake_cgi_env.cpp | 101 ------------------------------ test/unit/fake_cgi_env.hpp | 69 -------------------- test/unit/test_index_response.cpp | 40 ++++++------ 6 files changed, 39 insertions(+), 218 deletions(-) delete mode 100644 test/unit/fake_cgi_env.cpp delete mode 100644 test/unit/fake_cgi_env.hpp diff --git a/src/tawashiConfig.h.in b/src/tawashiConfig.h.in index cb2557d..43f9e5a 100644 --- a/src/tawashiConfig.h.in +++ b/src/tawashiConfig.h.in @@ -23,10 +23,3 @@ #define VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define VERSION_MINOR @PROJECT_VERSION_MINOR@ #define VERSION_PATCH @PROJECT_VERSION_PATCH@ -#cmakedefine BUILD_TESTING - -#if defined(BUILD_TESTING) -# define virtual_testing virtual -#else -# define virtual_testing -#endif diff --git a/src/tawashi_implem/cgi_env.hpp b/src/tawashi_implem/cgi_env.hpp index cf6a9fb..db3d105 100644 --- a/src/tawashi_implem/cgi_env.hpp +++ b/src/tawashi_implem/cgi_env.hpp @@ -21,7 +21,6 @@ #include "duckhandy/compatibility.h" #include "escapist.hpp" #include "kakoune/safe_ptr.hh" -#include "tawashiConfig.h" #include #include #include @@ -43,27 +42,27 @@ namespace tawashi { typedef boost::container::flat_map GetMapType; explicit Env (const char* const* parEnvList); - virtual_testing ~Env() noexcept; + ~Env() noexcept; - virtual_testing const std::string& auth_type() const; - virtual_testing std::size_t content_length() const; - virtual_testing const std::string& content_type() const; - virtual_testing boost::optional gateway_interface() const a_pure; - virtual_testing const std::string& path_info() const; - virtual_testing const std::string& path_translated() const; - virtual_testing const std::string& query_string() const; - virtual_testing const std::string& remote_addr() const; - virtual_testing const std::string& remote_host() const; - virtual_testing const std::string& remote_ident() const; - virtual_testing const std::string& remote_user() const; - virtual_testing const std::string& request_method() const; - virtual_testing const std::string& script_name() const; - virtual_testing const std::string& server_name() const; - virtual_testing uint16_t server_port() const a_pure; - virtual_testing boost::optional server_protocol() const a_pure; - virtual_testing const std::string& server_software() const; + const std::string& auth_type() const; + std::size_t content_length() const; + const std::string& content_type() const; + boost::optional gateway_interface() const a_pure; + const std::string& path_info() const; + const std::string& path_translated() const; + const std::string& query_string() const; + const std::string& remote_addr() const; + const std::string& remote_host() const; + const std::string& remote_ident() const; + const std::string& remote_user() const; + const std::string& request_method() const; + const std::string& script_name() const; + const std::string& server_name() const; + uint16_t server_port() const a_pure; + boost::optional server_protocol() const a_pure; + const std::string& server_software() const; - virtual_testing GetMapType query_string_split() const a_pure; + GetMapType query_string_split() const a_pure; std::ostream& print_all (std::ostream& parStream, const char* parNewline) const; diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 064456b..c185079 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -10,7 +10,6 @@ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_DEBUG} -Wall -Wpedantic -Wconversion add_executable(${PROJECT_NAME} check.cpp - fake_cgi_env.cpp test_ini_file.cpp test_settings_bag.cpp test_index_response.cpp diff --git a/test/unit/fake_cgi_env.cpp b/test/unit/fake_cgi_env.cpp deleted file mode 100644 index 6a3f7d2..0000000 --- a/test/unit/fake_cgi_env.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright 2017, Michele Santullo - * This file is part of "tawashi". - * - * "tawashi" 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 3 of the License, or - * (at your option) any later version. - * - * "tawashi" 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 "tawashi". If not, see . - */ - -#include "fake_cgi_env.hpp" -#include "duckhandy/lexical_cast.hpp" -#include - -namespace { - const char* const g_dummy_env_list[] = { nullptr }; -} //unnamed namespace - -namespace tawashi { - namespace cgi { - FakeEnv::FakeEnv (std::string&& parVariablesIni) : - Env(g_dummy_env_list), - m_variables(std::move(parVariablesIni)), - m_auth_type(m_variables.parsed().at("fake_env").at("auth_type")), - m_content_type(m_variables.parsed().at("fake_env").at("content_type")), - m_path_info(m_variables.parsed().at("fake_env").at("path_info")), - m_path_translated(m_variables.parsed().at("fake_env").at("path_translated")), - m_query_string(m_variables.parsed().at("fake_env").at("query_string")), - m_remote_addr(m_variables.parsed().at("fake_env").at("remote_addr")), - m_remote_host(m_variables.parsed().at("fake_env").at("remote_host")), - m_remote_ident(m_variables.parsed().at("fake_env").at("remote_ident")), - m_remote_user(m_variables.parsed().at("fake_env").at("remote_user")), - m_request_method(m_variables.parsed().at("fake_env").at("request_method")), - m_script_name(m_variables.parsed().at("fake_env").at("script_name")), - m_server_name(m_variables.parsed().at("fake_env").at("server_name")), - m_server_software(m_variables.parsed().at("fake_env").at("server_software")), - m_content_length(dhandy::lexical_cast(m_variables.parsed().at("fake_env").at("content_length"))), - m_server_port(dhandy::lexical_cast(m_variables.parsed().at("fake_env").at("server_port"))) - { - } - - const std::string& FakeEnv::auth_type() const { - return m_auth_type; - } - std::size_t FakeEnv::content_length() const { - std::size_t m_content_length; - } - const std::string& FakeEnv::content_type() const { - return m_content_type; - } - auto FakeEnv::gateway_interface() const -> boost::optional { - } - const std::string& FakeEnv::path_info() const { - return m_path_info; - } - const std::string& FakeEnv::path_translated() const { - return m_path_translated; - } - const std::string& FakeEnv::query_string() const { - return m_query_string; - } - const std::string& FakeEnv::remote_addr() const { - return m_remote_addr; - } - const std::string& FakeEnv::remote_host() const { - return m_remote_host; - } - const std::string& FakeEnv::remote_ident() const { - return m_remote_ident; - } - const std::string& FakeEnv::remote_user() const { - return m_remote_user; - } - const std::string& FakeEnv::request_method() const { - return m_request_method; - } - const std::string& FakeEnv::script_name() const { - return m_script_name; - } - const std::string& FakeEnv::server_name() const { - return m_server_name; - } - uint16_t FakeEnv::server_port() const { - uint16_t m_server_port; - } - auto FakeEnv::server_protocol() const -> boost::optional { - } - const std::string& FakeEnv::server_software() const { - return m_server_software; - } - auto FakeEnv::query_string_split() const -> GetMapType { - } - } //namespace cgi -} //namespace tawashi diff --git a/test/unit/fake_cgi_env.hpp b/test/unit/fake_cgi_env.hpp deleted file mode 100644 index 9c17858..0000000 --- a/test/unit/fake_cgi_env.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2017, Michele Santullo - * This file is part of "tawashi". - * - * "tawashi" 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 3 of the License, or - * (at your option) any later version. - * - * "tawashi" 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 "tawashi". If not, see . - */ - -#pragma once - -#include "cgi_env.hpp" -#include "ini_file.hpp" -#include - -namespace tawashi { - namespace cgi { - class FakeEnv : public Env { - public: - explicit FakeEnv (std::string&& parVariablesIni); - - virtual const std::string& auth_type() const override; - virtual std::size_t content_length() const override; - virtual const std::string& content_type() const override; - virtual boost::optional gateway_interface() const override a_pure; - virtual const std::string& path_info() const override; - virtual const std::string& path_translated() const override; - virtual const std::string& query_string() const override; - virtual const std::string& remote_addr() const override; - virtual const std::string& remote_host() const override; - virtual const std::string& remote_ident() const override; - virtual const std::string& remote_user() const override; - virtual const std::string& request_method() const override; - virtual const std::string& script_name() const override; - virtual const std::string& server_name() const override; - virtual uint16_t server_port() const override a_pure; - virtual boost::optional server_protocol() const override a_pure; - virtual const std::string& server_software() const override; - - virtual GetMapType query_string_split() const override a_pure; - - private: - IniFile m_variables; - std::string m_auth_type; - std::string m_content_type; - std::string m_path_info; - std::string m_path_translated; - std::string m_query_string; - std::string m_remote_addr; - std::string m_remote_host; - std::string m_remote_ident; - std::string m_remote_user; - std::string m_request_method; - std::string m_script_name; - std::string m_server_name; - std::string m_server_software; - std::size_t m_content_length; - uint16_t m_server_port; - }; - } //namespace cgi -} //namespace tawashi diff --git a/test/unit/test_index_response.cpp b/test/unit/test_index_response.cpp index 1e4bc95..59e2f9f 100644 --- a/test/unit/test_index_response.cpp +++ b/test/unit/test_index_response.cpp @@ -16,7 +16,7 @@ */ #include "catch.hpp" -#include "fake_cgi_env.hpp" +#include "cgi_env.hpp" #include "index_response.hpp" #include "ini_file.hpp" #include "settings_bag.hpp" @@ -74,25 +74,25 @@ namespace tawashi { TEST_CASE ("Index response", "[index][response]") { using curry::SafeStackObject; - std::string env_ini( - "[fake_env]\n" - " auth_type = \n" - " content_type = \n" - " path_info = \n" - " path_translated = \n" - " query_string = index.cgi\n" - " remote_addr = \n" - " remote_host = \n" - " remote_ident = \n" - " remote_user = \n" - " request_method = GET\n" - " script_name = \n" - " server_name = test_server\n" - " server_software = \n" - " content_length = 0\n" - " server_port = 80\n" - ); - SafeStackObject fake_env(std::move(env_ini)); + const char* const env_raw[] = { + "AUTH_TYPE=", + "CONTENT_TYPE=", + "PATH_INFO=", + "PATH_TRANSLATED=", + "QUERY_STRING=index.cgi" + "REMOTE_ADDR=", + "REMOTE_HOST=", + "REMOTE_IDENT=", + "REMOTE_USER=", + "REQUEST_METHOD=GET" + "SCRIPT_NAME=", + "SERVER_NAME=test_server" + "SERVER_SOFTWARE=", + "CONTENT_LENGTH=", + "SERVER_PORT=80", + nullptr + }; + SafeStackObject fake_env(env_raw); std::string tawashi_settings( "[tawashi]\n"