1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_comphelper.hxx" 29 #include "sal/config.h" 30 31 #include "comphelper/string.hxx" 32 #include "testshl/simpleheader.hxx" 33 #include "rtl/string.h" 34 #include "rtl/ustring.h" 35 #include "rtl/ustring.hxx" 36 #include "sal/types.h" 37 38 namespace { 39 40 class Test: public CppUnit::TestFixture { 41 public: 42 void test(); 43 44 CPPUNIT_TEST_SUITE(Test); 45 CPPUNIT_TEST(test); 46 CPPUNIT_TEST_SUITE_END(); 47 }; 48 49 void Test::test() { 50 rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar")); 51 sal_Int32 n1; 52 rtl::OUString s2( 53 comphelper::string::searchAndReplace( 54 s1, RTL_CONSTASCII_STRINGPARAM("bar"), 55 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1)); 56 CPPUNIT_ASSERT( 57 s2 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbar"))); 58 CPPUNIT_ASSERT(n1 == 3); 59 sal_Int32 n2; 60 rtl::OUString s3( 61 comphelper::string::searchAndReplace( 62 s2, RTL_CONSTASCII_STRINGPARAM("bar"), 63 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")), 64 n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2)); 65 CPPUNIT_ASSERT( 66 s3 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbz"))); 67 CPPUNIT_ASSERT(n2 == 7); 68 sal_Int32 n3; 69 rtl::OUString s4( 70 comphelper::string::searchAndReplace( 71 s3, RTL_CONSTASCII_STRINGPARAM("bar"), 72 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")), 73 n2 + RTL_CONSTASCII_LENGTH("bz"), &n3)); 74 CPPUNIT_ASSERT(s4 == s3); 75 CPPUNIT_ASSERT(n3 == -1); 76 } 77 78 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); 79 80 } 81 82 NOADDITIONAL; 83