-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.h
515 lines (402 loc) · 17.7 KB
/
tests.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/**
* DO NOT MODIFY!
* Test File for the FileReader
* A final version will be relased close to the deadline with mroe detailed tests.
*/
#pragma once
#include <string>
#include "../FileReader.h"
//#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
TEST_CASE( "STD 1: Creating a FileReader object" ) {
FileReader reader = FileReader();
CHECK(reader.currentFile().empty());
}
TEST_CASE( "STD 2: Opening File from data folder" ) {
FileReader reader = FileReader();
CHECK( reader.openFile("data/cube.obj") == true );
}
TEST_CASE("STD 3: Closing File from data folder" ) {
FileReader reader = FileReader();
reader.openFile("data/cube.obj");
CHECK(reader.closeFile("data/cube.obj") == true);
CHECK(reader.closeFile("data/cube.obj") == false);
}
TEST_CASE("STD 4: Closing currently open File" ) {
FileReader reader = FileReader();
reader.openFile("data/cube.obj");
CHECK(reader.closeCurrentFile() == true);
CHECK(reader.closeCurrentFile() == false);
}
TEST_CASE("STD 5: Opening and Reading a simple OBJ File") {
FileReader reader = FileReader();
std::string fileName = "data/cube.obj";
reader.openFile(fileName);
std::string checkName = reader.currentFile();
CHECK(checkName.compare(checkName.size() - fileName.size(), fileName.size(), fileName) == 0);
std::vector<std::string> lines = reader.getLines(0, 20);
std::string comparison = "v 1.000000 -1.000000 1.000000";
REQUIRE(lines.size() == 21);
CHECK(lines[14].compare(comparison) == 0);
CHECK(reader.lineCount() == 73);
reader.closeCurrentFile();
}
TEST_CASE("STD 6: Opening and Reading a large OBJ File and trying to load lines.") {
FileReader reader = FileReader();
std::string fileName = "data/boat.obj";
CHECK(reader.openFile(fileName) == true);
std::string checkName = reader.currentFile();
CHECK(checkName.compare(checkName.size() - fileName.size(), fileName.size(), fileName) == 0);
CHECK(reader.getLine(211222).length() == 0); //going beyond the length of the file on purpose
REQUIRE(reader.lineCount() == 119361);
std::string line = reader.getLine(92205);
std::string comparison = "o Cylinder.3_2";
REQUIRE(line.length() > 1);
CHECK(line.compare(comparison) == 0);
reader.closeCurrentFile();
}
TEST_CASE("STD 7: Trying to get an element from a simple OBJ file") {
FileReader reader = FileReader();
std::string fileName = "data/cube.obj";
CHECK(reader.openFile(fileName) == true);
std::vector<std::string> lines = reader.getElement("object");
std::string comparison = "Cube_Cube.001";
REQUIRE(lines.size() >= 1);
CHECK(lines[0].compare(comparison) == 0);
lines = reader.getElement("object");
REQUIRE(lines.size() >= 1);
CHECK(lines[0].compare(comparison) == 0);
lines = reader.getNextElement("object"); // moves cursor
std::string comparison2 = "";
REQUIRE(lines.size() >= 1);
CHECK(lines[0].compare(comparison2) == 0);
reader.resetElement("object"); //resetting cursor be beginning of vertrices
lines = reader.getElement("object");
REQUIRE(lines.size() >= 1);
CHECK(lines[0].compare(comparison) == 0);
reader.closeCurrentFile();
}
TEST_CASE("STD 8: Trying to get an element and attribute from a simple OBJ file") {
FileReader reader = FileReader();
std::string fileName = "data/cube.obj";
CHECK(reader.openFile(fileName) == true);
std::string line = reader.getElementAttribute("object", "vertex");
REQUIRE(line.length() > 1);
std::string comparison = "1.000000 1.000000 -1.000000";
CHECK(line.compare(comparison) == 0);
line = reader.getElementAttribute("vertex", "vertex-texture");
REQUIRE(line.length() > 1);
comparison = "0.625000 0.500000";
CHECK(line.compare(comparison) == 0);
line = reader.getElementAttribute("vertex", "vertex-normal");
REQUIRE(line.length() >= 0);
comparison = "0.0000 1.0000 0.0000";
CHECK(line.compare(comparison) == 0);
reader.closeCurrentFile();
}
TEST_CASE("STD 9: Trying to get an element attribute from an OBJ file") {
FileReader reader = FileReader();
std::string fileName = "data/boat.obj";
CHECK(reader.openFile(fileName) == true);
std::string value = reader.getElementAttribute("object", "face");
std::string comparison = "1/1/1 2/2/1 4/4/1";
value = reader.getNextElementAttribute("object", "face");
comparison = "1/1/1 4/4/1 6/6/1";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("object", "face");
comparison = "7/7/1 9/9/2 11/11/1";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("object", "face");
comparison = "7/7/1 11/11/1 12/12/1";
CHECK(value.compare(comparison) == 0);
reader.getNextElement("object");
value = reader.getElementAttribute("object", "face");
comparison = "364/364/11 398/398/12 399/399/13";
CHECK(value.compare(comparison) == 0);
reader.resetElement("object");
value = reader.getElementAttribute("object", "face");
comparison = "1/1/1 2/2/1 4/4/1";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("object", 3, "face"); // get's the n+1th attribute
comparison = "7/7/1 11/11/1 12/12/1";
CHECK(value.compare(comparison) == 0);
reader.closeCurrentFile();
}
TEST_CASE("STD 10: Opening and Reading a large OBJ File and trying to load too many lines.") {
FileReader reader = FileReader();
std::string fileName = "data/pouf.obj";
CHECK(reader.openFile(fileName) == true);
std::string checkName = reader.currentFile();
CHECK(checkName.compare(checkName.size() - fileName.size(), fileName.size(), fileName) == 0);
CHECK(reader.getLines(0, 2500000).size() > 0); //going beyond the length of the file on purpose
std::vector<std::string> lines = reader.getLines(0, 2500000);
CHECK(lines.size() == 207776);
reader.closeCurrentFile();
}
TEST_CASE("STD 11: Opening an invalid File from data folder") {
FileReader reader = FileReader();
//wrong file name supplied
CHECK(reader.openFile("data/cube.obje") == false);
CHECK(reader.openFile("data/large..dae") == false);
CHECK(reader.openFile("datas/cube.obj") == false);
CHECK(reader.openFile("data/ cube.obj") == false);
}
TEST_CASE("STD 12: Checking repeated Operations") {
FileReader reader = FileReader();
reader.openFile("data/cube.obj");
CHECK(reader.closeCurrentFile() == true);
CHECK(reader.closeCurrentFile() == false);
reader.openFile("data/boat.obj");
CHECK(reader.closeFile("data/cube.obj") == false);
CHECK(reader.getLines(0, 2).size() > 0);
CHECK(reader.closeCurrentFile() == true);
CHECK(reader.currentFile().empty());
CHECK(reader.getLines(0, 1).size() == 0);
}
TEST_CASE("STD 13: Multiple Files Can be Loaded and Inspected for their Elements") {
FileReader reader = FileReader();
//inspecting first file
std::string fileName = "data/boat.obj";
CHECK(reader.openFile(fileName) == true);
std::string line = reader.getElementAttribute("object", 2,"vertex");
REQUIRE(line.length() > 1);
std::string comparison = "-5.507223 25.197802 38.613228";
CHECK(line.compare(comparison) == 0);
//inspecting second file
reader.openFile("data/cube.obj");
line = reader.getElementAttribute("object", 0,"vertex-normal");
REQUIRE(line.length() > 1);
comparison = "0.0000 1.0000 0.0000";
CHECK(line.compare(comparison) == 0);
CHECK(reader.switchCurrentFile("data/boat.obj"));
line = reader.getElementAttribute("object", "vertex");
REQUIRE(line.length() > 1);
comparison = "2.210220 33.775902 38.926983";
CHECK(line.compare(comparison) == 0);
reader.closeCurrentFile();
reader.closeCurrentFile();
}
TEST_CASE("STD 14: Checking Wrong items in File") {
FileReader reader = FileReader();
REQUIRE(reader.openFile("data/cube.obj"));
std::string comparison = "18/21/6 1/23/6 5/24/6";
std::string value = reader.getElementAttribute("object", "red");
CHECK(value.compare("") == 0);
value = reader.getElementAttribute("object", "faces");
CHECK(value.compare("") == 0);
value = reader.getElementAttribute("object", 11, "face");
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("object", "faces");
CHECK(value.compare("") == 0);
reader.closeCurrentFile();
}
TEST_CASE("ADV 1: Checking repeated Operations 2") {
FileReader reader = FileReader();
reader.openFile("data/cube.obj");
CHECK(reader.switchCurrentFile("data/cube.obj") == true);
reader.closeFile("data/cube.obj");
CHECK(reader.currentFile().empty());
CHECK(reader.openFile("data/cube.obj") == true);
CHECK(reader.openFile("data/cube.obj") == false);
CHECK(reader.currentFile().compare("data/cube.obj") == 0);
CHECK(reader.openFile("data/boat.gltf") == true);
CHECK(reader.openFile("data/cube.obj") == false);
CHECK(reader.closeCurrentFile() == true);
CHECK(reader.closeCurrentFile() == true);
}
TEST_CASE("ADV 2: Checking Additional items in File") {
FileReader reader = FileReader();
REQUIRE(reader.openFile("data/pouf.gltf"));
REQUIRE(reader.openFile("data/cube.obj"));
REQUIRE(reader.openFile("data/boat.obj"));
CHECK(reader.switchCurrentFile("data/cube.obj") == true);
std::string comparison = "18/21/6 1/23/6 5/24/6";
std::string value = reader.getElementAttribute("object", 11, "face");
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("object", "face");
CHECK(value.compare(comparison) == 0);
REQUIRE(reader.switchCurrentFile("data/boat.obj") == true);
value = reader.getElementAttribute("object", 1, "face");
comparison = "1/1/1 4/4/1 6/6/1";
CHECK(value.compare(comparison) == 0);
reader.getNextElement("object");
value = reader.getElementAttribute("object", 2, "face");
comparison = "376/376/12 399/399/13 400/400/14";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElement("object")[0];
comparison = "Floor:2";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("object", "vertex");
comparison = "-0.326423 51.591156 31.248625";
CHECK(value.compare(comparison) == 0);
reader.closeCurrentFile();
}
TEST_CASE("ADV 3: Trying to get element attributes from an GLTF file") {
FileReader reader = FileReader();
std::string fileName = "data/cube.gltf";
CHECK(reader.openFile(fileName) == true);
std::string value = reader.getElementAttribute("mesh", "name");
std::string comparison = "Cube";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("mesh", "name");
comparison = "";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("accessor", "bufferView");
comparison = "0";
CHECK(value.compare(comparison) == 0);
reader.getNextElement("accessor");
value = reader.getElementAttribute("accessor", "bufferView");
comparison = "1";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("accessor", "bufferView");
comparison = "";
CHECK(value.compare(comparison) == 0);
std::vector<std::string> complex = reader.getElement("accessor");
comparison = "\"count\" : 24,";
REQUIRE(complex.size() > 2);
CHECK(comparison.compare(complex[2]) == 0);
complex = reader.getNextElement("accessor");
comparison = "\"componentType\" : 5126,";
REQUIRE(complex.size() > 1);
CHECK(comparison.compare(complex[1]) == 0);
complex = reader.getElement("bufferView");
comparison = "\"buffer\" : 0,";
REQUIRE(complex.size() > 1);
CHECK(comparison.compare(complex[0]) == 0);
comparison = "";
REQUIRE(complex.size() > 3);
CHECK(comparison.compare(complex[4]) == 0);
reader.closeCurrentFile();
}
TEST_CASE("ADV 4: Opening incorrect as well as lots of files from data folder") {
FileReader reader = FileReader();
//wrong file name supplied
CHECK(reader.openFile("data/cube. gltf") == false);
CHECK(reader.openFile("data/cube.dae") == false);
CHECK(reader.openFile("data/cube.obj") == true);
CHECK(reader.openFile("data/cube.gltf") == true);
CHECK(reader.openFile("data/pouf.obj") == true);
CHECK(reader.openFile("data/pouf.gltf") == true);
CHECK(reader.openFile("data/boat.obj") == true);
CHECK(reader.openFile("data/boat.gltf") == true);
CHECK(reader.openFile("data/cube.obj") == false);
}
TEST_CASE("ADV 5: Opening and Reading a large GLTF File and trying to load a lot.") {
FileReader reader = FileReader();
std::string fileName = "data/boat.gltf";
CHECK(reader.openFile(fileName) == true);
std::string value = reader.getElementAttribute("mesh", "name");
std::string comparison = "Floor:1";
CHECK(value.compare(comparison) == 0);
reader.getNextElement("mesh");
value = reader.getNextElementAttribute("mesh", "name");
comparison = "";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("mesh", "name");
comparison = "Body";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("mesh", "rotation");
comparison = "0.7071068286895752";
CHECK(value.compare(comparison) == 0);
reader.getElement("mesh",66);
value = reader.getElementAttribute("mesh", "name");
comparison = "Cylinder_12";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("mesh", "rotation");
comparison = "0.7071068286895752";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("mesh", "rotation");
comparison = "0";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("mesh", "rotation");
comparison = "0";
CHECK(value.compare(comparison) == 0);
std::vector<std::string> complex = reader.getElement("accessor",0);
comparison = "\"count\" : 306,";
REQUIRE(complex.size() > 1);
CHECK(complex[2].compare(comparison) == 0);
value = reader.getElementAttribute("accessor","max");
comparison = "59.13680648803711";
CHECK(comparison.compare(value) == 0);
value = reader.getNextElementAttribute("accessor", "max");
comparison = "98.21562957763672";
CHECK(comparison.compare(value) == 0);
reader.getNextElement("accessor");
value = reader.getElementAttribute("accessor", "max");
comparison = "";
CHECK(comparison.compare(value) == 0);
value = reader.getElementAttribute("accessor", "type");
comparison = "VEC3";
CHECK(comparison.compare(value) == 0);
reader.getNextElement("accessor");
value = reader.getElementAttribute("accessor", "type");
comparison = "VEC2";
CHECK(comparison.compare(value) == 0);
reader.getNextElement("accessor");
value = reader.getElementAttribute("accessor", "type");
comparison = "SCALAR";
CHECK(comparison.compare(value) == 0);
reader.closeCurrentFile();
}
TEST_CASE("ADV 6: Checking Multiple items in Files") {
FileReader reader = FileReader();
REQUIRE(reader.openFile("data/pouf.gltf"));
REQUIRE(reader.openFile("data/cube.obj"));
CHECK(reader.switchCurrentFile("data/cube.obj") == true);
std::string comparison = "18/21/6 1/23/6 5/24/6";
std::string value = reader.getElementAttribute("object", 11, "face");
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("object", "face");
CHECK(value.compare(comparison) == 0);
CHECK(reader.switchCurrentFile("data/cube.gltf") == false);
REQUIRE(reader.openFile("data/cube.gltf"));
value = reader.getElementAttribute("mesh", "name");
comparison = "Cube";
CHECK(value.compare(comparison) == 0);
reader.getNextElement("mesh");
value = reader.getNextElementAttribute("mesh", "name");
comparison = "";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("material", "doubleSided");
comparison = "true";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("material", "name");
comparison = "Material";
CHECK(value.compare(comparison) == 0);
reader.closeCurrentFile();
reader.closeCurrentFile();
CHECK(reader.closeCurrentFile());
}
TEST_CASE("ADV 7: Complex Deep Checks which dive into Properties.") {
FileReader reader = FileReader();
std::string fileName = "data/cube.gltf";
CHECK(reader.openFile(fileName) == true);
std::string value = reader.getElementAttribute("material", "name");
std::string comparison = "Material";
REQUIRE(value.compare(comparison) == 0);
value = reader.getElementAttribute("material", "pbrMetallicRoughness_baseColorFactor");
comparison = "0.800000011920929";
REQUIRE(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("material", "pbrMetallicRoughness_baseColorFactor");
comparison = "0.800000011920929";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("mesh", "primitives_attributes");
comparison = "\"POSITION\" : 0,";
CHECK(value.compare(comparison) == 0);
value = reader.getNextElementAttribute("mesh", "primitives_attributes");
comparison = "\"NORMAL\" : 1,";
CHECK(value.compare(comparison) == 0);
reader.resetElementAttribute("mesh", "primitives_attributes");
value = reader.getElementAttribute("mesh", "primitives_attributes");
comparison = "\"POSITION\" : 0,";
CHECK(value.compare(comparison) == 0);
value = reader.getElementAttribute("mesh", "primitives_attributes_POSITION");
comparison = "0";
CHECK(value.compare(comparison) == 0);
reader.getNextElement("mesh");
value = reader.getElementAttribute("mesh", "primitives_attributes_POSITION");
comparison = "";
CHECK(value.compare(comparison) == 0);
reader.closeCurrentFile();
}