comparison tests/libclient/js-sprite/main.cpp @ 44:f30c84b4b9ed

Tests: switch from GoogleTest to Boost.Unit, closes #588
author David Demelier <markand@malikania.fr>
date Wed, 30 Nov 2016 21:15:53 +0100
parents fabbe1759cec
children 96ba0c5cf893
comparison
equal deleted inserted replaced
43:fabbe1759cec 44:f30c84b4b9ed
17 */ 17 */
18 18
19 #include <chrono> 19 #include <chrono>
20 #include <thread> 20 #include <thread>
21 21
22 #include <gtest/gtest.h> 22 #define BOOST_TEST_MODULE "Javascript Sprite"
23 #include <boost/test/unit_test.hpp>
23 24
24 #include <malikania/js_client_resources_loader.hpp> 25 #include <malikania/js_client_resources_loader.hpp>
25 #include <malikania/js_image.hpp> 26 #include <malikania/js_image.hpp>
26 #include <malikania/js_sprite.hpp> 27 #include <malikania/js_sprite.hpp>
27 #include <malikania/js_window.hpp> 28 #include <malikania/js_window.hpp>
29 30
30 using namespace mlk; 31 using namespace mlk;
31 32
32 using namespace std::chrono_literals; 33 using namespace std::chrono_literals;
33 34
34 class TestSprite : public testing::Test { 35 class test_sprite {
35 protected: 36 protected:
36 directory_resources_locator m_locator; 37 directory_resources_locator m_locator;
37 client_resources_loader m_loader; 38 client_resources_loader m_loader;
38 UniqueContext m_ctx; 39 UniqueContext m_ctx;
39 40
40 public: 41 public:
41 TestSprite() 42 test_sprite()
42 : m_locator(SOURCE_DIRECTORY "/resources") 43 : m_locator(SOURCE_DIRECTORY "/resources")
43 , m_loader(m_locator) 44 , m_loader(m_locator)
44 { 45 {
45 duk_push_object(m_ctx); 46 duk_push_object(m_ctx);
46 duk_put_global_string(m_ctx, "Malikania"); 47 duk_put_global_string(m_ctx, "Malikania");
49 mlk::dukx_load_window(m_ctx); 50 mlk::dukx_load_window(m_ctx);
50 dukx_put_client_loader(m_ctx, m_loader); 51 dukx_put_client_loader(m_ctx, m_loader);
51 } 52 }
52 }; 53 };
53 54
54 TEST_F(TestSprite, cell) 55 BOOST_FIXTURE_TEST_SUITE(test_sprite_suite, test_sprite)
56
57 BOOST_AUTO_TEST_CASE(cell)
55 { 58 {
56 try { 59 try {
57 auto ret = duk_peval_string(m_ctx, 60 auto ret = duk_peval_string(m_ctx,
58 "s = new Malikania.Sprite('sprites/margins.json');" 61 "s = new Malikania.Sprite('sprites/margins.json');"
59 "w = s.cell.width;" 62 "w = s.cell.width;"
63 if (ret != 0) { 66 if (ret != 0) {
64 throw dukx_exception(m_ctx, -1); 67 throw dukx_exception(m_ctx, -1);
65 } 68 }
66 69
67 duk_get_global_string(m_ctx, "w"); 70 duk_get_global_string(m_ctx, "w");
68 ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); 71 BOOST_REQUIRE_EQUAL(32U, duk_to_uint(m_ctx, -1));
69 duk_pop(m_ctx); 72 duk_pop(m_ctx);
70 duk_get_global_string(m_ctx, "h"); 73 duk_get_global_string(m_ctx, "h");
71 ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); 74 BOOST_REQUIRE_EQUAL(32U, duk_to_uint(m_ctx, -1));
72 duk_pop(m_ctx); 75 duk_pop(m_ctx);
73 } catch (const std::exception &ex) { 76 } catch (const std::exception &ex) {
74 FAIL() << ex.what(); 77 BOOST_FAIL(ex.what());
75 } 78 }
76 } 79 }
77 80
78 TEST_F(TestSprite, columns) 81 BOOST_AUTO_TEST_CASE(columns)
79 { 82 {
80 try { 83 try {
81 auto ret = duk_peval_string(m_ctx, 84 auto ret = duk_peval_string(m_ctx,
82 "s = new Malikania.Sprite('sprites/margins.json');" 85 "s = new Malikania.Sprite('sprites/margins.json');"
83 "n = s.columns;" 86 "n = s.columns;"
86 if (ret != 0) { 89 if (ret != 0) {
87 throw dukx_exception(m_ctx, -1); 90 throw dukx_exception(m_ctx, -1);
88 } 91 }
89 92
90 duk_get_global_string(m_ctx, "n"); 93 duk_get_global_string(m_ctx, "n");
91 ASSERT_EQ(4U, duk_to_uint(m_ctx, -1)); 94 BOOST_REQUIRE_EQUAL(4U, duk_to_uint(m_ctx, -1));
92 duk_pop(m_ctx); 95 duk_pop(m_ctx);
93 } catch (const std::exception &ex) { 96 } catch (const std::exception &ex) {
94 FAIL() << ex.what(); 97 BOOST_FAIL(ex.what());
95 } 98 }
96 } 99 }
97 100
98 TEST_F(TestSprite, margins) 101 BOOST_AUTO_TEST_CASE(margins)
99 { 102 {
100 try { 103 try {
101 auto ret = duk_peval_string(m_ctx, 104 auto ret = duk_peval_string(m_ctx,
102 "s = new Malikania.Sprite('sprites/margins.json');" 105 "s = new Malikania.Sprite('sprites/margins.json');"
103 "w = s.margins.width;" 106 "w = s.margins.width;"
107 if (ret != 0) { 110 if (ret != 0) {
108 throw dukx_exception(m_ctx, -1); 111 throw dukx_exception(m_ctx, -1);
109 } 112 }
110 113
111 duk_get_global_string(m_ctx, "w"); 114 duk_get_global_string(m_ctx, "w");
112 ASSERT_EQ(4U, duk_to_uint(m_ctx, -1)); 115 BOOST_REQUIRE_EQUAL(4U, duk_to_uint(m_ctx, -1));
113 duk_pop(m_ctx); 116 duk_pop(m_ctx);
114 duk_get_global_string(m_ctx, "h"); 117 duk_get_global_string(m_ctx, "h");
115 ASSERT_EQ(6U, duk_to_uint(m_ctx, -1)); 118 BOOST_REQUIRE_EQUAL(6U, duk_to_uint(m_ctx, -1));
116 duk_pop(m_ctx); 119 duk_pop(m_ctx);
117 } catch (const std::exception &ex) { 120 } catch (const std::exception &ex) {
118 FAIL() << ex.what(); 121 BOOST_FAIL(ex.what());
119 } 122 }
120 } 123 }
121 124
122 TEST_F(TestSprite, rows) 125 BOOST_AUTO_TEST_CASE(rows)
123 { 126 {
124 try { 127 try {
125 auto ret = duk_peval_string(m_ctx, 128 auto ret = duk_peval_string(m_ctx,
126 "s = new Malikania.Sprite('sprites/margins.json');" 129 "s = new Malikania.Sprite('sprites/margins.json');"
127 "n = s.rows;" 130 "n = s.rows;"
130 if (ret != 0) { 133 if (ret != 0) {
131 throw dukx_exception(m_ctx, -1); 134 throw dukx_exception(m_ctx, -1);
132 } 135 }
133 136
134 duk_get_global_string(m_ctx, "n"); 137 duk_get_global_string(m_ctx, "n");
135 ASSERT_EQ(3U, duk_to_uint(m_ctx, -1)); 138 BOOST_REQUIRE_EQUAL(3U, duk_to_uint(m_ctx, -1));
136 duk_pop(m_ctx); 139 duk_pop(m_ctx);
137 } catch (const std::exception &ex) { 140 } catch (const std::exception &ex) {
138 FAIL() << ex.what(); 141 BOOST_FAIL(ex.what());
139 } 142 }
140 } 143 }
141 144
142 TEST_F(TestSprite, space) 145 BOOST_AUTO_TEST_CASE(space)
143 { 146 {
144 try { 147 try {
145 auto ret = duk_peval_string(m_ctx, 148 auto ret = duk_peval_string(m_ctx,
146 "s = new Malikania.Sprite('sprites/margins.json');" 149 "s = new Malikania.Sprite('sprites/margins.json');"
147 "w = s.space.width;" 150 "w = s.space.width;"
151 if (ret != 0) { 154 if (ret != 0) {
152 throw dukx_exception(m_ctx, -1); 155 throw dukx_exception(m_ctx, -1);
153 } 156 }
154 157
155 duk_get_global_string(m_ctx, "w"); 158 duk_get_global_string(m_ctx, "w");
156 ASSERT_EQ(2U, duk_to_uint(m_ctx, -1)); 159 BOOST_REQUIRE_EQUAL(2U, duk_to_uint(m_ctx, -1));
157 duk_pop(m_ctx); 160 duk_pop(m_ctx);
158 duk_get_global_string(m_ctx, "h"); 161 duk_get_global_string(m_ctx, "h");
159 ASSERT_EQ(3U, duk_to_uint(m_ctx, -1)); 162 BOOST_REQUIRE_EQUAL(3U, duk_to_uint(m_ctx, -1));
160 duk_pop(m_ctx); 163 duk_pop(m_ctx);
161 } catch (const std::exception &ex) { 164 } catch (const std::exception &ex) {
162 FAIL() << ex.what(); 165 BOOST_FAIL(ex.what());
163 } 166 }
164 } 167 }
165 168
166 TEST_F(TestSprite, basic) 169 BOOST_AUTO_TEST_CASE(basic)
167 { 170 {
168 try { 171 try {
169 auto ret = duk_peval_string(m_ctx, 172 auto ret = duk_peval_string(m_ctx,
170 "w = new Malikania.Window();" 173 "w = new Malikania.Window();"
171 "s = new Malikania.Sprite('sprites/margins.json');" 174 "s = new Malikania.Sprite('sprites/margins.json');"
189 } 192 }
190 193
191 std::this_thread::sleep_for(1s); 194 std::this_thread::sleep_for(1s);
192 } 195 }
193 } catch (const std::exception &ex) { 196 } catch (const std::exception &ex) {
194 FAIL() << ex.what(); 197 BOOST_FAIL(ex.what());
195 } 198 }
196 } 199 }
197 200
198 int main(int argc, char **argv) 201 BOOST_AUTO_TEST_SUITE_END()
199 {
200 testing::InitGoogleTest(&argc, argv);
201
202 return RUN_ALL_TESTS();
203 }