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 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_sal.hxx"
27 #include <testshl/simpleheader.hxx>
28 #include "stringhelper.hxx"
29 #include <rtl/ustrbuf.hxx>
30 #include <rtl/uri.hxx>
31 
32 namespace rtl_OUStringBuffer
33 {
34 
35 
36 class insertUtf32 : public CppUnit::TestFixture
37 {
38 public:
39     // initialise your test code values here.
setUp()40     void setUp()
41     {
42     }
43 
tearDown()44     void tearDown()
45     {
46     }
47 
insertUtf32_001()48     void insertUtf32_001()
49         {
50             ::rtl::OUStringBuffer aUStrBuf(4);
51             aUStrBuf.insertUtf32(0,0x10ffff);
52 
53             rtl::OUString suStr = aUStrBuf.makeStringAndClear();
54             rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
55 
56             rtl::OString sStr;
57             sStr <<= suStr2;
58             t_print("%s\n", sStr.getStr());
59 
60             CPPUNIT_ASSERT_MESSAGE("Strings must be '%F4%8F%BF%BF'", sStr.equals(rtl::OString("%F4%8F%BF%BF")) == sal_True);
61         }
62 
insertUtf32_002()63     void insertUtf32_002()
64         {
65             ::rtl::OUStringBuffer aUStrBuf(4);
66             aUStrBuf.insertUtf32(0,0x41);
67             aUStrBuf.insertUtf32(1,0x42);
68             aUStrBuf.insertUtf32(2,0x43);
69 
70             rtl::OUString suStr = aUStrBuf.makeStringAndClear();
71             rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
72 
73             rtl::OString sStr;
74             sStr <<= suStr2;
75             t_print("%s\n", sStr.getStr());
76 
77             CPPUNIT_ASSERT_MESSAGE("Strings must be 'ABC'", sStr.equals(rtl::OString("ABC")) == sal_True);
78         }
79 
80     CPPUNIT_TEST_SUITE(insertUtf32);
81     CPPUNIT_TEST(insertUtf32_001);
82     CPPUNIT_TEST(insertUtf32_002);
83     CPPUNIT_TEST_SUITE_END();
84 }; // class getToken
85 
86 // -----------------------------------------------------------------------------
87 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUStringBuffer::insertUtf32, "rtl_OUStringBuffer");
88 
89 } // namespace rtl_OUStringBuffer
90 
91 
92 // -----------------------------------------------------------------------------
93 
94 // this macro creates an empty function, which will called by the RegisterAllFunctions()
95 // to let the user the possibility to also register some functions by hand.
96 NOADDITIONAL;
97 
98