1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "precompiled_comphelper.hxx" 25 #include "sal/config.h" 26 27 #include "comphelper/string.hxx" 28 #include "testshl/simpleheader.hxx" 29 #include "rtl/string.h" 30 #include "rtl/ustring.h" 31 #include "rtl/ustring.hxx" 32 #include "sal/types.h" 33 34 namespace { 35 36 class Test: public CppUnit::TestFixture { 37 public: 38 void test(); 39 40 CPPUNIT_TEST_SUITE(Test); 41 CPPUNIT_TEST(test); 42 CPPUNIT_TEST_SUITE_END(); 43 }; 44 45 void Test::test() { 46 rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar")); 47 sal_Int32 n1; 48 rtl::OUString s2( 49 comphelper::string::searchAndReplace( 50 s1, RTL_CONSTASCII_STRINGPARAM("bar"), 51 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1)); 52 CPPUNIT_ASSERT( 53 s2 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbar"))); 54 CPPUNIT_ASSERT(n1 == 3); 55 sal_Int32 n2; 56 rtl::OUString s3( 57 comphelper::string::searchAndReplace( 58 s2, RTL_CONSTASCII_STRINGPARAM("bar"), 59 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")), 60 n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2)); 61 CPPUNIT_ASSERT( 62 s3 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbz"))); 63 CPPUNIT_ASSERT(n2 == 7); 64 sal_Int32 n3; 65 rtl::OUString s4( 66 comphelper::string::searchAndReplace( 67 s3, RTL_CONSTASCII_STRINGPARAM("bar"), 68 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")), 69 n2 + RTL_CONSTASCII_LENGTH("bz"), &n3)); 70 CPPUNIT_ASSERT(s4 == s3); 71 CPPUNIT_ASSERT(n3 == -1); 72 } 73 74 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); 75 76 } 77 78 NOADDITIONAL; 79