Blame view

morfeusz/test/test_result_equals.cpp 2.33 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
12
/* 
 * File:   test_result_equals.cpp
 * Author: lennyn
 *
 * Created on December 6, 2013, 12:45 PM
 */

#include <cstdlib>
#include <cassert>
#include <string>
#include <sstream>
#include <fstream>
Michał Lenart authored
13
#include <iostream>
Michał Lenart authored
14
#include "MorfeuszInternal.hpp"
Michał Lenart authored
15
#include "consoleUtils.hpp"
Michał Lenart authored
16
17

using namespace std;
Michał Lenart authored
18
using namespace morfeusz;
Michał Lenart authored
19
Michał Lenart authored
20
static Charset getEncoding(const string& encodingStr) {
Michał Lenart authored
21
22
23
24
    if (encodingStr == "UTF8")
        return UTF8;
    else if (encodingStr == "ISO8859_2")
        return ISO8859_2;
Michał Lenart authored
25
26
    else if (encodingStr == "CP1250")
        return CP1250;
Michał Lenart authored
27
28
    else if (encodingStr == "CP852")
        return CP852;
Michał Lenart authored
29
    else {
Michał Lenart authored
30
        cerr << "Invalid encoding: " << encodingStr << " must be one of: UTF8, ISO8859_2, WINDOWS1250" << endl;
Michał Lenart authored
31
        throw "Invalid encoding";
Michał Lenart authored
32
33
    }
}
Michał Lenart authored
34
35

int main(int argc, char** argv) {
Michał Lenart authored
36
    validate(argc == 3 || argc == 4, "Must provide exactly 2 or 3 arguments - input filename, required output filename, (optional) encoding.");
Michał Lenart authored
37
    string inputFilename = argv[1];
Michał Lenart authored
38
39
40
    ifstream in;
//    in.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    cerr << "OPEN " << inputFilename << endl;
Michał Lenart authored
41
    in.open(inputFilename.c_str());
Michał Lenart authored
42
    string requiredOutputFilename = argv[2];
Michał Lenart authored
43
44
45
    ifstream requiredIn;
//    requiredIn.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    cerr << "OPEN " << requiredOutputFilename << endl;
Michał Lenart authored
46
    requiredIn.open(requiredOutputFilename.c_str());
Michał Lenart authored
47
48
    //    string requiredOutput = readFile<char>(requiredOutputFilename);
    cerr << "TEST START" << endl;
Michał Lenart authored
49
    MorfeuszInternal morfeusz;
Michał Lenart authored
50
    if (argc == 4) {
Michał Lenart authored
51
        Charset encoding = getEncoding(argv[3]);
Michał Lenart authored
52
        morfeusz.setCharset(encoding);
Michał Lenart authored
53
    }
Michał Lenart authored
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    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;
Michał Lenart authored
68
            validate(gotOutputLine == requiredOutputLine, "lines do not match");
Michał Lenart authored
69
70
71
72
73
        }
    }
    return 0;
}