Mercurial > malikania
comparison tests/libclient/js-image/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 |
---|---|
19 #include <chrono> | 19 #include <chrono> |
20 #include <thread> | 20 #include <thread> |
21 | 21 |
22 #include <gtest/gtest.h> | 22 #include <gtest/gtest.h> |
23 | 23 |
24 #include <malikania/client-resources-loader.hpp> | 24 #include <malikania/js-client-resources-loader.hpp> |
25 #include <malikania/js-image.hpp> | 25 #include <malikania/js-image.hpp> |
26 #include <malikania/js-window.hpp> | 26 #include <malikania/js-window.hpp> |
27 #include <malikania/resources-locator.hpp> | 27 #include <malikania/resources-locator.hpp> |
28 | 28 |
29 using namespace malikania; | 29 using namespace malikania; |
32 | 32 |
33 class TestImage : public testing::Test { | 33 class TestImage : public testing::Test { |
34 protected: | 34 protected: |
35 ResourcesLocatorDirectory m_locator; | 35 ResourcesLocatorDirectory m_locator; |
36 ClientResourcesLoader m_loader; | 36 ClientResourcesLoader m_loader; |
37 | 37 UniqueContext m_ctx; |
38 duk::Context m_ctx; | |
39 | 38 |
40 public: | 39 public: |
41 TestImage() | 40 TestImage() |
42 : m_locator(SOURCE_DIRECTORY "/resources") | 41 : m_locator(SOURCE_DIRECTORY "/resources") |
43 , m_loader(m_locator) | 42 , m_loader(m_locator) |
44 { | 43 { |
45 duk::putGlobal(m_ctx, "Malikania", duk::Object()); | 44 duk_push_object(m_ctx); |
46 | 45 duk_put_global_string(m_ctx, "Malikania"); |
47 loadMalikaniaImage(m_ctx); | 46 dukx_load_image(m_ctx); |
48 loadMalikaniaWindow(m_ctx); | 47 dukx_load_window(m_ctx); |
49 | 48 dukx_put_client_loader(m_ctx, &m_loader); |
50 /* Store the loader */ | |
51 duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); | |
52 } | 49 } |
53 }; | 50 }; |
54 | 51 |
55 TEST_F(TestImage, size) | 52 TEST_F(TestImage, size) |
56 { | 53 { |
57 try { | 54 try { |
58 auto ret = duk::pevalString(m_ctx, | 55 auto ret = duk_peval_string(m_ctx, |
59 "i = new Malikania.Image('images/smiley.png');" | 56 "i = new Malikania.Image('images/smiley.png');" |
60 "w = i.size.width;" | 57 "w = i.size.width;" |
61 "h = i.size.height;" | 58 "h = i.size.height;" |
62 ); | 59 ); |
63 | 60 |
64 if (ret != 0) { | 61 if (ret != 0) |
65 throw duk::exception(m_ctx, -1); | 62 throw dukx_exception(m_ctx, -1); |
66 } | |
67 | 63 |
68 ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w")); | 64 duk_get_global_string(m_ctx, "w"); |
69 ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h")); | 65 ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); |
66 duk_pop(m_ctx); | |
67 duk_get_global_string(m_ctx, "h"); | |
68 ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); | |
69 duk_pop(m_ctx); | |
70 } catch (const std::exception &ex) { | 70 } catch (const std::exception &ex) { |
71 FAIL() << ex.what(); | 71 FAIL() << ex.what(); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 TEST_F(TestImage, basic) | 75 TEST_F(TestImage, basic) |
76 { | 76 { |
77 try { | 77 try { |
78 auto ret = duk::pevalString(m_ctx, | 78 auto ret = duk_peval_string(m_ctx, |
79 "w = new Malikania.Window();" | 79 "w = new Malikania.Window();" |
80 "i = new Malikania.Image('images/smiley.png');" | 80 "i = new Malikania.Image('images/smiley.png');" |
81 "w.setDrawingColor('lightskyblue');" | 81 "w.setDrawingColor('lightskyblue');" |
82 "w.clear();" | 82 "w.clear();" |
83 "i.draw(w, { x: 320 - 16, y: 240 - 16 });" | 83 "i.draw(w, { x: 320 - 16, y: 240 - 16 });" |
84 "w.present();" | 84 "w.present();" |
85 ); | 85 ); |
86 | 86 |
87 if (ret != 0) { | 87 if (ret != 0) |
88 throw duk::exception(m_ctx, -1); | 88 throw dukx_exception(m_ctx, -1); |
89 } | |
90 | 89 |
91 std::this_thread::sleep_for(3s); | 90 std::this_thread::sleep_for(3s); |
92 } catch (const std::exception &ex) { | 91 } catch (const std::exception &ex) { |
93 FAIL() << ex.what(); | 92 FAIL() << ex.what(); |
94 } | 93 } |
95 } | 94 } |
96 | 95 |
97 TEST_F(TestImage, stretch) | 96 TEST_F(TestImage, stretch) |
98 { | 97 { |
99 try { | 98 try { |
100 auto ret = duk::pevalString(m_ctx, | 99 auto ret = duk_peval_string(m_ctx, |
101 "w = new Malikania.Window();" | 100 "w = new Malikania.Window();" |
102 "i = new Malikania.Image('images/smiley.png');" | 101 "i = new Malikania.Image('images/smiley.png');" |
103 "w.setDrawingColor('lightskyblue');" | 102 "w.setDrawingColor('lightskyblue');" |
104 "w.clear();" | 103 "w.clear();" |
105 "i.draw(w, null, { x: 10, y: 10, width: 620, height: 460 });" | 104 "i.draw(w, null, { x: 10, y: 10, width: 620, height: 460 });" |
106 "w.present();" | 105 "w.present();" |
107 ); | 106 ); |
108 | 107 |
109 if (ret != 0) { | 108 if (ret != 0) |
110 throw duk::exception(m_ctx, -1); | 109 throw dukx_exception(m_ctx, -1); |
111 } | |
112 | 110 |
113 std::this_thread::sleep_for(3s); | 111 std::this_thread::sleep_for(3s); |
114 } catch (const std::exception &ex) { | 112 } catch (const std::exception &ex) { |
115 FAIL() << ex.what(); | 113 FAIL() << ex.what(); |
116 } | 114 } |