Mercurial > malikania
comparison tests/libclient/js-window/main.cpp @ 36:9af360f34c7d
Misc: use raw duktape API
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 10 Aug 2016 14:30:51 +0200 |
parents | d4f5f7231b84 |
children | a47a4477f347 |
comparison
equal
deleted
inserted
replaced
35:8e1241156034 | 36:9af360f34c7d |
---|---|
27 | 27 |
28 using namespace std::chrono_literals; | 28 using namespace std::chrono_literals; |
29 | 29 |
30 class TestWindow : public testing::Test { | 30 class TestWindow : public testing::Test { |
31 protected: | 31 protected: |
32 duk::Context m_ctx; | 32 UniqueContext m_ctx; |
33 | 33 |
34 public: | 34 public: |
35 TestWindow() | 35 TestWindow() |
36 { | 36 { |
37 duk::putGlobal(m_ctx, "Malikania", duk::Object()); | 37 duk_push_object(m_ctx); |
38 | 38 duk_put_global_string(m_ctx, "Malikania"); |
39 loadMalikaniaWindow(m_ctx); | 39 dukx_load_window(m_ctx); |
40 } | 40 } |
41 }; | 41 }; |
42 | 42 |
43 TEST_F(TestWindow, basic) | 43 TEST_F(TestWindow, basic) |
44 { | 44 { |
45 try { | 45 try { |
46 auto ret = duk::pevalString(m_ctx, | 46 auto ret = duk_peval_string(m_ctx, |
47 "w = new Malikania.Window();" | 47 "w = new Malikania.Window();" |
48 "w.setDrawingColor('lightskyblue');" | 48 "w.setDrawingColor('lightskyblue');" |
49 "w.clear();" | 49 "w.clear();" |
50 "w.present();" | 50 "w.present();" |
51 ); | 51 ); |
52 | 52 |
53 if (ret != 0) { | 53 if (ret != 0) |
54 throw duk::exception(m_ctx, -1); | 54 throw dukx_exception(m_ctx, -1); |
55 } | |
56 | 55 |
57 std::this_thread::sleep_for(3s); | 56 std::this_thread::sleep_for(3s); |
58 } catch (const std::exception &ex) { | 57 } catch (const std::exception &ex) { |
59 FAIL() << ex.what(); | 58 FAIL() << ex.what(); |
60 } | 59 } |
61 } | 60 } |
62 | 61 |
63 TEST_F(TestWindow, rect) | 62 TEST_F(TestWindow, rect) |
64 { | 63 { |
65 try { | 64 try { |
66 auto ret = duk::pevalString(m_ctx, | 65 auto ret = duk_peval_string(m_ctx, |
67 "w = new Malikania.Window();" | 66 "w = new Malikania.Window();" |
68 "w.setDrawingColor('lightskyblue');" | 67 "w.setDrawingColor('lightskyblue');" |
69 "w.clear();" | 68 "w.clear();" |
70 "w.setDrawingColor('white');" | 69 "w.setDrawingColor('white');" |
71 "w.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" | 70 "w.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" |
72 "w.present();" | 71 "w.present();" |
73 ); | 72 ); |
74 | 73 |
75 if (ret != 0) { | 74 if (ret != 0) |
76 throw duk::exception(m_ctx, -1); | 75 throw dukx_exception(m_ctx, -1); |
77 } | |
78 | 76 |
79 std::this_thread::sleep_for(3s); | 77 std::this_thread::sleep_for(3s); |
80 } catch (const std::exception &ex) { | 78 } catch (const std::exception &ex) { |
81 FAIL() << ex.what(); | 79 FAIL() << ex.what(); |
82 } | 80 } |
83 } | 81 } |
84 | 82 |
85 int main(int argc, char **argv) | 83 int main(int argc, char **argv) |
86 { | 84 { |
87 testing::InitGoogleTest(&argc, argv); | 85 testing::InitGoogleTest(&argc, argv); |