mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-08-03 12:50:02 +00:00
Make a new test project for full-page testing.
This commit is contained in:
parent
e2437a6b12
commit
9f8d89895d
5 changed files with 50 additions and 1 deletions
27
test/simulation/CMakeLists.txt
Normal file
27
test/simulation/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
project(tawashi_simulation CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wpedantic -Wconversion -Werror")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_DEBUG} -Wall -Wpedantic -Wconversion -Werror")
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
check.cpp
|
||||
test_index_response.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/Catch/single_include
|
||||
PRIVATE ${TAWASHI_GEN_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE tawashi_implem
|
||||
PRIVATE duckhandy
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME TawashiSimulationTest
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${PROJECT_NAME}
|
||||
)
|
19
test/simulation/check.cpp
Normal file
19
test/simulation/check.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* 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/>.
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
120
test/simulation/test_index_response.cpp
Normal file
120
test/simulation/test_index_response.cpp
Normal file
|
@ -0,0 +1,120 @@
|
|||
/* 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 "catch.hpp"
|
||||
#include "cgi_env.hpp"
|
||||
#include "index_response.hpp"
|
||||
#include "ini_file.hpp"
|
||||
#include "settings_bag.hpp"
|
||||
#include "safe_stack_object.hpp"
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace {
|
||||
const char g_mustache_html[] =
|
||||
R"(<body>
|
||||
<form action="{{base_uri}}/paste.cgi" method="post" accept-charset="UTF-8">
|
||||
|
||||
<div id="content">
|
||||
<textarea type="text" id="PasteTextBox" name="pastie" placeholder=">Text..." autofocus required autocomplete="off" name="text"></textarea>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</body>
|
||||
)";
|
||||
|
||||
const char g_expected_response[] =
|
||||
R"(Content-type: text/html
|
||||
|
||||
<body>
|
||||
<form action="http://127.0.0.1/paste.cgi" method="post" accept-charset="UTF-8">
|
||||
|
||||
<div id="content">
|
||||
<textarea type="text" id="PasteTextBox" name="pastie" placeholder=">Text..." autofocus required autocomplete="off" name="text"></textarea>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</body>
|
||||
)";
|
||||
} //unnamed namespace
|
||||
|
||||
namespace tawashi {
|
||||
class IndexResponseCustomMustache : public IndexResponse {
|
||||
public:
|
||||
IndexResponseCustomMustache (
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
) :
|
||||
IndexResponse(parSettings, parStreamOut, parCgiEnv)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string on_mustache_retrieve() override {
|
||||
return g_mustache_html;
|
||||
}
|
||||
};
|
||||
} //namespace tawashi
|
||||
|
||||
TEST_CASE ("Index response", "[index][response]") {
|
||||
using curry::SafeStackObject;
|
||||
|
||||
auto statuslog = spdlog::stdout_logger_st("statuslog");
|
||||
|
||||
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",
|
||||
"HTTPS=",
|
||||
nullptr
|
||||
};
|
||||
SafeStackObject<tawashi::cgi::Env> fake_env(env_raw, "/");
|
||||
|
||||
std::string tawashi_settings(
|
||||
"[tawashi]\n"
|
||||
" host_name = 127.0.0.1\n"
|
||||
" website_root = /home/michele/dev/code/cpp/tawashi/html\n"
|
||||
" logging_level = debug\n"
|
||||
" langmap_dir = /usr/share/source-highlight\n"
|
||||
" host_path = /\n"
|
||||
" host_port =\n"
|
||||
);
|
||||
SafeStackObject<tawashi::IniFile> ini(std::move(tawashi_settings));
|
||||
SafeStackObject<tawashi::SettingsBag> settings(ini);
|
||||
|
||||
std::stringstream response_stream;
|
||||
|
||||
tawashi::IndexResponseCustomMustache response(settings, &response_stream, fake_env);
|
||||
response.send();
|
||||
|
||||
response_stream.seekg(0);
|
||||
CHECK(response_stream.str() == g_expected_response);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue