tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / editeng / qa / lookuptree / lookuptree_test.cxx
blobbdad1418ca213e255f57c3fa8c84ef4b489310f8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 namespace {
28 class LookupTreeTest : public CppUnit::TestFixture
30 public:
31 void testTrie();
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()
44 editeng::Trie trie;
45 std::vector<OUString> suggestions;
47 trie.findSuggestions( u"", suggestions);
48 CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
50 trie.insert( u"" );
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] );
63 suggestions.clear();
65 trie.findSuggestions( u"abc", suggestions);
66 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
67 CPPUNIT_ASSERT_EQUAL( u"abcdefghijklmnopqrstuvwxyz"_ustr, suggestions[0] );
68 suggestions.clear();
70 trie.findSuggestions( u"abe", suggestions);
71 CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
72 suggestions.clear();
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] );
80 suggestions.clear();
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] );
87 suggestions.clear();
89 trie.insert( u"H1" );
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] );
94 suggestions.clear();
96 trie.findSuggestions( u"H3", suggestions);
97 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
98 CPPUNIT_ASSERT_EQUAL( u"H31l0"_ustr, suggestions[0] );
99 suggestions.clear();
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] );
107 suggestions.clear();
109 trie.findSuggestions( u"H3", suggestions );
110 CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
111 CPPUNIT_ASSERT_EQUAL( u"H31l0"_ustr, suggestions[0] );
112 suggestions.clear();
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] );
117 suggestions.clear();
119 trie.findSuggestions( u"", suggestions);
120 CPPUNIT_ASSERT_EQUAL( size_t(6), suggestions.size() );
121 suggestions.clear();
124 void LookupTreeTest::testTrieGetAllEntries()
126 editeng::Trie trie;
128 CPPUNIT_ASSERT_EQUAL( size_t(0), trie.size() );
130 trie.insert(u"A");
131 CPPUNIT_ASSERT_EQUAL( size_t(1), trie.size() );
133 trie.insert(u"B");
134 trie.insert(u"C");
135 CPPUNIT_ASSERT_EQUAL( size_t(3), trie.size() );
137 trie.insert(u"AA");
138 trie.insert(u"AAA");
139 CPPUNIT_ASSERT_EQUAL( size_t(5), trie.size() );
142 } // namespace end
144 CPPUNIT_PLUGIN_IMPLEMENT();
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */