-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFramework.h
More file actions
767 lines (675 loc) · 22.8 KB
/
TestFramework.h
File metadata and controls
767 lines (675 loc) · 22.8 KB
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#ifndef TESTFRAMEWORK_H
#define TESTFRAMEWORK_H
#include <QApplication>
#include <QCommandLineParser>
#include <QList>
#include <QString>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QTextStream>
#include <QProcess>
#include <QDebug>
#include <QRegularExpression>
#include <QImage>
#include <cmath>
#include "Exceptions.h"
#include "Helper.h"
#include "VersatileFile.h"
namespace TFW
{
class TestExecutor
{
public:
TestExecutor()
{
}
const QByteArray& name() const
{
return name_;
}
void setName(const QByteArray& name)
{
name_ = name;
}
int testCount()
{
return tests_.count();
}
QByteArray methodName(int i)
{
return tests_[i].first;
}
std::function<void()> method(int i)
{
return tests_[i].second;
}
//Get log file of last executeTool call
QString lastLogFile()
{
return last_log_;
}
///Executes a tool and returns (1) if the execution was successful (2) the error message if it was not successful
QString executeTool(QString toolname, QString arguments, bool ignore_error_code, QString file, int line)
{
if (QFile::exists(toolname)) //Linux
{
toolname = "./" + toolname;
}
else if (QFile::exists(toolname + ".exe")) //Windows
{
toolname = toolname + ".exe";
}
else
{
return "Tool '" + toolname + "' not found!";
}
QProcess process;
last_log_ = "out/" + QFileInfo(file).baseName() + "_line" + QString::number(line) + ".log";
process.setProcessChannelMode(QProcess::MergedChannels);
process.setStandardOutputFile(last_log_);
QStringList arg_split = arguments.simplified().trimmed().split(' ');
for(int i=0; i<arg_split.count(); ++i)
{
arg_split[i].replace("%20", " ");
}
process.start(toolname, arg_split);
bool started = process.waitForStarted(-1);
bool finished = process.waitForFinished(-1);
int exit_code = process.exitCode();
if (!started || !finished || (!ignore_error_code && exit_code!=0))
{
QByteArray result = "exit code: " + QByteArray::number(exit_code);
QFile tmp_file(last_log_);
tmp_file.open(QFile::ReadOnly|QFile::Text);
result += "\ntool output:\n" + tmp_file.readAll().trimmed();
return result;
}
return "";
}
protected:
QByteArray name_;
QList<QPair<QByteArray, std::function<void()>>> tests_;
QString last_log_;
};
//############## helper functions ##################
inline QByteArray name(QString filename)
{
return QFileInfo(filename).fileName().toUtf8();
}
inline QByteArray number(int num)
{
return QByteArray::number(num);
}
inline bool eq(int a, int e)
{
return a==e;
}
inline bool eq(double a, double e)
{
return fabs(a-e)<0.00001;
}
inline bool eq(QString a, QString e)
{
return a==e;
}
inline QByteArray findTestDataFile(QByteArray test_cpp_file, QByteArray testfile)
{
QByteArray test_cpp_file_original = test_cpp_file;
//current path is 'bin/' folder
QByteArray root_folder = QFileInfo(QDir::currentPath()).absolutePath().toUtf8();
QByteArray final_path;
//make CPP file an absolute path (in some compilers __FILE__ is relative to the build folder, which in turn depends on the Qt version)
if (QFileInfo(test_cpp_file).isRelative())
{
//normalize CPP file path
test_cpp_file = test_cpp_file.replace("\\", "/");
test_cpp_file = test_cpp_file.replace("//", "/");
//strip '../' from the start until the path is relative to the src/ folder
while(!QFile::exists(root_folder + "/src/" + test_cpp_file) && test_cpp_file.startsWith("../"))
{
test_cpp_file = test_cpp_file.mid(3);
}
test_cpp_file = root_folder + "/src/" + test_cpp_file;
}
final_path = QFileInfo(test_cpp_file).absolutePath().toUtf8() + "/" + testfile;
if (!QFile::exists(final_path)) THROW(ProgrammingException, "Could not find test file '" + testfile + "' relative to '"+test_cpp_file_original+"'. It's not at: " + final_path);
return final_path;
}
//################## status variables ####################
inline bool& skipped()
{
static bool skipped = false;
return skipped;
}
inline bool& failed()
{
static bool failed = false;
return failed;
}
inline QByteArray& message()
{
static QByteArray message;
return message;
}
//############### test execution ##################
inline QList<TestExecutor*>& testList()
{
static QList<TestExecutor*> list;
return list;
}
inline void addTest(TestExecutor* test)
{
QList<TestExecutor*>& list = testList();
foreach (TestExecutor* test2, list)
{
if (test2->name()==test->name()) return;
}
list.append(test);
}
inline int run(int argc, char *argv[])
{
qputenv("QT_QPA_FONTDIR", "."); // prevents errors from QFontDatabase
qputenv("QT_QPA_PLATFORM", "offscreen"); // handles headless mode for testing plots
//create a QApplication to be able to use a event loop (e.g. for XML validation)
QApplication core_app(argc, argv);
//parse command line parameters
QCommandLineParser parser;
parser.addOption(QCommandLineOption("s", "Test case string filter for test cases.", "s"));
parser.addOption(QCommandLineOption("l", "Test case list to execute.", "l"));
parser.addOption(QCommandLineOption("d", "Enable debug output."));
parser.addHelpOption();
parser.process(core_app);
QByteArray s_filter = parser.value("s").toUtf8();
QStringList l_filter;
if (parser.value("l")!="")
{
try
{
l_filter = Helper::loadTextFile(parser.value("l"), true, '#', true);
}
catch(Exception e)
{
qDebug() << "Error loading filter list " << parser.value("l");
qDebug() << e.message();
return -1;
}
}
bool debug_output = parser.isSet("d");
//create folder for test output data
QDir(".").mkdir("out");
//open output stream
QFile outstream;
outstream.open(stdout, QFile::WriteOnly);
//run tests
QElapsedTimer timer_all;
timer_all.start();
QElapsedTimer timer;
int c_failed = 0;
int c_skipped = 0;
int c_passed = 0;
foreach (TestExecutor* test, testList())
{
QByteArray test_name = test->name();
//delete output files of previous test runs
QStringList old_files = Helper::findFiles("out/", test_name.left(test_name.length()-5)+"*.*", false);
foreach(QString old_file, old_files)
{
QFileInfo file_info(old_file);
if(file_info.isFile() && file_info.exists())
{
QFile::remove(old_file);
}
}
for (int i=0; i<test->testCount(); ++i)
{
std::function<void()> method = test->method(i);
QByteArray method_name = test->methodName(i);
QByteArray test_and_method = test_name + "::" + method_name;
//string filter
if (!test_and_method.contains(s_filter))
{
continue;
}
//test list filter
if (!l_filter.isEmpty())
{
bool found = false;
foreach(QString filter, l_filter)
{
if (test_and_method+"()"==filter || test_and_method==filter)
{
found = true;
}
}
if (!found) continue;
}
//execute test
skipped() = false;
failed() = false;
message() = "";
timer.restart();
try
{
if (debug_output)
{
outstream.write("Performing " + test_name + ":" + method_name + "\n");
outstream.flush();
}
method();
}
catch (Exception& e)
{
QByteArray msg;
msg += "exception: Exception (cppCORE)\n";
msg += "location : " + name(e.file()) + ":" + QByteArray::number(e.line()) + "\n";
msg += "message : " + e.message().toUtf8() + "\n";
message() = msg;
failed() = true;
}
catch (std::exception& e)
{
QByteArray msg;
msg += "exception: std::exception\n";
msg += "message : " + QByteArray(e.what()) + "\n";
message() = msg;
failed() = true;
}
catch (...)
{
message() = "unknown exception";
failed() = true;
}
//evaluate what happened
QByteArray result;
if (failed())
{
result = "FAIL!";
++c_failed;
}
else if(skipped())
{
result = "SKIP";
++c_skipped;
}
else
{
result = "PASS";
++c_passed;
}
//output
outstream.write(result + "\t" + test_and_method + "()\t" + Helper::elapsedTime(timer, true) + "\n");
if (!message().isEmpty())
{
QList<QByteArray> parts = message().trimmed().split('\n');
foreach(QByteArray part, parts)
{
outstream.write(" " + part.trimmed() + "\n");
}
}
outstream.flush();
}
}
outstream.write("\n");
outstream.write("PASSED : " + QByteArray::number(c_passed).rightJustified(3, ' ') + "\n");
outstream.write("SKIPPED: " + QByteArray::number(c_skipped).rightJustified(3, ' ') + "\n");
outstream.write("FAILED : " + QByteArray::number(c_failed).rightJustified(3, ' ') + "\n");
outstream.write("TIME : " + Helper::elapsedTime(timer_all, true) + "\n");
outstream.close();
return c_failed;
}
/**
* @brief comareFiles
* Compares files line by line to check if they are identical, but uses a delta to check numerics
* @param actual
* @param expected
* @param delta How much absolute deviation should be allowed for numeric values. If delta is 0 then it will not be considered.
* @param delta_is_percentage If 'true', the delta is interpreted as percentage in the range [0-100] instead of as absolute value.
* @return empty string on success, otherwise return the diff
*/
inline QString comareFiles(QString actual, QString expected, double delta, bool delta_is_percentage, char separator)
{
actual = QFileInfo(actual).absoluteFilePath();
expected = QFileInfo(expected).absoluteFilePath();
//open files
VersatileFile astream(actual);
astream.open();
VersatileFile estream(expected);
estream.open();
//compare lines
int line_nr = 1;
while (!astream.atEnd() && !estream.atEnd())
{
QString aline = astream.readLine(true);
QString eline = estream.readLine(true);
if(aline!=eline)
{
//not delta allowed > no numeric comparison
if (delta == 0.0)
{
return "Differing line " + QByteArray::number(line_nr) + "\nactual : " + aline + "\nexpected : " + eline;
}
//numeric comparison
QStringList a_line_items = aline.split(separator);
QStringList e_line_items = eline.split(separator);
if (a_line_items.size() != e_line_items.size())
{
return "Differing line " + QByteArray::number(line_nr) + " (different token count)\nactual : " + aline + "\nexpected : " + eline;
}
for (int i=0; i<a_line_items.size(); ++i)
{
if (a_line_items[i]!=e_line_items[i])
{
bool a_item_is_numeric;
float a_line_value = a_line_items[i].toFloat(&a_item_is_numeric);
bool e_item_is_numeric;
float e_line_value = e_line_items[i].toFloat(&e_item_is_numeric);
if (!a_item_is_numeric || !e_item_is_numeric)
{
return "Differing line " + QByteArray::number(line_nr) + " (non-numeric difference)\nactual : " + aline + "\nexpected : " + eline;
}
double abs_diff = fabs(a_line_value-e_line_value);
if (delta_is_percentage)
{
double rel_diff = fabs(a_line_value-e_line_value)/e_line_value;
if (rel_diff > delta/100.0)
{
return "Differing numeric value in line " + QByteArray::number(line_nr) + " (relative difference too big)\nactual : " + QString::number(a_line_value) + "\nexpected : " + QString::number(e_line_value) + "\ndelta rel: " + QString::number(rel_diff, 'g', 4);
}
}
else
{
if (abs_diff > delta)
{
return "Differing numeric value in line " + QByteArray::number(line_nr) + " (absolute difference too big)\nactual : " + QString::number(a_line_value) + "\nexpected : " + QString::number(e_line_value)+ "\ndelta abs: " + QString::number(abs_diff, 'g', 4);
}
}
}
}
}
++line_nr;
}
//compare rest (ignore lines containing only whitespaces)
QString arest = astream.readAll().trimmed();
if (!arest.isEmpty()) return "Actual file '" + actual + "' contains more data than expected file '" + expected + "': " + arest;
QString erest = estream.readAll().trimmed();
if (!erest.isEmpty()) return "Expected file '" + expected + "' contains more data than actual file '" + actual + "': " + erest;
return "";
}
/**
* @brief comparePngFiles
* Compares two PNG images pixel by pixel using normalized RGB distance,
* optionally ignoring pixels where both images match the specified ignored_color.
* Returns an empty string if the similarity score meets the cutoff threshold;
* otherwise returns an error message with the calculated similarity.
* @param actual
* @param expected
* @param cutoff
* @return empty string on success, otherwise return a message saying how much the images are different (value between 0 and 1)
*/
inline QString comarePngFiles(QString actual, QString expected, double cutoff, QColor ignored_color)
{
QImage actual_image(actual);
QImage expected_image(expected);
if (actual_image.isNull() || expected_image.isNull()) THROW(FileAccessException, "Failed to load one or both images.");
if (actual_image.size() != expected_image.size()) return "Images have different dimentions";
actual_image = actual_image.convertToFormat(QImage::Format_RGB32);
expected_image = expected_image.convertToFormat(QImage::Format_RGB32);
const int width = actual_image.width();
const int height = actual_image.height();
double squared_distance = 0.0;
int compared_pixels = 0;
for (int y=0; y<height; y++)
{
QRgb* line_actual = reinterpret_cast<QRgb*>(actual_image.scanLine(y));
QRgb* line_expected = reinterpret_cast<QRgb*>(expected_image.scanLine(y));
for (int x=0; x<width; x++)
{
QColor color_actual(line_actual[x]);
QColor color_expected(line_expected[x]);
// Ignore pixels, if both are ignored_color
if (color_actual == ignored_color && color_expected == ignored_color) continue;
//calculate squared distance
int dr = qRed(line_actual[x]) - qRed(line_expected[x]);
int dg = qGreen(line_actual[x]) - qGreen(line_expected[x]);
int db = qBlue(line_actual[x]) - qBlue(line_expected[x]);
squared_distance += dr * dr + dg * dg + db * db;
//count used pixels
compared_pixels++;
}
}
if (compared_pixels == 0) return ""; // ignored all pixels => identical images
double similarity = 1.0 - (squared_distance / (compared_pixels*3.0 * 255.0 * 255.0));
if (similarity < cutoff)
return "The similarity score for the images is insufficient: got "
+ QString::number(similarity)
+ ", but expected at least "
+ QString::number(cutoff);
return "";
}
inline QString removeLinesMatching(QString filename, QRegularExpression regexp)
{
QFile file(filename);
QList<QByteArray> output;
//read input
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return "Could not open file '" + filename + " for reading!";
while(!file.atEnd())
{
QByteArray line = file.readLine();
if (regexp.match(line).hasMatch()) continue;
output.append(line);
}
file.close();
//store output
if (!file.open(QIODevice::WriteOnly)) return "Could not open file '" + filename + " for writing!";
foreach(const QByteArray& line, output)
{
file.write(line);
}
file.close();
return "";
}
/// Helper class to create a test instance and add it to the test list
template <class T>
class TestCreator
{
public:
TestCreator(QByteArray name)
{
//check name
if (!name.endsWith("_Test"))
{
qDebug() << "Test name must end with '_Test', but does not: " + name;
}
//add tests
TestExecutor* inst = new T();
inst->setName(name);
addTest(inst);
}
};
} //namespace
#define TEST_CLASS(className) \
class className; \
using TestClassType = className; \
static TFW::TestCreator<className> t(#className); \
class className : public TFW::TestExecutor
#define TEST_METHOD(methodName) \
struct Register_##methodName { \
Register_##methodName(TestClassType* obj) { \
obj->tests_.push_back({#methodName, [obj]{ obj->methodName(); }}); \
} \
} reg_##methodName{this}; \
void methodName()
#define SKIP(msg)\
{\
TFW::skipped() = true;\
TFW::message() = QByteArray("message : ") + #msg + "\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
//##################### simple comparison macros #####################
#define IS_TRUE(stmt)\
if ((stmt)==false)\
{\
TFW::failed() = true;\
TFW::message() = "IS_TRUE(" + QByteArray(#stmt) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define IS_FALSE(stmt)\
if ((stmt)==true)\
{\
TFW::failed() = true;\
TFW::message() = "IS_FALSE(" + QByteArray(#stmt) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define I_EQUAL(actual, expected)\
if (actual!=expected)\
{\
TFW::failed() = true;\
TFW::message() = "I_EQUAL(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "actual : " + QByteArray::number((qlonglong)actual) + "\n"\
+ "expected : " + QByteArray::number((qlonglong)expected) + "\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define F_EQUAL(actual, expected)\
if (fabs(actual-expected)>0.00000001)\
{\
TFW::failed() = true;\
TFW::message() = "F_EQUAL(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "actual : " + QByteArray::number(actual) + "\n"\
+ "expected : " + QByteArray::number(expected) + "\n"\
+ "max delta: " + QByteArray::number(0.00000001) + "\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define F_EQUAL2(actual, expected, delta)\
if (fabs(actual-expected)>delta)\
{\
TFW::failed() = true;\
TFW::message() = "F_EQUAL2(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "actual : " + QByteArray::number(actual) + "\n"\
+ "expected : " + QByteArray::number(expected) + "\n"\
+ "max delta: " + QByteArray::number(delta) + "\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define S_EQUAL(actual, expected)\
if (QString(actual)!=QString(expected))\
{\
TFW::failed() = true;\
TFW::message() = "S_EQUAL(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "actual : " + QString(actual).toUtf8() + "\n"\
+ "expected : " + QString(expected).toUtf8() + "\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define X_EQUAL(actual, expected)\
if (!(actual==expected))\
{\
TFW::failed() = true;\
TFW::message() = "X_EQUAL(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__);\
return;\
}
#define IS_THROWN(exception_type, command)\
{\
bool thrown = false;\
bool right = false;\
try{ command; } catch( exception_type e) { thrown=true; right=true; } catch(...) { thrown=true; } \
if (!thrown)\
{\
TFW::failed() = true;\
TFW::message() = "IS_THROWN(" + QByteArray(#exception_type) + ", " + QByteArray(#command) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : no exception thrown";\
return;\
}\
if (!right)\
{\
TFW::failed() = true;\
TFW::message() = "IS_THROWN(" + QByteArray(#exception_type) + ", " + QByteArray(#command) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : exception thrown, but not a '" + QByteArray(#exception_type) + "'";\
return;\
}\
}
//##################### tool execution and file comparison macros #####################
#define EXECUTE(toolname, arguments) \
{\
QString tfw_result = executeTool(toolname, arguments, false, __FILE__, __LINE__);\
if (tfw_result!="")\
{\
TFW::failed() = true;\
TFW::message() = "EXECUTE(" + QByteArray(#toolname) + ", " + QByteArray(#arguments) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : " + tfw_result.toUtf8();\
return;\
}\
}
//Allows execute without propagating the error. Doesn't check for/enforce return code 1.
#define EXECUTE_FAIL(toolname, arguments) \
{\
QString tfw_result = executeTool(toolname, arguments, true, __FILE__, __LINE__);\
if (tfw_result!="")\
{\
TFW::failed() = true;\
TFW::message() = "EXECUTE_FAIL(" + QByteArray(#toolname) + ", " + QByteArray(#arguments) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : " + tfw_result.toUtf8();\
return;\
}\
}
#define COMPARE_FILES(actual, expected)\
{\
QString tfw_result = TFW::comareFiles(actual, expected, 0.0, true, '\t');\
if (tfw_result!="")\
{\
TFW::failed() = true;\
TFW::message() = "COMPARE_FILES(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : " + tfw_result.toUtf8();\
return;\
}\
}
#define COMPARE_PNG_FILES(actual, expected, cutoff, ignored_color)\
{\
QString tfw_result = TFW::comarePngFiles(actual, expected, cutoff, ignored_color);\
if (tfw_result!="")\
{\
TFW::failed() = true;\
TFW::message() = "COMPARE_PNG_FILES(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : " + tfw_result.toUtf8();\
return;\
}\
}
#define COMPARE_FILES_DELTA(actual, expected, delta, delta_is_percentage, separator)\
{\
QString tfw_result = TFW::comareFiles(actual, expected, delta, delta_is_percentage, separator);\
if (tfw_result!="")\
{\
TFW::failed() = true;\
TFW::message() = "COMPARE_FILES_DELTA(" + QByteArray(#actual) + ", " + QByteArray(#expected) + ", " + QByteArray(#delta) + ", " + QByteArray(#delta_is_percentage) + ", " + QByteArray(#separator) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : " + tfw_result.toUtf8();\
return;\
}\
}
#define REMOVE_LINES(filename, regexp)\
{\
QString tfw_result = TFW::removeLinesMatching(filename, regexp);\
if (tfw_result!="")\
{\
TFW::failed() = true;\
TFW::message() = "REMOVE_LINES(" + QByteArray(#filename) + ", " + QByteArray(#regexp) + ") failed\n"\
+ "location : " + TFW::name(__FILE__) + ":" + TFW::number(__LINE__) + "\n"\
+ "message : " + tfw_result.toUtf8();\
return;\
}\
}
#define TESTDATA(filename)\
TFW::findTestDataFile(__FILE__, filename)
#endif // TESTFRAMEWORK_H