comparison tests/libclient/sprite/main.cpp @ 42:a47a4477f347

Misc: new style, closes #578
author David Demelier <markand@malikania.fr>
date Tue, 29 Nov 2016 21:21:36 +0100
parents d4f5f7231b84
children fabbe1759cec
comparison
equal deleted inserted replaced
41:3645200f46bf 42:a47a4477f347
20 #include <thread> 20 #include <thread>
21 #include <exception> 21 #include <exception>
22 22
23 #include <gtest/gtest.h> 23 #include <gtest/gtest.h>
24 24
25 #include <malikania/client-resources-loader.hpp> 25 #include <malikania/client_resources_loader.hpp>
26 #include <malikania/resources-locator.hpp> 26 #include <malikania/resources_locator.hpp>
27 #include <malikania/sprite.hpp> 27 #include <malikania/sprite.hpp>
28 #include <malikania/window.hpp> 28 #include <malikania/window.hpp>
29 29
30 using namespace malikania; 30 namespace mlk = malikania;
31 31
32 using namespace std::chrono_literals; 32 using namespace std::chrono_literals;
33 33
34 namespace { 34 namespace {
35 35
36 Window window(400, 400); 36 mlk::window window(400, 400);
37 37
38 } // !namespace 38 } // !namespace
39 39
40 class TestSprite : public testing::Test { 40 class TestSprite : public testing::Test {
41 protected: 41 protected:
42 ResourcesLocatorDirectory m_locator; 42 mlk::directory_resources_locator m_locator;
43 ClientResourcesLoader m_loader; 43 mlk::client_resources_loader m_loader;
44 44
45 public: 45 public:
46 TestSprite() 46 TestSprite()
47 : m_locator(SOURCE_DIRECTORY "/resources") 47 : m_locator(SOURCE_DIRECTORY "/resources")
48 , m_loader(m_locator) 48 , m_loader(m_locator)
56 */ 56 */
57 57
58 TEST_F(TestSprite, missingPropertyImage) 58 TEST_F(TestSprite, missingPropertyImage)
59 { 59 {
60 try { 60 try {
61 m_loader.loadSprite("sprites/no-property-image.json"); 61 m_loader.load_sprite("sprites/no-property-image.json");
62 62
63 FAIL() << "exception expected"; 63 FAIL() << "exception expected";
64 } catch (const std::exception &) { 64 } catch (const std::exception &) {
65 } 65 }
66 } 66 }
67 67
68 TEST_F(TestSprite, missingPropertyCell) 68 TEST_F(TestSprite, missingPropertyCell)
69 { 69 {
70 try { 70 try {
71 m_loader.loadSprite("sprites/no-property-cell.json"); 71 m_loader.load_sprite("sprites/no-property-cell.json");
72 72
73 FAIL() << "exception expected"; 73 FAIL() << "exception expected";
74 } catch (const std::exception &) { 74 } catch (const std::exception &) {
75 } 75 }
76 } 76 }
81 */ 81 */
82 82
83 TEST_F(TestSprite, imageNotString) 83 TEST_F(TestSprite, imageNotString)
84 { 84 {
85 try { 85 try {
86 m_loader.loadSprite("sprites/property-image-not-string.json"); 86 m_loader.load_sprite("sprites/property-image-not-string.json");
87 87
88 FAIL() << "exception expected"; 88 FAIL() << "exception expected";
89 } catch (const std::exception &) { 89 } catch (const std::exception &) {
90 } 90 }
91 } 91 }
92 92
93 TEST_F(TestSprite, cellNotArray) 93 TEST_F(TestSprite, cellNotArray)
94 { 94 {
95 try { 95 try {
96 m_loader.loadSprite("sprites/property-cell-not-array.json"); 96 m_loader.load_sprite("sprites/property-cell-not-array.json");
97 97
98 FAIL() << "exception expected"; 98 FAIL() << "exception expected";
99 } catch (const std::exception &) { 99 } catch (const std::exception &) {
100 } 100 }
101 } 101 }
102 102
103 TEST_F(TestSprite, cellNotArray2) 103 TEST_F(TestSprite, cellNotArray2)
104 { 104 {
105 try { 105 try {
106 m_loader.loadSprite("sprites/property-cell-not-array2.json"); 106 m_loader.load_sprite("sprites/property-cell-not-array2.json");
107 107
108 FAIL() << "exception expected"; 108 FAIL() << "exception expected";
109 } catch (const std::exception &) { 109 } catch (const std::exception &) {
110 } 110 }
111 } 111 }
116 */ 116 */
117 117
118 TEST_F(TestSprite, imageNotFound) 118 TEST_F(TestSprite, imageNotFound)
119 { 119 {
120 try { 120 try {
121 m_loader.loadSprite("sprites/image-not-found.json"); 121 m_loader.load_sprite("sprites/image-not-found.json");
122 122
123 FAIL() << "exception expected"; 123 FAIL() << "exception expected";
124 } catch (const std::exception &) { 124 } catch (const std::exception &) {
125 } 125 }
126 } 126 }
127 127
128 TEST_F(TestSprite, notObject) 128 TEST_F(TestSprite, notObject)
129 { 129 {
130 try { 130 try {
131 m_loader.loadSprite("sprites/not-object.json"); 131 m_loader.load_sprite("sprites/not-object.json");
132 132
133 FAIL() << "exception expected"; 133 FAIL() << "exception expected";
134 } catch (const std::exception &) { 134 } catch (const std::exception &) {
135 } 135 }
136 } 136 }
141 */ 141 */
142 142
143 TEST_F(TestSprite, standard) 143 TEST_F(TestSprite, standard)
144 { 144 {
145 try { 145 try {
146 Sprite sprite = m_loader.loadSprite("sprites/simple.json"); 146 auto sprite = m_loader.load_sprite("sprites/simple.json");
147 147
148 ASSERT_EQ(300U, sprite.cell().width()); 148 ASSERT_EQ(300U, sprite.cell().width());
149 ASSERT_EQ(300U, sprite.cell().height()); 149 ASSERT_EQ(300U, sprite.cell().height());
150 } catch (const std::exception &ex) { 150 } catch (const std::exception &ex) {
151 FAIL() << ex.what(); 151 FAIL() << ex.what();
153 } 153 }
154 154
155 TEST_F(TestSprite, margins) 155 TEST_F(TestSprite, margins)
156 { 156 {
157 try { 157 try {
158 Sprite sprite = m_loader.loadSprite("sprites/margins.json"); 158 auto sprite = m_loader.load_sprite("sprites/margins.json");
159 159
160 ASSERT_EQ(3U, sprite.rows()); 160 ASSERT_EQ(3U, sprite.rows());
161 ASSERT_EQ(4U, sprite.columns()); 161 ASSERT_EQ(4U, sprite.columns());
162 } catch (const std::exception &ex) { 162 } catch (const std::exception &ex) {
163 FAIL() << ex.what(); 163 FAIL() << ex.what();
165 } 165 }
166 166
167 TEST_F(TestSprite, draw) 167 TEST_F(TestSprite, draw)
168 { 168 {
169 try { 169 try {
170 Sprite sprite = m_loader.loadSprite("sprites/margins.json"); 170 auto sprite = m_loader.load_sprite("sprites/margins.json");
171 171
172 unsigned total = sprite.rows() * sprite.columns(); 172 auto total = sprite.rows() * sprite.columns();
173
174 auto x = (400 / 2) - (sprite.cell().width() / 2); 173 auto x = (400 / 2) - (sprite.cell().width() / 2);
175 auto y = (400 / 2) - (sprite.cell().height() / 2); 174 auto y = (400 / 2) - (sprite.cell().height() / 2);
176 175
177 for (unsigned c = 0; c < total; ++c) { 176 for (unsigned c = 0; c < total; ++c) {
178 window.clear(); 177 window.clear();
179 sprite.draw(window, c, Point(x, y)); 178 sprite.draw(window, c, mlk::point(x, y));
180 window.present(); 179 window.present();
181 180
182 std::this_thread::sleep_for(1s); 181 std::this_thread::sleep_for(1s);
183 } 182 }
184 } catch (const std::exception &ex) { 183 } catch (const std::exception &ex) {