comparison tests/js-elapsedtimer/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 bdeda4baf684
children 79d9840811a1
comparison
equal deleted inserted replaced
206:11808e98218f 207:6635b9187d71
29 using namespace irccd; 29 using namespace irccd;
30 using namespace std::chrono_literals; 30 using namespace std::chrono_literals;
31 31
32 class TestElapsedTimer : public testing::Test { 32 class TestElapsedTimer : public testing::Test {
33 protected: 33 protected:
34 Irccd m_irccd; 34 Irccd m_irccd;
35 std::shared_ptr<JsPlugin> m_plugin; 35 std::shared_ptr<JsPlugin> m_plugin;
36 36
37 TestElapsedTimer() 37 TestElapsedTimer()
38 : m_plugin(std::make_shared<JsPlugin>("empty", SOURCEDIR "/empty.js")) 38 : m_plugin(std::make_shared<JsPlugin>("empty", SOURCEDIR "/empty.js"))
39 { 39 {
40 m_irccd.moduleService().get("Irccd")->load(m_irccd, m_plugin); 40 m_irccd.moduleService().get("Irccd")->load(m_irccd, m_plugin);
41 m_irccd.moduleService().get("Irccd.ElapsedTimer")->load(m_irccd, m_plugin); 41 m_irccd.moduleService().get("Irccd.ElapsedTimer")->load(m_irccd, m_plugin);
42 } 42 }
43 }; 43 };
44 44
45 TEST_F(TestElapsedTimer, standard) 45 TEST_F(TestElapsedTimer, standard)
46 { 46 {
47 try { 47 try {
48 if (duk_peval_string(m_plugin->context(), "timer = new Irccd.ElapsedTimer();") != 0) 48 if (duk_peval_string(m_plugin->context(), "timer = new Irccd.ElapsedTimer();") != 0)
49 throw dukx_exception(m_plugin->context(), -1); 49 throw dukx_exception(m_plugin->context(), -1);
50 50
51 std::this_thread::sleep_for(300ms); 51 std::this_thread::sleep_for(300ms);
52 52
53 if (duk_peval_string(m_plugin->context(), "result = timer.elapsed();") != 0) 53 if (duk_peval_string(m_plugin->context(), "result = timer.elapsed();") != 0)
54 throw dukx_exception(m_plugin->context(), -1); 54 throw dukx_exception(m_plugin->context(), -1);
55 55
56 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "result")); 56 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "result"));
57 ASSERT_GE(duk_get_int(m_plugin->context(), -1), 250); 57 ASSERT_GE(duk_get_int(m_plugin->context(), -1), 250);
58 ASSERT_LE(duk_get_int(m_plugin->context(), -1), 350); 58 ASSERT_LE(duk_get_int(m_plugin->context(), -1), 350);
59 } catch (const std::exception &ex) { 59 } catch (const std::exception &ex) {
60 FAIL() << ex.what(); 60 FAIL() << ex.what();
61 } 61 }
62 } 62 }
63 63
64 TEST_F(TestElapsedTimer, reset) 64 TEST_F(TestElapsedTimer, reset)
65 { 65 {
66 try { 66 try {
67 if (duk_peval_string(m_plugin->context(), "timer = new Irccd.ElapsedTimer();") != 0) 67 if (duk_peval_string(m_plugin->context(), "timer = new Irccd.ElapsedTimer();") != 0)
68 throw dukx_exception(m_plugin->context(), -1); 68 throw dukx_exception(m_plugin->context(), -1);
69 69
70 std::this_thread::sleep_for(300ms); 70 std::this_thread::sleep_for(300ms);
71 71
72 if (duk_peval_string(m_plugin->context(), "timer.reset(); result = timer.elapsed();") != 0) 72 if (duk_peval_string(m_plugin->context(), "timer.reset(); result = timer.elapsed();") != 0)
73 throw dukx_exception(m_plugin->context(), -1); 73 throw dukx_exception(m_plugin->context(), -1);
74 74
75 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "result")); 75 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "result"));
76 ASSERT_LE(duk_get_int(m_plugin->context(), -1), 100); 76 ASSERT_LE(duk_get_int(m_plugin->context(), -1), 100);
77 } catch (const std::exception &ex) { 77 } catch (const std::exception &ex) {
78 FAIL() << ex.what(); 78 FAIL() << ex.what();
79 } 79 }
80 } 80 }
81 81
82 int main(int argc, char **argv) 82 int main(int argc, char **argv)
83 { 83 {
84 testing::InitGoogleTest(&argc, argv); 84 testing::InitGoogleTest(&argc, argv);
85 85
86 return RUN_ALL_TESTS(); 86 return RUN_ALL_TESTS();
87 } 87 }