-
Notifications
You must be signed in to change notification settings - Fork 1
/
BViewQtOpenGl_gtest.cpp
118 lines (97 loc) · 3.53 KB
/
BViewQtOpenGl_gtest.cpp
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
#include "gtest/gtest.h"
#include <algorithm>
#include <iostream>
#include "bdirectory.h"
#include "bsingletoncache.h"
#include "bcache.h"
#include "fileloaderfactory.h"
#include "bmpfileloader.h"
#include "bimage.h"
#include "bimagemanager.h"
#include "brender.h"
#include "bconvolution.h"
#include "functions/imagescale.h"
#include "bfunctionmanager.h"
class JPGFile : ImageFileLoader {
public:
static ImageFileLoader * CreateInstance() {
return new JPGFile();
}
virtual void Decode(Image *) {
}
};
TEST(Matrix, Matrix) {
int a[] = { -1,0,1, -2, 0, 2, -1,0,1};
Matrix<int> m(3,3,a);
EXPECT_EQ(3, m.height);
EXPECT_EQ(3, m.width);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
EXPECT_EQ(a[i*3 + j], m.Get(i,j));
}
}
int b[] = { 1,2,3,4,5,6,7,8,9};
Matrix<int> n(3,3,b);
Matrix<int> o(n);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
EXPECT_EQ(n.Get(i,j), o.Get(i,j));
}
}
}
TEST(Convolution, Convolute) {
FileFactory<ImageFileLoader *> fileFactory;
fileFactory.AddFactory("bmp", [](){ return BMPFileLoader::CreateInstance(); });
BImageManager imageManager;
imageManager.SetFileFactory(fileFactory);
imageManager.LoadDirectory(L".");
//EdgeDetectLaplace5x5 * laplace = new EdgeDetectLaplace5x5();
//std::shared_ptr<Image> image(&imageManager.ActualImage);
//laplace->Execute(image);
//delete laplace;
}
TEST(Render, Scale) {
FileFactory<ImageFileLoader *> fileFactory;
fileFactory.AddFactory("bmp", [](){ return BMPFileLoader::CreateInstance(); });
BImageManager imageManager;
imageManager.SetFileFactory(fileFactory);
imageManager.LoadDirectory(L".");
tbb::tick_count start_serial = tbb::tick_count::now();
for (float ratio = 0.2f; ratio < 1.0f; ratio = ratio + 0.02f) {
ImageScale scaler;
std::shared_ptr<Image> renderImage = scaler.ScaleSerial(&imageManager.ActualImage, ratio);
}
tbb::tick_count stop_serial = tbb::tick_count::now();
std::cout << "Seril done, parallel start" << std::endl;
tbb::tick_count start_parallel = tbb::tick_count::now();
for (float ratio = 0.2f; ratio < 1.0f; ratio = ratio + 0.02f) {
ImageScale scaler;
scaler.ScaleParallel(&imageManager.ActualImage, ratio);
}
tbb::tick_count stop_parallel = tbb::tick_count::now();
std::cout << "Serial: " << (stop_serial - start_serial).seconds() << std::endl;
std::cout << "parallel: " << (stop_parallel - start_parallel).seconds() << std::endl;
}
TEST(Directory, Listing) {
BDirectory directory;
EXPECT_FALSE(directory.file_begin() == directory.file_end());
}
TEST(SingletonCache, OneInstance) {
typedef BSingletonCache<BCache<FileLoader *, cache_traits> > fileCache;
auto instance = fileCache::Instance();
EXPECT_EQ(instance, fileCache::Instance());
}
TEST(ImageManager, LoadImageDir) {
FileFactory<ImageFileLoader *> fileFactory;
fileFactory.AddFactory("bmp", [](){ return BMPFileLoader::CreateInstance(); });
fileFactory.AddFactory("jpg", [](){ return JPGFile::CreateInstance(); });
BImageManager imageManager;
imageManager.SetFileFactory(fileFactory);
imageManager.LoadDirectory(L".");
EXPECT_EQ(100,imageManager.ActualImage->GetHeight());
EXPECT_EQ(100,imageManager.ActualImage->GetWidth());
}
void TestAll(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
}