LCOV - code coverage report
Current view: top level - libreoffice/editeng/qa/lookuptree - lookuptree_test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 125 125 100.0 %
Date: 2012-12-17 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          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           6 : class LookupTreeTest : public CppUnit::TestFixture
      31             : {
      32             :     public:
      33             :         void test();
      34             : 
      35           4 :     CPPUNIT_TEST_SUITE(LookupTreeTest);
      36           2 :     CPPUNIT_TEST(test);
      37           4 :     CPPUNIT_TEST_SUITE_END();
      38             : };
      39             : 
      40           2 : CPPUNIT_TEST_SUITE_REGISTRATION(LookupTreeTest);
      41             : 
      42           2 : void LookupTreeTest::test()
      43             : {
      44           2 :     LookupTree* a = new LatinLookupTree( "a" );
      45             : 
      46           2 :     a->insert( OUString("vorschlagnummer1"), 2 );
      47           2 :     a->insert( OUString("vorschlagnummer12") );
      48           2 :     a->insert( OUString("vorschlagnummer2") );
      49             : 
      50           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer1"), a->suggestAutoCompletion() );
      51             : 
      52           2 :     a->insert( OUString("vorschlagnummer12") );
      53           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
      54             : 
      55           2 :     a->insert( OUString("vorschlagnummer2") );
      56           2 :     a->insert( OUString("vorschlagnummer2") );
      57           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer2"), a->suggestAutoCompletion() );
      58             : 
      59           2 :     a->insert( OUString("vorschlag"), 15 );
      60           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
      61             : 
      62           2 :     a->insert( OUString("vorschlagnummer2"), 16 );
      63           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer2"), a->suggestAutoCompletion() );
      64             : 
      65           2 :     a->remove( OUString("vorschlagnummer2") );
      66           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
      67             : 
      68           2 :     a->insert( OUString("vorschlag20"), 20 );
      69           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag20"), a->suggestAutoCompletion() );
      70             : 
      71           2 :     a->remove( OUString("vorschlag20") );
      72           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
      73             : 
      74           2 :     a->insert( OUString("vorschlagn"), 14 );
      75           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
      76             : 
      77           2 :     a->remove( OUString("vorschlag") );
      78           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagn"), a->suggestAutoCompletion() );
      79             : 
      80           2 :     a->remove( OUString("vorschlagn") );
      81           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
      82             : 
      83           2 :     a->insert( OUString("aber"), 1 );
      84           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
      85             : 
      86           2 :     a->advance( 'a' );
      87           2 :     CPPUNIT_ASSERT_EQUAL( OUString("ber"), a->suggestAutoCompletion() );
      88             : 
      89           2 :     a->goBack();
      90           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() );
      91             : 
      92           2 :     a->insert( OUString("vorschlag"), 15 );
      93           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
      94             : 
      95           2 :     a->insert( OUString("vorschlag13"), 13 );
      96           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
      97             : 
      98           2 :     a->gotoNode( "vorsch" );
      99           2 :     CPPUNIT_ASSERT_EQUAL( OUString("lag"), a->suggestAutoCompletion() );
     100             : 
     101           2 :     a->advance( 'l' );
     102           2 :     CPPUNIT_ASSERT_EQUAL( OUString("ag"), a->suggestAutoCompletion() );
     103             : 
     104           2 :     a->advance( 'a' );
     105           2 :     CPPUNIT_ASSERT_EQUAL( OUString("g13"), a->suggestAutoCompletion() );
     106             : 
     107           2 :     a->advance( 'g' );
     108           2 :     CPPUNIT_ASSERT_EQUAL( OUString("13"), a->suggestAutoCompletion() );
     109             : 
     110           2 :     a->advance( '1' );
     111           2 :     CPPUNIT_ASSERT_EQUAL( OUString("3"), a->suggestAutoCompletion() );
     112             : 
     113           2 :     a->advance( '3' );
     114           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     115             : 
     116           2 :     a->goBack();
     117           2 :     a->advance( 'z' );
     118           2 :     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           2 :     a->insert( "VeraHatMichL1eb.", 1000000 );
     130           2 :     a->returnToRoot();
     131           2 :     CPPUNIT_ASSERT_EQUAL( OUString("VeraHatMichL1eb."), a->suggestAutoCompletion() );
     132             : 
     133           2 :     a->remove( "VeraHatMichL1eb." );
     134           2 :     a->gotoNode( "VeraHatMich" );
     135           2 :     CPPUNIT_ASSERT_EQUAL( OUString(""), a->suggestAutoCompletion() );
     136             : 
     137           2 :     a->returnToRoot();
     138           2 :     CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() );
     139             : 
     140           2 :     a->gotoNode( "VeraLiebtMich" );
     141           2 :     a->insert( 600 );
     142           2 :     a->returnToRoot();
     143           2 :     CPPUNIT_ASSERT_EQUAL( OUString("VeraLiebtMich"), a->suggestAutoCompletion() );
     144             : 
     145           2 :     a->insert( "VeraHatMichL1eb.", 1000000 );
     146           2 :     a->returnToRoot();
     147           2 :     CPPUNIT_ASSERT_EQUAL( OUString("VeraHatMichL1eb."), a->suggestAutoCompletion() );
     148             : 
     149           2 :     a->remove( "VeraHatMichL1eb." );
     150           2 :     a->gotoNode( "VeraHatMich" );
     151           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     152             : 
     153           2 :     a->advance( 'L' );
     154           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     155             : 
     156           2 :     a->insert( "VeraHatMichL1eb.", 1000000 );
     157           2 :     a->returnToRoot();
     158           2 :     a->remove( "VeraHatMichL1eb." );
     159           2 :     a->gotoNode( "VeraHatMich" );
     160           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     161             : 
     162           2 :     a->goBack();
     163           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     164             : 
     165           2 :     a->insert( "VeraHatMichL1eb.", 1000000 );
     166           2 :     a->returnToRoot();
     167           2 :     a->remove( "VeraHatMichL1eb." );
     168           2 :     a->gotoNode( "VeraHatMich" );
     169           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     170             : 
     171           2 :     a->goBack();
     172           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     173             : 
     174           2 :     a->insert( "neu", 2000 );
     175           2 :     a->returnToRoot();
     176           2 :     CPPUNIT_ASSERT_EQUAL( OUString("neu"), a->suggestAutoCompletion() );
     177             : 
     178           2 :     a->gotoNode( "ne" );
     179           2 :     CPPUNIT_ASSERT_EQUAL( OUString("u"), a->suggestAutoCompletion() );
     180             : 
     181           2 :     a->advance( sal_Unicode('u') );
     182           2 :     a->advance( sal_Unicode('e') );
     183           2 :     a->advance( sal_Unicode('r') );
     184           2 :     a->insert();
     185           2 :     CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() );
     186             : 
     187           2 :     a->returnToRoot();
     188           2 :     CPPUNIT_ASSERT_EQUAL( OUString("neu"), a->suggestAutoCompletion() );
     189             : 
     190           2 :     a->advance( 'n' );
     191           2 :     CPPUNIT_ASSERT_EQUAL( OUString("eu"), a->suggestAutoCompletion() );
     192             : 
     193           2 :     a->advance( 'e' );
     194           2 :     CPPUNIT_ASSERT_EQUAL( OUString("uer"), a->suggestAutoCompletion() );
     195             : 
     196             :     // Test unicode
     197           2 :     OUString aQueryString = rtl::OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 );
     198           2 :     a->insert( aQueryString );
     199           2 :     a->returnToRoot();
     200           2 :     a->advance( sal_Unicode('H') );
     201             : 
     202           2 :     OUString aAutocompletedString = a->suggestAutoCompletion();
     203           2 :     OUString aExpectedString = rtl::OStringToOUString( "\xC3\xA4llo", RTL_TEXTENCODING_UTF8 );
     204             : 
     205           2 :     CPPUNIT_ASSERT_EQUAL( aExpectedString, aAutocompletedString );
     206             : 
     207           2 :     OString aUtf8String( "\xe3\x81\x82\xe3\x81\x97\xe3\x81\x9f" );
     208           2 :     aQueryString = rtl::OStringToOUString( aUtf8String, RTL_TEXTENCODING_UTF8 );
     209           2 :     a->insert( aQueryString );
     210             : 
     211           2 :     OUString aGotoString = rtl::OStringToOUString( "\xe3\x81\x82", RTL_TEXTENCODING_UTF8 );
     212           2 :     a->gotoNode( aGotoString );
     213             : 
     214           2 :     aAutocompletedString = a->suggestAutoCompletion();
     215           2 :     aExpectedString      = rtl::OStringToOUString( "\xe3\x81\x97\xe3\x81\x9f", RTL_TEXTENCODING_UTF8 );
     216           2 :     CPPUNIT_ASSERT_EQUAL( aExpectedString, aAutocompletedString );
     217             : 
     218           2 :     delete a;
     219           2 : }
     220             : 
     221             : } // namespace end
     222             : 
     223           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10