comparison tests/src/libirccd-js/js-api-directory/main.cpp @ 758:445c071e8efb

Irccd: Javascript API cleanup - Place all related code to `js` namespace, - Import duk.hpp and duk.cpp from libduk.
author David Demelier <markand@malikania.fr>
date Thu, 09 Aug 2018 13:07:19 +0200
parents tests/src/libirccd-js/jsapi-directory/main.cpp@97b356010785
children 35c1517d705d
comparison
equal deleted inserted replaced
757:97b356010785 758:445c071e8efb
1 /*
2 * main.cpp -- test Irccd.Directory API
3 *
4 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #define BOOST_TEST_MODULE "Directory Javascript API"
20 #include <boost/test/unit_test.hpp>
21
22 #include <irccd/test/js_fixture.hpp>
23
24 namespace irccd::test {
25
26 using namespace irccd::js;
27
28 namespace {
29
30 class directory_js_fixture : public js_fixture {
31 public:
32 directory_js_fixture()
33 {
34 duk::push(plugin_->get_context(), CMAKE_SOURCE_DIR);
35 duk_put_global_string(plugin_->get_context(), "CMAKE_SOURCE_DIR");
36 }
37 };
38
39 BOOST_FIXTURE_TEST_SUITE(directory_js_api_suite, directory_js_fixture)
40
41 BOOST_AUTO_TEST_CASE(constructor)
42 {
43 const std::string script(
44 "d = new Irccd.Directory(CMAKE_SOURCE_DIR + \"/tests/root\");"
45 "p = d.path;"
46 "l = d.entries.length;"
47 );
48
49 if (duk_peval_string(plugin_->get_context(), script.c_str()) != 0)
50 throw duk::get_stack(plugin_->get_context(), -1);
51
52 duk_get_global_string(plugin_->get_context(), "l");
53 BOOST_TEST(duk_get_int(plugin_->get_context(), -1) == 3);
54 }
55
56 BOOST_AUTO_TEST_SUITE_END()
57
58 } // !namespace
59
60 } // !irccd::test