comparison tests/js-timer/main.cpp @ 0:1158cffe5a5e

Initial import
author David Demelier <markand@malikania.fr>
date Mon, 08 Feb 2016 16:43:14 +0100
parents
children f8160d515a76
comparison
equal deleted inserted replaced
-1:000000000000 0:1158cffe5a5e
1 /*
2 * main.cpp -- test Irccd.Timer API
3 *
4 * Copyright (c) 2013-2016 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 #include <gtest/gtest.h>
20
21 #include <irccd.h>
22 #include <elapsed-timer.h>
23 #include <system.h>
24
25 using namespace irccd;
26
27 TEST(Basic, single)
28 {
29 Irccd irccd;
30 ElapsedTimer timer;
31
32 auto plugin = std::make_shared<Plugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-single.js");
33
34 irccd.addPlugin(plugin);
35
36 while (timer.elapsed() < 3000) {
37 irccd.poll();
38 irccd.dispatch();
39 }
40
41 ASSERT_EQ(1, plugin->context().getGlobal<int>("count"));
42 }
43
44 TEST(Basic, repeat)
45 {
46 Irccd irccd;
47 ElapsedTimer timer;
48
49 auto plugin = std::make_shared<Plugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-repeat.js");
50
51 irccd.addPlugin(plugin);
52
53 while (timer.elapsed() < 3000) {
54 irccd.poll();
55 irccd.dispatch();
56 }
57
58 ASSERT_GE(plugin->context().getGlobal<int>("count"), 5);
59 }
60
61 #if 0
62
63 /*
64 * XXX: currently disabled because it will break single-shot timers.
65 */
66
67 TEST(Basic, pending)
68 {
69 /*
70 * This test ensure that if pending actions on a stopped timer are never executed.
71 */
72 Irccd irccd;
73 ElapsedTimer timer;
74
75 auto plugin = std::make_shared<Plugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-pending.js");
76
77 irccd.addPlugin(plugin);
78 irccd.poll();
79 irccd.dispatch();
80
81 ASSERT_EQ(0, plugin->context().getGlobal<int>("count"));
82 }
83
84 #endif
85
86 int main(int argc, char **argv)
87 {
88 /* Needed for some components */
89 sys::setProgramName("irccd");
90 path::setApplicationPath(argv[0]);
91 log::setInterface(std::make_unique<log::Console>());
92 log::setVerbose(true);
93 testing::InitGoogleTest(&argc, argv);
94
95 return RUN_ALL_TESTS();
96 }