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( u
"", suggestions
);
48 CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions
.size() );
51 trie
.findSuggestions( u
"", suggestions
);
52 CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions
.size() );
54 trie
.findSuggestions( u
"a", suggestions
);
55 CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions
.size() );
57 trie
.insert( u
"abc" );
58 trie
.insert( u
"abcdefghijklmnopqrstuvwxyz" );
59 trie
.findSuggestions( u
"a", suggestions
);
60 CPPUNIT_ASSERT_EQUAL( size_t(2), suggestions
.size() );
61 CPPUNIT_ASSERT_EQUAL( u
"abc"_ustr
, suggestions
[0] );
62 CPPUNIT_ASSERT_EQUAL( u
"abcdefghijklmnopqrstuvwxyz"_ustr
, suggestions
[1] );
65 trie
.findSuggestions( u
"abc", suggestions
);
66 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions
.size() );
67 CPPUNIT_ASSERT_EQUAL( u
"abcdefghijklmnopqrstuvwxyz"_ustr
, suggestions
[0] );
70 trie
.findSuggestions( u
"abe", suggestions
);
71 CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions
.size() );
74 trie
.insert( u
"abe" );
75 trie
.findSuggestions( u
"", suggestions
);
76 CPPUNIT_ASSERT_EQUAL( size_t(3), suggestions
.size() );
77 CPPUNIT_ASSERT_EQUAL( u
"abc"_ustr
, suggestions
[0] );
78 CPPUNIT_ASSERT_EQUAL( u
"abcdefghijklmnopqrstuvwxyz"_ustr
, suggestions
[1] );
79 CPPUNIT_ASSERT_EQUAL( u
"abe"_ustr
, suggestions
[2] );
82 trie
.insert( u
"H31l0" );
83 trie
.findSuggestions( u
"H", suggestions
);
85 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions
.size() );
86 CPPUNIT_ASSERT_EQUAL( u
"H31l0"_ustr
, suggestions
[0] );
90 trie
.findSuggestions( u
"H", suggestions
);
91 CPPUNIT_ASSERT_EQUAL( size_t(2), suggestions
.size() );
92 CPPUNIT_ASSERT_EQUAL( u
"H31l0"_ustr
, suggestions
[0] );
93 CPPUNIT_ASSERT_EQUAL( u
"H1"_ustr
, suggestions
[1] );
96 trie
.findSuggestions( u
"H3", suggestions
);
97 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions
.size() );
98 CPPUNIT_ASSERT_EQUAL( u
"H31l0"_ustr
, suggestions
[0] );
101 trie
.insert( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8
) );
102 trie
.findSuggestions( u
"H", suggestions
);
103 CPPUNIT_ASSERT_EQUAL( size_t(3), suggestions
.size() );
104 CPPUNIT_ASSERT_EQUAL( u
"H31l0"_ustr
, suggestions
[0] );
105 CPPUNIT_ASSERT_EQUAL( u
"H1"_ustr
, suggestions
[1] );
106 CPPUNIT_ASSERT_EQUAL( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8
), suggestions
[2] );
109 trie
.findSuggestions( u
"H3", suggestions
);
110 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions
.size() );
111 CPPUNIT_ASSERT_EQUAL( u
"H31l0"_ustr
, 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( u
"", suggestions
);
120 CPPUNIT_ASSERT_EQUAL( size_t(6), suggestions
.size() );
124 void LookupTreeTest::testTrieGetAllEntries()
128 CPPUNIT_ASSERT_EQUAL( size_t(0), trie
.size() );
131 CPPUNIT_ASSERT_EQUAL( size_t(1), trie
.size() );
135 CPPUNIT_ASSERT_EQUAL( size_t(3), trie
.size() );
139 CPPUNIT_ASSERT_EQUAL( size_t(5), trie
.size() );
144 CPPUNIT_PLUGIN_IMPLEMENT();
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */