test_result_equals_utf16.cpp
2.51 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
/*
* File: test_result_equals_utf16.cpp
* Author: lennyn
*
* Created on December 12, 2013, 12:16 PM
*/
#include <cstdlib>
#include <cassert>
using namespace std;
static MorfeuszCharset getEncoding(const string& encodingStr) {
if (encodingStr == "UTF16_BE")
return UTF16BE;
else if (encodingStr == "UTF16_LE")
return UTF16LE;
else {
cerr << "Invalid encoding: " << encodingStr << " must be one of: UTF16_BE, UTF16_LE" << endl;
assert(false);
}
}
string readFile(const char* fname) {
std::ifstream ifs;
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
ifs.open(fname, std::ios::in | std::ios::binary | std::ios::ate);
// if (ifs.is_open()) {
long size = ifs.tellg();
T* memblock = new T[size];
ifs.seekg(0, std::ios::beg);
ifs.read(reinterpret_cast<char*> (memblock), size);
ifs.close();
return memblock;
// }
// else {
// cerr << "Unable to open file " << fname << endl;
// }
}
/*
*
*/
int main(int argc, char** argv) {
validate(argc == 4, "Must provide exactly 2 or 3 arguments - input filename, required output filename, encoding.");
string inputFilename = argv[1];
ifstream in;
// in.exceptions(std::ifstream::failbit | std::ifstream::badbit);
cerr << "OPEN " << inputFilename << endl;
in.open(inputFilename);
string requiredOutputFilename = argv[2];
ifstream requiredIn;
// requiredIn.exceptions(std::ifstream::failbit | std::ifstream::badbit);
cerr << "OPEN " << requiredOutputFilename << endl;
requiredIn.open(requiredOutputFilename);
// string requiredOutput = readFile<char>(requiredOutputFilename);
cerr << "TEST START" << endl;
Morfeusz morfeusz;
MorfeuszCharset encoding = getEncoding(argv[3]);
morfeusz.setEncoding(encoding);
string line;
while (getline(in, line)) {
cerr << "TEST " << line << endl;
vector<MorphInterpretation> res;
morfeusz.analyze(line, res);
stringstream out;
appendMorfeuszResults(res, out);
string gotOutputLine;
string requiredOutputLine;
while (getline(out, gotOutputLine)) {
getline(requiredIn, requiredOutputLine);
cerr << "REQUIRED LINE " << requiredOutputLine << endl;
cerr << "GOT LINE " << gotOutputLine << endl;
cerr << (requiredOutputLine == gotOutputLine) << endl;
validate(gotOutputLine == requiredOutputLine, "lines do not match");
}
}
return 0;
}