comparison tests/libclient/js-image/main.cpp @ 30:a1e80d991968

Misc: convert to spaces, #519
author David Demelier <markand@malikania.fr>
date Thu, 16 Jun 2016 13:35:31 +0200
parents 0a1adf7dcca0
children d4f5f7231b84
comparison
equal deleted inserted replaced
29:99792c6c8b06 30:a1e80d991968
30 30
31 using namespace std::chrono_literals; 31 using namespace std::chrono_literals;
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
38 duk::Context m_ctx; 38 duk::Context m_ctx;
39 39
40 public: 40 public:
41 TestImage() 41 TestImage()
42 : m_locator(SOURCE_DIRECTORY "/resources") 42 : m_locator(SOURCE_DIRECTORY "/resources")
43 , m_loader(m_locator) 43 , m_loader(m_locator)
44 { 44 {
45 duk::putGlobal(m_ctx, "Malikania", duk::Object()); 45 duk::putGlobal(m_ctx, "Malikania", duk::Object());
46 46
47 loadMalikaniaImage(m_ctx); 47 loadMalikaniaImage(m_ctx);
48 loadMalikaniaWindow(m_ctx); 48 loadMalikaniaWindow(m_ctx);
49 49
50 /* Store the loader */ 50 /* Store the loader */
51 duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader); 51 duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader);
52 } 52 }
53 }; 53 };
54 54
55 TEST_F(TestImage, size) 55 TEST_F(TestImage, size)
56 { 56 {
57 try { 57 try {
58 auto ret = duk::pevalString(m_ctx, 58 auto ret = duk::pevalString(m_ctx,
59 "i = new Malikania.Image('images/smiley.png');" 59 "i = new Malikania.Image('images/smiley.png');"
60 "w = i.size.width;" 60 "w = i.size.width;"
61 "h = i.size.height;" 61 "h = i.size.height;"
62 ); 62 );
63 63
64 if (ret != 0) { 64 if (ret != 0) {
65 throw duk::exception(m_ctx, -1); 65 throw duk::exception(m_ctx, -1);
66 } 66 }
67 67
68 ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w")); 68 ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "w"));
69 ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h")); 69 ASSERT_EQ(32, duk::getGlobal<int>(m_ctx, "h"));
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::pevalString(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 duk::exception(m_ctx, -1);
89 } 89 }
90 90
91 std::this_thread::sleep_for(3s); 91 std::this_thread::sleep_for(3s);
92 } catch (const std::exception &ex) { 92 } catch (const std::exception &ex) {
93 FAIL() << ex.what(); 93 FAIL() << ex.what();
94 } 94 }
95 } 95 }
96 96
97 TEST_F(TestImage, stretch) 97 TEST_F(TestImage, stretch)
98 { 98 {
99 try { 99 try {
100 auto ret = duk::pevalString(m_ctx, 100 auto ret = duk::pevalString(m_ctx,
101 "w = new Malikania.Window();" 101 "w = new Malikania.Window();"
102 "i = new Malikania.Image('images/smiley.png');" 102 "i = new Malikania.Image('images/smiley.png');"
103 "w.setDrawingColor('lightskyblue');" 103 "w.setDrawingColor('lightskyblue');"
104 "w.clear();" 104 "w.clear();"
105 "i.draw(w, null, { x: 10, y: 10, width: 620, height: 460 });" 105 "i.draw(w, null, { x: 10, y: 10, width: 620, height: 460 });"
106 "w.present();" 106 "w.present();"
107 ); 107 );
108 108
109 if (ret != 0) { 109 if (ret != 0) {
110 throw duk::exception(m_ctx, -1); 110 throw duk::exception(m_ctx, -1);
111 } 111 }
112 112
113 std::this_thread::sleep_for(3s); 113 std::this_thread::sleep_for(3s);
114 } catch (const std::exception &ex) { 114 } catch (const std::exception &ex) {
115 FAIL() << ex.what(); 115 FAIL() << ex.what();
116 } 116 }
117 } 117 }
118 118
119 int main(int argc, char **argv) 119 int main(int argc, char **argv)
120 { 120 {
121 testing::InitGoogleTest(&argc, argv); 121 testing::InitGoogleTest(&argc, argv);
122 122
123 return RUN_ALL_TESTS(); 123 return RUN_ALL_TESTS();
124 } 124 }