comparison tests/libclient/js-animation/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 3645200f46bf
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>
25 #include <malikania/elapsed-timer.hpp> 24 #include <malikania/elapsed-timer.hpp>
25 #include <malikania/js-client-resources-loader.hpp>
26 #include <malikania/js-animation.hpp> 26 #include <malikania/js-animation.hpp>
27 #include <malikania/js-animator.hpp> 27 #include <malikania/js-animator.hpp>
28 #include <malikania/js-window.hpp> 28 #include <malikania/js-window.hpp>
29 #include <malikania/resources-locator.hpp> 29 #include <malikania/resources-locator.hpp>
30 30
34 34
35 class TestAnimation : public testing::Test { 35 class TestAnimation : public testing::Test {
36 protected: 36 protected:
37 ResourcesLocatorDirectory m_locator; 37 ResourcesLocatorDirectory m_locator;
38 ClientResourcesLoader m_loader; 38 ClientResourcesLoader m_loader;
39 39 UniqueContext m_ctx;
40 duk::Context m_ctx;
41 40
42 public: 41 public:
43 TestAnimation() 42 TestAnimation()
44 : m_locator(SOURCE_DIRECTORY "/resources") 43 : m_locator(SOURCE_DIRECTORY "/resources")
45 , m_loader(m_locator) 44 , m_loader(m_locator)
46 { 45 {
47 duk::putGlobal(m_ctx, "Malikania", duk::Object()); 46 duk_push_object(m_ctx);
48 47 duk_put_global_string(m_ctx, "Malikania");
49 loadMalikaniaAnimation(m_ctx); 48 dukx_load_animation(m_ctx);
50 loadMalikaniaAnimator(m_ctx); 49 dukx_load_animator(m_ctx);
51 loadMalikaniaWindow(m_ctx); 50 dukx_load_window(m_ctx);
52 51 dukx_put_client_loader(m_ctx, &m_loader);
53 /* Store the loader */
54 duk::putGlobal(m_ctx, "\xff""\xff""loader", &m_loader);
55 } 52 }
56 }; 53 };
57 54
58 TEST_F(TestAnimation, basic) 55 TEST_F(TestAnimation, basic)
59 { 56 {
60 try { 57 try {
61 auto ret = duk::pevalString(m_ctx, 58 auto ret = duk_peval_string(m_ctx,
62 "w = new Malikania.Window();" 59 "w = new Malikania.Window();"
63 "a = new Malikania.Animation('animations/margins.json');" 60 "a = new Malikania.Animation('animations/margins.json');"
64 "d = new Malikania.Animator(a);" 61 "d = new Malikania.Animator(a);"
65 ); 62 );
66 63
67 if (ret != 0) { 64 if (ret != 0)
68 throw duk::exception(m_ctx, -1); 65 throw dukx_exception(m_ctx, -1);
69 }
70 66
71 ElapsedTimer timer; 67 ElapsedTimer timer;
72 68
73 while (timer.elapsed() < 8000) { 69 while (timer.elapsed() < 8000) {
74 auto ret = duk::pevalString(m_ctx, 70 auto ret = duk_peval_string(m_ctx,
75 "w.setDrawingColor('lightskyblue');" 71 "w.setDrawingColor('lightskyblue');"
76 "w.clear();" 72 "w.clear();"
77 "d.draw(w, { x: 320 - 16, y: 240 - 16 });" 73 "d.draw(w, { x: 320 - 16, y: 240 - 16 });"
78 "d.update();" 74 "d.update();"
79 "w.present();" 75 "w.present();"
80 ); 76 );
81 77
82 if (ret != 0) { 78 if (ret != 0)
83 throw duk::exception(m_ctx, -1); 79 throw dukx_exception(m_ctx, -1);
84 }
85 } 80 }
86 81
87 std::this_thread::sleep_for(3s); 82 std::this_thread::sleep_for(3s);
88 } catch (const std::exception &ex) { 83 } catch (const std::exception &ex) {
89 FAIL() << ex.what(); 84 FAIL() << ex.what();