Mercurial > irccd
changeset 774:bfc51f8a00f3
Tests: cleanup data structure and rename io to stream
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 26 Oct 2018 13:57:36 +0200 |
parents | 8c44bbcbbab9 |
children | dc9af75c609c |
files | tests/data/root/file-1.txt tests/data/root/level-1/level-2/file-2.txt tests/data/root/lines.txt tests/root/file-1.txt tests/root/level-1/level-2/file-2.txt tests/root/lines.txt tests/src/libcommon/CMakeLists.txt tests/src/libcommon/fs-util/main.cpp tests/src/libcommon/io/CMakeLists.txt tests/src/libcommon/io/main.cpp tests/src/libcommon/stream/CMakeLists.txt tests/src/libcommon/stream/main.cpp tests/src/libirccd-js/js-api-directory/main.cpp tests/src/libirccd-js/js-api-file/main.cpp |
diffstat | 14 files changed, 281 insertions(+), 281 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/root/file-1.txt Fri Oct 26 13:57:36 2018 +0200 @@ -0,0 +1,1 @@ +file-1.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/root/level-1/level-2/file-2.txt Fri Oct 26 13:57:36 2018 +0200 @@ -0,0 +1,1 @@ +file-2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/root/lines.txt Fri Oct 26 13:57:36 2018 +0200 @@ -0,0 +1,3 @@ +a +b +c
--- a/tests/root/file-1.txt Fri Oct 26 13:01:00 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -file-1.txt
--- a/tests/root/level-1/level-2/file-2.txt Fri Oct 26 13:01:00 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -file-2.txt
--- a/tests/root/lines.txt Fri Oct 26 13:01:00 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -a -b -c
--- a/tests/src/libcommon/CMakeLists.txt Fri Oct 26 13:01:00 2018 +0200 +++ b/tests/src/libcommon/CMakeLists.txt Fri Oct 26 13:57:36 2018 +0200 @@ -17,5 +17,5 @@ # add_subdirectory(fs-util) -add_subdirectory(io) +add_subdirectory(stream) add_subdirectory(string-util)
--- a/tests/src/libcommon/fs-util/main.cpp Fri Oct 26 13:01:00 2018 +0200 +++ b/tests/src/libcommon/fs-util/main.cpp Fri Oct 26 13:57:36 2018 +0200 @@ -35,8 +35,8 @@ BOOST_AUTO_TEST_CASE(not_recursive) { - auto file1 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-1.txt", false); - auto file2 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-2.txt", false); + auto file1 = fs_util::find(CMAKE_SOURCE_DIR "/tests/data/root", "file-1.txt", false); + auto file2 = fs_util::find(CMAKE_SOURCE_DIR "/tests/data/root", "file-2.txt", false); BOOST_TEST(file1.find("file-1.txt") != std::string::npos); BOOST_TEST(file2.empty()); @@ -44,8 +44,8 @@ BOOST_AUTO_TEST_CASE(recursive) { - auto file1 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-1.txt", true); - auto file2 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-2.txt", true); + auto file1 = fs_util::find(CMAKE_SOURCE_DIR "/tests/data/root", "file-1.txt", true); + auto file2 = fs_util::find(CMAKE_SOURCE_DIR "/tests/data/root", "file-2.txt", true); BOOST_TEST(file1.find("file-1.txt") != std::string::npos); BOOST_TEST(file2.find("file-2.txt") != std::string::npos); @@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(not_recursive) { const std::regex regex("file-[12]\\.txt"); - const auto file = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", regex, false); + const auto file = fs_util::find(CMAKE_SOURCE_DIR "/tests/data/root", regex, false); BOOST_TEST(file.find("file-1.txt") != std::string::npos); } @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(recursive) { const std::regex regex("file-[12]\\.txt"); - const auto file = fs_util::find(CMAKE_SOURCE_DIR "/tests/root/level-1", regex, true); + const auto file = fs_util::find(CMAKE_SOURCE_DIR "/tests/data/root/level-1", regex, true); BOOST_TEST(file.find("file-2.txt") != std::string::npos); }
--- a/tests/src/libcommon/io/CMakeLists.txt Fri Oct 26 13:01:00 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -# -# CMakeLists.txt -- CMake build system for irccd -# -# Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -irccd_define_test( - NAME io - SOURCES main.cpp - LIBRARIES libirccd-core -)
--- a/tests/src/libcommon/io/main.cpp Fri Oct 26 13:01:00 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,228 +0,0 @@ -/* - * main.cpp -- test io classes - * - * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define BOOST_TEST_MODULE "io" -#include <boost/test/unit_test.hpp> -#include <boost/mpl/list.hpp> -#include <boost/predef/os.h> - -#include <irccd/sysconfig.hpp> - -#include <irccd/socket_acceptor.hpp> -#include <irccd/socket_connector.hpp> -#include <irccd/socket_stream.hpp> - -#if defined(IRCCD_HAVE_SSL) -# include <irccd/tls_acceptor.hpp> -# include <irccd/tls_connector.hpp> -# include <irccd/tls_stream.hpp> -#endif // !IRCCD_HAVE_SSL - -using boost::asio::io_service; -using boost::asio::ip::tcp; - -#if defined(IRCCD_HAVE_SSL) -using boost::asio::ssl::context; -#endif - -#if !BOOST_OS_WINDOWS -using boost::asio::local::stream_protocol; -#endif - -namespace irccd { - -namespace { - -class io_fixture { -public: - io_service service_; - - std::unique_ptr<acceptor> acceptor_; - std::unique_ptr<connector> connector_; - - std::shared_ptr<stream> stream1_; - std::shared_ptr<stream> stream2_; - - virtual auto create_acceptor() -> std::unique_ptr<acceptor> = 0; - - virtual auto create_connector() -> std::unique_ptr<connector> = 0; - - void init() - { - acceptor_ = create_acceptor(); - connector_ = create_connector(); - - acceptor_->accept([this] (auto code, auto stream) { - if (code) - throw std::system_error(code); - - stream1_ = std::move(stream); - }); - connector_->connect([this] (auto code, auto stream) { - if (code) - throw std::system_error(code); - - stream2_ = std::move(stream); - }); - - service_.run(); - service_.reset(); - } -}; - -class ip_io_fixture : public io_fixture { -private: - tcp::endpoint endpoint_; - -protected: - /** - * \copydoc io_fixture::create_acceptor - */ - auto create_acceptor() -> std::unique_ptr<acceptor> override - { - tcp::endpoint endpoint(tcp::v4(), 0U); - tcp::acceptor acceptor(service_, std::move(endpoint)); - - endpoint_ = acceptor.local_endpoint(); - - return std::make_unique<ip_acceptor>(std::move(acceptor)); - } - - /** - * \copydoc io_fixture::create_connector - */ - auto create_connector() -> std::unique_ptr<connector> override - { - return std::make_unique<ip_connector>(service_, endpoint_); - } -}; - -#if defined(IRCCD_HAVE_SSL) - -class ssl_io_fixture : public io_fixture { -private: - tcp::endpoint endpoint_; - -protected: - /** - * \copydoc io_fixture::create_acceptor - */ - auto create_acceptor() -> std::unique_ptr<acceptor> override - { - context context(context::sslv23); - - context.use_certificate_file(TESTS_SOURCE_DIR "/data/test.crt", context::pem); - context.use_private_key_file(TESTS_SOURCE_DIR "/data/test.key", context::pem); - - tcp::endpoint endpoint(tcp::v4(), 0U); - tcp::acceptor acceptor(service_, std::move(endpoint)); - - endpoint_ = acceptor.local_endpoint(); - - return std::make_unique<tls_acceptor<>>(std::move(context), std::move(acceptor)); - } - - /** - * \copydoc io_fixture::create_connector - */ - auto create_connector() -> std::unique_ptr<connector> override - { - return std::make_unique<tls_connector<>>(context(context::sslv23), service_, endpoint_); - } -}; - -#endif // !IRCCD_HAVE_SSL - -#if !BOOST_OS_WINDOWS - -class local_io_fixture : public io_fixture { -public: - /** - * \copydoc io_fixture::create_acceptor - */ - auto create_acceptor() -> std::unique_ptr<acceptor> override - { - std::remove(CMAKE_BINARY_DIR "/tmp/io-test.sock"); - - stream_protocol::acceptor acceptor(service_, CMAKE_BINARY_DIR "/tmp/io-test.sock"); - - return std::make_unique<local_acceptor>(std::move(acceptor)); - } - - /** - * \copydoc io_fixture::create_connector - */ - auto create_connector() -> std::unique_ptr<connector> override - { - return std::make_unique<local_connector>(service_, CMAKE_BINARY_DIR "/tmp/io-test.sock"); - } -}; - -#endif // !BOOST_OS_WINDOWS - -/** - * List of fixtures to tests. - */ -using list = boost::mpl::list< - ip_io_fixture -#if defined(IRCCD_HAVE_SSL) - , ssl_io_fixture -#endif -#if !BOOST_OS_WINDOWS - , local_io_fixture -#endif ->; - -BOOST_AUTO_TEST_CASE_TEMPLATE(invalid_argument, Test, list) -{ - Test fixture; - - const nlohmann::json message{ - { "abc", 123 }, - { "def", 456 } - }; - - fixture.init(); - fixture.stream1_->read([] (auto code, auto message) { - BOOST_TEST(!code); - BOOST_TEST(message.is_object()); - BOOST_TEST(message["abc"].template get<int>() == 123); - BOOST_TEST(message["def"].template get<int>() == 456); - }); - fixture.stream2_->write(message, [] (auto code) { - BOOST_TEST(!code); - }); - fixture.service_.run(); -} - -BOOST_AUTO_TEST_CASE_TEMPLATE(network_down, Test, list) -{ - Test fixture; - - fixture.init(); - fixture.stream1_->read([] (auto code, auto message) { - BOOST_TEST(code.value() == static_cast<int>(std::errc::not_connected)); - BOOST_TEST(message.is_null()); - }); - fixture.stream2_ = nullptr; - fixture.service_.run(); -} - -} // !namespace - -} // !irccd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/src/libcommon/stream/CMakeLists.txt Fri Oct 26 13:57:36 2018 +0200 @@ -0,0 +1,23 @@ +# +# CMakeLists.txt -- CMake build system for irccd +# +# Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +irccd_define_test( + NAME io + SOURCES main.cpp + LIBRARIES libirccd-core +)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/src/libcommon/stream/main.cpp Fri Oct 26 13:57:36 2018 +0200 @@ -0,0 +1,228 @@ +/* + * main.cpp -- test io classes + * + * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define BOOST_TEST_MODULE "stream" +#include <boost/test/unit_test.hpp> +#include <boost/mpl/list.hpp> +#include <boost/predef/os.h> + +#include <irccd/sysconfig.hpp> + +#include <irccd/socket_acceptor.hpp> +#include <irccd/socket_connector.hpp> +#include <irccd/socket_stream.hpp> + +#if defined(IRCCD_HAVE_SSL) +# include <irccd/tls_acceptor.hpp> +# include <irccd/tls_connector.hpp> +# include <irccd/tls_stream.hpp> +#endif // !IRCCD_HAVE_SSL + +using boost::asio::io_service; +using boost::asio::ip::tcp; + +#if defined(IRCCD_HAVE_SSL) +using boost::asio::ssl::context; +#endif + +#if !BOOST_OS_WINDOWS +using boost::asio::local::stream_protocol; +#endif + +namespace irccd { + +namespace { + +class stream_fixture { +public: + io_service service_; + + std::unique_ptr<acceptor> acceptor_; + std::unique_ptr<connector> connector_; + + std::shared_ptr<stream> stream1_; + std::shared_ptr<stream> stream2_; + + virtual auto create_acceptor() -> std::unique_ptr<acceptor> = 0; + + virtual auto create_connector() -> std::unique_ptr<connector> = 0; + + void init() + { + acceptor_ = create_acceptor(); + connector_ = create_connector(); + + acceptor_->accept([this] (auto code, auto stream) { + if (code) + throw std::system_error(code); + + stream1_ = std::move(stream); + }); + connector_->connect([this] (auto code, auto stream) { + if (code) + throw std::system_error(code); + + stream2_ = std::move(stream); + }); + + service_.run(); + service_.reset(); + } +}; + +class ip_stream_fixture : public stream_fixture { +private: + tcp::endpoint endpoint_; + +protected: + /** + * \copydoc io_fixture::create_acceptor + */ + auto create_acceptor() -> std::unique_ptr<acceptor> override + { + tcp::endpoint endpoint(tcp::v4(), 0U); + tcp::acceptor acceptor(service_, std::move(endpoint)); + + endpoint_ = acceptor.local_endpoint(); + + return std::make_unique<ip_acceptor>(std::move(acceptor)); + } + + /** + * \copydoc io_fixture::create_connector + */ + auto create_connector() -> std::unique_ptr<connector> override + { + return std::make_unique<ip_connector>(service_, endpoint_); + } +}; + +#if defined(IRCCD_HAVE_SSL) + +class ssl_stream_fixture : public stream_fixture { +private: + tcp::endpoint endpoint_; + +protected: + /** + * \copydoc io_fixture::create_acceptor + */ + auto create_acceptor() -> std::unique_ptr<acceptor> override + { + context context(context::sslv23); + + context.use_certificate_file(TESTS_SOURCE_DIR "/data/test.crt", context::pem); + context.use_private_key_file(TESTS_SOURCE_DIR "/data/test.key", context::pem); + + tcp::endpoint endpoint(tcp::v4(), 0U); + tcp::acceptor acceptor(service_, std::move(endpoint)); + + endpoint_ = acceptor.local_endpoint(); + + return std::make_unique<tls_acceptor<>>(std::move(context), std::move(acceptor)); + } + + /** + * \copydoc io_fixture::create_connector + */ + auto create_connector() -> std::unique_ptr<connector> override + { + return std::make_unique<tls_connector<>>(context(context::sslv23), service_, endpoint_); + } +}; + +#endif // !IRCCD_HAVE_SSL + +#if !BOOST_OS_WINDOWS + +class local_stream_fixture : public stream_fixture { +public: + /** + * \copydoc io_fixture::create_acceptor + */ + auto create_acceptor() -> std::unique_ptr<acceptor> override + { + std::remove(CMAKE_BINARY_DIR "/tmp/io-test.sock"); + + stream_protocol::acceptor acceptor(service_, CMAKE_BINARY_DIR "/tmp/io-test.sock"); + + return std::make_unique<local_acceptor>(std::move(acceptor)); + } + + /** + * \copydoc io_fixture::create_connector + */ + auto create_connector() -> std::unique_ptr<connector> override + { + return std::make_unique<local_connector>(service_, CMAKE_BINARY_DIR "/tmp/io-test.sock"); + } +}; + +#endif // !BOOST_OS_WINDOWS + +/** + * List of fixtures to tests. + */ +using list = boost::mpl::list< + ip_stream_fixture +#if defined(IRCCD_HAVE_SSL) + , ssl_stream_fixture +#endif +#if !BOOST_OS_WINDOWS + , local_stream_fixture +#endif +>; + +BOOST_AUTO_TEST_CASE_TEMPLATE(invalid_argument, Test, list) +{ + Test fixture; + + const nlohmann::json message{ + { "abc", 123 }, + { "def", 456 } + }; + + fixture.init(); + fixture.stream1_->read([] (auto code, auto message) { + BOOST_TEST(!code); + BOOST_TEST(message.is_object()); + BOOST_TEST(message["abc"].template get<int>() == 123); + BOOST_TEST(message["def"].template get<int>() == 456); + }); + fixture.stream2_->write(message, [] (auto code) { + BOOST_TEST(!code); + }); + fixture.service_.run(); +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(network_down, Test, list) +{ + Test fixture; + + fixture.init(); + fixture.stream1_->read([] (auto code, auto message) { + BOOST_TEST(code.value() == static_cast<int>(std::errc::not_connected)); + BOOST_TEST(message.is_null()); + }); + fixture.stream2_ = nullptr; + fixture.service_.run(); +} + +} // !namespace + +} // !irccd
--- a/tests/src/libirccd-js/js-api-directory/main.cpp Fri Oct 26 13:01:00 2018 +0200 +++ b/tests/src/libirccd-js/js-api-directory/main.cpp Fri Oct 26 13:57:36 2018 +0200 @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(constructor) { const std::string script( - "d = new Irccd.Directory(CMAKE_SOURCE_DIR + \"/tests/root\");" + "d = new Irccd.Directory(CMAKE_SOURCE_DIR + \"/tests/data/root\");" "p = d.path;" "l = d.entries.length;" );
--- a/tests/src/libirccd-js/js-api-file/main.cpp Fri Oct 26 13:01:00 2018 +0200 +++ b/tests/src/libirccd-js/js-api-file/main.cpp Fri Oct 26 13:57:36 2018 +0200 @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(function_exists) { - if (duk_peval_string(plugin_->get_context(), "result = Irccd.File.exists(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt')")) + if (duk_peval_string(plugin_->get_context(), "result = Irccd.File.exists(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt')")) throw duk::get_stack(plugin_->get_context(), -1); BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result")); @@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(method_basename) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "result = f.basename();" ); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(method_basename_closed) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.close();" "result = f.basename();" ); @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(method_dirname) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "result = f.dirname();" ); @@ -130,13 +130,13 @@ throw duk::get_stack(plugin_->get_context(), -1); BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result")); - BOOST_TEST(CMAKE_SOURCE_DIR "/tests/root" == duk_get_string(plugin_->get_context(), -1)); + BOOST_TEST(CMAKE_SOURCE_DIR "/tests/data/root" == duk_get_string(plugin_->get_context(), -1)); } BOOST_AUTO_TEST_CASE(method_dirname_closed) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.close();" "result = f.dirname();" ); @@ -145,13 +145,13 @@ throw duk::get_stack(plugin_->get_context(), -1); BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result")); - BOOST_TEST(CMAKE_SOURCE_DIR "/tests/root" == duk_get_string(plugin_->get_context(), -1)); + BOOST_TEST(CMAKE_SOURCE_DIR "/tests/data/root" == duk_get_string(plugin_->get_context(), -1)); } BOOST_AUTO_TEST_CASE(method_lines) { const auto ret = duk_peval_string(plugin_->get_context(), - "result = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/lines.txt', 'r').lines();" + "result = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/lines.txt', 'r').lines();" ); if (ret != 0) @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(method_seek1) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.seek(Irccd.File.SeekSet, 6);" "result = f.read(1);" ); @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(method_seek1_closed) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.close();" "f.seek(Irccd.File.SeekSet, 4);" "result = f.read(1);" @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(method_seek2) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.seek(Irccd.File.SeekSet, 2);" "f.seek(Irccd.File.SeekCur, 4);" "result = f.read(1);" @@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(method_seek2c_losed) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.close();" "f.seek(Irccd.File.SeekSet, 2);" "f.seek(Irccd.File.SeekCur, 2);" @@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(method_seek3) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.seek(Irccd.File.SeekEnd, -2);" "result = f.read(1);" ); @@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(method_seek3_closed) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "f.close();" "f.seek(Irccd.File.SeekEnd, -2);" "result = f.read(1);" @@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(method_read1) { const auto ret = duk_peval_string(plugin_->get_context(), - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/file-1.txt', 'r');" "result = f.read();" ); @@ -279,7 +279,7 @@ { const auto ret = duk_peval_string(plugin_->get_context(), "result = [];" - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/lines.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/lines.txt', 'r');" "for (var s; s = f.readline(); ) {" " result.push(s);" "}" @@ -298,7 +298,7 @@ { const auto ret = duk_peval_string(plugin_->get_context(), "result = [];" - "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/lines.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/data/root/lines.txt', 'r');" "f.close();" "for (var s; s = f.readline(); ) {" " result.push(s);"