comparison tests/js-timer/main.cpp @ 207:6635b9187d71

Irccd: switch to 4 spaces indent, #518
author David Demelier <markand@malikania.fr>
date Tue, 21 Jun 2016 20:52:17 +0200
parents cb61cc16e2b6
children 79d9840811a1
comparison
equal deleted inserted replaced
206:11808e98218f 207:6635b9187d71
27 27
28 using namespace irccd; 28 using namespace irccd;
29 29
30 TEST(Basic, single) 30 TEST(Basic, single)
31 { 31 {
32 Irccd irccd; 32 Irccd irccd;
33 ElapsedTimer timer; 33 ElapsedTimer timer;
34 34
35 auto plugin = std::make_shared<JsPlugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-single.js"); 35 auto plugin = std::make_shared<JsPlugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-single.js");
36 36
37 plugin->onLoad(irccd); 37 plugin->onLoad(irccd);
38 irccd.pluginService().add(plugin); 38 irccd.pluginService().add(plugin);
39 39
40 while (timer.elapsed() < 3000) { 40 while (timer.elapsed() < 3000) {
41 irccd.poll(); 41 irccd.poll();
42 irccd.dispatch(); 42 irccd.dispatch();
43 } 43 }
44 44
45 ASSERT_TRUE(duk_get_global_string(plugin->context(), "count")); 45 ASSERT_TRUE(duk_get_global_string(plugin->context(), "count"));
46 ASSERT_EQ(1, duk_get_int(plugin->context(), -1)); 46 ASSERT_EQ(1, duk_get_int(plugin->context(), -1));
47 } 47 }
48 48
49 TEST(Basic, repeat) 49 TEST(Basic, repeat)
50 { 50 {
51 Irccd irccd; 51 Irccd irccd;
52 ElapsedTimer timer; 52 ElapsedTimer timer;
53 53
54 auto plugin = std::make_shared<JsPlugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-repeat.js"); 54 auto plugin = std::make_shared<JsPlugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-repeat.js");
55 55
56 plugin->onLoad(irccd); 56 plugin->onLoad(irccd);
57 irccd.pluginService().add(plugin); 57 irccd.pluginService().add(plugin);
58 58
59 while (timer.elapsed() < 3000) { 59 while (timer.elapsed() < 3000) {
60 irccd.poll(); 60 irccd.poll();
61 irccd.dispatch(); 61 irccd.dispatch();
62 } 62 }
63 63
64 ASSERT_TRUE(duk_get_global_string(plugin->context(), "count")); 64 ASSERT_TRUE(duk_get_global_string(plugin->context(), "count"));
65 ASSERT_GE(duk_get_int(plugin->context(), -1), 5); 65 ASSERT_GE(duk_get_int(plugin->context(), -1), 5);
66 } 66 }
67 67
68 #if 0 68 #if 0
69 69
70 /* 70 /*
71 * XXX: currently disabled because it will break single-shot timers. 71 * XXX: currently disabled because it will break single-shot timers.
72 */ 72 */
73 73
74 TEST(Basic, pending) 74 TEST(Basic, pending)
75 { 75 {
76 /* 76 /*
77 * This test ensure that if pending actions on a stopped timer are never executed. 77 * This test ensure that if pending actions on a stopped timer are never executed.
78 */ 78 */
79 Irccd irccd; 79 Irccd irccd;
80 ElapsedTimer timer; 80 ElapsedTimer timer;
81 81
82 auto plugin = std::make_shared<Plugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-pending.js"); 82 auto plugin = std::make_shared<Plugin>("timer", IRCCD_TESTS_DIRECTORY "/timer-pending.js");
83 83
84 irccd.addPlugin(plugin); 84 irccd.addPlugin(plugin);
85 irccd.poll(); 85 irccd.poll();
86 irccd.dispatch(); 86 irccd.dispatch();
87 87
88 ASSERT_EQ(0, plugin->context().getGlobal<int>("count")); 88 ASSERT_EQ(0, plugin->context().getGlobal<int>("count"));
89 } 89 }
90 90
91 #endif 91 #endif
92 92
93 int main(int argc, char **argv) 93 int main(int argc, char **argv)
94 { 94 {
95 // Needed for some components. 95 // Needed for some components.
96 sys::setProgramName("irccd"); 96 sys::setProgramName("irccd");
97 path::setApplicationPath(argv[0]); 97 path::setApplicationPath(argv[0]);
98 log::setInterface(std::make_unique<log::Silent>()); 98 log::setInterface(std::make_unique<log::Silent>());
99 log::setVerbose(true); 99 log::setVerbose(true);
100 testing::InitGoogleTest(&argc, argv); 100 testing::InitGoogleTest(&argc, argv);
101 101
102 return RUN_ALL_TESTS(); 102 return RUN_ALL_TESTS();
103 } 103 }