1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
24 #include <editeng/Trie.hxx>
28 class LookupTreeTest
: public CppUnit::TestFixture
32 void testTrieGetAllEntries();
34 CPPUNIT_TEST_SUITE(LookupTreeTest
);
35 CPPUNIT_TEST(testTrie
);
36 CPPUNIT_TEST(testTrieGetAllEntries
);
37 CPPUNIT_TEST_SUITE_END();
40 CPPUNIT_TEST_SUITE_REGISTRATION(LookupTreeTest
);
42 void LookupTreeTest::testTrie()
45 std::vector
<OUString
> suggestions
;
47 trie
.findSuggestions( OUString(), suggestions
);
48 CPPUNIT_ASSERT_EQUAL( (size_t) 0, suggestions
.size() );
50 trie
.insert( OUString() );
51 trie
.findSuggestions( OUString(), suggestions
);
52 CPPUNIT_ASSERT_EQUAL( (size_t) 0, suggestions
.size() );
54 trie
.findSuggestions( OUString("a"), suggestions
);
55 CPPUNIT_ASSERT_EQUAL( (size_t) 0, suggestions
.size() );
57 trie
.insert( OUString("abc") );
58 trie
.insert( OUString("abcdefghijklmnopqrstuvwxyz") );
59 trie
.findSuggestions( OUString("a"), suggestions
);
60 CPPUNIT_ASSERT_EQUAL( (size_t) 2, suggestions
.size() );
61 CPPUNIT_ASSERT_EQUAL( OUString("abc"), suggestions
[0] );
62 CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions
[1] );
65 trie
.findSuggestions( OUString("abc"), suggestions
);
66 CPPUNIT_ASSERT_EQUAL( (size_t) 1, suggestions
.size() );
67 CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions
[0] );
70 trie
.findSuggestions( OUString("abe"), suggestions
);
71 CPPUNIT_ASSERT_EQUAL( (size_t) 0, suggestions
.size() );
74 trie
.insert( OUString("abe") );
75 trie
.findSuggestions( OUString(""), suggestions
);
76 CPPUNIT_ASSERT_EQUAL( (size_t) 3, suggestions
.size() );
77 CPPUNIT_ASSERT_EQUAL( OUString("abc"), suggestions
[0] );
78 CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions
[1] );
79 CPPUNIT_ASSERT_EQUAL( OUString("abe"), suggestions
[2] );
82 trie
.insert( OUString("H31l0") );
83 trie
.findSuggestions( OUString("H"), suggestions
);
85 CPPUNIT_ASSERT_EQUAL( (size_t) 1, suggestions
.size() );
86 CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions
[0] );
89 trie
.insert( OUString("H1") );
90 trie
.findSuggestions( OUString("H"), suggestions
);
91 CPPUNIT_ASSERT_EQUAL( (size_t) 2, suggestions
.size() );
92 CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions
[0] );
93 CPPUNIT_ASSERT_EQUAL( OUString("H1"), suggestions
[1] );
96 trie
.findSuggestions( OUString("H3"), suggestions
);
97 CPPUNIT_ASSERT_EQUAL( (size_t) 1, suggestions
.size() );
98 CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions
[0] );
101 trie
.insert( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8
) );
102 trie
.findSuggestions( OUString("H"), suggestions
);
103 CPPUNIT_ASSERT_EQUAL( (size_t) 3, suggestions
.size() );
104 CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions
[0] );
105 CPPUNIT_ASSERT_EQUAL( OUString("H1"), suggestions
[1] );
106 CPPUNIT_ASSERT_EQUAL( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8
), suggestions
[2] );
109 trie
.findSuggestions( OUString("H3"), suggestions
);
110 CPPUNIT_ASSERT_EQUAL( (size_t) 1, suggestions
.size() );
111 CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions
[0] );
114 trie
.findSuggestions( OStringToOUString("H\xC3\xA4", RTL_TEXTENCODING_UTF8
), suggestions
);
115 CPPUNIT_ASSERT_EQUAL( (size_t) 1, suggestions
.size() );
116 CPPUNIT_ASSERT_EQUAL( OStringToOUString("H\xC3\xA4llo", RTL_TEXTENCODING_UTF8
), suggestions
[0] );
119 trie
.findSuggestions( OUString(""), suggestions
);
120 CPPUNIT_ASSERT_EQUAL( (size_t) 6, suggestions
.size() );
124 void LookupTreeTest::testTrieGetAllEntries()
128 std::vector
<OUString
> entries
;
130 trie
.getAllEntries(entries
);
131 CPPUNIT_ASSERT_EQUAL( (size_t) 0, entries
.size() );
134 trie
.getAllEntries(entries
);
135 CPPUNIT_ASSERT_EQUAL( (size_t) 1, entries
.size() );
140 trie
.getAllEntries(entries
);
141 CPPUNIT_ASSERT_EQUAL( (size_t) 3, entries
.size() );
146 trie
.getAllEntries(entries
);
147 CPPUNIT_ASSERT_EQUAL( (size_t) 5, entries
.size() );
153 CPPUNIT_PLUGIN_IMPLEMENT();
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */