Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/types.h>
21 : #include <cppunit/TestFixture.h>
22 : #include <cppunit/extensions/HelperMacros.h>
23 : #include <cppunit/plugin/TestPlugIn.h>
24 :
25 : #include <editeng/LookupTree.hxx>
26 : #include <editeng/LatinLookupTree.hxx>
27 :
28 : namespace {
29 :
30 3 : class LookupTreeTest : public CppUnit::TestFixture
31 : {
32 : public:
33 : void test();
34 :
35 2 : CPPUNIT_TEST_SUITE(LookupTreeTest);
36 1 : CPPUNIT_TEST(test);
37 2 : CPPUNIT_TEST_SUITE_END();
38 : };
39 :
40 1 : CPPUNIT_TEST_SUITE_REGISTRATION(LookupTreeTest);
41 :
42 1 : void LookupTreeTest::test()
43 : {
44 1 : LookupTree* a = new LatinLookupTree( "a" );
45 :
46 1 : a->insert( OUString("vorschlagnummer1"), 2 );
47 1 : a->insert( OUString("vorschlagnummer12") );
48 1 : a->insert( OUString("vorschlagnummer2") );
49 :
50 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer1"), a->suggestAutoCompletion() );
51 :
52 1 : a->insert( OUString("vorschlagnummer12") );
53 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
54 :
55 1 : a->insert( OUString("vorschlagnummer2") );
56 1 : a->insert( OUString("vorschlagnummer2") );
57 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer2"), a->suggestAutoCompletion() );
58 :
59 1 : a->insert( OUString("vorschlag"), 15 );
60 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
61 :
62 1 : a->insert( OUString("vorschlagnummer2"), 16 );
63 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer2"), a->suggestAutoCompletion() );
64 :
65 1 : a->remove( OUString("vorschlagnummer2") );
66 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
67 :
68 1 : a->insert( OUString("vorschlag20"), 20 );
69 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag20"), a->suggestAutoCompletion() );
70 :
71 1 : a->remove( OUString("vorschlag20") );
72 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
73 :
74 1 : a->insert( OUString("vorschlagn"), 14 );
75 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
76 :
77 1 : a->remove( OUString("vorschlag") );
78 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagn"), a->suggestAutoCompletion() );
79 :
80 1 : a->remove( OUString("vorschlagn") );
81 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
82 :
83 1 : a->insert( OUString("aber"), 1 );
84 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
85 :
86 1 : a->advance( 'a' );
87 1 : CPPUNIT_ASSERT_EQUAL( OUString("ber"), a->suggestAutoCompletion() );
88 :
89 1 : a->goBack();
90 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
91 :
92 1 : a->insert( OUString("vorschlag"), 15 );
93 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
94 :
95 1 : a->insert( OUString("vorschlag13"), 13 );
96 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
97 :
98 1 : a->gotoNode( "vorsch" );
99 1 : CPPUNIT_ASSERT_EQUAL( OUString("lag"), a->suggestAutoCompletion() );
100 :
101 1 : a->advance( 'l' );
102 1 : CPPUNIT_ASSERT_EQUAL( OUString("ag"), a->suggestAutoCompletion() );
103 :
104 1 : a->advance( 'a' );
105 1 : CPPUNIT_ASSERT_EQUAL( OUString("g13"), a->suggestAutoCompletion() );
106 :
107 1 : a->advance( 'g' );
108 1 : CPPUNIT_ASSERT_EQUAL( OUString("13"), a->suggestAutoCompletion() );
109 :
110 1 : a->advance( '1' );
111 1 : CPPUNIT_ASSERT_EQUAL( OUString("3"), a->suggestAutoCompletion() );
112 :
113 1 : a->advance( '3' );
114 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
115 :
116 1 : a->goBack();
117 1 : a->advance( 'z' );
118 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
119 :
120 : /*a->gotoNode( "vorschlag13" );
121 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
122 :
123 : a->advance( 'g' );
124 : a->advance( '1' );
125 : a->advance( '3' );
126 : a->remove( "vorschlag13" );
127 : CPPUNIT_ASSERT_EQUAL( OUString(""), a->suggestAutoCompletion() );*/
128 :
129 1 : a->insert( "VeraHatMichL1eb.", 1000000 );
130 1 : a->returnToRoot();
131 1 : CPPUNIT_ASSERT_EQUAL( OUString("VeraHatMichL1eb."), a->suggestAutoCompletion() );
132 :
133 1 : a->remove( "VeraHatMichL1eb." );
134 1 : a->gotoNode( "VeraHatMich" );
135 1 : CPPUNIT_ASSERT_EQUAL( OUString(""), a->suggestAutoCompletion() );
136 :
137 1 : a->returnToRoot();
138 1 : CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
139 :
140 1 : a->gotoNode( "VeraLiebtMich" );
141 1 : a->insert( 600 );
142 1 : a->returnToRoot();
143 1 : CPPUNIT_ASSERT_EQUAL( OUString("VeraLiebtMich"), a->suggestAutoCompletion() );
144 :
145 1 : a->insert( "VeraHatMichL1eb.", 1000000 );
146 1 : a->returnToRoot();
147 1 : CPPUNIT_ASSERT_EQUAL( OUString("VeraHatMichL1eb."), a->suggestAutoCompletion() );
148 :
149 1 : a->remove( "VeraHatMichL1eb." );
150 1 : a->gotoNode( "VeraHatMich" );
151 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
152 :
153 1 : a->advance( 'L' );
154 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
155 :
156 1 : a->insert( "VeraHatMichL1eb.", 1000000 );
157 1 : a->returnToRoot();
158 1 : a->remove( "VeraHatMichL1eb." );
159 1 : a->gotoNode( "VeraHatMich" );
160 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
161 :
162 1 : a->goBack();
163 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
164 :
165 1 : a->insert( "VeraHatMichL1eb.", 1000000 );
166 1 : a->returnToRoot();
167 1 : a->remove( "VeraHatMichL1eb." );
168 1 : a->gotoNode( "VeraHatMich" );
169 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
170 :
171 1 : a->goBack();
172 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
173 :
174 1 : a->insert( "neu", 2000 );
175 1 : a->returnToRoot();
176 1 : CPPUNIT_ASSERT_EQUAL( OUString("neu"), a->suggestAutoCompletion() );
177 :
178 1 : a->gotoNode( "ne" );
179 1 : CPPUNIT_ASSERT_EQUAL( OUString("u"), a->suggestAutoCompletion() );
180 :
181 1 : a->advance( sal_Unicode('u') );
182 1 : a->advance( sal_Unicode('e') );
183 1 : a->advance( sal_Unicode('r') );
184 1 : a->insert();
185 1 : CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
186 :
187 1 : a->returnToRoot();
188 1 : CPPUNIT_ASSERT_EQUAL( OUString("neu"), a->suggestAutoCompletion() );
189 :
190 1 : a->advance( 'n' );
191 1 : CPPUNIT_ASSERT_EQUAL( OUString("eu"), a->suggestAutoCompletion() );
192 :
193 1 : a->advance( 'e' );
194 1 : CPPUNIT_ASSERT_EQUAL( OUString("uer"), a->suggestAutoCompletion() );
195 :
196 : // Test unicode
197 1 : OUString aQueryString = rtl::OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 );
198 1 : a->insert( aQueryString );
199 1 : a->returnToRoot();
200 1 : a->advance( sal_Unicode('H') );
201 :
202 1 : OUString aAutocompletedString = a->suggestAutoCompletion();
203 1 : OUString aExpectedString = rtl::OStringToOUString( "\xC3\xA4llo", RTL_TEXTENCODING_UTF8 );
204 :
205 1 : CPPUNIT_ASSERT_EQUAL( aExpectedString, aAutocompletedString );
206 :
207 1 : OString aUtf8String( "\xe3\x81\x82\xe3\x81\x97\xe3\x81\x9f" );
208 1 : aQueryString = rtl::OStringToOUString( aUtf8String, RTL_TEXTENCODING_UTF8 );
209 1 : a->insert( aQueryString );
210 :
211 1 : OUString aGotoString = rtl::OStringToOUString( "\xe3\x81\x82", RTL_TEXTENCODING_UTF8 );
212 1 : a->gotoNode( aGotoString );
213 :
214 1 : aAutocompletedString = a->suggestAutoCompletion();
215 1 : aExpectedString = rtl::OStringToOUString( "\xe3\x81\x97\xe3\x81\x9f", RTL_TEXTENCODING_UTF8 );
216 1 : CPPUNIT_ASSERT_EQUAL( aExpectedString, aAutocompletedString );
217 :
218 1 : delete a;
219 1 : }
220 :
221 : } // namespace end
222 :
223 4 : CPPUNIT_PLUGIN_IMPLEMENT();
224 :
225 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|