Blame view

morfeusz/tests/TestCAPI.cpp 7.04 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
/*
 * File:   TestCAPI.cpp
 * Author: lennyn
 *
 * Created on Jun 27, 2014, 12:49:12 PM
 */

#include "TestCAPI.hpp"
#include <string>
Michał Lenart authored
10
#include <iostream>
Michał Lenart authored
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "morfeusz2_c.h"

using namespace std;


CPPUNIT_TEST_SUITE_REGISTRATION(TestCAPI);

TestCAPI::TestCAPI() {
}

TestCAPI::~TestCAPI() {
}

void TestCAPI::setUp() {
}

void TestCAPI::tearDown() {
}

void TestCAPI::testTwoSimpleInvocations() {
Michał Lenart authored
31
32
    cerr << "testTwoSimpleInvocations" << endl;
Michał Lenart authored
33
    char* text = const_cast<char*> ("AAaaBBbbCCcc DDDD.");
Michał Lenart authored
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
    InterpMorf* results = morfeusz_analyse(text);
    CPPUNIT_ASSERT_EQUAL(0, results[0].p);
    CPPUNIT_ASSERT_EQUAL(1, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string("AAaaBBbbCCcc"), string(results[0].forma));
    CPPUNIT_ASSERT_EQUAL(string("AAaaBBbbCCcc"), string(results[0].haslo));
    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[0].interp));

    CPPUNIT_ASSERT_EQUAL(1, results[1].p);
    CPPUNIT_ASSERT_EQUAL(2, results[1].k);
    CPPUNIT_ASSERT_EQUAL(string("DDDD"), string(results[1].forma));
    CPPUNIT_ASSERT_EQUAL(string("DDDD"), string(results[1].haslo));
    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[1].interp));

    CPPUNIT_ASSERT_EQUAL(2, results[2].p);
    CPPUNIT_ASSERT_EQUAL(3, results[2].k);
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[2].forma));
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[2].haslo));
    //    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[2].interp));
    CPPUNIT_ASSERT_EQUAL(-1, results[3].p);

    char* text1 = const_cast<char*> (string("EEeeFFff").c_str());
    results = morfeusz_analyse(text1);
    CPPUNIT_ASSERT_EQUAL(0, results[0].p);
    CPPUNIT_ASSERT_EQUAL(1, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string("EEeeFFff"), string(results[0].forma));
    CPPUNIT_ASSERT_EQUAL(string("EEeeFFff"), string(results[0].haslo));
    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[0].interp));

    CPPUNIT_ASSERT_EQUAL(-1, results[1].p);
}

void TestCAPI::testWhitespaceKEEP() {
Michał Lenart authored
66
67
    cerr << "testWhitespaceKEEP" << endl;
Michał Lenart authored
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

    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_WHITESPACE, MORFEUSZ_KEEP_WHITESPACE));

    char* text = const_cast<char*> (string("AAaaBBbbCCcc  .").c_str());
    InterpMorf* results = morfeusz_analyse(text);
    CPPUNIT_ASSERT_EQUAL(0, results[0].p);
    CPPUNIT_ASSERT_EQUAL(1, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string("AAaaBBbbCCcc"), string(results[0].forma));
    CPPUNIT_ASSERT_EQUAL(string("AAaaBBbbCCcc"), string(results[0].haslo));
    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[0].interp));

    CPPUNIT_ASSERT_EQUAL(1, results[1].p);
    CPPUNIT_ASSERT_EQUAL(2, results[1].k);
    CPPUNIT_ASSERT_EQUAL(string("  "), string(results[1].forma));
    CPPUNIT_ASSERT_EQUAL(string("  "), string(results[1].haslo));
    //    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[2].interp));

    CPPUNIT_ASSERT_EQUAL(2, results[2].p);
    CPPUNIT_ASSERT_EQUAL(3, results[2].k);
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[2].forma));
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[2].haslo));
    //    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[2].interp));

    CPPUNIT_ASSERT_EQUAL(-1, results[3].p);
}

void TestCAPI::testWhitespaceAPPEND() {
Michał Lenart authored
95
96
    cerr << "testWhitespaceAPPEND" << endl;
Michał Lenart authored
97
98
99
100
101
102
103
    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_WHITESPACE, MORFEUSZ_APPEND_WHITESPACE));

    char* text = const_cast<char*> (string("AAaaBBbbCCcc  .").c_str());
    InterpMorf* results = morfeusz_analyse(text);
    CPPUNIT_ASSERT_EQUAL(0, results[0].p);
    CPPUNIT_ASSERT_EQUAL(1, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string("AAaaBBbbCCcc  "), string(results[0].forma));
Michał Lenart authored
104
    CPPUNIT_ASSERT_EQUAL(string("AAaaBBbbCCcc"), string(results[0].haslo));
Michał Lenart authored
105
106
107
108
109
110
111
112
113
114
115
116
    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[0].interp));

    CPPUNIT_ASSERT_EQUAL(1, results[1].p);
    CPPUNIT_ASSERT_EQUAL(2, results[1].k);
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[1].forma));
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[1].haslo));
    //    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[2].interp));

    CPPUNIT_ASSERT_EQUAL(-1, results[2].p);
}

void TestCAPI::testEncodingUTF8() {
Michał Lenart authored
117
118
    cerr << "testEncodingUTF8" << endl;
Michał Lenart authored
119
120
121
122
123
124
125
126
127
128
129
130
131
    unsigned char text[] = {'z', 'a', /* ż */ 197, 188, /* ó */ 195, 179, '\0'};
    char* actualText = (char*) text;
    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP1250));
    InterpMorf* results = morfeusz_analyse(actualText);
    CPPUNIT_ASSERT_EQUAL(0, results[0].p);
    CPPUNIT_ASSERT_EQUAL(1, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string(actualText), string(results[0].forma));
    CPPUNIT_ASSERT_EQUAL(string(actualText), string(results[0].haslo));
    CPPUNIT_ASSERT_EQUAL(string("ign"), string(results[0].interp));
    CPPUNIT_ASSERT_EQUAL(-1, results[2].p);
}

void TestCAPI::testTokenNumberingCONTINUOUS() {
Michał Lenart authored
132
133
    cerr << "testTokenNumberingCONTINUOUS" << endl;
Michał Lenart authored
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

    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_WHITESPACE, MORFEUSZ_SKIP_WHITESPACE));
    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_TOKEN_NUMBERING, MORFEUSZ_CONTINUOUS_TOKEN_NUMBERING));

    InterpMorf* results = morfeusz_analyse(const_cast<char*>("aaaabbbb bbbbcccc."));
    CPPUNIT_ASSERT_EQUAL(0, results[0].p);
    CPPUNIT_ASSERT_EQUAL(1, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string("aaaabbbb"), string(results[0].forma));

    CPPUNIT_ASSERT_EQUAL(1, results[1].p);
    CPPUNIT_ASSERT_EQUAL(2, results[1].k);
    CPPUNIT_ASSERT_EQUAL(string("bbbbcccc"), string(results[1].forma));

    CPPUNIT_ASSERT_EQUAL(2, results[2].p);
    CPPUNIT_ASSERT_EQUAL(3, results[2].k);
    CPPUNIT_ASSERT_EQUAL(string("."), string(results[2].forma));

    CPPUNIT_ASSERT_EQUAL(-1, results[3].p);

    results = morfeusz_analyse(const_cast<char*>("ccccdddd"));
    CPPUNIT_ASSERT_EQUAL(3, results[0].p);
    CPPUNIT_ASSERT_EQUAL(4, results[0].k);
    CPPUNIT_ASSERT_EQUAL(string("ccccdddd"), string(results[0].forma));

    CPPUNIT_ASSERT_EQUAL(-1, results[1].p);
}

void TestCAPI::testEncodingISO8859_2() {
Michał Lenart authored
162
163
    cerr << "testEncodingISO8859_2" << endl;
Michał Lenart authored
164
165
166
167
    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_ISO8859_2));
}

void TestCAPI::testEncodingCP1250() {
Michał Lenart authored
168
169
    cerr << "testEncodingCP1250" << endl;
Michał Lenart authored
170
171
172
173
    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP1250));
}

void TestCAPI::testEncodingCP852() {
Michał Lenart authored
174
175
    cerr << "testEncodingCP852" << endl;
Michał Lenart authored
176
177
178
179
    CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP852));
}

void TestCAPI::testWrongWhitespaceOption() {
Michał Lenart authored
180
181
    cerr << "testWrongWhitespaceOption" << endl;
Michał Lenart authored
182
183
184
185
    CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_WHITESPACE, 666777));
}

void TestCAPI::testWrongEncodingOption() {
Michał Lenart authored
186
187
    cerr << "testWrongEncodingOption" << endl;
Michał Lenart authored
188
189
190
191
    CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_ENCODING, 666777));
}

void TestCAPI::testWrongCaseOption() {
Michał Lenart authored
192
193
    cerr << "testWrongCaseOption" << endl;
Michał Lenart authored
194
195
196
197
    CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_CASE, 666777));
}

void TestCAPI::testWrongTokenNumberingOption() {
Michał Lenart authored
198
199
    cerr << "testWrongTokenNumberingOption" << endl;
Michał Lenart authored
200
201
202
    CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_TOKEN_NUMBERING, 666777));
}