serviceTester.cpp
3.77 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
#include "serviceTester.h"
ServiceTester::ServiceTester(int _position, int _size, int _background) {
if(_position != 0)
this->position = _position;
else
this->position = 3; //bottom_rigth
if(_size != 0)
this->resolution = _size;
else
this->resolution = 2; //medium
this->background = _background;
msgErr = "";
finish = false;
fail = false;
PRINTL(util::_DEBUG, "ServiceTester Done!\n");
}
ServiceTester::~ServiceTester() {
PRINTL(util::_DEBUG, "ServiceTester Finalized!\n");
}
void ServiceTester::checkServiceSRT() {
PRINTL(util::_DEBUG, "Checando extração de legenda...\n");
setPathContents();
service_srt = new ServiceWindowGenerationFromSubtitle((char*)VID_FILE, (char*)SRT_FILE, 1, position,
resolution, background, (char*)TESTER_ID, MODE_TEST, 1);
try{
service_srt->initialize();
}catch(ServiceException &ex){
msgErr += "Extração de legenda\n";
fail = true;
return;
}
while(!service_srt->isFinished())
sleep(5);
delete service_srt;
bool sucess;
sucess = checkFiles(VID_FILE, OUT_FILE);
if(!sucess){
msgErr += "Extração de legenda\n";
}
deleteFiles();
}
void ServiceTester::checkServiceRec() {
PRINTL(util::_DEBUG, "Checando reconhecimento...\n");
setPathContents();
service_rec = new ServiceWindowGenerationFromRec((char*)REC_FILE, 0, 0,
background, (char*)TESTER_ID, MODE_TEST, 6);// 6 serviço sem mixagem
try{
service_rec->initialize();
}catch(ServiceException &ex){
msgErr += "Reconhecimento\n";
fail = true;
return;
}
while(!service_rec->isFinished())
sleep(5);
delete service_rec;
bool sucess;
sucess = checkFiles(REC_FILE, OUT_FILE);
if(!sucess){
msgErr += "Reconhecimento\n";
}
deleteFiles();
}
void ServiceTester::checkServiceText() {
PRINTL(util::_DEBUG, "Checando extração de texto...\n");
setPathContents();
service_text = new ServiceWindowGenerationFromText((char*)TXT_FILE, 1, background,
(char*)TESTER_ID, MODE_TEST);
try{
service_text->initialize();
}catch(ServiceException &ex){
msgErr += "Extração de texto\n";
fail = true;
return;
}
while (!service_text->isFinished())
usleep(100000); //100ms
delete service_text;
bool sucess;
sucess = checkFiles(TXT_FILE, OUT_FILE);
if(!sucess){
msgErr += "Extração de texto\n";
}
deleteFiles();
}
bool ServiceTester::checkFiles(string fileIn, string fileOut) {
int64_t inSize;
int64_t outSize;
fIn = new lavidlib::File(fileIn);
fOut = new lavidlib::File(fileOut);
try{
fIO_in = new lavidlib::FileIO(fIn->getPath(), FileIO::MODE_READ);
fIO_out = new lavidlib::FileIO(fOut->getPath(), FileIO::MODE_READ);
}catch(Exception &ex){
delete fIn;
delete fOut;
fail = true;
return false;
}
inSize = fIO_in->getSize();
outSize = fIO_out->getSize();
delete fIn;
delete fOut;
delete fIO_in;
delete fIO_out;
if(outSize != 0 && outSize != inSize)
return true;
fail = true;
return false;
}
bool ServiceTester::isFinished(){
return this->finish;
}
bool ServiceTester::hasFailed() {
return this->fail;
}
void ServiceTester::setPathContents() {
string command = "mkdir -p ";
command.append(PATH_TEST_CONTENTS).append(" && mkdir -p ")
.append(PATH_TEST_UPLOADS).append("/").append(TESTER_ID);
system(command.c_str());
}
void ServiceTester::deleteFiles() {
string command = "rm -f ";
command.append(OUT_FILE).append(" && rm -rf ")
.append(PATH_TEST_UPLOADS).append("/").append(TESTER_ID);
system(command.c_str());
}
void ServiceTester::Run() {
PRINTL(util::_INFO, "Verificando módulos, aguarde...\n");
checkServiceText();
checkServiceSRT();
checkServiceRec();
if(hasFailed())
throw ServiceException(msgErr);
PRINTL(util::_INFO, "Não foram encontrados problemas!\n");
finish = true;
}