-
Notifications
You must be signed in to change notification settings - Fork 2
/
testset_files.cpp
58 lines (42 loc) · 1.02 KB
/
testset_files.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
#include "testset_files.h"
#include <stdio.h>
bool TestSetFiles::next(std::vector<unsigned char>& dest) {
if(currentTest != tests.end())
++currentTest;
if(currentTest == tests.end())
return false;
dest = currentTest->data;
return true;
}
std::string TestSetFiles::description() {
return currentTest->name;
}
TestSetFiles::TestSetFiles(const std::vector<std::string>& filenames) {
std::vector<unsigned char> v;
v.clear();
tests.push_back(OneTest("you need to call next()", v));
for(std::string fname : filenames) {
v.clear();
FILE* fp = fopen(fname.c_str(), "rb");
if(fp) {
if(fseek(fp, 0, SEEK_END) == 0) {
off_t s = ftello(fp);
if(s >= 0) {
v.resize(s);
if(fseek(fp, 0, SEEK_SET) == 0) {
if(fread(&v[0], 1, s, fp) != s) {
v.clear();
}
}
}
}
fclose(fp);
}
if(v.empty()) {
printf("ERROR: could not open from, or read entirely, %s", fname.c_str());
exit(1);
}
tests.push_back(OneTest(fname.c_str(), v));
}
currentTest = tests.begin();
}