-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
45 lines (37 loc) · 995 Bytes
/
common.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
#pragma once
#include <QGuiApplication>
#include <QImage>
#include <gtest/gtest.h>
#include <filesystem>
#include <fstream>
std::string readFileStr(const std::string &fileName)
{
std::ifstream file(fileName);
if (!file.is_open()) {
std::cout << "Failed to open " + fileName << std::endl;
return "";
}
std::stringstream buffer;
buffer << file.rdbuf();
return buffer.str();
}
double fuzzyCompareImages(const QImage &a, const QImage &b)
{
if (a.size() != b.size())
return 1;
int x, y, c = 0;
for (y = 0; y < a.height(); y++) {
for (x = 0; x < a.width(); x++) {
if (a.pixelColor(x, y).rgba() != b.pixelColor(x, y).rgba())
c++;
}
}
return c / static_cast<double>((a.width() * a.height()));
}
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
std::filesystem::current_path(DATA_DIR);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}