1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/uri.hxx>
21 #include <osl/thread.h>
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
29 class Convert
: public CppUnit::TestFixture
32 OString
convertToOString(OUString
const& _suStr
)
34 return OUStringToOString(_suStr
, osl_getThreadTextEncoding()/*RTL_TEXTENCODING_ASCII_US*/);
37 void showContent(OUString
const& _suStr
)
39 OString sStr
= convertToOString(_suStr
);
40 printf("%s\n", sStr
.getStr());
43 void test_FromUTF8_001()
46 OUString suStrUTF8
= OStringToOUString("h%C3%A4llo", RTL_TEXTENCODING_ASCII_US
);
48 // UTF8 --> real ustring
49 OUString suStr_UriDecodeToIuri
= rtl::Uri::decode(suStrUTF8
, rtl_UriDecodeToIuri
, RTL_TEXTENCODING_UTF8
);
50 showContent(suStr_UriDecodeToIuri
);
53 OString
sStr("h\xE4llo", strlen("h\xE4llo"));
54 OUString suString
= OStringToOUString(sStr
, RTL_TEXTENCODING_ISO_8859_15
);
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must be equal", suString
, suStr_UriDecodeToIuri
);
58 // ustring --> ustring (UTF8)
59 OUString suStr2
= rtl::Uri::encode(suStr_UriDecodeToIuri
, rtl_UriCharClassUnoParamValue
, rtl_UriEncodeKeepEscapes
, RTL_TEXTENCODING_UTF8
);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must be equal", suStr2
, suStrUTF8
);
63 // suStr should be equal to suStr2
66 CPPUNIT_TEST_SUITE( Convert
);
67 CPPUNIT_TEST( test_FromUTF8_001
);
68 CPPUNIT_TEST_SUITE_END( );
73 CPPUNIT_TEST_SUITE_REGISTRATION( Stringtest::Convert
);
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */