/* Copyright 2017, Michele Santullo * This file is part of "kamokan". * * "kamokan" 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. * * "kamokan" 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 "kamokan". If not, see . */ #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 "simulation_config.h" #include #include #include #include namespace { const char g_mustache_html[] = R"(
)"; const char g_expected_response[] = R"(Content-type: text/html
)"; } //unnamed namespace namespace kamokan { class IndexResponseCustomMustache : public IndexResponse { public: IndexResponseCustomMustache ( const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv ) : IndexResponse(parSettings, parStreamOut, parCgiEnv) { } virtual std::string on_mustache_retrieve() override { return g_mustache_html; } }; } //namespace kamokan 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=", "REQUEST_METHOD=GET", nullptr }; SafeStackObject fake_env(env_raw, "/"); std::string kamokan_settings( "[kamokan]\n" " host_name = 127.0.0.1\n" " website_root = " KAMOKAN_HTML_PATH "\n" " logging_level = debug\n" " langmap_dir = /usr/share/source-highlight\n" " host_path = /\n" " host_port =\n" ); SafeStackObject ini(std::move(kamokan_settings)); SafeStackObject settings(ini, "kamokan"); std::stringstream response_stream; kamokan::IndexResponseCustomMustache response(settings, &response_stream, fake_env); response.send(); response_stream.seekg(0); CHECK(response_stream.str() == g_expected_response); }