Mercurial > malikania
comparison tests/libclient/js-color/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 |
---|---|
22 | 22 |
23 using namespace malikania; | 23 using namespace malikania; |
24 | 24 |
25 class TestColor : public testing::Test { | 25 class TestColor : public testing::Test { |
26 protected: | 26 protected: |
27 duk::Context m_ctx; | 27 UniqueContext m_ctx; |
28 | 28 |
29 public: | 29 public: |
30 TestColor() | 30 TestColor() |
31 { | 31 { |
32 duk::putGlobal(m_ctx, "Malikania", duk::Object()); | 32 duk_push_object(m_ctx); |
33 | 33 duk_put_global_string(m_ctx, "Malikania"); |
34 loadMalikaniaColor(m_ctx); | 34 dukx_load_color(m_ctx); |
35 } | |
36 | |
37 int component(const char *name) | |
38 { | |
39 duk_get_global_string(m_ctx, name); | |
40 auto value = duk_require_int(m_ctx, -1); | |
41 duk_pop(m_ctx); | |
42 | |
43 return value; | |
35 } | 44 } |
36 }; | 45 }; |
37 | 46 |
38 /* | 47 /* |
39 * Valid constructors | 48 * Valid constructors |
41 */ | 50 */ |
42 | 51 |
43 TEST_F(TestColor, ConstructorNoArgs) | 52 TEST_F(TestColor, ConstructorNoArgs) |
44 { | 53 { |
45 try { | 54 try { |
46 auto ret = duk::pevalString(m_ctx, | 55 auto ret = duk_peval_string(m_ctx, |
47 "c = Malikania.Color();" | 56 "c = Malikania.Color();" |
48 "r = c.red;" | 57 "r = c.red;" |
49 "g = c.green;" | 58 "g = c.green;" |
50 "b = c.blue;" | 59 "b = c.blue;" |
51 "a = c.alpha;" | 60 "a = c.alpha;" |
52 ); | 61 ); |
53 | 62 |
54 if (ret != 0) { | 63 if (ret != 0) |
55 throw duk::exception(m_ctx, -1); | 64 throw dukx_exception(m_ctx, -1); |
56 } | 65 |
57 | 66 ASSERT_EQ(0, component("r")); |
58 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); | 67 ASSERT_EQ(0, component("g")); |
59 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); | 68 ASSERT_EQ(0, component("b")); |
60 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); | 69 ASSERT_EQ(255, component("a")); |
61 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | |
62 } catch (const std::exception &ex) { | 70 } catch (const std::exception &ex) { |
63 FAIL() << ex.what(); | 71 FAIL() << ex.what(); |
64 } | 72 } |
65 } | 73 } |
66 | 74 |
67 TEST_F(TestColor, ConstructorString) | 75 TEST_F(TestColor, ConstructorString) |
68 { | 76 { |
69 try { | 77 try { |
70 auto ret = duk::pevalString(m_ctx, | 78 auto ret = duk_peval_string(m_ctx, |
71 "c = Malikania.Color('white');" | 79 "c = Malikania.Color('white');" |
72 "r = c.red;" | 80 "r = c.red;" |
73 "g = c.green;" | 81 "g = c.green;" |
74 "b = c.blue;" | 82 "b = c.blue;" |
75 "a = c.alpha;" | 83 "a = c.alpha;" |
76 ); | 84 ); |
77 | 85 |
78 if (ret != 0) { | 86 if (ret != 0) |
79 throw duk::exception(m_ctx, -1); | 87 throw dukx_exception(m_ctx, -1); |
80 } | 88 |
81 | 89 ASSERT_EQ(255, component("r")); |
82 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); | 90 ASSERT_EQ(255, component("g")); |
83 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g")); | 91 ASSERT_EQ(255, component("b")); |
84 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b")); | 92 ASSERT_EQ(255, component("a")); |
85 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | |
86 } catch (const std::exception &ex) { | 93 } catch (const std::exception &ex) { |
87 FAIL() << ex.what(); | 94 FAIL() << ex.what(); |
88 } | 95 } |
89 } | 96 } |
90 | 97 |
91 TEST_F(TestColor, ConstructorStringRgb) | 98 TEST_F(TestColor, ConstructorStringRgb) |
92 { | 99 { |
93 try { | 100 try { |
94 auto ret = duk::pevalString(m_ctx, | 101 auto ret = duk_peval_string(m_ctx, |
95 "c = Malikania.Color('#0000ff');" | 102 "c = Malikania.Color('#0000ff');" |
96 "r = c.red;" | 103 "r = c.red;" |
97 "g = c.green;" | 104 "g = c.green;" |
98 "b = c.blue;" | 105 "b = c.blue;" |
99 "a = c.alpha;" | 106 "a = c.alpha;" |
100 ); | 107 ); |
101 | 108 |
102 if (ret != 0) { | 109 if (ret != 0) |
103 throw duk::exception(m_ctx, -1); | 110 throw dukx_exception(m_ctx, -1); |
104 } | 111 |
105 | 112 ASSERT_EQ(0, component("r")); |
106 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); | 113 ASSERT_EQ(0, component("g")); |
107 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); | 114 ASSERT_EQ(255, component("b")); |
108 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "b")); | 115 ASSERT_EQ(255, component("a")); |
109 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | |
110 } catch (const std::exception &ex) { | 116 } catch (const std::exception &ex) { |
111 FAIL() << ex.what(); | 117 FAIL() << ex.what(); |
112 } | 118 } |
113 } | 119 } |
114 | 120 |
115 TEST_F(TestColor, Constructor3Args) | 121 TEST_F(TestColor, Constructor3Args) |
116 { | 122 { |
117 try { | 123 try { |
118 auto ret = duk::pevalString(m_ctx, | 124 auto ret = duk_peval_string(m_ctx, |
119 "c = Malikania.Color(10, 20, 30);" | 125 "c = Malikania.Color(10, 20, 30);" |
120 "r = c.red;" | 126 "r = c.red;" |
121 "g = c.green;" | 127 "g = c.green;" |
122 "b = c.blue;" | 128 "b = c.blue;" |
123 "a = c.alpha;" | 129 "a = c.alpha;" |
124 ); | 130 ); |
125 | 131 |
126 if (ret != 0) { | 132 if (ret != 0) |
127 throw duk::exception(m_ctx, -1); | 133 throw dukx_exception(m_ctx, -1); |
128 } | 134 |
129 | 135 ASSERT_EQ(10, component("r")); |
130 ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); | 136 ASSERT_EQ(20, component("g")); |
131 ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); | 137 ASSERT_EQ(30, component("b")); |
132 ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); | 138 ASSERT_EQ(255, component("a")); |
133 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | |
134 } catch (const std::exception &ex) { | 139 } catch (const std::exception &ex) { |
135 FAIL() << ex.what(); | 140 FAIL() << ex.what(); |
136 } | 141 } |
137 } | 142 } |
138 | 143 |
139 TEST_F(TestColor, Constructor4Args) | 144 TEST_F(TestColor, Constructor4Args) |
140 { | 145 { |
141 try { | 146 try { |
142 auto ret = duk::pevalString(m_ctx, | 147 auto ret = duk_peval_string(m_ctx, |
143 "c = Malikania.Color(10, 20, 30, 40);" | 148 "c = Malikania.Color(10, 20, 30, 40);" |
144 "r = c.red;" | 149 "r = c.red;" |
145 "g = c.green;" | 150 "g = c.green;" |
146 "b = c.blue;" | 151 "b = c.blue;" |
147 "a = c.alpha;" | 152 "a = c.alpha;" |
148 ); | 153 ); |
149 | 154 |
150 if (ret != 0) { | 155 if (ret != 0) |
151 throw duk::exception(m_ctx, -1); | 156 throw dukx_exception(m_ctx, -1); |
152 } | 157 |
153 | 158 ASSERT_EQ(10, component("r")); |
154 ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); | 159 ASSERT_EQ(20, component("g")); |
155 ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); | 160 ASSERT_EQ(30, component("b")); |
156 ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); | 161 ASSERT_EQ(40, component("a")); |
157 ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); | |
158 } catch (const std::exception &ex) { | 162 } catch (const std::exception &ex) { |
159 FAIL() << ex.what(); | 163 FAIL() << ex.what(); |
160 } | 164 } |
161 } | 165 } |
162 | 166 |
163 TEST_F(TestColor, ConstructorObjectNoAlpha) | 167 TEST_F(TestColor, ConstructorObjectNoAlpha) |
164 { | 168 { |
165 try { | 169 try { |
166 auto ret = duk::pevalString(m_ctx, | 170 auto ret = duk_peval_string(m_ctx, |
167 "c = Malikania.Color({ red: 10, green: 20, blue: 30 });" | 171 "c = Malikania.Color({ red: 10, green: 20, blue: 30 });" |
168 "r = c.red;" | 172 "r = c.red;" |
169 "g = c.green;" | 173 "g = c.green;" |
170 "b = c.blue;" | 174 "b = c.blue;" |
171 "a = c.alpha;" | 175 "a = c.alpha;" |
172 ); | 176 ); |
173 | 177 |
174 if (ret != 0) { | 178 if (ret != 0) |
175 throw duk::exception(m_ctx, -1); | 179 throw dukx_exception(m_ctx, -1); |
176 } | 180 |
177 | 181 ASSERT_EQ(10, component("r")); |
178 ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); | 182 ASSERT_EQ(20, component("g")); |
179 ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); | 183 ASSERT_EQ(30, component("b")); |
180 ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); | 184 ASSERT_EQ(255, component("a")); |
181 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | |
182 } catch (const std::exception &ex) { | 185 } catch (const std::exception &ex) { |
183 FAIL() << ex.what(); | 186 FAIL() << ex.what(); |
184 } | 187 } |
185 } | 188 } |
186 | 189 |
187 TEST_F(TestColor, ConstructorObjectAlpha) | 190 TEST_F(TestColor, ConstructorObjectAlpha) |
188 { | 191 { |
189 try { | 192 try { |
190 auto ret = duk::pevalString(m_ctx, | 193 auto ret = duk_peval_string(m_ctx, |
191 "c = Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" | 194 "c = Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" |
192 "r = c.red;" | 195 "r = c.red;" |
193 "g = c.green;" | 196 "g = c.green;" |
194 "b = c.blue;" | 197 "b = c.blue;" |
195 "a = c.alpha;" | 198 "a = c.alpha;" |
196 ); | 199 ); |
197 | 200 |
198 if (ret != 0) { | 201 if (ret != 0) |
199 throw duk::exception(m_ctx, -1); | 202 throw dukx_exception(m_ctx, -1); |
200 } | 203 |
201 | 204 ASSERT_EQ(10, component("r")); |
202 ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); | 205 ASSERT_EQ(20, component("g")); |
203 ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); | 206 ASSERT_EQ(30, component("b")); |
204 ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); | 207 ASSERT_EQ(40, component("a")); |
205 ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); | |
206 } catch (const std::exception &ex) { | 208 } catch (const std::exception &ex) { |
207 FAIL() << ex.what(); | 209 FAIL() << ex.what(); |
208 } | 210 } |
209 } | 211 } |
210 | 212 |
212 { | 214 { |
213 /* | 215 /* |
214 * Just one test, function parse the same way, only 'this' or a new object is returned. | 216 * Just one test, function parse the same way, only 'this' or a new object is returned. |
215 */ | 217 */ |
216 try { | 218 try { |
217 auto ret = duk::pevalString(m_ctx, | 219 auto ret = duk_peval_string(m_ctx, |
218 "c = new Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" | 220 "c = new Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });" |
219 "r = c.red;" | 221 "r = c.red;" |
220 "g = c.green;" | 222 "g = c.green;" |
221 "b = c.blue;" | 223 "b = c.blue;" |
222 "a = c.alpha;" | 224 "a = c.alpha;" |
223 ); | 225 ); |
224 | 226 |
225 if (ret != 0) { | 227 if (ret != 0) |
226 throw duk::exception(m_ctx, -1); | 228 throw dukx_exception(m_ctx, -1); |
227 } | 229 |
228 | 230 ASSERT_EQ(10, component("r")); |
229 ASSERT_EQ(10, duk::getGlobal<int>(m_ctx, "r")); | 231 ASSERT_EQ(20, component("g")); |
230 ASSERT_EQ(20, duk::getGlobal<int>(m_ctx, "g")); | 232 ASSERT_EQ(30, component("b")); |
231 ASSERT_EQ(30, duk::getGlobal<int>(m_ctx, "b")); | 233 ASSERT_EQ(40, component("a")); |
232 ASSERT_EQ(40, duk::getGlobal<int>(m_ctx, "a")); | |
233 } catch (const std::exception &ex) { | 234 } catch (const std::exception &ex) { |
234 FAIL() << ex.what(); | 235 FAIL() << ex.what(); |
235 } | 236 } |
236 } | 237 } |
237 | 238 |
241 */ | 242 */ |
242 | 243 |
243 TEST_F(TestColor, InvalidConstructorArg1) | 244 TEST_F(TestColor, InvalidConstructorArg1) |
244 { | 245 { |
245 try { | 246 try { |
246 auto ret = duk::pevalString(m_ctx, | 247 auto ret = duk_peval_string(m_ctx, |
247 "try {" | 248 "try {" |
248 " Malikania.Color(null);" | 249 " Malikania.Color(null);" |
249 "} catch (e) {" | 250 "} catch (e) {" |
250 " name = e.name;" | 251 " name = e.name;" |
251 " correct = (e instanceof TypeError);" | 252 " correct = (e instanceof TypeError);" |
252 "}" | 253 "}" |
253 ); | 254 ); |
254 | 255 |
255 if (ret != 0) { | 256 if (ret != 0) |
256 throw duk::exception(m_ctx, -1); | 257 throw dukx_exception(m_ctx, -1); |
257 } | 258 |
258 | 259 duk_get_global_string(m_ctx, "name"); |
259 ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); | 260 ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1)); |
260 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 261 duk_pop(m_ctx); |
262 duk_get_global_string(m_ctx, "correct"); | |
263 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
264 duk_pop(m_ctx); | |
261 } catch (const std::exception &ex) { | 265 } catch (const std::exception &ex) { |
262 FAIL() << ex.what(); | 266 FAIL() << ex.what(); |
263 } | 267 } |
264 } | 268 } |
265 | 269 |
266 TEST_F(TestColor, InvalidConstructorArg2) | 270 TEST_F(TestColor, InvalidConstructorArg2) |
267 { | 271 { |
268 try { | 272 try { |
269 auto ret = duk::pevalString(m_ctx, | 273 auto ret = duk_peval_string(m_ctx, |
270 "try {" | 274 "try {" |
271 " Malikania.Color(10, null, 30);" | 275 " Malikania.Color(10, null, 30);" |
272 "} catch (e) {" | 276 "} catch (e) {" |
273 " name = e.name;" | 277 " name = e.name;" |
274 " correct = (e instanceof TypeError);" | 278 " correct = (e instanceof TypeError);" |
275 "}" | 279 "}" |
276 ); | 280 ); |
277 | 281 |
278 if (ret != 0) { | 282 if (ret != 0) |
279 throw duk::exception(m_ctx, -1); | 283 throw dukx_exception(m_ctx, -1); |
280 } | 284 |
281 | 285 duk_get_global_string(m_ctx, "name"); |
282 ASSERT_EQ("TypeError", duk::getGlobal<std::string>(m_ctx, "name")); | 286 ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1)); |
283 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 287 duk_pop(m_ctx); |
288 duk_get_global_string(m_ctx, "correct"); | |
289 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
290 duk_pop(m_ctx); | |
284 } catch (const std::exception &ex) { | 291 } catch (const std::exception &ex) { |
285 FAIL() << ex.what(); | 292 FAIL() << ex.what(); |
286 } | 293 } |
287 } | 294 } |
288 | 295 |
289 TEST_F(TestColor, InvalidConstructorRange1) | 296 TEST_F(TestColor, InvalidConstructorRange1) |
290 { | 297 { |
291 try { | 298 try { |
292 auto ret = duk::pevalString(m_ctx, | 299 auto ret = duk_peval_string(m_ctx, |
293 "try {" | 300 "try {" |
294 " Malikania.Color(-1, 20, 30);" | 301 " Malikania.Color(-1, 20, 30);" |
295 "} catch (e) {" | 302 "} catch (e) {" |
296 " name = e.name;" | 303 " name = e.name;" |
297 " correct = (e instanceof RangeError);" | 304 " correct = (e instanceof RangeError);" |
298 "}" | 305 "}" |
299 ); | 306 ); |
300 | 307 |
301 if (ret != 0) { | 308 if (ret != 0) |
302 throw duk::exception(m_ctx, -1); | 309 throw dukx_exception(m_ctx, -1); |
303 } | 310 |
304 | 311 duk_get_global_string(m_ctx, "name"); |
305 ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); | 312 ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); |
306 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 313 duk_pop(m_ctx); |
314 duk_get_global_string(m_ctx, "correct"); | |
315 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
316 duk_pop(m_ctx); | |
307 } catch (const std::exception &ex) { | 317 } catch (const std::exception &ex) { |
308 FAIL() << ex.what(); | 318 FAIL() << ex.what(); |
309 } | 319 } |
310 } | 320 } |
311 | 321 |
312 TEST_F(TestColor, InvalidConstructorRange2) | 322 TEST_F(TestColor, InvalidConstructorRange2) |
313 { | 323 { |
314 try { | 324 try { |
315 auto ret = duk::pevalString(m_ctx, | 325 auto ret = duk_peval_string(m_ctx, |
316 "try {" | 326 "try {" |
317 " Malikania.Color(10, 20, 256);" | 327 " Malikania.Color(10, 20, 256);" |
318 "} catch (e) {" | 328 "} catch (e) {" |
319 " name = e.name;" | 329 " name = e.name;" |
320 " correct = (e instanceof RangeError);" | 330 " correct = (e instanceof RangeError);" |
321 "}" | 331 "}" |
322 ); | 332 ); |
323 | 333 |
324 if (ret != 0) { | 334 if (ret != 0) |
325 throw duk::exception(m_ctx, -1); | 335 throw dukx_exception(m_ctx, -1); |
326 } | 336 |
327 | 337 duk_get_global_string(m_ctx, "name"); |
328 ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); | 338 ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); |
329 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 339 duk_pop(m_ctx); |
340 duk_get_global_string(m_ctx, "correct"); | |
341 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
342 duk_pop(m_ctx); | |
330 } catch (const std::exception &ex) { | 343 } catch (const std::exception &ex) { |
331 FAIL() << ex.what(); | 344 FAIL() << ex.what(); |
332 } | 345 } |
333 } | 346 } |
334 | 347 |
335 TEST_F(TestColor, InvalidConstructorRange3) | 348 TEST_F(TestColor, InvalidConstructorRange3) |
336 { | 349 { |
337 try { | 350 try { |
338 auto ret = duk::pevalString(m_ctx, | 351 auto ret = duk_peval_string(m_ctx, |
339 "try {" | 352 "try {" |
340 " Malikania.Color(10, 20, 30, 800);" | 353 " Malikania.Color(10, 20, 30, 800);" |
341 "} catch (e) {" | 354 "} catch (e) {" |
342 " name = e.name;" | 355 " name = e.name;" |
343 " correct = (e instanceof RangeError);" | 356 " correct = (e instanceof RangeError);" |
344 "}" | 357 "}" |
345 ); | 358 ); |
346 | 359 |
347 if (ret != 0) { | 360 if (ret != 0) |
348 throw duk::exception(m_ctx, -1); | 361 throw dukx_exception(m_ctx, -1); |
349 } | 362 |
350 | 363 duk_get_global_string(m_ctx, "name"); |
351 ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); | 364 ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); |
352 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 365 duk_pop(m_ctx); |
366 duk_get_global_string(m_ctx, "correct"); | |
367 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
368 duk_pop(m_ctx); | |
353 } catch (const std::exception &ex) { | 369 } catch (const std::exception &ex) { |
354 FAIL() << ex.what(); | 370 FAIL() << ex.what(); |
355 } | 371 } |
356 } | 372 } |
357 | 373 |
358 TEST_F(TestColor, InvalidConstructorRange4) | 374 TEST_F(TestColor, InvalidConstructorRange4) |
359 { | 375 { |
360 try { | 376 try { |
361 auto ret = duk::pevalString(m_ctx, | 377 auto ret = duk_peval_string(m_ctx, |
362 "try {" | 378 "try {" |
363 " Malikania.Color({ red: -1, green: 20, blue: 30 });" | 379 " Malikania.Color({ red: -1, green: 20, blue: 30 });" |
364 "} catch (e) {" | 380 "} catch (e) {" |
365 " name = e.name;" | 381 " name = e.name;" |
366 " correct = (e instanceof RangeError);" | 382 " correct = (e instanceof RangeError);" |
367 "}" | 383 "}" |
368 ); | 384 ); |
369 | 385 |
370 if (ret != 0) { | 386 if (ret != 0) |
371 throw duk::exception(m_ctx, -1); | 387 throw dukx_exception(m_ctx, -1); |
372 } | 388 |
373 | 389 duk_get_global_string(m_ctx, "name"); |
374 ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); | 390 ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); |
375 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 391 duk_pop(m_ctx); |
392 duk_get_global_string(m_ctx, "correct"); | |
393 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
394 duk_pop(m_ctx); | |
376 } catch (const std::exception &ex) { | 395 } catch (const std::exception &ex) { |
377 FAIL() << ex.what(); | 396 FAIL() << ex.what(); |
378 } | 397 } |
379 } | 398 } |
380 | 399 |
381 TEST_F(TestColor, InvalidConstructorRange5) | 400 TEST_F(TestColor, InvalidConstructorRange5) |
382 { | 401 { |
383 try { | 402 try { |
384 auto ret = duk::pevalString(m_ctx, | 403 auto ret = duk_peval_string(m_ctx, |
385 "try {" | 404 "try {" |
386 " Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 800 });" | 405 " Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 800 });" |
387 "} catch (e) {" | 406 "} catch (e) {" |
388 " name = e.name;" | 407 " name = e.name;" |
389 " correct = (e instanceof RangeError);" | 408 " correct = (e instanceof RangeError);" |
390 "}" | 409 "}" |
391 ); | 410 ); |
392 | 411 |
393 if (ret != 0) { | 412 if (ret != 0) |
394 throw duk::exception(m_ctx, -1); | 413 throw dukx_exception(m_ctx, -1); |
395 } | 414 |
396 | 415 duk_get_global_string(m_ctx, "name"); |
397 ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); | 416 ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); |
398 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 417 duk_pop(m_ctx); |
418 duk_get_global_string(m_ctx, "correct"); | |
419 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
420 duk_pop(m_ctx); | |
399 } catch (const std::exception &ex) { | 421 } catch (const std::exception &ex) { |
400 FAIL() << ex.what(); | 422 FAIL() << ex.what(); |
401 } | 423 } |
402 } | 424 } |
403 | 425 |
404 TEST_F(TestColor, InvalidConstructorStringUnknown) | 426 TEST_F(TestColor, InvalidConstructorStringUnknown) |
405 { | 427 { |
406 try { | 428 try { |
407 auto ret = duk::pevalString(m_ctx, | 429 auto ret = duk_peval_string(m_ctx, |
408 "try {" | 430 "try {" |
409 " Malikania.Color('does not exist');" | 431 " Malikania.Color('does not exist');" |
410 "} catch (e) {" | 432 "} catch (e) {" |
411 " name = e.name;" | 433 " name = e.name;" |
412 " correct = (e instanceof Error);" | 434 " correct = (e instanceof Error);" |
413 "}" | 435 "}" |
414 ); | 436 ); |
415 | 437 |
416 if (ret != 0) { | 438 if (ret != 0) |
417 throw duk::exception(m_ctx, -1); | 439 throw dukx_exception(m_ctx, -1); |
418 } | 440 |
419 | 441 duk_get_global_string(m_ctx, "name"); |
420 ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); | 442 ASSERT_STREQ("Error", duk_to_string(m_ctx, -1)); |
421 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 443 duk_pop(m_ctx); |
444 duk_get_global_string(m_ctx, "correct"); | |
445 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
446 duk_pop(m_ctx); | |
422 } catch (const std::exception &ex) { | 447 } catch (const std::exception &ex) { |
423 FAIL() << ex.what(); | 448 FAIL() << ex.what(); |
424 } | 449 } |
425 } | 450 } |
426 | 451 |
427 TEST_F(TestColor, InvalidConstructorStringRgb) | 452 TEST_F(TestColor, InvalidConstructorStringRgb) |
428 { | 453 { |
429 try { | 454 try { |
430 auto ret = duk::pevalString(m_ctx, | 455 auto ret = duk_peval_string(m_ctx, |
431 "try {" | 456 "try {" |
432 " Malikania.Color('#ghijkl');" | 457 " Malikania.Color('#ghijkl');" |
433 "} catch (e) {" | 458 "} catch (e) {" |
434 " name = e.name;" | 459 " name = e.name;" |
435 " correct = (e instanceof Error);" | 460 " correct = (e instanceof Error);" |
436 "}" | 461 "}" |
437 ); | 462 ); |
438 | 463 |
439 if (ret != 0) { | 464 if (ret != 0) |
440 throw duk::exception(m_ctx, -1); | 465 throw dukx_exception(m_ctx, -1); |
441 } | 466 |
442 | 467 duk_get_global_string(m_ctx, "name"); |
443 ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); | 468 ASSERT_STREQ("Error", duk_to_string(m_ctx, -1)); |
444 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 469 duk_pop(m_ctx); |
470 duk_get_global_string(m_ctx, "correct"); | |
471 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
472 duk_pop(m_ctx); | |
445 } catch (const std::exception &ex) { | 473 } catch (const std::exception &ex) { |
446 FAIL() << ex.what(); | 474 FAIL() << ex.what(); |
447 } | 475 } |
448 } | 476 } |
449 | 477 |
456 */ | 484 */ |
457 | 485 |
458 TEST_F(TestColor, requireSuccess) | 486 TEST_F(TestColor, requireSuccess) |
459 { | 487 { |
460 try { | 488 try { |
461 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 489 duk_push_c_function(m_ctx, [] (auto ctx) { |
462 Color color = duk::require<Color>(ctx, 0); | 490 Color color = dukx_require_color(ctx, 0); |
463 | 491 |
464 duk::putGlobal(ctx, "r", static_cast<int>(color.red())); | 492 duk_push_uint(ctx, color.red()); |
465 duk::putGlobal(ctx, "g", static_cast<int>(color.green())); | 493 duk_put_global_string(ctx, "r"); |
466 duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); | 494 duk_push_uint(ctx, color.green()); |
467 duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); | 495 duk_put_global_string(ctx, "g"); |
496 duk_push_uint(ctx, color.blue()); | |
497 duk_put_global_string(ctx, "b"); | |
498 duk_push_uint(ctx, color.alpha()); | |
499 duk_put_global_string(ctx, "a"); | |
468 | 500 |
469 return 0; | 501 return 0; |
470 }, 1}); | 502 }, 1); |
471 | 503 duk_put_global_string(m_ctx, "draw"); |
472 auto ret = duk::pevalString(m_ctx, "draw('#ff0000');"); | 504 |
473 | 505 auto ret = duk_peval_string(m_ctx, "draw('#ff0000');"); |
474 if (ret != 0) { | 506 |
475 throw duk::exception(m_ctx, -1); | 507 if (ret != 0) |
476 } | 508 throw dukx_exception(m_ctx, -1); |
477 | 509 |
478 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); | 510 duk_get_global_string(m_ctx, "r"); |
479 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); | 511 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); |
480 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); | 512 duk_pop(m_ctx); |
481 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | 513 duk_get_global_string(m_ctx, "g"); |
514 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
515 duk_pop(m_ctx); | |
516 duk_get_global_string(m_ctx, "b"); | |
517 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
518 duk_pop(m_ctx); | |
519 duk_get_global_string(m_ctx, "a"); | |
520 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); | |
521 duk_pop(m_ctx); | |
482 } catch (const std::exception &ex) { | 522 } catch (const std::exception &ex) { |
483 FAIL() << ex.what(); | 523 FAIL() << ex.what(); |
484 } | 524 } |
485 } | 525 } |
486 | 526 |
487 TEST_F(TestColor, requireFail) | 527 TEST_F(TestColor, requireFail) |
488 { | 528 { |
489 try { | 529 try { |
490 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 530 duk_push_c_function(m_ctx, [] (auto ctx) { |
491 duk::require<Color>(ctx, 0); | 531 dukx_require_color(ctx, 0); |
492 | 532 |
493 return 0; | 533 return 0; |
494 }, 1}); | 534 }, 1); |
495 | 535 duk_put_global_string(m_ctx, "draw"); |
496 auto ret = duk::pevalString(m_ctx, | 536 |
537 auto ret = duk_peval_string(m_ctx, | |
497 "try {" | 538 "try {" |
498 " draw('#ghijkl');" | 539 " draw('#ghijkl');" |
499 "} catch (e) {" | 540 "} catch (e) {" |
500 " name = e.name;" | 541 " name = e.name;" |
501 " correct = (e instanceof Error);" | 542 " correct = (e instanceof Error);" |
502 "}" | 543 "}" |
503 ); | 544 ); |
504 | 545 |
505 if (ret != 0) { | 546 if (ret != 0) |
506 throw duk::exception(m_ctx, -1); | 547 throw dukx_exception(m_ctx, -1); |
507 } | 548 |
508 | 549 duk_get_global_string(m_ctx, "name"); |
509 ASSERT_EQ("Error", duk::getGlobal<std::string>(m_ctx, "name")); | 550 ASSERT_STREQ("Error", duk_to_string(m_ctx, -1)); |
510 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 551 duk_pop(m_ctx); |
552 duk_get_global_string(m_ctx, "correct"); | |
553 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
554 duk_pop(m_ctx); | |
511 } catch (const std::exception &ex) { | 555 } catch (const std::exception &ex) { |
512 FAIL() << ex.what(); | 556 FAIL() << ex.what(); |
513 } | 557 } |
514 } | 558 } |
515 | 559 |
516 TEST_F(TestColor, requireFailAlpha) | 560 TEST_F(TestColor, requireFailAlpha) |
517 { | 561 { |
518 try { | 562 try { |
519 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 563 duk_push_c_function(m_ctx, [] (auto ctx) { |
520 duk::require<Color>(ctx, 0); | 564 dukx_require_color(ctx, 0); |
521 | 565 |
522 return 0; | 566 return 0; |
523 }, 1}); | 567 }, 1); |
524 | 568 duk_put_global_string(m_ctx, "draw"); |
525 auto ret = duk::pevalString(m_ctx, | 569 |
570 auto ret = duk_peval_string(m_ctx, | |
526 "try {" | 571 "try {" |
527 " draw({ red: 10, green: 20, blue: 30, alpha: 800 });" | 572 " draw({ red: 10, green: 20, blue: 30, alpha: 800 });" |
528 "} catch (e) {" | 573 "} catch (e) {" |
529 " name = e.name;" | 574 " name = e.name;" |
530 " correct = (e instanceof RangeError);" | 575 " correct = (e instanceof RangeError);" |
531 "}" | 576 "}" |
532 ); | 577 ); |
533 | 578 |
534 if (ret != 0) { | 579 if (ret != 0) |
535 throw duk::exception(m_ctx, -1); | 580 throw dukx_exception(m_ctx, -1); |
536 } | 581 |
537 | 582 duk_get_global_string(m_ctx, "name"); |
538 ASSERT_EQ("RangeError", duk::getGlobal<std::string>(m_ctx, "name")); | 583 ASSERT_STREQ("RangeError", duk_to_string(m_ctx, -1)); |
539 ASSERT_TRUE(duk::getGlobal<bool>(m_ctx, "correct")); | 584 duk_pop(m_ctx); |
585 duk_get_global_string(m_ctx, "correct"); | |
586 ASSERT_TRUE(duk_to_boolean(m_ctx, -1)); | |
587 duk_pop(m_ctx); | |
540 } catch (const std::exception &ex) { | 588 } catch (const std::exception &ex) { |
541 FAIL() << ex.what(); | 589 FAIL() << ex.what(); |
542 } | 590 } |
543 } | 591 } |
544 | 592 |
550 */ | 598 */ |
551 | 599 |
552 TEST_F(TestColor, getNormal) | 600 TEST_F(TestColor, getNormal) |
553 { | 601 { |
554 try { | 602 try { |
555 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 603 duk_push_c_function(m_ctx, [] (auto ctx) { |
556 Color color = duk::get<Color>(ctx, 0); | 604 Color color = dukx_get_color(ctx, 0); |
557 | 605 |
558 duk::putGlobal(ctx, "r", static_cast<int>(color.red())); | 606 duk_push_uint(ctx, color.red()); |
559 duk::putGlobal(ctx, "g", static_cast<int>(color.green())); | 607 duk_put_global_string(ctx, "r"); |
560 duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); | 608 duk_push_uint(ctx, color.green()); |
561 duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); | 609 duk_put_global_string(ctx, "g"); |
610 duk_push_uint(ctx, color.blue()); | |
611 duk_put_global_string(ctx, "b"); | |
612 duk_push_uint(ctx, color.alpha()); | |
613 duk_put_global_string(ctx, "a"); | |
562 | 614 |
563 return 0; | 615 return 0; |
564 }, 1}); | 616 }, 1); |
565 | 617 duk_put_global_string(m_ctx, "draw"); |
566 auto ret = duk::pevalString(m_ctx, "draw('#ff0000');"); | 618 |
567 | 619 auto ret = duk_peval_string(m_ctx, "draw('#ff0000');"); |
568 if (ret != 0) { | 620 |
569 throw duk::exception(m_ctx, -1); | 621 if (ret != 0) |
570 } | 622 throw dukx_exception(m_ctx, -1); |
571 | 623 |
572 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "r")); | 624 duk_get_global_string(m_ctx, "r"); |
573 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); | 625 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); |
574 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); | 626 duk_pop(m_ctx); |
575 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | 627 duk_get_global_string(m_ctx, "g"); |
628 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
629 duk_pop(m_ctx); | |
630 duk_get_global_string(m_ctx, "b"); | |
631 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
632 duk_pop(m_ctx); | |
633 duk_get_global_string(m_ctx, "a"); | |
634 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); | |
635 duk_pop(m_ctx); | |
576 } catch (const std::exception &ex) { | 636 } catch (const std::exception &ex) { |
577 FAIL() << ex.what(); | 637 FAIL() << ex.what(); |
578 } | 638 } |
579 } | 639 } |
580 | 640 |
581 TEST_F(TestColor, getAdjustRgb) | 641 TEST_F(TestColor, getAdjustRgb) |
582 { | 642 { |
583 try { | 643 try { |
584 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 644 duk_push_c_function(m_ctx, [] (auto ctx) { |
585 Color color = duk::get<Color>(ctx, 0); | 645 Color color = dukx_get_color(ctx, 0); |
586 | 646 |
587 duk::putGlobal(ctx, "r", static_cast<int>(color.red())); | 647 duk_push_uint(ctx, color.red()); |
588 duk::putGlobal(ctx, "g", static_cast<int>(color.green())); | 648 duk_put_global_string(ctx, "r"); |
589 duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); | 649 duk_push_uint(ctx, color.green()); |
590 duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); | 650 duk_put_global_string(ctx, "g"); |
651 duk_push_uint(ctx, color.blue()); | |
652 duk_put_global_string(ctx, "b"); | |
653 duk_push_uint(ctx, color.alpha()); | |
654 duk_put_global_string(ctx, "a"); | |
591 | 655 |
592 return 0; | 656 return 0; |
593 }, 1}); | 657 }, 1); |
594 | 658 duk_put_global_string(m_ctx, "draw"); |
595 auto ret = duk::pevalString(m_ctx, "draw('#ghijkl');"); | 659 |
596 | 660 auto ret = duk_peval_string(m_ctx, "draw('#ghijkl');"); |
597 if (ret != 0) { | 661 |
598 throw duk::exception(m_ctx, -1); | 662 if (ret != 0) |
599 } | 663 throw dukx_exception(m_ctx, -1); |
600 | 664 |
601 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); | 665 duk_get_global_string(m_ctx, "r"); |
602 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); | 666 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); |
603 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); | 667 duk_pop(m_ctx); |
604 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | 668 duk_get_global_string(m_ctx, "g"); |
669 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
670 duk_pop(m_ctx); | |
671 duk_get_global_string(m_ctx, "b"); | |
672 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
673 duk_pop(m_ctx); | |
674 duk_get_global_string(m_ctx, "a"); | |
675 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); | |
676 duk_pop(m_ctx); | |
605 } catch (const std::exception &ex) { | 677 } catch (const std::exception &ex) { |
606 FAIL() << ex.what(); | 678 FAIL() << ex.what(); |
607 } | 679 } |
608 } | 680 } |
609 | 681 |
610 TEST_F(TestColor, getAdjustAll) | 682 TEST_F(TestColor, getAdjustAll) |
611 { | 683 { |
612 try { | 684 try { |
613 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 685 duk_push_c_function(m_ctx, [] (auto ctx) { |
614 Color color = duk::get<Color>(ctx, 0); | 686 Color color = dukx_get_color(ctx, 0); |
615 | 687 |
616 duk::putGlobal(ctx, "r", static_cast<int>(color.red())); | 688 duk_push_uint(ctx, color.red()); |
617 duk::putGlobal(ctx, "g", static_cast<int>(color.green())); | 689 duk_put_global_string(ctx, "r"); |
618 duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); | 690 duk_push_uint(ctx, color.green()); |
619 duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); | 691 duk_put_global_string(ctx, "g"); |
692 duk_push_uint(ctx, color.blue()); | |
693 duk_put_global_string(ctx, "b"); | |
694 duk_push_uint(ctx, color.alpha()); | |
695 duk_put_global_string(ctx, "a"); | |
620 | 696 |
621 return 0; | 697 return 0; |
622 }, 1}); | 698 }, 1); |
623 | 699 duk_put_global_string(m_ctx, "draw"); |
624 auto ret = duk::pevalString(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });"); | 700 |
625 | 701 auto ret = duk_peval_string(m_ctx, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });"); |
626 if (ret != 0) { | 702 |
627 throw duk::exception(m_ctx, -1); | 703 if (ret != 0) |
628 } | 704 throw dukx_exception(m_ctx, -1); |
629 | 705 |
630 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); | 706 duk_get_global_string(m_ctx, "r"); |
631 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "g")); | 707 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); |
632 ASSERT_EQ(100, duk::getGlobal<int>(m_ctx, "b")); | 708 duk_pop(m_ctx); |
633 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | 709 duk_get_global_string(m_ctx, "g"); |
710 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); | |
711 duk_pop(m_ctx); | |
712 duk_get_global_string(m_ctx, "b"); | |
713 ASSERT_EQ(100U, duk_to_uint(m_ctx, -1)); | |
714 duk_pop(m_ctx); | |
715 duk_get_global_string(m_ctx, "a"); | |
716 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); | |
717 duk_pop(m_ctx); | |
634 } catch (const std::exception &ex) { | 718 } catch (const std::exception &ex) { |
635 FAIL() << ex.what(); | 719 FAIL() << ex.what(); |
636 } | 720 } |
637 } | 721 } |
638 | 722 |
639 TEST_F(TestColor, getSomethingElse) | 723 TEST_F(TestColor, getSomethingElse) |
640 { | 724 { |
641 try { | 725 try { |
642 duk::putGlobal(m_ctx, "draw", duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { | 726 duk_push_c_function(m_ctx, [] (auto ctx) { |
643 Color color = duk::get<Color>(ctx, 0); | 727 Color color = dukx_get_color(ctx, 0); |
644 | 728 |
645 duk::putGlobal(ctx, "r", static_cast<int>(color.red())); | 729 duk_push_uint(ctx, color.red()); |
646 duk::putGlobal(ctx, "g", static_cast<int>(color.green())); | 730 duk_put_global_string(ctx, "r"); |
647 duk::putGlobal(ctx, "b", static_cast<int>(color.blue())); | 731 duk_push_uint(ctx, color.green()); |
648 duk::putGlobal(ctx, "a", static_cast<int>(color.alpha())); | 732 duk_put_global_string(ctx, "g"); |
733 duk_push_uint(ctx, color.blue()); | |
734 duk_put_global_string(ctx, "b"); | |
735 duk_push_uint(ctx, color.alpha()); | |
736 duk_put_global_string(ctx, "a"); | |
649 | 737 |
650 return 0; | 738 return 0; |
651 }, 1}); | 739 }, 1); |
652 | 740 duk_put_global_string(m_ctx, "draw"); |
653 auto ret = duk::pevalString(m_ctx, "draw(null);"); | 741 |
654 | 742 auto ret = duk_peval_string(m_ctx, "draw(null);"); |
655 if (ret != 0) { | 743 |
656 throw duk::exception(m_ctx, -1); | 744 if (ret != 0) |
657 } | 745 throw dukx_exception(m_ctx, -1); |
658 | 746 |
659 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "r")); | 747 duk_get_global_string(m_ctx, "r"); |
660 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "g")); | 748 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); |
661 ASSERT_EQ(0, duk::getGlobal<int>(m_ctx, "b")); | 749 duk_pop(m_ctx); |
662 ASSERT_EQ(255, duk::getGlobal<int>(m_ctx, "a")); | 750 duk_get_global_string(m_ctx, "g"); |
751 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
752 duk_pop(m_ctx); | |
753 duk_get_global_string(m_ctx, "b"); | |
754 ASSERT_EQ(0U, duk_to_uint(m_ctx, -1)); | |
755 duk_pop(m_ctx); | |
756 duk_get_global_string(m_ctx, "a"); | |
757 ASSERT_EQ(255U, duk_to_uint(m_ctx, -1)); | |
758 duk_pop(m_ctx); | |
663 } catch (const std::exception &ex) { | 759 } catch (const std::exception &ex) { |
664 FAIL() << ex.what(); | 760 FAIL() << ex.what(); |
665 } | 761 } |
666 } | 762 } |
667 | 763 |