TestCAPI.cpp
7.05 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* File: TestCAPI.cpp
* Author: lennyn
*
* Created on Jun 27, 2014, 12:49:12 PM
*/
#include "TestCAPI.hpp"
#include <string>
#include <iostream>
#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() {
cerr << "testTwoSimpleInvocations" << endl;
char* text = const_cast<char*> (string("AAaaBBbbCCcc DDDD.").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("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() {
cerr << "testWhitespaceKEEP" << endl;
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() {
cerr << "testWhitespaceAPPEND" << endl;
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));
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(-1, results[2].p);
}
void TestCAPI::testEncodingUTF8() {
cerr << "testEncodingUTF8" << endl;
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() {
cerr << "testTokenNumberingCONTINUOUS" << endl;
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() {
cerr << "testEncodingISO8859_2" << endl;
CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_ISO8859_2));
}
void TestCAPI::testEncodingCP1250() {
cerr << "testEncodingCP1250" << endl;
CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP1250));
}
void TestCAPI::testEncodingCP852() {
cerr << "testEncodingCP852" << endl;
CPPUNIT_ASSERT_EQUAL(1, morfeusz_set_option(MORFOPT_ENCODING, MORFEUSZ_CP852));
}
void TestCAPI::testWrongWhitespaceOption() {
cerr << "testWrongWhitespaceOption" << endl;
CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_WHITESPACE, 666777));
}
void TestCAPI::testWrongEncodingOption() {
cerr << "testWrongEncodingOption" << endl;
CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_ENCODING, 666777));
}
void TestCAPI::testWrongCaseOption() {
cerr << "testWrongCaseOption" << endl;
CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_CASE, 666777));
}
void TestCAPI::testWrongTokenNumberingOption() {
cerr << "testWrongTokenNumberingOption" << endl;
CPPUNIT_ASSERT_EQUAL(0, morfeusz_set_option(MORFOPT_TOKEN_NUMBERING, 666777));
}