1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-02-09 09:23:56 +00:00

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.
This commit is contained in:
King_DuckZ 2017-05-15 09:18:11 +01:00
parent 660d911539
commit 7fc7e2fba8
6 changed files with 39 additions and 218 deletions

View file

@ -23,10 +23,3 @@
#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define VERSION_MINOR @PROJECT_VERSION_MINOR@ #define VERSION_MINOR @PROJECT_VERSION_MINOR@
#define VERSION_PATCH @PROJECT_VERSION_PATCH@ #define VERSION_PATCH @PROJECT_VERSION_PATCH@
#cmakedefine BUILD_TESTING
#if defined(BUILD_TESTING)
# define virtual_testing virtual
#else
# define virtual_testing
#endif

View file

@ -21,7 +21,6 @@
#include "duckhandy/compatibility.h" #include "duckhandy/compatibility.h"
#include "escapist.hpp" #include "escapist.hpp"
#include "kakoune/safe_ptr.hh" #include "kakoune/safe_ptr.hh"
#include "tawashiConfig.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_ref.hpp>
@ -43,27 +42,27 @@ namespace tawashi {
typedef boost::container::flat_map<std::string, std::string> GetMapType; typedef boost::container::flat_map<std::string, std::string> GetMapType;
explicit Env (const char* const* parEnvList); explicit Env (const char* const* parEnvList);
virtual_testing ~Env() noexcept; ~Env() noexcept;
virtual_testing const std::string& auth_type() const; const std::string& auth_type() const;
virtual_testing std::size_t content_length() const; std::size_t content_length() const;
virtual_testing const std::string& content_type() const; const std::string& content_type() const;
virtual_testing boost::optional<VersionInfo> gateway_interface() const a_pure; boost::optional<VersionInfo> gateway_interface() const a_pure;
virtual_testing const std::string& path_info() const; const std::string& path_info() const;
virtual_testing const std::string& path_translated() const; const std::string& path_translated() const;
virtual_testing const std::string& query_string() const; const std::string& query_string() const;
virtual_testing const std::string& remote_addr() const; const std::string& remote_addr() const;
virtual_testing const std::string& remote_host() const; const std::string& remote_host() const;
virtual_testing const std::string& remote_ident() const; const std::string& remote_ident() const;
virtual_testing const std::string& remote_user() const; const std::string& remote_user() const;
virtual_testing const std::string& request_method() const; const std::string& request_method() const;
virtual_testing const std::string& script_name() const; const std::string& script_name() const;
virtual_testing const std::string& server_name() const; const std::string& server_name() const;
virtual_testing uint16_t server_port() const a_pure; uint16_t server_port() const a_pure;
virtual_testing boost::optional<VersionInfo> server_protocol() const a_pure; boost::optional<VersionInfo> server_protocol() const a_pure;
virtual_testing const std::string& server_software() const; 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; std::ostream& print_all (std::ostream& parStream, const char* parNewline) const;

View file

@ -10,7 +10,6 @@ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_DEBUG} -Wall -Wpedantic -Wconversion
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}
check.cpp check.cpp
fake_cgi_env.cpp
test_ini_file.cpp test_ini_file.cpp
test_settings_bag.cpp test_settings_bag.cpp
test_index_response.cpp test_index_response.cpp

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "fake_cgi_env.hpp"
#include "duckhandy/lexical_cast.hpp"
#include <cassert>
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<std::size_t>(m_variables.parsed().at("fake_env").at("content_length"))),
m_server_port(dhandy::lexical_cast<uint16_t>(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<VersionInfo> {
}
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<VersionInfo> {
}
const std::string& FakeEnv::server_software() const {
return m_server_software;
}
auto FakeEnv::query_string_split() const -> GetMapType {
}
} //namespace cgi
} //namespace tawashi

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "cgi_env.hpp"
#include "ini_file.hpp"
#include <string>
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<VersionInfo> 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<VersionInfo> 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

View file

@ -16,7 +16,7 @@
*/ */
#include "catch.hpp" #include "catch.hpp"
#include "fake_cgi_env.hpp" #include "cgi_env.hpp"
#include "index_response.hpp" #include "index_response.hpp"
#include "ini_file.hpp" #include "ini_file.hpp"
#include "settings_bag.hpp" #include "settings_bag.hpp"
@ -74,25 +74,25 @@ namespace tawashi {
TEST_CASE ("Index response", "[index][response]") { TEST_CASE ("Index response", "[index][response]") {
using curry::SafeStackObject; using curry::SafeStackObject;
std::string env_ini( const char* const env_raw[] = {
"[fake_env]\n" "AUTH_TYPE=",
" auth_type = \n" "CONTENT_TYPE=",
" content_type = \n" "PATH_INFO=",
" path_info = \n" "PATH_TRANSLATED=",
" path_translated = \n" "QUERY_STRING=index.cgi"
" query_string = index.cgi\n" "REMOTE_ADDR=",
" remote_addr = \n" "REMOTE_HOST=",
" remote_host = \n" "REMOTE_IDENT=",
" remote_ident = \n" "REMOTE_USER=",
" remote_user = \n" "REQUEST_METHOD=GET"
" request_method = GET\n" "SCRIPT_NAME=",
" script_name = \n" "SERVER_NAME=test_server"
" server_name = test_server\n" "SERVER_SOFTWARE=",
" server_software = \n" "CONTENT_LENGTH=",
" content_length = 0\n" "SERVER_PORT=80",
" server_port = 80\n" nullptr
); };
SafeStackObject<tawashi::cgi::FakeEnv> fake_env(std::move(env_ini)); SafeStackObject<tawashi::cgi::Env> fake_env(env_raw);
std::string tawashi_settings( std::string tawashi_settings(
"[tawashi]\n" "[tawashi]\n"