serviceTester.cpp
2.98 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
#include "serviceTester.h"
ServiceTester::serviceTester(int _language, int _position, int _size, int _background) {
language = _language;
position = _position;
size = _size;
background = _background;
msgErr = "";
finish = false;
fail = false;
printl(util::_DEBUG, "Done!\n");
}
ServiceTester::~serviceTester() {
printl(util::_DEBUG, "ServiceTester Finalized!\n");
}
void ServiceTester::checkServiceSRT() {
service_srt = new ServiceWindowGenerationFromSRT(PATH_VID, PATH_SRT, language, position, size, background, 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(PATH_VID, FILE_OUT_SRT);
if(!sucess){
msgErr += "Extração de legenda\n";
}
deleteFiles();
}
void ServiceTester::checkServiceRec() {
service_rec = new ServiceWindowGenerationFromRec(PATH_VID, position, size, background, TESTER_ID, MODE_TEST, 2);
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(PATH_VID, FILE_OUT_REC);
if(!sucess){
msgErr += "Reconhecimento\n";
}
deleteFiles();
}
void ServiceTester::checkServiceText() {
service_text = new ServiceWindowGenerationFromText(PATH_TXT, language, background, 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(PATH_TXT, FILE_OUT_TXT);
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;
}
void hasFailed() {
return fail;
}
void ServiceTester::deleteFiles() {
string command = "rm -f ";
command += OUTPUT_FILE;
system(command);
}
void ServiceTester::Run() {
printl(util::_INFO, "Verificando módulos, aguarde...\n");
checkServiceSRT();
checkServiceRec();
checkServiceText();
if(hasFailed())
throw ServiceException(msgErr);
finish = true;
}