xref: /trunk/main/comphelper/qa/test_string.cxx (revision e92f3138)
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 "gtest/gtest.h"
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 ::testing::Test {
37 public:
38 };
39 
TEST_F(Test,test)40 TEST_F(Test, test) {
41     rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar"));
42     sal_Int32 n1;
43     rtl::OUString s2(
44         comphelper::string::searchAndReplaceAsciiI(
45             s1, rtl::OString(RTL_CONSTASCII_STRINGPARAM("bar")),
46             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1));
47     ASSERT_TRUE(
48         s2 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbar")));
49     ASSERT_TRUE(n1 == 3);
50     sal_Int32 n2;
51     rtl::OUString s3(
52         comphelper::string::searchAndReplaceAsciiI(
53             s2, rtl::OString(RTL_CONSTASCII_STRINGPARAM("bar")),
54             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")),
55             n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2));
56     ASSERT_TRUE(
57         s3 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbz")));
58     ASSERT_TRUE(n2 == 7);
59     sal_Int32 n3;
60     rtl::OUString s4(
61         comphelper::string::searchAndReplaceAsciiI(
62             s3, rtl::OString(RTL_CONSTASCII_STRINGPARAM("bar")),
63             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")),
64             n2 + RTL_CONSTASCII_LENGTH("bz"), &n3));
65     ASSERT_TRUE(s4 == s3);
66     ASSERT_TRUE(n3 == -1);
67 }
68 
69 
70 }
71 
main(int argc,char ** argv)72 int main(int argc, char **argv)
73 {
74     ::testing::InitGoogleTest(&argc, argv);
75     return RUN_ALL_TESTS();
76 }
77