diff options
Diffstat (limited to '')
80 files changed, 44655 insertions, 0 deletions
diff --git a/sal/qa/ByteSequence/ByteSequence.cxx b/sal/qa/ByteSequence/ByteSequence.cxx new file mode 100644 index 000000000..f5541a0f3 --- /dev/null +++ b/sal/qa/ByteSequence/ByteSequence.cxx @@ -0,0 +1,183 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <rtl/byteseq.hxx> + +namespace { + +class Test: public CppUnit::TestFixture { +public: + void test_default() { + rtl::ByteSequence s; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + } + + void test_size0() { + rtl::ByteSequence s(sal_Int32(0)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + } + + void test_size5() { + rtl::ByteSequence s(5); + sal_Int8 const * p = s.getConstArray(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength()); + CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[1]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[2]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[3]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[4]); + } + + void test_noinit0() { + rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + } + + void test_noinit5() { + rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength()); + } + + void test_elem0() { + rtl::ByteSequence s(nullptr, 0); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + } + + void test_elem5() { + sal_Int8 const a[5] = { 0, 1, 2, 3, 4 }; + rtl::ByteSequence s(a, 5); + sal_Int8 const * p = s.getConstArray(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength()); + CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(1), p[1]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(2), p[2]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(3), p[3]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(4), p[4]); + } + + void test_copy() { + rtl::ByteSequence s1(5); + { + rtl::ByteSequence s2(s1); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s2.getLength()); + CPPUNIT_ASSERT_EQUAL(s1.getConstArray(), s2.getConstArray()); + CPPUNIT_ASSERT_EQUAL(s1.getHandle(), s2.getHandle()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s1.getHandle()->nRefCount); + } + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount); + } + + void test_fromC() { + sal_Sequence c = { 1, 1, { 0 } }; + { + rtl::ByteSequence s(&c); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength()); + CPPUNIT_ASSERT_EQUAL( + static_cast< void const * >(c.elements), + static_cast< void const * >(s.getConstArray())); + CPPUNIT_ASSERT_EQUAL(&c, s.getHandle()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount); + } + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount); + } + + void test_noacquire() { + sal_Sequence c = { 2, 1, { 0 } }; + { + rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength()); + CPPUNIT_ASSERT_EQUAL( + static_cast< void const * >(c.elements), + static_cast< void const * >(s.getConstArray())); + CPPUNIT_ASSERT_EQUAL(&c, s.getHandle()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount); + } + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount); + } + + void test_getArray() { + sal_Int8 const a[5] = { 0, 1, 2, 3, 4 }; + rtl::ByteSequence s1(a, 5); + rtl::ByteSequence s2(s1); + sal_Int8 * p = s2.getArray(); + p[2] = 10; + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s2.getHandle()->nRefCount); + CPPUNIT_ASSERT_EQUAL(sal_Int8(2), s1.getConstArray()[2]); + CPPUNIT_ASSERT_EQUAL(sal_Int8(10), s2.getConstArray()[2]); + } + + void test_same0() { + rtl::ByteSequence s1; + rtl::ByteSequence s2; + CPPUNIT_ASSERT_EQUAL(true, s1 == s2); + CPPUNIT_ASSERT_EQUAL(true, s2 == s1); + CPPUNIT_ASSERT_EQUAL(false, s1 != s2); + CPPUNIT_ASSERT_EQUAL(false, s2 != s1); + } + + void test_diffLen() { + sal_Int8 const a[5] = { 0, 1, 2, 3, 4 }; + rtl::ByteSequence s1(a, 5); + rtl::ByteSequence s2(a, 4); + CPPUNIT_ASSERT_EQUAL(false, s1 == s2); + CPPUNIT_ASSERT_EQUAL(false, s2 == s1); + CPPUNIT_ASSERT_EQUAL(true, s1 != s2); + CPPUNIT_ASSERT_EQUAL(true, s2 != s1); + } + + void test_diffElem() { + sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 }; + rtl::ByteSequence s1(a1, 5); + sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 }; + rtl::ByteSequence s2(a2, 5); + CPPUNIT_ASSERT_EQUAL(false, s1 == s2); + CPPUNIT_ASSERT_EQUAL(false, s2 == s1); + CPPUNIT_ASSERT_EQUAL(true, s1 != s2); + CPPUNIT_ASSERT_EQUAL(true, s2 != s1); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test_default); + CPPUNIT_TEST(test_size0); + CPPUNIT_TEST(test_size5); + CPPUNIT_TEST(test_noinit0); + CPPUNIT_TEST(test_noinit5); + CPPUNIT_TEST(test_elem0); + CPPUNIT_TEST(test_elem5); + CPPUNIT_TEST(test_copy); + CPPUNIT_TEST(test_fromC); + CPPUNIT_TEST(test_noacquire); + CPPUNIT_TEST(test_getArray); + CPPUNIT_TEST(test_same0); + CPPUNIT_TEST(test_diffLen); + CPPUNIT_TEST(test_diffElem); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx new file mode 100644 index 000000000..c8a7ccce2 --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx @@ -0,0 +1,15574 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <rtl/string.hxx> +#include "rtl_String_Const.h" +#include <rtl/strbuf.hxx> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <string.h> + +// This file contains cppunit tests for the +// OString and OStringBuffer classes + +// testing constructors +namespace rtl_OStringBuffer +{ + class ctors : public CppUnit::TestFixture + { + public: + + void ctor_001() + { + OStringBuffer aStrBuf; + const char* pStr = aStrBuf.getStr(); + + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters", + aStrBuf.isEmpty() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer containing no characters", + '\0', *pStr + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer containing no characters", + sal_Int32(16), aStrBuf.getCapacity() + ); + } + + void ctor_002() + { + OString aStrtmp( kTestStr1 ); + OStringBuffer aStrBuftmp( aStrtmp ); + OStringBuffer aStrBuf( aStrBuftmp ); + // sal_Bool res = cmpstr(aStrBuftmp.getStr(),aStrBuf.getStr()); + + sal_Int32 nLenStrBuftmp = aStrBuftmp.getLength(); + + OString sStr(aStrBuftmp.getStr()); + bool res = aStrtmp == sStr; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from another OStringBuffer", + nLenStrBuftmp, aStrBuf.getLength() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from another OStringBuffer", + aStrBuftmp.getCapacity(), aStrBuf.getCapacity() + ); + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer from another OStringBuffer", + res + ); + + } + + void ctor_003() + { + OStringBuffer aStrBuf1(kTestStr2Len); + OStringBuffer aStrBuf2(0); + + const char* pStr1 = aStrBuf1.getStr(); + const char* pStr2 = aStrBuf2.getStr(); + + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + aStrBuf1.isEmpty() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + '\0', *pStr1 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + kTestStr2Len, aStrBuf1.getCapacity() + ); + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + aStrBuf2.isEmpty() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + '\0', *pStr2 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + sal_Int32(0), aStrBuf2.getCapacity() + ); + + } + + void ctor_004() + { + OString aStrtmp( kTestStr1 ); + OStringBuffer aStrBuf( aStrtmp ); + sal_Int32 leg = aStrBuf.getLength(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from OString", + aStrtmp, OString(aStrBuf.getStr()) + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from OString", + aStrtmp.pData->length, leg + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from OString", + leg+16, aStrBuf.getCapacity() + + ); + } + + void ctor_005() { + OStringBuffer b1; + auto dummy = b1.makeStringAndClear(); + (void)dummy; + OStringBuffer b2(b1); + (void)b2; + } + + void ctor_006() + { + //pass in a const char*, get a temp + //OString + OStringBuffer aStrBuf(kTestStr1); + sal_Int32 leg = aStrBuf.getLength(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from const char*", + rtl_str_getLength(kTestStr1), leg + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "New OStringBuffer from const char*", + leg+16, aStrBuf.getCapacity() + ); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST(ctor_003); + CPPUNIT_TEST(ctor_004); + CPPUNIT_TEST(ctor_005); + CPPUNIT_TEST(ctor_006); + CPPUNIT_TEST_SUITE_END(); + }; + + class makeStringAndClear : public CppUnit::TestFixture + { + OString arrOUS[6]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr1 ); + arrOUS[1] = OString( kTestStr14 ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( kTestStr27 ); + arrOUS[4] = OString( kTestStr29 ); + arrOUS[5] = OString( "\0", 1 ); + + } + + void makeStringAndClear_001() + { + OStringBuffer aStrBuf1; + OString aStr1; + + bool lastRes = (aStrBuf1.makeStringAndClear() == aStr1 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "two empty strings(def. constructor)", + lastRes + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "two empty strings(def. constructor)", + sal_Int32(0), aStrBuf1.getCapacity() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "two empty strings(def. constructor)", + '\0', *(aStrBuf1.getStr()) + ); + + } + + void makeStringAndClear_002() + { + OStringBuffer aStrBuf2(26); + OString aStr2; + + bool lastRes = (aStrBuf2.makeStringAndClear() == aStr2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "two empty strings(with an argu)", + lastRes && ( aStrBuf2.getCapacity() == 0 ) && + ( *(aStrBuf2.getStr()) == '\0' ) + ); + + } + + void makeStringAndClear_003() + { + OStringBuffer aStrBuf3(arrOUS[0]); + OString aStr3(arrOUS[0]); + + bool lastRes = (aStrBuf3.makeStringAndClear() == aStr3 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "normal string", + lastRes && ( aStrBuf3.getCapacity() == 0 ) && + ( *(aStrBuf3.getStr()) == '\0' ) + ); + + } + + void makeStringAndClear_004() + { + OStringBuffer aStrBuf4(arrOUS[1]); + OString aStr4(arrOUS[1]); + + bool lastRes = (aStrBuf4.makeStringAndClear() == aStr4 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string with space ", + lastRes && ( aStrBuf4.getCapacity() == 0 ) && + ( *(aStrBuf4.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_005() + { + OStringBuffer aStrBuf5(arrOUS[2]); + OString aStr5(arrOUS[2]); + + bool lastRes = (aStrBuf5.makeStringAndClear() == aStr5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "empty string", + lastRes && ( aStrBuf5.getCapacity() == 0 ) && + ( *(aStrBuf5.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_006() + { + OStringBuffer aStrBuf6(arrOUS[3]); + OString aStr6(arrOUS[3]); + + bool lastRes = (aStrBuf6.makeStringAndClear() == aStr6 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string with a character", + lastRes && ( aStrBuf6.getCapacity() == 0 ) && + ( *(aStrBuf6.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_007() + { + OStringBuffer aStrBuf7(arrOUS[4]); + OString aStr7(arrOUS[4]); + + bool lastRes = (aStrBuf7.makeStringAndClear() == aStr7 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string with special characters", + lastRes && ( aStrBuf7.getCapacity() == 0 ) && + ( *(aStrBuf7.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_008() + { + OStringBuffer aStrBuf8(arrOUS[5]); + OString aStr8(arrOUS[5]); + + bool lastRes = (aStrBuf8.makeStringAndClear() == aStr8 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string only with (\0)", + lastRes && ( aStrBuf8.getCapacity() == 0 ) && + ( *(aStrBuf8.getStr()) == '\0' ) + ); + } + + CPPUNIT_TEST_SUITE(makeStringAndClear); + CPPUNIT_TEST(makeStringAndClear_001); + CPPUNIT_TEST(makeStringAndClear_002); + CPPUNIT_TEST(makeStringAndClear_003); + CPPUNIT_TEST(makeStringAndClear_004); + CPPUNIT_TEST(makeStringAndClear_005); + CPPUNIT_TEST(makeStringAndClear_006); + CPPUNIT_TEST(makeStringAndClear_007); + CPPUNIT_TEST(makeStringAndClear_008); + CPPUNIT_TEST_SUITE_END(); + }; + + class remove : public CppUnit::TestFixture + { + public: + void remove_001() + { + OStringBuffer sb( + RTL_CONSTASCII_STRINGPARAM("Red Hat, Inc.")); + + sb.remove(0, 4); + CPPUNIT_ASSERT(sb.toString().equalsL( + RTL_CONSTASCII_STRINGPARAM("Hat, Inc."))); + + sb.remove(3, 6); + CPPUNIT_ASSERT(sb.toString().equalsL( + RTL_CONSTASCII_STRINGPARAM("Hat"))); + + sb.remove(0, 100); + + CPPUNIT_ASSERT(sb.toString().isEmpty()); + + sb.append(RTL_CONSTASCII_STRINGPARAM("Red Hat, Inc.")); + + sb.remove(3, 100); + + CPPUNIT_ASSERT(sb.toString().equalsL( + RTL_CONSTASCII_STRINGPARAM("Red"))); + + sb.remove(0, sb.getLength()); + + CPPUNIT_ASSERT(sb.toString().isEmpty()); + } + + CPPUNIT_TEST_SUITE(remove); + CPPUNIT_TEST(remove_001); + CPPUNIT_TEST_SUITE_END(); + }; + + class getLength : public CppUnit::TestFixture + { + OString arrOUS[6]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr1 ); + arrOUS[1] = OString( "1" ); + arrOUS[2] = OString( ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( "\0", 1 ); + arrOUS[5] = OString( kTestStr2 ); + + } + + void getLength_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal = kTestStr1Len; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of ascii string", + expVal, aStrBuf.getLength() + ); + + } + + void getLength_002() + { + OStringBuffer aStrBuf( arrOUS[1] ); + sal_Int32 expVal = 1; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of ascii string of size 1", + expVal, aStrBuf.getLength() + ); + } + + void getLength_003() + { + OStringBuffer aStrBuf( arrOUS[2] ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of empty string", + expVal, aStrBuf.getLength() + ); + } + + void getLength_004() + { + OStringBuffer aStrBuf( arrOUS[3] ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of empty string (empty ascii string arg)", + expVal, aStrBuf.getLength() + ); + } + + void getLength_005() + { + OStringBuffer aStrBuf( arrOUS[4] ); + sal_Int32 expVal = 1; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of string with \\0 embedded", + expVal, aStrBuf.getLength() + ); + } + + void getLength_006() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal = kTestStr2Len; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length(>16) of ascii string", + expVal, aStrBuf.getLength() + ); + } + + void getLength_007() + { + OStringBuffer aStrBuf; + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of empty string (default constructor)", + expVal, aStrBuf.getLength() + ); + } + + void getLength_008() + { + OStringBuffer aStrBuf( 26 ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "length of empty string (with capacity)", + expVal, aStrBuf.getLength() + ); + } + + CPPUNIT_TEST_SUITE( getLength ); + CPPUNIT_TEST( getLength_001 ); + CPPUNIT_TEST( getLength_002 ); + CPPUNIT_TEST( getLength_003 ); + CPPUNIT_TEST( getLength_004 ); + CPPUNIT_TEST( getLength_005 ); + CPPUNIT_TEST( getLength_006 ); + CPPUNIT_TEST( getLength_007 ); + CPPUNIT_TEST( getLength_008 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class getCapacity : public CppUnit::TestFixture + { + OString arrOUS[6]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr1 ); + arrOUS[1] = OString( "1" ); + arrOUS[2] = OString( ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( "\0", 1 ); + arrOUS[5] = OString( kTestStr2 ); + + } + + void getCapacity_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal = kTestStr1Len+16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of ascii string", + expVal, aStrBuf.getCapacity() + ); + + } + + void getCapacity_002() + { + OStringBuffer aStrBuf( arrOUS[1] ); + sal_Int32 expVal = 1+16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of ascii string of size 1", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_003() + { + OStringBuffer aStrBuf( arrOUS[2] ); + sal_Int32 expVal = 0+16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of empty string", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_004() + { + OStringBuffer aStrBuf( arrOUS[3] ); + sal_Int32 expVal = 0+16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of empty string (empty ascii string arg)", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_005() + { + OStringBuffer aStrBuf( arrOUS[4] ); + sal_Int32 expVal = 1+16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of string with \\0 embedded", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_006() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal = kTestStr2Len+16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity(>16) of ascii string", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_007() + { + OStringBuffer aStrBuf; + sal_Int32 expVal = 16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of empty string (default constructor)", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_010() + { + OStringBuffer aStrBuf( 16 ); + sal_Int32 expVal = 16; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of empty string (with capacity 16)", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_011() + { + OStringBuffer aStrBuf( 6 ); + sal_Int32 expVal = 6; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of empty string (with capacity 6)", + expVal, aStrBuf.getCapacity() + ); + } + + void getCapacity_012() + { + OStringBuffer aStrBuf( 0 ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity of empty string (with capacity 0)", + expVal, aStrBuf.getCapacity() + ); + } + + CPPUNIT_TEST_SUITE( getCapacity ); + CPPUNIT_TEST( getCapacity_001 ); + CPPUNIT_TEST( getCapacity_002 ); + CPPUNIT_TEST( getCapacity_003 ); + CPPUNIT_TEST( getCapacity_004 ); + CPPUNIT_TEST( getCapacity_005 ); + CPPUNIT_TEST( getCapacity_006 ); + CPPUNIT_TEST( getCapacity_007 ); + CPPUNIT_TEST( getCapacity_010 ); + CPPUNIT_TEST( getCapacity_011 ); + CPPUNIT_TEST( getCapacity_012 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class ensureCapacity : public CppUnit::TestFixture + { + void ensureCapacity_001() + { + sal_Int32 expVal = 16; + OStringBuffer aStrBuf; + sal_Int32 input = 5; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 16, minimum is 5", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_002() + { + sal_Int32 expVal = 16; + OStringBuffer aStrBuf; + sal_Int32 input = -5; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 16, minimum is -5", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_003() + { + sal_Int32 expVal = 16; + OStringBuffer aStrBuf; + sal_Int32 input = 0; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 16, minimum is 0", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_004() //the testcase is based on comments + { + sal_Int32 expVal = 20; + OStringBuffer aStrBuf; + sal_Int32 input = 20; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 16, minimum is 20", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_005() + { + sal_Int32 expVal = 50; + OStringBuffer aStrBuf; + sal_Int32 input = 50; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 16, minimum is 50", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_006() + { + sal_Int32 expVal = 20; + OStringBuffer aStrBuf( 6 ); + sal_Int32 input = 20; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 6, minimum is 20", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_007() + { + sal_Int32 expVal = 6; + OStringBuffer aStrBuf( 6 ); + sal_Int32 input = 2; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 6, minimum is 2", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_008() + { + sal_Int32 expVal = 6; + OStringBuffer aStrBuf( 6 ); + sal_Int32 input = -6; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 6, minimum is -6", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_009() //the testcase is based on comments + { + sal_Int32 expVal = 10; + OStringBuffer aStrBuf( 6 ); + sal_Int32 input = 10; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 6, minimum is -6", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_010() + { + sal_Int32 expVal = 6; + OStringBuffer aStrBuf( 0 ); + sal_Int32 input = 6; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 0, minimum is 6", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_011() //the testcase is based on comments + { + sal_Int32 expVal = 2; // capacity is x = (str->length + 1) * 2; minimum < x ? x : minimum + OStringBuffer aStrBuf( 0 ); + sal_Int32 input = 1; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 0, minimum is 1", + expVal, aStrBuf.getCapacity() + ); + + } + + void ensureCapacity_012() + { + sal_Int32 expVal = 0; + OStringBuffer aStrBuf( 0 ); + sal_Int32 input = -1; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "capacity equal to 0, minimum is -1", + expVal, aStrBuf.getCapacity() + ); + + } + + CPPUNIT_TEST_SUITE( ensureCapacity ); + CPPUNIT_TEST( ensureCapacity_001 ); + CPPUNIT_TEST( ensureCapacity_002 ); + CPPUNIT_TEST( ensureCapacity_003 ); + CPPUNIT_TEST( ensureCapacity_004 ); + CPPUNIT_TEST( ensureCapacity_005 ); + CPPUNIT_TEST( ensureCapacity_006 ); + CPPUNIT_TEST( ensureCapacity_007 ); + CPPUNIT_TEST( ensureCapacity_008 ); + CPPUNIT_TEST( ensureCapacity_009 ); + CPPUNIT_TEST( ensureCapacity_010 ); + CPPUNIT_TEST( ensureCapacity_011 ); + CPPUNIT_TEST( ensureCapacity_012 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class setLength : public CppUnit::TestFixture + { + OString arrOUS[6]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr1 ); + arrOUS[1] = OString( "1" ); + arrOUS[2] = OString( ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( "\0", 1 ); + arrOUS[5] = OString( kTestStr2 ); + + } + + void setLength_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal1 = 50; + OString expVal2( kTestStr1 ); + sal_Int32 expVal3 = 50; + sal_Int32 input = 50; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the capacity of OStringBuffer(kTestStr1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal1 = kTestStr13Len; + OString expVal2( kTestStr1 ); + sal_Int32 expVal3 = 32; + sal_Int32 input = kTestStr13Len; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer(kTestStr1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal1 = kTestStr1Len; + OString expVal2( kTestStr1 ); + sal_Int32 expVal3 = 32; + sal_Int32 input = kTestStr1Len; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength equal to the length of OStringBuffer(kTestStr1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal1 = kTestStr7Len; + OString expVal2( kTestStr7 ); + sal_Int32 expVal3 = 32; + sal_Int32 input = kTestStr7Len; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength less than the length of OStringBuffer(kTestStr1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + sal_Int32 expVal1 = 0; + OString expVal2; + sal_Int32 expVal3 = 32; + sal_Int32 input = 0; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength equal to 0", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_006() + { + OStringBuffer aStrBuf( arrOUS[1] ); + sal_Int32 expVal1 = 25; + OString expVal2( arrOUS[1] ); + sal_Int32 expVal3 = 25; + sal_Int32 input = 25; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the capacity of OStringBuffer(1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_007() + { + OStringBuffer aStrBuf( arrOUS[1] ); + sal_Int32 expVal1 = kTestStr27Len; + OString expVal2( arrOUS[1] ); + sal_Int32 expVal3 = 17; + sal_Int32 input = kTestStr27Len; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength equal to the length of OStringBuffer(1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_008() + { + OStringBuffer aStrBuf( arrOUS[1] ); + sal_Int32 expVal1 = 0; + OString expVal2; + sal_Int32 expVal3 = 17; + sal_Int32 input = 0; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength less than the length of OUStringBuffer(1)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_009() + { + OStringBuffer aStrBuf( arrOUS[2] ); + sal_Int32 expVal1 = 20; + OString expVal2; + sal_Int32 expVal3 = 20; + sal_Int32 input = 20; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the capacity of OStringBuffer()", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_010() + { + OStringBuffer aStrBuf( arrOUS[2] ); + sal_Int32 expVal1 = 3; + OString expVal2; + sal_Int32 expVal3 = 16; + sal_Int32 input = 3; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer()", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_011() + { + OStringBuffer aStrBuf( arrOUS[2] ); + sal_Int32 expVal1 = 0; + OString expVal2; + sal_Int32 expVal3 = 16; + sal_Int32 input = 0; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer()", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_012() + { + OStringBuffer aStrBuf( arrOUS[3] ); + sal_Int32 expVal1 = 20; + OString expVal2; + sal_Int32 expVal3 = 20; + sal_Int32 input = 20; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the capacity of OStringBuffer("")", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_013() + { + OStringBuffer aStrBuf( arrOUS[3] ); + sal_Int32 expVal1 = 5; + OString expVal2; + sal_Int32 expVal3 = 16; + sal_Int32 input = 5; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer("")", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_014() + { + OStringBuffer aStrBuf( arrOUS[3] ); + sal_Int32 expVal1 = 0; + OString expVal2; + sal_Int32 expVal3 = 16; + sal_Int32 input = 0; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength less than the length of OStringBuffer("")", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_015() + { + OStringBuffer aStrBuf( arrOUS[4] ); + sal_Int32 expVal1 = 20; + OString expVal2; + sal_Int32 expVal3 = 20; + sal_Int32 input = 20; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer(\0)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_016() + { + OStringBuffer aStrBuf( arrOUS[4] ); + sal_Int32 expVal1 = 5; + OString expVal2; + sal_Int32 expVal3 = 17; + sal_Int32 input = 5; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer(\0)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_017() + { + OStringBuffer aStrBuf( arrOUS[4] ); + sal_Int32 expVal1 = 0; + OString expVal2; + sal_Int32 expVal3 = 17; + sal_Int32 input = 0; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength less than the length of OStringBuffer(\0)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_018() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal1 = 50; + OString expVal2( kTestStr2 ); + sal_Int32 expVal3 = 66; + sal_Int32 input = 50; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the capacity of OStringBuffer(kTestStr2)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_019() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal1 = 40; + OString expVal2(kTestStr2); + sal_Int32 expVal3 = 48; + sal_Int32 input = 40; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength more than the length of OStringBuffer(kTestStr2)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_020() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal1 = kTestStr2Len; + OString expVal2(kTestStr2); + sal_Int32 expVal3 = 48; + sal_Int32 input = kTestStr2Len; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength equal to the length of OUStringBuffer(kTestStr2)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_021() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal1 = kTestStr7Len; + OString expVal2(kTestStr7); + sal_Int32 expVal3 = 48; + sal_Int32 input = kTestStr7Len; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength less than the length of OUStringBuffer(TestStr2)", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + void setLength_022() + { + OStringBuffer aStrBuf( arrOUS[5] ); + sal_Int32 expVal1 = 0; + OString expVal2; + sal_Int32 expVal3 = 48; + sal_Int32 input = 0; + + aStrBuf.setLength( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "newLength equal to 0", + aStrBuf.getStr() == expVal2 && + aStrBuf.getLength() == expVal1 && + aStrBuf.getCapacity() == expVal3 + ); + + } + + CPPUNIT_TEST_SUITE( setLength ); + CPPUNIT_TEST( setLength_001 ); + CPPUNIT_TEST( setLength_002 ); + CPPUNIT_TEST( setLength_003 ); + CPPUNIT_TEST( setLength_004 ); + CPPUNIT_TEST( setLength_005 ); + CPPUNIT_TEST( setLength_006 ); + CPPUNIT_TEST( setLength_007 ); + CPPUNIT_TEST( setLength_008 ); + CPPUNIT_TEST( setLength_009 ); + CPPUNIT_TEST( setLength_010 ); + CPPUNIT_TEST( setLength_011 ); + CPPUNIT_TEST( setLength_012 ); + CPPUNIT_TEST( setLength_013 ); + CPPUNIT_TEST( setLength_014 ); + CPPUNIT_TEST( setLength_015 ); + CPPUNIT_TEST( setLength_016 ); + CPPUNIT_TEST( setLength_017 ); + CPPUNIT_TEST( setLength_018 ); + CPPUNIT_TEST( setLength_019 ); + CPPUNIT_TEST( setLength_020 ); + CPPUNIT_TEST( setLength_021 ); + CPPUNIT_TEST( setLength_022 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class csuc : public CppUnit::TestFixture + { + void csuc_001() + { + const char* expVal = kTestStr1; + OStringBuffer aStrBuf( kTestStr1 ); + sal_Int32 cmpLen = kTestStr1Len; + + // LLA: wrong access! const char* pstr = *&aStrBuf; + const char* pstr = aStrBuf.getStr(); + int nEqual = strncmp(pstr, expVal, cmpLen); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "test normal string", + /* cmpstr( pstr, expVal, cmpLen ) */ + 0, nEqual + ); + + } + + void csuc_002() + { + OStringBuffer aStrBuf; + + // LLA: wrong access! const char* pstr = *&aStrBuf; + const char* pstr = aStrBuf.getStr(); + sal_Int32 nLen = strlen(pstr); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "test empty string", + // cmpstr( pstr, &expVal, cmpLen ) + static_cast<sal_Int32>(0), nLen + ); + + } + + CPPUNIT_TEST_SUITE( csuc ); + CPPUNIT_TEST( csuc_001 ); + CPPUNIT_TEST( csuc_002 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class getStr : public CppUnit::TestFixture + { + void getStr_001() + { + const char* expVal = kTestStr1; + OStringBuffer aStrBuf( kTestStr1 ); + sal_Int32 cmpLen = kTestStr1Len; + + const char* pstr = aStrBuf.getStr(); + int nEqual = strncmp(pstr, expVal, cmpLen); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "test normal string", + 0, nEqual + ); + + } + + void getStr_002() + { + OStringBuffer aStrBuf; + const char* pstr = aStrBuf.getStr(); + CPPUNIT_ASSERT_MESSAGE + ( + "test empty string", + pstr != nullptr && + pstr[0] == '\0' + ); + + } + + CPPUNIT_TEST_SUITE( getStr ); + CPPUNIT_TEST( getStr_001 ); + CPPUNIT_TEST( getStr_002 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class append_001 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + + } + + void append_001_001() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[0] ); + OString input2( kTestStr8 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_001_002() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[0] ); + OString input2( kTestStr36 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_003() + { + OString expVal( kTestStr37 ); + OStringBuffer aStrBuf( arrOUS[0] ); + OString input2( kTestStr23 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_004() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[0] ); + OString input2; + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_005() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[1] ); + OString input2( kTestStr7 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_006() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[1] ); + OString input2( kTestStr2 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_007() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[1] ); + OString input2( kTestStr1 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_008() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[1] ); + OString input2; + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_009() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[2] ); + OString input2( kTestStr7 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_010() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[2] ); + OString input2( kTestStr2 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_011() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[2] ); + OString input2( kTestStr1 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_012() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[2] ); + OString input2; + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_013() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[3] ); + OString input2( kTestStr7 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_014() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[3] ); + OString input2( kTestStr2 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_015() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[3] ); + OString input2( kTestStr1 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_016() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[3] ); + OString input2; + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_017() + { + OString expVal( kTestStr29 ); + OStringBuffer aStrBuf( arrOUS[4] ); + OString input2( kTestStr38 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_018() + { + OString expVal( kTestStr39 ); + OStringBuffer aStrBuf( arrOUS[4] ); + OString input2( kTestStr17 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_019() + { + OString expVal( kTestStr40 ); + OStringBuffer aStrBuf( arrOUS[4] ); + OString input2( kTestStr31 ); + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_001_020() + { + OString expVal( kTestStr28 ); + OStringBuffer aStrBuf( arrOUS[4] ); + OString input2; + + aStrBuf.append( input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_null() + { + OStringBuffer aStrBuf("hello world"); + + aStrBuf.append('\0'); + aStrBuf.append('\1'); + aStrBuf.append('\2'); + + aStrBuf.append("hello world"); + + CPPUNIT_ASSERT_MESSAGE + ( + "should be able to append nulls", + aStrBuf.getLength() == + 2 * RTL_CONSTASCII_LENGTH("hello world") + 3 && + aStrBuf[RTL_CONSTASCII_LENGTH("hello world")] == 0 && + aStrBuf[RTL_CONSTASCII_LENGTH("hello world")]+1 == 1 && + aStrBuf[RTL_CONSTASCII_LENGTH("hello world")]+2 == 2 + ); + + } + + CPPUNIT_TEST_SUITE( append_001 ); + CPPUNIT_TEST( append_001_001 ); + CPPUNIT_TEST( append_001_002 ); + CPPUNIT_TEST( append_001_003 ); + CPPUNIT_TEST( append_001_004 ); + CPPUNIT_TEST( append_001_005 ); + CPPUNIT_TEST( append_001_006 ); + CPPUNIT_TEST( append_001_007 ); + CPPUNIT_TEST( append_001_008 ); + CPPUNIT_TEST( append_001_009 ); + CPPUNIT_TEST( append_001_010 ); + CPPUNIT_TEST( append_001_011 ); + CPPUNIT_TEST( append_001_012 ); + CPPUNIT_TEST( append_001_013 ); + CPPUNIT_TEST( append_001_014 ); + CPPUNIT_TEST( append_001_015 ); + CPPUNIT_TEST( append_001_016 ); + CPPUNIT_TEST( append_001_017 ); + CPPUNIT_TEST( append_001_018 ); + CPPUNIT_TEST( append_001_019 ); + CPPUNIT_TEST( append_001_020 ); + CPPUNIT_TEST( append_null ); + CPPUNIT_TEST_SUITE_END(); + }; + + class append_002 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + + } + + void append_002_001() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input = kTestStr8; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_002() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input = kTestStr36; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_003() + { + OString expVal( kTestStr37 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input = kTestStr23; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_004() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input = kTestStr25; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_005() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input = kTestStr7; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_006() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input = kTestStr2; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_007() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input = kTestStr1; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_008() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input = kTestStr25; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_009() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input = kTestStr7; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_010() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input = kTestStr2; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_011() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input = kTestStr1; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_012() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input = kTestStr25; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_013() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input = kTestStr7; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_014() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input = kTestStr2; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_015() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input = kTestStr1; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_016() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input = kTestStr25; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_017() + { + OString expVal( kTestStr29 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input = kTestStr38; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_018() + { + OString expVal( kTestStr39 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input = kTestStr17; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_019() + { + OString expVal( kTestStr40 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input = kTestStr31; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002_020() + { + OString expVal( kTestStr28 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input = kTestStr25; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + +#ifdef WITH_CORE + void append_002_021() + { + OString expVal; + OStringBuffer aStrBuf( kSInt32Max ); + const char* input = kTestStr25; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer(with INT_MAX)", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_002 ); + CPPUNIT_TEST( append_002_001 ); + CPPUNIT_TEST( append_002_002 ); + CPPUNIT_TEST( append_002_003 ); + CPPUNIT_TEST( append_002_004 ); + CPPUNIT_TEST( append_002_005 ); + CPPUNIT_TEST( append_002_006 ); + CPPUNIT_TEST( append_002_007 ); + CPPUNIT_TEST( append_002_008 ); + CPPUNIT_TEST( append_002_009 ); + CPPUNIT_TEST( append_002_010 ); + CPPUNIT_TEST( append_002_011 ); + CPPUNIT_TEST( append_002_012 ); + CPPUNIT_TEST( append_002_013 ); + CPPUNIT_TEST( append_002_014 ); + CPPUNIT_TEST( append_002_015 ); + CPPUNIT_TEST( append_002_016 ); + CPPUNIT_TEST( append_002_017 ); + CPPUNIT_TEST( append_002_018 ); + CPPUNIT_TEST( append_002_019 ); + CPPUNIT_TEST( append_002_020 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_002_021 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + + class append_003 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + + } + + void append_003_001() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input1 = kTestStr36; + sal_Int32 input2 = 12; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_002() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input1 = kTestStr36; + sal_Int32 input2 = 28; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_003() + { + OString expVal( kTestStr37 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input1 = kTestStr23; + sal_Int32 input2 = 16; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_004() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[0] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 0; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_006() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 4; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_007() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 32; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_008() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 16; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_009() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[1] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 0; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_011() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 4; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_012() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 32; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_013() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 16; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_014() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[2] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 0; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_016() + { + OString expVal( kTestStr7 ); + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 4; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_017() + { + OString expVal( kTestStr2 ); + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 32; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_018() + { + OString expVal( kTestStr1 ); + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 16; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_019() + { + OString expVal; + OStringBuffer aStrBuf( arrOUS[3] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 0; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_021() + { + OString expVal( kTestStr29 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input1 = kTestStr38; + sal_Int32 input2 = 7; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length less than 16) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_022() + { + OString expVal( kTestStr39 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input1 = kTestStr17; + sal_Int32 input2 = 22; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length more than 16) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_023() + { + OString expVal( kTestStr40 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input1 = kTestStr31; + sal_Int32 input2 = 16; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 16) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003_024() + { + OString expVal( kTestStr28 ); + OStringBuffer aStrBuf( arrOUS[4] ); + const char* input1 = kTestStr2; + sal_Int32 input2 = 0; + + aStrBuf.append( input1, input2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the string(length equal to 0) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + CPPUNIT_TEST_SUITE( append_003 ); + CPPUNIT_TEST( append_003_001 ); + CPPUNIT_TEST( append_003_002 ); + CPPUNIT_TEST( append_003_003 ); + CPPUNIT_TEST( append_003_004 ); + CPPUNIT_TEST( append_003_006 ); + CPPUNIT_TEST( append_003_007 ); + CPPUNIT_TEST( append_003_008 ); + CPPUNIT_TEST( append_003_009 ); + CPPUNIT_TEST( append_003_011 ); + CPPUNIT_TEST( append_003_012 ); + CPPUNIT_TEST( append_003_013 ); + CPPUNIT_TEST( append_003_014 ); + CPPUNIT_TEST( append_003_016 ); + CPPUNIT_TEST( append_003_017 ); + CPPUNIT_TEST( append_003_018 ); + CPPUNIT_TEST( append_003_019 ); + CPPUNIT_TEST( append_003_021 ); + CPPUNIT_TEST( append_003_022 ); + CPPUNIT_TEST( append_003_023 ); + CPPUNIT_TEST( append_003_024 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class append_004 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + + } + + void append_004_001() + { + OString expVal( kTestStr45 ); + OStringBuffer aStrBuf( arrOUS[0] ); + bool input = true; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_True) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_002() + { + OString expVal( kTestStr46 ); + OStringBuffer aStrBuf( arrOUS[0] ); + bool input = false; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_False) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_003() + { + OString expVal( kTestStr47 ); + OStringBuffer aStrBuf( arrOUS[1] ); + bool input = true; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_True) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_004() + { + OString expVal( kTestStr48 ); + OStringBuffer aStrBuf( arrOUS[1] ); + bool input = false; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_False) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_005() + { + OString expVal( kTestStr47 ); + OStringBuffer aStrBuf( arrOUS[2] ); + bool input = true; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_True) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_006() + { + OString expVal( kTestStr48 ); + OStringBuffer aStrBuf( arrOUS[2] ); + bool input = false; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_False) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_007() + { + OString expVal( kTestStr47 ); + OStringBuffer aStrBuf( arrOUS[3] ); + bool input = true; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_True) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_008() + { + OString expVal( kTestStr48 ); + OStringBuffer aStrBuf( arrOUS[3] ); + bool input = false; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_False) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_009() + { + OString expVal( kTestStr49 ); + OStringBuffer aStrBuf( arrOUS[4] ); + bool input = true; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_True) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_010() + { + OString expVal( kTestStr50 ); + OStringBuffer aStrBuf( arrOUS[4] ); + bool input = false; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_False) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + +#ifdef WITH_CORE + void append_004_011() + { + OString expVal( kTestStr47 ); + OStringBuffer aStrBuf( kSInt32Max ); + sal_Bool input = sal_True; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_True) to the string buffer(with INT_MAX)", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004_012() + { + OString expVal( kTestStr48 ); + OStringBuffer aStrBuf( kSInt32Max ); + sal_Bool input = sal_False; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Bool(sal_False) to the string buffer(with INT_MAX)", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_004 ); + CPPUNIT_TEST( append_004_001 ); + CPPUNIT_TEST( append_004_002 ); + CPPUNIT_TEST( append_004_003 ); + CPPUNIT_TEST( append_004_004 ); + CPPUNIT_TEST( append_004_005 ); + CPPUNIT_TEST( append_004_006 ); + CPPUNIT_TEST( append_004_007 ); + CPPUNIT_TEST( append_004_008 ); + CPPUNIT_TEST( append_004_009 ); + CPPUNIT_TEST( append_004_010 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_004_011 ); + CPPUNIT_TEST( append_004_012 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append(char c) + + class append_005 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + + } + + void append_001() + { + OString expVal( kTestStr51 ); + OStringBuffer aStrBuf( arrOUS[0] ); + char input = 'M'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(M) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002() + { + OString expVal( kTestStr143 ); + OStringBuffer aStrBuf( arrOUS[0] ); + char input = static_cast<char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Unicode(kSInt8Max) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_003() + { + OString expVal( kTestStr27 ); + OStringBuffer aStrBuf( arrOUS[1] ); + char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(s) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004() + { + OString expVal( kTestStr144 ); + OStringBuffer aStrBuf( arrOUS[1] ); + char input = static_cast<char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(kSInt8Max) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_005_005() + { + OString expVal( kTestStr27 ); + OStringBuffer aStrBuf( arrOUS[2] ); + char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(s) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_006() + { + OString expVal( kTestStr144 ); + OStringBuffer aStrBuf( arrOUS[2] ); + char input = static_cast<char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(kSInt8Max) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_007() + { + OString expVal( kTestStr27 ); + OStringBuffer aStrBuf( arrOUS[3] ); + char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(s) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_008() + { + OString expVal( kTestStr144 ); + OStringBuffer aStrBuf( arrOUS[3] ); + char input = static_cast<char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(kSInt8Max) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_009() + { + OString expVal( kTestStr56 ); + OStringBuffer aStrBuf( arrOUS[4] ); + char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(s) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_010() + { + OString expVal( kTestStr145 ); + OStringBuffer aStrBuf( arrOUS[4] ); + char input = static_cast<char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(kSInt8Max) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + +#ifdef WITH_CORE + void append_011() + { + OString expVal( kTestStr27 ); + OStringBuffer aStrBuf( kSInt32Max ); + char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(s) to the string buffer(with INT_MAX)", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_012() + { + OString expVal( kTestStr144 ); + OStringBuffer aStrBuf( kSInt32Max ); + char input = static_cast<char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the char(kSInt8Max) to the string buffer with INT_MAX)", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_005 ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005_005 ); + CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); + CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); + CPPUNIT_TEST( append_010 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_011 ); + CPPUNIT_TEST( append_012 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + + class append_006_Int32 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_036() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_043() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_044() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_045() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_046() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_047() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_048() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_049() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_050() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_051() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_052() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_053() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_054() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_055() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_056() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_057() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_058() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_059() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_060() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_061() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_062() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_063() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_064() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_065() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_066() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_067() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_068() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_069() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_070() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_071() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_072() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_073() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_074() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_075() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_076() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_077() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_078() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_079() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_080() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_081() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_082() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_083() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_084() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_085() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_086() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_087() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_088() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_089() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_090() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_091() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_092() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_093() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_094() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_095() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_096() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_097() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_098() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_099() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_100() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + CPPUNIT_TEST_SUITE( append_006_Int32 ); + CPPUNIT_TEST( append_001 ); CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); CPPUNIT_TEST( append_030 ); + CPPUNIT_TEST( append_031 ); CPPUNIT_TEST( append_032 ); + CPPUNIT_TEST( append_033 ); CPPUNIT_TEST( append_034 ); + CPPUNIT_TEST( append_035 ); CPPUNIT_TEST( append_036 ); + CPPUNIT_TEST( append_037 ); CPPUNIT_TEST( append_038 ); + CPPUNIT_TEST( append_039 ); CPPUNIT_TEST( append_040 ); + CPPUNIT_TEST( append_041 ); CPPUNIT_TEST( append_042 ); + CPPUNIT_TEST( append_043 ); CPPUNIT_TEST( append_044 ); + CPPUNIT_TEST( append_045 ); CPPUNIT_TEST( append_046 ); + CPPUNIT_TEST( append_047 ); CPPUNIT_TEST( append_048 ); + CPPUNIT_TEST( append_049 ); CPPUNIT_TEST( append_050 ); + CPPUNIT_TEST( append_051 ); CPPUNIT_TEST( append_052 ); + CPPUNIT_TEST( append_053 ); CPPUNIT_TEST( append_054 ); + CPPUNIT_TEST( append_055 ); CPPUNIT_TEST( append_056 ); + CPPUNIT_TEST( append_057 ); CPPUNIT_TEST( append_058 ); + CPPUNIT_TEST( append_059 ); CPPUNIT_TEST( append_060 ); + CPPUNIT_TEST( append_061 ); CPPUNIT_TEST( append_062 ); + CPPUNIT_TEST( append_063 ); CPPUNIT_TEST( append_064 ); + CPPUNIT_TEST( append_065 ); CPPUNIT_TEST( append_066 ); + CPPUNIT_TEST( append_067 ); CPPUNIT_TEST( append_068 ); + CPPUNIT_TEST( append_069 ); CPPUNIT_TEST( append_070 ); + CPPUNIT_TEST( append_071 ); CPPUNIT_TEST( append_072 ); + CPPUNIT_TEST( append_073 ); CPPUNIT_TEST( append_074 ); + CPPUNIT_TEST( append_075 ); CPPUNIT_TEST( append_076 ); + CPPUNIT_TEST( append_077 ); CPPUNIT_TEST( append_078 ); + CPPUNIT_TEST( append_079 ); CPPUNIT_TEST( append_080 ); + CPPUNIT_TEST( append_081 ); CPPUNIT_TEST( append_082 ); + CPPUNIT_TEST( append_083 ); CPPUNIT_TEST( append_084 ); + CPPUNIT_TEST( append_085 ); CPPUNIT_TEST( append_086 ); + CPPUNIT_TEST( append_087 ); CPPUNIT_TEST( append_088 ); + CPPUNIT_TEST( append_089 ); CPPUNIT_TEST( append_090 ); + CPPUNIT_TEST( append_091 ); CPPUNIT_TEST( append_092 ); + CPPUNIT_TEST( append_093 ); CPPUNIT_TEST( append_094 ); + CPPUNIT_TEST( append_095 ); CPPUNIT_TEST( append_096 ); + CPPUNIT_TEST( append_097 ); CPPUNIT_TEST( append_098 ); + CPPUNIT_TEST( append_099 ); CPPUNIT_TEST( append_100 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( sal_Int32 i, sal_Int16 radix=2 ) +// where i = large constants +// testing the method append( sal_Int32 i, sal_Int16 radix=8 ) +// where i = large constants +// testing the method append( sal_Int32 i, sal_Int16 radix=10 ) +// where i = large constants +// testing the method append( sal_Int32 i, sal_Int16 radix=16 ) +// where i = large constants +// testing the method append( sal_Int32 i, sal_Int16 radix=36 ) +// where i = large constants + + class append_006_Int32_Bounderies : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 8; + + expVal += OString( "17777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 10; + + expVal += OString( "2147483647" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 36; + + expVal += OString( "zik0zj" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 8; + + expVal += OString( "17777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 10; + + expVal += OString( "2147483647" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 36; + + expVal += OString( "zik0zj" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 8; + + expVal += OString( "17777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 10; + + expVal += OString( "2147483647" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 36; + + expVal += OString( "zik0zj" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 8; + + expVal += OString( "17777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_036() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 10; + + expVal += OString( "2147483647" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 36; + + expVal += OString( "zik0zj" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_043() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_044() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 8; + + expVal += OString( "17777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_045() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_046() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 10; + + expVal += OString( "2147483647" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_047() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_048() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_049() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_050() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = kSInt32Max; + sal_Int16 radix = 36; + + expVal += OString( "zik0zj" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + CPPUNIT_TEST_SUITE( append_006_Int32_Bounderies ); + CPPUNIT_TEST( append_001 ); CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); CPPUNIT_TEST( append_030 ); + CPPUNIT_TEST( append_031 ); CPPUNIT_TEST( append_032 ); + CPPUNIT_TEST( append_033 ); CPPUNIT_TEST( append_034 ); + CPPUNIT_TEST( append_035 ); CPPUNIT_TEST( append_036 ); + CPPUNIT_TEST( append_037 ); CPPUNIT_TEST( append_038 ); + CPPUNIT_TEST( append_039 ); CPPUNIT_TEST( append_040 ); + CPPUNIT_TEST( append_041 ); CPPUNIT_TEST( append_042 ); + CPPUNIT_TEST( append_043 ); CPPUNIT_TEST( append_044 ); + CPPUNIT_TEST( append_045 ); CPPUNIT_TEST( append_046 ); + CPPUNIT_TEST( append_047 ); CPPUNIT_TEST( append_048 ); + CPPUNIT_TEST( append_049 ); CPPUNIT_TEST( append_050 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( sal_Int32 i, sal_Int16 radix=2 ) +// for negative value +// testing the method append( sal_Int32 i, sal_Int16 radix=8 ) +// for negative value +// testing the method append( sal_Int32 i, sal_Int16 radix=10 ) +// for negative value +// testing the method append( sal_Int32 i, sal_Int16 radix=16 ) +// for negative value +// testing the method append( sal_Int32 i, sal_Int16 radix=36 ) +// for negative value + + class append_006_Int32_Negative : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_036() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_043() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_044() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_045() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_046() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_047() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_048() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_049() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_050() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_051() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_052() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_053() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_054() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_055() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_056() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_057() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_058() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_059() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_060() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_061() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_062() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_063() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_064() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_065() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_066() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_067() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_068() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_069() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_070() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_071() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_072() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_073() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_074() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_075() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_076() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_077() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_078() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_079() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_080() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_081() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_082() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_083() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_084() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_085() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_086() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_087() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_088() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_089() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_090() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_091() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_092() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_093() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_094() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_095() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_096() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_097() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_098() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + } + + void append_099() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + } + + void append_100() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + } + + CPPUNIT_TEST_SUITE( append_006_Int32_Negative ); + CPPUNIT_TEST( append_001 ); CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); CPPUNIT_TEST( append_030 ); + CPPUNIT_TEST( append_031 ); CPPUNIT_TEST( append_032 ); + CPPUNIT_TEST( append_033 ); CPPUNIT_TEST( append_034 ); + CPPUNIT_TEST( append_035 ); CPPUNIT_TEST( append_036 ); + CPPUNIT_TEST( append_037 ); CPPUNIT_TEST( append_038 ); + CPPUNIT_TEST( append_039 ); CPPUNIT_TEST( append_040 ); + CPPUNIT_TEST( append_041 ); CPPUNIT_TEST( append_042 ); + CPPUNIT_TEST( append_043 ); CPPUNIT_TEST( append_044 ); + CPPUNIT_TEST( append_045 ); CPPUNIT_TEST( append_046 ); + CPPUNIT_TEST( append_047 ); CPPUNIT_TEST( append_048 ); + CPPUNIT_TEST( append_049 ); CPPUNIT_TEST( append_050 ); + CPPUNIT_TEST( append_051 ); CPPUNIT_TEST( append_052 ); + CPPUNIT_TEST( append_053 ); CPPUNIT_TEST( append_054 ); + CPPUNIT_TEST( append_055 ); CPPUNIT_TEST( append_056 ); + CPPUNIT_TEST( append_057 ); CPPUNIT_TEST( append_058 ); + CPPUNIT_TEST( append_059 ); CPPUNIT_TEST( append_060 ); + CPPUNIT_TEST( append_061 ); CPPUNIT_TEST( append_062 ); + CPPUNIT_TEST( append_063 ); CPPUNIT_TEST( append_064 ); + CPPUNIT_TEST( append_065 ); CPPUNIT_TEST( append_066 ); + CPPUNIT_TEST( append_067 ); CPPUNIT_TEST( append_068 ); + CPPUNIT_TEST( append_069 ); CPPUNIT_TEST( append_070 ); + CPPUNIT_TEST( append_071 ); CPPUNIT_TEST( append_072 ); + CPPUNIT_TEST( append_073 ); CPPUNIT_TEST( append_074 ); + CPPUNIT_TEST( append_075 ); CPPUNIT_TEST( append_076 ); + CPPUNIT_TEST( append_077 ); CPPUNIT_TEST( append_078 ); + CPPUNIT_TEST( append_079 ); CPPUNIT_TEST( append_080 ); + CPPUNIT_TEST( append_081 ); CPPUNIT_TEST( append_082 ); + CPPUNIT_TEST( append_083 ); CPPUNIT_TEST( append_084 ); + CPPUNIT_TEST( append_085 ); CPPUNIT_TEST( append_086 ); + CPPUNIT_TEST( append_087 ); CPPUNIT_TEST( append_088 ); + CPPUNIT_TEST( append_089 ); CPPUNIT_TEST( append_090 ); + CPPUNIT_TEST( append_091 ); CPPUNIT_TEST( append_092 ); + CPPUNIT_TEST( append_093 ); CPPUNIT_TEST( append_094 ); + CPPUNIT_TEST( append_095 ); CPPUNIT_TEST( append_096 ); + CPPUNIT_TEST( append_097 ); CPPUNIT_TEST( append_098 ); + CPPUNIT_TEST( append_099 ); CPPUNIT_TEST( append_100 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class append_006_Int32_defaultParam : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr59 ); + sal_Int32 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 11 and return OStringBuffer[0]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr62 ); + sal_Int32 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 0 and return OStringBuffer[0]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr63 ); + sal_Int32 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -11 and return OStringBuffer[0]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr64 ); + sal_Int32 input = 2147483647; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 2147483647 and return OStringBuffer[0]+2147483647", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr65 ); + sal_Int32 input = kNonSInt32Max; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -2147483648 and return OStringBuffer[0]+(-2147483648)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr60 ); + sal_Int32 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 11 and return OStringBuffer[1]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr66 ); + sal_Int32 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 0 and return OStringBuffer[1]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr67 ); + sal_Int32 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -11 and return OStringBuffer[1]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr68 ); + sal_Int32 input = 2147483647; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 2147483647 and return OStringBuffer[1]+2147483647", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr69 ); + sal_Int32 input = SAL_MIN_INT32 /*-2147483648*/; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -2147483648 and return OStringBuffer[1]+(-2147483648)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr60 ); + sal_Int32 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 11 and return OStringBuffer[2]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr66 ); + sal_Int32 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 0 and return OUStringBuffer[2]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr67 ); + sal_Int32 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -11 and return OUStringBuffer[2]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr68 ); + sal_Int32 input = 2147483647; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 2147483647 and return OStringBuffer[2]+2147483647", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr69 ); + sal_Int32 input = SAL_MIN_INT32; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -2147483648 and return OStringBuffer[2]+(-2147483648)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr60 ); + sal_Int32 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 11 and return OStringBuffer[3]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr66 ); + sal_Int32 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 0 and return OStringBuffer[3]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr67 ); + sal_Int32 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -11 and return OStringBuffer[3]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr68 ); + sal_Int32 input = 2147483647; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 2147483647 and return OStringBuffer[3]+2147483647", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr69 ); + sal_Int32 input = SAL_MIN_INT32; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -2147483648 and return OStringBuffer[3]+(-2147483648)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr61 ); + sal_Int32 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 11 and return OStringBuffer[4]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr70 ); + sal_Int32 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 0 and return OStringBuffer[4]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr71 ); + sal_Int32 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -11 and return OStringBuffer[4]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr72 ); + sal_Int32 input = 2147483647; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 2147483647 and return OStringBuffer[4]+2147483647", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr73 ); + sal_Int32 input = SAL_MIN_INT32; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -2147483648 and return OStringBuffer[4]+(-2147483648)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } +#ifdef WITH_CORE + void append_026() + { + OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr60 ); + sal_Int32 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 11 and return OStringBuffer(kSInt32Max)+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr66 ); + sal_Int32 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 0 and return OStringBuffer(kSInt32Max)+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr67 ); + sal_Int32 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -11 and return OStringBuffer(kSInt32Max)+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr68 ); + sal_Int32 input = 2147483647; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 2147483647 and return OStringBuffer(kSInt32Max)+2147483647", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr69 ); + sal_Int32 input = SAL_MIN_INT32; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int32 -2147483648 and return OStringBuffer(kSInt32Max)+(-2147483648)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_006_Int32_defaultParam ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); + CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); + CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); + CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); + CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); + CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); + CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); + CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); + CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); + CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); + CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); + CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); + CPPUNIT_TEST( append_030 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( sal_Int64 l, sal_Int16 radix=2 ) +// testing the method append( sal_Int64 l, sal_Int16 radix=8 ) +// testing the method append( sal_Int64 l, sal_Int16 radix=10 ) +// testing the method append( sal_Int64 l, sal_Int16 radix=16 ) +// testing the method append( sal_Int64 l, sal_Int16 radix=36 ) + + class append_007_Int64 : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_036() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_043() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_044() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_045() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_046() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_047() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_048() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_049() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_050() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_051() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_052() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_053() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_054() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_055() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_056() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_057() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_058() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_059() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_060() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_061() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_062() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_063() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_064() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_065() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_066() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_067() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_068() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_069() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_070() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_071() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_072() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_073() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_074() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_075() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_076() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_077() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_078() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_079() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_080() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_081() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_082() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 2; + + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_083() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 2; + + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_084() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 2; + + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_085() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_086() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 8; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_087() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 8; + + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_088() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 8; + + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_089() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_090() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 10; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_091() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 10; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_092() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 10; + + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_093() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_094() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 16; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_095() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 16; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_096() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 15; + sal_Int16 radix = 16; + + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_097() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_098() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 4; + sal_Int16 radix = 36; + + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_099() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 8; + sal_Int16 radix = 36; + + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_100() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = 35; + sal_Int16 radix = 36; + + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + CPPUNIT_TEST_SUITE( append_007_Int64 ); + CPPUNIT_TEST( append_001 ); CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); CPPUNIT_TEST( append_030 ); + CPPUNIT_TEST( append_031 ); CPPUNIT_TEST( append_032 ); + CPPUNIT_TEST( append_033 ); CPPUNIT_TEST( append_034 ); + CPPUNIT_TEST( append_035 ); CPPUNIT_TEST( append_036 ); + CPPUNIT_TEST( append_037 ); CPPUNIT_TEST( append_038 ); + CPPUNIT_TEST( append_039 ); CPPUNIT_TEST( append_040 ); + CPPUNIT_TEST( append_041 ); CPPUNIT_TEST( append_042 ); + CPPUNIT_TEST( append_043 ); CPPUNIT_TEST( append_044 ); + CPPUNIT_TEST( append_045 ); CPPUNIT_TEST( append_046 ); + CPPUNIT_TEST( append_047 ); CPPUNIT_TEST( append_048 ); + CPPUNIT_TEST( append_049 ); CPPUNIT_TEST( append_050 ); + CPPUNIT_TEST( append_051 ); CPPUNIT_TEST( append_052 ); + CPPUNIT_TEST( append_053 ); CPPUNIT_TEST( append_054 ); + CPPUNIT_TEST( append_055 ); CPPUNIT_TEST( append_056 ); + CPPUNIT_TEST( append_057 ); CPPUNIT_TEST( append_058 ); + CPPUNIT_TEST( append_059 ); CPPUNIT_TEST( append_060 ); + CPPUNIT_TEST( append_061 ); CPPUNIT_TEST( append_062 ); + CPPUNIT_TEST( append_063 ); CPPUNIT_TEST( append_064 ); + CPPUNIT_TEST( append_065 ); CPPUNIT_TEST( append_066 ); + CPPUNIT_TEST( append_067 ); CPPUNIT_TEST( append_068 ); + CPPUNIT_TEST( append_069 ); CPPUNIT_TEST( append_070 ); + CPPUNIT_TEST( append_071 ); CPPUNIT_TEST( append_072 ); + CPPUNIT_TEST( append_073 ); CPPUNIT_TEST( append_074 ); + CPPUNIT_TEST( append_075 ); CPPUNIT_TEST( append_076 ); + CPPUNIT_TEST( append_077 ); CPPUNIT_TEST( append_078 ); + CPPUNIT_TEST( append_079 ); CPPUNIT_TEST( append_080 ); + CPPUNIT_TEST( append_081 ); CPPUNIT_TEST( append_082 ); + CPPUNIT_TEST( append_083 ); CPPUNIT_TEST( append_084 ); + CPPUNIT_TEST( append_085 ); CPPUNIT_TEST( append_086 ); + CPPUNIT_TEST( append_087 ); CPPUNIT_TEST( append_088 ); + CPPUNIT_TEST( append_089 ); CPPUNIT_TEST( append_090 ); + CPPUNIT_TEST( append_091 ); CPPUNIT_TEST( append_092 ); + CPPUNIT_TEST( append_093 ); CPPUNIT_TEST( append_094 ); + CPPUNIT_TEST( append_095 ); CPPUNIT_TEST( append_096 ); + CPPUNIT_TEST( append_097 ); CPPUNIT_TEST( append_098 ); + CPPUNIT_TEST( append_099 ); CPPUNIT_TEST( append_100 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( sal_Int64 i, sal_Int16 radix=2 ) +// where i = large constants +// testing the method append( sal_Int64 i, sal_Int16 radix=8 ) +// where i = large constants +// testing the method append( sal_Int64 i, sal_Int16 radix=10 ) +// where i = large constants +// testing the method append( sal_Int64 i, sal_Int16 radix=16 ) +// where i = large constants +// testing the method append( sal_Int64 i, sal_Int16 radix=36 ) +// where i = large constants + + class append_007_Int64_Bounderies : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 2; + + expVal += OString( "111111111111111111111111111111111111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 8; + + expVal += OString( "777777777777777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 10; + + expVal += OString( "9223372036854775807" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffffffffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 36; + + expVal += OString( "1y2p0ij32e8e7" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 2; + + expVal += OString( "111111111111111111111111111111111111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 8; + + expVal += OString( "777777777777777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 10; + + expVal += OString( "9223372036854775807" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffffffffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 36; + + expVal += OString( "1y2p0ij32e8e7" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 2; + + expVal += OString( "111111111111111111111111111111111111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 8; + + expVal += OString( "777777777777777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 10; + + expVal += OString( "9223372036854775807" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffffffffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 36; + + expVal += OString( "1y2p0ij32e8e7" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 2; + + expVal += OString( "111111111111111111111111111111111111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 8; + + expVal += OString( "777777777777777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_036() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 10; + + expVal += OString( "9223372036854775807" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffffffffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 36; + + expVal += OString( "1y2p0ij32e8e7" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 2; + + expVal += OString( "1111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 2; + + expVal += OString( "111111111111111111111111111111111111111111111111111111111111111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_043() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 8; + + expVal += OString( "177" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_044() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 8; + + expVal += OString( "777777777777777777777" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_045() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 10; + + expVal += OString( "127" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_046() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 10; + + expVal += OString( "9223372036854775807" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_047() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 16; + + expVal += OString( "7f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_048() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 16; + + expVal += OString( "7fffffffffffffff" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_049() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt8Max; + sal_Int16 radix = 36; + + expVal += OString( "3j" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_050() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = kSInt64Max; + sal_Int16 radix = 36; + + expVal += OString( "1y2p0ij32e8e7" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_Bounderies_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + CPPUNIT_TEST_SUITE( append_007_Int64_Bounderies ); + CPPUNIT_TEST( append_001 ); CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); CPPUNIT_TEST( append_030 ); + CPPUNIT_TEST( append_031 ); CPPUNIT_TEST( append_032 ); + CPPUNIT_TEST( append_033 ); CPPUNIT_TEST( append_034 ); + CPPUNIT_TEST( append_035 ); CPPUNIT_TEST( append_036 ); + CPPUNIT_TEST( append_037 ); CPPUNIT_TEST( append_038 ); + CPPUNIT_TEST( append_039 ); CPPUNIT_TEST( append_040 ); + CPPUNIT_TEST( append_041 ); CPPUNIT_TEST( append_042 ); + CPPUNIT_TEST( append_043 ); CPPUNIT_TEST( append_044 ); + CPPUNIT_TEST( append_045 ); CPPUNIT_TEST( append_046 ); + CPPUNIT_TEST( append_047 ); CPPUNIT_TEST( append_048 ); + CPPUNIT_TEST( append_049 ); CPPUNIT_TEST( append_050 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( sal_Int64 i, sal_Int16 radix=2 ) +// for negative value +// testing the method append( sal_Int64 i, sal_Int16 radix=8 ) +// for negative value +// testing the method append( sal_Int64 i, sal_Int16 radix=10 ) +// for negative value +// testing the method append( sal_Int64 i, sal_Int16 radix=16 ) +// for negative value +// testing the method append( sal_Int64 i, sal_Int16 radix=36 ) +// for negative value + + class append_007_Int64_Negative : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_036() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[1]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_043() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_044() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_045() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_046() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_047() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_048() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_049() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_050() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_051() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_052() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_053() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_054() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_055() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_056() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_057() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_058() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_059() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_060() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[2]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_061() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_062() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_063() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_064() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_065() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_066() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_067() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_068() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_069() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_070() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_071() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_072() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_073() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_074() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_075() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_076() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_077() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_078() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_079() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_080() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[3]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_081() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_082() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "100" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_083() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1000" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_084() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 2; + + expVal += OString( "-" ); + expVal += OString( "1111" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 2)_006_negative_kRadixBinary for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_085() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 8; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_086() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_087() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "10" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_088() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 8; + + expVal += OString( "-" ); + expVal += OString( "17" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 8)_006_negative_kRadixOctol for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_089() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 10; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_090() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_091() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_092() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 10; + + expVal += OString( "-" ); + expVal += OString( "15" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 10)_006_negative_kRadixDecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_093() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 16; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_094() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_095() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_096() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -15; + sal_Int16 radix = 16; + + expVal += OString( "-" ); + expVal += OString( "f" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 16)_006_negative_kRadixHexdecimal for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_097() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -0; + sal_Int16 radix = 36; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_098() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -4; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "4" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_099() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -8; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "8" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_100() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( aStrBuf.getStr() ); + sal_Int64 input = -35; + sal_Int16 radix = 36; + + expVal += OString( "-" ); + expVal += OString( "z" ); + aStrBuf.append( input, radix ); + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int64, radix 36)_006_negative_kRadixBase36 for arrOUS[4]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + CPPUNIT_TEST_SUITE( append_007_Int64_Negative ); + CPPUNIT_TEST( append_001 ); CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); CPPUNIT_TEST( append_030 ); + CPPUNIT_TEST( append_031 ); CPPUNIT_TEST( append_032 ); + CPPUNIT_TEST( append_033 ); CPPUNIT_TEST( append_034 ); + CPPUNIT_TEST( append_035 ); CPPUNIT_TEST( append_036 ); + CPPUNIT_TEST( append_037 ); CPPUNIT_TEST( append_038 ); + CPPUNIT_TEST( append_039 ); CPPUNIT_TEST( append_040 ); + CPPUNIT_TEST( append_041 ); CPPUNIT_TEST( append_042 ); + CPPUNIT_TEST( append_043 ); CPPUNIT_TEST( append_044 ); + CPPUNIT_TEST( append_045 ); CPPUNIT_TEST( append_046 ); + CPPUNIT_TEST( append_047 ); CPPUNIT_TEST( append_048 ); + CPPUNIT_TEST( append_049 ); CPPUNIT_TEST( append_050 ); + CPPUNIT_TEST( append_051 ); CPPUNIT_TEST( append_052 ); + CPPUNIT_TEST( append_053 ); CPPUNIT_TEST( append_054 ); + CPPUNIT_TEST( append_055 ); CPPUNIT_TEST( append_056 ); + CPPUNIT_TEST( append_057 ); CPPUNIT_TEST( append_058 ); + CPPUNIT_TEST( append_059 ); CPPUNIT_TEST( append_060 ); + CPPUNIT_TEST( append_061 ); CPPUNIT_TEST( append_062 ); + CPPUNIT_TEST( append_063 ); CPPUNIT_TEST( append_064 ); + CPPUNIT_TEST( append_065 ); CPPUNIT_TEST( append_066 ); + CPPUNIT_TEST( append_067 ); CPPUNIT_TEST( append_068 ); + CPPUNIT_TEST( append_069 ); CPPUNIT_TEST( append_070 ); + CPPUNIT_TEST( append_071 ); CPPUNIT_TEST( append_072 ); + CPPUNIT_TEST( append_073 ); CPPUNIT_TEST( append_074 ); + CPPUNIT_TEST( append_075 ); CPPUNIT_TEST( append_076 ); + CPPUNIT_TEST( append_077 ); CPPUNIT_TEST( append_078 ); + CPPUNIT_TEST( append_079 ); CPPUNIT_TEST( append_080 ); + CPPUNIT_TEST( append_081 ); CPPUNIT_TEST( append_082 ); + CPPUNIT_TEST( append_083 ); CPPUNIT_TEST( append_084 ); + CPPUNIT_TEST( append_085 ); CPPUNIT_TEST( append_086 ); + CPPUNIT_TEST( append_087 ); CPPUNIT_TEST( append_088 ); + CPPUNIT_TEST( append_089 ); CPPUNIT_TEST( append_090 ); + CPPUNIT_TEST( append_091 ); CPPUNIT_TEST( append_092 ); + CPPUNIT_TEST( append_093 ); CPPUNIT_TEST( append_094 ); + CPPUNIT_TEST( append_095 ); CPPUNIT_TEST( append_096 ); + CPPUNIT_TEST( append_097 ); CPPUNIT_TEST( append_098 ); + CPPUNIT_TEST( append_099 ); CPPUNIT_TEST( append_100 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class append_007_Int64_defaultParam : public CppUnit::TestFixture + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr59 ); + sal_Int64 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 11 and return OStringBuffer[0]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr62 ); + sal_Int64 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 0 and return OStringBuffer[0]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr63 ); + sal_Int64 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -11 and return OStringBuffer[0]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr116 ); + sal_Int64 input = SAL_CONST_INT64(9223372036854775807); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[0]+9223372036854775807", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + OString expVal( kTestStr117 ); + sal_Int64 input = SAL_MIN_INT64/*-9223372036854775808*/; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + bool bRes = expVal == aStrBuf.getStr(); + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer[0]+(-9223372036854775808)", + bRes && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr60 ); + sal_Int64 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 11 and return OStringBuffer[1]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr66 ); + sal_Int64 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 0 and return OStringBuffer[1]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr67 ); + sal_Int64 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -11 and return OStringBuffer[1]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr118 ); + sal_Int64 input = SAL_CONST_INT64(9223372036854775807); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[1]+9223372036854775807", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[1] ); + OString expVal( kTestStr119 ); + sal_Int64 input = SAL_MIN_INT64; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer[1]+(-9223372036854775808)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr60 ); + sal_Int64 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 11 and return OStringBuffer[2]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr66 ); + sal_Int64 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 0 and return OUStringBuffer[2]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr67 ); + sal_Int64 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -11 and return OUStringBuffer[2]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr118 ); + sal_Int64 input = SAL_CONST_INT64(9223372036854775807); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[2]+9223372036854775807", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[2] ); + OString expVal( kTestStr119 ); + sal_Int64 input = SAL_MIN_INT64; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer[2]+(-9223372036854775808)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr60 ); + sal_Int64 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 11 and return OStringBuffer[3]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr66 ); + sal_Int64 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 0 and return OStringBuffer[3]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr67 ); + sal_Int64 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -11 and return OStringBuffer[3]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr118 ); + sal_Int64 input = SAL_CONST_INT64(9223372036854775807); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[3]+9223372036854775807", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[3] ); + OString expVal( kTestStr119 ); + sal_Int64 input = SAL_MIN_INT64; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer[3]+(-9223372036854775808)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr61 ); + sal_Int64 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 11 and return OStringBuffer[4]+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr70 ); + sal_Int64 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 0 and return OStringBuffer[4]+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr71 ); + sal_Int64 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -11 and return OStringBuffer[4]+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr120 ); + sal_Int64 input = SAL_CONST_INT64(9223372036854775807); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[4]+9223372036854775807", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[4] ); + OString expVal( kTestStr121 ); + sal_Int64 input = SAL_MIN_INT64; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer[4]+(-9223372036854775808)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } +#ifdef WITH_CORE + void append_026() + { + OStringBuffer aStrBuf( kSInt64Max ); + OString expVal( kTestStr60 ); + sal_Int64 input = 11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 11 and return OStringBuffer(kSInt64Max)+11", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_027() + { + OStringBuffer aStrBuf( kSInt64Max ); + OString expVal( kTestStr66 ); + sal_Int64 input = 0; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 0 and return OStringBuffer(kSInt64Max)+0", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_028() + { + OStringBuffer aStrBuf( kSInt64Max ); + OString expVal( kTestStr67 ); + sal_Int64 input = -11; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -11 and return OStringBuffer(kSInt64Max)+(-11)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_029() + { + OStringBuffer aStrBuf( kSInt64Max ); + OString expVal( kTestStr118 ); + sal_Int64 input = 9223372036854775807; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer(kSInt64Max)+9223372036854775807", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } + + void append_030() + { + OStringBuffer aStrBuf( kSInt64Max ); + OString expVal( kTestStr119 ); + sal_Int64 input = SAL_MIN_INT64; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer(kSInt64Max)+(-9223372036854775808)", + (aStrBuf.toString() == expVal && + aStrBuf.getLength() == expVal.getLength()) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_007_Int64_defaultParam ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); + CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); + CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); + CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); + CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); + CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); + CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); + CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); + CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); + CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); + CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); + CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); + CPPUNIT_TEST( append_030 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( float f ) + + class checkfloat : public CppUnit::TestFixture + { + public: + bool checkIfStrBufContainAtPosTheFloat(OStringBuffer const& _sStrBuf, sal_Int32 _nLen, float _nFloat) + { + OString sFloatValue = OString::number(_nFloat); + + OString sBufferString(_sStrBuf.getStr()); + sal_Int32 nPos = sBufferString.indexOf(sFloatValue); + return nPos >= 0 && nPos == _nLen; + } + }; + + class append_008_float : public checkfloat + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.0")); + + // LLA: + // the complex problem is here, that a float value is not really what we write. + // So a 3.0 could also be 3 or 3.0 or 3.0000001 or 2.9999999 + // this has to be checked. + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.141592")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.5025255")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("3.00390625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.141592")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.5025255")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("3.00390625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.141592")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.5025255")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("3.00390625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + +#ifdef WITH_CORE + void append_036() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.0"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.5"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.0625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.502525"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.141592"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.5025255"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("3.00390625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_008_float ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); + CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); + CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); + CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); + CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); + CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); + CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); + CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); + CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); + CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); + CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); + CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); + CPPUNIT_TEST( append_030 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( float f ) for negative value + + class append_008_Float_Negative : public checkfloat + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_002() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_003() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_004() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_005() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.141592")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_006() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.5025255")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_007() + { + OStringBuffer aStrBuf( arrOUS[0] ); + float input = static_cast<float>(atof("-3.00390625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_008() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_009() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_010() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_011() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_012() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.141592")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_013() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.5025255")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_014() + { + OStringBuffer aStrBuf( arrOUS[1] ); + float input = static_cast<float>(atof("-3.00390625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_015() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_016() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_017() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_018() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_019() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.141592")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_020() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.5025255")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_021() + { + OStringBuffer aStrBuf( arrOUS[2] ); + float input = static_cast<float>(atof("-3.00390625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_022() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("-3.0")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_023() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("-3.5")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_024() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("-3.0625")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_025() + { + OStringBuffer aStrBuf( arrOUS[3] ); + float input = static_cast<float>(atof("-3.502525")); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + +#ifdef WITH_CORE + void append_036() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.0"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_037() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.5"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_038() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.0625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_039() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.502525"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_040() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.141592"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_041() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.5025255"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_042() + { + OStringBuffer aStrBuf( kSInt32Max ); + float input = (float)atof("-3.00390625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_008_Float_Negative ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); + CPPUNIT_TEST( append_006 ); + CPPUNIT_TEST( append_007 ); + CPPUNIT_TEST( append_008 ); + CPPUNIT_TEST( append_009 ); + CPPUNIT_TEST( append_010 ); + CPPUNIT_TEST( append_011 ); + CPPUNIT_TEST( append_012 ); + CPPUNIT_TEST( append_013 ); + CPPUNIT_TEST( append_014 ); + CPPUNIT_TEST( append_015 ); + CPPUNIT_TEST( append_016 ); + CPPUNIT_TEST( append_017 ); + CPPUNIT_TEST( append_018 ); + CPPUNIT_TEST( append_019 ); + CPPUNIT_TEST( append_020 ); + CPPUNIT_TEST( append_021 ); + CPPUNIT_TEST( append_022 ); + CPPUNIT_TEST( append_023 ); + CPPUNIT_TEST( append_024 ); + CPPUNIT_TEST( append_025 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_026 ); + CPPUNIT_TEST( append_027 ); + CPPUNIT_TEST( append_028 ); + CPPUNIT_TEST( append_029 ); + CPPUNIT_TEST( append_030 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( double d ) + + class checkdouble : public CppUnit::TestFixture + { + public: + bool checkIfStrBufContainAtPosTheDouble(OStringBuffer const& _sStrBuf, sal_Int32 _nLen, double _nDouble) + { + OString sDoubleValue = OString::number(_nDouble); + + OString sBufferString(_sStrBuf.getStr()); + sal_Int32 nPos = sBufferString.indexOf(sDoubleValue); + return nPos >= 0 && nPos == _nLen; + } + }; + + class append_009_double : public checkdouble + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + double input = atof("3.0"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.0", + checkIfStrBufContainAtPosTheDouble(aStrBuf, nLen, input) + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[4] ); + double input = atof("3.141592653589793238462643"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.141592653589793238462643", + checkIfStrBufContainAtPosTheDouble(aStrBuf, nLen, input) + ); + + } + + CPPUNIT_TEST_SUITE( append_009_double ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_035 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// testing the method append( double f ) for negative value + + class append_009_Double_Negative : public checkdouble + { + OString arrOUS[5]; + + public: + void setUp() override + { + arrOUS[0] = OString( kTestStr7 ); + arrOUS[1] = OString( ); + arrOUS[2] = OString( kTestStr25 ); + arrOUS[3] = OString( "" ); + arrOUS[4] = OString( kTestStr28 ); + } + + void append_001() + { + OStringBuffer aStrBuf( arrOUS[0] ); + double input = atof("-3.0"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.0", + checkIfStrBufContainAtPosTheDouble(aStrBuf, nLen, input) + ); + + } + + void append_035() + { + OStringBuffer aStrBuf( arrOUS[4] ); + double input = atof("-3.141592653589793238462643"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.141592653589793238462643", + checkIfStrBufContainAtPosTheDouble(aStrBuf, nLen, input) + ); + + } + + CPPUNIT_TEST_SUITE( append_009_Double_Negative ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_035 ); + CPPUNIT_TEST_SUITE_END(); + }; + + class AppendUninitialized: public CppUnit::TestFixture { + private: + void testEmpty(); + + void testNonEmpty(); + + void testZero(); + + CPPUNIT_TEST_SUITE(AppendUninitialized); + CPPUNIT_TEST(testEmpty); + CPPUNIT_TEST(testNonEmpty); + CPPUNIT_TEST(testZero); + CPPUNIT_TEST_SUITE_END(); + }; + + void AppendUninitialized::testEmpty() { + OStringBuffer s; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + char * p = s.appendUninitialized(5); + CPPUNIT_ASSERT_EQUAL( + static_cast<void const *>(s.getStr()), + static_cast<void const *>(p)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength()); + } + + void AppendUninitialized::testNonEmpty() { + OStringBuffer s("ab"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s.getLength()); + char * p = s.appendUninitialized(5); + CPPUNIT_ASSERT_EQUAL( + static_cast<void const *>(s.getStr() + 2), + static_cast<void const *>(p)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength()); + } + + void AppendUninitialized::testZero() { + OStringBuffer s; + char * p = s.appendUninitialized(0); + CPPUNIT_ASSERT_EQUAL( + static_cast<void const *>(s.getStr()), + static_cast<void const *>(p)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + } +} // namespace rtl_OStringBuffer + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::ctors); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::makeStringAndClear); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::getLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::getCapacity); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::ensureCapacity); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::setLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::csuc); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::getStr); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_001); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_002); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_003); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_004); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_005); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_Bounderies); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_Negative); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_006_Int32_defaultParam); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_Bounderies); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_Negative); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_007_Int64_defaultParam); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_008_float); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_008_Float_Negative); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_009_double); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_009_Double_Negative); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::AppendUninitialized); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::remove); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/OStringBuffer/rtl_String_Const.h b/sal/qa/OStringBuffer/rtl_String_Const.h new file mode 100644 index 000000000..1abdefefc --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_String_Const.h @@ -0,0 +1,468 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSTRINGBUFFER_RTL_STRING_CONST_H +#define INCLUDED_SAL_QA_OSTRINGBUFFER_RTL_STRING_CONST_H + +#include <limits.h> +#include <sal/types.h> +#include <rtl/textenc.h> +#include <rtl/ustring.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +static const rtl_TextEncoding kEncodingRTLTextUSASCII = RTL_TEXTENCODING_ASCII_US; + +static const sal_uInt32 kConvertFlagsOUStringToOString = OUSTRING_TO_OSTRING_CVTFLAGS; +static const sal_uInt32 kConvertFlagsOStringToOUString = OSTRING_TO_OUSTRING_CVTFLAGS; + +static const char * const kTestStr1 = "Sun Microsystems"; +static const char * const kTestStr2 = "Sun Microsystems Java Technology"; +static const char * const kTestStr7 = "Sun "; +static const char * const kTestStr8 = "Microsystems"; +static const char * const kTestStr14 = " Sun Microsystems"; +static const char * const kTestStr17 = " Sun Microsystems "; +static const char * const kTestStr23 = " Java Technology"; +static const char * const kTestStr25 = ""; +static const char * const kTestStr27 = "s"; +static const char * const kTestStr28 = "\50\3\5\7\11\13\15\17sun"; +static const char * const kTestStr29 = "\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50"; +static const char * const kTestStr31 = "sun Microsystems"; +static const char * const kTestStr36 = "Microsystems Java Technology"; +static const char * const kTestStr37 = "Sun Java Technology"; +static const char * const kTestStr38 = "\21\23\25\27\31\33\50"; +static const char * const kTestStr39 = "\50\3\5\7\11\13\15\17sun Sun Microsystems "; +static const char * const kTestStr40 = "\50\3\5\7\11\13\15\17sunsun Microsystems"; +static const char * const kTestStr45 = "Sun true"; +static const char * const kTestStr46 = "Sun false"; +static const char * const kTestStr47 = "true"; +static const char * const kTestStr48 = "false"; +static const char * const kTestStr49 = "\50\3\5\7\11\13\15\17suntrue"; +static const char * const kTestStr50 = "\50\3\5\7\11\13\15\17sunfalse"; +static const char * const kTestStr51 = "Sun M"; +//static const char *kTestStr52 = "Sun \077777"; +//static const char *kTestStr53 = "Sun \100000"; +//static const char *kTestStr54 = "\77777"; +//static const char *kTestStr55 = "\100000"; +static const char * const kTestStr56 = "\50\3\5\7\11\13\15\17suns"; +//static const char *kTestStr57 = "\50\3\5\7\11\13\15\17sun\77777"; +//static const char *kTestStr58 = "\50\3\5\7\11\13\15\17sun\10000"; +static const char * const kTestStr59 = "Sun 11"; +static const char * const kTestStr60 = "11"; +static const char * const kTestStr61 = "\50\3\5\7\11\13\15\17sun11"; +static const char * const kTestStr62 = "Sun 0"; +static const char * const kTestStr63 = "Sun -11"; +static const char * const kTestStr64 = "Sun 2147483647"; +static const char * const kTestStr65 = "Sun -2147483648"; +static const char * const kTestStr66 = "0"; +static const char * const kTestStr67 = "-11"; +static const char * const kTestStr68 = "2147483647"; +static const char * const kTestStr69 = "-2147483648"; +static const char * const kTestStr70 = "\50\3\5\7\11\13\15\17sun0"; +static const char * const kTestStr71 = "\50\3\5\7\11\13\15\17sun-11"; +static const char * const kTestStr72 = "\50\3\5\7\11\13\15\17sun2147483647"; +static const char * const kTestStr73 = "\50\3\5\7\11\13\15\17sun-2147483648"; +static const char * const kTestStr116 = "Sun 9223372036854775807"; +static const char * const kTestStr117 = "Sun -9223372036854775808"; +static const char * const kTestStr118 = "9223372036854775807"; +static const char * const kTestStr119 = "-9223372036854775808"; +static const char * const kTestStr120 = "\50\3\5\7\11\13\15\17sun9223372036854775807"; +static const char * const kTestStr121 = "\50\3\5\7\11\13\15\17sun-9223372036854775808"; +static const char * const kTestStr143 = "Sun \377"; +static const char * const kTestStr144 = "\377"; +static const char * const kTestStr145 = "\50\3\5\7\11\13\15\17sun\377"; + +static const sal_Int32 kTestStr1Len = 16; +static const sal_Int32 kTestStr2Len = 32; +static const sal_Int32 kTestStr3Len = 16; +static const sal_Int32 kTestStr4Len = 16; +static const sal_Int32 kTestStr5Len = 16; +static const sal_Int32 kTestStr6Len = 15; +static const sal_Int32 kTestStr7Len = 4; +static const sal_Int32 kTestStr8Len = 12; +static const sal_Int32 kTestStr9Len = 32; +static const sal_Int32 kTestStr10Len = 17; +static const sal_Int32 kTestStr11Len = 17; +static const sal_Int32 kTestStr12Len = 18; +static const sal_Int32 kTestStr13Len = 19; +static const sal_Int32 kTestStr14Len = 19; +static const sal_Int32 kTestStr15Len = 20; +static const sal_Int32 kTestStr16Len = 20; +static const sal_Int32 kTestStr17Len = 22; +static const sal_Int32 kTestStr18Len = 16; +static const sal_Int32 kTestStr19Len = 22; +static const sal_Int32 kTestStr20Len = 3; +static const sal_Int32 kTestStr21Len = 3; +static const sal_Int32 kTestStr22Len = 32; +static const sal_Int32 kTestStr23Len = 16; +static const sal_Int32 kTestStr24Len = 31; +static const sal_Int32 kTestStr25Len = 0; +static const sal_Int32 kTestStr26Len = 4; +static const sal_Int32 kTestStr27Len = 1; +static const sal_Int32 kTestStr28Len = 11; +static const sal_Int32 kTestStr29Len = 18; +static const sal_Int32 kTestStr30Len = 10; +static const sal_Int32 kTestStr31Len = 16; +static const sal_Int32 kTestStr32Len = 16; +static const sal_Int32 kTestStr33Len = 1; +static const sal_Int32 kTestStr34Len = 11; +static const sal_Int32 kTestStr35Len = 11; +static const sal_Int32 kTestStr36Len = 28; +static const sal_Int32 kTestStr37Len = 20; +static const sal_Int32 kTestStr38Len = 7; +static const sal_Int32 kTestStr39Len = 33; +static const sal_Int32 kTestStr40Len = 27; +static const sal_Int32 kTestStr41Len = 3; +static const sal_Int32 kTestStr42Len = 10; +static const sal_Int32 kTestStr43Len = 13; +static const sal_Int32 kTestStr44Len = 2; +static const sal_Int32 kTestStr45Len = 8; +static const sal_Int32 kTestStr46Len = 9; +static const sal_Int32 kTestStr47Len = 4; +static const sal_Int32 kTestStr48Len = 5; +static const sal_Int32 kTestStr49Len = 15; +static const sal_Int32 kTestStr50Len = 16; +static const sal_Int32 kTestStr51Len = 5; +static const sal_Int32 kTestStr52Len = 5; +static const sal_Int32 kTestStr53Len = 5; +static const sal_Int32 kTestStr54Len = 1; +static const sal_Int32 kTestStr55Len = 1; +static const sal_Int32 kTestStr56Len = 12; +static const sal_Int32 kTestStr57Len = 12; +static const sal_Int32 kTestStr58Len = 12; +static const sal_Int32 kTestStr59Len = 6; +static const sal_Int32 kTestStr60Len = 2; +static const sal_Int32 kTestStr61Len = 13; +static const sal_Int32 kTestStr62Len = 5; +static const sal_Int32 kTestStr63Len = 7; +static const sal_Int32 kTestStr64Len = 14; +static const sal_Int32 kTestStr65Len = 15; +static const sal_Int32 kTestStr66Len = 1; +static const sal_Int32 kTestStr67Len = 3; +static const sal_Int32 kTestStr68Len = 10; +static const sal_Int32 kTestStr69Len = 11; +static const sal_Int32 kTestStr70Len = 12; +static const sal_Int32 kTestStr71Len = 14; +static const sal_Int32 kTestStr72Len = 21; +static const sal_Int32 kTestStr73Len = 22; +static const sal_Int32 kTestStr74Len = 7; +static const sal_Int32 kTestStr75Len = 7; +static const sal_Int32 kTestStr76Len = 10; +static const sal_Int32 kTestStr77Len = 12; +static const sal_Int32 kTestStr78Len = 12; +static const sal_Int32 kTestStr79Len = 13; +static const sal_Int32 kTestStr80Len = 13; +static const sal_Int32 kTestStr81Len = 3; +static const sal_Int32 kTestStr82Len = 3; +static const sal_Int32 kTestStr83Len = 6; +static const sal_Int32 kTestStr84Len = 8; +static const sal_Int32 kTestStr85Len = 8; +static const sal_Int32 kTestStr86Len = 9; +static const sal_Int32 kTestStr87Len = 9; +static const sal_Int32 kTestStr88Len = 14; +static const sal_Int32 kTestStr89Len = 14; +static const sal_Int32 kTestStr90Len = 17; +static const sal_Int32 kTestStr91Len = 19; +static const sal_Int32 kTestStr92Len = 19; +static const sal_Int32 kTestStr93Len = 20; +static const sal_Int32 kTestStr94Len = 20; +static const sal_Int32 kTestStr95Len = 8; +static const sal_Int32 kTestStr96Len = 8; +static const sal_Int32 kTestStr97Len = 11; +static const sal_Int32 kTestStr98Len = 13; +static const sal_Int32 kTestStr99Len = 13; +static const sal_Int32 kTestStr100Len = 14; +static const sal_Int32 kTestStr101Len = 14; +static const sal_Int32 kTestStr102Len = 4; +static const sal_Int32 kTestStr103Len = 4; +static const sal_Int32 kTestStr104Len = 7; +static const sal_Int32 kTestStr105Len = 9; +static const sal_Int32 kTestStr106Len = 9; +static const sal_Int32 kTestStr107Len = 10; +static const sal_Int32 kTestStr108Len = 10; +static const sal_Int32 kTestStr109Len = 15; +static const sal_Int32 kTestStr110Len = 15; +static const sal_Int32 kTestStr111Len = 18; +static const sal_Int32 kTestStr112Len = 20; +static const sal_Int32 kTestStr113Len = 20; +static const sal_Int32 kTestStr114Len = 21; +static const sal_Int32 kTestStr115Len = 21; +static const sal_Int32 kTestStr116Len = 23; +static const sal_Int32 kTestStr117Len = 24; +static const sal_Int32 kTestStr118Len = 19; +static const sal_Int32 kTestStr119Len = 20; +static const sal_Int32 kTestStr120Len = 30; +static const sal_Int32 kTestStr121Len = 31; +static const sal_Int32 kTestStr122Len = 16; +static const sal_Int32 kTestStr123Len = 21; +static const sal_Int32 kTestStr124Len = 23; +static const sal_Int32 kTestStr125Len = 30; +static const sal_Int32 kTestStr126Len = 12; +static const sal_Int32 kTestStr127Len = 17; +static const sal_Int32 kTestStr128Len = 19; +static const sal_Int32 kTestStr129Len = 26; +static const sal_Int32 kTestStr130Len = 23; +static const sal_Int32 kTestStr131Len = 28; +static const sal_Int32 kTestStr132Len = 30; +static const sal_Int32 kTestStr133Len = 37; +static const sal_Int32 kTestStr134Len = 22; +static const sal_Int32 kTestStr135Len = 24; +static const sal_Int32 kTestStr136Len = 31; +static const sal_Int32 kTestStr137Len = 18; +static const sal_Int32 kTestStr138Len = 20; +static const sal_Int32 kTestStr139Len = 27; +static const sal_Int32 kTestStr140Len = 29; +static const sal_Int32 kTestStr141Len = 31; +static const sal_Int32 kTestStr142Len = 38; +static const sal_Int32 kTestStr143Len = 5; +static const sal_Int32 kTestStr144Len = 1; +static const sal_Int32 kTestStr145Len = 12; +static const sal_Int32 kTestStr146Len = 19; +static const sal_Int32 kTestStr147Len = 19; +static const sal_Int32 kTestStr148Len = 19; +static const sal_Int32 kTestStr149Len = 32; +static const sal_Int32 kTestStr150Len = 32; +static const sal_Int32 kTestStr151Len = 31; +static const sal_Int32 kTestStr152Len = 31; +static const sal_Int32 kTestStr153Len = 31; +static const sal_Int32 kTestStr154Len = 36; +static const sal_Int32 kTestStr155Len = 36; +static const sal_Int32 kTestStr156Len = 36; +static const sal_Int32 kTestStr157Len = 49; +static const sal_Int32 kTestStr158Len = 49; +static const sal_Int32 kTestStr159Len = 49; +static const sal_Int32 kTestStr160Len = 48; +static const sal_Int32 kTestStr161Len = 48; +static const sal_Int32 kTestStr162Len = 48; +static const sal_Int32 kTestStr163Len = 15; +static const sal_Int32 kTestStr164Len = 15; +static const sal_Int32 kTestStr165Len = 15; +static const sal_Int32 kTestStr166Len = 28; +static const sal_Int32 kTestStr167Len = 28; +static const sal_Int32 kTestStr168Len = 28; +static const sal_Int32 kTestStr169Len = 27; +static const sal_Int32 kTestStr170Len = 27; +static const sal_Int32 kTestStr171Len = 27; +static const sal_Int32 kTestStr1PlusStr6Len = kTestStr1Len + kTestStr6Len; + +static const sal_Int32 uTestStr1Len = 16; +static const sal_Int32 uTestStr2Len = 32; +static const sal_Int32 uTestStr3Len = 16; +static const sal_Int32 uTestStr4Len = 16; +static const sal_Int32 uTestStr5Len = 16; +static const sal_Int32 uTestStr9Len = 32; +static const sal_Int32 uTestStr22Len = 32; + +const sal_Unicode uTestStr31[]= {0x400,0x410,0x4DF}; +const sal_Unicode uTestStr32[]= {0x9F9F,0xA000,0x8F80,0x9AD9}; + +static const sal_Int32 uTestStr31Len = 3; +static const sal_Int32 uTestStr32Len = 4; + +static const sal_Int16 kRadixBinary = 2; +static const sal_Int16 kRadixOctol = 8; +static const sal_Int16 kRadixDecimal = 10; +static const sal_Int16 kRadixHexdecimal = 16; +static const sal_Int16 kRadixBase36 = 36; + +static const sal_Int8 kSInt8Max = SCHAR_MAX; +static const sal_Int16 kUInt8Max = UCHAR_MAX; +static const sal_Int16 kSInt16Max = SHRT_MAX; +static const sal_Int32 kUInt16Max = USHRT_MAX; +static const sal_Int32 kSInt32Max = INT_MAX; +static const sal_Int64 kUInt32Max = UINT_MAX; +static const sal_Int64 kSInt64Max = SAL_CONST_INT64(9223372036854775807); + +static const sal_Int32 kInt32MaxNumsCount = 5; + +static const sal_Int32 kInt32MaxNums[kInt32MaxNumsCount] = + { + kSInt8Max, kUInt8Max, + kSInt16Max, kUInt16Max, + kSInt32Max + }; + +static const sal_Int32 kInt64MaxNumsCount = 7; + +static const sal_Int64 kInt64MaxNums[kInt64MaxNumsCount] = + { + kSInt8Max, kUInt8Max, + kSInt16Max, kUInt16Max, + kSInt32Max, kUInt32Max, + kSInt64Max + }; + +static const sal_Int32 kBinaryNumsCount = 16; + +static const sal_Int32 kBinaryMaxNumsCount = 7; + +static const sal_Int32 kOctolNumsCount = 16; + +static const sal_Int32 kOctolMaxNumsCount = 7; + +static const sal_Int32 kDecimalNumsCount = 16; + +static const sal_Int32 kDecimalMaxNumsCount = 7; + +static const sal_Int32 kHexDecimalNumsCount = 16; + +static const sal_Int32 kHexDecimalMaxNumsCount = 7; + +static const sal_Int32 kBase36NumsCount = 36; + +static const sal_Int32 kBase36MaxNumsCount = 7; + +static const sal_Int32 nDoubleCount=24; +static const double expValDouble[nDoubleCount]= + { + 3.0,3.1,3.1415,3.1415926535,3.141592653589793, + 3.1415926535897932,3.14159265358979323,3.1, + 3.141592653589793238462643,9.1096e-31,2.997925e8,6.241e18,5.381e18, + 1.7e-309,6.5822e-16,1.7e+307,2.2e30,3.1,3.1,-3.1, + 0.0,0.0,0.0,1.00e+308 + }; + +static const sal_Int32 nFloatCount=22; +static const float expValFloat[nFloatCount] = + { + 3.0f,3.1f,3.1415f,3.14159f,3.141592f, + 3.1415926f,3.14159265f,3.141592653589793238462643f, + 6.5822e-16f,9.1096e-31f,2.997925e8f,6.241e18f, + 1.00e38f,6.241e-37f,6.241e37f,3.1f,3.1f,-3.1f, + 3.1f,0.0f,0.0f,0.0f + }; + +static const sal_Int32 nCharCount=15; +static const sal_Unicode expValChar[nCharCount] = + { + 65,97,48,45,95, + 21,27,29, + 64,10,39,34, + 0,0,83 + }; + +static const sal_Int32 nDefaultCount=6; +static const sal_Unicode input1Default[nDefaultCount] = + { + 77,115,85,119,32,0 + }; +static const sal_Int32 input2Default[nDefaultCount] = + { + 0,0,0,0,0,0 + }; +static const sal_Int32 expValDefault[nDefaultCount] = + { + 4,9,-1,-1,3,-1 + }; + +static const sal_Int32 nNormalCount=10; +static const sal_Unicode input1Normal[nNormalCount] = + { + 77,77,77,115,115,115,119,119,0,0 + }; +static const sal_Int32 input2Normal[nNormalCount] = + { + 0,32,80,0,13,20,0,80,0,32 + }; +static const sal_Int32 expValNormal[nNormalCount] = + { + 4,-1,-1,9,15,-1,-1,-1,-1,-1 + }; + +static const sal_Int32 nlastDefaultCount=5; +static const sal_Unicode input1lastDefault[nlastDefaultCount] = + { + 77,115,119,32,0 + }; +static const sal_Int32 input2lastDefault[nlastDefaultCount] = + { + 31,31,31,31,31 + }; +static const sal_Int32 expVallastDefault[nlastDefaultCount] = + { + 4,15,-1,21,-1 + }; + +static const sal_Int32 nlastNormalCount=8; +static const sal_Unicode input1lastNormal[nlastNormalCount] = + { + 77,77,77,115,115,119,119,0 + }; +static const sal_Int32 input2lastNormal[nlastNormalCount] = + { + 29,0,80,31,3,31,80,31 + }; +static const sal_Int32 expVallastNormal[nlastNormalCount] = + { + 4,-1,4,15,-1,-1,-1,-1 + }; + +static const sal_Int32 nStrDefaultCount=6; +static const sal_Int32 input2StrDefault[nStrDefaultCount] = + { + 0,0,0,0,0,0 + }; +static const sal_Int32 expValStrDefault[nStrDefaultCount] = + { + 0,4,-1,-1,-1,3 + }; + +static const sal_Int32 nStrNormalCount=9; +static const sal_Int32 input2StrNormal[nStrNormalCount] = + { + 0,32,0,30,0,0,0,32,0 + }; +static const sal_Int32 expValStrNormal[nStrNormalCount] = + { + 0,-1,4,-1,-1,-1,-1,-1,3 + }; + +static const sal_Int32 nStrLastDefaultCount=6; +static const sal_Int32 input2StrLastDefault[nStrLastDefaultCount] = + { + 31,31,31,31,31,31 + }; +static const sal_Int32 expValStrLastDefault[nStrLastDefaultCount] = + { + 0,4,-1,-1,-1,3 + }; + +static const sal_Int32 nStrLastNormalCount=12; +static const sal_Int32 input2StrLastNormal[nStrLastNormalCount] = + { + 31,0,80,31,2,31,31,31,0,31,31,14 + }; +static const sal_Int32 expValStrLastNormal[nStrLastNormalCount] = + { + 0,-1,0,4,-1,-1,-1,-1,-1,3,15,11 + }; + +static const sal_Int32 kNonSInt32Max = INT_MIN; +static const sal_Int32 kNonSInt16Max = SHRT_MIN; + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDED_SAL_QA_OSTRINGBUFFER_RTL_STRING_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/OStringBuffer/rtl_String_Utils_Const.h b/sal/qa/OStringBuffer/rtl_String_Utils_Const.h new file mode 100644 index 000000000..fc258ead3 --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_String_Utils_Const.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSTRINGBUFFER_RTL_STRING_UTILS_CONST_H +#define INCLUDED_SAL_QA_OSTRINGBUFFER_RTL_STRING_UTILS_CONST_H + +#include <sal/types.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +static const sal_Int32 kErrCompareAStringToUString = -2; +static const sal_Int32 kErrCompareNAStringToUString = -3; +static const sal_Int32 kErrCompareAStringToRTLUString = -4; +static const sal_Int32 kErrCompareNAStringToRTLUString = -5; +static const sal_Int32 kErrAStringToByteStringCompare = -6; +static const sal_Int32 kErrAStringToByteStringNCompare = -7; +static const sal_Int32 kErrCompareAStringToString = -8; +static const sal_Int32 kErrCompareNAStringToString = -9; + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDED_SAL_QA_OSTRINGBUFFER_RTL_STRING_UTILS_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/inc/stringhelper.hxx b/sal/qa/inc/stringhelper.hxx new file mode 100644 index 000000000..5bce6ebbb --- /dev/null +++ b/sal/qa/inc/stringhelper.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_INC_STRINGHELPER_HXX +#define INCLUDED_SAL_QA_INC_STRINGHELPER_HXX + +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> + +inline void operator <<= (OString& _rAsciiString, OUString const & _rUnicodeString) +{ + _rAsciiString = OUStringToOString(_rUnicodeString,RTL_TEXTENCODING_ASCII_US); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/inc/valueequal.hxx b/sal/qa/inc/valueequal.hxx new file mode 100644 index 000000000..5e6d47d30 --- /dev/null +++ b/sal/qa/inc/valueequal.hxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_INC_VALUEEQUAL_HXX +#define INCLUDED_SAL_QA_INC_VALUEEQUAL_HXX + +#include <sal/config.h> + +#include <cmath> + +#define PREC_float 1 +#define PREC_double 2 +#define PREC_long_double 3 + +template<class T> +bool is_equal(T x, T y, sal_Int16 _nPrec) +{ + if (!(std::isfinite(x) && std::isfinite(y))) { + return x == y; + } + + // due to the fact that this check looks only if both values are equal + // we only need to look on one value + + // 14 digits will announce the checkPrecisionSize + + sal_Int32 nPRECISION; + switch(_nPrec) + { + case PREC_float: + nPRECISION = 6; + break; + case PREC_double: + nPRECISION = 14; + break; + case PREC_long_double: + nPRECISION = 20; + break; + default: + nPRECISION = 2; + } + + if (x < 0) + { + x = -x; + } + if (y < 0) + { + y = -y; + } + + if (_nPrec != PREC_long_double) + { + printf("double equal: %.20f\n", x); + printf(" %.20f\n", y); + } + //here nPrecOfN is the number after dot + sal_Int32 nBeforeDot = sal_Int32( log10(x) ); + if ( nBeforeDot < 0) + { + nBeforeDot = 0; + } + //printf("nPRECISION is %d\n", nPRECISION); + sal_Int32 nPrecOfN = -nPRECISION + nBeforeDot; + + if (_nPrec != PREC_long_double) + printf("nPrecOfN is %" SAL_PRIdINT32 "\n", nPrecOfN); + + double nPrec = pow(0.1, -nPrecOfN); + + if (_nPrec != PREC_long_double) + printf(" prec: %.20f\n", nPrec); + + double nDelta = fabs( x - y ) ; + + if (_nPrec != PREC_long_double) + { + printf(" delta: %.20f\n", nDelta); + printf(" nPrec: %.20f\n", nPrec); + printf("delta must be less or equal to prec\n\n"); + } + + if (nDelta > nPrec) + { + // values are not equal + return false; + } + + // values are equal + return true; +} + +bool is_float_equal(float x, float y) +{ + return is_equal<float>(x, y, PREC_float); +} +bool is_double_equal(double x, double y) +{ + return is_equal<double>(x, y, PREC_double); +} + +#endif // INCLUDED_SAL_QA_INC_VALUEEQUAL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/libs2test.txt b/sal/qa/libs2test.txt new file mode 100644 index 000000000..5503124f4 --- /dev/null +++ b/sal/qa/libs2test.txt @@ -0,0 +1,101 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# +# This file contain a list of todos for testshl2 automated tests. +# +# Legend: +# there exist 2 formats +# 1. file +# 2. path ; file +# +# 1. if only a file exist, it will be assume, that a directory with name 'file' +# exist, and a library with name 'file' create. +# 2. if the path to the file differ from the library file, use this format. +# + + +# LLA: marked as deprecated by Stephan Bergmann +ByteSequence ; rtl_ByteSequence + +OStringBuffer ; rtl_OStringBuffer + +rtl_strings ; rtl_OUString +rtl_strings ; rtl_OString +rtl_strings ; rtl_OUStringBuffer + +# replacements for old rtl::XString tests +rtl/oustring ; rtl_OUString2 +rtl/ostring ; rtl_OString2 + +osl/file ; osl_File +# LLA: temporarily removed, there are lot of problems with our environment +osl/socket ; osl_StreamSocket +osl/socket ; osl_DatagramSocket +osl/socket ; osl_SocketAddr +osl/socket ; osl_Socket2 +osl/socket ; osl_ConnectorSocket +osl/socket ; osl_AcceptorSocket + +osl/mutex ; osl_Mutex +osl/pipe ; osl_Pipe +osl/condition ; osl_Condition +osl/module ; osl_Module +osl/security ; osl_Security + +rtl/math ; rtl_math +rtl/math ; rtl_math2 + +# new 20040315 +rtl/alloc ; rtl_Alloc +rtl/crc32 ; rtl_crc32 +rtl/digest ; rtl_digest +rtl/bootstrap ; rtl_Bootstrap +rtl/ostring ; rtl_str +rtl/ostring ; rtl_string +rtl/random ; rtl_Random + +# new 20040324 +rtl/oustring ; rtl_ustr + +# new 20040326 +rtl/cipher ; rtl_cipher + +# new 20040331 +rtl/locale ; rtl_locale +rtl/uuid ; rtl_Uuid +rtl/process ; rtl_Process + +# new 20040413 +rtl/textenc ; rtl_textcvt +rtl/textenc ; rtl_tencinfo +rtl/oustringbuffer; rtl_OUStringBuffer2 + +# new 20040420 +rtl/uri ; rtl_Uri +rtl/logfile ; rtl_logfile + +# LLA: Due to the fact, that thread testing seems to be little bit error prone, now +# check this at the end. +osl/process ; osl_Thread + +# not ready yet +# strings ; test_oustring + +# new 20041025 +rtl/doublelock ; rtl_doublelocking + diff --git a/sal/qa/osl/condition/osl_Condition.cxx b/sal/qa/osl/condition/osl_Condition.cxx new file mode 100644 index 000000000..05b7fc661 --- /dev/null +++ b/sal/qa/osl/condition/osl_Condition.cxx @@ -0,0 +1,327 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "osl_Condition_Const.h" +#include <stdlib.h> + +using namespace osl; + +namespace { + +enum ConditionType +{ + thread_type_set, + thread_type_reset, + thread_type_wait +}; + +/** thread for testing Condition. + */ +class ConditionThread : public Thread +{ +public: + //get the Condition to operate + ConditionThread( ::osl::Condition& Con, ConditionType tType): m_MyCon( Con ), m_MyType( tType ) { } + +protected: + ::osl::Condition& m_MyCon; + ConditionType m_MyType; + + void SAL_CALL run() override + { + switch ( m_MyType ) + { + case thread_type_wait: + m_MyCon.wait(); break; + case thread_type_set: + m_MyCon.set(); break; + case thread_type_reset: + m_MyCon.reset(); break; + default: + break; + } + } +}; + +} + +namespace osl_Condition +{ + /** testing the method: + Condition() + */ + class ctors : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void ctors_create() + { + ::osl::Condition aCond; + bRes = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: create a condition its initial check state should be sal_False.", + !bRes ); + } + + void ctors_createAndSet() + { + ::osl::Condition aCond; + aCond.set(); + bRes = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: create a condition and set it.", + bRes ); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctors_create); + CPPUNIT_TEST(ctors_createAndSet); + CPPUNIT_TEST_SUITE_END(); + }; + + /** testing the method: + void set() + */ + class set : public CppUnit::TestFixture + { + public: + bool bRes, bRes1, bRes2; + + void set_createAndSet() + { + ::osl::Condition aCond; + aCond.set(); + bRes = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: check state should be sal_True after set.", + bRes ); + } + + void set_threadWaitRelease() + { + ::osl::Condition aCond; + ConditionThread myThread1(aCond, thread_type_wait); + myThread1.create(); + bRes = myThread1.isRunning(); + + ConditionThread myThread2(aCond, thread_type_set); + myThread2.create(); + + myThread1.join(); + bRes1 = myThread1.isRunning(); + bRes2 = aCond.check(); + myThread2.join(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: use one thread to set the condition in order to release another thread.", + bRes); + CPPUNIT_ASSERT_MESSAGE("#test comment#: use one thread to set the condition in order to release another thread.", + !bRes1); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: use one thread to set the condition in order to release another thread.", + bRes2); + } + + CPPUNIT_TEST_SUITE(set); + CPPUNIT_TEST(set_createAndSet); + CPPUNIT_TEST(set_threadWaitRelease); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + void reset() + */ + class reset : public CppUnit::TestFixture + { + public: + bool bRes, bRes1, bRes2; + + void reset_resetWaitAndSet() + { + ::osl::Condition aCond; + aCond.reset(); + + ConditionThread myThread(aCond, thread_type_wait); + myThread.create(); + bRes = myThread.isRunning(); + bRes2 = aCond.check(); + + aCond.set(); + myThread.join(); + bRes1 = myThread.isRunning(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: wait will cause a reset thread block, use set to release it.", + bRes); + CPPUNIT_ASSERT_MESSAGE("#test comment#: wait will cause a reset thread block, use set to release it.", + !bRes1); + CPPUNIT_ASSERT_MESSAGE("#test comment#: wait will cause a reset thread block, use set to release it.", + !bRes2); + } + + void reset_resetAndSet() + { + ::osl::Condition aCond; + aCond.reset(); + bRes = aCond.check(); + aCond.set(); + bRes1 = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: create a condition and reset/set it.", + !bRes ); + CPPUNIT_ASSERT_MESSAGE("#test comment#: create a condition and reset/set it.", + bRes1 ); + } + + CPPUNIT_TEST_SUITE(reset); + CPPUNIT_TEST(reset_resetWaitAndSet); + CPPUNIT_TEST(reset_resetAndSet); + CPPUNIT_TEST_SUITE_END(); + }; + + /** testing the method: + Result wait(const TimeValue *pTimeout = 0) + */ + class wait : public CppUnit::TestFixture + { + public: + bool bRes, bRes1, bRes2; + std::unique_ptr<TimeValue> tv1; + + void setUp() override + { + tv1.reset(new TimeValue); + tv1->Seconds = 1; + tv1->Nanosec = 0; + } + + void tearDown() override + { + tv1.reset(); + } + + void wait_testAllCombos( ) + { + ::osl::Condition cond1; + ::osl::Condition cond2; + ::osl::Condition cond3; + + cond1.set(); + cond2.set(); + + osl::Condition::Result r1=cond1.wait(tv1.get()); + osl::Condition::Result r2=cond2.wait(); + osl::Condition::Result r3=cond3.wait(tv1.get()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: test three types of wait.", + ::osl::Condition::result_ok, r1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: test three types of wait.", + ::osl::Condition::result_ok, r2 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: test three types of wait.", + ::osl::Condition::result_timeout, r3 ); + } + + void wait_timeoutWaits() + { + ::osl::Condition aCond; + ::osl::Condition::Result wRes, wRes1; + + aCond.reset(); + bRes = aCond.check(); + wRes = aCond.wait(tv1.get()); + + aCond.set(); + wRes1 = aCond.wait(tv1.get()); + bRes1 = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: wait a condition after set/reset.", + !bRes ); + CPPUNIT_ASSERT_MESSAGE("#test comment#: wait a condition after set/reset.", + bRes1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("#test comment#: wait a condition after set/reset.", + ::osl::Condition::result_timeout, wRes ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("#test comment#: wait a condition after set/reset.", + ::osl::Condition::result_ok, wRes1 ); + } + + CPPUNIT_TEST_SUITE(wait); + CPPUNIT_TEST(wait_testAllCombos); + CPPUNIT_TEST(wait_timeoutWaits); + CPPUNIT_TEST_SUITE_END(); + }; + + /** testing the method: + sal_Bool check() + */ + class check : public CppUnit::TestFixture + { + public: + bool bRes, bRes1, bRes2; + + void check_checkStates() + { + ::osl::Condition aCond; + + aCond.reset(); + bRes = aCond.check(); + aCond.set(); + bRes1 = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: check the condition states.", + !bRes ); + CPPUNIT_ASSERT_MESSAGE("#test comment#: check the condition states.", + bRes1 ); + } + + void check_threadedCheckStates( ) + { + ::osl::Condition aCond; + aCond.reset(); + + ConditionThread myThread(aCond, thread_type_set); + myThread.create(); + myThread.join(); + bRes = aCond.check(); + + ConditionThread myThread1(aCond, thread_type_reset); + myThread1.create(); + myThread1.join(); + bRes1 = aCond.check(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: use threads to set/reset Condition and check it in main routine.", + bRes ); + CPPUNIT_ASSERT_MESSAGE("#test comment#: use threads to set/reset Condition and check it in main routine.", + !bRes1 ); + } + + CPPUNIT_TEST_SUITE(check); + CPPUNIT_TEST(check_checkStates); + CPPUNIT_TEST(check_threadedCheckStates); + CPPUNIT_TEST_SUITE_END(); + }; + + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Condition::ctors); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Condition::set); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Condition::reset); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Condition::wait); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Condition::check); + +} // namespace osl_Condition + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/condition/osl_Condition_Const.h b/sal/qa/osl/condition/osl_Condition_Const.h new file mode 100644 index 000000000..6bcf9e730 --- /dev/null +++ b/sal/qa/osl/condition/osl_Condition_Const.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSL_CONDITION_OSL_CONDITION_CONST_H +#define INCLUDED_SAL_QA_OSL_CONDITION_OSL_CONDITION_CONST_H + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <osl/thread.hxx> +#include <osl/mutex.hxx> +#include <osl/pipe.hxx> +#include <osl/conditn.hxx> +#include <osl/time.h> + +#ifdef UNX +#include <unistd.h> +#endif + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +// condition names + +OUString aTestCon( "testcondition" ); + +const char pTestString[17] = "Sun Microsystems"; + +#endif // INCLUDED_SAL_QA_OSL_CONDITION_OSL_CONDITION_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/file/osl_File.cxx b/sal/qa/osl/file/osl_File.cxx new file mode 100644 index 000000000..dbe461ae3 --- /dev/null +++ b/sal/qa/osl/file/osl_File.cxx @@ -0,0 +1,5202 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <rtl/byteseq.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +#include <osl/thread.h> +#include <osl/file.hxx> +#include "osl_File_Const.h" + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <tools/urlobj.hxx> + +#include <memory> + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#endif + +using namespace osl; + +/** detailed wrong message. +*/ +static OString errorToString(const osl::FileBase::RC _nError) +{ + OString sResult; + switch (_nError) { + case osl::FileBase::E_None: + sResult = "Success"; + break; + case osl::FileBase::E_PERM: + sResult = "Operation not permitted"; + break; + case osl::FileBase::E_NOENT: + sResult = "No such file or directory"; + break; + case osl::FileBase::E_EXIST: + sResult = "Already Exist"; + break; + case osl::FileBase::E_ACCES: + sResult = "Permission denied"; + break; + case osl::FileBase::E_INVAL: + sResult = "The format of the parameters was not valid"; + break; + case osl::FileBase::E_NOTDIR: + sResult = "Not a directory"; + break; + case osl::FileBase::E_ISDIR: + sResult = "Is a directory"; + break; + case osl::FileBase::E_BADF: + sResult = "Bad file"; + break; + case osl::FileBase::E_NOTEMPTY: + sResult = "The directory is not empty"; + break; + default: + sResult = "Unknown Error"; + break; + } + return sResult; +} + +static OString errorToStr(osl::FileBase::RC const& nError) +{ + OString suBuf = "The returned error is: " + + errorToString(nError) + + "!\n"; + return suBuf; +} + +/** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX. +*/ +/* FIXME: the above assertion is bogus */ + +#if (defined UNX) // precision of time in Windows is better than UNX +# define delta 2000 // time precision, 2000ms +#else +# define delta 1800 // time precision, 1.8s +#endif + +static bool t_compareTime(TimeValue *m_aEndTime, TimeValue *m_aStartTime, sal_Int32 nDelta) +{ + sal_Int32 nDeltaSeconds = m_aEndTime->Seconds - m_aStartTime->Seconds; + sal_Int32 nDeltaNanoSec = sal_Int32(m_aEndTime->Nanosec) - sal_Int32(m_aStartTime->Nanosec); + if (nDeltaNanoSec < 0) + { + nDeltaNanoSec = 1000000000 + nDeltaNanoSec; + nDeltaSeconds--; + } + + sal_Int32 nDeltaMilliSec = (nDeltaSeconds * 1000) + (nDeltaNanoSec / 1000000); + return (nDeltaMilliSec < nDelta); +} + +/** compare two OUString file name. +*/ +static bool compareFileName(const OUString & ustr1, const OUString & ustr2) +{ + bool bOk; +// on Windows, the separator is '\', so here change to '/', then compare +#if defined(_WIN32) + OUString ustr1new,ustr2new; + sal_Unicode reverseSlash = '\\'; + + if (ustr1.lastIndexOf(reverseSlash) != -1) + ustr1new = ustr1.replace(reverseSlash,'/'); + else + ustr1new = ustr1; + if (ustr2.lastIndexOf(reverseSlash) != -1) + ustr2new = ustr2.replace(reverseSlash,'/'); + else + ustr2new = ustr2; + bOk = ustr1new.equalsIgnoreAsciiCase(ustr2new); +#else + bOk = ustr1.equalsIgnoreAsciiCase(ustr2); +#endif + return bOk; +} + +/** simple version to judge if a file name or directory name is a URL or a system path, just to see if it + is start with "file:///";. +*/ +static bool isURL(const OUString& pathname) +{ + return pathname.startsWith(aPreURL); +} + +/** concat two part to form a URL or system path, add PATH_SEPARATOR between them if necessary, add "file:///" to beginning if necessary. +*/ +static void concatURL(OUString & pathname1, const OUString & pathname2) +{ + // check if pathname1 is full qualified URL; + if (!isURL(pathname1)) + { + OUString aPathName = pathname1.copy(0); + osl::FileBase::getFileURLFromSystemPath(pathname1, aPathName); // convert if not full qualified URL + pathname1 = aPathName.copy(0); + } + + // check if '/' is in the end of pathname1 or at the begin of pathname2; + if (!pathname1.endsWith(aSlashURL) && !pathname2.startsWith(aSlashURL)) + pathname1 += aSlashURL; + pathname1 += pathname2; +} + +/** create a temp test file using OUString name of full qualified URL or system path. +*/ +static void createTestFile(const OUString& filename) +{ + OUString aPathURL = filename.copy(0); + osl::FileBase::RC nError; + + if (!isURL(filename)) + osl::FileBase::getFileURLFromSystemPath(filename, aPathURL); // convert if not full qualified URL + + File aFile(aPathURL); + nError = aFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create); + if ((nError != osl::FileBase::E_None) && (nError != osl::FileBase::E_EXIST)) + printf("createTestFile failed!\n"); + + aFile.close(); + +} + +/** create a temp test file using OUString name of full qualified URL or system path in a base directory. +*/ +static void createTestFile(const OUString& basename, const OUString& filename) +{ + OUString aBaseURL = basename.copy(0); + + concatURL(aBaseURL, filename); + createTestFile(aBaseURL); +} + +/** delete a temp test file using OUString name. +*/ +static void deleteTestFile(const OUString& filename) +{ + OUString aPathURL = filename.copy(0); + osl::FileBase::RC nError; + + if (!isURL(filename)) + osl::FileBase::getFileURLFromSystemPath(filename, aPathURL); // convert if not full qualified URL + + nError = File::setAttributes(aPathURL, osl_File_Attribute_GrpWrite| osl_File_Attribute_OwnWrite| osl_File_Attribute_OthWrite); // if readonly, make writable. + CPPUNIT_ASSERT_MESSAGE("In deleteTestFile Function: set writable ", (osl::FileBase::E_None == nError) || (osl::FileBase::E_NOENT == nError)); + + nError = File::remove(aPathURL); + CPPUNIT_ASSERT_MESSAGE("In deleteTestFile Function: remove ", (osl::FileBase::E_None == nError) || (nError == osl::FileBase::E_NOENT)); +} + +/** delete a temp test file using OUString name of full qualified URL or system path in a base directory. +*/ +static void deleteTestFile(const OUString& basename, const OUString& filename) +{ + OUString aBaseURL = basename.copy(0); + + concatURL(aBaseURL, filename); + deleteTestFile(aBaseURL); +} + +/** create a temp test directory using OUString name of full qualified URL or system path. +*/ +static void createTestDirectory(const OUString& dirname) +{ + OUString aPathURL = dirname.copy(0); + osl::FileBase::RC nError; + + if (!isURL(dirname)) + osl::FileBase::getFileURLFromSystemPath(dirname, aPathURL); // convert if not full qualified URL + nError = Directory::create(aPathURL); + if ((nError != osl::FileBase::E_None) && (nError != osl::FileBase::E_EXIST)) + printf("createTestDirectory failed!\n"); +} + +/** create a temp test directory using OUString name of full qualified URL or system path in a base directory. +*/ +static void createTestDirectory(const OUString& basename, const OUString& dirname) +{ + OUString aBaseURL = basename.copy(0); + + concatURL(aBaseURL, dirname); + createTestDirectory(aBaseURL); +} + +/** delete a temp test directory using OUString name of full qualified URL or system path. +*/ +static void deleteTestDirectory(const OUString& dirname) +{ + OUString aPathURL = dirname.copy(0); + osl::FileBase::RC nError; + if (!isURL(dirname)) + osl::FileBase::getFileURLFromSystemPath(dirname, aPathURL); // convert if not full qualified URL + + Directory testDir(aPathURL); + if (testDir.isOpen()) + testDir.close(); // close if still open. + + nError = Directory::remove(aPathURL); + + OString strError = "In deleteTestDirectory function: remove Directory " + + OUStringToOString(aPathURL, RTL_TEXTENCODING_ASCII_US); + CPPUNIT_ASSERT_MESSAGE(strError.getStr(), (osl::FileBase::E_None == nError) || (nError == osl::FileBase::E_NOENT)); +} + +/** delete a temp test directory using OUString name of full qualified URL or system path in a base directory. +*/ +static void deleteTestDirectory(const OUString& basename, const OUString& dirname) +{ + OUString aBaseURL = basename.copy(0); + + concatURL(aBaseURL, dirname); + deleteTestDirectory(aBaseURL); +} + +namespace { + +/** Check for the file and directory access right. +*/ +enum class oslCheckMode { + Exist, + OpenAccess, + ReadAccess, + WriteAccess +}; + +} + +/** check if the file exist +*/ +static bool ifFileExist(const OUString & str) +{ + File testFile(str); + return (testFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None); +} + +/** check if the file can be written +*/ +static bool ifFileCanWrite(const OUString & str) +{ + // on Windows, the file has no write right, but can be written +#ifdef _WIN32 + bool bCheckResult = false; + OUString aUStr = str.copy(0); + if (isURL(str)) + osl::FileBase::getSystemPathFromFileURL(str, aUStr); + + OString aString = OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US); + const char *path = aString.getStr(); + if ((_access(path, 2)) != -1) + bCheckResult = true; + // on UNX, just test if open success with osl_File_OpenFlag_Write +#else + File testFile(str); + bool bCheckResult = (testFile.open(osl_File_OpenFlag_Write) == osl::FileBase::E_None); +#endif + return bCheckResult; +} + +static bool checkDirectory(const OUString& str, oslCheckMode nCheckMode) +{ + OUString aUString; + DirectoryItem rItem; + osl::FileBase::RC rc; + bool bCheckResult= false; + + Directory aDir(str); + rc = aDir.open(); + + if ((rc != osl::FileBase::E_NOENT) && (rc != osl::FileBase::E_ACCES)) + { + switch (nCheckMode) + { + case oslCheckMode::Exist: + if (rc == ::osl::FileBase::E_None) + bCheckResult = true; + break; + case oslCheckMode::OpenAccess: + if (rc == osl::FileBase::E_None) + bCheckResult = true; + break; + case oslCheckMode::ReadAccess: + rc = aDir.getNextItem(rItem); + bCheckResult = (rc == osl::FileBase::E_None) || (rc == osl::FileBase::E_NOENT); + break; + case oslCheckMode::WriteAccess: + ((aUString += str) += aSlashURL) += aTmpName2; + if (Directory::create(aUString) == osl::FileBase::E_None) + { + bCheckResult = true; + rc = Directory::remove(aUString); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, rc); + } + else + { + bCheckResult = false; + } + break; + + default: + bCheckResult = false; + } + + rc = aDir.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, rc); + } + + return bCheckResult; +} + +/** construct error message +*/ +static OString outputError(const OString & returnVal, const OString & rightVal, const char * msg = "") +{ + if (returnVal == rightVal) + return OString(); + + OString aString = msg + + OStringLiteral(": the returned value is '") + + returnVal + + "', but the value should be '" + + rightVal + + "'."; + return aString; +} + +#if (defined UNX) /* chmod() method is different in Windows */ +/** Change file mode, two version in UNIX and Windows;. +*/ +static void changeFileMode(OUString & filepath, sal_Int32 mode) +{ + OString aString; + OUString aUStr = filepath.copy(0); + + if (isURL(filepath)) + osl::FileBase::getSystemPathFromFileURL(filepath, aUStr); + + aString = OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US); + int ret = chmod(aString.getStr(), mode); + CPPUNIT_ASSERT_EQUAL(0, ret); +} +#endif + +#if defined UNX +static OUString getCurrentPID(); +#endif + +// Beginning of the test cases for osl::FileBase class + +namespace osl_FileBase +{ + // testing the method + // static inline RC getAbsoluteFileURL(const OUString& ustrBaseDirectoryURL, + // const OUString& ustrRelativeFileURL, + // OUString& ustrAbsoluteFileURL) + + class getAbsoluteFileURL : public CppUnit::TestFixture + { + public: + void check_getAbsoluteFileURL(OUString const& _suBaseURL, + OString const& _sRelativeURL, + osl::FileBase::RC _nAssumeError, + OUString const& _suAssumeResultStr); + + void getAbsoluteFileURL_001_1(); + void getAbsoluteFileURL_001_2(); + void getAbsoluteFileURL_001_3(); + void getAbsoluteFileURL_001_4(); + void getAbsoluteFileURL_001_5(); + void getAbsoluteFileURL_001_6(); + void getAbsoluteFileURL_001_7(); + void getAbsoluteFileURL_001_8(); + void getAbsoluteFileURL_002(); + void getAbsoluteFileURL_003(); + void getAbsoluteFileURL_004(); + + CPPUNIT_TEST_SUITE(getAbsoluteFileURL); + CPPUNIT_TEST(getAbsoluteFileURL_001_1); + CPPUNIT_TEST(getAbsoluteFileURL_001_2); + CPPUNIT_TEST(getAbsoluteFileURL_001_3); + CPPUNIT_TEST(getAbsoluteFileURL_001_4); + CPPUNIT_TEST(getAbsoluteFileURL_001_5); + CPPUNIT_TEST(getAbsoluteFileURL_001_6); + CPPUNIT_TEST(getAbsoluteFileURL_001_7); + CPPUNIT_TEST(getAbsoluteFileURL_001_8); + CPPUNIT_TEST(getAbsoluteFileURL_002); + CPPUNIT_TEST(getAbsoluteFileURL_003); + CPPUNIT_TEST(getAbsoluteFileURL_004); + CPPUNIT_TEST_SUITE_END(); + }; + + void getAbsoluteFileURL::check_getAbsoluteFileURL(OUString const& _suBaseURL, + OString const& _sRelativeURL, + osl::FileBase::RC _nAssumeError, + OUString const& _suAssumeResultStr) + { + OUString suRelativeURL = OStringToOUString(_sRelativeURL, RTL_TEXTENCODING_UTF8); + OString sBaseURL = OUStringToOString(_suBaseURL, RTL_TEXTENCODING_UTF8); + OUString suResultURL; + osl::FileBase::RC nError = osl::FileBase::getAbsoluteFileURL(_suBaseURL, suRelativeURL, suResultURL); + OString sResultURL = OUStringToOString(suResultURL, RTL_TEXTENCODING_UTF8); + OString sError = errorToString(nError); + printf("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n", + sBaseURL.getStr(), _sRelativeURL.getStr(),sResultURL.getStr(), sError.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong: error number is wrong", _nAssumeError, nError); + + if (nError == osl::FileBase::E_None) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong: ResultURL is not equal to expected URL ", _suAssumeResultStr, suResultURL); + } + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_1() + { + OUString suAssume = aUserDirectoryURL.concat("/relative/file1"); + check_getAbsoluteFileURL(aUserDirectoryURL, "relative/file1",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_2() + { + OUString suAssume = aUserDirectoryURL.concat("/relative/file2"); + check_getAbsoluteFileURL(aUserDirectoryURL, "relative/./file2",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_3() + { + OUString suAssume = aUserDirectoryURL.concat("/file3"); + check_getAbsoluteFileURL(aUserDirectoryURL, "relative/../file3",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_4() + { + OUString suAssume = aUserDirectoryURL.concat("/file4"); + check_getAbsoluteFileURL(aUserDirectoryURL, "././relative/../file4",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_5() + { + OUString suAssume; +#if (defined UNX) + suAssume = aUserDirectoryURL.concat("/relative/"); +#else + suAssume = aUserDirectoryURL.concat("/relative"); +#endif + check_getAbsoluteFileURL(aUserDirectoryURL, "././relative/.",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_6() + { + OUString suAssume = aUserDirectoryURL.concat("/.relative"); + check_getAbsoluteFileURL(aUserDirectoryURL, "./.relative",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_7() + { + OUString suAssume; +#if (defined UNX) + suAssume = aUserDirectoryURL.concat("/.a/"); +#else // windows + suAssume = aUserDirectoryURL.concat("/.a"); +#endif + check_getAbsoluteFileURL(aUserDirectoryURL, "./.a/mydir/..",osl::FileBase::E_None, suAssume); + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_8() + { + OUString suAssume = aUserDirectoryURL.concat("/tmp/ok"); +#if (defined UNX) + check_getAbsoluteFileURL(aUserDirectoryURL, "tmp//ok",osl::FileBase::E_None, suAssume); +#else + check_getAbsoluteFileURL(aUserDirectoryURL, "tmp//ok",osl::FileBase::E_INVAL, suAssume); +#endif + } + + void getAbsoluteFileURL::getAbsoluteFileURL_002() + { +#if (defined UNX) // Link is not defined in Windows + OUString aUStr_LnkFileSys(aTempDirectorySys), aUStr_SrcFileSys(aTempDirectorySys); + aUStr_LnkFileSys += aSlashURL + getCurrentPID() + "/link.file"; + aUStr_SrcFileSys += aSlashURL + getCurrentPID() + "/canonical.name"; + + OString strLinkFileName, strSrcFileName; + strLinkFileName = OUStringToOString(aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US); + strSrcFileName = OUStringToOString(aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US); + + createTestFile(aCanURL1); + sal_Int32 fd = symlink(strSrcFileName.getStr(), strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd); + OString sLnkURL = OUStringToOString(aLnkURL1, RTL_TEXTENCODING_ASCII_US); + OUString suAssume = aUserDirectoryURL.concat("/canonical.name"); + check_getAbsoluteFileURL(aUserDirectoryURL, sLnkURL, osl::FileBase::E_None, suAssume); + deleteTestFile(aCanURL1); + fd = remove(strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd); +#endif + } + + // please see line# 930 + void getAbsoluteFileURL::getAbsoluteFileURL_003() + { + } + + void getAbsoluteFileURL::getAbsoluteFileURL_004() + { + // create two level directories under $Temp/PID/ + OUString aUStrUpBase = aUserDirectoryURL + "/test1"; + createTestDirectory(aUStrUpBase); + OUString aUStrBase = aUserDirectoryURL + "/test1/dir1"; + createTestDirectory(aUStrBase); + + OUString suAssume = aUserDirectoryURL.concat("/mytestfile"); + check_getAbsoluteFileURL(aUStrBase, "../../mytestfile" , osl::FileBase::E_None, suAssume); + deleteTestDirectory(aUStrBase); + deleteTestDirectory(aUStrUpBase); + } + + // testing two methods: + // static inline RC getSystemPathFromFileURL(const OUString& ustrFileURL, + // OUString& ustrSystemPath) + // static RC getFileURLFromSystemPath(const OUString & ustrSystemPath, + // OUString & ustrFileURL); + + class SystemPath_FileURL : public CppUnit::TestFixture + { + public: + void getSystemPathFromFileURL_001_1(); + void getSystemPathFromFileURL_001_2(); + void getSystemPathFromFileURL_001_21(); + void getSystemPathFromFileURL_001_22(); + void getSystemPathFromFileURL_001_3(); + void getSystemPathFromFileURL_001_31(); + void getSystemPathFromFileURL_001_4(); + void getSystemPathFromFileURL_001_41(); + void getSystemPathFromFileURL_001_5(); + void getSystemPathFromFileURL_001_51(); + void getSystemPathFromFileURL_001_52(); + void getSystemPathFromFileURL_001_53(); + void getSystemPathFromFileURL_001_6(); + void getSystemPathFromFileURL_001_61(); + void getSystemPathFromFileURL_001_7(); + void getSystemPathFromFileURL_001_71(); + void getSystemPathFromFileURL_001_8(); + void getSystemPathFromFileURL_001_81(); + void getSystemPathFromFileURL_001_9(); + void getSystemPathFromFileURL_001_91(); + void getSystemPathFromFileURL_001_92(); + void getSystemPathFromFileURL_004(); + void getSystemPathFromFileURL_005(); + + // test case for getFileURLFromSystemPath + void getFileURLFromSystemPath_001(); + void getFileURLFromSystemPath_002(); + void getFileURLFromSystemPath_003(); + void getFileURLFromSystemPath_004(); + void getFileURLFromSystemPath_004_1(); + void getFileURLFromSystemPath_005(); + + CPPUNIT_TEST_SUITE(SystemPath_FileURL); + CPPUNIT_TEST(getSystemPathFromFileURL_001_1); + CPPUNIT_TEST(getSystemPathFromFileURL_001_2); + CPPUNIT_TEST(getSystemPathFromFileURL_001_21); + CPPUNIT_TEST(getSystemPathFromFileURL_001_22); + CPPUNIT_TEST(getSystemPathFromFileURL_001_3); + CPPUNIT_TEST(getSystemPathFromFileURL_001_31); + CPPUNIT_TEST(getSystemPathFromFileURL_001_4); + CPPUNIT_TEST(getSystemPathFromFileURL_001_41); + CPPUNIT_TEST(getSystemPathFromFileURL_001_5); + CPPUNIT_TEST(getSystemPathFromFileURL_001_51); + CPPUNIT_TEST(getSystemPathFromFileURL_001_52); + CPPUNIT_TEST(getSystemPathFromFileURL_001_53); + CPPUNIT_TEST(getSystemPathFromFileURL_001_6); + CPPUNIT_TEST(getSystemPathFromFileURL_001_61); + CPPUNIT_TEST(getSystemPathFromFileURL_001_7); + CPPUNIT_TEST(getSystemPathFromFileURL_001_71); + CPPUNIT_TEST(getSystemPathFromFileURL_001_8); + CPPUNIT_TEST(getSystemPathFromFileURL_001_81); + CPPUNIT_TEST(getSystemPathFromFileURL_001_9); + CPPUNIT_TEST(getSystemPathFromFileURL_001_91); + CPPUNIT_TEST(getSystemPathFromFileURL_001_92); + CPPUNIT_TEST(getSystemPathFromFileURL_004); + CPPUNIT_TEST(getSystemPathFromFileURL_005); + CPPUNIT_TEST(getFileURLFromSystemPath_001); + CPPUNIT_TEST(getFileURLFromSystemPath_002); + CPPUNIT_TEST(getFileURLFromSystemPath_003); + CPPUNIT_TEST(getFileURLFromSystemPath_004); + CPPUNIT_TEST(getFileURLFromSystemPath_004_1); + CPPUNIT_TEST(getFileURLFromSystemPath_005); + CPPUNIT_TEST_SUITE_END(); + + private: + void check_SystemPath_FileURL( + OString const& _sSource, + osl::FileBase::RC _nAssumeError, + OString const& _sAssumeResultStr, + bool bDirection = true); + + void checkWNTBehaviour_getSystemPathFromFileURL( + OString const& _sURL, + osl::FileBase::RC _nAssumeError, + OString const& _sWNTAssumeResultString); + + void checkUNXBehaviour_getSystemPathFromFileURL( + OString const& _sURL, + osl::FileBase::RC _nAssumeError, + OString const& _sUnixAssumeResultString); + + void checkWNTBehaviour_getFileURLFromSystemPath(OString const& _sSysPath, + osl::FileBase::RC _nAssumeError, + OString const& _sWNTAssumeResultString); + + void checkUNXBehaviour_getFileURLFromSystemPath( + OString const& _sSysPath, + osl::FileBase::RC _nAssumeError, + OString const& _sUnixAssumeResultString); + + }; + + // if bDirection==sal_True, check getSystemPathFromFileURL + // if bDirection==sal_False, check getFileURLFromSystemPath + void SystemPath_FileURL::check_SystemPath_FileURL( + OString const& _sSource, + osl::FileBase::RC _nAssumeError, + OString const& _sAssumeResultStr, + bool bDirection) + { + // PRE: URL as String + OUString suSource; + OUString suStr; + suSource = OStringToOUString(_sSource, RTL_TEXTENCODING_UTF8); + osl::FileBase::RC nError; + + if (bDirection) + nError = osl::FileBase::getSystemPathFromFileURL(suSource, suStr); + else + nError = osl::FileBase::getFileURLFromSystemPath(suSource, suStr); + + // if the given string is gt length 0, + // we check also this string + OString sStr = OUStringToOString(suStr, RTL_TEXTENCODING_UTF8); + OString sError = errorToString(nError); + + if (bDirection) + printf("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", + _sSource.getStr(), sStr.getStr(), sError.getStr()); + else + printf("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n", + _sSource.getStr(), sStr.getStr(), sError.getStr()); + + if (!_sAssumeResultStr.isEmpty()) + { + bool bStrAreEqual = _sAssumeResultStr == sStr; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong", + _nAssumeError, nError); + CPPUNIT_ASSERT_MESSAGE("Assumption is wrong", + bStrAreEqual); + } + else + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong", _nAssumeError, nError); + } + } + + void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL( + OString const& _sURL, + osl::FileBase::RC _nAssumeError, + OString const& _sWNTAssumeResultString) + { +#if defined(_WIN32) + check_SystemPath_FileURL(_sURL, _nAssumeError, _sWNTAssumeResultString); +#else + (void)_sURL; + (void)_nAssumeError; + (void)_sWNTAssumeResultString; +#endif + } + + void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL( + OString const& _sURL, + osl::FileBase::RC _nAssumeError, + OString const& _sUnixAssumeResultString) + { +#if (defined UNX) + check_SystemPath_FileURL(_sURL, _nAssumeError, _sUnixAssumeResultString); +#else + (void)_sURL; + (void)_nAssumeError; + (void)_sUnixAssumeResultString; +#endif + } + + void SystemPath_FileURL::checkWNTBehaviour_getFileURLFromSystemPath( + OString const& _sSysPath, + osl::FileBase::RC _nAssumeError, + OString const& _sWNTAssumeResultString) + { +#if defined(_WIN32) + check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sWNTAssumeResultString, false); +#else + (void)_sSysPath; + (void)_nAssumeError; + (void)_sWNTAssumeResultString; +#endif + } + + void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath( + OString const& _sSysPath, + osl::FileBase::RC _nAssumeError, + OString const& _sUnixAssumeResultString) + { +#if (defined UNX) + check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sUnixAssumeResultString, false); +#else + (void)_sSysPath; + (void)_nAssumeError; + (void)_sUnixAssumeResultString; +#endif + } + + /** Test for getSystemPathFromFileURL() + this test is split into 2 different OS tests, + the first function checkUNXBehaviour... runs only on Unix based Systems, + the second only on windows based systems + the first parameter are a file URL where we want to get the system path of, + the second parameter is the assumed error of the osl_getSystemPathFromFileURL() function, + the third parameter is the assumed result string, the string will only test, if its length is greater 0 + */ + + void SystemPath_FileURL::getSystemPathFromFileURL_001_1() + { + OString sURL(""); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_2() + { + OString sURL("/"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_21() + { + /* From RFC3986, "2.2. Reserved Characters": + + "The purpose of reserved characters is to provide a set of delimiting + characters that are distinguishable from other data within a URI. + URIs that differ in the replacement of a reserved character with its + corresponding percent-encoded octet are not equivalent. Percent- + encoding a reserved character, or decoding a percent-encoded octet + that corresponds to a reserved character, will change how the URI is + interpreted by most applications. Thus, characters in the reserved + set are protected from normalization and are therefore safe to be + used by scheme-specific and producer-specific algorithms for + delimiting data subcomponents within a URI." + + In other words, %2F ("/") is NOT the same as /. + */ + OString sURL("%2F"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_22() + { + OString sURL("file:///tmp%2Fmydir"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_3() + { + OString sURL("a"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_31() + { + OString sURL("tmpname"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_4() + { + OString sURL("file://"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_41() + { + OString sURL("file://localhost/tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_5() + { + OString sURL("file:///tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_51() + { + OString sURL("file://c:/tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_52() + { + OString sURL("file:///c:/tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_53() + { + OString sURL("file:///c|/tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c|/tmp"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_6() + { + OString sURL("file:///tmp/first"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_61() + { + OString sURL("file:///c:/tmp/first"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_7() + { + OString sURL("file:///tmp/../second"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/../second"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_71() + { + OString sURL("file:///c:/tmp/../second"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/../second"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\..\\second"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_8() + { + OString sURL("../tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "../tmp"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "..\\tmp"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_81() + { +#if 0 + OString sURL("file://~/tmp"); + char* home_path; + home_path = getenv("HOME"); + OString expResult(home_path); + expResult += "/tmp"; + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, expResult); +#endif + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_9() + { + OString sURL("file:///tmp/first%20second"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first second"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_91() + { + OString sURL("file:///c:/tmp/first%20second"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first second"); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first second"); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_92() + { + OString sURL("ca@#;+.,$///78no%01ni..name"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + // normal legal case + void SystemPath_FileURL::getSystemPathFromFileURL_004() + { + OUString aUStr; + OUString aUNormalURL(aTmpName6); + OUString aUResultURL (aSysPath4); + osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL(aUNormalURL, aUStr); + + bool bOk = compareFileName(aUStr, aUResultURL); + + OString sError = + "test for getSystemPathFromFileURL(' " + + OUStringToOString(aUNormalURL, RTL_TEXTENCODING_ASCII_US) + + " ') function:use an absolute file URL, " + + outputError(OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US), + OUStringToOString(aUResultURL, RTL_TEXTENCODING_ASCII_US)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_None, nError); + CPPUNIT_ASSERT_MESSAGE(sError.getStr(), bOk); + + } + + // CJK characters case + void SystemPath_FileURL::getSystemPathFromFileURL_005() + { + OUString aUStr; + createTestDirectory(aTmpName10); + OUString aUNormalURL(aTmpName10); + OUString aUResultURL (aSysPath5); + + osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL(aUNormalURL, aUStr); + + bool bOk = compareFileName(aUStr, aUResultURL); + + OString sError = + "test for getSystemPathFromFileURL(' " + + OUStringToOString(aUNormalURL, RTL_TEXTENCODING_ASCII_US) + + " ') function:use a CJK coded absolute URL, " + + outputError(OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US), + OUStringToOString(aUResultURL, RTL_TEXTENCODING_ASCII_US)); + deleteTestDirectory(aTmpName10); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_None, nError); + CPPUNIT_ASSERT_MESSAGE(sError.getStr(), bOk); + } + + void SystemPath_FileURL::getFileURLFromSystemPath_001() + { + OString sSysPath("~/tmp"); + char* home_path; + home_path = getenv("HOME"); + OString expResult(home_path); + expResult = "file://"+ expResult + "/tmp"; + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, expResult); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "~/tmp"); + } + + void SystemPath_FileURL::getFileURLFromSystemPath_002() + { + OString sSysPath("c:/tmp"); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "c:/tmp"); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///c:/tmp"); + } + + void SystemPath_FileURL::getFileURLFromSystemPath_003() + { + OString sSysPath("file:///temp"); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getFileURLFromSystemPath_004() + { + OString sSysPath("//tmp//first start"); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start"); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getFileURLFromSystemPath_004_1() + { + OString sSysPath("/tmp///first start"); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start"); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getFileURLFromSystemPath_005() + { + OString sSysPath(""); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + } + + // testing the method + // static inline RC searchFileURL( const OUString& ustrFileName, + // const OUString& ustrSearchPath, + // OUString& ustrFileURL) + + class searchFileURL : public CppUnit::TestFixture + { + private: + OUString aUStr; + osl::FileBase::RC nError1, nError2, nError3,nError4; + + public: + searchFileURL() + : nError1(osl::FileBase::E_None) + , nError2(osl::FileBase::E_None) + , nError3(osl::FileBase::E_None) + , nError4(osl::FileBase::E_None) {} + + void searchFileURL_001() + { + /* search file is passed by system filename */ + nError1 = osl::FileBase::searchFileURL(aTmpName1, aUserDirectorySys, aUStr); + /* search file is passed by full qualified file URL */ + nError2 = osl::FileBase::searchFileURL(aCanURL1, aUserDirectorySys, aUStr); + /* search file is passed by relative file path */ + nError3 = osl::FileBase::searchFileURL(aRelURL4, aUserDirectorySys, aUStr); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ", + osl::FileBase::E_NOENT, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ", + osl::FileBase::E_NOENT, nError2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ", + osl::FileBase::E_NOENT, nError3); + } + + void searchFileURL_002() + { + /* search file is passed by system filename */ + OUString strRootSys = INetURLObject(aTempDirectoryURL).GetLastName(); + nError1 = osl::FileBase::searchFileURL(aTempDirectorySys, strRootSys, aUStr); + bool bOk1 = compareFileName(aUStr, aTempDirectoryURL); + /* search file is passed by full qualified file URL */ + nError2 = osl::FileBase::searchFileURL(aTempDirectoryURL, strRootSys, aUStr); + bool bOk2 = compareFileName(aUStr, aTempDirectoryURL); + /* search file is passed by relative file path */ + nError3 = osl::FileBase::searchFileURL(aRelURL5, strRootSys, aUStr); + bool bOk3 = compareFileName(aUStr, aTempDirectoryURL); + /* search file is passed by an exist file */ + createTestFile(aCanURL1); + nError4 = osl::FileBase::searchFileURL(aCanURL4, aUserDirectorySys, aUStr); + bool bOk4 = compareFileName(aUStr, aCanURL1); + deleteTestFile(aCanURL1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + osl::FileBase::E_None, nError3); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + osl::FileBase::E_None, nError4); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + bOk1); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + bOk2); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + bOk3); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + bOk4); + } + + void searchFileURL_003() + { + OUString aSystemPathList(aRootSys + PATH_LIST_DELIMITER + aTempDirectorySys + PATH_LIST_DELIMITER + aRootSys + "system/path"); + nError1 = osl::FileBase::searchFileURL(aUserDirectoryURL, aSystemPathList, aUStr); + bool bOk = compareFileName(aUStr, aUserDirectoryURL); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: search directory is a list of system paths", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: search directory is a list of system paths", + bOk); + } + + void searchFileURL_004() + { + OUString aSystemPathList(aRootSys + PATH_LIST_DELIMITER + aTempDirectorySys + PATH_LIST_DELIMITER + aRootSys + "system/path/../name"); + nError1 = osl::FileBase::searchFileURL(aUserDirectoryURL, aSystemPathList, aUStr); + bool bOk = compareFileName(aUStr, aUserDirectoryURL); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: search directory is a list of system paths", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: search directory is a list of system paths", + bOk); + } + + void searchFileURL_005() + { + nError1 = osl::FileBase::searchFileURL(aUserDirectoryURL, aNullURL, aUStr); + bool bOk = compareFileName(aUStr, aUserDirectoryURL); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: search directory is NULL", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: search directory is NULL", + bOk); + } + + CPPUNIT_TEST_SUITE(searchFileURL); + CPPUNIT_TEST(searchFileURL_001); + CPPUNIT_TEST(searchFileURL_002); + CPPUNIT_TEST(searchFileURL_003); + CPPUNIT_TEST(searchFileURL_004); + CPPUNIT_TEST(searchFileURL_005); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // static inline RC getTempDirURL(OUString& ustrTempDirURL) + + class getTempDirURL : public CppUnit::TestFixture + { + private: + OUString aUStr; + osl::FileBase::RC nError; + + public: + getTempDirURL() : nError(osl::FileBase::E_None) {} + + void setUp() override + { + nError = osl::FileBase::getTempDirURL(aUStr); + } + + void getTempDirURL_001() + { + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getTempDirURL function: execution", + osl::FileBase::E_None, nError); + } + + void getTempDirURL_002() + { + CPPUNIT_ASSERT_MESSAGE("test for getTempDirURL function: test for open and write access rights", + checkDirectory(aUStr, oslCheckMode::OpenAccess)); + CPPUNIT_ASSERT_MESSAGE("test for getTempDirURL function: test for open and write access rights", + checkDirectory(aUStr, oslCheckMode::ReadAccess)); + CPPUNIT_ASSERT_MESSAGE("test for getTempDirURL function: test for open and write access rights", + checkDirectory(aUStr, oslCheckMode::WriteAccess)); + } + + CPPUNIT_TEST_SUITE(getTempDirURL); + CPPUNIT_TEST(getTempDirURL_001); + CPPUNIT_TEST(getTempDirURL_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // static inline RC createTempFile(OUString* pustrDirectoryURL, + // oslFileHandle* pHandle, + // OUString* pustrTempFileURL) + + class createTempFile : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + bool bOK; + + std::unique_ptr<oslFileHandle> pHandle; + std::unique_ptr<OUString> pUStr_DirURL; + std::unique_ptr<OUString> pUStr_FileURL; + + public: + createTempFile() + : nError1(osl::FileBase::E_None) + , nError2(osl::FileBase::E_None) + , bOK(false) + { + } + + void setUp() override + { + pHandle.reset(new oslFileHandle()); + pUStr_DirURL.reset(new OUString(aUserDirectoryURL)); + pUStr_FileURL.reset(new OUString()); + } + + void tearDown() override + { + pUStr_DirURL.reset(); + pUStr_FileURL.reset(); + pHandle.reset(); + } + + void createTempFile_001() + { + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), pUStr_FileURL.get()); + File testFile(*pUStr_FileURL); + nError2 = testFile.open(osl_File_OpenFlag_Create); + + if (nError2 == osl::FileBase::E_EXIST) + { + osl_closeFile(*pHandle); + deleteTestFile(*pUStr_FileURL); + } + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for createTempFile function: create temp file and test the existence", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for createTempFile function: create temp file and test the existence", + (pHandle != nullptr)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for createTempFile function: create temp file and test the existence", + osl::FileBase::E_EXIST, nError2); + } + + void createTempFile_002() + { + bOK = false; + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), pUStr_FileURL.get()); + File testFile(*pUStr_FileURL); + nError2 = testFile.open(osl_File_OpenFlag_Create); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("createTempFile function: create a temp file, but it does not exist", + (pHandle != nullptr)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist", + osl::FileBase::E_EXIST, nError2); + + // check file if have the write permission + if (nError2 == osl::FileBase::E_EXIST) + { + bOK = ifFileCanWrite(*pUStr_FileURL); + osl_closeFile(*pHandle); + deleteTestFile(*pUStr_FileURL); + } + + CPPUNIT_ASSERT_MESSAGE("test for open and write access rights, in (W32), it did not have write access right, but it should be writable.", + bOK); + } + + void createTempFile_003() + { + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), nullptr); + // the temp file will be removed when return from createTempFile + bOK = (pHandle != nullptr && nError1 == osl::FileBase::E_None); + if (bOK) + osl_closeFile(*pHandle); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.", + bOK); + } + + void createTempFile_004() + { + nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), nullptr, pUStr_FileURL.get()); + bOK = (pUStr_FileURL != nullptr); + CPPUNIT_ASSERT(bOK); + File testFile(*pUStr_FileURL); + nError2 = testFile.open(osl_File_OpenFlag_Create); + deleteTestFile(*pUStr_FileURL); + CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist", + osl::FileBase::E_EXIST, nError2); + CPPUNIT_ASSERT_MESSAGE("createTempFile function: create a temp file, but it does not exist", + bOK); + + } + + CPPUNIT_TEST_SUITE(createTempFile); + CPPUNIT_TEST(createTempFile_001); + CPPUNIT_TEST(createTempFile_002); + CPPUNIT_TEST(createTempFile_003); + CPPUNIT_TEST(createTempFile_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // FIXME: remove the _disabled to enable: + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::getAbsoluteFileURL, "osl_osl::FileBase_disabled"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::SystemPath_FileURL, "osl_osl::FileBase"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::searchFileURL, "osl_osl::FileBase_disabled"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::getTempDirURL, "osl_osl::FileBase_disabled"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::createTempFile, "osl_osl::FileBase_disabled"); + + CPPUNIT_REGISTRY_ADD_TO_DEFAULT("osl_osl::FileBase"); +} + +namespace osl_FileStatus +{ + // testing the method + // FileStatus(sal_uInt32 nMask): _nMask(nMask) + class ctors : public CppUnit::TestFixture + { + private: + OUString aUStr; + osl::FileBase::RC nError1; + DirectoryItem rItem; + + public: + ctors() : nError1(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + Directory aDir(aTmpName3); + nError1 = aDir.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = aDir.getNextItem(rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + aDir.close(); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + void ctors_001() + { + FileStatus rFileStatus(osl_FileStatus_Mask_All); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + aUStr = rFileStatus.getFileName(); + + CPPUNIT_ASSERT_MESSAGE("test for ctors function: mask all and see the file name", + compareFileName(aUStr, aTmpName2)); + } + + void ctors_002() + { + FileStatus rFileStatus(0); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + aUStr = rFileStatus.getFileName(); + + CPPUNIT_ASSERT_MESSAGE("test for ctors function: mask is empty", + compareFileName(aUStr, aNullURL)); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctors_001); + CPPUNIT_TEST(ctors_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline sal_Bool isValid(sal_uInt32 nMask) const + + class isValid : public CppUnit::TestFixture + { + private: + std::unique_ptr<Directory> pDir; + DirectoryItem rItem_file, rItem_link; + + public: + isValid() + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + pDir.reset(new Directory(aTmpName3)); + osl::FileBase::RC nError1 = pDir->open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = pDir->getNextItem(rItem_file, 1); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + osl::FileBase::RC nError1 = pDir->close(); + pDir.reset(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1); + + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + void isValid_001() + { + sal_uInt32 mask = 0; + FileStatus rFileStatus(mask); + osl::FileBase::RC nError1 = rItem_file.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + bool bOk = rFileStatus.isValid(mask); + + CPPUNIT_ASSERT_MESSAGE("test for isValid function: no fields specified", bOk); + } + + void check_FileStatus(FileStatus const& _aStatus) + { + OString sStat; + if (_aStatus.isValid(osl_FileStatus_Mask_Type)) + sStat += "type "; + if (_aStatus.isValid(osl_FileStatus_Mask_Attributes)) + sStat += "attributes "; + if (_aStatus.isValid(osl_FileStatus_Mask_CreationTime)) + sStat += "ctime "; + if (_aStatus.isValid(osl_FileStatus_Mask_AccessTime)) + sStat += "atime "; + if (_aStatus.isValid(osl_FileStatus_Mask_ModifyTime)) + sStat += "mtime "; + if (_aStatus.isValid(osl_FileStatus_Mask_FileSize)) + sStat += "filesize "; + if (_aStatus.isValid(osl_FileStatus_Mask_FileName)) + sStat += "filename "; + if (_aStatus.isValid(osl_FileStatus_Mask_FileURL)) + sStat += "fileurl "; + printf("mask: %s\n", sStat.getStr()); + } + + void isValid_002() + { + createTestFile(aTmpName6); + sal_uInt32 mask_file = osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_Attributes | + osl_FileStatus_Mask_CreationTime | + osl_FileStatus_Mask_AccessTime | + osl_FileStatus_Mask_ModifyTime | + osl_FileStatus_Mask_FileSize | + osl_FileStatus_Mask_FileName | + osl_FileStatus_Mask_FileURL; + + FileStatus rFileStatus(mask_file); + DirectoryItem::get(aTmpName6, rItem_file); + osl::FileBase::RC nError1 = rItem_file.getFileStatus(rFileStatus); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1); + + check_FileStatus(rFileStatus); + deleteTestFile(aTmpName6); + + } + + /** Check if is a valid linked file. + + Link is not defined in Windows, and on Linux, we can not get the directory item of the linked file. + We have to defer to filesystems, normal filesystems support links (EXT2, ...), castrated filesystems + don't have links (FAT, FAT32) and Windows NT NTFS support links, but the Windows API doesn't :-( + */ + void isValid_003() + { +#if defined (UNX) + sal_Int32 fd; + + OUString aUStr_LnkFileSys(aTempDirectorySys), aUStr_SrcFileSys(aTempDirectorySys); + aUStr_LnkFileSys += aSlashURL + getCurrentPID() + "/tmpdir/link.file"; + aUStr_SrcFileSys += aSlashURL + getCurrentPID() + "/tmpdir/tmpname"; + + OString strLinkFileName; + OString strSrcFileName; + strLinkFileName = OUStringToOString(aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US); + strSrcFileName = OUStringToOString(aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US); + + // create a link file and link it to file "/tmp/PID/tmpdir/tmpname" + fd = symlink(strSrcFileName.getStr(), strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd); + + // testDirectory is "/tmp/PID/tmpdir/" + Directory testDirectory(aTmpName3); + testDirectory.open(); + OUString aFileName ("link.file"); + bool bOk = false; + while (true) + { + osl::FileBase::RC nError1 = testDirectory.getNextItem(rItem_link, 4); + + if (nError1 == osl::FileBase::E_None) + { + sal_uInt32 mask_link = osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_LinkTargetURL; + FileStatus rFileStatus(mask_link); + rItem_link.getFileStatus(rFileStatus); + + if (compareFileName(rFileStatus.getFileName(), aFileName)) + { + if (rFileStatus.isValid(osl_FileStatus_Mask_LinkTargetURL)) + { + bOk = true; + break; + } + } + } + else + { + break; + } + }; + + fd = remove(strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd); + + CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL", bOk); +#endif + } + + void isValid_004() + { + sal_uInt32 mask_file_all = osl_FileStatus_Mask_All; + FileStatus rFileStatus_all(mask_file_all); + osl::FileBase::RC nError1 = rItem_file.getFileStatus(rFileStatus_all); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + check_FileStatus(rFileStatus_all); + + sal_uInt32 mask_file_val = osl_FileStatus_Mask_Validate; + FileStatus rFileStatus_val(mask_file_val); + nError1 = rItem_file.getFileStatus(rFileStatus_val); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + check_FileStatus(rFileStatus_val); + } + + CPPUNIT_TEST_SUITE(isValid); + CPPUNIT_TEST(isValid_001); + CPPUNIT_TEST(isValid_002); + CPPUNIT_TEST(isValid_003); + CPPUNIT_TEST(isValid_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline Type getFileType() const + + class getFileType : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + + DirectoryItem m_aItem_1, m_aItem_2, m_aVolumeItem, m_aFifoItem; + DirectoryItem m_aLinkItem, m_aSocketItem, m_aSpecialItem; + + public: + getFileType() : nError1(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile: $TEMP/tmpdir/tmpname. + // a tempdirectory: $TEMP/tmpdir/tmpdir. + // use $ROOT/staroffice as volume ---> use dev/fd as volume. + // and get their directory item. + createTestDirectory(aTmpName3); + createTestFile(aTmpName3, aTmpName2); + createTestDirectory(aTmpName3, aTmpName1); + + std::unique_ptr<Directory> xDir(new Directory(aTmpName3)); + nError1 = xDir->open(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("open aTmpName3 failed!", osl::FileBase::E_None, nError1); + // getNextItem can not assure which item retrieved + nError1 = xDir->getNextItem(m_aItem_1, 1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get first item failed!", osl::FileBase::E_None, nError1); + + nError1 = xDir->getNextItem(m_aItem_2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get second item failed!", osl::FileBase::E_None, nError1); + xDir->close(); + // FIXME mindy: failed on my RH9, so removed temporarily + // nError1 = DirectoryItem::get(aVolURL2, m_aVolumeItem); + // CPPUNIT_ASSERT_MESSAGE("get volume item failed!", osl::FileBase::E_None == nError1); + } + + void tearDown() override + { + // remove all in $TEMP/tmpdir. + deleteTestDirectory(aTmpName3, aTmpName1); + deleteTestFile(aTmpName3, aTmpName2); + deleteTestDirectory(aTmpName3); + } + + void getFileType_001() + { + FileStatus rFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName); + nError1 = m_aItem_1.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getFileStatus failed", osl::FileBase::E_None, nError1); + + check_FileType(rFileStatus); + } + + void check_FileType(osl::FileStatus const& _rFileStatus) + { + if (_rFileStatus.isValid(osl_FileStatus_Mask_FileName)) + { + OUString suFilename = _rFileStatus.getFileName(); + + if (_rFileStatus.isValid(osl_FileStatus_Mask_Type)) + { + osl::FileStatus::Type eType = _rFileStatus.getFileType(); + bool bOK = false; + + if (compareFileName(suFilename, aTmpName2)) + bOK = (eType == osl::FileStatus::Regular); + + if (compareFileName(suFilename, aTmpName1)) + bOK = (eType == FileStatus::Directory); + + CPPUNIT_ASSERT_MESSAGE("test for getFileType function: ", bOK); + } + } + // LLA: it's not a bug, if a FileStatus not exist, so no else + } + + void getFileType_002() + { + FileStatus rFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName); + nError1 = m_aItem_2.getFileStatus(rFileStatus); + + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + check_FileType(rFileStatus); + } + + void getFileType_003() + { + } + + void getFileType_007() + { +#if defined(__sun) // Special file is different in Windows + nError1 = DirectoryItem::get(aTypeURL2, m_aSpecialItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // check for File type + FileStatus rFileStatus(osl_FileStatus_Mask_Type); + nError1 = m_aSpecialItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + if (rFileStatus.isValid(osl_FileStatus_Mask_Type)) + { + osl::FileStatus::Type eType = rFileStatus.getFileType(); + + CPPUNIT_ASSERT_MESSAGE("test for getFileType function: Special, Solaris version ", + (eType == FileStatus::Special)); + } +#endif + } + + CPPUNIT_TEST_SUITE(getFileType); + CPPUNIT_TEST(getFileType_001); + CPPUNIT_TEST(getFileType_002); + CPPUNIT_TEST(getFileType_003); + CPPUNIT_TEST(getFileType_007); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline sal_uInt64 getAttributes() const + + class getAttributes : public CppUnit::TestFixture + { + private: + OUString aTypeURL, aTypeURL_Hid; + osl::FileBase::RC nError; + DirectoryItem rItem, rItem_hidden; + + public: + getAttributes() : nError(osl::FileBase::E_None) {} + + void setUp() override + { + aTypeURL = aUserDirectoryURL.copy(0); + concatURL(aTypeURL, aTmpName2); + createTestFile(aTypeURL); + nError = DirectoryItem::get(aTypeURL, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + aTypeURL_Hid = aUserDirectoryURL.copy(0); + concatURL(aTypeURL_Hid, aHidURL1); + createTestFile(aTypeURL_Hid); + nError = DirectoryItem::get(aTypeURL_Hid, rItem_hidden); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + } + + void tearDown() override + { + deleteTestFile(aTypeURL); + deleteTestFile(aTypeURL_Hid); + } + +#if (defined UNX) +// windows only has 3 file attributes: normal, readonly and hidden + void getAttributes_001() + { + changeFileMode(aTypeURL, S_IRUSR | S_IRGRP | S_IROTH); + + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead(UNX version) ", + static_cast<sal_uInt64>(osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead), + rFileStatus.getAttributes()); + } +#else // Windows version + void getAttributes_001() + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead(Windows version)", + 1, 1); + } +#endif + + void getAttributes_002() + { +#if (defined UNX) + changeFileMode(aTypeURL, S_IXUSR | S_IXGRP | S_IXOTH); + + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getAttributes function: Executable, GrpExe, OwnExe, OthExe, the result is Readonly, Executable, GrpExe, OwnExe, OthExe, it partly not pass(Solaris version)", + static_cast<sal_uInt64>(osl_File_Attribute_ReadOnly | osl_File_Attribute_Executable | osl_File_Attribute_GrpExe | osl_File_Attribute_OwnExe | osl_File_Attribute_OthExe), + rFileStatus.getAttributes()); +#endif + } + +#if (defined UNX) + void getAttributes_003() + { + changeFileMode(aTypeURL, S_IWUSR | S_IWGRP | S_IWOTH); + + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getAttributes function: GrpWrite, OwnWrite, OthWrite(Solaris version)", + static_cast<sal_uInt64>(osl_File_Attribute_GrpWrite | osl_File_Attribute_OwnWrite | osl_File_Attribute_OthWrite), + rFileStatus.getAttributes()); + } +#else // Windows version + void getAttributes_003() + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getAttributes function: GrpWrite, OwnWrite, OthWrite(Windows version)", + 1, 1); + } +#endif + +#if (defined UNX) // hidden file definition may be different in Windows + void getAttributes_004() + { + sal_Int32 test_Attributes = osl_File_Attribute_Hidden; + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError = rItem_hidden.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + test_Attributes &= rFileStatus.getAttributes(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getAttributes function: Hidden files(Solaris version)", + static_cast<sal_Int32>(osl_File_Attribute_Hidden), test_Attributes); + } +#else // Windows version + void getAttributes_004() + { + OUString aUserHiddenFileURL ("file:///c:/AUTOEXEC.BAT"); + nError = DirectoryItem::get(aUserHiddenFileURL, rItem_hidden); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get item fail", osl::FileBase::E_None, nError); + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError = rItem_hidden.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + CPPUNIT_ASSERT_MESSAGE("Hidden files(Windows version), please check if hidden file c:/AUTOEXEC.BAT exists ", + (rFileStatus.getAttributes() & osl_File_Attribute_Hidden)!= 0); + } +#endif + + CPPUNIT_TEST_SUITE(getAttributes); + CPPUNIT_TEST(getAttributes_001); + CPPUNIT_TEST(getAttributes_002); + CPPUNIT_TEST(getAttributes_003); + CPPUNIT_TEST(getAttributes_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline TimeValue getAccessTime() const + + class getAccessTime : public CppUnit::TestFixture + { + private: + OUString aTypeURL; + osl::FileBase::RC nError; + DirectoryItem rItem; + + public: + getAccessTime() : nError(osl::FileBase::E_None) {} + + void setUp() override + { + aTypeURL = aUserDirectoryURL.copy(0); + concatURL(aTypeURL, aTmpName2); + createTestFile(aTypeURL); + nError = DirectoryItem::get(aTypeURL, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + } + + void tearDown() override + { + deleteTestFile(aTypeURL); + } + + void getAccessTime_001() + { + TimeValue *pTV_current = nullptr; + CPPUNIT_ASSERT((pTV_current = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + TimeValue *pTV_access = nullptr; + CPPUNIT_ASSERT((pTV_access = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + + FileStatus rFileStatus(osl_FileStatus_Mask_AccessTime); + nError = rItem.getFileStatus(rFileStatus); + bool bOk = osl_getSystemTime(pTV_current); + CPPUNIT_ASSERT(bOk); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + *pTV_access = rFileStatus.getAccessTime(); + + bool bOK = t_compareTime(pTV_access, pTV_current, delta); + free(pTV_current); + free(pTV_access); + + CPPUNIT_ASSERT_MESSAGE("test for getAccessTime function: This test turns out that UNX precision is no more than 1 sec, don't know how to test this function, in Windows test, it lost hour min sec, only have date time. ", + bOK); + } + + CPPUNIT_TEST_SUITE(getAccessTime); + CPPUNIT_TEST(getAccessTime_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline TimeValue getModifyTime() const + + class getModifyTime : public CppUnit::TestFixture + { + private: + OUString aTypeURL; + osl::FileBase::RC nError; + DirectoryItem rItem; + + public: + getModifyTime() : nError(osl::FileBase::E_None) {} + + void getModifyTime_001() + { + TimeValue *pTV_current = nullptr; + CPPUNIT_ASSERT((pTV_current = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + + // create file + aTypeURL = aUserDirectoryURL.copy(0); + concatURL(aTypeURL, aTmpName2); + createTestFile(aTypeURL); + + // get current time + bool bOk = osl_getSystemTime(pTV_current); + CPPUNIT_ASSERT(bOk); + + // get instance item and filestatus + nError = DirectoryItem::get(aTypeURL, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + FileStatus rFileStatus(osl_FileStatus_Mask_ModifyTime); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + // get modify time + TimeValue* pTV_modify = nullptr; + CPPUNIT_ASSERT((pTV_modify = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + *pTV_modify = rFileStatus.getModifyTime(); + + bool bOK = t_compareTime(pTV_modify, pTV_current, delta); + // delete file + deleteTestFile(aTypeURL); + free(pTV_current); + free(pTV_modify); + + CPPUNIT_ASSERT_MESSAGE("test for getModifyTime function: This test turns out that UNX precision is no more than 1 sec, don't know how to improve this function. ", + bOK); + } + + CPPUNIT_TEST_SUITE(getModifyTime); + CPPUNIT_TEST(getModifyTime_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline sal_uInt64 getFileSize() const + + class getFileSize : public CppUnit::TestFixture + { + private: + OUString aTypeURL; + osl::FileBase::RC nError; + DirectoryItem rItem; + + public: + getFileSize() : nError(osl::FileBase::E_None) {} + + void setUp() override + { + aTypeURL = aUserDirectoryURL.copy(0); + concatURL(aTypeURL, aTmpName2); + createTestFile(aTypeURL); + nError = DirectoryItem::get(aTypeURL, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + } + + void tearDown() override + { + deleteTestFile(aTypeURL); + } + + void getFileSize_001() + { + FileStatus rFileStatus(osl_FileStatus_Mask_FileSize); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + sal_uInt64 uFileSize = rFileStatus.getFileSize(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getFileSize function: empty file ", + static_cast<sal_uInt64>(0), uFileSize); + } + + void getFileSize_002() + { + File testfile(aTypeURL); + nError = testfile.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + nError = testfile.setSize(TEST_FILE_SIZE); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + nError = DirectoryItem::get(aTypeURL, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + FileStatus rFileStatus(osl_FileStatus_Mask_FileSize); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + sal_uInt64 uFileSize = rFileStatus.getFileSize(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getFileSize function: file with size of TEST_FILE_SIZE, did not pass in (W32). ", + static_cast<sal_uInt64>(TEST_FILE_SIZE), uFileSize); + } + + CPPUNIT_TEST_SUITE(getFileSize); + CPPUNIT_TEST(getFileSize_001); + CPPUNIT_TEST(getFileSize_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline OUString getFileName() const + + class getFileName : public CppUnit::TestFixture + { + private: + OUString aTypeURL; + osl::FileBase::RC nError; + DirectoryItem rItem; + + public: + getFileName() : nError(osl::FileBase::E_None) {} + void setUp() override + { + aTypeURL = aUserDirectoryURL.copy(0); + concatURL(aTypeURL, aTmpName2); + createTestFile(aTypeURL); + nError = DirectoryItem::get(aTypeURL, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + } + + void tearDown() override + { + deleteTestFile(aTypeURL); + } + + + void getFileName_001() + { + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + OUString aFileName = rFileStatus.getFileName(); + + CPPUNIT_ASSERT_MESSAGE("test for getFileName function: name compare with specify", + compareFileName(aFileName, aTmpName2)); + } + + CPPUNIT_TEST_SUITE(getFileName); + CPPUNIT_TEST(getFileName_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline OUString getFileURL() const + + class getFileURL : public CppUnit::TestFixture + { + osl::FileBase::RC nError; + DirectoryItem rItem; + + public: + getFileURL() : nError(osl::FileBase::E_None) {} + + + void setUp() override + { + createTestFile(aTmpName6); + nError = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + } + + void tearDown() override + { + deleteTestFile(aTmpName6); + } + + + void getFileURL_001() + { + FileStatus rFileStatus(osl_FileStatus_Mask_FileURL); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError); + + OUString aFileURL = rFileStatus.getFileURL(); + + CPPUNIT_ASSERT_MESSAGE("test for getFileURL function: ", + compareFileName(aFileURL, aTmpName6)); + } + + CPPUNIT_TEST_SUITE(getFileURL); + CPPUNIT_TEST(getFileURL_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline OUString getLinkTargetURL() const + + class getLinkTargetURL : public CppUnit::TestFixture + { + private: + OUString aTypeURL; + DirectoryItem rItem; + + public: + void setUp() override + { + aTypeURL = aUserDirectoryURL.copy(0); + concatURL(aTypeURL, aTmpName2); + createTestFile(aTypeURL); + } + + void tearDown() override + { + deleteTestFile(aTypeURL); + } + +#if (defined UNX) // Link file is not defined in Windows + void getLinkTargetURL_001() + { + // create a link file; + OUString aUStr_LnkFileSys(aTempDirectorySys), aUStr_SrcFileSys(aTempDirectorySys); + aUStr_LnkFileSys += aSlashURL + getCurrentPID() + "/link.file"; + aUStr_SrcFileSys += aSlashURL + getCurrentPID() + "/tmpname"; + + OString strLinkFileName, strSrcFileName; + strLinkFileName = OUStringToOString(aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US); + strSrcFileName = OUStringToOString(aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US); + + sal_Int32 fd; + fd = symlink(strSrcFileName.getStr(), strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("in creating link file", static_cast<sal_Int32>(0), fd); + + // get linkTarget URL + auto nError = DirectoryItem::get(aLnkURL1, rItem); + CPPUNIT_ASSERT_EQUAL_MESSAGE("in getting link file item", osl::FileBase::E_None, nError); + + FileStatus rFileStatus(osl_FileStatus_Mask_LinkTargetURL); + nError = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL_MESSAGE("in getting link file status", osl::FileBase::E_None, nError); + OUString aFileURL = rFileStatus.getLinkTargetURL(); + + // remove link file + fd = remove(strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("in deleting link file", static_cast<sal_Int32>(0), fd); + + CPPUNIT_ASSERT_MESSAGE("test for getLinkTargetURL function: Solaris version, create a file, and a link file link to it, get its LinkTargetURL and compare", + compareFileName(aFileURL, aTypeURL)); + } +#else + void getLinkTargetURL_001() + { + CPPUNIT_ASSERT_MESSAGE("test for getLinkTargetURL function: Windows version, not tested", + 1); + } +#endif + + CPPUNIT_TEST_SUITE(getLinkTargetURL); + CPPUNIT_TEST(getLinkTargetURL_001); + CPPUNIT_TEST_SUITE_END(); + }; + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::ctors, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::isValid, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getFileType, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getAttributes, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getAccessTime, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getModifyTime, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getFileSize, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getFileName, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getFileURL, "osl_FileStatus"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileStatus::getLinkTargetURL, "osl_FileStatus"); +} + +namespace osl_File +{ + + // testing the method + // File(const OUString& ustrFileURL) + + class ctors : public CppUnit::TestFixture + { + public: + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + void ctors_001() + { + File testFile(aTmpName4); + + osl::FileBase::RC nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + osl::FileBase::RC nError2 = testFile.close(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: initialize a File and test its open and close", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: initialize a File and test its open and close", + osl::FileBase::E_None, nError2); + } + + void ctors_002() + { + File testFile(aTmpName5); + char buffer[30] = "Test for File constructor"; + sal_uInt64 nCount; + + osl::FileBase::RC nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + osl::FileBase::RC nError2 = testFile.write(buffer, 30, nCount); + testFile.close(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: test relative file URL, this test show that relative file URL is also acceptable", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: test relative file URL, this test show that relative file URL is also acceptable", + osl::FileBase::E_None, nError2); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctors_001); + CPPUNIT_TEST(ctors_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC open(sal_uInt32 uFlags) + + class open : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2, nError3; + + public: + open() + : nError1(osl::FileBase::E_None) + , nError2(osl::FileBase::E_None) + , nError3(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void open_001() + { + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + nError2 = testFile.close(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("close error", osl::FileBase::E_None, nError2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: open a regular file", + osl::FileBase::E_None, nError1); + } + + void open_002() + { + File testFile(aTmpName3); + + nError1 = testFile.open(osl_File_OpenFlag_Read); + + CPPUNIT_ASSERT_MESSAGE("test for open function: open a directory", + (File::E_INVAL == nError1) || (File::E_ACCES == nError1)); + } + + void open_003() + { + File testFile(aCanURL1); + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: open a non-exist file", + File::E_NOENT, nError1); + } + + void open_004() + { + OUString aTestFile(aRootURL); + concatURL(aTestFile, aTmpName2); + File testFile(aTestFile); + + nError1 = testFile.open(osl_File_OpenFlag_Create); + bool bOK = (nError1 == File::E_ACCES); +#ifdef _WIN32 + bOK = true; /// in Windows, you can create file in c:\ any way. + testFile.close(); + deleteTestFile(aTestFile); +#endif + + CPPUNIT_ASSERT_MESSAGE("test for open function: create an illegal file", + bOK); + } + + void open_005() + { + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Create); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: create an exist file", + File::E_EXIST, nError1); + } + + void open_006() + { + File testFile(aCanURL1); + char buffer_write[30] = "Test for File open"; + char buffer_read[30]; + sal_uInt64 nCount_write, nCount_read; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create); + nError2 = testFile.write(buffer_write, 30, nCount_write); + osl::FileBase::RC nError4 = testFile.setPos(osl_Pos_Absolut, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError4); + nError3 = testFile.read(buffer_read, 10, nCount_read); + + osl::FileBase::RC nError5 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError5); + osl::FileBase::RC nError6 = osl::File::remove(aCanURL1); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError6); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create", + osl::FileBase::E_None, nError3); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create", + sal_uInt64(30), nCount_write); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create", + sal_uInt64(10), nCount_read); + } + + CPPUNIT_TEST_SUITE(open); + CPPUNIT_TEST(open_001); + CPPUNIT_TEST(open_002); + CPPUNIT_TEST(open_003); + CPPUNIT_TEST(open_004); + CPPUNIT_TEST(open_005); + CPPUNIT_TEST(open_006); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC close() + + class close : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2, nError3; + + public: + close() + : nError1(osl::FileBase::E_None) + , nError2(osl::FileBase::E_None) + , nError3(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void close_001() + { + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError2 = testFile.close(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for close function: close a regular file", + osl::FileBase::E_None, nError2); + } + + void close_002() + { + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError2 = testFile.close(); + + nError3 = testFile.setPos(osl_Pos_Absolut, 0); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for close function: manipulate a file after it has been closed", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_MESSAGE("test for close function: manipulate a file after it has been closed", + (osl::FileBase::E_None != nError3)); + } + + CPPUNIT_TEST_SUITE(close); + CPPUNIT_TEST(close_001); + CPPUNIT_TEST(close_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC setPos(sal_uInt32 uHow, sal_Int64 uPos) + + class setPos : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + setPos() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + , nCount_read(0) + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + void setPos_001() + { + File testFile(aTmpName4); + char buffer_read[2]; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.setPos(osl_Pos_Absolut, 26); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.read(buffer_read, 1, nCount_read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for setPos function: test for osl_Pos_Absolut, set the position to 26, test if the 26th char in file is correct", + pBuffer_Char[26], buffer_read[0]); + } + + void setPos_002() + { + File testFile(aTmpName4); + char buffer_read[2]; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.setPos(osl_Pos_Absolut, sizeof(pBuffer_Char) - 2); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.setPos(osl_Pos_Current, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.read(buffer_read, 1, nCount_read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for setPos function: test for osl_Pos_Current, set the position to end, test if the (end -1) char in file is correct", + pBuffer_Char[sizeof(pBuffer_Char) - 2], buffer_read[0]); + } + + void setPos_003() + { + File testFile(aTmpName4); + char buffer_read[2]; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // the file size is smaller than 100 + nError1 = testFile.setPos(osl_Pos_End, -100); + CPPUNIT_ASSERT_EQUAL_MESSAGE("should return error", osl::FileBase::E_INVAL, nError1); + + nError1 = testFile.setPos(osl_Pos_End, -53); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.read(buffer_read, 1, nCount_read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for setPos function: test for osl_Pos_End, set the position to end, test if the first char in file is correct", + pBuffer_Char[0], buffer_read[0]); + } + + CPPUNIT_TEST_SUITE(setPos); + CPPUNIT_TEST(setPos_001); + CPPUNIT_TEST(setPos_002); + CPPUNIT_TEST(setPos_003); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC getPos(sal_uInt64& uPos) + + class getPos : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + sal_uInt64 nCount_write; + + public: + getPos() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + { + } + + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void getPos_001() + { + File testFile(aTmpName4); + sal_uInt64 nFilePointer; + + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, nError1); + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.setPos(osl_Pos_Absolut, 26); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getPos function: set the position to 26, get position and check if it is right", + static_cast<sal_uInt64>(26), nFilePointer); + } + + CPPUNIT_TEST_SUITE(getPos); + CPPUNIT_TEST(getPos_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC isEndOfFile(sal_Bool *pIsEOF) + + class isEndOfFile : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + sal_uInt64 nCount_write; + + public: + isEndOfFile() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + { + } + + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void isEndOfFile_001() + { + File testFile(aTmpName4); + sal_Bool bEOF = false; + sal_Bool *pEOF = &bEOF; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.setPos(osl_Pos_End, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.isEndOfFile(pEOF); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for isEndOfFile function: set the position to end, check if reach end", + *pEOF); + } + + void isEndOfFile_002() + { + File testFile(aTmpName4); + sal_Bool bEOF = false; + sal_Bool *pEOF = &bEOF; + sal_uInt64 nFilePointer = 0; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.setPos(osl_Pos_Absolut, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + *pEOF = false; + + while (!(*pEOF)) + { + nError1 = testFile.isEndOfFile(pEOF); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.setPos(osl_Pos_Current, 1); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for isEndOfFile function: use isEndOfFile to move pointer step by step", + static_cast<sal_uInt64>(sizeof(pBuffer_Char) + 1), nFilePointer); + } + CPPUNIT_TEST_SUITE(isEndOfFile); + CPPUNIT_TEST(isEndOfFile_001); + CPPUNIT_TEST(isEndOfFile_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC setSize(sal_uInt64 uSize) + + class setSize : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + sal_uInt64 nCount_write; + + public: + setSize() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void setSize_001() + { + File testFile(aTmpName4); + sal_uInt64 nFilePointer; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // enlarge the file to size of 100; + nError1 = testFile.setSize(100); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // get the file size; + nError1 = testFile.setPos(osl_Pos_End, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for setSize function: enlarge the file ", + static_cast<sal_uInt64>(100), nFilePointer); + } + + void setSize_002() + { + File testFile(aTmpName4); + sal_uInt64 nFilePointer; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // enlarge the file to size of 100; + nError1 = testFile.setSize(10); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // get the file size; + nError1 = testFile.setPos(osl_Pos_End, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for setSize function: truncate the file ", + static_cast<sal_uInt64>(10), nFilePointer); + } + + CPPUNIT_TEST_SUITE(setSize); + CPPUNIT_TEST(setSize_001); + CPPUNIT_TEST(setSize_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC read(void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead) + + class read : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + read() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + , nCount_read(0) + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void read_001() + { + File testFile(aTmpName4); + sal_uInt64 nFilePointer; + char buffer_read[10]; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.read(buffer_read, 10, nCount_read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for read function: read whole content in the file to a buffer", + sal_uInt64(10), nFilePointer); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for read function: read whole content in the file to a buffer", + 0, strncmp(buffer_read, pBuffer_Char, 10)); + } + + void read_002() + { + File testFile(aTmpName4); + sal_uInt64 nFilePointer; + char buffer_read[26]; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.setPos(osl_Pos_Absolut, 26); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.read(buffer_read, 26, nCount_read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for read function: read from a special position in the file", + sal_uInt64(52), nFilePointer); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for read function: read from a special position in the file", + sal_uInt64(26), nCount_read); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for read function: read from a special position in the file", + 0, strncmp(buffer_read, &pBuffer_Char[26], 26)); + } + + CPPUNIT_TEST_SUITE(read); + CPPUNIT_TEST(read_001); + CPPUNIT_TEST(read_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten) + + class write : public CppUnit::TestFixture + { + osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + write() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + , nCount_read(0) + { + } + + + void setUp() override + { + // create a tempfile in $TEMP/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile(aTmpName6); + } + + + void write_001() + { + File testFile(aTmpName6); + sal_uInt64 nFilePointer; + char buffer_read[10]; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // write chars into the file. + nError1 = testFile.write(pBuffer_Char, 10, nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // get the current pointer; + nError1 = testFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // reset pointer to the beginning; + nError1 = testFile.setPos(osl_Pos_Absolut, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.read(buffer_read, 10, nCount_read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for write function: read whole content in the file to a buffer. Note, buffer size can not smaller than the read size", + sal_uInt64(10), nFilePointer); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for write function: read whole content in the file to a buffer. Note, buffer size can not smaller than the read size", + 0, strncmp(buffer_read, pBuffer_Char, 10)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for write function: read whole content in the file to a buffer. Note, buffer size can not smaller than the read size", + sal_uInt64(10), nCount_write); + } + + CPPUNIT_TEST_SUITE(write); + CPPUNIT_TEST(write_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC readLine(::ByteSequence& aSeq) + + class readLine : public CppUnit::TestFixture + { + osl::FileBase::RC nError1; + sal_uInt64 nCount_write; + rtl::ByteSequence aSequence; + + public: + readLine() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpname. + createTestFile(aTmpName6); + + // write some strings into the file. + File testFile(aTmpName6); + char ppStrSeq[3][27] = { "abcde\n", + "1234567890\n", + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + }; + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + for (int nCount = 0; nCount < 3; nCount++) + { + nError1 = testFile.write(ppStrSeq[nCount], strlen(ppStrSeq[nCount]), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile(aTmpName6); + } + + + void readLine_001() + { + File testFile(aTmpName6); + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.readLine(aSequence); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for readLine function: read the first line of the file.", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for readLine function: read the first line of the file.", + 0, strncmp(reinterpret_cast<char *>(aSequence.getArray()), pBuffer_Char, 5)); + } + + void readLine_002() + { + File testFile(aTmpName6); + sal_Bool bEOF = false; + sal_Bool *pEOF = &bEOF; + + nError1 = testFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + for (int nCount = 0; nCount < 3; nCount++) + { + nError1 = testFile.readLine(aSequence); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + nError1 = testFile.isEndOfFile(pEOF); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for readLine function: read three lines of the file and check the file pointer moving.", + *pEOF); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for readLine function: read three lines of the file and check the file pointer moving.", + 0, strncmp(reinterpret_cast<char *>(aSequence.getArray()), &pBuffer_Char[26], 26)); + } + CPPUNIT_TEST_SUITE(readLine); + CPPUNIT_TEST(readLine_001); + CPPUNIT_TEST(readLine_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC copy(const OUString& ustrSourceFileURL, const OUString& ustrDestFileURL) + + class copy : public CppUnit::TestFixture + { + osl::FileBase::RC nError1; + sal_uInt64 nCount_write; + + public: + copy() + : nError1(osl::FileBase::E_None) + , nCount_write(0) + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + void copy_001() + { + File testFile(aTmpName6); + + // copy $TEMP/tmpdir/tmpname to $TEMP/tmpname. + nError1 = File::copy(aTmpName4, aTmpName6); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // check + nError1 = testFile.open(osl_File_OpenFlag_Create); + deleteTestFile(aTmpName6); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for copy function: copy file to upper directory", + osl::FileBase::E_EXIST, nError1); + } + + void copy_002() + { + // copy $TEMP/tmpdir/tmpname to $TEMP/tmpdir. + nError1 = File::copy(aTmpName4, aTmpName3); + + CPPUNIT_ASSERT_MESSAGE("test for copy function: use directory as destination", + (osl::FileBase::E_ISDIR == nError1) ||(osl::FileBase::E_ACCES == nError1)); + } + + void copy_003() + { + // copy $TEMP/tmpdir/tmpname to $ROOT/tmpname. + nError1 = File::copy(aTmpName4, aTmpName7); +#if defined(_WIN32) + nError1 = osl::FileBase::E_ACCES; /// for Windows, c:\ is writable anyway. + deleteTestFile(aTmpName7); +#endif + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for copy function: copy to an illegal place", + osl::FileBase::E_ACCES, nError1); + } + + void copy_004() + { + // copy $TEMP/tmpname to $TEMP/tmpdir/tmpname. + nError1 = File::copy(aTmpName6, aTmpName4); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for copy function: copy a not exist file", + osl::FileBase::E_NOENT, nError1); + } + + void copy_005() + { + // copy $TEMP/tmpname to $TEMP/system.path using system path. + nError1 = File::copy(aTmpName6, aSysPath1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for copy function: copy a file using system file path", + osl::FileBase::E_INVAL, nError1); + } + + void copy_006() + { + createTestFile(aTmpName6); + File tmpFile(aTmpName6); + tmpFile.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Read); + tmpFile.setSize(200); + tmpFile.close(); + // copy to new path + nError1 = File::copy(aTmpName6, aTmpName4); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // check if is the new file + File newFile(aTmpName4); + newFile.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Read); + nError1 = newFile.setPos(osl_Pos_End, 0); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + sal_uInt64 nFilePointer; + nError1 = newFile.getPos(nFilePointer); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + newFile.close(); + deleteTestFile(aTmpName6); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for copy function: the dest file exist", + static_cast<sal_uInt64>(200), nFilePointer); + } + + CPPUNIT_TEST_SUITE(copy); + CPPUNIT_TEST(copy_001); + CPPUNIT_TEST(copy_002); + CPPUNIT_TEST(copy_003); + CPPUNIT_TEST(copy_004); + CPPUNIT_TEST(copy_005); + CPPUNIT_TEST(copy_006); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC move(const OUString& ustrSourceFileURL, const OUString& ustrDestFileURL) + + class move : public CppUnit::TestFixture + { + osl::FileBase::RC nError1, nError2; + sal_uInt64 nCount_write; + + public: + move() + : nError1(osl::FileBase::E_None) + , nError2(osl::FileBase::E_None) + , nCount_write(0) + { + } + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void move_001() + { + // rename $TEMP/tmpdir/tmpname to $TEMP/canonical.name. + nError1 = File::move(aTmpName4, aCanURL1); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // check + File testFile(aCanURL1); + nError2 = testFile.open(osl_File_OpenFlag_Create); + deleteTestFile(aCanURL1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: rename file to another directory", + osl::FileBase::E_EXIST, nError2); + } + + void move_002() + { + // move $TEMP/tmpdir/tmpname to $TEMP/tmpdir. + nError1 = File::move(aTmpName4, aTmpName3); + // returned osl::FileBase::E_ACCES on WNT + CPPUNIT_ASSERT_MESSAGE("test for move function: use directory as destination", + (osl::FileBase::E_ACCES == nError1 || osl::FileBase::E_ISDIR == nError1) ||(osl::FileBase::E_EXIST == nError1)); + } + + void move_003() + { + // move $TEMP/tmpdir/tmpname to $ROOT/tmpname. + nError1 = File::move(aTmpName4, aTmpName7); +#if defined(_WIN32) + nError1 = osl::FileBase::E_ACCES; /// for Windows, c:\ is writable any way. + deleteTestFile(aTmpName7); +#endif + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move to an illegal place", + osl::FileBase::E_ACCES, nError1); + } + + void move_004() + { + // move $TEMP/tmpname to $TEMP/tmpdir/tmpname. + nError1 = File::move(aTmpName6, aTmpName4); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move a not exist file", + osl::FileBase::E_NOENT, nError1); + } + + void move_005() + { + // move $TEMP/tmpname to $TEMP/system.path using system path. + nError1 = File::move(aTmpName6, aSysPath1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move a file using system file", + osl::FileBase::E_INVAL, nError1); + } + + void move_006() + { + // move directory $TEMP/tmpname to $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName6); + nError1 = File::move(aTmpName6, aTmpName4); + // move file $TEMP/tmpdir/tmpname to $TEMP/tmpname + nError2 = File::move(aTmpName4, aTmpName6); + deleteTestDirectory(aTmpName6); +#if defined(_WIN32) + deleteTestDirectory(aTmpName4);// in Windows, it can be moved!!!!! this is only for not influence the following test. + deleteTestFile(aTmpName6); + nError1 = osl::FileBase::E_NOTDIR; + nError2 = osl::FileBase::E_ISDIR; +#endif + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move a directory to an exist file with same name, did not pass in (W32)", + osl::FileBase::E_NOTDIR, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move a directory to an exist file with same name, did not pass in (W32)", + osl::FileBase::E_ISDIR, nError2); + } + + void move_007() + { + // create directory $TEMP/tmpname. + createTestDirectory(aTmpName6); + // move directory $TEMP/tmpdir to $TEMP/tmpname/tmpdir + nError1 = File::move(aTmpName3, aTmpName8); + // check + nError2 = Directory::create(aTmpName8); + File::move(aTmpName8, aTmpName3); + deleteTestDirectory(aTmpName6); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move a directory to an exist file with same name", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for move function: move a directory to an exist file with same name", + osl::FileBase::E_EXIST, nError2); + } + + // bugid# 115420, after the bug fix, add the case + CPPUNIT_TEST_SUITE(move); + CPPUNIT_TEST(move_001); + CPPUNIT_TEST(move_002); + CPPUNIT_TEST(move_003); + CPPUNIT_TEST(move_004); + CPPUNIT_TEST(move_005); + CPPUNIT_TEST(move_006); + CPPUNIT_TEST(move_007); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC remove(const OUString& ustrFileURL) + + class remove : public CppUnit::TestFixture + { + osl::FileBase::RC nError1, nError2; + sal_uInt64 nCount_write; + + public: + remove() + : nError1(osl::FileBase::E_None) + , nError2(osl::FileBase::E_None) + , nCount_write(0) + { + } + + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + + // write chars into the file. + File testFile(aTmpName4); + + nError1 = testFile.open(osl_File_OpenFlag_Write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.write(pBuffer_Char, sizeof(pBuffer_Char), nCount_write); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = testFile.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void remove_001() + { + // remove $TEMP/tmpdir/tmpname. + nError1 = File::remove(aTmpName4); + // check + File testFile(aTmpName4); + nError2 = testFile.open(osl_File_OpenFlag_Create); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: remove a file", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for remove function: remove a file", + (osl::FileBase::E_EXIST != nError2)); + } + + void remove_002() + { + // remove $TEMP/tmpname. + nError1 = File::remove(aTmpName6); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: remove a file not exist", + osl::FileBase::E_NOENT, nError1); + } + + void remove_003() + { + // remove $TEMP/system/path. + nError1 = File::remove(aSysPath2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: removing a file not using full qualified URL", + osl::FileBase::E_INVAL, nError1); + } + + void remove_004() + { + // remove $TEMP/tmpdir. + nError1 = File::remove(aTmpName3); + + CPPUNIT_ASSERT_MESSAGE("test for remove function: remove a directory", + (osl::FileBase::E_ISDIR == nError1) || (osl::FileBase::E_ACCES == nError1)); + } + + CPPUNIT_TEST_SUITE(remove); + CPPUNIT_TEST(remove_001); + CPPUNIT_TEST(remove_002); + CPPUNIT_TEST(remove_003); + CPPUNIT_TEST(remove_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC setAttributes(const OUString& ustrFileURL, sal_uInt64 uAttributes) + + class setAttributes : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + DirectoryItem rItem, rItem_hidden; + + public: + setAttributes() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName6); + } + + + void setAttributes_001() + { + // on windows, only can set 2 attributes: osl_File_Attribute_ReadOnly, osl_File_Attribute_Hidden +#ifdef UNX + // set the file to readonly + nError2 = File::setAttributes(aTmpName6, osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // get the file attributes + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for setAttributes function: set file attributes and get it to verify.", + static_cast<sal_uInt64>(osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead), + rFileStatus.getAttributes()); +#else + // please see GetFileAttributes + nError2 = File::setAttributes(aTmpName6, osl_File_Attribute_ReadOnly); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // get the file attributes + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // here the file has 2 Attributes: FILE_ATTRIBUTE_READONLY and FILE_ATTRIBUTE_NORMAL, + // but FILE_ATTRIBUTE_NORMAL is valid only if used alone, so this is maybe a bug + /*OString aString = OUStringToOString(aTmpName6, RTL_TEXTENCODING_ASCII_US); + DWORD dwFileAttributes = GetFileAttributes(aString.getStr()); + if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL) + printf("has normal attribute"); + if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) + printf("has readonly attribute"); + */ + CPPUNIT_ASSERT_MESSAGE("test for setAttributes function: set file attributes READONLY and get it to verify.", + (osl_File_Attribute_ReadOnly & rFileStatus.getAttributes()) != 0); +#endif + } + void setAttributes_002() + { + // on UNX, can not set hidden attribute to file, rename file can set the attribute +#ifdef _WIN32 + // set the file to hidden + nError2 = File::setAttributes(aTmpName6, osl_File_Attribute_Hidden); + + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // get the file attributes + FileStatus rFileStatus(osl_FileStatus_Mask_Attributes); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for setAttributes function: set file attributes and get it to verify.", + (osl_File_Attribute_Hidden & rFileStatus.getAttributes()) != 0); +#endif + } + + CPPUNIT_TEST_SUITE(setAttributes); + CPPUNIT_TEST(setAttributes_001); + CPPUNIT_TEST(setAttributes_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC setTime( + // const OUString& ustrFileURL, + // const TimeValue& rCreationTime, + // const TimeValue& rLastAccessTime, + // const TimeValue& rLastWriteTime) + + class setTime : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + DirectoryItem rItem; + + public: + setTime() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName6); + } + + + void setTime_001() + { + TimeValue *pTV_current = nullptr; + CPPUNIT_ASSERT((pTV_current = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + TimeValue *pTV_creation = nullptr; + CPPUNIT_ASSERT((pTV_creation = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + TimeValue *pTV_access = nullptr; + CPPUNIT_ASSERT((pTV_access = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + TimeValue *pTV_modify = nullptr; + CPPUNIT_ASSERT((pTV_modify = static_cast<TimeValue*>(malloc(sizeof(TimeValue)))) != nullptr); + + // get current time + bool bOk = osl_getSystemTime(pTV_current); + CPPUNIT_ASSERT(bOk); + + // set the file time + nError2 = File::setTime(aTmpName6, *pTV_current, *pTV_current, *pTV_current); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError2).getStr(), osl::FileBase::E_None, nError2); + + // get the file access time, creation time, modify time + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1); + + FileStatus rFileStatus(osl_FileStatus_Mask_AccessTime); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1); + *pTV_access = rFileStatus.getAccessTime(); + + FileStatus rFileStatus1(osl_FileStatus_Mask_CreationTime); + nError1 = rItem.getFileStatus(rFileStatus1); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1); + *pTV_creation = rFileStatus1.getCreationTime(); + + FileStatus rFileStatus2(osl_FileStatus_Mask_ModifyTime); + nError1 = rItem.getFileStatus(rFileStatus2); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1); + *pTV_modify = rFileStatus2.getModifyTime(); + + CPPUNIT_ASSERT_MESSAGE("test for setTime function: set access time then get it. time precision is still a problem for it cut off the nanosec.", + t_compareTime(pTV_access, pTV_current, delta)); +#if defined(_WIN32) + // Unfortunately there is no way to get the creation time of a file under Unix (it's a Windows only feature). + // That means the flag osl_FileStatus_Mask_CreationTime should be deprecated under Unix. + CPPUNIT_ASSERT_MESSAGE("test for setTime function: set creation time then get it. ", + t_compareTime(pTV_creation, pTV_current, delta)); +#endif + CPPUNIT_ASSERT_MESSAGE("test for setTime function: set modify time then get it. ", + t_compareTime(pTV_modify, pTV_current, delta)); + free(pTV_current); + free(pTV_creation); + free(pTV_access); + free(pTV_modify); + } + + CPPUNIT_TEST_SUITE(setTime); + CPPUNIT_TEST(setTime_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC sync() + + class sync : public CppUnit::TestFixture + { + private: + DirectoryItem rItem; + + public: + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestFile(aTmpName6); + + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName6); + } + + // test case: if The file is located on a read only file system. + void sync_001() + { +#ifdef UNX + auto nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + File tmp_file(aTmpName6); + osl::FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("File open failed", osl::FileBase::E_None, err); + + char buffer[50000]; + sal_uInt64 written = 0; + nError1 = tmp_file.write(static_cast<void*>(buffer), sizeof(buffer), written); + CPPUNIT_ASSERT_EQUAL_MESSAGE("write failed!", osl::FileBase::E_None, nError1); + + // set the file to readonly + auto nError2 = File::setAttributes(aTmpName6, osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + + nError2 = tmp_file.sync(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("can not sync to readonly file!", osl::FileBase::E_None, nError2); + + tmp_file.close(); +#endif + } + // test case:no enough space, how to create such case???see test_cpy_wrt_file.cxx::test_osl_writeFile + + CPPUNIT_TEST_SUITE(sync); + CPPUNIT_TEST(sync_001); + CPPUNIT_TEST_SUITE_END(); + }; + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::ctors, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::open, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::close, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::setPos, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::getPos, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::isEndOfFile, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::setSize, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::read, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::write, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::readLine, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::copy, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::move, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::remove, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::setAttributes, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::setTime, "osl_File"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_File::sync, "osl_File"); +// FIXME: to enable these tests (when they work cross-platform) we need to add the below: +// CPPUNIT_REGISTRY_ADD_TO_DEFAULT("osl_File"); + +} + +// Beginning of the test cases for DirectoryItem class + +namespace osl_DirectoryItem +{ + // testing the method + // DirectoryItem(): _pData(NULL) + + class ctors : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + + public: + ctors() : nError1(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile(aTmpName6); + } + + void ctors_001() + { + File testFile(aTmpName6); + DirectoryItem rItem; // constructor + + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: initialize a new instance of DirectoryItem and get an item to check.", + osl::FileBase::E_None, nError1); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctors_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // DirectoryItem(const DirectoryItem& rItem): _pData(rItem._pData) + + class copy_assin_Ctors : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + + public: + copy_assin_Ctors() : nError1(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile(aTmpName6); + } + + + void copy_assin_Ctors_001() + { + DirectoryItem rItem; // constructor + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + DirectoryItem copyItem(rItem); // copy constructor + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError1 = copyItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for copy_assin_Ctors function: use copy constructor to get an item and check filename.", + compareFileName(rFileStatus.getFileName(), aTmpName2)); + } + + void copy_assin_Ctors_002() + { + DirectoryItem rItem; // constructor + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + DirectoryItem copyItem; + copyItem = rItem; // assignment operator + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError1 = copyItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for copy_assin_Ctors function: test assignment operator here since it is same as copy constructor in test way.", + compareFileName(rFileStatus.getFileName(), aTmpName2)); + } + + CPPUNIT_TEST_SUITE(copy_assin_Ctors); + CPPUNIT_TEST(copy_assin_Ctors_001); + CPPUNIT_TEST(copy_assin_Ctors_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline sal_Bool is() + + class is : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + + public: + is() : nError1(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile(aTmpName6); + } + + void is_001() + { + DirectoryItem rItem; // constructor + + CPPUNIT_ASSERT_MESSAGE("test for is function: use an uninitialized instance.", + !rItem.is()); + } + + void is_002() + { + DirectoryItem rItem; // constructor + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName6, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for is function: use an uninitialized instance.", + rItem.is()); + } + + CPPUNIT_TEST_SUITE(is); + CPPUNIT_TEST(is_001); + CPPUNIT_TEST(is_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // static inline RC get(const OUString& ustrFileURL, DirectoryItem& rItem) + + class get : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + get() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpname. + createTestFile(aTmpName6); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile(aTmpName6); + } + + + void get_001() + { + DirectoryItem rItem; + nError2 = DirectoryItem::get(aTmpName6, rItem); + + // check the file name + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for get function: use copy constructor to get an item and check filename.", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_MESSAGE("test for get function: use copy constructor to get an item and check filename.", + compareFileName(rFileStatus.getFileName(), aTmpName2)); + } + + void get_002() + { + DirectoryItem rItem; + nError1 = DirectoryItem::get(aSysPath1, rItem); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for get function: use a system name instead of a URL.", + osl::FileBase::E_INVAL, nError1); + } + + void get_003() + { + DirectoryItem rItem; + + nError1 = DirectoryItem::get(aTmpName3, rItem); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for get function: use a non existed file URL.", + osl::FileBase::E_NOENT, nError1); + } + + CPPUNIT_TEST_SUITE(get); + CPPUNIT_TEST(get_001); + CPPUNIT_TEST(get_002); + CPPUNIT_TEST(get_003); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC getFileStatus(FileStatus& rStatus) + + class getFileStatus : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + getFileStatus() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void getFileStatus_001() + { + DirectoryItem rItem; + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName4, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // check the file name + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError2 = rItem.getFileStatus(rFileStatus); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getFileStatus function: get file status and check filename", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_MESSAGE("test for getFileStatus function: get file status and check filename", + compareFileName(rFileStatus.getFileName(), aTmpName2)); + } + + void getFileStatus_002() + { + DirectoryItem rItem; // constructor + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName6, rItem); + + // check the file name + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError2 = rItem.getFileStatus(rFileStatus); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getFileStatus function: file not existed", + osl::FileBase::E_INVAL, nError2); + } + + void getFileStatus_003() + { + DirectoryItem rItem; // constructor + // get the DirectoryItem. + nError1 = DirectoryItem::get(aTmpName3, rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // check the file name + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError2 = rItem.getFileStatus(rFileStatus); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getFileStatus function: get directory information", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_MESSAGE("test for getFileStatus function: get directory information", + compareFileName(rFileStatus.getFileName(), aTmpName1)); + } + + CPPUNIT_TEST_SUITE(getFileStatus); + CPPUNIT_TEST(getFileStatus_001); + CPPUNIT_TEST(getFileStatus_002); + CPPUNIT_TEST(getFileStatus_003); + CPPUNIT_TEST_SUITE_END(); + }; + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DirectoryItem::ctors, "osl_DirectoryItem"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DirectoryItem::copy_assin_Ctors, "osl_DirectoryItem"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DirectoryItem::is, "osl_DirectoryItem"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DirectoryItem::get, "osl_DirectoryItem"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DirectoryItem::getFileStatus, "osl_DirectoryItem"); +} + +// Beginning of the test cases for Directory class + +namespace osl_Directory +{ + // testing the method + // Directory(const OUString& strPath): _pData(0), _aPath(strPath) + + class ctors : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + ctors() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + // LLA: t_print("tearDown done.\n"); + } + + + void ctors_001() + { + Directory testDirectory(aTmpName3); // constructor + + // open a directory + nError1 = testDirectory.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // close a directory + nError2 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: create an instance and check open and close", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: create an instance and check open and close", + osl::FileBase::E_None, nError2); + } + + void ctors_002() + { + Directory testDirectory(aTmpName9); // constructor + + // open a directory + nError1 = testDirectory.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // close a directory + nError2 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: relative URL, :-), it is also worked", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for ctors function: relative URL, :-), it is also worked", + osl::FileBase::E_None, nError2); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctors_001); + CPPUNIT_TEST(ctors_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC open() + + class open : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + open() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + void open_001() + { + Directory testDirectory(aTmpName3); + + // open a directory + nError1 = testDirectory.open(); + // check if directory is opened. + bool bOk = testDirectory.isOpen(); + // close a directory + nError2 = testDirectory.close(); + + CPPUNIT_ASSERT_MESSAGE("test for open function: open a directory and check for open", + bOk); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: open a directory and check for open", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: open a directory and check for open", + osl::FileBase::E_None, nError2); + } + + void open_002() + { + Directory testDirectory(aTmpName6); + + nError1 = testDirectory.open(); + if (nError1 == osl::FileBase::E_None) + { + nError2 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + } + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: open a file that is not existed", + osl::FileBase::E_NOENT, nError1); + } + + void open_003() + { + Directory testDirectory(aUserDirectorySys); + + nError1 = testDirectory.open(); + if (nError1 == osl::FileBase::E_None) + { + nError2 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + } + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for open function: using system path", + osl::FileBase::E_INVAL, nError1); + } + + void open_004() + { + Directory testDirectory(aTmpName4); + + nError1 = testDirectory.open(); + if (nError1 == osl::FileBase::E_None) + { + nError2 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + } + + CPPUNIT_ASSERT_MESSAGE("test for open function: open a file instead of a directory", + (osl::FileBase::E_NOTDIR == nError1) || (osl::FileBase::E_ACCES == nError1)); + } + + CPPUNIT_TEST_SUITE(open); + CPPUNIT_TEST(open_001); + CPPUNIT_TEST(open_002); + CPPUNIT_TEST(open_003); + CPPUNIT_TEST(open_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline sal_Bool isOpen() { return _pData != NULL; }; + + class isOpen : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + isOpen() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + } + + void tearDown() override + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + } + + + void isOpen_001() + { + Directory testDirectory(aTmpName3); // constructor + + // open a directory + nError1 = testDirectory.open(); + // check if directory is opened. + bool bOk = testDirectory.isOpen(); + // close a directory + nError2 = testDirectory.close(); + + CPPUNIT_ASSERT_MESSAGE("test for isOpen function: open a directory and check for open", + bOk); + } + + void isOpen_002() + { + Directory testDirectory(aTmpName3); // constructor + + // check if directory is opened. + bool bOk = testDirectory.isOpen(); + + CPPUNIT_ASSERT_MESSAGE("test for isOpen function: do not open a directory and check for open", + !bOk); + } + + CPPUNIT_TEST_SUITE(isOpen); + CPPUNIT_TEST(isOpen_001); + CPPUNIT_TEST(isOpen_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC close() + + class close : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + close() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempdirectory : $TEMP/tmpdir. + createTestDirectory(aTmpName3); + } + + void tearDown() override + { + // remove a tempdirectory : $TEMP/tmpdir. + deleteTestDirectory(aTmpName3); + } + + void close_001() + { + Directory testDirectory(aTmpName3); + + // open a directory + nError1 = testDirectory.open(); + // close a directory + nError2 = testDirectory.close(); + // check if directory is opened. + bool bOk = testDirectory.isOpen(); + + CPPUNIT_ASSERT_MESSAGE("test for isOpen function: close a directory and check for open", + !bOk); + } + + void close_002() + { + Directory testDirectory(aTmpName3); + + // close a directory + nError1 = testDirectory.close(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for isOpen function: close a not opened directory", + osl::FileBase::E_BADF, nError1); + } + + CPPUNIT_TEST_SUITE(close); + CPPUNIT_TEST(close_001); + CPPUNIT_TEST(close_002); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC reset() + + class reset : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + DirectoryItem rItem; + + public: + reset() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempdirectory : $TEMP/tmpdir. + createTestDirectory(aTmpName3); + // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile, + createTestFile(aTmpName3, aTmpName2); + createTestFile(aTmpName3, aTmpName1); + createTestFile(aTmpName3, aHidURL1); + } + + void tearDown() override + { + // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile, + deleteTestFile(aTmpName3, aHidURL1); + deleteTestFile(aTmpName3, aTmpName1); + deleteTestFile(aTmpName3, aTmpName2); + // remove a tempdirectory : $TEMP/tmpdir. + deleteTestDirectory(aTmpName3); + } + + + void reset_001() + { + Directory testDirectory(aTmpName3); // constructor + + // open a directory + nError1 = testDirectory.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // get first Item + nError1 = testDirectory.getNextItem(rItem, 1); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // check the file name of first Item + FileStatus rFileStatusFirst(osl_FileStatus_Mask_FileName); + nError1 = rItem.getFileStatus(rFileStatusFirst); + + // get second Item + // mindy: nError1 = testDirectory.getNextItem(rItem, 0); + // mindy: CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // reset enumeration + nError2 = testDirectory.reset(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError2); + // get reset Item, if reset does not work, getNextItem() should return the second Item (aTmpName1) + nError1 = testDirectory.getNextItem(rItem); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // check the file name again + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + nError1 = rItem.getFileStatus(rFileStatus); + // close a directory + nError1 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + bool bOK1,bOK2,bOK3; + bOK1 = compareFileName(rFileStatus.getFileName(), aTmpName2); + bOK2 = compareFileName(rFileStatus.getFileName(), aHidURL1); + bOK3 = compareFileName(rFileStatus.getFileName(), rFileStatusFirst.getFileName()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for reset function: get two directory item, reset it, then get again, check the filename", + osl::FileBase::E_None, nError2); + CPPUNIT_ASSERT_MESSAGE("test for reset function: get two directory item, reset it, then get again, check the filename", + (bOK1 || bOK2 || bOK3)); + } + + void reset_002() + { + Directory testDirectory(aTmpName6); // constructor + + // close a directory + nError1 = testDirectory.reset(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for reset function: reset a non existed directory", + osl::FileBase::E_NOENT, nError1); + } + + void reset_003() + { + Directory testDirectory(aTmpName4); // constructor + + // close a directory + nError1 = testDirectory.reset(); + + CPPUNIT_ASSERT_MESSAGE("test for reset function: reset a file instead of a directory", + (osl::FileBase::E_NOTDIR == nError1) || (osl::FileBase::E_NOENT == nError1)); + } + + void reset_004() + { + Directory testDirectory(aUserDirectorySys); // constructor + + // close a directory + nError1 = testDirectory.reset(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for reset function: use a system path", + osl::FileBase::E_INVAL, nError1); + } + + CPPUNIT_TEST_SUITE(reset); + CPPUNIT_TEST(reset_001); + CPPUNIT_TEST(reset_002); + CPPUNIT_TEST(reset_003); + CPPUNIT_TEST(reset_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline RC getNextItem(DirectoryItem& rItem, sal_uInt32 nHint = 0) + + class getNextItem : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + DirectoryItem rItem; + + public: + getNextItem() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void setUp() override + { + // create a tempdirectory : $TEMP/tmpdir. + createTestDirectory(aTmpName3); + // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile, + createTestFile(aTmpName3, aTmpName2); + createTestFile(aTmpName3, aTmpName1); + createTestFile(aTmpName3, aHidURL1); + + } + + void tearDown() override + { + // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile, + deleteTestFile(aTmpName3, aHidURL1); + deleteTestFile(aTmpName3, aTmpName1); + deleteTestFile(aTmpName3, aTmpName2); + // remove a tempdirectory : $TEMP/tmpdir. + deleteTestDirectory(aTmpName3); + } + + + void getNextItem_001() + { + Directory testDirectory(aTmpName3); // constructor + + // open a directory + nError1 = testDirectory.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // check the file name + bool bOk1 = false; + bool bOk2 = false; + bool bOk3 = false; + FileStatus rFileStatus(osl_FileStatus_Mask_FileName); + + for (int nCount = 0; nCount < 3; nCount++) + { + // get three Items + nError1 = testDirectory.getNextItem(rItem, 2); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + nError1 = rItem.getFileStatus(rFileStatus); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + // a special order is not guaranteed. So any file may occur on any time. + // But every file name should occur only once. + if (!bOk1 && compareFileName(rFileStatus.getFileName(), aTmpName1)) + { + bOk1 = true; + } + + if (!bOk2 && compareFileName(rFileStatus.getFileName(), aTmpName2)) + { + bOk2 = true; + } + + if (!bOk3 && compareFileName(rFileStatus.getFileName(), aHidURL1)) + { + bOk3 = true; + } + } + + // close a directory + nError1 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_MESSAGE("test for getNextItem function: retrieve three items and check their names.", + bOk1); + CPPUNIT_ASSERT_MESSAGE("test for getNextItem function: retrieve three items and check their names.", + bOk2); + CPPUNIT_ASSERT_MESSAGE("test for getNextItem function: retrieve three items and check their names.", + bOk3); + } + + void getNextItem_002() + { + Directory testDirectory(aTmpName3); // constructor + nError1 = testDirectory.getNextItem(rItem); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getNextItem function: retrieve an item in a directory which is not opened, also test for nHint's default value.", + osl::FileBase::E_INVAL, nError1); + } + + void getNextItem_003() + { + Directory testDirectory(aTmpName3); // constructor + + // open a directory + nError1 = testDirectory.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + for (int nCount = 0; nCount < 4; nCount++) + { + nError2 = testDirectory.getNextItem(rItem, 3); + } + + // close a directory + nError1 = testDirectory.close(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getNextItem function: retrieve 4 times in a directory which contain only 3 files.", + osl::FileBase::E_NOENT, nError2); + } + + void getNextItem_004() + { + // create a link file(can not on Windows), then check if getNextItem can get it. +#ifdef UNX + bool bLnkOK = false; + bool bFoundOK = false; + + OUString aUStr_LnkFileSys(aTempDirectorySys), aUStr_SrcFileSys(aTempDirectorySys); + aUStr_LnkFileSys += aSlashURL + "/tmpdir/link.file"; + aUStr_SrcFileSys += aSlashURL + "/tmpdir/tmpname"; + + OString strLinkFileName, strSrcFileName; + strLinkFileName = OUStringToOString(aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US); + strSrcFileName = OUStringToOString(aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US); + + // create a link file and link it to file "/tmp/PID/tmpdir/tmpname" + sal_Int32 fd = symlink(strSrcFileName.getStr(), strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd); + Directory testDirectory(aTmpName3); + + // open a directory + nError1 = testDirectory.open(); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + OUString aFileName ("link.file"); + + while (true) { + nError1 = testDirectory.getNextItem(rItem, 4); + if (nError1 == osl::FileBase::E_None) { + FileStatus rFileStatus(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Type); + rItem.getFileStatus(rFileStatus); + if (compareFileName(rFileStatus.getFileName(), aFileName)) + { + bFoundOK = true; + if (rFileStatus.getFileType() == FileStatus::Link) + { + bLnkOK = true; + break; + } + } + } + else + break; + } + fd = std::remove(strLinkFileName.getStr()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("remove link file failed", static_cast<sal_Int32>(0), fd); + CPPUNIT_ASSERT_MESSAGE("test for getNextItem function: check if can retrieve the link file name", + bFoundOK); + CPPUNIT_ASSERT_MESSAGE("test for getNextItem function: check if link file has file type link", + bLnkOK); +#endif + } + + CPPUNIT_TEST_SUITE(getNextItem); + CPPUNIT_TEST(getNextItem_001); + CPPUNIT_TEST(getNextItem_002); + CPPUNIT_TEST(getNextItem_003); + CPPUNIT_TEST(getNextItem_004); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC getVolumeInfo(const OUString& ustrDirectoryURL, VolumeInfo& rInfo) + + class getVolumeInfo : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1; + + public: + getVolumeInfo() : nError1(osl::FileBase::E_None) {} + + void checkValidMask(osl::VolumeInfo const& _aVolumeInfo, sal_Int32 _nMask) + { + if (_nMask == osl_VolumeInfo_Mask_FileSystemName) + { + // get file system name + OUString aFileSysName = _aVolumeInfo.getFileSystemName(); + + bool bRes2 = compareFileName(aFileSysName, aNullURL); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getVolumeInfo function: getVolumeInfo of root directory.", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_MESSAGE("test for getVolumeInfo function: getVolumeInfo of root directory.", + !bRes2); + } + + if (_nMask == osl_VolumeInfo_Mask_Attributes) + { + bool b1 = _aVolumeInfo.getRemoteFlag(); + bool b2 = _aVolumeInfo.getRemoveableFlag(); + bool b3 = _aVolumeInfo.getCompactDiscFlag(); + bool b4 = _aVolumeInfo.getFloppyDiskFlag(); + bool b5 = _aVolumeInfo.getFixedDiskFlag(); + bool b6 = _aVolumeInfo.getRAMDiskFlag(); + + OString sAttr; + if (b1) sAttr = "Remote"; + if (b2) sAttr += " Removeable"; + if (b3) sAttr += " CDROM"; + if (b4) sAttr += " Floppy"; + if (b5) sAttr += " FixedDisk"; + if (b6) sAttr += " RAMDisk"; + + printf("Attributes: %s\n", sAttr.getStr()); + } + if (_nMask == osl_VolumeInfo_Mask_TotalSpace) + { + // within Linux, df / * 1024 bytes is the result + sal_uInt64 nSize = _aVolumeInfo.getTotalSpace(); + printf("Total space: %" SAL_PRIuUINT64 "\n", nSize); + } + if (_nMask == osl_VolumeInfo_Mask_UsedSpace) + { + sal_uInt64 nSize = _aVolumeInfo.getUsedSpace(); + printf(" Used space: %" SAL_PRIuUINT64 "\n", nSize); + } + if (_nMask == osl_VolumeInfo_Mask_FreeSpace) + { + sal_uInt64 nSize = _aVolumeInfo.getFreeSpace(); + printf(" Free space: %" SAL_PRIuUINT64 "\n", nSize); + } + if (_nMask == osl_VolumeInfo_Mask_MaxNameLength) + { + sal_uInt32 nLength = _aVolumeInfo.getMaxNameLength(); + printf("max name length: %" SAL_PRIuUINT32 "\n", nLength); + } + if (_nMask == osl_VolumeInfo_Mask_MaxPathLength) + { + sal_uInt32 nLength = _aVolumeInfo.getMaxPathLength(); + printf("max path length: %" SAL_PRIuUINT32 "\n", nLength); + } + if (_nMask == osl_VolumeInfo_Mask_FileSystemCaseHandling) + { + bool bIsCase = _aVolumeInfo.isCaseSensitiveFileSystem(); + printf("filesystem case sensitive: %s\n", bIsCase ? "yes" : "no"); + } + } + + void checkVolumeInfo(sal_Int32 _nMask) + { + VolumeInfo aVolumeInfo(_nMask); + // call getVolumeInfo here + nError1 = Directory::getVolumeInfo(aVolURL1, aVolumeInfo); + // LLA: IMHO it's not a bug, if VolumeInfo is not valid, it's a feature + // LLA: CPPUNIT_ASSERT_MESSAGE("mask is not valid", sal_True == aVolumeInfo.isValid(_nMask)); + if (aVolumeInfo.isValid(_nMask)) + checkValidMask(aVolumeInfo, _nMask); + } + + void getVolumeInfo_001_1() + { + sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_2() + { + sal_Int32 mask = osl_VolumeInfo_Mask_Attributes; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_3() + { + sal_Int32 mask = osl_VolumeInfo_Mask_TotalSpace; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_4() + { + sal_Int32 mask = osl_VolumeInfo_Mask_UsedSpace; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_5() + { + sal_Int32 mask = osl_VolumeInfo_Mask_FreeSpace; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_6() + { + sal_Int32 mask = osl_VolumeInfo_Mask_MaxNameLength; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_7() + { + sal_Int32 mask = osl_VolumeInfo_Mask_MaxPathLength; + checkVolumeInfo(mask); + } + + void getVolumeInfo_001_8() + { + sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemCaseHandling; + checkVolumeInfo(mask); + } + + void getVolumeInfo_002() + { + sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName; + VolumeInfo aVolumeInfo(mask); + // call getVolumeInfo here + + OUString aRootSysURL; + nError1 = osl::File::getFileURLFromSystemPath(aRootSys, aRootSysURL); + CPPUNIT_ASSERT_EQUAL_MESSAGE("can't convert root path to file url", osl::FileBase::E_None, nError1); + + nError1 = Directory::getVolumeInfo(aRootSys, aVolumeInfo); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getVolumeInfo function: use system path as parameter.", + osl::FileBase::E_INVAL, nError1); + } + + void getVolumeInfo_003() + { + sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName; + VolumeInfo aVolumeInfo(mask); + // call getVolumeInfo here + nError1 = Directory::getVolumeInfo(aTmpName3, aVolumeInfo); + +// LLA: in Windows, it reply no error, it did not pass in (W32). +#if defined(UNX) && !defined(IOS) + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getVolumeInfo function: non-existence test. ", + osl::FileBase::E_NOENT, nError1); +#endif + } + + CPPUNIT_TEST_SUITE(getVolumeInfo); + CPPUNIT_TEST(getVolumeInfo_001_1); + CPPUNIT_TEST(getVolumeInfo_001_2); + CPPUNIT_TEST(getVolumeInfo_001_3); + CPPUNIT_TEST(getVolumeInfo_001_4); + CPPUNIT_TEST(getVolumeInfo_001_5); + CPPUNIT_TEST(getVolumeInfo_001_6); + CPPUNIT_TEST(getVolumeInfo_001_7); + CPPUNIT_TEST(getVolumeInfo_001_8); + CPPUNIT_TEST(getVolumeInfo_002); + CPPUNIT_TEST(getVolumeInfo_003); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC create(const OUString& ustrDirectoryURL) + + class create : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + create() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + void create_001() + { + // create directory in $TEMP/tmpdir + nError1 = Directory::create(aTmpName3); + // check for existence + nError2 = Directory::create(aTmpName3); + // remove it + deleteTestDirectory(aTmpName3); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for create function: create a directory and check its existence.", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for create function: create a directory and check its existence.", + osl::FileBase::E_EXIST, nError2); + } + + void create_002() + { +#if !defined(_WIN32) && !defined(MACOSX) && defined(SAL_UNX) + if (geteuid() == 0) // don't test if building as root + return; + + OUString aTmpDir; + nError1 = osl::FileBase::createTempFile(nullptr, nullptr, &aTmpDir); + CPPUNIT_ASSERT_EQUAL_MESSAGE("temp File creation failed", osl::FileBase::E_None, nError1); + + nError1 = File::remove(aTmpDir); + CPPUNIT_ASSERT_EQUAL_MESSAGE("temp File removal failed", osl::FileBase::E_None, nError1); + + nError1 = Directory::create(aTmpDir); + OString sError = "test for create function: create a directory '" + + OUStringToOString(aTmpDir, RTL_TEXTENCODING_ASCII_US) + + "' and check its existence."; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_None, nError1); + osl_setFileAttributes(aTmpDir.pData, 0); // no access allowed now + + // Shouldn't be possible now to create a dir underneath it + OUString aTmpSubLevel = aTmpDir + "/notallowedhere"; + nError1 = Directory::create(aTmpSubLevel); + + // allow removal + osl_setFileAttributes(aTmpDir.pData, + osl_File_Attribute_OwnRead | + osl_File_Attribute_OwnWrite | + osl_File_Attribute_OwnExe); + deleteTestDirectory(aTmpDir); + sError = "test for create function: create a directory under '" + + OUStringToOString(aTmpDir, RTL_TEXTENCODING_ASCII_US) + + "' for access test."; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_ACCES, nError1); +#endif + } + + void create_003() + { + // create directory in /tmpname + nError1 = Directory::create(aSysPath1); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for create function: create a directory using system path.", + osl::FileBase::E_INVAL, nError1); + } + + CPPUNIT_TEST_SUITE(create); + CPPUNIT_TEST(create_001); + CPPUNIT_TEST(create_002); + CPPUNIT_TEST(create_003); + CPPUNIT_TEST_SUITE_END(); + }; + + // testing the method + // inline static RC remove(const OUString& ustrDirectoryURL) + + class remove : public CppUnit::TestFixture + { + private: + osl::FileBase::RC nError1, nError2; + + public: + remove() : nError1(osl::FileBase::E_None),nError2(osl::FileBase::E_None) {} + + void remove_001() + { + // create directory in $TEMP/tmpdir + nError1 = Directory::create(aTmpName3); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // remove it + nError1 = Directory::remove(aTmpName3); + // check for existence + Directory rDirectory(aTmpName3); + nError2 = rDirectory.open(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: remove a directory and check its existence.", + osl::FileBase::E_None, nError1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: remove a directory and check its existence.", + osl::FileBase::E_NOENT, nError2); + } + + void remove_002() + { + // create directory in $TEMP/tmpdir + nError1 = Directory::create(aTmpName3); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1); + // try to remove it by system path + nError1 = Directory::remove(aSysPath3); + // check for existence + Directory rDirectory(aTmpName3); + nError2 = rDirectory.open(); + + if (nError2 != osl::FileBase::E_NOENT) + Directory::remove(aTmpName3); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: remove a directory by its system path, and check its existence.", + osl::FileBase::E_INVAL, nError1); + } + + void remove_003() + { + // try to remove a non-existed directory + nError1 = Directory::remove(aTmpName6); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("test for remove function: try to remove a non-existed directory.", + osl::FileBase::E_NOENT, nError1); + } + + void remove_004() + { + createTestFile(aTmpName6); + bool bExist = ifFileExist(aTmpName6); + // try to remove file. + nError1 = Directory::remove(aTmpName6); + deleteTestFile(aTmpName6); + + CPPUNIT_ASSERT_MESSAGE("test for remove function: try to remove a file but not directory.", + bExist); + CPPUNIT_ASSERT_MESSAGE("test for remove function: try to remove a file but not directory.", + (osl::FileBase::E_NOTDIR == nError1) || (osl::FileBase::E_NOENT == nError1)); + } + + void remove_005() + { + createTestDirectory(aTmpName3); + createTestFile(aTmpName4); + nError1 = Directory::remove(aTmpName3); + deleteTestFile(aTmpName4); + deleteTestDirectory(aTmpName3); + OString sError = "test for remove function: try to remove a directory that is not empty." + + errorToStr(nError1); +#if defined(__sun) + // on UNX, the implementation uses rmdir(), which EEXIST is thrown on Solaris when the directory is not empty, refer to: 'man -s 2 rmdir', while on linux, ENOTEMPTY is thrown. + // EEXIST The directory contains entries other than those for "." and "..". + printf("#Solaris test\n"); + CPPUNIT_ASSERT_MESSAGE(sError.getStr(), (osl::FileBase::E_EXIST == nError1)); +#else + CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_NOTEMPTY, nError1); +#endif + } + + CPPUNIT_TEST_SUITE(remove); + CPPUNIT_TEST(remove_001); + CPPUNIT_TEST(remove_002); + CPPUNIT_TEST(remove_003); + CPPUNIT_TEST(remove_004); + CPPUNIT_TEST(remove_005); + CPPUNIT_TEST_SUITE_END(); + }; + + // TEST Directory::createPath + + #ifdef _WIN32 + # define PATH_BUFFER_SIZE MAX_PATH + #else + # define PATH_BUFFER_SIZE PATH_MAX + #endif + +#define TEST_PATH_POSTFIX "hello/world" + + static OUString const & get_test_path() + { + static OUString test_path = [&]() + { + OUString tmp; + osl::FileBase::RC rc = osl::FileBase::getTempDirURL(tmp); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "Getting the location of TMP dir failed", + osl::FileBase::E_None, rc + ); + + OUString system_path; + rc = osl::FileBase::getSystemPathFromFileURL(tmp, system_path); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "Cannot convert the TMP dir to system path", + osl::FileBase::E_None, rc + ); + + OString tmp_x(OUStringToOString(system_path, RTL_TEXTENCODING_UTF8)); + if (tmp_x.lastIndexOf('/') != (tmp_x.getLength() - 1)) + tmp_x += OString('/'); + +#if !defined(_WIN32) && !defined(ANDROID) && !defined(AIX) + // FIXME would be nice to create unique dir even on Windows + tmp_x += "XXXXXX"; + char *out = mkdtemp(const_cast<char*>(tmp_x.getStr())); + + CPPUNIT_ASSERT_MESSAGE + ( + "mkdtemp call failed", + out != nullptr + ); + + tmp_x += OString('/'); +#endif + tmp_x += OString(TEST_PATH_POSTFIX); + + OUString tmpTestPath; + rc = osl::FileBase::getFileURLFromSystemPath(OStringToOUString(tmp_x, RTL_TEXTENCODING_UTF8), tmpTestPath); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "Cannot convert the system path back to a URL", + osl::FileBase::E_None, rc + ); + return tmpTestPath; + }(); + return test_path; + } + + static void rm_test_path(const OUString& path) + { + sal_Unicode buffer[PATH_BUFFER_SIZE]; + memcpy(buffer, path.getStr(), (path.getLength() + 1) * sizeof(sal_Unicode)); + + sal_Int32 i = rtl_ustr_lastIndexOfChar(buffer, '/'); + if (i == path.getLength()) + buffer[i] = 0; + + Directory::remove(buffer); + + i = rtl_ustr_lastIndexOfChar(buffer, '/'); + assert(i != -1); + if (i != -1) + { + buffer[i] = 0; + Directory::remove(buffer); + } + } + + namespace { + + class DirCreatedObserver : public DirectoryCreationObserver + { + public: + DirCreatedObserver() : i(0) {} + virtual void DirectoryCreated(const OUString&) override { i++; }; + + int number_of_dirs_created() const { return i; } + + private: + int i; + }; + + } + + class createPath : public CppUnit::TestFixture + { + public: + createPath() + {} + + void with_relative_path() + { + osl::FileBase::RC rc = Directory::createPath(TEST_PATH_POSTFIX); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createDirectoryPath contract broken", + osl::FileBase::E_INVAL, rc + ); + } + + void without_callback() + { + OUString tp_url = get_test_path(); + + rm_test_path(tp_url); + + osl::FileBase::RC rc = Directory::createPath(tp_url); + + rm_test_path(tp_url); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createDirectoryPath failed", + osl::FileBase::E_None, rc + ); + } + + void with_callback() + { + OUString tp_url = get_test_path(); + + rm_test_path(tp_url); + + DirCreatedObserver* observer = new DirCreatedObserver; + osl::FileBase::RC rc = Directory::createPath(tp_url, observer); + int nDirs = observer->number_of_dirs_created(); + delete observer; + + rm_test_path(tp_url); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createDirectoryPath failed", + osl::FileBase::E_None, rc + ); + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath failed", + nDirs > 0 + ); + + } + +#ifdef _WIN32 + + const char* get_unused_drive_letter() + { + static const char m_aBuff[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + DWORD ld = GetLogicalDrives(); + DWORD i = 4; + DWORD j = 2; + + while ((ld & i) && (i > 1)) + { i = i << 1; j++; } + + if (i > 2) + return m_aBuff + j; + + return nullptr; + } + + void at_invalid_logical_drive() + { + const char* drv = get_unused_drive_letter(); + char buff[PATH_BUFFER_SIZE]; + memset(buff, 0, sizeof(buff)); + + strncpy(buff, drv, 1); + strcat(buff, ":\\"); + strcat(buff, TEST_PATH_POSTFIX); + + OUString path = OUString::createFromAscii(buff); + OUString tp_url; + osl::FileBase::getFileURLFromSystemPath(path, tp_url); + + osl::FileBase::RC rc = Directory::createPath(tp_url); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath doesn't fail on unused logical drive letters", + rc != osl::FileBase::E_None + ); + } +#endif /* _WIN32 */ + + CPPUNIT_TEST_SUITE(createPath); + CPPUNIT_TEST(with_relative_path); + CPPUNIT_TEST(without_callback); + CPPUNIT_TEST(with_callback); +#ifdef _WIN32 + CPPUNIT_TEST(at_invalid_logical_drive); +#endif + CPPUNIT_TEST_SUITE_END(); + + }; + + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::ctors); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::open); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::isOpen); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::close); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::reset); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::getNextItem); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::getVolumeInfo); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::create); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::remove); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Directory::createPath); +} + +#if defined UNX +/** get Current PID. +*/ +OUString getCurrentPID() +{ + //~ Get current PID and turn it into OUString; + int nPID = 0; +#ifdef _WIN32 + nPID = GetCurrentProcessId(); +#else + nPID = getpid(); +#endif + return OUString::number(nPID); +} +#endif + +namespace { + +//~ do some clean up work after all test completed. +class GlobalObject +{ +public: + ~GlobalObject() + { + try + { + //~ special clean up task in Windows and Unix separately; +#if (defined UNX) + //~ some clean up task for UNIX OS + ; +#else + //~ some clean up task for Windows OS + //~ check if some files are in the way, remove them if necessary. + if (ifFileExist(aTmpName6)) + deleteTestFile(aTmpName6); + if (ifFileExist(aTmpName4)) + deleteTestFile(aTmpName4); + if (checkDirectory(aTmpName4, oslCheckMode::Exist)) + deleteTestDirectory(aTmpName4); + if (ifFileExist(aTmpName3)) + deleteTestFile(aTmpName3); + if (checkDirectory(aTmpName3, oslCheckMode::Exist)) + deleteTestDirectory(aTmpName3); + + OUString aUStr(aUserDirectoryURL); + concatURL(aUStr, aHidURL1); + if (ifFileExist(aUStr)) + deleteTestFile(aUStr); + + OUString aUStr1(aRootURL); + concatURL(aUStr1, aTmpName2); + if (ifFileExist(aUStr1)) + deleteTestFile(aUStr1); +#endif + } + catch (const CppUnit::Exception &e) + { + printf("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber()); + } + catch (...) + { + printf("Exception caught (...) in GlobalObject dtor()\n"); + } + } +}; + +} + +static GlobalObject theGlobalObject; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/file/osl_File_Const.h b/sal/qa/osl/file/osl_File_Const.h new file mode 100644 index 000000000..6cf324f29 --- /dev/null +++ b/sal/qa/osl/file/osl_File_Const.h @@ -0,0 +1,203 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSL_FILE_OSL_FILE_CONST_H +#define INCLUDED_SAL_QA_OSL_FILE_OSL_FILE_CONST_H + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sal/types.h> + +#include <rtl/ustring.hxx> + +#include <cppunit/extensions/HelperMacros.h> + +static OUString getTempDirectoryURL_() +{ + OUString aDir; + CPPUNIT_ASSERT_EQUAL_MESSAGE("couldn't get system temp URL", + osl::FileBase::E_None, osl::FileBase::getTempDirURL(aDir)); + return aDir; +} + +static OUString getTempDirectorySys_() +{ + OUString aDir; + CPPUNIT_ASSERT_EQUAL_MESSAGE("couldn't get system temp directory", + osl::FileBase::E_None, osl::FileBase::getSystemPathFromFileURL(getTempDirectoryURL_(), aDir)); + return aDir; +} + +#ifdef __cplusplus +extern "C" +{ +#endif + +// common used string resource +// these common used string will be used as assist resource in test +// they are mostly OS independent, some of the resource can be reused +// so, a common test data repository will be better since it can be +// shared among all test code + +const char pBuffer_Char[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const char pBuffer_Number[] = "1234567890"; +const char pBuffer_Blank[] = ""; + +// OS dependent/independent definitions/includes +// we use FILE_PREFIX for URL prefix, +// TEST_PLATFORM for test platform initial, +// TEST_PLATFORM_ROOT for root dir in comrresponding platform, +// TEST_PLATFORM_TEMP for temp dir in comrresponding platform, +// PATH_LIST_DELIMITER for separator of path list in comrresponding platform, +// PATH_SEPARATOR for separator in URL or system path in comrresponding platform, +// PATH_MAX/MAX_PATH for max path length in comrresponding platform, + +// OS independent const definition + +# define FILE_PREFIX "file:///" +# define TEST_FILE_SIZE 1024 + +// OS dependent declaration and includes + +#if ( defined UNX ) //Unix +# include <unistd.h> +# include <limits.h> +# include <math.h> +# include <errno.h> +# include <fcntl.h> +# include <sys/stat.h> +# if !defined(MACOSX) && !defined(IOS) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined (DRAGONFLY) && !defined(HAIKU) +# include <sys/statfs.h> +# else +# include <sys/param.h> +# ifndef HAIKU +# include <sys/mount.h> +# endif +# endif +# if !defined(ANDROID) +# include <sys/statvfs.h> +# endif +# include <sys/types.h> +# define TEST_PLATFORM_ROOT "/" +# define PATH_LIST_DELIMITER ":" +# define PATH_SEPARATOR "/" +#endif + +#if defined(_WIN32) // Windows +# include <io.h> +# define PATH_MAX MAX_PATH +# define TEST_PLATFORM_ROOT "c:/" +# define PATH_LIST_DELIMITER ";" +# define PATH_SEPARATOR "/" +#endif + +// OS independent file definition + +OUString aNullURL( "" ); +OUString aSlashURL( PATH_SEPARATOR ); +OUString aPreURL( FILE_PREFIX ); +OUString aRootURL( FILE_PREFIX TEST_PLATFORM_ROOT ); + +OUString aTempDirectorySys(getTempDirectorySys_()); +OUString aTempDirectoryURL(getTempDirectoryURL_()); +OUString aUserDirectorySys( aTempDirectorySys + "" ); +OUString aUserDirectoryURL( aTempDirectoryURL + "" ); + +// common used URL:temp, canonical, root, relative, link,etc + +OUString aCanURL1( aTempDirectoryURL + "/canonical.name" ); +OUString aCanURL2( + RTL_CONSTASCII_USTRINGPARAM("ca@#;+.,$///78no\0ni..name")); +OUString aCanURL3( "ca@#;+.,$//tmp/678nonical//name" ); +OUString aCanURL4( "canonical.name" ); +OUString aTmpName1( "tmpdir" ); +OUString aTmpName2( "tmpname" ); +OUString aTmpName3( aTempDirectoryURL + "/tmpdir" ); +OUString aTmpName4( aTempDirectoryURL + "/tmpdir/tmpname" ); +OUString aTmpName5( aTempDirectoryURL + "/tmpdir/../tmpdir/./tmpname" ); +OUString aTmpName6( aTempDirectoryURL + "/tmpname" ); +OUString aTmpName7( aTempDirectoryURL + "/noaccess" ); +OUString aTmpName8( aTempDirectoryURL + "/tmpname/tmpdir" ); +OUString aTmpName9( aTempDirectoryURL + "/tmpdir/../tmpdir/./" ); +OUString aTmpName10(aTempDirectoryURL + "/\xE6\x9C\xAA\xE5\x91\xBD\xE5\x90\x8Dzhgb18030"); + +OUString aRelURL1( "relative/file1" ); +OUString aRelURL2( "relative/./file2" ); +OUString aRelURL3( "relative/../file3" ); +OUString aRelURL4( "././relative/../file4" ); +OUString aRelURL5( aTempDirectoryURL + "/./../" ); +OUString aLnkURL1( aTempDirectoryURL + "/link.file" ); +OUString aHidURL1( ".hiddenfile" ); + +// common used System Path:temp, root,etc + +OUString aRootSys( TEST_PLATFORM_ROOT ); +OUString aSysPath1( aTempDirectorySys + "/system.path" ); +OUString aSysPath2( aTempDirectorySys + "/system/path" ); +OUString aSysPath3( aTempDirectorySys + "/tmpdir" ); +OUString aSysPath4( aTempDirectorySys + "/tmpname" ); +OUString aSysPath5( aTempDirectorySys + "/\xE6\x9C\xAA\xE5\x91\xBD\xE5\x90\x8Dzhgb18030" ); +OUString aSysPathLnk( aTempDirectorySys + "/link.file" ); +OUString aFifoSys( aTempDirectorySys + "/tmpdir/fifo" ); + +// FileType URL, we pick some canonical file in corresponding system for test: +// socket, link, etc. +// Note that this may be changed in the different platform, so be careful to use. + +#if ( defined UNX ) // Unix +OUString aTypeURL1( FILE_PREFIX "dev/ccv"); //socket Solaris/Linux +OUString aTypeURL2( FILE_PREFIX "devices/pseudo/tcp@0:tcp"); //special Solaris/Linux +OUString aTypeURL3( FILE_PREFIX "lib" ); //link Solaris +#else // Windows +OUString aTypeURL1( FILE_PREFIX "" ); +OUString aTypeURL2( FILE_PREFIX "" ); +OUString aTypeURL3( FILE_PREFIX "" ); +#endif + +// Volume device URL, we pick some canonical volume device for test: +// UNIX file system, Floppy Disk, Proc file system, Temp file system, Compact Disk. + +#if ( defined UNX ) // Unix +OUString aVolURL1( FILE_PREFIX ""); //ufs Solaris/Linux +#ifdef __sun +OUString aVolURL2( FILE_PREFIX "dev/fd" ); //fd Solaris +#else +OUString aVolURL2( FILE_PREFIX "dev/floppy/0u1440" ); //fd0 Linux +#endif +OUString aVolURL3( FILE_PREFIX "proc" ); //proc Solaris/Linux +OUString aVolURL4( FILE_PREFIX "staroffice" ); //nfs Solaris/Linux +OUString aVolURL5( FILE_PREFIX "tmp" ); //tmpfs Solaris +OUString aVolURL6( FILE_PREFIX "cdrom" ); //cd Solaris +#else // Windows +OUString aVolURL1( FILE_PREFIX "c:/" ); +OUString aVolURL2( FILE_PREFIX "a:/" ); +OUString aVolURL3( FILE_PREFIX "" ); +OUString aVolURL4( FILE_PREFIX "" ); +OUString aVolURL5( FILE_PREFIX "c:/temp" ); +OUString aVolURL6( FILE_PREFIX "e:/" ); +#endif + +#ifdef __cplusplus +} +#endif + +#endif // INCLUDED_SAL_QA_OSL_FILE_OSL_FILE_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/file/osl_old_test_file.cxx b/sal/qa/osl/file/osl_old_test_file.cxx new file mode 100644 index 000000000..ee89b836d --- /dev/null +++ b/sal/qa/osl/file/osl_old_test_file.cxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <osl/file.h> +#include <osl/process.h> +#include <rtl/ustring.hxx> +#ifdef SAL_UNX +#include <unistd.h> +#include <limits.h> +#include <string.h> +#include <sys/stat.h> +#define TEST_VOLUME "" +#endif + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +namespace osl_test_file +{ + +class oldtestfile : public CppUnit::TestFixture +{ +public: + void test_file_001(); + void test_file_002(); + void test_file_004(); + + CPPUNIT_TEST_SUITE( oldtestfile ); + CPPUNIT_TEST( test_file_001 ); + CPPUNIT_TEST( test_file_002 ); + CPPUNIT_TEST( test_file_004 ); + CPPUNIT_TEST_SUITE_END( ); +}; + +#ifndef _WIN32 +const char * const aSource1[] = +{ + "a" , "file:///" TEST_VOLUME "bla/a", + ///TODO: check if last slash must be omitted in resolved path. +// "a/" , "file:///" TEST_VOLUME "bla/a", + "../a" , "file:///" TEST_VOLUME "a" , + "a/.." , "file:///" TEST_VOLUME "bla/", + "a/../b" , "file:///" TEST_VOLUME "bla/b", + ".." , "file:///" TEST_VOLUME "", + "a/b/c/d" , "file:///" TEST_VOLUME "bla/a/b/c/d", + "a/./c" , "file:///" TEST_VOLUME "bla/a/c", + "file:///bla/blub", "file:///" "bla/blub", + nullptr , nullptr +}; + +const char * const aSource2[ ] = +{ + "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a", + ///TODO: check if last slash must be omitted in resolved path. +// "a/", "file:///" TEST_VOLUME "bla/blubs/schnubbel/a", + "../a", "file:///" TEST_VOLUME "bla/blubs/a", + "../../a", "file:///" TEST_VOLUME "bla/a", + "../../../a", "file:///" TEST_VOLUME "a", + "../../../a/b/c/d", "file:///" TEST_VOLUME "a/b/c/d", + nullptr,nullptr +}; +#endif + +void oldtestfile::test_file_001() +{ +#ifndef _WIN32 + OUString base1( "file:///" TEST_VOLUME "bla" ); + int i; + for( i = 0 ; aSource1[i] ; i +=2 ) + { + OUString target; + OUString rel = OUString::createFromAscii( aSource1[i] ); + oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #1", osl_File_E_None, e ); + if( e == osl_File_E_None ) + { + CPPUNIT_ASSERT_MESSAGE("failure #1.1", target.equalsAscii( aSource1[i+1] ) ); + } + } +#endif +} + +void oldtestfile::test_file_002() +{ +#ifndef _WIN32 + OUString base2( "file:///" TEST_VOLUME "bla/blubs/schnubbel" ); + int i; + for( i = 0 ; aSource2[i] ; i +=2 ) + { + OUString target; + OUString rel = OUString::createFromAscii( aSource2[i] ); + oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #2", osl_File_E_None, e ); + if( e == osl_File_E_None ) + { + CPPUNIT_ASSERT_MESSAGE("failure #2.1", target.equalsAscii( aSource2[i+1] ) ); + } + } +#endif +} + +void oldtestfile::test_file_004() +{ +#ifndef _WIN32 + OUString base4( "file:///" TEST_VOLUME "bla/" ); + int i; + for( i = 0 ; aSource1[i] ; i +=2 ) + { + OUString target; + OUString rel = OUString::createFromAscii( aSource1[i] ); + oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #10", osl_File_E_None, e ); + if( e == osl_File_E_None ) + { + CPPUNIT_ASSERT_MESSAGE("failure #10.1", target.equalsAscii( aSource1[i+1] ) ); + } + } +#endif +} + +} // namespace osl_test_file + +CPPUNIT_TEST_SUITE_REGISTRATION( osl_test_file::oldtestfile); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/file/test_cpy_wrt_file.cxx b/sal/qa/osl/file/test_cpy_wrt_file.cxx new file mode 100644 index 000000000..6843d10b3 --- /dev/null +++ b/sal/qa/osl/file/test_cpy_wrt_file.cxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <rtl/ustring.hxx> + +using namespace osl; + +class test_osl_writeFile : public CppUnit::TestFixture +{ +public: + void wrt_file() + { + FileBase::RC err; + + //create a tempfile + OUString aTmpFile; + err = FileBase::createTempFile(nullptr, nullptr, &aTmpFile); + CPPUNIT_ASSERT_EQUAL_MESSAGE("temp File creation failed", osl::FileBase::E_None, err); + + //now attempt to open with Create flag an existing file, should get E_EXIST + File tmp_file(aTmpFile); + err = tmp_file.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create); + + OString sErrorMsg = "Expected that '" + + OUStringToOString(aTmpFile, RTL_TEXTENCODING_ASCII_US) + + "' would exist!"; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sErrorMsg.getStr(), FileBase::E_EXIST, err); + + char buffer[1]; + sal_uInt64 written = 0; + err = tmp_file.write(static_cast<void*>(buffer), sizeof(buffer), written); + CPPUNIT_ASSERT_MESSAGE("write on unconnected file should fail", + err != osl::FileBase::E_None); + CPPUNIT_ASSERT_EQUAL_MESSAGE("write on unconnected file should fail", + sal_uInt64(0), written); + + err = tmp_file.sync(); + CPPUNIT_ASSERT_MESSAGE("sync on unconnected file should fail", err != FileBase::E_None); + err = tmp_file.close(); + CPPUNIT_ASSERT_MESSAGE("close on unconnected file should fail", err != FileBase::E_None); + + err = ::osl::File::remove(aTmpFile); + CPPUNIT_ASSERT_EQUAL_MESSAGE("temp file should have existed", FileBase::E_None, err); + } + + CPPUNIT_TEST_SUITE(test_osl_writeFile); + CPPUNIT_TEST(wrt_file); + CPPUNIT_TEST_SUITE_END(); +}; + +// register test suites +CPPUNIT_TEST_SUITE_REGISTRATION(test_osl_writeFile); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/getsystempathfromfileurl/test-getsystempathfromfileurl.cxx b/sal/qa/osl/getsystempathfromfileurl/test-getsystempathfromfileurl.cxx new file mode 100644 index 000000000..4fd5d6b16 --- /dev/null +++ b/sal/qa/osl/getsystempathfromfileurl/test-getsystempathfromfileurl.cxx @@ -0,0 +1,243 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <osl/file.hxx> + +#if defined(_WIN32) +#define MY_PATH_IN "/c:/foo/bar" +#define MY_PATH_OUT "c:\\foo\\bar" +#define MY_PATH_OUT_CONT MY_PATH_OUT "\\" +#define MY_PATH_OUT_REL "foo\\bar" +#else +#define MY_PATH_IN "/foo/bar" +#define MY_PATH_OUT MY_PATH_IN +#define MY_PATH_OUT_CONT MY_PATH_OUT "/" +#define MY_PATH_OUT_REL "foo/bar" +#endif + +namespace { + +class Test: public CppUnit::TestFixture { +private: + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testBadScheme); + CPPUNIT_TEST(testNoScheme); + CPPUNIT_TEST(testBadAuthority); + CPPUNIT_TEST(testLocalhost1Authority); + CPPUNIT_TEST(testLocalhost2Authority); + CPPUNIT_TEST(testLocalhost3Authority); + CPPUNIT_TEST(testNoAuthority); + CPPUNIT_TEST(testEmptyPath); + CPPUNIT_TEST(testHomeAbbreviation); + CPPUNIT_TEST(testOtherHomeAbbreviation); + CPPUNIT_TEST(testRelative); + CPPUNIT_TEST(testEscape); + CPPUNIT_TEST(testBadEscape2f); + CPPUNIT_TEST(testBadEscape2F); + CPPUNIT_TEST(testBad0); + CPPUNIT_TEST(testBadEscape0); + CPPUNIT_TEST(testBadQuery); + CPPUNIT_TEST(testBadFragment); + CPPUNIT_TEST_SUITE_END(); + + void testBadScheme(); + void testNoScheme(); + void testBadAuthority(); + void testLocalhost1Authority(); + void testLocalhost2Authority(); + void testLocalhost3Authority(); + void testNoAuthority(); + void testEmptyPath(); + void testHomeAbbreviation(); + void testOtherHomeAbbreviation(); + void testRelative(); + void testEscape(); + void testBadEscape2f(); + void testBadEscape2F(); + void testBad0(); + void testBadEscape0(); + void testBadQuery(); + void testBadFragment(); +}; + +void Test::testBadScheme() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL("foo:bar", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +void Test::testNoScheme() { +#if !defined(_WIN32) //TODO + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL("//" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString(MY_PATH_OUT), p); +#endif +} + +void Test::testBadAuthority() { +#if defined UNX + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://baz" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +#endif +} + +void Test::testLocalhost1Authority() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://localhost" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString(MY_PATH_OUT), p); +} + +void Test::testLocalhost2Authority() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://LOCALHOST" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString(MY_PATH_OUT), p); +} + +void Test::testLocalhost3Authority() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://127.0.0.1" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString(MY_PATH_OUT), p); +} + +void Test::testNoAuthority() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL("file:" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString(MY_PATH_OUT), p); +} + +void Test::testEmptyPath() { +#if defined UNX + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL("file://", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString("/"), p); +#endif +} + +void Test::testHomeAbbreviation() { +#if defined UNX + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL("file:///~", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + // could theoretically fail due to osl::Security::getHomeDir problem + e = osl::FileBase::getSystemPathFromFileURL("file:///~/foo%2525/bar", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + // could theoretically fail due to osl::Security::getHomeDir problem + CPPUNIT_ASSERT(p.endsWith("/foo%25/bar")); +#endif +} + +void Test::testOtherHomeAbbreviation() { +#if defined UNX + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file:///~baz" MY_PATH_IN, p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); // not supported for now + CPPUNIT_ASSERT_EQUAL(OUString(), p); +#endif +} + +void Test::testRelative() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL("foo/bar", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT(p.endsWith(MY_PATH_OUT_REL)); +} + +void Test::testEscape() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://" MY_PATH_IN "/b%61z", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + CPPUNIT_ASSERT_EQUAL(OUString(MY_PATH_OUT_CONT "baz"), p); +} + +void Test::testBadEscape2f() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://" MY_PATH_IN "/b%2fz", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +void Test::testBadEscape2F() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://" MY_PATH_IN "/b%2Fz", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +void Test::testBad0() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + OUString(RTL_CONSTASCII_USTRINGPARAM("file://" MY_PATH_IN "/b\x00z")), + p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +void Test::testBadEscape0() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://" MY_PATH_IN "/b%00z", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +void Test::testBadQuery() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://" MY_PATH_IN "?baz", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +void Test::testBadFragment() { + OUString p; + auto e = osl::FileBase::getSystemPathFromFileURL( + "file://" MY_PATH_IN "#baz", p); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_INVAL, e); + CPPUNIT_ASSERT_EQUAL(OUString(), p); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/module/osl_Module.cxx b/sal/qa/osl/module/osl_Module.cxx new file mode 100644 index 000000000..f440a7151 --- /dev/null +++ b/sal/qa/osl/module/osl_Module.cxx @@ -0,0 +1,376 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +// include files + +#include "osl_Module_Const.h" + +using namespace osl; + +/** get dll file URL. +*/ +static OUString getDllURL() +{ +#if defined(_WIN32) // lib in Unix and lib in Windows are not same in file name. + OUString libPath( "test_Module_DLL.dll" ); +#else + OUString libPath( "libtest_Module_DLL.so" ); +#endif + + OUString dirPath, dllPath; + osl::Module::getUrlFromAddress( + reinterpret_cast<oslGenericFunction>(&getDllURL), dirPath); + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1); + osl::FileBase::getAbsoluteFileURL( dirPath, libPath, dllPath ); + + return dllPath; +} + +namespace osl_Module +{ + namespace { + + /** class and member function that is available for module test : + */ + + class testClass + { + public: + static void myFunc() + { + printf("#Sun Microsystem\n"); + }; + }; + + } + + /** testing the methods: + Module(); + Module( const OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT); + */ + class ctors : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void ctors_none( ) + { + ::osl::Module aMod; + bRes = aMod.is(); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor without parameter.", + !bRes ); + } + + void ctors_name_mode( ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( + reinterpret_cast<oslGenericFunction>( + &osl_Module::testClass::myFunc), + aFileURL); + + if ( !bRes ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", false ); + } + + ::osl::Module aMod( aFileURL ); + bRes = aMod.is( ); + aMod.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with load action.", + bRes ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_name_mode ); + CPPUNIT_TEST_SUITE_END( ); + }; // class ctors + + /** testing the methods: + static sal_Bool getUrlFromAddress(void * addr, OUString & libraryUrl) + */ + class getUrlFromAddress : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getUrlFromAddress_001( ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( + reinterpret_cast<oslGenericFunction>( + &osl_Module::testClass::myFunc), + aFileURL); + if ( !bRes ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", false ); + } + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test get Module URL from address.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test get Module URL from address.", + 0 < aFileURL.lastIndexOf('/') ); + } + + void getUrlFromAddress_002( ) + { +#if !defined( MACOSX ) + // TODO: Find out why this fails on macOS + ::osl::Module aMod( getDllURL( ) ); + FuncPtr pFunc = reinterpret_cast<FuncPtr>(aMod.getSymbol( "firstfunc" )); + + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( + reinterpret_cast<oslGenericFunction>(pFunc), aFileURL); + if ( !bRes ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", false ); + } + aMod.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load an external library, get its function address and get its URL.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load an external library, get its function address and get its URL.", + 0 < aFileURL.lastIndexOf('/') ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load an external library, get its function address and get its URL.", + aFileURL.equalsIgnoreAsciiCase( getDllURL( ) ) ); +#endif + } + + /* tester comments: another case is getFunctionSymbol_001*/ + + CPPUNIT_TEST_SUITE( getUrlFromAddress ); + CPPUNIT_TEST( getUrlFromAddress_001 ); + CPPUNIT_TEST( getUrlFromAddress_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getUrlFromAddress + + /** testing the method: + sal_Bool SAL_CALL load( const OUString& strModuleName, + sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) + */ + class load : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void load_001( ) + { + ::osl::Module aMod( getDllURL( ) ); + ::osl::Module aMod1; + + aMod1.load( getDllURL( ) ); + bRes = oslModule(aMod) == oslModule(aMod1); + aMod.unload( ); + aMod1.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load function should do the same thing as constructor with library name.", + bRes ); + } + + CPPUNIT_TEST_SUITE( load ); + CPPUNIT_TEST( load_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class load + + /** testing the method: + void SAL_CALL unload() + */ + class unload : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void unload_001( ) + { + ::osl::Module aMod( getDllURL( ) ); + + aMod.unload( ); + bRes = oslModule(aMod) ==nullptr; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: unload function should do the same thing as destructor.", + bRes ); + } + + CPPUNIT_TEST_SUITE( unload ); + CPPUNIT_TEST( unload_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class unload + + /** testing the methods: + sal_Bool SAL_CALL is() const + */ + class is : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void is_001( ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( + reinterpret_cast<oslGenericFunction>( + osl_Module::testClass::myFunc), + aFileURL); + if ( !bRes ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module - using executable instead", false ); + } + + ::osl::Module aMod; + bRes = aMod.is( ); + aMod.load( aFileURL ); + bRes1 = aMod.is( ); + aMod.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test if a module is a loaded module.", + !bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test if a module is a loaded module.", + bRes1 ); + } + CPPUNIT_TEST_SUITE( is ); + CPPUNIT_TEST( is_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class is + + /** testing the methods: + void* SAL_CALL getSymbol( const OUString& strSymbolName) + */ + class getSymbol : public CppUnit::TestFixture + { + public: + bool bRes; + + void getSymbol_001( ) + { +#if !defined( MACOSX ) + // TODO: Find out why this fails on macOS + ::osl::Module aMod( getDllURL( ) ); + FuncPtr pFunc = reinterpret_cast<FuncPtr>(aMod.getSymbol( "firstfunc" )); + bRes = false; + if ( pFunc ) + bRes = pFunc( bRes ); + aMod.unload(); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and call one function in it.", + bRes ); +#endif + } + + CPPUNIT_TEST_SUITE( getSymbol ); + CPPUNIT_TEST( getSymbol_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getSymbol + + /** testing the methods: + operator oslModule() const + */ + class optr_oslModule : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void optr_oslModule_001( ) + { +#if !defined( MACOSX ) + // TODO: Find out why this fails on macOS + ::osl::Module aMod; + bRes = ( static_cast<oslModule>(aMod) == nullptr ); + + aMod.load( getDllURL( ) ); + bRes1 = static_cast<oslModule>(aMod) != nullptr; + + aMod.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: the m_Module of a Module instance will be NULL when is not loaded, it will not be NULL after loaded.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: the m_Module of a Module instance will be NULL when is not loaded, it will not be NULL after loaded.", + bRes1 ); +#endif + } + + void optr_oslModule_002( ) + { +#if !defined( MACOSX ) + // TODO: Find out why this fails on macOS + ::osl::Module aMod( getDllURL( ) ); + OUString funcName( "firstfunc" ); + + FuncPtr pFunc = reinterpret_cast<FuncPtr>(osl_getSymbol( static_cast<oslModule>(aMod), funcName.pData )); + bRes = false; + if ( pFunc ) + bRes = pFunc( bRes ); + + aMod.unload(); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: use m_Module to call osl_getSymbol() function.", + bRes ); +#endif + } + + CPPUNIT_TEST_SUITE( optr_oslModule ); + CPPUNIT_TEST( optr_oslModule_001 ); + CPPUNIT_TEST( optr_oslModule_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class optr_oslModule + + /** testing the methods: + oslGenericFunction SAL_CALL getFunctionSymbol( const OUString& ustrFunctionSymbolName ) + */ + class getFunctionSymbol : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getFunctionSymbol_001( ) + { +#if !defined( MACOSX ) + // TODO: Find out why this fails on macOS + ::osl::Module aMod( getDllURL( ) ); + oslGenericFunction oslFunc = aMod.getFunctionSymbol( "firstfunc" ); + OUString aLibraryURL; + bRes = ::osl::Module::getUrlFromAddress( oslFunc, aLibraryURL); + aMod.unload(); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and get its function addr and get its URL.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and get its function addr and get its URL.", + aLibraryURL.equalsIgnoreAsciiCase( getDllURL() ) ); +#endif + } + + CPPUNIT_TEST_SUITE( getFunctionSymbol ); + CPPUNIT_TEST( getFunctionSymbol_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getFunctionSymbol + +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::ctors); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::getUrlFromAddress); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::load); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::unload); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::is); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::getSymbol); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::optr_oslModule); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::getFunctionSymbol); + +} // namespace osl_Module + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/module/osl_Module_Const.h b/sal/qa/osl/module/osl_Module_Const.h new file mode 100644 index 000000000..3434d439f --- /dev/null +++ b/sal/qa/osl/module/osl_Module_Const.h @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSL_MODULE_OSL_MODULE_CONST_H +#define INCLUDED_SAL_QA_OSL_MODULE_OSL_MODULE_CONST_H + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <osl/module.hxx> +#include <osl/file.hxx> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#if defined(UNX) // Unix +# include <unistd.h> +#elif defined(_WIN32) // Windows +# include <io.h> +#endif + +# define FILE_PREFIX "file:///" + +// function pointer type. + +typedef sal_Bool (* FuncPtr )( sal_Bool ); + +#endif // INCLUDED_SAL_QA_OSL_MODULE_OSL_MODULE_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/module/osl_Module_DLL.cxx b/sal/qa/osl/module/osl_Module_DLL.cxx new file mode 100644 index 000000000..b8d488596 --- /dev/null +++ b/sal/qa/osl/module/osl_Module_DLL.cxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "osl_Module_Const.h" + +#include <stdio.h> +#include <sal/types.h> + +// This module contains no tests. It is loaded as a dynamic library by +// osl_Module. +// But we instantiate a test plugin to fake the build process. +CPPUNIT_PLUGIN_IMPLEMENT(); + +extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool firstfunc( sal_Bool ) +{ + return true; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/mutex/osl_Mutex.cxx b/sal/qa/osl/mutex/osl_Mutex.cxx new file mode 100644 index 000000000..c345ae33e --- /dev/null +++ b/sal/qa/osl/mutex/osl_Mutex.cxx @@ -0,0 +1,896 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +// include files + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include "osl_Mutex_Const.h" + +using namespace osl; + +/** pause nSec seconds helper function. +*/ +namespace ThreadHelper +{ + static void thread_sleep_tenth_sec(sal_uInt32 _nTenthSec) + { + osl::Thread::wait(std::chrono::milliseconds(_nTenthSec * 100)); + } + static void thread_sleep( sal_uInt32 _nSec ) + { + /// print statement in thread process must use fflush() to force display. + // t_print("# wait %d seconds. ", _nSec ); + fflush(stdout); + + thread_sleep_tenth_sec( _nSec * 10 ); + // printf("# done\n" ); + } +} + +// Beginning of the test cases for osl_Mutex class + +namespace { + +/** mutually exclusive data +*/ +struct resource { + sal_Int32 data1; + sal_Int32 data2; + Mutex lock; +}; + +/** IncreaseThread provide data. +*/ +class IncreaseThread : public Thread +{ +public: + explicit IncreaseThread( struct resource *pData ): pResource( pData ) { } + + virtual ~IncreaseThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#IncreaseThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + struct resource *pResource; + + void SAL_CALL run( ) override + { + pResource->lock.acquire( ); + for( sal_Int8 i = 0; i < 3; i++ ) + { + pResource->data1++; + yield( ); //yield() give CPU time to other thread, other thread if not block, they will change the data; + } + if ( pResource->data2 == 0 ) + pResource->data2 = ( pResource->data1 > 0 ? pResource->data1 : 0 - pResource->data1 ); + pResource->lock.release(); + } +}; + +/** DecreaseThread consume data. +*/ +class DecreaseThread : public Thread +{ +public: + explicit DecreaseThread( struct resource *pData ): pResource( pData ) { } + + virtual ~DecreaseThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#DecreaseThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + struct resource *pResource; + + void SAL_CALL run( ) override + { + pResource->lock.acquire( ); + for( sal_Int8 i = 0; i < 3; i++ ) + { + pResource->data1--; + yield( ); //yield() give CPU time to other thread, other thread if not block, they will change the data; + } + if ( pResource->data2 == 0 ) + pResource->data2 = ( pResource->data1 > 0 ? pResource->data1 : 0 - pResource->data1 ); + pResource->lock.release(); + } +}; + +/** chain structure used in Threads as critical resource +*/ +struct chain { + sal_Int32 buffer[ BUFFER_SIZE ]; + Mutex lock; + sal_Int8 pos; +}; + +/** PutThread write to the chain structure in a mutex manner. +*/ +class PutThread : public Thread +{ +public: + //get the struct pointer to write data to buffer + explicit PutThread( struct chain* pData ): pChain( pData ) { } + + virtual ~PutThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#PutThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + struct chain* pChain; + + void SAL_CALL run( ) override + { + //block here if the mutex has been acquired + pChain->lock.acquire( ); + + //current position in buffer to write + sal_Int8 nPos = pChain->pos; + oslThreadIdentifier oId = getIdentifier( ); + //write data + sal_Int8 i; + for ( i = 0; i < 5; i++ ) + { + pChain->buffer[ nPos + i ] = oId; + yield( ); + } + //revise the position + pChain->pos = nPos + i; + + //finish writing, release the mutex + pChain->lock.release(); + } +}; + +/** thread for testing Mutex acquire. + */ +class HoldThread : public Thread +{ +public: + //get the Mutex pointer to operate + explicit HoldThread( Mutex* pMutex ): pMyMutex( pMutex ) { } + + virtual ~HoldThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#HoldThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run() override + { + // block here if the mutex has been acquired + pMyMutex->acquire( ); + printf("# Mutex acquired. \n" ); + pMyMutex->release( ); + } +}; + +class WaitThread : public Thread +{ +public: + //get the Mutex pointer to operate + explicit WaitThread( Mutex* pMutex ): pMyMutex( pMutex ) { } + + virtual ~WaitThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#WaitThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) override + { + // block here if the mutex has been acquired + pMyMutex->acquire( ); + ThreadHelper::thread_sleep_tenth_sec( 2 ); + pMyMutex->release( ); + } +}; + +/** thread for testing getGlobalMutex. + */ +class GlobalMutexThread : public Thread +{ +public: + //get the Mutex pointer to operate + GlobalMutexThread( ){ } + + virtual ~GlobalMutexThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#GlobalMutexThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + void SAL_CALL run( ) override + { + // block here if the mutex has been acquired + Mutex* pGlobalMutex; + pGlobalMutex = Mutex::getGlobalMutex( ); + pGlobalMutex->acquire( ); + printf("# Global Mutex acquired. \n" ); + pGlobalMutex->release( ); + } +}; + +} + +namespace osl_Mutex +{ + + /** Test of the osl::Mutex::constructor + */ + class ctor : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + struct chain m_Data; + struct resource m_Res; + + void setUp( ) override + { + for ( sal_Int8 i=0; i < BUFFER_SIZE; i++ ) + m_Data.buffer[i] = 0; + m_Data.pos = 0; + + m_Res.data1 = 0; + m_Res.data2 = 0; + } + + /** Create two threads to write data to the same buffer, use Mutex to assure + during one thread write data five times, the other thread should not begin writing. + the two threads wrote two different data: their thread ID, so we can check the data + in buffer to know the order of the two threads writing + */ + void ctor_001() + { + PutThread myThread1( &m_Data ); + PutThread myThread2( &m_Data ); + + myThread1.create( ); + myThread2.create( ); + + //wait until the two threads terminate + myThread1.join( ); + myThread2.join( ); + + bool bRes = false; + + // every 5 data should the same + // LLA: this is not a good check, it's too fix + if (m_Data.buffer[0] == m_Data.buffer[1] && + m_Data.buffer[1] == m_Data.buffer[2] && + m_Data.buffer[2] == m_Data.buffer[3] && + m_Data.buffer[3] == m_Data.buffer[4] && + m_Data.buffer[5] == m_Data.buffer[6] && + m_Data.buffer[6] == m_Data.buffer[7] && + m_Data.buffer[7] == m_Data.buffer[8] && + m_Data.buffer[8] == m_Data.buffer[9]) + bRes = true; + + /*for (sal_Int8 i=0; i<BUFFER_SIZE; i++) + printf("#data in buffer is %d\n", m_Data.buffer[i]); + */ + + CPPUNIT_ASSERT_MESSAGE("Mutex ctor", bRes); + + } + + /** Create two threads to write data to operate on the same number , use Mutex to assure, + one thread increase data 3 times, the other thread decrease 3 times, store the operate + result when the first thread complete, if it is interrupt by the other thread, the stored + number will not be 3. + */ + void ctor_002() + { + IncreaseThread myThread1( &m_Res ); + DecreaseThread myThread2( &m_Res ); + + myThread1.create( ); + myThread2.create( ); + + //wait until the two threads terminate + myThread1.join( ); + myThread2.join( ); + + bool bRes = false; + + // every 5 data should the same + if ( ( m_Res.data1 == 0 ) && ( m_Res.data2 == 3 ) ) + bRes = true; + + CPPUNIT_ASSERT_MESSAGE( "test Mutex ctor function: increase and decrease a number 3 times without interrupt.", bRes ); + } + + CPPUNIT_TEST_SUITE( ctor ); + CPPUNIT_TEST( ctor_001 ); + CPPUNIT_TEST( ctor_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class ctor + + /** Test of the osl::Mutex::acquire method + */ + class acquire : public CppUnit::TestFixture + { + public: + // acquire mutex in main thread, and then call acquire again in myThread, + // the child thread should block, wait 2 secs, it still block. + // Then release mutex in main thread, the child thread could return from acquire, + // and go to exec next statement, so could terminate quickly. + void acquire_001( ) + { + Mutex aMutex; + //acquire here + bool bRes = aMutex.acquire( ); + // pass the pointer of mutex to child thread + HoldThread myThread( &aMutex ); + myThread.create( ); + + ThreadHelper::thread_sleep_tenth_sec( 2 ); + // if acquire in myThread does not work, 2 secs is long enough, + // myThread should terminate now, and bRes1 should be sal_False + bool bRes1 = myThread.isRunning( ); + + aMutex.release( ); + ThreadHelper::thread_sleep_tenth_sec( 1 ); + // after release mutex, myThread stops blocking and will terminate immediately + bool bRes2 = myThread.isRunning( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE( "Mutex acquire", bRes ); + CPPUNIT_ASSERT_MESSAGE( "Mutex acquire", bRes1 ); + CPPUNIT_ASSERT_MESSAGE( "Mutex acquire", !bRes2 ); + } + + //in the same thread, acquire twice should success + void acquire_002() + { + Mutex aMutex; + //acquire here + bool bRes = aMutex.acquire(); + bool bRes1 = aMutex.acquire(); + + bool bRes2 = aMutex.tryToAcquire(); + + aMutex.release(); + + CPPUNIT_ASSERT_MESSAGE("Mutex acquire", bRes); + CPPUNIT_ASSERT_MESSAGE("Mutex acquire", bRes1); + CPPUNIT_ASSERT_MESSAGE("Mutex acquire", bRes2); + + } + + CPPUNIT_TEST_SUITE( acquire ); + CPPUNIT_TEST( acquire_001 ); + CPPUNIT_TEST( acquire_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class acquire + + /** Test of the osl::Mutex::tryToAcquire method + */ + class tryToAcquire : public CppUnit::TestFixture + { + public: + // First let child thread acquire the mutex, and wait 2 secs, during the 2 secs, + // in main thread, tryToAcquire mutex should return False + // then after the child thread terminated, tryToAcquire should return True + void tryToAcquire_001() + { + Mutex aMutex; + WaitThread myThread(&aMutex); + myThread.create(); + + // ensure the child thread acquire the mutex + ThreadHelper::thread_sleep_tenth_sec(1); + + bool bRes1 = aMutex.tryToAcquire(); + + if (bRes1) + aMutex.release(); + // wait the child thread terminate + myThread.join(); + + bool bRes2 = aMutex.tryToAcquire(); + + if (bRes2) + aMutex.release(); + + CPPUNIT_ASSERT_MESSAGE("Try to acquire Mutex", !bRes1); + CPPUNIT_ASSERT_MESSAGE("Try to acquire Mutex", bRes2); + } + + CPPUNIT_TEST_SUITE(tryToAcquire); + CPPUNIT_TEST(tryToAcquire_001); + CPPUNIT_TEST_SUITE_END(); + }; // class tryToAcquire + + /** Test of the osl::Mutex::release method + */ + class release : public CppUnit::TestFixture + { + public: + /** acquire/release are not used in pairs: after child thread acquired mutex, + the main thread release it, then any thread could acquire it. + */ + void release_001() + { + Mutex aMutex; + WaitThread myThread( &aMutex ); + myThread.create( ); + + // ensure the child thread acquire the mutex + ThreadHelper::thread_sleep_tenth_sec( 1 ); + + bool bRunning = myThread.isRunning( ); + bool bRes1 = aMutex.tryToAcquire( ); + // wait the child thread terminate + myThread.join( ); + + bool bRes2 = aMutex.tryToAcquire( ); + + if ( bRes2 ) + aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "release Mutex: try to acquire before and after the mutex has been released", + !bRes1 ); + CPPUNIT_ASSERT_MESSAGE( "release Mutex: try to acquire before and after the mutex has been released", + bRes2 ); + CPPUNIT_ASSERT_MESSAGE( "release Mutex: try to acquire before and after the mutex has been released", + bRunning ); + + } + + // how about release twice? + void release_002() + { + } + + CPPUNIT_TEST_SUITE( release ); + CPPUNIT_TEST( release_001 ); + CPPUNIT_TEST( release_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class release + + /** Test of the osl::Mutex::getGlobalMutex method + */ + class getGlobalMutex : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void getGlobalMutex_001() + { + Mutex* pGlobalMutex; + pGlobalMutex = Mutex::getGlobalMutex(); + pGlobalMutex->acquire(); + + GlobalMutexThread myThread; + myThread.create(); + + ThreadHelper::thread_sleep_tenth_sec(1); + bool bRes1 = myThread.isRunning(); + + pGlobalMutex->release(); + ThreadHelper::thread_sleep_tenth_sec(1); + // after release mutex, myThread stops blocking and will terminate immediately + bool bRes2 = myThread.isRunning(); + + CPPUNIT_ASSERT_MESSAGE("Global Mutex works", bRes1); + CPPUNIT_ASSERT_MESSAGE("Global Mutex works", !bRes2); + } + + void getGlobalMutex_002( ) + { + bool bRes; + + Mutex *pGlobalMutex; + pGlobalMutex = Mutex::getGlobalMutex( ); + pGlobalMutex->acquire( ); + { + Mutex *pGlobalMutex1; + pGlobalMutex1 = Mutex::getGlobalMutex( ); + bRes = pGlobalMutex1->release( ); + } + + CPPUNIT_ASSERT_MESSAGE( "Global Mutex works: if the code between {} get the different mutex as the former one, it will return false when release.", + bRes ); + } + + CPPUNIT_TEST_SUITE(getGlobalMutex); + CPPUNIT_TEST(getGlobalMutex_001); + CPPUNIT_TEST(getGlobalMutex_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getGlobalMutex + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::ctor, "osl_Mutex"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::acquire, "osl_Mutex"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::tryToAcquire, "osl_Mutex"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::release, "osl_Mutex"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Mutex::getGlobalMutex, "osl_Mutex"); +} // namespace osl_Mutex + +// Beginning of the test cases for osl_Guard class + +namespace { + +class GuardThread : public Thread +{ +public: + //get the Mutex pointer to operate + explicit GuardThread( Mutex* pMutex ): pMyMutex( pMutex ) { } + + virtual ~GuardThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#GuardThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) override + { + // block here if the mutex has been acquired + MutexGuard aGuard( pMyMutex ); + ThreadHelper::thread_sleep_tenth_sec( 2 ); + } +}; + +} + +namespace osl_Guard +{ + class ctor : public CppUnit::TestFixture + { + public: + // insert your test code here. + void ctor_001() + { + Mutex aMutex; + GuardThread myThread(&aMutex); + myThread.create(); + + ThreadHelper::thread_sleep_tenth_sec(1); + bool bRes = aMutex.tryToAcquire(); + // after 1 second, the mutex has been guarded, and the child thread should be running + bool bRes1 = myThread.isRunning(); + + myThread.join(); + bool bRes2 = aMutex.tryToAcquire(); + + CPPUNIT_ASSERT_MESSAGE("GuardThread constructor", + !bRes); + CPPUNIT_ASSERT_MESSAGE("GuardThread constructor", + bRes1); + CPPUNIT_ASSERT_MESSAGE("GuardThread constructor", + bRes2); + } + + void ctor_002( ) + { + Mutex aMutex; + + /// use reference constructor here + MutexGuard myGuard( aMutex ); + + /// the GuardThread will block here when it is initialised. + GuardThread myThread( &aMutex ); + myThread.create( ); + + /// is it still blocking? + ThreadHelper::thread_sleep_tenth_sec( 2 ); + bool bRes = myThread.isRunning( ); + + /// oh, release him. + aMutex.release( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE("GuardThread constructor: reference initialization, acquire the mutex before running the thread, then check if it is blocking.", + bRes); + } + + CPPUNIT_TEST_SUITE(ctor); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST_SUITE_END(); + }; // class ctor + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Guard::ctor, "osl_Guard"); +} // namespace osl_Guard + +// Beginning of the test cases for osl_ClearableGuard class + +namespace { + +/** Thread for test ClearableGuard + */ +class ClearGuardThread : public Thread +{ +public: + //get the Mutex pointer to operate + explicit ClearGuardThread( Mutex* pMutex ): pMyMutex( pMutex ) {} + + virtual ~ClearGuardThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#ClearGuardThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) override + { + // acquire the mutex + // printf("# ClearGuardThread" ); + ClearableMutexGuard aGuard( pMyMutex ); + ThreadHelper::thread_sleep( 5 ); + + // release the mutex + aGuard.clear( ); + ThreadHelper::thread_sleep( 2 ); + } +}; + +} + +namespace osl_ClearableGuard +{ + + class ctor : public CppUnit::TestFixture + { + public: + void ctor_001() + { + Mutex aMutex; + + /// now, the aMutex has been guarded. + ClearableMutexGuard myMutexGuard( &aMutex ); + + /// it will return sal_False if the aMutex has not been Guarded. + bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the acquire operation when initialized.", + bRes); + } + + void ctor_002( ) + { + Mutex aMutex; + + /// now, the aMutex has been guarded, this time, we use reference constructor. + ClearableMutexGuard myMutexGuard( aMutex ); + + /// it will return sal_False if the aMutex has not been Guarded. + bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the acquire operation when initialized, we use reference constructor this time.", + bRes); + } + + CPPUNIT_TEST_SUITE(ctor); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST_SUITE_END(); + }; // class ctor + + class clear : public CppUnit::TestFixture + { + public: + void clear_001() + { + Mutex aMutex; + ClearGuardThread myThread(&aMutex); + myThread.create(); + + TimeValue aTimeVal_befor; + osl_getSystemTime( &aTimeVal_befor ); + // wait 1 second to assure the child thread has begun + ThreadHelper::thread_sleep(1); + + while (true) + { + if (aMutex.tryToAcquire()) + { + break; + } + ThreadHelper::thread_sleep(1); + } + TimeValue aTimeVal_after; + osl_getSystemTime( &aTimeVal_after ); + sal_Int32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + printf("nSec is %" SAL_PRIdINT32 "\n", nSec); + + myThread.join(); + + CPPUNIT_ASSERT_MESSAGE("ClearableGuard method: clear", + nSec < 7); + CPPUNIT_ASSERT_MESSAGE("ClearableGuard method: clear", + nSec > 1); + } + + void clear_002( ) + { + Mutex aMutex; + + /// now, the aMutex has been guarded. + ClearableMutexGuard myMutexGuard( &aMutex ); + + /// launch the HoldThread, it will be blocked here. + HoldThread myThread( &aMutex ); + myThread.create( ); + + /// is it blocking? + ThreadHelper::thread_sleep_tenth_sec( 4 ); + bool bRes = myThread.isRunning( ); + + /// use clear to release. + myMutexGuard.clear( ); + myThread.join( ); + bool bRes1 = myThread.isRunning( ); + + CPPUNIT_ASSERT_MESSAGE( "ClearableGuard method: clear, control the HoldThread's running status!", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "ClearableGuard method: clear, control the HoldThread's running status!", + !bRes1 ); + } + + CPPUNIT_TEST_SUITE( clear ); + CPPUNIT_TEST( clear_001 ); + CPPUNIT_TEST( clear_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class clear + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_ClearableGuard::ctor, "osl_ClearableGuard" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_ClearableGuard::clear, "osl_ClearableGuard" ); +} // namespace osl_ClearableGuard + +// Beginning of the test cases for osl_ResettableGuard class + +namespace { + +/** Thread for test ResettableGuard + */ +class ResetGuardThread : public Thread +{ +public: + //get the Mutex pointer to operate + explicit ResetGuardThread( Mutex* pMutex ): pMyMutex( pMutex ) {} + + virtual ~ResetGuardThread( ) override + { + CPPUNIT_ASSERT_MESSAGE( "#ResetGuardThread does not shutdown properly.\n", !isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) override + { + // acquire the mutex + printf("# ResettableGuard\n" ); + ResettableMutexGuard aGuard( pMyMutex ); + // release the mutex + aGuard.clear( ); + ThreadHelper::thread_sleep_tenth_sec( 2 ); + } +}; + +} + +namespace osl_ResettableGuard +{ + class ctor : public CppUnit::TestFixture + { + public: + void ctor_001() + { + Mutex aMutex; + + /// now, the aMutex has been guarded. + ResettableMutexGuard myMutexGuard( &aMutex ); + + /// it will return sal_False if the aMutex has not been Guarded. + bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE("ResettableMutexGuard constructor, test the acquire operation when initialized.", + bRes); + } + + void ctor_002( ) + { + Mutex aMutex; + + /// now, the aMutex has been guarded, this time, we use reference constructor. + ResettableMutexGuard myMutexGuard( aMutex ); + + /// it will return sal_False if the aMutex has not been Guarded. + bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard constructor, test the acquire operation when initialized, we use reference constructor this time.", + bRes); + } + + CPPUNIT_TEST_SUITE(ctor); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST_SUITE_END(); + }; // class ctor + + class reset : public CppUnit::TestFixture + { + public: + void reset_001( ) + { + Mutex aMutex; + ResetGuardThread myThread( &aMutex ); + ResettableMutexGuard myMutexGuard( aMutex ); + myThread.create( ); + + /// is it running? and clear done? + bool bRes = myThread.isRunning( ); + myMutexGuard.clear( ); + ThreadHelper::thread_sleep_tenth_sec( 1 ); + + /// if reset is not success, the release will return sal_False + myMutexGuard.reset( ); + bool bRes1 = aMutex.release( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset", + bRes1 ); + } + +#ifdef LINUX + void reset_002( ) + { + Mutex aMutex; + ResettableMutexGuard myMutexGuard( &aMutex ); + + /// shouldn't release after clear; + myMutexGuard.clear( ); + bool bRes = aMutex.release( ); + + /// can release after reset. + myMutexGuard.reset( ); + bool bRes1 = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset, release after clear and reset, on Solaris, the mutex can be release without acquire, so it can not passed on (SOLARIS), but not the reason for reset_002", + !bRes ); + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset, release after clear and reset, on Solaris, the mutex can be release without acquire, so it can not passed on (SOLARIS), but not the reason for reset_002", + bRes1 ); + } +#endif + + CPPUNIT_TEST_SUITE(reset); + CPPUNIT_TEST(reset_001); +#ifdef LINUX + CPPUNIT_TEST(reset_002); +#endif + CPPUNIT_TEST_SUITE_END(); + }; // class reset + +CPPUNIT_TEST_SUITE_REGISTRATION(osl_ResettableGuard::ctor); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_ResettableGuard::reset); +} // namespace osl_ResettableGuard + +// The following sets variables for GNU EMACS +// Local Variables: +// tab-width:4 +// End: + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/mutex/osl_Mutex_Const.h b/sal/qa/osl/mutex/osl_Mutex_Const.h new file mode 100644 index 000000000..a5ac53ed4 --- /dev/null +++ b/sal/qa/osl/mutex/osl_Mutex_Const.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSL_MUTEX_OSL_MUTEX_CONST_H +#define INCLUDED_SAL_QA_OSL_MUTEX_OSL_MUTEX_CONST_H + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <osl/thread.hxx> +#include <osl/mutex.hxx> +#include <osl/time.h> + +#ifdef UNX +#include <unistd.h> +#endif + +#define BUFFER_SIZE 16 + +#endif // INCLUDED_SAL_QA_OSL_MUTEX_OSL_MUTEX_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/pipe/osl_Pipe.cxx b/sal/qa/osl/pipe/osl_Pipe.cxx new file mode 100644 index 000000000..0237fa57a --- /dev/null +++ b/sal/qa/osl/pipe/osl_Pipe.cxx @@ -0,0 +1,896 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +// include files + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <rtl/ustring.hxx> + +#include <osl/test/uniquepipename.hxx> +#include <osl/thread.hxx> + +#include <osl/pipe.hxx> +#include <osl/time.h> + +#ifdef UNX +#include <unistd.h> +#endif +#include <string.h> + +using namespace osl; + +/** print last error of pipe system. + */ +static void printPipeError( ::osl::Pipe const & aPipe ) +{ + oslPipeError nError = aPipe.getError( ); + printf("#printPipeError# " ); + switch ( nError ) { + case osl_Pipe_E_None: + printf("Success!\n" ); + break; + case osl_Pipe_E_NotFound: + printf("The returned error is: Not found!\n" ); + break; + case osl_Pipe_E_AlreadyExists: + printf("The returned error is: Already exist!\n" ); + break; + case osl_Pipe_E_NoProtocol: + printf("The returned error is: No protocol!\n" ); + break; + case osl_Pipe_E_NetworkReset: + printf("The returned error is: Network reset!\n" ); + break; + case osl_Pipe_E_ConnectionAbort: + printf("The returned error is: Connection aborted!\n" ); + break; + case osl_Pipe_E_ConnectionReset: + printf("The returned error is: Connection reset!\n" ); + break; + case osl_Pipe_E_NoBufferSpace: + printf("The returned error is: No buffer space!\n" ); + break; + case osl_Pipe_E_TimedOut: + printf("The returned error is: Timeout!\n" ); + break; + case osl_Pipe_E_ConnectionRefused: + printf("The returned error is: Connection refused!\n" ); + break; + case osl_Pipe_E_invalidError: + printf("The returned error is: Invalid error!\n" ); + break; + default: + printf("The returned error is: Number %d, Unknown Error\n", nError ); + break; + } +} + +// pipe name and transfer contents + +const OUString aTestPipeName("testpipe2"); +const OUString aTestPipe1("testpipe1"); +const OUString aTestString("Sun Microsystems"); + +const OString m_pTestString1("Sun Microsystems"); +const OString m_pTestString2("test pipe PASS/OK"); + +// test code start here + +namespace osl_Pipe +{ + +// most return value -1 denote a fail of operation. + +#define OSL_PIPE_FAIL -1 + + /** testing the methods: + inline Pipe(); + inline Pipe(const OUString& strName, oslPipeOptions Options); + inline Pipe(const OUString& strName, oslPipeOptions Options,const Security & rSecurity); + inline Pipe(const Pipe& pipe); + inline Pipe(oslPipe pipe, __sal_NoAcquire noacquire ); + inline Pipe(oslPipe Pipe); + */ + class ctors : public CppUnit::TestFixture + { + public: + bool bRes, bRes1, bRes2; + + void ctors_none( ) + { + ::osl::Pipe aPipe; + bRes = aPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.", + !bRes ); + } + + void ctors_name_option( ) + { + /// create a named pipe. + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + ::osl::Pipe aAssignPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); + + bRes = aPipe.is( ) && aAssignPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.", + bRes ); + } + + void ctors_name_option_security( ) + { + /// create a security pipe. + const ::osl::Security rSecurity; + ::osl::Pipe aSecurityPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSecurity ); + + bRes = aSecurityPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.", + bRes ); + } + + void ctors_copy( ) + { + /// create a pipe. + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + /// create a pipe using copy constructor. + ::osl::Pipe aCopyPipe( aPipe ); + + bRes = aCopyPipe.is( ) && aCopyPipe == aPipe; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.", + bRes ); + } + + /* Note: DO NOT DO THIS - I have very deliberately caused send to FAIL, *on purpose* as this is the + only sane way to test noacquire. This is a terrible misuse of no-acquire, but in this case is + needed only so we can test to make sure no-acquire is working! + */ + void ctors_no_acquire( ) + { + /// create a pipe. + OUString aPipeName(test::uniquePipeName(aTestPipeName)); + oslPipe handle(osl_createPipe(aPipeName.pData, osl_Pipe_CREATE, nullptr)); + /// constructs a pipe reference without acquiring the handle. + std::unique_ptr<osl::Pipe> xNoAcquirePipe(new osl::Pipe(handle, SAL_NO_ACQUIRE)); + + StreamPipe aStreamPipe(handle); + xNoAcquirePipe.reset(); + int nRet = aStreamPipe.send("a", 1); + + if (nRet >= 0) + bRes = false; + else + bRes = true; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, deleted nonacquired pipe but could still send on original pipe!.", + bRes ); + } + + void ctors_acquire( ) + { + /// create a base pipe. + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + /// constructs two pipes, the second acquires the first pipe's handle. + ::osl::Pipe aAcquirePipe( aPipe.getHandle( ) ); + ::osl::Pipe aAcquirePipe1( nullptr ); + + bRes = aAcquirePipe.is(); + bRes1 = aAcquirePipe1.is(); + bRes2 = aPipe == aAcquirePipe; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with acquire of handle, original pipe does not exist.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with acquire of handle, copied pipe does not exist", + !bRes1 ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test pipes should have same handle", bRes2); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_name_option ); + CPPUNIT_TEST( ctors_name_option_security ); + CPPUNIT_TEST( ctors_copy ); + CPPUNIT_TEST( ctors_no_acquire ); + CPPUNIT_TEST( ctors_acquire ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + inline sal_Bool SAL_CALL is() const; + */ + class is : public CppUnit::TestFixture + { + public: + void is_001( ) + { + ::osl::Pipe aPipe; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", !aPipe.is( ) ); + } + + void is_002( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", aPipe.is( ) ); + } + + void is_003( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", !aPipe.is( ) ); + } + + void is_004( ) + { + ::osl::Pipe aPipe( nullptr ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", !aPipe.is( ) ); + } + + CPPUNIT_TEST_SUITE( is ); + CPPUNIT_TEST( is_001 ); + CPPUNIT_TEST( is_002 ); + CPPUNIT_TEST( is_003 ); + CPPUNIT_TEST( is_004 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the methods: + inline sal_Bool create( const OUString & strName, + oslPipeOptions Options, const Security &rSec ); + nline sal_Bool create( const OUString & strName, + oslPipeOptions Options = osl_Pipe_OPEN ); + */ + class create : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + /** tester comment: + + security create only be tested creation, security section is + untested yet. + */ + + void create_named_security_001( ) + { + const Security rSec; + ::osl::Pipe aPipe; + bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSec ); + bRes1 = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSec ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", + bRes); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", + !bRes1); + } + + void create_named_security_002( ) + { + const Security rSec; + ::osl::Pipe aPipe, aPipe1; + bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSec ); + bRes1 = aPipe1.create( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN, rSec ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", + bRes); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", + bRes1); + } + + void create_named_001( ) + { + ::osl::Pipe aPipe; + bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + bRes1 = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", + bRes); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", + !bRes1); + } + + void create_named_002( ) + { + ::osl::Pipe aPipe, aPipe1; + bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + bRes1 = aPipe1.create( test::uniquePipeName(aTestPipeName) ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", + bRes); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", + bRes1); + } + + void create_named_003( ) + { + ::osl::Pipe aPipe; + bRes = aPipe.create( test::uniquePipeName(aTestPipeName) ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.", + !bRes ); + } + + CPPUNIT_TEST_SUITE( create ); + CPPUNIT_TEST( create_named_security_001 ); + CPPUNIT_TEST( create_named_security_002 ); + CPPUNIT_TEST( create_named_001 ); + CPPUNIT_TEST( create_named_002 ); + CPPUNIT_TEST( create_named_003 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + inline void SAL_CALL clear(); + */ + class clear : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void clear_001( ) + { + ::osl::Pipe aPipe; + aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + aPipe.clear( ); + bRes = aPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.", + !bRes ); + } + + CPPUNIT_TEST_SUITE( clear ); + CPPUNIT_TEST( clear_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the methods: + inline Pipe& SAL_CALL operator= (const Pipe& pipe); + inline Pipe& SAL_CALL operator= (const oslPipe pipe ); + */ + class assign : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void assign_ref( ) + { + ::osl::Pipe aPipe, aPipe1; + aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + aPipe1 = aPipe; + bRes = aPipe1.is( ); + bRes1 = aPipe == aPipe1; + aPipe.close( ); + aPipe1.close( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.", + bRes1 ); + } + + void assign_handle( ) + { + ::osl::Pipe aPipe, aPipe1; + aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + aPipe1 = aPipe.getHandle( ); + bRes = aPipe1.is( ); + bRes1 = aPipe == aPipe1; + aPipe.close( ); + aPipe1.close( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.", + bRes1 ); + } + + CPPUNIT_TEST_SUITE( assign ); + CPPUNIT_TEST( assign_ref ); + CPPUNIT_TEST( assign_handle ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + inline sal_Bool SAL_CALL isValid() const; + isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx + */ + + /** testing the method: + inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const; + */ + class isEqual : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void isEqual_001( ) + { + ::osl::Pipe aPipe; + aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + bRes = aPipe == aPipe; // NOLINT(misc-redundant-expression) + aPipe.close( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare itself.", + bRes ); + } + + void isEqual_002( ) + { + ::osl::Pipe aPipe, aPipe1, aPipe2; + aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + + aPipe1 = aPipe; + aPipe2.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + + bRes = aPipe == aPipe1; + bRes1 = aPipe == aPipe2; + aPipe.close( ); + aPipe1.close( ); + aPipe2.close( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.", + bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.", + !bRes1 ); + } + + CPPUNIT_TEST_SUITE( isEqual ); + CPPUNIT_TEST( isEqual_001 ); + CPPUNIT_TEST( isEqual_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + inline void SAL_CALL close(); + */ + class close : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void close_001( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipe1), osl_Pipe_CREATE ); + aPipe.close( ); + bRes = aPipe.is( ); + + aPipe.clear( ); + bRes1 = aPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.", + bRes); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.", + !bRes1); + } + + void close_002( ) + { + ::osl::StreamPipe aPipe( test::uniquePipeName(aTestPipe1), osl_Pipe_CREATE ); + aPipe.close( ); + int nRet = aPipe.send( m_pTestString1.getStr(), 3 ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: use after close.", + OSL_PIPE_FAIL, nRet ); + } + + CPPUNIT_TEST_SUITE( close ); + CPPUNIT_TEST( close_001 ); + CPPUNIT_TEST( close_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + inline oslPipeError SAL_CALL accept(StreamPipe& Connection); + please refer to StreamPipe::recv + */ + + /** testing the method: + inline oslPipeError SAL_CALL getError() const; + */ + class getError : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getError_001( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); + oslPipeError nError = aPipe.getError( ); + printPipeError( aPipe ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe.", + nError != osl_Pipe_E_None ); + } + + void getError_002( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + ::osl::Pipe aPipe1( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + oslPipeError nError = aPipe.getError( ); + printPipeError( aPipe ); + aPipe.clear( ); + aPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.", + nError != osl_Pipe_E_None ); + } + + CPPUNIT_TEST_SUITE( getError ); + CPPUNIT_TEST( getError_001 ); + CPPUNIT_TEST( getError_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the method: + inline oslPipe SAL_CALL getHandle() const; + */ + class getHandle : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getHandle_equalityOperatorAgainstSelf( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); + bRes = aPipe == aPipe.getHandle( ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.", + bRes ); + } + + void getHandle_equalityOperatorAgainstDerivedPipe( ) + { + ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + ::osl::Pipe aPipe1( aPipe.getHandle( ) ); + bRes = aPipe == aPipe1; + aPipe.clear( ); + aPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.", + bRes ); + } + + CPPUNIT_TEST_SUITE( getHandle ); + CPPUNIT_TEST( getHandle_equalityOperatorAgainstSelf ); + CPPUNIT_TEST( getHandle_equalityOperatorAgainstDerivedPipe ); + CPPUNIT_TEST_SUITE_END( ); + }; + + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::ctors); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::is); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::create); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::clear); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::assign); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isEqual); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::close); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getError); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getHandle); + +} // namespace osl_Pipe + +namespace osl_StreamPipe +{ + + /** testing the methods: + inline StreamPipe(); + inline StreamPipe(oslPipe Pipe); + inline StreamPipe(const StreamPipe& Pipe); + inline StreamPipe(const OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN); + inline StreamPipe(const OUString& strName, oslPipeOptions Options, const Security &rSec ); + inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire ); + */ + class ctors : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void ctors_none( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + // create an unattached pipe. + ::osl::StreamPipe aStreamPipe1; + bRes = aStreamPipe1.is( ); + + // assign it and check. + aStreamPipe1 = aStreamPipe; + bRes1 = aStreamPipe1.is( ); + aStreamPipe.clear( ); + aStreamPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.", + !bRes ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.", + bRes1 ); + } + + void ctors_handle( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + // create a pipe with last handle. + ::osl::StreamPipe aStreamPipe1( aStreamPipe.getHandle( ) ); + bRes = aStreamPipe1.is( ) && aStreamPipe == aStreamPipe1; + aStreamPipe.clear( ); + aStreamPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.", + bRes ); + } + + void ctors_copy( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + // create an unattached pipe. + ::osl::StreamPipe aStreamPipe1( aStreamPipe ); + bRes = aStreamPipe1.is( ) && aStreamPipe == aStreamPipe1; + aStreamPipe.clear( ); + aStreamPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.", + bRes ); + } + + void ctors_name_option( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + // create an unattached pipe. + ::osl::StreamPipe aStreamPipe1( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); + bRes = aStreamPipe1.is( ) && aStreamPipe.is( ); + aStreamPipe.clear( ); + aStreamPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.", + bRes ); + } + + void ctors_name_option_security( ) + { + /// create a security pipe. + const ::osl::Security rSecurity; + ::osl::StreamPipe aSecurityPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSecurity ); + + bRes = aSecurityPipe.is( ); + aSecurityPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.", + bRes ); + } + + /** tester comment: + + When test the following constructor, don't know how to test the + acquire and no acquire action. possible plans: + 1.release one handle and check the other( did not success since the + other still exist and valid. ) + 2. release one handle twice to see getLastError( )(the getLastError + always returns invalidError(LINUX)). + */ + + void ctors_no_acquire( ) + { + // create a pipe. + ::osl::StreamPipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + osl_acquirePipe(aPipe.getHandle()); + // constructs a pipe reference without acquiring the handle. + ::osl::StreamPipe aNoAcquirePipe( aPipe.getHandle( ), SAL_NO_ACQUIRE ); + + bRes = aNoAcquirePipe.is( ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, only validation test, do not know how to test no acquire.", + bRes ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_handle ); + CPPUNIT_TEST( ctors_copy ); + CPPUNIT_TEST( ctors_name_option ); + CPPUNIT_TEST( ctors_name_option_security ); + CPPUNIT_TEST( ctors_no_acquire ); + CPPUNIT_TEST_SUITE_END( ); + }; + + /** testing the methods: + inline StreamPipe & SAL_CALL operator=(oslPipe Pipe); + inline StreamPipe& SAL_CALL operator=(const Pipe& pipe); + mindy: not implemented in osl/pipe.hxx, so remove the cases + */ + + /** wait _nSec seconds. + */ + static void thread_sleep( sal_uInt32 _nSec ) + { + /// print statement in thread process must use fflush() to force display. + fflush(stdout); + + osl::Thread::wait(std::chrono::seconds(_nSec)); + } + // test read/write & send/recv data to pipe + + namespace { + + class Pipe_DataSink_Thread : public Thread + { + public: + char buf[256]; + Pipe_DataSink_Thread( ) { } + + protected: + void SAL_CALL run( ) override + { + printf("open pipe\n"); + ::osl::StreamPipe aSenderPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); // test::uniquePipeName(aTestPipeName) is a string = "TestPipe" + if ( !aSenderPipe.is() ) + { + printf("pipe open failed! \n"); + } + else + { + printf("read\n"); + sal_Int32 nChars = aSenderPipe.read( buf, m_pTestString1.getLength() + 1 ); + if ( nChars < 0 ) + { + printf("read failed! \n"); + return; + } + buf[sizeof(buf)-1] = '\0'; + printf("buffer is %s \n", buf); + printf("send\n"); + nChars = aSenderPipe.send( m_pTestString2.getStr(), m_pTestString2.getLength() + 1 ); + if ( nChars < 0 ) + { + printf("client send failed! \n"); + return; + } + } + } + + }; + + class Pipe_DataSource_Thread : public Thread + { + public: + char buf[256]; + ::osl::Pipe aListenPipe; + ::osl::StreamPipe aConnectionPipe; + Pipe_DataSource_Thread( ) + { + printf("create pipe\n"); + aListenPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); + } + virtual ~Pipe_DataSource_Thread( ) override + { + aListenPipe.close(); + } + protected: + void SAL_CALL run( ) override + { + //create pipe. + sal_Int32 nChars; + printf("listen\n"); + if ( !aListenPipe.is() ) + { + printf("pipe create failed! \n"); + } + else + { + //start server and wait for connection. + printf("accept\n"); + if ( aListenPipe.accept( aConnectionPipe ) != osl_Pipe_E_None ) + { + printf("pipe accept failed!"); + return; + } + printf("write\n"); + // write to pipe + nChars = aConnectionPipe.write( m_pTestString1.getStr(), m_pTestString1.getLength() + 1 ); + if ( nChars < 0) + { + printf("server write failed! \n"); + return; + } + printf("recv\n"); + nChars = aConnectionPipe.recv( buf, 256 ); + + if ( nChars < 0) + { + printf("server receive failed! \n"); + return; + } + buf[sizeof(buf)-1] = '\0'; + printf("received message is: %s\n", buf ); + } + } + }; + + } + + /** testing the method: read/write/send/recv and Pipe::accept + */ + class recv : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void recv_001( ) + { + //launch threads. + Pipe_DataSource_Thread myDataSourceThread; + Pipe_DataSink_Thread myDataSinkThread; + myDataSourceThread.create( ); + thread_sleep( 1 ); + myDataSinkThread.create( ); + + //wait until the thread terminate + myDataSinkThread.join( ); + myDataSourceThread.join( ); + + int nCompare1 = strcmp( myDataSinkThread.buf, m_pTestString1.getStr() ); + int nCompare2 = strcmp( myDataSourceThread.buf, m_pTestString2.getStr() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "test send/recv/write/read.", 0, nCompare1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "test send/recv/write/read.", 0, nCompare2 ); + } + //close pipe when accept + void recv_002() + { + thread_sleep( 1 ); + + Pipe_DataSource_Thread myDataSourceThread; + Pipe_DataSink_Thread myDataSinkThread; + myDataSourceThread.create( ); + thread_sleep( 1 ); + myDataSourceThread.aListenPipe.close(); + myDataSourceThread.join( ); + //no condition judgement here, if the case could finish executing within 1 or 2 seconds, it passes. + } + + CPPUNIT_TEST_SUITE( recv ); + CPPUNIT_TEST( recv_001 ); + CPPUNIT_TEST( recv_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::ctors); +//CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::assign); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::recv); + +} // namespace osl_StreamPipe + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/process/batch.bat b/sal/qa/osl/process/batch.bat new file mode 100755 index 000000000..e27f7191b --- /dev/null +++ b/sal/qa/osl/process/batch.bat @@ -0,0 +1,19 @@ +rem +rem This file is part of the LibreOffice project. +rem +rem This Source Code Form is subject to the terms of the Mozilla Public +rem License, v. 2.0. If a copy of the MPL was not distributed with this +rem file, You can obtain one at http://mozilla.org/MPL/2.0/. +rem +rem This file incorporates work covered by the following license notice: +rem +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed +rem with this work for additional information regarding copyright +rem ownership. The ASF licenses this file to you under the Apache +rem License, Version 2.0 (the "License"); you may not use this file +rem except in compliance with the License. You may obtain a copy of +rem the License at http://www.apache.org/licenses/LICENSE-2.0 . +rem +@echo off +echo "Hello world"
\ No newline at end of file diff --git a/sal/qa/osl/process/batch.sh b/sal/qa/osl/process/batch.sh new file mode 100755 index 000000000..fd3828c6a --- /dev/null +++ b/sal/qa/osl/process/batch.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "Hello world"
\ No newline at end of file diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx new file mode 100644 index 000000000..d551f471d --- /dev/null +++ b/sal/qa/osl/process/osl_Thread.cxx @@ -0,0 +1,1989 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <algorithm> +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#else +#include <unistd.h> +#include <time.h> +#endif + +// include files + +#include <sal/types.h> +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> +#include <osl/thread.hxx> +#include <osl/mutex.hxx> +#include <osl/time.h> + +#include <string.h> +#include <memory> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#define t_print printf + +using namespace osl; + +namespace { + +// Small stopwatch +class StopWatch { + TimeValue t1,t2; // Start and stoptime + +protected: + sal_Int32 m_nNanoSec; + sal_Int32 m_nSeconds; + + bool m_bIsValid; // TRUE, when started and stopped + bool m_bIsRunning; // TRUE, when started + +public: + StopWatch(); + + void start(); // Starts time + void stop(); // Stops time + + double getSeconds() const; + double getTenthSec() const; +}; + +} + +// ================================= Stop Watch ================================= + +// A small stopwatch for internal use +// (c) Lars Langhans 29.12.1996 22:10 + +StopWatch::StopWatch() + : m_nNanoSec(0) + , m_nSeconds(0) + , m_bIsValid(false) + , m_bIsRunning(false) +{ + t1.Seconds = 0; + t1.Nanosec = 0; + t2.Seconds = 0; + t2.Nanosec = 0; +} + +void StopWatch::start() +{ +// pre: % +// post: Start Timer + + m_bIsValid = false; + m_bIsRunning = true; + osl_getSystemTime( &t1 ); + t_print("# %u %u nsecs\n", static_cast<unsigned>(t1.Seconds), static_cast<unsigned>(t1.Nanosec)); + // gettimeofday(&t1, 0); +} + +void StopWatch::stop() +{ +// pre: Timer should be started +// post: Timer will stopped + + osl_getSystemTime( &t2 ); + t_print("# %u %u nsecs\n", static_cast<unsigned>(t2.Seconds), static_cast<unsigned>(t2.Nanosec)); + + if (m_bIsRunning) + { // check if started. + m_nSeconds = static_cast<sal_Int32>(t2.Seconds) - static_cast<sal_Int32>(t1.Seconds); + if ( t2.Nanosec > t1.Nanosec ) + m_nNanoSec = static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec); + else + { + m_nNanoSec = 1000000000 + static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec); + m_nSeconds -= 1; + } + t_print("# %u %u nsecs\n", static_cast<unsigned>(m_nSeconds), static_cast<unsigned>(m_nNanoSec) ); + m_bIsValid = true; + m_bIsRunning = false; + } +} + +double StopWatch::getSeconds() const +{ +// pre: valid = TRUE +// BACK: time in seconds + + double nValue = 0.0; + if (m_bIsValid) + { + nValue = double(m_nNanoSec) / 1000000000.0 + m_nSeconds; // milli micro nano + } + return nValue; +} + +double StopWatch::getTenthSec() const +{ + double nValue = 0.0; + if (m_bIsValid) + { + nValue = double(m_nNanoSec) / 100000000.0 + m_nSeconds * 10; + } + return nValue ; +} + +namespace { + +template <class T> +class ThreadSafeValue +{ + T m_nFlag; + Mutex m_aMutex; +public: + explicit ThreadSafeValue(T n = 0): m_nFlag(n) {} + T getValue() + { + //block if already acquired by another thread. + osl::MutexGuard g(m_aMutex); + return m_nFlag; + } + void incValue() + { + //only one thread operate on the flag. + osl::MutexGuard g(m_aMutex); + m_nFlag++; + } + void acquire() {m_aMutex.acquire();} + void release() {m_aMutex.release();} +}; + +} + +namespace ThreadHelper +{ + static void thread_sleep_tenth_sec(sal_Int32 _nTenthSec) + { + osl::Thread::wait(std::chrono::milliseconds(_nTenthSec * 100)); + } + + static void outputPriority(oslThreadPriority const& _aPriority) + { + // LLA: output the priority + if (_aPriority == osl_Thread_PriorityHighest) + { + t_print("Prio is High\n"); + } + else if (_aPriority == osl_Thread_PriorityAboveNormal) + { + t_print("Prio is above normal\n"); + } + else if (_aPriority == osl_Thread_PriorityNormal) + { + t_print("Prio is normal\n"); + } + else if (_aPriority == osl_Thread_PriorityBelowNormal) + { + t_print("Prio is below normal\n"); + } + else if (_aPriority == osl_Thread_PriorityLowest) + { + t_print("Prio is lowest\n"); + } + else + { + t_print("Prio is unknown\n"); + } + } +} + +namespace { + +/** Simple thread for testing Thread-create. + + Just add 1 of value 0, and after running, result is 1. + */ +class myThread : public Thread +{ + ThreadSafeValue<sal_Int32> m_aFlag; +public: + sal_Int32 getValue() { return m_aFlag.getValue(); } +protected: + /** guarded value which initialized 0 + + @see ThreadSafeValue + */ + void SAL_CALL run() override + { + while(schedule()) + { + m_aFlag.incValue(); + ThreadHelper::thread_sleep_tenth_sec(1); + } + } + +public: + + virtual void SAL_CALL suspend() override + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } + + virtual ~myThread() override + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } + +}; + +/** Thread which has a flag add 1 every second until 20 + */ +class OCountThread : public Thread +{ + ThreadSafeValue<sal_Int32> m_aFlag; +public: + OCountThread() : m_nWaitSec(0) + { + t_print("new OCountThread thread %u!\n", static_cast<unsigned>(getIdentifier())); + } + sal_Int32 getValue() { return m_aFlag.getValue(); } + + void setWait(sal_Int32 nSec) + { + m_nWaitSec = nSec; + //m_bWait = sal_True; + } + + virtual void SAL_CALL suspend() override + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } + +protected: + //sal_Bool m_bWait; + sal_Int32 m_nWaitSec; + + void SAL_CALL run() override + { + /// if the thread should terminate, schedule return false + while (m_aFlag.getValue() < 20 && schedule()) + { + m_aFlag.incValue(); + ThreadHelper::thread_sleep_tenth_sec(1); + + if (m_nWaitSec != 0) + { + TimeValue nTV; + nTV.Seconds = m_nWaitSec / 10 ; + nTV.Nanosec = ( m_nWaitSec%10 ) * 100000000 ; + wait( nTV ); + m_nWaitSec = 0; + } + } + } + void SAL_CALL onTerminated() override + { + t_print("normally terminate this thread %u!\n", static_cast<unsigned>(getIdentifier())); + } +public: + + virtual ~OCountThread() override + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } + +}; + +/** no call schedule in the run method +*/ +class ONoScheduleThread : public Thread +{ + ThreadSafeValue<sal_Int32> m_aFlag; +public: + sal_Int32 getValue() { return m_aFlag.getValue(); } + + virtual void SAL_CALL suspend() override + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } +protected: + void SAL_CALL run() override + { + while (m_aFlag.getValue() < 10) + { + m_aFlag.incValue(); + ThreadHelper::thread_sleep_tenth_sec(1); + } + } + void SAL_CALL onTerminated() override + { + t_print("normally terminate this thread %u!\n", static_cast<unsigned>(getIdentifier())); + } +public: + ONoScheduleThread() + { + t_print("new thread id %u!\n", static_cast<unsigned>(getIdentifier())); + } + virtual ~ONoScheduleThread() override + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } + +}; + + +class OAddThread : public Thread +{ + ThreadSafeValue<sal_Int32> m_aFlag; +public: + //oslThreadIdentifier m_id, m_CurId; + OAddThread(){} + sal_Int32 getValue() { return m_aFlag.getValue(); } + + virtual void SAL_CALL suspend() override + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } +protected: + void SAL_CALL run() override + { + //if the thread should terminate, schedule return false + while (schedule()) + { + m_aFlag.incValue(); + } + } + void SAL_CALL onTerminated() override + { + // t_print("normally terminate this thread %d!\n", getIdentifier()); + } +public: + + virtual ~OAddThread() override + { + if (isRunning()) + { + // t_print("error: not terminated.\n"); + } + } + +}; + +} + +namespace osl_Thread +{ + + static void resumeAndWaitThread(Thread* _pThread) + { + // This function starts a thread, wait a second and suspends the thread + // Due to the fact, that a suspend and never run thread never really exists. + + // Note: on UNX, after createSuspended, and then terminate the thread, it performs well; + // while on Windows, after createSuspended, the thread can not terminate, wait endlessly, + // so here call resume at first, then call terminate. +#ifdef _WIN32 + t_print("resumeAndWaitThread\n"); + _pThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(1); +#else + _pThread->resume(); +#endif + } + + // kill a running thread and join it, if it has terminated, do nothing + static void termAndJoinThread(Thread* _pThread) + { + _pThread->terminate(); + +// LLA: Windows feature???, a suspended thread can not terminated, so we have to weak it up +#ifdef _WIN32 + _pThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(1); +#endif + t_print("#wait for join.\n"); + _pThread->join(); + } +/** Test of the osl::Thread::create method + */ + + class create : public CppUnit::TestFixture + { + public: + /** Simple create a thread. + + Create a simple thread, it just does add 1 to value(which initialized 0), + if the thread run, the value should be 1. + */ + void create_001() + { + myThread* newthread = new myThread; + bool bRes = newthread->create(); + CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!\n", bRes); + + ThreadHelper::thread_sleep_tenth_sec(1); // wait short + bool isRunning = newthread->isRunning(); // check if thread is running + /// wait for the new thread to assure it has run + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); + /// to assure the new thread has terminated + termAndJoinThread(newthread); + delete newthread; + + t_print(" nValue = %d\n", static_cast<int>(nValue)); + t_print("isRunning = %s\n", isRunning ? "true" : "false"); + + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread", + nValue >= 1 + ); + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread", + isRunning + ); + + } + + /** only one running thread per instance, return false if create secondly + */ + void create_002() + { + myThread* newthread = new myThread; + bool res1 = newthread->create(); + bool res2 = newthread->create(); + t_print("In non pro, an assertion should occurred. This behaviour is right.\n"); + termAndJoinThread(newthread); + delete newthread; + + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread: can not create two threads per instance", + res1 + ); + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread: can not create two threads per instance", + !res2 + ); + + } + + CPPUNIT_TEST_SUITE(create); + CPPUNIT_TEST(create_001); + CPPUNIT_TEST(create_002); + CPPUNIT_TEST_SUITE_END(); + }; // class create + + /** Test of the osl::Thread::createSuspended method + */ + class createSuspended : public CppUnit::TestFixture + { + public: + /** Create a suspended thread, use the same class as create_001 + + after create, wait enough time, check the value, if it's still the initial value, pass + */ + void createSuspended_001() + { + myThread* newthread = new myThread; + bool bRes = newthread->createSuspended(); + CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!", bRes); + + ThreadHelper::thread_sleep_tenth_sec(1); + bool isRunning = newthread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); + + resumeAndWaitThread(newthread); + + termAndJoinThread(newthread); + delete newthread; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Creates a new suspended thread", + sal_Int32(0), nValue + ); + CPPUNIT_ASSERT_MESSAGE( + "Creates a new suspended thread", + isRunning + ); + } + + void createSuspended_002() + { + myThread* newthread = new myThread; + bool res1 = newthread->createSuspended(); + bool res2 = newthread->createSuspended(); + + resumeAndWaitThread(newthread); + + termAndJoinThread(newthread); + + delete newthread; + + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread: can not create two threads per instance", + res1 + ); + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread: can not create two threads per instance", + !res2 + ); + } + + CPPUNIT_TEST_SUITE(createSuspended); + CPPUNIT_TEST(createSuspended_001); + // LLA: Deadlocked!!! + CPPUNIT_TEST(createSuspended_002); + CPPUNIT_TEST_SUITE_END(); + }; // class createSuspended + + /** when the count value equal to or more than 3, suspend the thread. + */ + static void suspendCountThread(OCountThread* _pCountThread) + { + sal_Int32 nValue = 0; + while (true) + { + nValue = _pCountThread->getValue(); + if (nValue >= 3) + { + _pCountThread->suspend(); + break; + } + } + } + + /** Test of the osl::Thread::suspend method + */ + class suspend : public CppUnit::TestFixture + { + public: + /** Use a thread which has a flag added 1 every second + + ALGORITHM: + create the thread, after running special time, record value of flag, then suspend it, + wait a long time, check the flag, if it remains unchanged during suspending + */ + void suspend_001() + { + OCountThread* aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + // the thread run for some seconds, but not terminate + suspendCountThread( aCountThread ); + + // the value just after calling suspend + sal_Int32 nValue = aCountThread->getValue(); // (2) + + ThreadHelper::thread_sleep_tenth_sec(3); + + // the value after waiting 3 seconds + sal_Int32 nLaterValue = aCountThread->getValue(); // (3) + + resumeAndWaitThread(aCountThread); + termAndJoinThread(aCountThread); + delete aCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Suspend the thread", + bRes + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Suspend the thread", + nValue, nLaterValue + ); + + } + + CPPUNIT_TEST_SUITE(suspend); + CPPUNIT_TEST(suspend_001); + // LLA: Deadlocked!!! + // CPPUNIT_TEST(createSuspended_002); + CPPUNIT_TEST_SUITE_END(); + }; // class suspend + + /** Test of the osl::Thread::resume method + */ + class resume : public CppUnit::TestFixture + { + public: + /** check if the thread run samely as usual after suspend and resume + + ALGORITHM: + compare the values before and after suspend, they should be same, + then compare values before and after resume, the difference should be same as the sleep seconds number + */ + void resume_001() + { + OCountThread* pCountThread = new OCountThread(); + bool bRes = pCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + suspendCountThread(pCountThread); + + sal_Int32 nSuspendValue = pCountThread->getValue(); // (2) + // suspend for 3 seconds + ThreadHelper::thread_sleep_tenth_sec(3); + pCountThread->resume(); + + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nResumeValue = pCountThread->getValue(); + + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = pCountThread->getValue(); + + termAndJoinThread(pCountThread); + delete pCountThread; + + t_print("SuspendValue: %d\n", static_cast<int>(nSuspendValue)); + t_print("ResumeValue: %d\n", static_cast<int>(nResumeValue)); + t_print("LaterValue: %d\n", static_cast<int>(nLaterValue)); + + /* LLA: this assumption is no longer relevant: nResumeValue == nSuspendValue && */ + CPPUNIT_ASSERT_MESSAGE( + "Suspend then resume the thread", + nLaterValue >= 9 + ); + CPPUNIT_ASSERT_MESSAGE( + "Suspend then resume the thread", + nResumeValue > nSuspendValue + ); + CPPUNIT_ASSERT_MESSAGE( + "Suspend then resume the thread", + nLaterValue > nResumeValue + ); + + } + + /** Create a suspended thread then resume, check if the thread has run + */ + void resume_002() + { + myThread* newthread = new myThread; + bool bRes = newthread->createSuspended(); + CPPUNIT_ASSERT_MESSAGE ( "Can't create thread!", bRes ); + + newthread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = newthread->getValue(); + + termAndJoinThread(newthread); + delete newthread; + + t_print(" nValue = %d\n", static_cast<int>(nValue)); + + CPPUNIT_ASSERT_MESSAGE( + "Creates a suspended thread, then resume", + nValue >= 1 + ); + } + + CPPUNIT_TEST_SUITE(resume); + CPPUNIT_TEST(resume_001); + CPPUNIT_TEST(resume_002); + CPPUNIT_TEST_SUITE_END(); + }; // class resume + + /** Test of the osl::Thread::terminate method + */ + class terminate : public CppUnit::TestFixture + { + public: + /** Check after call terminate if the running thread running go on executing + + ALGORITHM: + before and after call terminate, the values should be the same + */ + void terminate_001() + { + OCountThread* aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = aCountThread->getValue(); + aCountThread->terminate(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nLaterValue = aCountThread->getValue(); + + // isRunning should be false after terminate + bool isRunning = aCountThread->isRunning(); + aCountThread->join(); + delete aCountThread; + + t_print(" nValue = %d\n", static_cast<int>(nValue)); + t_print("nLaterValue = %d\n", static_cast<int>(nLaterValue)); + + CPPUNIT_ASSERT_MESSAGE( + "Terminate the thread", + !isRunning + ); + CPPUNIT_ASSERT_MESSAGE( + "Terminate the thread", + nLaterValue >= nValue + ); + } + /** Check if a suspended thread will terminate after call terminate, different on w32 and on UNX + */ + void terminate_002() + { + OCountThread* aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + ThreadHelper::thread_sleep_tenth_sec(1); + suspendCountThread(aCountThread); + sal_Int32 nValue = aCountThread->getValue(); + + // seems a suspended thread can not be terminated on W32, while on Solaris can + resumeAndWaitThread(aCountThread); + + ThreadHelper::thread_sleep_tenth_sec(2); + + termAndJoinThread(aCountThread); + sal_Int32 nLaterValue = aCountThread->getValue(); + delete aCountThread; + + t_print(" nValue = %d\n", static_cast<int>(nValue)); + t_print("nLaterValue = %d\n", static_cast<int>(nLaterValue)); + + CPPUNIT_ASSERT_MESSAGE( + "Suspend then resume the thread", + nLaterValue > nValue ); + } + + CPPUNIT_TEST_SUITE(terminate); + CPPUNIT_TEST(terminate_001); + CPPUNIT_TEST(terminate_002); + CPPUNIT_TEST_SUITE_END(); + }; // class terminate + + /** Test of the osl::Thread::join method + */ + class join : public CppUnit::TestFixture + { + public: + /** Check after call terminate if the thread running function will not go on executing + + the next statement after join will not exec before the thread terminates + ALGORITHM: + recode system time at the beginning of the thread run, call join, then record system time again, + the difference of the two times should be equal or more than 20 seconds, the CountThread normally terminates + */ + void join_001() + { + OCountThread *aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + StopWatch aStopWatch; + aStopWatch.start(); + // TimeValue aTimeVal_befor; + // osl_getSystemTime( &aTimeVal_befor ); + //t_print("#join:the system time is %d,%d\n", pTimeVal_befor->Seconds,pTimeVal_befor->Nanosec); + + aCountThread->join(); + + //the below line will be executed after aCountThread terminate + // TimeValue aTimeVal_after; + // osl_getSystemTime( &aTimeVal_after ); + aStopWatch.stop(); + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + double nSec = aStopWatch.getSeconds(); + t_print("join_001 nSec=%f\n", nSec); + delete aCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Join the thread: after the thread terminate", + nSec >= 2 + ); + + } + /** after terminated by another thread, join exited immediately + + ALGORITHM: + terminate the thread when value>=3, call join, check the beginning time and time after join, + the difference should be 3 seconds, join costs little time + */ + void join_002() + { + OCountThread *aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + //record the time when the running begin + // TimeValue aTimeVal_befor; + // osl_getSystemTime( &aTimeVal_befor ); + StopWatch aStopWatch; + aStopWatch.start(); + + ThreadHelper::thread_sleep_tenth_sec(10); + termAndJoinThread(aCountThread); + + //the below line will be executed after aCountThread terminate + // TimeValue aTimeVal_after; + // osl_getSystemTime( &aTimeVal_after ); + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + aStopWatch.stop(); + double nSec = aStopWatch.getSeconds(); + t_print("join_002 nSec=%f\n", nSec); + + delete aCountThread; + CPPUNIT_ASSERT_MESSAGE( + "Join the thread: after thread terminate by another thread", + nSec >= 1 + ); + } + + CPPUNIT_TEST_SUITE(join); + CPPUNIT_TEST(join_001); + CPPUNIT_TEST(join_002); + CPPUNIT_TEST_SUITE_END(); + }; // class join + + /** Test of the osl::Thread::isRunning method + */ + class isRunning : public CppUnit::TestFixture + { + public: + void isRunning_001() + { + OCountThread *aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + bool bRun = aCountThread->isRunning(); + + ThreadHelper::thread_sleep_tenth_sec(2); + termAndJoinThread(aCountThread); + bool bTer = aCountThread->isRunning(); + delete aCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + bRun + ); + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + !bTer + ); + } + /** check the value of isRunning when suspending and after resume + */ + void isRunning_002() + { + OCountThread *aCountThread = new OCountThread(); + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + // sal_Bool bRunning = aCountThread->isRunning(); + // sal_Int32 nValue = 0; + suspendCountThread(aCountThread); + + bool bRunning_sup = aCountThread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(2); + aCountThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + bool bRunning_res = aCountThread->isRunning(); + termAndJoinThread(aCountThread); + bool bRunning_ter = aCountThread->isRunning(); + delete aCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + bRes && bRunning_sup ); + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + bRunning_res ); + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + !bRunning_ter ); + + } + + CPPUNIT_TEST_SUITE(isRunning); + CPPUNIT_TEST(isRunning_001); + CPPUNIT_TEST(isRunning_002); + CPPUNIT_TEST_SUITE_END(); + }; // class isRunning + + /// check osl::Thread::setPriority + class setPriority : public CppUnit::TestFixture + { + public: + // insert your test code here. + OString getPrioName(oslThreadPriority _aPriority) + { + OString sPrioStr; + switch (_aPriority) + { + case osl_Thread_PriorityHighest: + sPrioStr = "Highest"; + break; + + case osl_Thread_PriorityAboveNormal: + sPrioStr = "AboveNormal"; + break; + + case osl_Thread_PriorityNormal: + sPrioStr = "Normal"; + break; + + case osl_Thread_PriorityBelowNormal: + sPrioStr = "BelowNormal"; + break; + + case osl_Thread_PriorityLowest: + sPrioStr = "Lowest"; + break; + default: + sPrioStr = "unknown"; + } + return sPrioStr; + } + + /** check 2 threads. + + ALGORITHM: + Here the function should show, that 2 different threads, + which only increase a value, should run at the same time with same prio. + The test fails, if the difference between the two values is more than 5% + but IMHO this isn't a failure, it's only a feature of the OS. + */ + + void check2Threads(oslThreadPriority _aPriority) + { + // initial 5 threads with different priorities + OAddThread* pThread = new OAddThread(); + OAddThread* p2Thread = new OAddThread(); + + //Create them and start running at the same time + pThread->create(); + pThread->setPriority(_aPriority); + p2Thread->create(); + p2Thread->setPriority(_aPriority); + + ThreadHelper::thread_sleep_tenth_sec(5); + + pThread->terminate(); + p2Thread->terminate(); + + sal_Int32 nValueNormal = pThread->getValue(); + + sal_Int32 nValueNormal2 = p2Thread->getValue(); + + OString sPrio = getPrioName(_aPriority); + t_print("After 10 tenth seconds\n"); + + t_print("nValue in %s Prio Thread is %d\n",sPrio.getStr(), static_cast<int>(nValueNormal)); + t_print("nValue in %s Prio Thread is %d\n", sPrio.getStr(), static_cast<int>(nValueNormal2)); + + // ThreadHelper::thread_sleep_tenth_sec(1); + pThread->join(); + p2Thread->join(); + + delete pThread; + delete p2Thread; + + sal_Int32 nDelta = abs(nValueNormal - nValueNormal2); + double nQuotient = std::max(nValueNormal, nValueNormal2); + CPPUNIT_ASSERT_MESSAGE( + "Quotient is zero, which means, there exist no right values.", + nQuotient != 0 + ); + double nDeltaPercent = nDelta / nQuotient * 100; + + t_print("Delta value %d, percent %f\n", static_cast<int>(nDelta), nDeltaPercent); + + // LLA: it's not a bug if the current OS is not able to handle thread scheduling right and good. + // like Windows XP + // LLA: CPPUNIT_ASSERT_MESSAGE( + // LLA: "Run 2 normal threads, the count diff more than 5 percent.", + // LLA: nDeltaPercent <= 5 + // LLA: ); + } + + void setPriority_001_1() + { + check2Threads(osl_Thread_PriorityHighest); + } + void setPriority_001_2() + { + check2Threads(osl_Thread_PriorityAboveNormal); + } + void setPriority_001_3() + { + check2Threads(osl_Thread_PriorityNormal); + } + void setPriority_001_4() + { + check2Threads(osl_Thread_PriorityBelowNormal); + } + void setPriority_001_5() + { + check2Threads(osl_Thread_PriorityLowest); + } + + void setPriority_002() + { + // initial 5 threads with different priorities + + OAddThread aHighestThread; + OAddThread aAboveNormalThread; + OAddThread aNormalThread; + //OAddThread *aBelowNormalThread = new OAddThread(); + //OAddThread *aLowestThread = new OAddThread(); + + //Create them and start running at the same time + aHighestThread.createSuspended(); + aHighestThread.setPriority(osl_Thread_PriorityHighest); + + aAboveNormalThread.createSuspended(); + aAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); + + aNormalThread.createSuspended(); + aNormalThread.setPriority(osl_Thread_PriorityNormal); + /*aBelowNormalThread->create(); + aBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + aLowestThread->create(); + aLowestThread->setPriority(osl_Thread_PriorityLowest); + */ + + aHighestThread.resume(); + aAboveNormalThread.resume(); + aNormalThread.resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + aHighestThread.suspend(); + aAboveNormalThread.suspend(); + aNormalThread.suspend(); + + termAndJoinThread(&aNormalThread); + termAndJoinThread(&aAboveNormalThread); + termAndJoinThread(&aHighestThread); + //aBelowNormalThread->terminate(); + //aLowestThread->terminate(); + + sal_Int32 nValueHighest = aHighestThread.getValue(); + + sal_Int32 nValueAboveNormal = aAboveNormalThread.getValue(); + + sal_Int32 nValueNormal = aNormalThread.getValue(); + + t_print("After 10 tenth seconds\n"); + t_print("nValue in Highest Prio Thread is %d\n", static_cast<int>(nValueHighest)); + t_print("nValue in AboveNormal Prio Thread is %d\n", static_cast<int>(nValueAboveNormal)); + t_print("nValue in Normal Prio Thread is %d\n", static_cast<int>(nValueNormal)); + +#ifndef _WIN32 + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueHighest > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueAboveNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueNormal > 0 + ); +#endif + } + + void setPriority_003() + { + // initial 5 threads with different priorities + OAddThread pHighestThread; + OAddThread pAboveNormalThread; + OAddThread pNormalThread; + OAddThread pBelowNormalThread; + OAddThread pLowestThread; + + //Create them and start running at the same time + pHighestThread.createSuspended(); + pHighestThread.setPriority(osl_Thread_PriorityHighest); + + pAboveNormalThread.createSuspended(); + pAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread.createSuspended(); + pNormalThread.setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread.createSuspended(); + pBelowNormalThread.setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread.createSuspended(); + pLowestThread.setPriority(osl_Thread_PriorityLowest); + + pHighestThread.resume(); + pAboveNormalThread.resume(); + pNormalThread.resume(); + pBelowNormalThread.resume(); + pLowestThread.resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + pHighestThread.suspend(); + pAboveNormalThread.suspend(); + pNormalThread.suspend(); + pBelowNormalThread.suspend(); + pLowestThread.suspend(); + + termAndJoinThread(&pHighestThread); + termAndJoinThread(&pAboveNormalThread); + termAndJoinThread(&pNormalThread); + termAndJoinThread(&pBelowNormalThread); + termAndJoinThread(&pLowestThread); + + sal_Int32 nValueHighest = pHighestThread.getValue(); + + sal_Int32 nValueAboveNormal = pAboveNormalThread.getValue(); + + sal_Int32 nValueNormal = pNormalThread.getValue(); + + sal_Int32 nValueBelowNormal = pBelowNormalThread.getValue(); + + sal_Int32 nValueLowest = pLowestThread.getValue(); + + t_print("After 10 tenth seconds\n"); + t_print("nValue in Highest Prio Thread is %d\n", static_cast<int>(nValueHighest)); + t_print("nValue in AboveNormal Prio Thread is %d\n", static_cast<int>(nValueAboveNormal)); + t_print("nValue in Normal Prio Thread is %d\n", static_cast<int>(nValueNormal)); + t_print("nValue in BelowNormal Prio Thread is %d\n", static_cast<int>(nValueBelowNormal)); + t_print("nValue in Lowest Prio Thread is %d\n", static_cast<int>(nValueLowest)); + +#ifndef _WIN32 + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueBelowNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueLowest > 0 + ); +#endif + } + + void setPriority_004() + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + OAddThread pAboveNormalThread; + OAddThread pNormalThread; + OAddThread pBelowNormalThread; + OAddThread pLowestThread; + + //Create them and start running at the same time + // pHighestThread->createSuspended(); + // pHighestThread->setPriority(osl_Thread_PriorityHighest); + + pAboveNormalThread.createSuspended(); + pAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread.createSuspended(); + pNormalThread.setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread.createSuspended(); + pBelowNormalThread.setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread.createSuspended(); + pLowestThread.setPriority(osl_Thread_PriorityLowest); + + // pHighestThread->resume(); + pAboveNormalThread.resume(); + pNormalThread.resume(); + pBelowNormalThread.resume(); + pLowestThread.resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + // pHighestThread->suspend(); + pAboveNormalThread.suspend(); + pNormalThread.suspend(); + pBelowNormalThread.suspend(); + pLowestThread.suspend(); + + // termAndJoinThread(pHighestThread); + termAndJoinThread(&pAboveNormalThread); + termAndJoinThread(&pNormalThread); + termAndJoinThread(&pBelowNormalThread); + termAndJoinThread(&pLowestThread); + + // sal_Int32 nValueHighest = 0; + // nValueHighest = pHighestThread->getValue(); + + sal_Int32 nValueAboveNormal = pAboveNormalThread.getValue(); + + sal_Int32 nValueNormal = pNormalThread.getValue(); + + sal_Int32 nValueBelowNormal = pBelowNormalThread.getValue(); + + sal_Int32 nValueLowest = pLowestThread.getValue(); + + t_print("After 5 tenth seconds\n"); + t_print("nValue in AboveNormal Prio Thread is %d\n", static_cast<int>(nValueAboveNormal)); + t_print("nValue in Normal Prio Thread is %d\n", static_cast<int>(nValueNormal)); + t_print("nValue in BelowNormal Prio Thread is %d\n", static_cast<int>(nValueBelowNormal)); + t_print("nValue in Lowest Prio Thread is %d\n", static_cast<int>(nValueLowest)); + + // delete pHighestThread; + +#ifndef _WIN32 + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + /* nValueHighest > 0 && */ + nValueAboveNormal > 0 && + nValueNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueBelowNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueLowest > 0 + ); +#endif + } + void setPriority_005() + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + // OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread pNormalThread; + OAddThread pBelowNormalThread; + OAddThread pLowestThread; + + //Create them and start running at the same time + // pHighestThread->createSuspended(); + // pHighestThread->setPriority(osl_Thread_PriorityHighest); + + // pAboveNormalThread->createSuspended(); + // pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread.createSuspended(); + pNormalThread.setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread.createSuspended(); + pBelowNormalThread.setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread.createSuspended(); + pLowestThread.setPriority(osl_Thread_PriorityLowest); + + // pHighestThread->resume(); + // pAboveNormalThread->resume(); + pNormalThread.resume(); + pBelowNormalThread.resume(); + pLowestThread.resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + // pHighestThread->suspend(); + // pAboveNormalThread->suspend(); + pNormalThread.suspend(); + pBelowNormalThread.suspend(); + pLowestThread.suspend(); + + // termAndJoinThread(pHighestThread); + // termAndJoinThread(pAboveNormalThread); + termAndJoinThread(&pNormalThread); + termAndJoinThread(&pBelowNormalThread); + termAndJoinThread(&pLowestThread); + + // sal_Int32 nValueHighest = 0; + // nValueHighest = pHighestThread->getValue(); + + // sal_Int32 nValueAboveNormal = 0; + // nValueAboveNormal = pAboveNormalThread->getValue(); + + sal_Int32 nValueNormal = pNormalThread.getValue(); + + sal_Int32 nValueBelowNormal = pBelowNormalThread.getValue(); + + sal_Int32 nValueLowest = pLowestThread.getValue(); + + t_print("After 5 tenth seconds\n"); + t_print("nValue in Normal Prio Thread is %d\n", static_cast<int>(nValueNormal)); + t_print("nValue in BelowNormal Prio Thread is %d\n", static_cast<int>(nValueBelowNormal)); + t_print("nValue in Lowest Prio Thread is %d\n", static_cast<int>(nValueLowest)); + +#ifndef _WIN32 + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + /* nValueHighest > 0 && */ + /* nValueAboveNormal > 0 && */ + nValueNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueBelowNormal > 0 + ); + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueLowest > 0 + ); +#endif + } + + CPPUNIT_TEST_SUITE(setPriority); +#ifndef __sun + CPPUNIT_TEST(setPriority_002); + CPPUNIT_TEST(setPriority_003); + CPPUNIT_TEST(setPriority_004); + CPPUNIT_TEST(setPriority_005); +#endif + CPPUNIT_TEST(setPriority_001_1); + CPPUNIT_TEST(setPriority_001_2); + CPPUNIT_TEST(setPriority_001_3); + CPPUNIT_TEST(setPriority_001_4); + CPPUNIT_TEST(setPriority_001_5); + CPPUNIT_TEST_SUITE_END(); + }; // class setPriority + + /** Test of the osl::Thread::getPriority method + */ + class getPriority : public CppUnit::TestFixture + { + public: + // insert your test code here. + void getPriority_001() + { + OAddThread *pHighestThread = new OAddThread(); + + //Create them and start running at the same time + pHighestThread->create(); + pHighestThread->setPriority(osl_Thread_PriorityHighest); + + oslThreadPriority aPriority = pHighestThread->getPriority(); + termAndJoinThread(pHighestThread); + delete pHighestThread; + + ThreadHelper::outputPriority(aPriority); + +// LLA: Priority settings may not work within some OS versions. +#if defined(_WIN32) || defined(__sun) + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "getPriority", + osl_Thread_PriorityHighest, aPriority + ); +#else +// LLA: Linux +// NO_PTHREAD_PRIORITY ??? + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "getPriority", + osl_Thread_PriorityNormal, aPriority + ); +#endif + } + + CPPUNIT_TEST_SUITE(getPriority); + CPPUNIT_TEST(getPriority_001); + CPPUNIT_TEST_SUITE_END(); + }; // class getPriority + + class getIdentifier : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + + void getIdentifier_001() + { + // insert your test code here. + } + + CPPUNIT_TEST_SUITE(getIdentifier); + CPPUNIT_TEST(getIdentifier_001); + CPPUNIT_TEST_SUITE_END(); + }; // class getIdentifier + + /** Test of the osl::Thread::getCurrentIdentifier method + */ + class getCurrentIdentifier : public CppUnit::TestFixture + { + public: + void getCurrentIdentifier_001() + { + oslThreadIdentifier oId; + OCountThread* pCountThread = new OCountThread; + pCountThread->create(); + pCountThread->setWait(3); + oId = Thread::getCurrentIdentifier(); + oslThreadIdentifier oIdChild = pCountThread->getIdentifier(); + termAndJoinThread(pCountThread); + delete pCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Get the identifier for the current active thread.", + oId != oIdChild); + } + + CPPUNIT_TEST_SUITE(getCurrentIdentifier); + CPPUNIT_TEST(getCurrentIdentifier_001); + CPPUNIT_TEST_SUITE_END(); + }; // class getCurrentIdentifier + + /** Test of the osl::Thread::wait method + */ + class waittest : public CppUnit::TestFixture + { + public: + /** call wait in the run method + + ALGORITHM: + tested thread wait nWaitSec seconds, main thread sleep (2) seconds, + then terminate the tested thread, due to the fact that the thread do a sleep(1) + wait(5) + it's finish after 6 seconds. + */ + void wait_001() + { + OCountThread *aCountThread = new OCountThread(); + sal_Int32 nWaitSec = 5; + aCountThread->setWait(nWaitSec); + // thread runs at least 5 seconds. + bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + //record the time when the running begin + StopWatch aStopWatch; + aStopWatch.start(); + + // wait a little bit, to let the thread the time, to start + ThreadHelper::thread_sleep_tenth_sec( 4 ); + + // if wait works, + // this function returns, after 4 sec. later + termAndJoinThread(aCountThread); + + // value should be one. + sal_Int32 nValue = aCountThread->getValue(); + + aStopWatch.stop(); + + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + double nTenthSec = aStopWatch.getTenthSec(); + double nSec = aStopWatch.getSeconds(); + delete aCountThread; + t_print("nTenthSec = %f \n", nTenthSec); + t_print("nSec = %f \n", nSec); + t_print("nValue = %d \n", static_cast<int>(nValue)); + + CPPUNIT_ASSERT_MESSAGE( + "Wait: Blocks the calling thread for the given number of time.", + nTenthSec >= 5 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Wait: Blocks the calling thread for the given number of time.", + sal_Int32(1), nValue + ); + + } + + CPPUNIT_TEST_SUITE(waittest); + CPPUNIT_TEST(wait_001); + CPPUNIT_TEST_SUITE_END(); + }; // class waittest + + /** osl::Thread::yield method: can not design good test scenario to test up to now + */ + class yield : public CppUnit::TestFixture + { + public: + void yield_001() + { + // insert your test code here. + } + + CPPUNIT_TEST_SUITE(yield); + CPPUNIT_TEST(yield_001); + CPPUNIT_TEST_SUITE_END(); + }; // class yield + + /** Test of the osl::Thread::schedule method + */ + class schedule : public CppUnit::TestFixture + { + public: + + /** The requested thread will get terminate the next time schedule() is called. + + Note: on UNX, if call suspend thread is not the to be suspended thread, the to be + suspended thread will get suspended the next time schedule() is called, + while on w32, it's nothing with schedule. + + check if suspend and terminate work well via schedule + */ + void schedule_001() + { + OAddThread* aThread = new OAddThread(); + bool bRes = aThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + ThreadHelper::thread_sleep_tenth_sec(2); + aThread->suspend(); + ThreadHelper::thread_sleep_tenth_sec(1); + sal_Int32 nValue = aThread->getValue(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = aThread->getValue(); + // resumeAndWaitThread(aThread); + t_print(" value = %d\n", static_cast<int>(nValue)); + t_print("later value = %d\n", static_cast<int>(nLaterValue)); + // if value and latervalue not equal, then the thread would not suspended + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Schedule: suspend works.", + nValue, nLaterValue + ); + + aThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + + aThread->terminate(); + sal_Int32 nValue_term = aThread->getValue(); + + aThread->join(); + sal_Int32 nValue_join = aThread->getValue(); + + t_print("value after term = %d\n", static_cast<int>(nValue_term)); + t_print("value after join = %d\n", static_cast<int>(nValue_join)); + + // nValue_term and nValue_join should be the same + // but should be differ from nValue + + delete aThread; + //check if thread really terminate after call terminate, if join immediately return + CPPUNIT_ASSERT_MESSAGE( + "Schedule: Returns False if the thread should terminate.", + nValue_join - nValue_term <= 1 + ); + CPPUNIT_ASSERT_MESSAGE( + "Schedule: Returns False if the thread should terminate.", + nValue_join - nValue_term >= 0 + ); + + } + + /** design a thread that has not call schedule in the workfunction--run method + */ + void schedule_002() + { + ONoScheduleThread aThread; // this thread runs 10 sec. (no schedule() used) + bool bRes = aThread.create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes ); + + ThreadHelper::thread_sleep_tenth_sec(2); + aThread.suspend(); + sal_Int32 nValue = aThread.getValue(); + + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = aThread.getValue(); + ThreadHelper::thread_sleep_tenth_sec(5); + + resumeAndWaitThread(&aThread); + + t_print(" value = %d\n", static_cast<int>(nValue)); + t_print("later value = %d\n", static_cast<int>(nLaterValue)); + + //On windows, suspend works, so the values are same +#ifdef _WIN32 + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Schedule: don't schedule in thread run method, suspend works.", + nValue, nLaterValue + ); +#endif + + //On UNX, suspend does not work, so the difference of the values equals to sleep seconds number +#ifdef UNX + aThread.resume(); + CPPUNIT_ASSERT_MESSAGE( + "Schedule: don't schedule in thread run method, suspend does not work too.", + nLaterValue > nValue + ); +#endif + + // terminate will not work if no schedule in thread's work function + termAndJoinThread(&aThread); + sal_Int32 nValue_term = aThread.getValue(); + + t_print(" value term = %d\n", static_cast<int>(nValue_term)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Schedule: don't schedule in thread run method, terminate failed.", + static_cast<sal_Int32>(10), nValue_term + ); + } + + CPPUNIT_TEST_SUITE(schedule); + CPPUNIT_TEST(schedule_001); + CPPUNIT_TEST(schedule_002); + CPPUNIT_TEST_SUITE_END(); + }; // class schedule + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::create, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::createSuspended, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::suspend, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::resume, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::terminate, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::join, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::isRunning, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::setPriority, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::getPriority, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::getIdentifier, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::getCurrentIdentifier, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::waittest, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::yield, "osl_Thread"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Thread::schedule, "osl_Thread"); +} // namespace osl_Thread + +// destroy function when the binding thread terminate +static void destroyCallback(void * data) +{ + delete[] static_cast<char *>(data); +} + +static ThreadData myThreadData(destroyCallback); + +namespace { + +class myKeyThread : public Thread +{ +public: + // a public char member for test result checking + char m_Char_Test; + // for pass thread-special data to thread + explicit myKeyThread(const char cData) + : m_Char_Test(0) + { + m_nData = cData; + } +private: + char m_nData; + + void SAL_CALL run() override + { + char * pc = new char[2]; +// strcpy(pc, &m_nData); + memcpy(pc, &m_nData, 1); + pc[1] = '\0'; + + myThreadData.setData(pc); + char* pData = static_cast<char*>(myThreadData.getData()); + m_Char_Test = *pData; + // wait for long time to check the data value in main thread + ThreadHelper::thread_sleep_tenth_sec(3); + } +public: + virtual ~myKeyThread() override + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } +}; + +} + +static ThreadData idData; + +namespace { + +class idThread: public Thread +{ +public: + oslThreadIdentifier m_Id; +private: + void SAL_CALL run() override + { + std::unique_ptr<oslThreadIdentifier> pId( new oslThreadIdentifier ); + *pId = getIdentifier(); + idData.setData(pId.get()); + oslThreadIdentifier* pIdData = static_cast<oslThreadIdentifier*>(idData.getData()); + //t_print("Thread %d has Data %d\n", getIdentifier(), *pIdData); + m_Id = *pIdData; + } + +public: + virtual ~idThread() override + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } +}; + +} + +namespace osl_ThreadData +{ + + class ctors : public CppUnit::TestFixture + { + public: + + // insert your test code here. + void ctor_001() + { + + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST_SUITE_END(); + }; // class ctors + + class setData : public CppUnit::TestFixture + { + public: + + /** the same instance of the class can have different values in different threads + */ + void setData_001() + { + idThread aThread1; + aThread1.create(); + idThread aThread2; + aThread2.create(); + + aThread1.join(); + aThread2.join(); + + oslThreadIdentifier aThreadId1 = aThread1.getIdentifier(); + oslThreadIdentifier aThreadId2 = aThread2.getIdentifier(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + aThread1.m_Id, aThreadId1 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + aThread2.m_Id, aThreadId2 + ); + + } + + void setData_002() + { + // at first, set the data a value + char* pc = new char[2]; + char nData = 'm'; + pc[0] = nData; + pc[1] = '\0'; + + myThreadData.setData(pc); + + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); + // aThread1 and aThread2 should have not terminated yet, check current data, not 'a' 'b' + char* pChar = static_cast<char*>(myThreadData.getData()); + char aChar = *pChar; + + aThread1.join(); + aThread2.join(); + + // the saved thread data of aThread1 & aThread2, different + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'a', cData1 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'b', cData2 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'm', aChar + ); + + } + /** setData the second time, and then getData + */ + void setData_003() + { + // at first, set the data a value + char* pc = new char[2]; + char nData = 'm'; + memcpy(pc, &nData, 1); + pc[1] = '\0'; + myThreadData.setData(pc); + + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); + // aThread1 and aThread2 should have not terminated yet + // setData the second time + char* pc2 = new char[2]; + nData = 'o'; + memcpy(pc2, &nData, 1); + pc2[1] = '\0'; + + myThreadData.setData(pc2); + char* pChar = static_cast<char*>(myThreadData.getData()); + char aChar = *pChar; + + aThread1.join(); + aThread2.join(); + + // the saved thread data of aThread1 & aThread2, different + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'a', cData1 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'b', cData2 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'o', aChar + ); + } + + CPPUNIT_TEST_SUITE(setData); + CPPUNIT_TEST(setData_001); + CPPUNIT_TEST(setData_002); + CPPUNIT_TEST(setData_003); + CPPUNIT_TEST_SUITE_END(); + }; // class setData + + class getData : public CppUnit::TestFixture + { + public: + + // After setData in child threads, get Data in the main thread, should be independent + void getData_001() + { + char* pc = new char[2]; + strcpy(pc, "i"); + myThreadData.setData(pc); + + myKeyThread aThread1('c'); + aThread1.create(); + myKeyThread aThread2('d'); + aThread2.create(); + + aThread1.join(); + aThread2.join(); + + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; + + char* pChar = static_cast<char*>(myThreadData.getData()); + char aChar = *pChar; + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'c', cData1 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'd', cData2 + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'i', aChar + ); + } + + // setData then change the value in the address data pointer points, + // and then getData, should get the new value + void getData_002() + { + char* pc = new char[2]; + char nData = 'i'; + memcpy(pc, &nData, 1); + pc[1] = '\0'; + + myThreadData.setData(pc); + + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); + + // change the value which pc points + char nData2 = 'j'; + memcpy(pc, &nData2, 1); + pc[1] = '\0'; + + void* pChar = myThreadData.getData(); + char aChar = *static_cast<char*>(pChar); + + aThread1.join(); + aThread2.join(); + + char cData1 = aThread1.m_Char_Test; + char cData2 = aThread2.m_Char_Test; + + CPPUNIT_ASSERT_MESSAGE( + "ThreadData setData: ", + cData1 == 'a' && cData2 == 'b' + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "ThreadData setData: ", + 'j', aChar + ); + + } + + CPPUNIT_TEST_SUITE(getData); + CPPUNIT_TEST(getData_001); + CPPUNIT_TEST(getData_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getData + + CPPUNIT_TEST_SUITE_REGISTRATION(osl_ThreadData::ctors); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_ThreadData::setData); + CPPUNIT_TEST_SUITE_REGISTRATION(osl_ThreadData::getData); +} // namespace osl_ThreadData + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/process/osl_Thread.xsce b/sal/qa/osl/process/osl_Thread.xsce new file mode 100644 index 000000000..11d0c5da1 --- /dev/null +++ b/sal/qa/osl/process/osl_Thread.xsce @@ -0,0 +1,18 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +osl_Thread.setPriority.setPriority_001_1 unxsols4 diff --git a/sal/qa/osl/process/osl_process.cxx b/sal/qa/osl/process/osl_process.cxx new file mode 100644 index 000000000..4555a0d83 --- /dev/null +++ b/sal/qa/osl/process/osl_process.cxx @@ -0,0 +1,448 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef IOS +#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_osl_process +#endif + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <osl/process.h> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <rtl/ustring.hxx> +#include <signal.h> + +#include <stdio.h> +#include <stdlib.h> +#include <osl/module.hxx> +#include <sal/macros.h> + +#if defined HAVE_VALGRIND_HEADERS +#include <valgrind/valgrind.h> +#elif !defined _WIN32 +#define RUNNING_ON_VALGRIND false +#endif + +#if !defined(_WIN32) // Windows +#include <unistd.h> +#endif + +#include <iostream> +#include <fstream> +#include <vector> +#include <algorithm> +#include <iterator> +#include <string> + +#ifdef UNX +#if defined( MACOSX ) +# include <crt_externs.h> +# define environ (*_NSGetEnviron()) +# else + extern char** environ; +# endif +#endif + +using namespace osl; + +/** get binary Path. +*/ +static OUString getExecutablePath() +{ + OUString dirPath; + osl::Module::getUrlFromAddress( + reinterpret_cast<oslGenericFunction>(&getExecutablePath), dirPath); + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') ); + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1) + + "Executable"; + return dirPath; +} + +#if !defined _WIN32 + +namespace { + +class exclude +{ +public: + + explicit exclude(const std::vector<OString>& exclude_list) + { + for (auto& exclude_list_item : exclude_list) + exclude_list_.push_back(env_var_name(exclude_list_item)); + } + + bool operator() (const OString& env_var) const + { + return (exclude_list_.end() != + std::find( + exclude_list_.begin(), + exclude_list_.end(), + env_var_name(env_var))); + } + +private: + + // extract the name from an environment variable + // that is given in the form "NAME=VALUE" + static OString env_var_name(const OString& env_var) + { + sal_Int32 pos_equal_sign = + env_var.indexOf('='); + + if (pos_equal_sign != -1) + return env_var.copy(0, pos_equal_sign); + + return OString(); + } + +private: + std::vector<OString> exclude_list_; +}; + + void tidy_container(std::vector<OString> &env_container) + { + //sort them because there are no guarantees to ordering + std::sort(env_container.begin(), env_container.end()); + if (RUNNING_ON_VALGRIND) + { + env_container.erase( + std::remove_if( + env_container.begin(), env_container.end(), + [](OString const & s) { + return s.startsWith("LD_PRELOAD=") + || s.startsWith("VALGRIND_LIB="); }), + env_container.end()); + } + } +} + + static void read_parent_environment(std::vector<OString>* env_container) + { + for (int i = 0; environ[i] != nullptr; i++) + env_container->push_back(OString(environ[i])); + tidy_container(*env_container); + } + +#endif + +class Test_osl_executeProcess : public CppUnit::TestFixture +{ + const OUString env_param_; + + OUString temp_file_url_; + OUString temp_file_path_; + rtl_uString* parameters_[2]; + static const int parameters_count_ = 2; + OUString suCWD; + OUString suExecutableFileURL; + +public: + + // ctor + Test_osl_executeProcess() : + env_param_(OUString("-env")), suCWD(getExecutablePath()) + { + parameters_[0] = env_param_.pData; + +#if defined(_WIN32) + suExecutableFileURL = suCWD + "/" "osl_process_child.exe"; +#else + suExecutableFileURL = suCWD + "/" "osl_process_child"; +#endif + } + + virtual void setUp() override + { + temp_file_path_ = create_temp_file(temp_file_url_); + parameters_[1] = temp_file_path_.pData; + } + + virtual void tearDown() override + { + osl::File::remove(temp_file_url_); + } + + OUString create_temp_file(OUString &temp_file_url) + { + FileBase::RC rc = FileBase::createTempFile(nullptr, nullptr, &temp_file_url); + CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile failed", FileBase::E_None, rc); + + OUString temp_file_path; + rc = FileBase::getSystemPathFromFileURL(temp_file_url, temp_file_path); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getSystemPathFromFileURL failed", FileBase::E_None, rc); + + return temp_file_path; + } + +#if !defined _WIN32 + + void read_child_environment(std::vector<OString>* env_container) + { + OString temp_file_name = OUStringToOString(OUString( + parameters_[1]), osl_getThreadTextEncoding()); + std::ifstream file(temp_file_name.getStr()); + + CPPUNIT_ASSERT_MESSAGE + ( + "I/O error, cannot open child environment file", + file.is_open() + ); + + std::string line; + line.reserve(1024); + while (std::getline(file, line, '\0')) + env_container->push_back(OString(line.c_str())); + tidy_container(*env_container); + } + + // environment of the child process that was + // started. The child process writes his + // environment into a file + void compare_environments() + { + std::vector<OString> parent_env; + read_parent_environment(&parent_env); + + std::vector<OString> child_env; + read_child_environment(&child_env); + + OString msg( + OString::number(parent_env.size()) + "/" + + OString::number(child_env.size())); + auto min = std::min(parent_env.size(), child_env.size()); + for (decltype(min) i = 0; i != min; ++i) { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + msg.getStr(), parent_env[i], child_env[i]); + } + if (parent_env.size() != child_env.size()) { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + (parent_env.size() >= child_env.size() + ? parent_env.back() : child_env.back()).getStr(), + parent_env.size(), child_env.size()); + } + } + + // compare the equal environment parts and the + // different part of the child environment + bool compare_merged_environments(const std::vector<OString>& different_env_vars) + { + std::vector<OString> parent_env; + read_parent_environment(&parent_env); + + for (auto& env : parent_env) + std::cout << "initially parent env: " << env << "\n"; + + //remove the environment variables that we have changed + //in the child environment from the read parent environment + parent_env.erase( + std::remove_if(parent_env.begin(), parent_env.end(), exclude(different_env_vars)), + parent_env.end()); + + for (auto& env : parent_env) + std::cout << "stripped parent env: " << env << "\n"; + + //read the child environment and exclude the variables that + //are different + std::vector<OString> child_env; + read_child_environment(&child_env); + + for (auto& env : child_env) + std::cout << "initial child env: " << env << "\n"; + //partition the child environment into the variables that + //are different to the parent environment (they come first) + //and the variables that should be equal between parent + //and child environment + auto iter_logical_end = + std::stable_partition(child_env.begin(), child_env.end(), exclude(different_env_vars)); + + std::vector<OString> different_child_env_vars(child_env.begin(), iter_logical_end); + child_env.erase(child_env.begin(), iter_logical_end); + + for (auto& env : child_env) + std::cout << "stripped child env: " << env << "\n"; + + bool common_env_size_equals = (parent_env.size() == child_env.size()); + bool common_env_content_equals = std::equal(child_env.begin(), child_env.end(), parent_env.begin()); + + for (auto& env_var : different_env_vars) + std::cout << "different should be: " << env_var << "\n"; + + for (auto& env_var : different_child_env_vars) + std::cout << "different are: " << env_var << "\n"; + + bool different_env_size_equals = (different_child_env_vars.size() == different_env_vars.size()); + bool different_env_content_equals = + std::equal(different_env_vars.begin(), different_env_vars.end(), different_child_env_vars.begin()); + + return (common_env_size_equals && common_env_content_equals && + different_env_size_equals && different_env_content_equals); + } + + // test that parent and child process have the + // same environment when osl_executeProcess will + // be called without setting new environment + // variables + void osl_execProc_parent_equals_child_environment() + { + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + nullptr, + suCWD.pData, + nullptr, + 0, + &process); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createProcess failed", + osl_Process_E_None, osl_error + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None, osl_error + ); + + osl_freeProcessHandle(process); + + compare_environments(); + } + + #define ENV1 "PAT=a:\\" + #define ENV2 "PATHb=b:\\" + #define ENV3 "Patha=c:\\" + #define ENV4 "Patha=d:\\" + + void osl_execProc_merged_child_environment() + { + rtl_uString* child_env[4]; + OUString env1(ENV1); + OUString env2(ENV2); + OUString env3(ENV3); + OUString env4(ENV4); + + child_env[0] = env1.pData; + child_env[1] = env2.pData; + child_env[2] = env3.pData; + child_env[3] = env4.pData; + + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + nullptr, + suCWD.pData, + child_env, + SAL_N_ELEMENTS(child_env), + &process); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createProcess failed", + osl_Process_E_None, osl_error + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None, osl_error + ); + + osl_freeProcessHandle(process); + + std::vector<OString> different_child_env_vars; + different_child_env_vars.push_back(ENV1); + different_child_env_vars.push_back(ENV2); + different_child_env_vars.push_back(ENV4); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_execProc_merged_child_environment", + compare_merged_environments(different_child_env_vars) + ); + } + +#endif + + void osl_execProc_test_batch() + { + oslProcess process; +#if defined(_WIN32) + OUString suBatch = suCWD + "/batch.bat"; +#else + OUString suBatch = suCWD + "/batch.sh"; +#endif + oslProcessError osl_error = osl_executeProcess( + suBatch.pData, + nullptr, + 0, + osl_Process_NORMAL, + nullptr, + suCWD.pData, + nullptr, + 0, + &process); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createProcess failed", + osl_Process_E_None, osl_error + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None, osl_error + ); + + osl_freeProcessHandle(process); + } + + CPPUNIT_TEST_SUITE(Test_osl_executeProcess); + //TODO: Repair these (at least under Windows) +#if !defined(_WIN32) + CPPUNIT_TEST(osl_execProc_parent_equals_child_environment); + CPPUNIT_TEST(osl_execProc_merged_child_environment); +#endif + CPPUNIT_TEST(osl_execProc_test_batch); + ///TODO: Repair test (or tested function ;-) - test fails. + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Test_osl_executeProcess); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/process/osl_process_child.cxx b/sal/qa/osl/process/osl_process_child.cxx new file mode 100644 index 000000000..17f749bc2 --- /dev/null +++ b/sal/qa/osl/process/osl_process_child.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#if defined(_WIN32) // Windows +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#else +# include <unistd.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <fstream> +#include <string.h> + + +#ifdef UNX +#if defined( MACOSX ) +# include <crt_externs.h> +# define environ (*_NSGetEnviron()) +# else + extern char** environ; +# endif +#endif + +#ifdef _WIN32 +# define SLEEP(t) (Sleep((t)*1000)) +#else +# define SLEEP(t) (sleep((t))) +#endif + +static void wait_for_seconds(char* time) +{ + SLEEP(atoi(time)); +} + +#ifdef _WIN32 + +static void w_to_a(LPCWSTR strW, LPSTR strA, DWORD size) +{ + WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, nullptr, nullptr); +} + + static void dump_env(char* file_path) + { + LPWSTR env = GetEnvironmentStringsW(); + LPWSTR p = env; + + std::ofstream file(file_path); + + char buffer[32767]; + while (size_t l = wcslen(p)) + { + w_to_a(p, buffer, sizeof(buffer)); + file << buffer << '\0'; + p += l + 1; + } + FreeEnvironmentStringsW(env); + } +#else + static void dump_env(char* file_path) + { + std::ofstream file(file_path); + for (int i = 0; environ[i] != nullptr; ++i) + file << environ[i] << '\0'; + } +#endif + +int main(int argc, char* argv[]) +{ + if (argc > 2) + { + if (strcmp("-join", argv[1]) == 0) + { + // coverity[tainted_data] - this is a build-time only test tool + wait_for_seconds(argv[2]); + } + else if (strcmp("-env", argv[1]) == 0) + dump_env(argv[2]); + } + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/profile/osl_old_testprofile.cxx b/sal/qa/osl/profile/osl_old_testprofile.cxx new file mode 100644 index 000000000..d1556bb15 --- /dev/null +++ b/sal/qa/osl/profile/osl_old_testprofile.cxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <osl/profile.h> +#include <rtl/bootstrap.hxx> + +namespace osl_Profile +{ + class oldtests : public CppUnit::TestFixture + { + public: + void test_profile(); + + CPPUNIT_TEST_SUITE( oldtests ); + CPPUNIT_TEST( test_profile ); + CPPUNIT_TEST_SUITE_END( ); + }; + +void oldtests::test_profile() +{ + OUString baseUrl; + CPPUNIT_ASSERT(rtl::Bootstrap::get("UserInstallation", baseUrl)); + + // successful write + oslProfile hProfile = osl_openProfile( OUString(baseUrl + "/soffice.ini").pData, osl_Profile_WRITELOCK ); + CPPUNIT_ASSERT(hProfile != nullptr); + CPPUNIT_ASSERT_MESSAGE( + "cannot write into init file", + osl_writeProfileBool( hProfile, "testsection", "testbool", true )); + CPPUNIT_ASSERT(osl_closeProfile( hProfile )); + + // unsuccessful open + CPPUNIT_ASSERT_EQUAL(oslProfile(nullptr), osl_openProfile( OUString(baseUrl + "/not_existing_path/soffice.ini").pData, osl_Profile_WRITELOCK )); +} + +} // namespace osl_Profile + +CPPUNIT_TEST_SUITE_REGISTRATION( osl_Profile::oldtests ); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/security/TODO.h b/sal/qa/osl/security/TODO.h new file mode 100644 index 000000000..082c54633 --- /dev/null +++ b/sal/qa/osl/security/TODO.h @@ -0,0 +1,8 @@ +#include "sal/types.h" +#define T1(x) do { x; } while (0) +#define T2(x) do { x; } while (sal_False) +#define T3(x) do { x; } while (false) +#define T4(x, y) do { x; } while (y) +#define T5(x) T4(x, 0) +#define T6(x) T4(x, sal_False) +#define T7(x) T4(x, false) diff --git a/sal/qa/osl/security/osl_Security.cxx b/sal/qa/osl/security/osl_Security.cxx new file mode 100644 index 000000000..f37187480 --- /dev/null +++ b/sal/qa/osl/security/osl_Security.cxx @@ -0,0 +1,627 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <algorithm> +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#include <sddl.h> +#undef min +#endif +#include "osl_Security_Const.h" +#include <osl/thread.h> +#include <rtl/process.h> +#include <rtl/strbuf.hxx> +#include <sal/log.hxx> +#include <o3tl/char16_t2wchar_t.hxx> + +using namespace osl; +using namespace rtl; + +/** print a UNICODE String. +*/ +static void printUString( const OUString & str ) +{ + //t_print("#printUString_u# " ); + OString aString = OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +// test code start here + +namespace osl_Security +{ + + /** testing the method: + Security() + */ + class ctors : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void ctors_001( ) + { + ::osl::Security aSec; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create a security its handle should not be NULL.", + aSec.getHandle( ) != nullptr ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class ctors + + /** testing the methods: + inline sal_Bool SAL_CALL logonUser(const OUString& strName, + const OUString& strPasswd); + inline sal_Bool SAL_CALL logonUser(const OUString & strName, + const OUString & strPasswd, + const OUString & strFileServer); + */ + class logonUser : public CppUnit::TestFixture + { + public: + bool bRes; + + void logonUser_user_pwd( ) + { + ::osl::Security aSec; + bRes = aSec.logonUser( aLogonUser, aLogonPasswd ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: check logon user through forwarded user name, pwd, passed in (UNX), failed in (W32).", + bRes ); + } + + void logonUser_user_pwd_server( ) + { + ::osl::Security aSec; + bRes = aSec.logonUser( aLogonUser, aLogonPasswd, aFileServer ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: check logon user through forwarded user name, pwd and server name, failed in (UNX)(W32).", + bRes ); + } + + CPPUNIT_TEST_SUITE( logonUser ); + if ( !aStringForward.isEmpty() && aStringForward.indexOf( ' ' ) != -1 && ( aStringForward.indexOf( ' ' ) == aStringForward.lastIndexOf( ' ' ) ) ) + /// if user name and passwd are forwarded + { + CPPUNIT_TEST( logonUser_user_pwd ); + } + if ( !aStringForward.isEmpty() && aStringForward.indexOf( ' ' ) != -1 && ( aStringForward.indexOf( ' ' ) != aStringForward.lastIndexOf( ' ' ) ) ) + /// if user name and passwd and file server are forwarded + { + CPPUNIT_TEST( logonUser_user_pwd_server ); + } + CPPUNIT_TEST_SUITE_END( ); + }; // class logonUser + + /** testing the method: + inline sal_Bool Security::getUserIdent( OUString& strIdent) const + */ + class getUserIdent : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getUserIdent_001( ) + { + ::osl::Security aSec; + OUString strID; + bRes = aSec.getUserIdent( strID ); + + OString aMessage = "strUserID: " + + OUStringToOString(strUserID, osl_getThreadTextEncoding()) + + ", strID: " + + OUStringToOString(strID, osl_getThreadTextEncoding()) + + ", bRes: " + + OString::boolean(bRes); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( aMessage.getStr(), strUserID, strID ); + CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), bRes ); + } + + CPPUNIT_TEST_SUITE( getUserIdent ); + CPPUNIT_TEST( getUserIdent_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getUserIdent + + /** testing the method: + inline sal_Bool SAL_CALL getUserName( OUString& strName) const; + */ + class getUserName : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getUserName_001( ) + { + ::osl::Security aSec; +#ifdef _WIN32 + OUString strName( strUserName ), strGetName; +#else + OUString strName( strUserName ), strGetName; +#endif + bRes = aSec.getUserName( strGetName ); + + sal_Int32 nPos = -1; + if (!strName.isEmpty()) + { + nPos = strGetName.indexOf(strName); + } + CPPUNIT_ASSERT_MESSAGE( "#test comment#: get UserName and compare it with names got at the beginning of the test.", + ( nPos >= 0 ) ); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: get UserName and compare it with names got at the beginning of the test.", + bRes ); + } + + CPPUNIT_TEST_SUITE( getUserName ); + CPPUNIT_TEST( getUserName_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getUserName + + /** testing the method: + inline sal_Bool Security::getConfigDir( OUString& strDirectory ) const + */ + class getConfigDir : public CppUnit::TestFixture + { + public: + bool bRes, bRes1; + + void getConfigDir_001( ) + { + ::osl::Security aSec; + OUString strConfig; + bRes = aSec.getConfigDir( strConfig ); + + CPPUNIT_ASSERT_MESSAGE( "failed to find a ConfigDir!", bRes ); + } + + CPPUNIT_TEST_SUITE( getConfigDir ); + CPPUNIT_TEST( getConfigDir_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getConfigDir + + /** testing the method: + inline sal_Bool SAL_CALL isAdministrator() const; + */ + class isAdministrator : public CppUnit::TestFixture + { + public: + bool bRes; + + void isAdministrator_001( ) + { + ::osl::Security aSec; + bRes = aSec.isAdministrator( ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: check if the user is administrator at beginning, compare here.", + isAdmin, bRes ); + } + + CPPUNIT_TEST_SUITE( isAdministrator ); + CPPUNIT_TEST( isAdministrator_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class isAdministrator + + /** testing the method: + inline oslSecurity getHandle() const; + */ + class getHandle : public CppUnit::TestFixture + { + public: + bool bRes; + + void getHandle_001( ) + { + ::osl::Security aSec; + bRes = aSec.isAdministrator( ) == bool(osl_isAdministrator( aSec.getHandle( ) )); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: use getHandle function to call C API.", + bRes ); + } + + CPPUNIT_TEST_SUITE( getHandle ); + CPPUNIT_TEST( getHandle_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getHandle + + class UserProfile : public CppUnit::TestFixture + { + public: + + void loadUserProfile( ) + { + ::osl::Security aSec; + bool bValue = osl_loadUserProfile(aSec.getHandle()); + + CPPUNIT_ASSERT_MESSAGE( "empty function.", !bValue ); + } + + void unloadUserProfile( ) + { + ::osl::Security aSec; + osl_unloadUserProfile(aSec.getHandle()); + CPPUNIT_ASSERT_MESSAGE( "empty function.", true ); + } + + CPPUNIT_TEST_SUITE( UserProfile ); + CPPUNIT_TEST( loadUserProfile ); + CPPUNIT_TEST( unloadUserProfile ); + CPPUNIT_TEST_SUITE_END( ); + }; // class UserProfile + + class loginUserOnFileServer : public CppUnit::TestFixture + { + public: + + void loginUserOnFileServer_001( ) + { + OUString suUserName; + OUString suPassword; + OUString suFileServer; + ::osl::Security aSec; + oslSecurity pSec = aSec.getHandle(); + + oslSecurityError erg = osl_loginUserOnFileServer(suUserName.pData, suPassword.pData, suFileServer.pData, &pSec); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "empty function.", osl_Security_E_UserUnknown, erg ); + } + + CPPUNIT_TEST_SUITE( loginUserOnFileServer ); + CPPUNIT_TEST( loginUserOnFileServer_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class loginUserOnFileServer + +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::ctors); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::logonUser); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getUserIdent); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getUserName); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getConfigDir); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::isAdministrator); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getHandle); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::UserProfile); +CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::loginUserOnFileServer); + +} // namespace osl_Security + +/* This defines an own TestPlugIn implementation with an own initialize() + method that will be called after loading the PlugIn + */ +#include <cppunit/plugin/TestPlugInDefaultImpl.h> + +namespace { + +class MyTestPlugInImpl: public CPPUNIT_NS::TestPlugInDefaultImpl +{ + public: + MyTestPlugInImpl() {}; + void initialize( CPPUNIT_NS::TestFactoryRegistry *registry, + const CPPUNIT_NS::PlugInParameters ¶meters ) override; +}; + +} + +void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, + const CPPUNIT_NS::PlugInParameters & ) +{ + /// start message + t_print("#Initializing ...\n" ); + t_print("#\n#logonUser function need root/Administrator account to test.\n" ); + t_print("#You can test by login with root/Administrator, and execute:\n" ); + t_print("#testshl2 -forward \"username password\" ../../../wntmsci9/bin/Security.dll\n" ); + t_print("# where username and password are forwarded account info.\n" ); + t_print("#if no text forwarded, this function will be skipped.\n" ); + + /// get system information +#if ( defined UNX ) + /// some initialization work for UNIX OS + + struct passwd* pw; + CPPUNIT_ASSERT_MESSAGE( "getpwuid: no password entry\n",( pw = getpwuid( getuid() ) ) != nullptr ); + + /// get user ID; + strUserID = OUString::number( getuid( ) ); + + /// get user Name; + strUserName = OUString::createFromAscii( pw->pw_name ); + + /// get home directory; + char *pw_dir = pw->pw_dir; + if( getenv( "FAKEROOTKEY" ) ) + pw_dir = getenv("HOME"); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#Convert from system path to URL failed.", + ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( OUString::createFromAscii( pw_dir ), strHomeDirectory ) ); + + /// get config directory; + strConfigDirectory = strHomeDirectory.copy(0); + + /// is administrator; + if( !getuid( ) ) + isAdmin = true; + +#endif +#if defined(_WIN32) + /// some initialization work for Windows OS + + /// Get the user name, computer name, user home directory. + LPWSTR lpszSystemInfo; // pointer to system information string + DWORD cchBuff = BUFSIZE; // size of computer or user name + WCHAR wchBuffer[BUFSIZE]; // buffer for string + + lpszSystemInfo = wchBuffer; + if( GetUserNameW(lpszSystemInfo, &cchBuff) ) + strUserName = o3tl::toU(lpszSystemInfo); + + cchBuff = BUFSIZE; + if( GetComputerNameW(lpszSystemInfo, &cchBuff) ) + strComputerName = o3tl::toU(lpszSystemInfo); + + /// Get user home directory. + HKEY hRegKey; + if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS) + { + sal_Unicode PathW[_MAX_PATH]; + LSTATUS lRet; + DWORD lSize = sizeof(PathW); + DWORD Type; + + lRet = RegQueryValueExW(hRegKey, L"AppData", nullptr, &Type, reinterpret_cast<unsigned char *>(PathW), &lSize); + if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _waccess( o3tl::toW(PathW), 0 ) == 0 ) ) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#Convert from system path to URL failed.", + ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( PathW, strConfigDirectory ) ); + } + + lSize = sizeof(PathW); + lRet = RegQueryValueExW(hRegKey, L"Personal", nullptr, &Type, reinterpret_cast<unsigned char *>(PathW), &lSize); + if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _waccess( o3tl::toW(PathW), 0 ) == 0 ) ) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( "#Convert from system path to URL failed.", + ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( PathW, strHomeDirectory ) ); + } + + RegCloseKey(hRegKey); + } + + /// Get user Security ID: + + // Create buffers that may be large enough. If a buffer is too small, the count parameter will be set to the size needed. + const DWORD INITIAL_SIZE = 32; + DWORD cbSid = 0; + DWORD dwSidBufferSize = INITIAL_SIZE; + DWORD cchDomainName = 0; + DWORD dwDomainBufferSize = INITIAL_SIZE; + WCHAR * wszDomainName = nullptr; + SID_NAME_USE eSidType; + DWORD dwErrorCode = 0; + + OUString sLookupUserName = strUserName; + LPCWSTR wszAccName = o3tl::toW(sLookupUserName.getStr( )); + + // Create buffers for the SID and the domain name. + PSID pSid = static_cast<PSID>(new BYTE[dwSidBufferSize]); + memset( pSid, 0, dwSidBufferSize); + + wszDomainName = new WCHAR[dwDomainBufferSize]; + memset(wszDomainName, 0, dwDomainBufferSize*sizeof(WCHAR)); + + // Obtain the SID for the account name passed. + for ( ; ; ) + { + // Set the count variables to the buffer sizes and retrieve the SID. + cbSid = dwSidBufferSize; + cchDomainName = dwDomainBufferSize; + if (LookupAccountNameW( + nullptr, // Computer name. NULL for the local computer + wszAccName, + pSid, // Pointer to the SID buffer. Use NULL to get the size needed, + &cbSid, // Size of the SID buffer needed. + wszDomainName, // wszDomainName, + &cchDomainName, + &eSidType + )) + { + if (eSidType == SID_NAME_USE::SidTypeDomain) + { + // LookupAccountNameW returned SID of a domain; likely the hostname is the same as + // username (case-insensitive): something like "JOHNSMITH\JohnSmith", so looking up + // for "JohnSmith" without domain returns domain itself. Try getting the SID of the + // user using fully qualified name (the case of user of another domain having name + // identical this hostname is not handled). + sLookupUserName = o3tl::toU(wszDomainName) + OUStringLiteral("\\") + strUserName; + wszAccName = o3tl::toW(sLookupUserName.getStr()); + continue; + } + if (IsValidSid( pSid) == FALSE) + wprintf(L"# The SID for %s is invalid.\n", wszAccName); + break; + } + dwErrorCode = GetLastError(); + + // Check if one of the buffers was too small. + if (dwErrorCode == ERROR_INSUFFICIENT_BUFFER) + { + if (cbSid > dwSidBufferSize) + { + // Reallocate memory for the SID buffer. + wprintf(L"# The SID buffer was too small. It will be reallocated.\n"); + delete[] static_cast<BYTE*>(pSid); + pSid = static_cast<PSID>(new BYTE[cbSid]); + memset( pSid, 0, cbSid); + dwSidBufferSize = cbSid; + } + if (cchDomainName > dwDomainBufferSize) + { + // Reallocate memory for the domain name buffer. + wprintf(L"# The domain name buffer was too small. It will be reallocated.\n"); + delete [] wszDomainName; + wszDomainName = new WCHAR[cchDomainName]; + memset(wszDomainName, 0, cchDomainName*sizeof(WCHAR)); + dwDomainBufferSize = cchDomainName; + } + } + else + { + wprintf(L"# LookupAccountNameW failed. GetLastError returned: %d\n", dwErrorCode); + break; + } + } + + LPWSTR pSidStr = nullptr; + if (ConvertSidToStringSidW(pSid, &pSidStr)) + { + strUserID = o3tl::toU(pSidStr); + LocalFree(pSidStr); + } + else + { + wprintf(L"# ConvertSidToStringSidW failed. GetLastError returned: %d\n", GetLastError()); + } + + delete [] static_cast<BYTE*>(pSid); + delete [] wszDomainName; + + /// check if logged in user is administrator: + + BOOL b; + SID_IDENTIFIER_AUTHORITY NtAuthority = { SECURITY_NT_AUTHORITY }; + PSID AdministratorsGroup; + b = AllocateAndInitializeSid( + &NtAuthority, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + 0, 0, 0, 0, 0, 0, + &AdministratorsGroup); + if(b) + { + if (!CheckTokenMembership( nullptr, AdministratorsGroup, &b)) + { + b = FALSE; + } + FreeSid(AdministratorsGroup); + } + + isAdmin = b; + +#endif + + /// print the information. + t_print("#\n#Retrieved system information is below:\n"); + + t_print("Computer Name: "); + if ( strComputerName.isEmpty()) + t_print("Not retrieved\n" ); + else + printUString( strComputerName ); + + t_print("Current User Name: "); + if ( strUserName.isEmpty()) + t_print("Not retrieved\n" ); + else + printUString( strUserName ); + + t_print("Current User Home Directory:"); + if ( strHomeDirectory.isEmpty()) + t_print("Not retrieved\n" ); + else + printUString( strHomeDirectory ); + + t_print("Current Config Directory: "); + if ( strConfigDirectory.isEmpty()) + t_print("Not retrieved\n" ); + else + printUString( strConfigDirectory ); + + t_print("Current UserID: "); + if ( strUserID.isEmpty()) + t_print("Not retrieved\n" ); + else + printUString( strUserID ); + + t_print("Current User is: "); + if ( !isAdmin ) + t_print("NOT Administrator.\n" ); + else + t_print("Administrator.\n" ); + + /// get and display forwarded text if available. + OUString args[ 3 ]; + int argsCount = 0; + sal_uInt32 n = rtl_getAppCommandArgCount(); + for (sal_uInt32 i = 0; i < n; ++i) + { + OUString arg; + rtl_getAppCommandArg(i, &arg.pData); + if( arg.startsWith("-") ) + continue; + if( argsCount >= 3 ) + { + SAL_WARN( "sal.osl", "Too many test arguments" ); + continue; + } + args[ argsCount++ ] = arg; + } + /// only forwarded two parameters, username and password. + if( argsCount == 2 ) + { + aLogonUser = args[ 0 ]; + t_print("\n#Forwarded username: "); + printUString( aLogonUser); + + aLogonPasswd = args[ 1 ]; + t_print("#Forwarded password: "); + for (int i = 0; i < aLogonPasswd.getLength(); ++i) + t_print("*"); + t_print("\n" ); + } + else if( argsCount == 3 ) + /// forwarded three parameters, username, password and fileserver. + { + aLogonUser = args[ 0 ]; + t_print("#Forwarded username: "); + printUString( aLogonUser); + + aLogonPasswd = args[ 1 ]; + t_print("#Forwarded password: "); + for (int i = 0; i < aLogonPasswd.getLength(); ++i) + t_print("*"); + t_print("\n" ); + + aFileServer = args[ 2 ]; + t_print("#Forwarded FileServer: "); + printUString( aFileServer ); + } + t_print("#\n#Initialization Done.\n" ); + +} + +/* Instantiate and register the own TestPlugIn and instantiate the default + main() function. + (This is done by CPPUNIT_PLUGIN_IMPLEMENT() for TestPlugInDefaultImpl) + */ + +CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( MyTestPlugInImpl ); +CPPUNIT_PLUGIN_IMPLEMENT_MAIN(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/security/osl_Security_Const.h b/sal/qa/osl/security/osl_Security_Const.h new file mode 100644 index 000000000..58f578814 --- /dev/null +++ b/sal/qa/osl/security/osl_Security_Const.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_OSL_SECURITY_OSL_SECURITY_CONST_H +#define INCLUDED_SAL_QA_OSL_SECURITY_OSL_SECURITY_CONST_H + +#if defined(_WIN32) // Windows +#include <io.h> +#endif + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <osl/file.hxx> +#include <osl/security.hxx> + +#include <stdlib.h> +#include <stdio.h> + +#if ( defined UNX ) +#include <unistd.h> +#include <pwd.h> +#endif + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <cppunit/plugin/TestPlugInDefaultImpl.h> + +#define t_print printf + +#define BUFSIZE 1024 +const char pTestString[17] = "Sun Microsystems"; + +OUString aLogonUser, aLogonPasswd, aFileServer, aStringForward; +OUString strUserName, strComputerName, strHomeDirectory; +OUString strConfigDirectory, strUserID; + +bool isAdmin = false; + +#endif // INCLUDED_SAL_QA_OSL_SECURITY_OSL_SECURITY_CONST_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/setthreadname/test-setthreadname.cxx b/sal/qa/osl/setthreadname/test-setthreadname.cxx new file mode 100644 index 000000000..c0c884eea --- /dev/null +++ b/sal/qa/osl/setthreadname/test-setthreadname.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cstdlib> +#include <iostream> +#include <limits> + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <osl/thread.hxx> + +namespace { + +class TestThread: public osl::Thread { +private: + virtual void SAL_CALL run() override; +public: + TestThread() = default; + TestThread(const TestThread&) = delete; + TestThread& operator=(const TestThread&) = delete; +}; + +void TestThread::run() { +#if defined(_WIN32) + if (std::getenv("URE_TEST_SETTHREADNAME") != nullptr) { + // On Windows, setting thread names appears to only take effect when the + // process is being debugged, so attach a debugger now: + std::cout << "set: "; + std::cin.ignore(std::numeric_limits< int >::max(), '\n'); + } +#endif + setName("TestThread"); + if (std::getenv("URE_TEST_SETTHREADNAME") != nullptr) { + // On Linux, the thread name can now be observed with "ps -L"; on + // Windows with the Microsoft compiler, the thread name can now be + // observed in a debugger. + std::cout << "stop: "; + std::cin.ignore(std::numeric_limits< int >::max(), '\n'); + } +} + +class Test: public CppUnit::TestFixture { +private: + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + + void test(); +}; + +void Test::test() { + TestThread t; + t.create(); + t.join(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/osl/thread/test_thread.cxx b/sal/qa/osl/thread/test_thread.cxx new file mode 100644 index 000000000..12ddafc6d --- /dev/null +++ b/sal/qa/osl/thread/test_thread.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include "osl/conditn.hxx" +#include "osl/thread.hxx" +#include "osl/time.h" +#include <chrono> + +namespace { + +osl::Condition global; + +class Thread: public osl::Thread { +public: + explicit Thread(osl::Condition & cond): m_cond(cond) {} + +private: + virtual void SAL_CALL run() {} + + virtual void SAL_CALL onTerminated() { + m_cond.set(); + CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok, global.wait()); + } + + osl::Condition & m_cond; +}; + +class Test: public CppUnit::TestFixture { +public: + // Nondeterministic, best effort test that an osl::Thread can be destroyed + // (and in particular osl_destroyThread---indirectly---be called) before the + // corresponding thread has terminated: + void test() { + for (int i = 0; i < 50; ++i) { + osl::Condition c; + Thread t(c); + CPPUNIT_ASSERT(t.create()); + // Make sure virtual Thread::run/onTerminated are called before + // Thread::~Thread: + CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok, c.wait()); + } + // Make sure Thread::~Thread is called before each spawned thread + // terminates: + global.set(); + // Give the spawned threads enough time to terminate: + osl::Thread::wait(std::chrono::seconds(20)); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/alloc/rtl_alloc.cxx b/sal/qa/rtl/alloc/rtl_alloc.cxx new file mode 100644 index 000000000..419a3f3b0 --- /dev/null +++ b/sal/qa/rtl/alloc/rtl_alloc.cxx @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <rtl/alloc.h> +#include <rtl/ustrbuf.hxx> +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include "../../../rtl/strimp.hxx" + +#include <memory.h> + +namespace rtl_alloc +{ + + // small memory check routine, which return false, if there is a problem + + static bool checkMemory(const char* _pMemory, sal_uInt32 _nSize, char _n) + { + bool bOk = true; + + for (sal_uInt32 i=0;i<_nSize;i++) + { + if (_pMemory[i] != _n) + { + bOk = false; + } + } + return bOk; + } + +class Memory : public CppUnit::TestFixture +{ + // for normal alloc functions + char *m_pMemory; + static const sal_uInt32 m_nSizeOfMemory = 1024; + +public: + Memory() + : m_pMemory(nullptr) + { + } + + // initialise your test code values here. + void setUp() override + { + m_pMemory = static_cast<char*>(rtl_allocateMemory( m_nSizeOfMemory )); + } + + void tearDown() override + { + rtl_freeMemory(m_pMemory); + m_pMemory = nullptr; + } + + void rtl_allocateMemory_001() + { + CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != nullptr); + memset(m_pMemory, 1, m_nSizeOfMemory); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1)); + } + + void rtl_reallocateMemory_001() + { + sal_uInt32 nSize = 2 * 1024; + m_pMemory = static_cast<char*>(rtl_reallocateMemory(m_pMemory, nSize)); + + CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != nullptr); + memset(m_pMemory, 2, nSize); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2)); + } + + CPPUNIT_TEST_SUITE(Memory); + CPPUNIT_TEST(rtl_allocateMemory_001); + CPPUNIT_TEST(rtl_reallocateMemory_001); + CPPUNIT_TEST_SUITE_END(); +}; // class test + +class TestZeroMemory : public CppUnit::TestFixture +{ + // for zero functions + char *m_pZeroMemory; + static const sal_uInt32 m_nSizeOfZeroMemory = 50 * 1024 * 1024; + +public: + TestZeroMemory() + : m_pZeroMemory(nullptr) + { + } + + // initialise your test code values here. + void setUp() override + { + m_pZeroMemory = static_cast<char*>(rtl_allocateZeroMemory( m_nSizeOfZeroMemory )); + } + + void tearDown() override + { + rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory); + // LLA: no check possible, may GPF if there is something wrong. + // CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", pZeroMemory != NULL); + } + + // insert your test code here. + + void rtl_allocateZeroMemory_001() + { + CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory != nullptr); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0)); + + memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3)); + } + + CPPUNIT_TEST_SUITE(TestZeroMemory); + CPPUNIT_TEST(rtl_allocateZeroMemory_001); + CPPUNIT_TEST_SUITE_END(); +}; + +class TestPreinit : public CppUnit::TestFixture +{ +public: + TestPreinit() + { + } + + // initialise your test code values here. + void setUp() override + { + } + + void tearDown() override + { + } + + // insert your test code here. + + void test() + { + const char sample[] = "Hello World"; + std::vector<OUString> aStrings; + + rtl_alloc_preInit(true); + + OUString aFoo("foo"); + + // fill some cache bits + for (int iter = 0; iter < 4; iter++) + { + for (int i = 1; i < 4096; i += 8) + { + OUStringBuffer aBuf(i); + aBuf.appendAscii(sample, (i/8) % (SAL_N_ELEMENTS(sample)-1)); + OUString aStr = aBuf.makeStringAndClear(); + aStrings.push_back(aStr); + } + // free some pieces to make holes + for (size_t i = iter; i < aStrings.size(); i += 17) + aStrings[i] = aFoo; + } + + for (size_t i = 0; i < aStrings.size(); ++i) + { + CPPUNIT_ASSERT_MESSAGE( "not static before.", !(aStrings[i].pData->refCount & SAL_STRING_STATIC_FLAG) ); + } + + // should static-ize all the strings. + rtl_alloc_preInit(false); + + for (size_t i = 0; i < aStrings.size(); ++i) + CPPUNIT_ASSERT_MESSAGE( "static after.", (aStrings[i].pData->refCount & SAL_STRING_STATIC_FLAG) ); + } + + void test2() + { + // should never happen but lets try it again. + test(); + } + + CPPUNIT_TEST_SUITE(TestPreinit); + CPPUNIT_TEST(test); + CPPUNIT_TEST(test2); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::Memory); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestZeroMemory); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestPreinit); +} // namespace rtl_alloc + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/bootstrap/expand.cxx b/sal/qa/rtl/bootstrap/expand.cxx new file mode 100644 index 000000000..e9799c15f --- /dev/null +++ b/sal/qa/rtl/bootstrap/expand.cxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <rtl/bootstrap.hxx> +#include <rtl/ustring.hxx> + +namespace { + +class Test: public CppUnit::TestFixture { +public: + virtual void setUp() override; + +private: + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testDollar); + CPPUNIT_TEST(testIndirectDollar); + CPPUNIT_TEST_SUITE_END(); + + void testDollar(); + + void testIndirectDollar(); +}; + +void Test::setUp() { + rtl::Bootstrap::set("TEST", "<expanded TEST>"); + rtl::Bootstrap::set("WITH_DOLLAR", "foo\\$TEST"); + rtl::Bootstrap::set("INDIRECT", "$WITH_DOLLAR"); +} + +void Test::testDollar() { + OUString s("$WITH_DOLLAR"); + rtl::Bootstrap::expandMacros(s); + CPPUNIT_ASSERT_EQUAL(OUString("foo$TEST"), s); +} + +void Test::testIndirectDollar() { + OUString s("$INDIRECT"); + rtl::Bootstrap::expandMacros(s); + CPPUNIT_ASSERT_EQUAL(OUString("foo$TEST"), s); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/cipher/rtl_cipher.cxx b/sal/qa/rtl/cipher/rtl_cipher.cxx new file mode 100644 index 000000000..1f6852184 --- /dev/null +++ b/sal/qa/rtl/cipher/rtl_cipher.cxx @@ -0,0 +1,600 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cstring> + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/strbuf.hxx> +#include <rtl/cipher.h> + +namespace rtl_cipher +{ + +class create : public CppUnit::TestFixture +{ +public: + + void create_001() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); +#endif + } + void create_002() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher); + } + void create_003() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); +#endif + } + void create_004() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher); + } + void create_005() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); + } + void create_006() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher); + } + void create_007() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher); + } + void create_008() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(create); + CPPUNIT_TEST(create_001); + CPPUNIT_TEST(create_002); + CPPUNIT_TEST(create_003); + CPPUNIT_TEST(create_004); + CPPUNIT_TEST(create_005); + CPPUNIT_TEST(create_006); + CPPUNIT_TEST(create_007); + CPPUNIT_TEST(create_008); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +class createBF : public CppUnit::TestFixture +{ +public: + + void createBF_001() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); +#endif + } + void createBF_002() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); +#endif + } + void createBF_003() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); + } + void createBF_004() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher); + // rtl_cipher_destroy(aCipher); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(createBF); + CPPUNIT_TEST(createBF_001); + CPPUNIT_TEST(createBF_002); + CPPUNIT_TEST(createBF_003); + CPPUNIT_TEST(createBF_004); + CPPUNIT_TEST_SUITE_END(); +}; // class createBF + +class decode : public CppUnit::TestFixture +{ +public: + + void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, OString const& _sPlainTextStr) + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); + (void) _nKeyValue; + (void) _nArgValue; + (void) _sPlainTextStr; +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + pKeyBuffer[0] = _nKeyValue; + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + pArgBuffer[0] = _nArgValue; + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + sal_uInt32 nPlainTextLen = 16; + sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ]; + memset(pPlainTextBuffer, 0, nPlainTextLen); + strncpy(reinterpret_cast<char*>(pPlainTextBuffer), _sPlainTextStr.getStr(), 16); + + sal_uInt32 nCipherLen = 16; + sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ]; + memset(pCipherBuffer, 0, nCipherLen); + + /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong encode", rtl_Cipher_E_None, aError); + + sal_uInt32 nPlainText2Len = 16; + sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ]; + memset(pPlainText2Buffer, 0, nPlainText2Len); + + /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len); + CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None); + + delete [] pPlainText2Buffer; + + delete [] pCipherBuffer; + delete [] pPlainTextBuffer; + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + + void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, OString const& _sPlainTextStr) + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); + (void) _nKeyValue; + (void) _nArgValue; + (void) _sPlainTextStr; +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + pKeyBuffer[0] = _nKeyValue; + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + pArgBuffer[0] = _nArgValue; + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + sal_uInt32 nPlainTextLen = 16; + sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ]; + memset(pPlainTextBuffer, 0, nPlainTextLen); + strncpy(reinterpret_cast<char*>(pPlainTextBuffer), _sPlainTextStr.getStr(), 16); + + sal_uInt32 nCipherLen = 16; + sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ]; + memset(pCipherBuffer, 0, nCipherLen); + + /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong encode", rtl_Cipher_E_None, aError); + + sal_uInt32 nPlainText2Len = 16; + sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ]; + memset(pPlainText2Buffer, 0, nPlainText2Len); + + /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong decode", rtl_Cipher_E_None, aError); + + sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("compare between plain and decoded plain failed", static_cast<sal_Int32>(0), nCompare); + + delete [] pPlainText2Buffer; + + delete [] pCipherBuffer; + delete [] pPlainTextBuffer; + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + + void decode_001() + { + test_encode_and_decode(0,0,""); + test_encode_and_decode(0,0,"hallo"); + test_encode_and_decode(1,0,"B2Aahg5B"); + test_encode_and_decode(1,2,"Longer text string"); + } + + void decode_002() + { + test_encode(0,0,""); + test_encode(0,0,"hallo"); + test_encode(1,0,"B2Aahg5B"); + test_encode(1,2,"Longer text string"); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(decode); + CPPUNIT_TEST(decode_001); + CPPUNIT_TEST(decode_002); + CPPUNIT_TEST_SUITE_END(); +}; // class decode + +class decodeBF : public CppUnit::TestFixture +{ +public: + + void decodeBF_001() + { + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(decodeBF); + CPPUNIT_TEST(decodeBF_001); + CPPUNIT_TEST_SUITE_END(); +}; // class decodeBF + +class destroy : public CppUnit::TestFixture +{ +public: + + void destroy_001() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroy(aCipher); +#endif + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(destroy); + CPPUNIT_TEST(destroy_001); + CPPUNIT_TEST_SUITE_END(); +}; // class destroy + +class destroyBF : public CppUnit::TestFixture +{ +public: + + void destroyBF_001() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + rtl_cipher_destroyBF(aCipher); + // more proforma + // should not GPF +#endif + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(destroyBF); + CPPUNIT_TEST(destroyBF_001); + CPPUNIT_TEST_SUITE_END(); +}; // class destroyBF + +class encode : public CppUnit::TestFixture +{ +public: + + void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue) + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); + (void) _nKeyValue; + (void) _nArgValue; + (void) _nDataValue; +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + pKeyBuffer[0] = _nKeyValue; + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + pArgBuffer[0] = _nArgValue; + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + sal_uInt32 nDataLen = 16; + sal_uInt8 *pDataBuffer = new sal_uInt8[ nDataLen ]; + memset(pDataBuffer, 0, nDataLen); + pDataBuffer[0] = _nDataValue; + + sal_uInt32 nLen = 16; + sal_uInt8 *pBuffer = new sal_uInt8[ nLen ]; + memset(pBuffer, 0, nLen); + + /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong encode", rtl_Cipher_E_None, aError); + + delete [] pBuffer; + delete [] pDataBuffer; + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + + void encode_001() + { + test_encode(0,0,0); + test_encode(1,0,0); + test_encode(0,1,0); + test_encode(1,1,0); + + test_encode(0,0,1); + test_encode(1,0,1); + test_encode(0,1,1); + test_encode(1,1,1); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(encode); + CPPUNIT_TEST(encode_001); + CPPUNIT_TEST_SUITE_END(); +}; // class encode + +class encodeBF : public CppUnit::TestFixture +{ +public: + + void encodeBF_001() + { + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(encodeBF); + CPPUNIT_TEST(encodeBF_001); + CPPUNIT_TEST_SUITE_END(); +}; // class encodeBF + +class init : public CppUnit::TestFixture +{ +public: + + void init_001() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + + void init_002() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + pKeyBuffer[0] = 1; + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + void init_003() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + pArgBuffer[0] = 1; + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + void init_004() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); +#if defined LIBO_CIPHER_OPENSSL_BACKEND + CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher); +#else + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr); + + sal_uInt32 nKeyLen = 16; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + memset(pKeyBuffer, 0, nKeyLen); + pKeyBuffer[0] = 1; + + sal_uInt32 nArgLen = 16; + sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; + memset(pArgBuffer, 0, nArgLen); + pArgBuffer[0] = 1; + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); +#endif + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(init); + CPPUNIT_TEST(init_001); + CPPUNIT_TEST(init_002); + CPPUNIT_TEST(init_003); + CPPUNIT_TEST(init_004); + CPPUNIT_TEST_SUITE_END(); +}; // class init + +class initBF : public CppUnit::TestFixture +{ +public: + + void initBF_001() + { + // seems to be the same as init, so empty + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(initBF); + CPPUNIT_TEST(initBF_001); + CPPUNIT_TEST_SUITE_END(); +}; // class initBF + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::create); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::createBF); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::decode); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::decodeBF); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::destroy); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::destroyBF); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::encode); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::encodeBF); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::init); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::initBF); + +} // namespace rtl_cipher + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/crc32/rtl_crc32.cxx b/sal/qa/rtl/crc32/rtl_crc32.cxx new file mode 100644 index 000000000..00933b589 --- /dev/null +++ b/sal/qa/rtl/crc32/rtl_crc32.cxx @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/crc.h> + +namespace rtl_CRC32 +{ + +class test : public CppUnit::TestFixture +{ +public: + + // insert your test code here. + void rtl_crc32_001() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + sal_uInt32 nCRC = 0; + + char buf[] = {0}; + int num = 0; + + nCRC = rtl_crc32(nCRC, buf, num); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("empty crc buffer", static_cast<sal_uInt32>(0), nCRC); + } + + void rtl_crc32_002() + { + sal_uInt32 nCRC = 0; + + char buf[] = {0,0}; + int num = sizeof(buf); + + nCRC = rtl_crc32(nCRC, buf, num); + + CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0); + } + + void rtl_crc32_002_1() + { + sal_uInt32 nCRC = 0; + + char buf[] = {0,0,0}; + int num = sizeof(buf); + + nCRC = rtl_crc32(nCRC, buf, num); + + CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0); + } + + /** + * crc32 check: + * Build checksum on two buffers with same size but different content, + * the result (crc32 checksum) must differ + */ + + void rtl_crc32_003() + { + sal_uInt32 nCRC1 = 0; + char buf1[] = {2}; + int num1 = sizeof(buf1); + + nCRC1 = rtl_crc32(nCRC1, buf1, num1); + + sal_uInt32 nCRC2 = 0; + char buf2[] = {3}; + int num2 = sizeof(buf2); + + nCRC2 = rtl_crc32(nCRC2, buf2, num2); + + CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2); + } + + /** check if the crc32 only use as much values, as given + * + */ + void rtl_crc32_003_1() + { + sal_uInt32 nCRC1 = 0; + char buf1[] = {2,1}; + int num1 = sizeof(buf1) - 1; + + nCRC1 = rtl_crc32(nCRC1, buf1, num1); + + sal_uInt32 nCRC2 = 0; + char buf2[] = {2,2}; + int num2 = sizeof(buf2) - 1; + + nCRC2 = rtl_crc32(nCRC2, buf2, num2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("checksum leave it's bounds", nCRC2, nCRC1); + } + + /** check if the crc32 differ at same content in reverse order + * + */ + void rtl_crc32_003_2() + { + sal_uInt32 nCRC1 = 0; + char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + int num1 = sizeof(buf1); + + nCRC1 = rtl_crc32(nCRC1, buf1, num1); + + sal_uInt32 nCRC2 = 0; + char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0}; + int num2 = sizeof(buf2); + + nCRC2 = rtl_crc32(nCRC2, buf2, num2); + + CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(test); + CPPUNIT_TEST(rtl_crc32_001); + CPPUNIT_TEST(rtl_crc32_002); + CPPUNIT_TEST(rtl_crc32_002_1); + CPPUNIT_TEST(rtl_crc32_003); + CPPUNIT_TEST(rtl_crc32_003_1); + CPPUNIT_TEST(rtl_crc32_003_2); + CPPUNIT_TEST_SUITE_END(); +}; // class test + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_CRC32::test); +} // namespace rtl_CRC32 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/digest/rtl_digest.cxx b/sal/qa/rtl/digest/rtl_digest.cxx new file mode 100644 index 000000000..6bc9070be --- /dev/null +++ b/sal/qa/rtl/digest/rtl_digest.cxx @@ -0,0 +1,516 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <memory> + +#include <rtl/digest.h> +#include <rtl/string.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/strbuf.hxx> + +#include <string.h> + +using namespace rtl; + +namespace +{ + +const OString sSampleString = "This is a sample sentence, which we use to check some crypto functions in sal."; +const OString sSampleString_only_one_diff = "This is a sample sentence. which we use to check some crypto functions in sal."; + +const rtlDigestAlgorithm constDigestAlgorithms[] = +{ + rtl_Digest_AlgorithmMD2, + rtl_Digest_AlgorithmMD5, + rtl_Digest_AlgorithmSHA, + rtl_Digest_AlgorithmSHA1, + rtl_Digest_AlgorithmHMAC_MD5, + rtl_Digest_AlgorithmHMAC_SHA1, +}; + +const sal_uInt32 constDigestAlgorithmLengths[] = +{ + RTL_DIGEST_LENGTH_MD2, + RTL_DIGEST_LENGTH_MD5, + RTL_DIGEST_LENGTH_SHA, + RTL_DIGEST_LENGTH_SHA1, + RTL_DIGEST_LENGTH_HMAC_MD5, + RTL_DIGEST_LENGTH_HMAC_SHA1, +}; + +const OString constSampleStringSums[] = +{ + "647ee6c9d4aa5fdd374ed9d7a156acbf", + "b16b903e6fc0b62ae389013ed93fe531", + "eab2814429b2613301c8a077b806af3680548914", + "2bc5bdb7506a2cdc2fd27fc8b9889343012d5008", + "0b1b0e1a6f2e4420326354b031063605", + "1998c6a556915be76451bfb587fa7c34d849936e" +}; + +// Create hex-value string from the digest value to keep the string size minimal +OString createHex(const sal_uInt8* pKeyBuffer, sal_uInt32 nKeyLen) +{ + OStringBuffer aBuffer(nKeyLen * 2 + 1); + for (sal_uInt32 i = 0; i < nKeyLen; ++i) + { + sal_Int32 nValue = static_cast<sal_Int32>(pKeyBuffer[i]); + if (nValue < 16) + aBuffer.append('0'); + aBuffer.append(nValue, 16); + } + return aBuffer.makeStringAndClear(); +} + +OString getDigest(const OString& aMessage, rtlDigestAlgorithm aAlgorithm) +{ + rtlDigest handle = rtl_digest_create(aAlgorithm); + + const sal_uInt8* pData = reinterpret_cast<const sal_uInt8*>(aMessage.getStr()); + sal_uInt32 nSize = aMessage.getLength(); + + rtl_digest_init(handle, pData, nSize); + rtl_digest_update(handle, pData, nSize); + + sal_uInt32 nKeyLen = rtl_digest_queryLength(handle); + std::unique_ptr<sal_uInt8[]> pKeyBuffer(new sal_uInt8[nKeyLen]); + + rtl_digest_get(handle, pKeyBuffer.get(), nKeyLen); + OString aSum = createHex(pKeyBuffer.get(), nKeyLen); + + rtl_digest_destroy( handle ); + return aSum; +} + +class DigestTest : public CppUnit::TestFixture +{ +public: + void testCreate() + { + for (size_t i = 0; i < SAL_N_ELEMENTS(constDigestAlgorithms); i++) + { + rtlDigest handle = rtl_digest_create( constDigestAlgorithms[i] ); + CPPUNIT_ASSERT_MESSAGE("create digest", handle != nullptr); + rtl_digest_destroy( handle ); + } + + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("create invalid digest", static_cast<rtlDigest>(nullptr), handle); + rtl_digest_destroy( handle ); + } + + void testQuery() + { + for (size_t i = 0; i < SAL_N_ELEMENTS(constDigestAlgorithms); i++) + { + rtlDigest handle = rtl_digest_create(constDigestAlgorithms[i]); + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("query handle", aAlgo, constDigestAlgorithms[i]); + rtl_digest_destroy( handle ); + } + + } + + void testQueryLength() + { + rtlDigest handle; + sal_uInt32 nAlgoLength; + + for (size_t i = 0; i < SAL_N_ELEMENTS(constDigestAlgorithms); i++) + { + handle = rtl_digest_create(constDigestAlgorithms[i]); + nAlgoLength = rtl_digest_queryLength(handle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("query Length", nAlgoLength, constDigestAlgorithmLengths[i]); + rtl_digest_destroy( handle ); + } + + handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); + nAlgoLength = rtl_digest_queryLength(handle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("query length", static_cast<sal_uInt32>(0), nAlgoLength); + rtl_digest_destroy( handle ); + } + + void testInit() + { + rtlDigestError aError; + rtlDigest handle; + + handle = nullptr; + aError = rtl_digest_init(handle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("init(NULL, 0, 0)", rtl_Digest_E_Argument, aError); + + handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + aError = rtl_digest_init(handle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("init(handle, 0, 0)", rtl_Digest_E_None, aError); + rtl_digest_destroy( handle ); + + for (size_t i = 0; i < SAL_N_ELEMENTS(constDigestAlgorithms); i++) + { + handle = rtl_digest_create(constDigestAlgorithms[i]); + + OString aMessage = sSampleString; + const sal_uInt8* pData = reinterpret_cast<const sal_uInt8*>(aMessage.getStr()); + sal_uInt32 nSize = aMessage.getLength(); + + aError = rtl_digest_init(handle, pData, nSize); + CPPUNIT_ASSERT_EQUAL_MESSAGE("init(handle, pData, nSize)", rtl_Digest_E_None, aError); + + rtl_digest_update(handle, pData, nSize); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + std::unique_ptr<sal_uInt8[]> pKeyBuffer(new sal_uInt8[nKeyLen]); + + rtl_digest_get( handle, pKeyBuffer.get(), nKeyLen ); + createHex(pKeyBuffer.get(), nKeyLen); + + rtl_digest_destroy( handle ); + } + } + + void testEqual() + { + { + OString aMsg1 = sSampleString; + OString aMsg2 = sSampleString; + + OString aSum1 = getDigest(aMsg1, rtl_Digest_AlgorithmMD5); + OString aSum2 = getDigest(aMsg2, rtl_Digest_AlgorithmMD5); + + CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aSum1.getLength() == 32 && aSum2.getLength() == 32 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("source is the same, dest must be also the same", aSum1, aSum2); + } + + { + OString aMsg1 = sSampleString; + OString aMsg2 = sSampleString_only_one_diff; + + OString aSum1 = getDigest(aMsg1, rtl_Digest_AlgorithmMD5); + OString aSum2 = getDigest(aMsg2, rtl_Digest_AlgorithmMD5); + + CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aSum1.getLength() == 32 && aSum2.getLength() == 32 ); + CPPUNIT_ASSERT_MESSAGE("differ only in one char", aSum1 != aSum2); + } + } + + void testCheckSum() + { + for (size_t i = 0; i < SAL_N_ELEMENTS(constDigestAlgorithms); i++) + { + OString aSum = getDigest(sSampleString, constDigestAlgorithms[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Checksum of sample string is wrong.", constSampleStringSums[i], aSum); + } + } + + OString runCheckPBKDF2(OString& sPassword, bool bClearSalt, sal_uInt32 nCount) + { + sal_uInt32 nKeyLen = RTL_DIGEST_LENGTH_HMAC_SHA1; + std::unique_ptr<sal_uInt8[]> pKeyBuffer(new sal_uInt8[nKeyLen]); + + memset(pKeyBuffer.get(), 0, nKeyLen); + + sal_uInt8 const * pPassword = reinterpret_cast<sal_uInt8 const *>(sPassword.getStr()); + sal_Int32 nPasswordLen = sPassword.getLength(); + + sal_uInt32 nSaltDataLen = RTL_DIGEST_LENGTH_HMAC_SHA1; + std::unique_ptr<sal_uInt8[]> pSaltData(new sal_uInt8[nSaltDataLen]); + memset(pSaltData.get(), 0, nSaltDataLen); + + if (!bClearSalt) + { + // wilful contamination + pSaltData[0] = 1; + } + + rtlDigestError aError = rtl_digest_PBKDF2(pKeyBuffer.get(), nKeyLen, pPassword, nPasswordLen, pSaltData.get(), nSaltDataLen, nCount); + + CPPUNIT_ASSERT_EQUAL(rtl_Digest_E_None, aError); + + OString aKey = createHex(pKeyBuffer.get(), nKeyLen); + + // OString sSalt = createHex(pSaltData, nSaltDataLen); + // printf("Salt: %s\n", sSalt.getStr()); + + // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) ); + return aKey; + } + + void testPBKDF2() + { + OString aPassword = "Password"; + + // all permutations + runCheckPBKDF2(aPassword, false, 1); + runCheckPBKDF2(aPassword, false, 2); + runCheckPBKDF2(aPassword, true, 1); + runCheckPBKDF2(aPassword, true, 2); + runCheckPBKDF2(aPassword, false, 3); + runCheckPBKDF2(aPassword, false, 4); + runCheckPBKDF2(aPassword, true, 3); + runCheckPBKDF2(aPassword, true, 4); + } + + void testUpdate() + { + rtlDigestError aError; + rtlDigest aHandle; + + aHandle = nullptr; + aError = rtl_digest_update(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument, aError); + + aHandle = nullptr; + aError = rtl_digest_updateMD2(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument, aError); + + aError = rtl_digest_updateMD5(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument, aError); + + aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != nullptr); + + const sal_uInt8* pData = reinterpret_cast<const sal_uInt8*>(sSampleString.getStr()); + sal_uInt32 nSize = sSampleString.getLength(); + + aError = rtl_digest_updateMD2(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'pData' wrong", rtl_Digest_E_Argument, aError); + + aError = rtl_digest_updateMD2(aHandle, pData, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'nSize' wrong", rtl_Digest_E_None, aError); + + rtl_digest_destroyMD2(aHandle); + + // use wrong Algorithm!!! This is volitional! + aHandle = rtl_digest_create(rtl_Digest_AlgorithmMD2); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != nullptr); + + aError = rtl_digest_updateMD5(aHandle, pData, nSize); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'handle' wrong", rtl_Digest_E_Algorithm, aError); + + rtl_digest_destroyMD5(aHandle); + + aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != nullptr); + + aError = rtl_digest_updateMD5(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'pData' wrong", rtl_Digest_E_Argument, aError); + + aError = rtl_digest_updateMD5(aHandle, pData, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'nSize' wrong", rtl_Digest_E_None, aError); + + rtl_digest_destroyMD5(aHandle); + } + + void testGet() + { + rtlDigest aHandle; + rtlDigestError aError; + + aHandle = nullptr; + aError = rtl_digest_get(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument, aError); + + aHandle = nullptr; + aError = rtl_digest_getMD5(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("does not handle wrong parameter", rtl_Digest_E_Argument, aError); + + // test with wrong algorithm + aHandle = rtl_digest_create(rtl_Digest_AlgorithmMD2); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != nullptr); + + sal_uInt32 nKeyLen = rtl_digest_queryLength(aHandle); + std::unique_ptr<sal_uInt8[]> pKeyBuffer(new sal_uInt8[nKeyLen]); + + aError = rtl_digest_getMD5(aHandle, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle 2. parameter wrong", rtl_Digest_E_Argument, aError); + + aError = rtl_digest_getMD5(aHandle, pKeyBuffer.get(), 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'handle' wrong", rtl_Digest_E_Algorithm, aError); + + rtl_digest_destroyMD2(aHandle); + + aHandle = rtl_digest_create(rtl_Digest_AlgorithmMD5); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != nullptr); + + aError = rtl_digest_getMD5(aHandle, nullptr, nKeyLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'pData' wrong", rtl_Digest_E_Argument, aError); + + aError = rtl_digest_getMD5(aHandle, pKeyBuffer.get(), 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("handle parameter 'nSize' wrong", rtl_Digest_E_BufferSize, aError); + + rtl_digest_destroyMD5(aHandle); + } + + void testSHA1SumForBiggerInputData() + { + // The test data was extracted from oox encrypted document (salt + password). + // First case: 16 bytes salt + 34 bytes password (12345678901234567) + // Second case: 16 bytes salt + 36 bytes password (123456789012345678) + { + const unsigned char aData[] = { + 0x37, 0x5f, 0x47, 0x7a, 0xd2, 0x13, 0xbe, 0xd2, 0x3c, 0x23, 0x33, 0x39, + 0x68, 0x21, 0x03, 0x6d, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, + 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x30, 0x00, + 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, + 0x37, 0x00 + }; + + std::unique_ptr<sal_uInt8[]> pResult(new sal_uInt8[RTL_DIGEST_LENGTH_SHA1]); + + OString sExpected = "06f460d693aecdd3b5cbe8365408eccfc570f32a"; + + rtl_digest_SHA1(aData, sizeof(aData), pResult.get(), RTL_DIGEST_LENGTH_SHA1); + + OString sKey = createHex(pResult.get(), RTL_DIGEST_LENGTH_SHA1); + + CPPUNIT_ASSERT_EQUAL(sExpected, sKey); + } + + // tdf#114939, verify that rtl_digest_SHA1 computes broken results for certain input (which + // is not fixed for compatibility reasons): + { + sal_uInt8 result[RTL_DIGEST_LENGTH_SHA1]; + rtl_digest_SHA1( + RTL_CONSTASCII_STRINGPARAM("1012345678901234567890123456789012345678901234567890"), + result, RTL_DIGEST_LENGTH_SHA1); + // Rather than correct "9cb1dab34448c1ea460da1f8736869c8852f212f": + CPPUNIT_ASSERT_EQUAL( + OString("90a461ee9cc69cedaeb25c2dc5cc62544ebd5241"), + createHex(result, RTL_DIGEST_LENGTH_SHA1)); + } + } + + void testMD5() + { + unsigned char const data[] = { + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + }; + OString const expected[] = { + "d41d8cd98f00b204e9800998ecf8427e", + "cfcd208495d565ef66e7dff9f98764da", + "b4b147bc522828731f1a016bfa72c073", + "c6f057b86584942e415435ffb1fa93d4", + "4a7d1ed414474e4033ac29ccb8653d9b", + "dcddb75469b4b4875094e14561e573d8", + "670b14728ad9902aecba32e22fa4f6bd", + "29c3eea3f305d6b823f562ac4be35217", + "dd4b21e9ef71e1291183a46b913ae6f2", + "4c93008615c2d041e33ebac605d14b5b", + "f1b708bba17f1ce948dc979f4d7092bc", + "645a8aca5a5b84527c57ee2f153f1946", + "35b9ab5a36f3234dd26db357fd4a0dc1", + "4aad0d9ff11812ebdd5e376fdbef6222", + "c47532bbb1e2883c902071591ae1ec9b", + "5284047f4ffb4e04824a2fd1d1f0cd62", + "1e4a1b03d1b6cd8a174a826f76e009f4", + "0e7b9f29a828b6f953b482fc299e536b", + "3ea032bf79e8c116b05f4698d5a8e044", + "15f47c8a3e5e9685307dd65a653b8dc0", + "cc545187d0745132de1e9941db0ef6ce", + "0585e303e79acd837c3a3e2a2bec8b18", + "b28ccfdee4b9f39ba18b58a4f61a03d1", + "d018229b1183c926c10ea688350afec8", + "660719b4a7591769583a7c8d20c6dfa4", + "1e2432adacf481836265fcc62ee8f3e3", + "6e88e2af74c1d9d7d7d652b90d03751e", + "780ca685003cec1d617beaa6f346e1be", + "7f2e1dcfd6e2a3f5c38f31e640136ff6", + "1a3dee46117aeb8010cf365b8653faa8", + "1d0064395af3c745f6c3194e92373d7a", + "b52582043219f2deb2d3c9cb05d6448a", + "cd9e459ea708a948d5c2f5a6ca8838cf", + "00de800ecd7a4fb2813986c987e46d51", + "15336d4b38561a82bd24c9398b781aed", + "5fe699d3c461ab5a795505f59d5adf15", + "c5e0eb03cbb4bea95ce3f8f48fca77d5", + "355c1410373ef02fff2b03844d72c7d4", + "02df97da8207de2b3afa69c151ca8958", + "82c66dbf3e73f87ffc9564b2098d6a4f", + "b373e3ddc3438d7c10c76f3ad9d4c401", + "fac901a4a3dbc4461541731a33a31d15", + "f573e011b414bf3f9dd284f7dad29592", + "11694570cc5dda099669f2ba3660a70d", + "60997cc8aef7fedd9995e6b3ca89ce26", + "63c5fcf83c2275fe64e880dd8dfc5cd6", + "c7a0a100057ebbfc63ee169562026aea", + "42c2dec247919384edece38033458627", + "b505acf9fc996902b0c547a2abfc62b2", + "2fa7a1321d6b5fa0e04ad46785f574f3", + "86d2bfc0bab44eecf21e1432be7b3efc", + "7ca318f12a0955a3e637dc5645a2f96e", + "3eda02765b8fb8bb9b20c735f4537827", + "26dead12262c9a5c115b01e0a3c805b6", + "978b0444e93c5f7d714575f28a77dca1", + "d7fe636bd28e2ee2ba4d6c5898318699", + "ce992c2ad906967c63c3f9ab0c2294a9", + "1f3b814e9d417e9fd8750299982feb1f", + "1a2f42174eaa78ce6a67d75e98a59cb6", + "17c772c45c9a09f6e56b7228ddd161a7", + "5b19445b70b493c78f3bc06eb7962315", + "e590c24cc612bdedd522dfe23bb29b42", + "4d78c699a0167bc0cfce8a5c5a715c0e", + "5703db92acb9d45e3975822c9206453f", + "10eab6008d5642cf42abd2aa41f847cb", + }; + rtlDigest digest = rtl_digest_createMD5(); + for (size_t i = 0; i < sizeof(data); ++i) + { + rtl_digest_updateMD5(digest, &data, i); + sal_uInt8 buf[RTL_DIGEST_LENGTH_MD5]; + rtl_digest_getMD5(digest, &buf[0], sizeof(buf)); + OString const sResult = createHex(&buf[0], sizeof(buf)); + CPPUNIT_ASSERT_EQUAL(expected[i], sResult); + } + rtl_digest_destroyMD5(digest); + } + + CPPUNIT_TEST_SUITE(DigestTest); + CPPUNIT_TEST(testCreate); + CPPUNIT_TEST(testQuery); + CPPUNIT_TEST(testQueryLength); + CPPUNIT_TEST(testInit); + CPPUNIT_TEST(testEqual); + CPPUNIT_TEST(testCheckSum); + CPPUNIT_TEST(testPBKDF2); + CPPUNIT_TEST(testUpdate); + CPPUNIT_TEST(testGet); + CPPUNIT_TEST(testSHA1SumForBiggerInputData); + CPPUNIT_TEST(testMD5); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DigestTest); + +} // namespace rtl_digest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/doublelock/rtl_doublelocking.cxx b/sal/qa/rtl/doublelock/rtl_doublelocking.cxx new file mode 100644 index 000000000..ef639423d --- /dev/null +++ b/sal/qa/rtl/doublelock/rtl_doublelocking.cxx @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <iostream> + +#include <sal/types.h> + +#include <osl/thread.hxx> + +#include <rtl/instance.hxx> +#include <rtl/ustring.hxx> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#else +#include <unistd.h> +#include <time.h> +#endif + +#define CONST_TEST_STRING "gregorian" + +namespace { +struct Gregorian : public rtl::StaticWithInit<OUString, Gregorian> { + OUString operator () () { + return CONST_TEST_STRING; + } +}; + +/** Simple thread for testing Thread-create. + * Just add 1 of value 0, and after running, result is 1. + */ +class OGetThread : public osl::Thread +{ + osl::Mutex m_mutex; + sal_Int32 m_nOK; + sal_Int32 m_nFails; + + OUString m_sConstStr; +public: + OGetThread() + :m_nOK(0), + m_nFails(0), + m_sConstStr(CONST_TEST_STRING) + { + } + + sal_Int32 getOK() { osl::MutexGuard g(m_mutex); return m_nOK; } + sal_Int32 getFails() {osl::MutexGuard g(m_mutex); return m_nFails;} + +protected: + + /** guarded value which initialized 0 + + @see ThreadSafeValue + */ + void SAL_CALL run() override + { + for (int i = 0; i != 5; ++i) + { + OUString aStr = Gregorian::get(); + if (aStr == m_sConstStr) + { + osl::MutexGuard g(m_mutex); + m_nOK++; + } + else + { + osl::MutexGuard g(m_mutex); + m_nFails++; + } + } + } + +public: + + virtual ~OGetThread() override + { + if (isRunning()) + { + printf("error: not terminated.\n"); + } + } +}; + +} + +namespace rtl_DoubleLocking +{ + +/** Test of the osl::Thread::create method + */ + + class getValue : public CppUnit::TestFixture + { + public: + + void getValue_001() + { + OUString aStr = Gregorian::get(); + + CPPUNIT_ASSERT_MESSAGE( + "Gregorian::get() failed, wrong value expected.", + !aStr.isEmpty() + ); + } + + /** check 2 threads. + + ALGORITHM: + Here the function should show, that 2 different threads, + which only increase a value, should run at the same time with same prio. + The test fails, if the difference between the two values is more than 5% + but IMHO this isn't a failure, it's only a feature of the OS. + */ + + void getValue_002() + { + // initial 5 threads with different priorities + OGetThread* pThread = new OGetThread(); + OGetThread* p2Thread = new OGetThread(); + + //Create them and start running at the same time + pThread->create(); + p2Thread->create(); + + pThread->join(); + p2Thread->join(); + + sal_Int32 nValueOK = pThread->getOK(); + + sal_Int32 nValueOK2 = p2Thread->getOK(); + + std::cout << "Value in Thread #1 is " << nValueOK << "\n"; + std::cout << "Value in Thread #2 is " << nValueOK2 << "\n"; + sal_Int32 nValueFails = pThread->getFails(); + + sal_Int32 nValueFails2 = p2Thread->getFails(); + + delete pThread; + delete p2Thread; + + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nValueOK); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nValueOK2); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nValueFails); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nValueFails2); + } + + CPPUNIT_TEST_SUITE(getValue); + CPPUNIT_TEST(getValue_001); + CPPUNIT_TEST(getValue_002); + CPPUNIT_TEST_SUITE_END(); + }; // class create + + CPPUNIT_TEST_SUITE_REGISTRATION(rtl_DoubleLocking::getValue); +} // namespace rtl_DoubleLocking + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/locale/rtl_locale.cxx b/sal/qa/rtl/locale/rtl_locale.cxx new file mode 100644 index 000000000..27e30db9f --- /dev/null +++ b/sal/qa/rtl/locale/rtl_locale.cxx @@ -0,0 +1,280 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <rtl/locale.h> +#include <rtl/ustring.hxx> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +namespace rtl_locale +{ + // default locale for test purpose + static void setDefaultLocale() + { + rtl_locale_setDefault(OUString("de").getStr(), OUString("DE").getStr(), /* OUString() */ OUString("hochdeutsch").getStr() ); + } + +class getDefault : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + void getDefault_001() + { + rtl_Locale* pData = rtl_locale_getDefault(); + CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != nullptr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getDefault); + CPPUNIT_TEST(getDefault_001); + CPPUNIT_TEST_SUITE_END(); +}; // class getDefault + +class setDefault : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + void tearDown() override + { + setDefaultLocale(); + } + + // insert your test code here. + void setDefault_001() + { + rtl_locale_setDefault(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr()); + rtl_Locale* pData = rtl_locale_getDefault(); + CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != nullptr); + + // be sure to not GPF + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(setDefault); + CPPUNIT_TEST(setDefault_001); + CPPUNIT_TEST_SUITE_END(); +}; // class setDefault + +class getLanguage : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + // insert your test code here. + void getLanguage_001() + { + rtl_Locale* pData = rtl_locale_getDefault(); + OUString suLanguage = pData->Language; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale language must be 'de'", OUString("de"), suLanguage ); + } + void getLanguage_002() + { + rtl_Locale* pData = rtl_locale_getDefault(); + OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale language must be 'de'", OUString("de"), suLanguage ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getLanguage); + CPPUNIT_TEST(getLanguage_001); + CPPUNIT_TEST(getLanguage_002); + CPPUNIT_TEST_SUITE_END(); +}; // class getLanguage + +class getCountry : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + // insert your test code here. + void getCountry_001() + { + rtl_Locale* pData = rtl_locale_getDefault(); + OUString suCountry = pData->Country; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale country must be 'DE'", OUString("DE"), suCountry ); + } + void getCountry_002() + { + rtl_Locale* pData = rtl_locale_getDefault(); + OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale country must be 'DE'", OUString("DE"), suCountry ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getCountry); + CPPUNIT_TEST(getCountry_001); + CPPUNIT_TEST(getCountry_002); + CPPUNIT_TEST_SUITE_END(); +}; // class getCountry + +class getVariant : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + // insert your test code here. + void getVariant_001() + { + rtl_Locale* pData = rtl_locale_getDefault(); + OUString suVariant = pData->Variant; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale variant must be 'hochdeutsch'", OUString("hochdeutsch"), suVariant ); + } + void getVariant_002() + { + rtl_Locale* pData = rtl_locale_getDefault(); + OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale variant must be 'hochdeutsch'", OUString("hochdeutsch"), suVariant ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getVariant); + CPPUNIT_TEST(getVariant_001); + CPPUNIT_TEST(getVariant_002); + CPPUNIT_TEST_SUITE_END(); +}; // class getVariant + +class hashCode : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + // insert your test code here. + void hashCode_001() + { + rtl_Locale* pData = rtl_locale_getDefault(); + sal_Int32 nHashCode = pData->HashCode; + CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); + } + void hashCode_002() + { + rtl_Locale* pData = rtl_locale_getDefault(); + sal_Int32 nHashCode = rtl_locale_hashCode(pData); + CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(hashCode); + CPPUNIT_TEST(hashCode_001); + CPPUNIT_TEST(hashCode_002); + CPPUNIT_TEST_SUITE_END(); +}; // class hashCode + +class equals : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() override + { + // start message + rtl_locale::setDefaultLocale(); + } + + // insert your test code here. + void equals_001() + { + rtl_Locale* pData1 = rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr()); + rtl_Locale* pData2 = rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr()); + + bool bLocaleAreEqual = (pData1 == pData2); + + CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual); + } + + void equals_002() + { + rtl_Locale* pData1 = rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr()); + rtl_Locale* pData2 = rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr()); + + sal_Int32 nEqual = rtl_locale_equals(pData1, pData2); + CPPUNIT_ASSERT(nEqual != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(equals); + CPPUNIT_TEST(equals_001); + CPPUNIT_TEST(equals_002); + CPPUNIT_TEST_SUITE_END(); +}; // class equals + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::equals); +} // namespace rtl_locale + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx new file mode 100644 index 000000000..4843d66c2 --- /dev/null +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -0,0 +1,527 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <rtl/math.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <limits> + +CPPUNIT_NS_BEGIN + +template<> struct assertion_traits<rtl_math_ConversionStatus> +{ + static bool equal( const rtl_math_ConversionStatus& x, const rtl_math_ConversionStatus& y ) + { + return x == y; + } + + static std::string toString( const rtl_math_ConversionStatus& x ) + { + OStringStream ost; + ost << static_cast<unsigned int>(x); + return ost.str(); + } +}; + +CPPUNIT_NS_END + +namespace { + +class Test: public CppUnit::TestFixture { +public: + void test_stringToDouble_good() { + rtl_math_ConversionStatus status; + sal_Int32 end; + double res = rtl::math::stringToDouble( + OUString(" +1.E01foo"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(RTL_CONSTASCII_LENGTH(" +1.E01"), end); + CPPUNIT_ASSERT_EQUAL(10.0, res); + + res = rtl::math::stringToDouble( + OUString("NaN"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end); + CPPUNIT_ASSERT(std::isnan(res)); + + res = rtl::math::stringToDouble( + OUString("NaN1.23"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end); + CPPUNIT_ASSERT(std::isnan(res)); + + res = rtl::math::stringToDouble( + OUString("INF"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end); + CPPUNIT_ASSERT(std::isinf(res)); + + res = rtl::math::stringToDouble( + OUString("INF1.23"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end); + CPPUNIT_ASSERT(std::isinf(res)); + + res = rtl::math::stringToDouble( + OUString(".5"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end); + CPPUNIT_ASSERT_EQUAL(0.5, res); + + res = rtl::math::stringToDouble( + OUString("5."), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end); + CPPUNIT_ASSERT_EQUAL(5.0, res); + + // Leading 0 and group separator. + res = rtl::math::stringToDouble( + OUString("0,123"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end); + CPPUNIT_ASSERT_EQUAL(123.0, res); + + // Leading 0 and two consecutive group separators are none. + res = rtl::math::stringToDouble( + OUString("0,,1"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Leading 0 and group separator at end is none. + res = rtl::math::stringToDouble( + OUString("0,"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Leading 0 and group separator before non-digit is none. + res = rtl::math::stringToDouble( + OUString("0,x"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Trailing group separator is none. + res = rtl::math::stringToDouble( + OUString("1,234,"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end); + CPPUNIT_ASSERT_EQUAL(1234.0, res); + + // Group separator followed by non-digit is none. + res = rtl::math::stringToDouble( + OUString("1,234,x"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end); + CPPUNIT_ASSERT_EQUAL(1234.0, res); + + // Check that the value is the nearest double-precision representation of the decimal 0.0042 + // (it was 0.0042000000000000006 instead of 0.0041999999999999997) + res = rtl::math::stringToDouble(OUString("0,0042"), ',', ' ', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(0.0042, res); + + // "- 1" is nothing + res = rtl::math::stringToDouble(OUString("- 1"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // "-1E+E" : no exponent + res = rtl::math::stringToDouble(OUString("-1E+E"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end); + CPPUNIT_ASSERT_EQUAL(-1.0, res); + + // "-0" is negative zero + res = rtl::math::stringToDouble(OUString("-0"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + CPPUNIT_ASSERT(std::signbit(res)); + + // Compensating: "0.001E311" is 1E308, not overflow/inf + res = rtl::math::stringToDouble(OUString("0.001E311"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(9), end); + CPPUNIT_ASSERT_EQUAL(1E308, res); + + res = rtl::math::stringToDouble(OUString("1E8589934590"), '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(12), end); + CPPUNIT_ASSERT_EQUAL(std::numeric_limits<double>::infinity(), res); + } + + void test_stringToDouble_bad() { + rtl_math_ConversionStatus status; + sal_Int32 end; + double res = rtl::math::stringToDouble( + OUString(" +Efoo"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + res = rtl::math::stringToDouble( + OUString("."), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + res = rtl::math::stringToDouble( + OUString(" +.Efoo"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + res = rtl::math::stringToDouble( + OUString(" +,.Efoo"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Leading group separator is none. + res = rtl::math::stringToDouble( + OUString(",1234"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + } + + void test_stringToDouble_exponent_without_digit() { + rtl_math_ConversionStatus status; + sal_Int32 end; + double res = rtl::math::stringToDouble( + OUString("1e"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(RTL_CONSTASCII_LENGTH("1"), end); + CPPUNIT_ASSERT_EQUAL(1.0, res); + res = rtl::math::stringToDouble( + OUString("0e"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(RTL_CONSTASCII_LENGTH("1"), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + } + + void test_doubleToString() { + double fVal = 999999999999999.0; + sal_Int32 aGroups[3] = { 3, 2, 0 }; + OUString aRes( rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, + '.', aGroups, ',', true)); + CPPUNIT_ASSERT_EQUAL( OUString("99,99,99,99,99,99,999"), aRes); + + fVal = 949.0; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + -2, // round before decimals + '.', aGroups, ',', true); + CPPUNIT_ASSERT_EQUAL( OUString("900"), aRes); + + fVal = 950.0; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + -2, // round before decimals + '.', aGroups, ',', true); + CPPUNIT_ASSERT_EQUAL( OUString("1,000"), aRes); + + fVal = 4503599627370495.0; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.'); + CPPUNIT_ASSERT_EQUAL( OUString("4503599627370495"), aRes); + + fVal = 4503599627370496.0; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + 2, '.'); + CPPUNIT_ASSERT_EQUAL( OUString("4503599627370496.00"), aRes); + + fVal = 9007199254740991.0; // (2^53)-1 + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("9007199254740991"), aRes); + + fVal = 9007199254740992.0; // (2^53), algorithm switch + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("9.00719925474099E+015"), aRes); + + fVal = 9007199254740993.0; // (2^53)+1 would be but is 9007199254740992 + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("9.00719925474099E+015"), aRes); + + // Test rtl_math_StringFormat_G + + fVal = 0.001234567; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("0.00123"), aRes); + + fVal = 123.4567; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("123"), aRes); + + fVal = 123.4567; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 4, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("123.5"), aRes); + + fVal = 99.6; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("99.6"), aRes); + + // Expected could be 1E+03 (as 999.6 rounded to 3 significant digits + // results in 1000 with an exponent equal to significant digits). + // Currently we don't and output 1000 instead, negligible. + fVal = 999.6; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1000"), aRes); + + fVal = 9999.6; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, 3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1E+004"), aRes); + + fVal = 12345.6789; + aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_G, -3, '.', true); + CPPUNIT_ASSERT_EQUAL( OUString("1.2E+004"), aRes); + } + + void test_approx() { + // (2^53)-1 , (2^53)-3 + CPPUNIT_ASSERT_EQUAL( false, rtl::math::approxEqual( 9007199254740991.0, 9007199254740989.0)); + // (2^53)-1 , (2^53)-2 + CPPUNIT_ASSERT_EQUAL( false, rtl::math::approxEqual( 9007199254740991.0, 9007199254740990.0)); + // Note: the following are internally represented as 900719925474099.12 + // and 900719925474098.88 and the difference is 0.25 ... + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 900719925474099.1, 900719925474098.9)); + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 72.944444444444443, 72.9444444444444)); + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 359650.27322404372, 359650.27322404401)); + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 5.3590326375710063e+238, 5.3590326375710109e+238)); + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 7.4124095894894475e+158, 7.4124095894894514e+158)); + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 1.2905754687023132e+79, 1.2905754687023098e+79)); + CPPUNIT_ASSERT_EQUAL( true, rtl::math::approxEqual( 3.5612905090455637e+38, 3.5612905090455599e+38)); + // 0.3 - 0.2 - 0.1 == 0.0 + CPPUNIT_ASSERT_EQUAL( 0.0, rtl::math::approxSub( rtl::math::approxSub( 0.3, 0.2), 0.1)); + // ((2^53)-1) - ((2^53)-2) == 1.0 + CPPUNIT_ASSERT_EQUAL( 1.0, rtl::math::approxSub( 9007199254740991.0, 9007199254740990.0)); + // (3^31) - ((3^31)-1) == 1.0 + CPPUNIT_ASSERT_EQUAL( 1.0, rtl::math::approxSub( 617673396283947.0, 617673396283946.0)); + } + + void test_erf() { + double x, res; + x = 0.0; + res = rtl::math::erf(x); + CPPUNIT_ASSERT_EQUAL(0.0,res); + rtl::math::setInf( &x, false); + res = rtl::math::erf(x); + CPPUNIT_ASSERT_EQUAL(1.0,res); + rtl::math::setInf( &x, true); + res = rtl::math::erf(x); + CPPUNIT_ASSERT_EQUAL(-1.0,res); + rtl::math::setNan( &x); + res = rtl::math::erf(x); + CPPUNIT_ASSERT(std::isnan(res)); + x = 3.0; + res = rtl::math::erf(-x); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -rtl::math::erf(x), res, 1E-12); + } + + void test_erfc() { + double x, res; + x = 0.0; + res = rtl::math::erfc(x); + CPPUNIT_ASSERT_EQUAL(1.0,res); + rtl::math::setInf( &x, false); + res = rtl::math::erfc(x); + CPPUNIT_ASSERT_EQUAL(0.0,res); + rtl::math::setInf( &x, true); + res = rtl::math::erfc(x); + CPPUNIT_ASSERT_EQUAL(2.0,res); + rtl::math::setNan( &x); + res = rtl::math::erfc(x); + CPPUNIT_ASSERT(std::isnan(res)); + x = 3.0; + res = rtl::math::erfc(-x); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0 - rtl::math::erfc(x), res, 1E-12); + } + + void test_expm1() { + double x, res; + x = 0.0; + res = rtl::math::expm1(x); + CPPUNIT_ASSERT_EQUAL(0.0,res); + x = -0.0; + res = rtl::math::expm1(x); + CPPUNIT_ASSERT_EQUAL(-0.0,res); + CPPUNIT_ASSERT(std::signbit(res)); + rtl::math::setInf( &x, false); + res = rtl::math::expm1(x); + CPPUNIT_ASSERT_EQUAL(true, std::isinf(res) && !std::signbit(res)); + rtl::math::setInf( &x, true); + res = rtl::math::expm1(x); + CPPUNIT_ASSERT_EQUAL(-1.0,res); + rtl::math::setNan( &x); + res = rtl::math::expm1(x); + CPPUNIT_ASSERT(std::isnan(res)); + } + + void test_log1p() { + double x, res; + x = 0.0; + res = rtl::math::log1p(x); + CPPUNIT_ASSERT_EQUAL(0.0,res); + x = -0.0; + res = rtl::math::log1p(x); + CPPUNIT_ASSERT_EQUAL(-0.0,res); + CPPUNIT_ASSERT(std::signbit(res)); + rtl::math::setInf( &x, false); + res = rtl::math::log1p(x); + CPPUNIT_ASSERT_EQUAL(true, std::isinf(res) && !std::signbit(res)); + x = -1.0; + res = rtl::math::log1p(x); + CPPUNIT_ASSERT_EQUAL(true, std::isinf(res) && std::signbit(res)); + x = -1.1; + res = rtl::math::log1p(x); + CPPUNIT_ASSERT(std::isnan(res)); + rtl::math::setInf( &x, true); + res = rtl::math::log1p(x); + CPPUNIT_ASSERT(std::isnan(res)); + rtl::math::setNan( &x); + res = rtl::math::log1p(x); + CPPUNIT_ASSERT(std::isnan(res)); + } + + void test_acosh() { + double res; + + res = rtl::math::acosh(-1.0); // NaN + CPPUNIT_ASSERT(std::isnan(res)); + + res = rtl::math::acosh(0.0); // NaN + CPPUNIT_ASSERT(std::isnan(res)); + + res = rtl::math::acosh(0.5); // NaN + CPPUNIT_ASSERT(std::isnan(res)); + + CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::acosh(1.0)); + + res = rtl::math::acosh(std::numeric_limits<double>::infinity()); // +Inf + CPPUNIT_ASSERT(!std::signbit(res)); + CPPUNIT_ASSERT(std::isinf(res)); + + // #i97605 + CPPUNIT_ASSERT_DOUBLES_EQUAL(692.56728736744176, rtl::math::acosh(3e+300), 1e-15); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.014142017775252324, rtl::math::acosh(1.0001), 1e-15); + } + + void test_asinh() { + double res; + + res = rtl::math::asinh(-std::numeric_limits<double>::infinity()); // -Inf + CPPUNIT_ASSERT(std::signbit(res)); + CPPUNIT_ASSERT(std::isinf(res)); + + CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::asinh(0.0)); + + res = rtl::math::asinh(std::numeric_limits<double>::infinity()); // +Inf + CPPUNIT_ASSERT(!std::signbit(res)); + CPPUNIT_ASSERT(std::isinf(res)); + + // #i97605 + CPPUNIT_ASSERT_DOUBLES_EQUAL(691.67568924815798, rtl::math::asinh(1.23e+300), 1e-15); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0350378961923076, rtl::math::asinh(1.23), 1e-16); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.23e-300, rtl::math::asinh(1.23e-300), 1e-303); + + // asinh is an odd function + CPPUNIT_ASSERT_EQUAL(-rtl::math::asinh(1.23e+300), rtl::math::asinh(-1.23e+300)); + CPPUNIT_ASSERT_EQUAL(-rtl::math::asinh(1.23), rtl::math::asinh(-1.23)); + CPPUNIT_ASSERT_EQUAL(-rtl::math::asinh(1.23e-300), rtl::math::asinh(-1.23e-300)); + } + + void test_atanh() { + double res; + + res = rtl::math::atanh(-2.0); // NaN + CPPUNIT_ASSERT(std::isnan(res)); + + res = rtl::math::atanh(-1.0); // -Inf + CPPUNIT_ASSERT(std::signbit(res)); + CPPUNIT_ASSERT(std::isinf(res)); + + CPPUNIT_ASSERT_EQUAL(0.0, rtl::math::atanh(0.0)); + + res = rtl::math::atanh(1.0); // +Inf + CPPUNIT_ASSERT(!std::signbit(res)); + CPPUNIT_ASSERT(std::isinf(res)); + + res = rtl::math::atanh(2.0); // NaN + CPPUNIT_ASSERT(std::isnan(res)); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test_stringToDouble_good); + CPPUNIT_TEST(test_stringToDouble_bad); + CPPUNIT_TEST(test_stringToDouble_exponent_without_digit); + CPPUNIT_TEST(test_doubleToString); + CPPUNIT_TEST(test_erf); + CPPUNIT_TEST(test_erfc); + CPPUNIT_TEST(test_expm1); + CPPUNIT_TEST(test_log1p); + CPPUNIT_TEST(test_approx); + CPPUNIT_TEST(test_acosh); + CPPUNIT_TEST(test_asinh); + CPPUNIT_TEST(test_atanh); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/ostring/rtl_OString2.cxx b/sal/qa/rtl/ostring/rtl_OString2.cxx new file mode 100644 index 000000000..204475084 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_OString2.cxx @@ -0,0 +1,508 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/string.hxx> + +#include "valueequal.hxx" + +namespace rtl_OString +{ + +class valueOf : public CppUnit::TestFixture +{ + void valueOf_float_test_impl(float _nValue) + { + OString sValue; + sValue = OString::valueOf( _nValue ); + printf("nFloat := %.9f sValue := %s\n", _nValue, sValue.getStr()); + + float nValueATOF = static_cast<float>(atof( sValue.getStr() )); + + bool bEqualResult = is_float_equal(_nValue, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void valueOf_float_test(float _nValue) + { + valueOf_float_test_impl(_nValue); + + // test also the negative part. + float nNegativeValue = -_nValue; + valueOf_float_test_impl(nNegativeValue); + } + +public: + // insert your test code here. + void valueOf_float_test_001() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + float nValue = 3.0f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_002() + { + float nValue = 3.5f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_003() + { + float nValue = 3.0625f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_004() + { + float nValue = 3.502525f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_005() + { + float nValue = 3.141592f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_006() + { + float nValue = 3.5025255f; + valueOf_float_test(nValue); + } + + void valueOf_float_test_007() + { + float nValue = 3.0039062f; + valueOf_float_test(nValue); + } + +private: + + void valueOf_double_test_impl(double _nValue) + { + OString sValue; + sValue = OString::valueOf( _nValue ); + printf("nDouble := %.20f sValue := %s\n", _nValue, sValue.getStr()); + + double nValueATOF = atof( sValue.getStr() ); + + bool bEqualResult = is_double_equal(_nValue, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void valueOf_double_test(double _nValue) + { + valueOf_double_test_impl(_nValue); + + // test also the negative part. + double nNegativeValue = -_nValue; + valueOf_double_test_impl(nNegativeValue); + } +public: + + // valueOf double + void valueOf_double_test_001() + { + double nValue = 3.0; + valueOf_double_test(nValue); + } + void valueOf_double_test_002() + { + double nValue = 3.5; + valueOf_double_test(nValue); + } + void valueOf_double_test_003() + { + double nValue = 3.0625; + valueOf_double_test(nValue); + } + void valueOf_double_test_004() + { + double nValue = 3.1415926535; + valueOf_double_test(nValue); + } + void valueOf_double_test_005() + { + double nValue = 3.141592653589793; + valueOf_double_test(nValue); + } + void valueOf_double_test_006() + { + double nValue = 3.1415926535897932; + valueOf_double_test(nValue); + } + void valueOf_double_test_007() + { + double nValue = 3.14159265358979323; + valueOf_double_test(nValue); + } + void valueOf_double_test_008() + { + double nValue = 3.141592653589793238462643; + valueOf_double_test(nValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(valueOf); + CPPUNIT_TEST(valueOf_float_test_001); + CPPUNIT_TEST(valueOf_float_test_002); + CPPUNIT_TEST(valueOf_float_test_003); + CPPUNIT_TEST(valueOf_float_test_004); + CPPUNIT_TEST(valueOf_float_test_005); + CPPUNIT_TEST(valueOf_float_test_006); + CPPUNIT_TEST(valueOf_float_test_007); + + CPPUNIT_TEST(valueOf_double_test_001); + CPPUNIT_TEST(valueOf_double_test_002); + CPPUNIT_TEST(valueOf_double_test_003); + CPPUNIT_TEST(valueOf_double_test_004); + CPPUNIT_TEST(valueOf_double_test_005); + CPPUNIT_TEST(valueOf_double_test_006); + CPPUNIT_TEST(valueOf_double_test_007); + CPPUNIT_TEST(valueOf_double_test_008); + CPPUNIT_TEST_SUITE_END(); +}; // class valueOf + +// - toDouble (tests) + +class toDouble : public CppUnit::TestFixture +{ + +public: + + toDouble() + { + // testPrecision a; + } + + void toDouble_test_impl(OString const& _sValue) + { + double nValueATOF = atof( _sValue.getStr() ); + + // OUString suValue = OUString::createFromAscii( _sValue.getStr() ); + double nValueToDouble = _sValue.toDouble(); + + bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void toDouble_test(OString const& _sValue) + { + toDouble_test_impl(_sValue); + + // test also the negative part. + OString sNegativValue("-"); + sNegativValue += _sValue; + toDouble_test_impl(sNegativValue); + } + + // insert your test code here. + void toDouble_selftest() + { + printf("Start selftest:\n"); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.01) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000001) == false); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000001) == false); + // we check til 14 values after comma + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001) == true); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001) == true); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001) == true); + printf("Selftest done.\n"); + } + + void toDouble_test_3() + { + OString sValue("3"); + toDouble_test(sValue); + } + void toDouble_test_3_5() + { + OString sValue("3.5"); + toDouble_test(sValue); + } + void toDouble_test_3_0625() + { + OString sValue("3.0625"); + toDouble_test(sValue); + } + void toDouble_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + OString sValue("3.141592653589793238462643383279502884197169399375"); + toDouble_test(sValue); + } + + void toDouble_test_1() + { + OString sValue("1"); + toDouble_test(sValue); + } + void toDouble_test_10() + { + OString sValue("10"); + toDouble_test(sValue); + } + void toDouble_test_100() + { + OString sValue("100"); + toDouble_test(sValue); + } + void toDouble_test_1000() + { + OString sValue("1000"); + toDouble_test(sValue); + } + void toDouble_test_10000() + { + OString sValue("10000"); + toDouble_test(sValue); + } + void toDouble_test_1e99() + { + OString sValue("1e99"); + toDouble_test(sValue); + } + void toDouble_test_1e_n99() + { + OString sValue("1e-99"); + toDouble_test(sValue); + } + void toDouble_test_1e308() + { + OString sValue("1e308"); + toDouble_test(sValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toDouble); + CPPUNIT_TEST(toDouble_selftest); + + CPPUNIT_TEST(toDouble_test_3); + CPPUNIT_TEST(toDouble_test_3_5); + CPPUNIT_TEST(toDouble_test_3_0625); + CPPUNIT_TEST(toDouble_test_pi); + CPPUNIT_TEST(toDouble_test_1); + CPPUNIT_TEST(toDouble_test_10); + CPPUNIT_TEST(toDouble_test_100); + CPPUNIT_TEST(toDouble_test_1000); + CPPUNIT_TEST(toDouble_test_10000); + CPPUNIT_TEST(toDouble_test_1e99); + CPPUNIT_TEST(toDouble_test_1e_n99); + CPPUNIT_TEST(toDouble_test_1e308); + CPPUNIT_TEST_SUITE_END(); +}; // class toDouble + +// - getToken (tests) + +class getToken : public CppUnit::TestFixture +{ + +public: + void getToken_000() + { + OString sTokenStr; + + sal_Int32 nIndex = 0; + do + { + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + } + while ( nIndex >= 0 ); + // printf("Index %d\n", nIndex); + // should not GPF + } + + void getToken_001() + { + OString sTokenStr = "a;b"; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_002() + { + OString sTokenStr = "a;b.c"; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'c'", sToken.equals("c") == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_003() + { + OString sTokenStr = "a;;b"; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", sToken.isEmpty()); + + /* OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_004() + { + OString sTokenStr = "longer.then.ever."; + + sal_Int32 nIndex = 0; + + OString sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'longer'", sToken.equals("longer") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'then'", sToken.equals("then") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'ever'", sToken.equals("ever") == sal_True); + + /* OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", sToken.isEmpty()); + + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + CPPUNIT_TEST_SUITE(getToken); + CPPUNIT_TEST(getToken_000); + CPPUNIT_TEST(getToken_001); + CPPUNIT_TEST(getToken_002); + CPPUNIT_TEST(getToken_003); + CPPUNIT_TEST(getToken_004); + CPPUNIT_TEST_SUITE_END(); +}; // class getToken + +// testing the method replaceAt( sal_Int32 index, sal_Int32 count, +// const OString& newStr ) + +// Developer note: Mindy Liu, 2004-04-23 +// stolen from sal/qa/rtl_strings/rtl_OString.cxx + +class replaceAt : public CppUnit::TestFixture +{ + +public: + sal_Bool check_replaceAt( const OString* expVal, const OString* input, + const OString* newStr, sal_Int32 index, sal_Int32 count) + { + OString aStr1; + aStr1= input->replaceAt( index, count, *newStr ); + + printf("the result OString is %s#\n", aStr1.getStr() ); + + sal_Bool bRes = ( expVal->compareTo(aStr1) == 0 ); + return bRes; + } + + void replaceAt_001() + { + sal_Bool bRes = check_replaceAt(new OString("Java@Sun"), + new OString("Sun java"), new OString("Java@Sun"), 0, 8 ); + CPPUNIT_ASSERT_MESSAGE("string differs, replace whole string", bRes == sal_True); + } + + void replaceAt_002() + { + sal_Bool bRes = check_replaceAt(new OString("Sun Java desktop system"), + new OString("Sun "), new OString("Java desktop system"), 10, 8 ); + CPPUNIT_ASSERT_MESSAGE("index > length of input string", bRes == sal_True); + } + + void replaceAt_003() + { + sal_Bool bRes = check_replaceAt(new OString("SuJava desktop system"), + new OString("Sun "), new OString("Java desktop system"), 2, 64 ); + CPPUNIT_ASSERT_MESSAGE("larger count", bRes == sal_True); + } + + void replaceAt_004() + { + + sal_Bool bRes = check_replaceAt(new OString("Java desktop system"), + new OString("Sun "), new OString("Java desktop system"), -4, 8 ); + CPPUNIT_ASSERT_MESSAGE("navigate index", bRes == sal_True); + } + void replaceAt_005() + { + + sal_Bool bRes = check_replaceAt(new OString("Sun Jesktop System"), + new OString("Sun Java Desktop System"), new OString(""), 5, 5 ); + CPPUNIT_ASSERT_MESSAGE("replace with null string", bRes == sal_True); + } + + CPPUNIT_TEST_SUITE(replaceAt); + CPPUNIT_TEST(replaceAt_001); + CPPUNIT_TEST(replaceAt_002); + CPPUNIT_TEST(replaceAt_003); + CPPUNIT_TEST(replaceAt_004); + CPPUNIT_TEST(replaceAt_005); + CPPUNIT_TEST_SUITE_END(); +}; // class replaceAt + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::valueOf); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::toDouble); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::getToken); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OString::replaceAt); + +} // namespace rtl_OString + +// this macro creates an empty function, which will called by the RegisterAllFunctions() +// to let the user the possibility to also register some functions by hand. +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx new file mode 100644 index 000000000..7cfabcab7 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_str.cxx @@ -0,0 +1,849 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/string.hxx> +#include <cstring> + +namespace rtl_str +{ + + class compare : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_str_compare( NULL, NULL); + } + + void compare_000_1() + { + OString aStr1 = "Line must be equal."; + rtl_str_compare( aStr1.getStr(), NULL); + } + void compare_001() + { + OString aStr1 = ""; + OString aStr2 = ""; + + sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_003() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(compare); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST_SUITE_END(); +}; // class compare + + class compareIgnoreAsciiCase : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_str_compareIgnoreAsciiCase( NULL, NULL); + } + + void compare_000_1() + { + OString aStr1 = "Line must be equal."; + rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + } + void compare_001() + { + OString aStr1 = ""; + OString aStr2 = ""; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002_1() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "LINE MUST BE EQUAL."; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + } + + void compare_003() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_002_1); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST_SUITE_END(); + }; // class compareIgnoreAsciiCase + + class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0); + } + + void compare_000_1() + { + OString aStr1 = "Line must be equal."; + rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); + } + void compare_001() + { + OString aStr1 = ""; + OString aStr2 = ""; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002_1() + { + OString aStr1 = "Line must be equal."; + OString aStr2 = "LINE MUST BE EQUAL."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + } + + void compare_003() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + 5); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0); + } + + void compare_004() + { + OString aStr1 = "Line must differ."; + OString aStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_002_1); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST(compare_004); + CPPUNIT_TEST_SUITE_END(); +}; // class compare + + class hashCode : public CppUnit::TestFixture + { + public: + + void hashCode_000() + { + rtl_str_hashCode( NULL ); + } + + void hashCode_001() + { + OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() ); + printf("hashcode: %d\n", nHashCode); + // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0); + } + + void hashCode_002() + { + OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() ); + + OString aStr2 = "Line for a hashCode."; + sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 ); + } + + void hashCode_003() + { + OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() ); + + OString aStr2 = "Line for another hashcode."; + sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(hashCode); + CPPUNIT_TEST(hashCode_000); + CPPUNIT_TEST(hashCode_001); + CPPUNIT_TEST(hashCode_002); + CPPUNIT_TEST(hashCode_003); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class indexOfChar : public CppUnit::TestFixture + { + public: + + void indexOfChar_000() + { + rtl_str_indexOfChar( NULL, 0 ); + } + + void indexOfChar_001() + { + OString aStr1 = "Line for an indexOfChar."; + + sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1); + + /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2); + + /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3); + } + + void indexOfChar_002() + { + OString aStr1 = "Line for an indexOfChar."; + sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(indexOfChar); + CPPUNIT_TEST(indexOfChar_000); + CPPUNIT_TEST(indexOfChar_001); + CPPUNIT_TEST(indexOfChar_002); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class lastIndexOfChar : public CppUnit::TestFixture + { + public: + + void lastIndexOfChar_000() + { + rtl_str_lastIndexOfChar( NULL, 0 ); + } + + void lastIndexOfChar_001() + { + OString aStr1 = "Line for a lastIndexOfChar."; + + sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22); + + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23); + + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24); + + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25); + } + + void lastIndexOfChar_002() + { + OString aStr1 = "Line for a lastIndexOfChar."; + sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOfChar); + CPPUNIT_TEST(lastIndexOfChar_000); + CPPUNIT_TEST(lastIndexOfChar_001); + CPPUNIT_TEST(lastIndexOfChar_002); + CPPUNIT_TEST_SUITE_END(); + }; // class lastIndexOfChar + + class indexOfStr : public CppUnit::TestFixture + { + public: + + void indexOfStr_000() + { + rtl_str_indexOfStr( NULL, 0 ); + } + + void indexOfStr_000_1() + { + OString aStr1 = "Line for an indexOfStr."; + rtl_str_indexOfStr( aStr1.getStr(), 0 ); + } + + void indexOfStr_001() + { + OString aStr1 = "Line for an indexOfStr."; + + sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5); + + /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9); + + /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "an index" ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9); + } + + void indexOfStr_002() + { + OString aStr1 = "Line for an indexOfStr."; + sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(indexOfStr); + CPPUNIT_TEST(indexOfStr_000); + CPPUNIT_TEST(indexOfStr_001); + CPPUNIT_TEST(indexOfStr_002); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class lastIndexOfStr : public CppUnit::TestFixture + { + public: + + void lastIndexOfStr_000() + { + rtl_str_lastIndexOfStr( NULL, NULL ); + } + + void lastIndexOfStr_000_1() + { + OString aStr1 = "Line for a lastIndexOfStr."; + rtl_str_lastIndexOfStr( aStr1.getStr(), NULL ); + } + + void lastIndexOfStr_001() + { + OString aStr1 = "Line for a lastIndexOfStr."; + OString aSearchStr = "Index"; + + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15); + + /* OString */ aSearchStr = "Line"; + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* OString */ aSearchStr = ""; + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1); + } + + void lastIndexOfStr_002() + { + OString aStr1 = "Line for a lastIndexOfStr."; + OString aSearchStr = "foo"; + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + void lastIndexOfStr_003() + { + OString aStr1 = "Line for a lastIndexOfStr."; + OString aSearchStr = "O"; + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOfStr); + CPPUNIT_TEST(lastIndexOfStr_000); + CPPUNIT_TEST(lastIndexOfStr_001); + CPPUNIT_TEST(lastIndexOfStr_002); + CPPUNIT_TEST(lastIndexOfStr_003); + CPPUNIT_TEST_SUITE_END(); + }; // class lastIndexOfStr + + class replaceChar : public CppUnit::TestFixture + { + public: + + void replaceChar_000() + { + rtl_str_replaceChar( NULL, 0, 0 ); + } + + void replaceChar_001() + { + OString aStr1 = "replace char."; + OString aShouldStr1 = "ruplacu char."; + + char* pStr = (char*) malloc(aStr1.getLength() + 1); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + strcpy(pStr, aStr1.getStr()); + + rtl_str_replaceChar( pStr, 'e', 'u' ); + + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr)) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(replaceChar); + CPPUNIT_TEST(replaceChar_000); + CPPUNIT_TEST(replaceChar_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class replaceChar_WithLength : public CppUnit::TestFixture + { + public: + + void replaceChar_WithLength_000() + { + rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 ); + } + + void replaceChar_WithLength_000_1() + { + rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 ); + } + void replaceChar_WithLength_001() + { + OString aStr1 = "replace char."; + OString aShouldStr1 = "ruplace char."; + + char* pStr = (char*) malloc(aStr1.getLength() + 1); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + strcpy(pStr, aStr1.getStr()); + + rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' ); + + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(OString(pStr)) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(replaceChar_WithLength); + CPPUNIT_TEST(replaceChar_WithLength_000); + CPPUNIT_TEST(replaceChar_WithLength_000_1); + CPPUNIT_TEST(replaceChar_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiLowerCase : public CppUnit::TestFixture + { + public: + + void toAsciiLowerCase_000() + { + rtl_str_toAsciiLowerCase( NULL ); + } + + void toAsciiLowerCase_001() + { + OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; + OString aShouldStr1 = "change this to ascii lower case."; + + char* pStr = (char*) malloc(aStr1.getLength() + 1); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + strcpy(pStr, aStr1.getStr()); + + rtl_str_toAsciiLowerCase( pStr ); + + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiLowerCase); + CPPUNIT_TEST(toAsciiLowerCase_000); + CPPUNIT_TEST(toAsciiLowerCase_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiLowerCase_WithLength : public CppUnit::TestFixture + { + public: + + void toAsciiLowerCase_WithLength_000() + { + rtl_str_toAsciiLowerCase_WithLength( NULL, 0 ); + } + + void toAsciiLowerCase_WithLength_001() + { + OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; + OString aShouldStr1 = "change thiS TO ASCII LOWER CASE."; + + char* pStr = (char*) malloc(aStr1.getLength() + 1); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + strcpy(pStr, aStr1.getStr()); + + rtl_str_toAsciiLowerCase_WithLength( pStr, 10 ); + + printf("Lowercase with length: '%s'\n", pStr); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength); + CPPUNIT_TEST(toAsciiLowerCase_WithLength_000); + CPPUNIT_TEST(toAsciiLowerCase_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiUpperCase : public CppUnit::TestFixture + { + public: + + void toAsciiUpperCase_000() + { + rtl_str_toAsciiUpperCase( NULL ); + } + + void toAsciiUpperCase_001() + { + OString aStr1 = "change this to ascii upper case."; + OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE."; + + char* pStr = (char*) malloc(aStr1.getLength() + 1); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + strcpy(pStr, aStr1.getStr()); + + rtl_str_toAsciiUpperCase( pStr ); + + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiUpperCase); + CPPUNIT_TEST(toAsciiUpperCase_000); + CPPUNIT_TEST(toAsciiUpperCase_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiUpperCase_WithLength : public CppUnit::TestFixture + { + public: + + void toAsciiUpperCase_WithLength_000() + { + rtl_str_toAsciiUpperCase_WithLength( NULL, 0 ); + } + + void toAsciiUpperCase_WithLength_001() + { + OString aStr1 = "change this to ascii lower case."; + OString aShouldStr1 = "CHANGE THIs to ascii lower case."; + + char* pStr = (char*) malloc(aStr1.getLength() + 1); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + + strcpy(pStr, aStr1.getStr()); + rtl_str_toAsciiUpperCase_WithLength( pStr, 10 ); + + printf("Uppercase with length: '%s'\n", aStr1.getStr()); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(OString(pStr)) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength); + CPPUNIT_TEST(toAsciiUpperCase_WithLength_000); + CPPUNIT_TEST(toAsciiUpperCase_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class trim_WithLength : public CppUnit::TestFixture + { + public: + void trim_WithLength_000() + { + rtl_str_trim_WithLength(NULL, 0); + // should not GPF + } + + void trim_WithLength_000_1() + { + char pStr[] = { " trim this" }; + rtl_str_trim_WithLength( pStr, 0 ); + } + + void trim_WithLength_001() + { + char const *pStr = " trim this"; + char *pStr2 = strdup(pStr); + if (pStr2) + { + rtl_str_trim_WithLength( pStr2, 2 ); + + CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0); + free(pStr2); + } + } + + void trim_WithLength_002() + { + char const *pStr = "trim this"; + char *pStr2 = strdup(pStr); + if (pStr2) + { + rtl_str_trim_WithLength( pStr2, 5 ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4); + free(pStr2); + } + } + + void trim_WithLength_003() + { + char const *pStr = " trim this"; + char *pStr2 = strdup(pStr); + if (pStr2) + { + strcpy(pStr2, pStr); + rtl_str_trim_WithLength( pStr2, 11 ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4); + free(pStr2); + } + } + + void trim_WithLength_004() + { + char const *pStr = "\r\n\t \n\r trim \n this"; + char *pStr2 = strdup(pStr); + if (pStr2) + { + rtl_str_trim_WithLength( pStr2, 17 ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4); + free(pStr2); + } + } + + void trim_WithLength_005() + { + char const *pStr = "\r\n\t \n\r trim \t this \n\r\t\t "; + char *pStr2 = strdup(pStr); + if (pStr2) + { + rtl_str_trim_WithLength( pStr2, strlen(pStr2) ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11); + free(pStr2); + } + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(trim_WithLength); + CPPUNIT_TEST(trim_WithLength_000); + CPPUNIT_TEST(trim_WithLength_000_1); + CPPUNIT_TEST(trim_WithLength_001); + CPPUNIT_TEST(trim_WithLength_002); + CPPUNIT_TEST(trim_WithLength_003); + CPPUNIT_TEST(trim_WithLength_004); + CPPUNIT_TEST(trim_WithLength_005); + CPPUNIT_TEST_SUITE_END(); + }; + + class valueOfChar : public CppUnit::TestFixture + { + public: + void valueOfChar_000() + { + rtl_str_valueOfChar(NULL, 0); + // should not GPF + } + void valueOfChar_001() + { + char *pStr = (char*)malloc(RTL_STR_MAX_VALUEOFCHAR); + if (pStr) + { + rtl_str_valueOfChar(pStr, 'A'); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == 'A'); + free(pStr); + } + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(valueOfChar); + CPPUNIT_TEST(valueOfChar_000); + CPPUNIT_TEST(valueOfChar_001); + CPPUNIT_TEST_SUITE_END(); + }; + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compare); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compareIgnoreAsciiCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::hashCode); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfStr); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfStr); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::trim_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::valueOfChar); + +} // namespace rtl_str + +// this macro creates an empty function, which will called by the RegisterAllFunctions() +// to let the user the possibility to also register some functions by hand. +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/ostring/rtl_str.xsce b/sal/qa/rtl/ostring/rtl_str.xsce new file mode 100644 index 000000000..cd12e72f7 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_str.xsce @@ -0,0 +1,43 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# signaled with SIGNAL 11 +rtl_str.compare.compare_000 +rtl_str.compare.compare_000_1 + +rtl_str.compareIgnoreAsciiCase.compare_000 +rtl_str.compareIgnoreAsciiCase.compare_000_1 + +rtl_str.hashCode.hashCode_000 + +rtl_str.indexOfChar.indexOfChar_000 + +rtl_str.lastIndexOfChar.lastIndexOfChar_000 + +rtl_str.indexOfStr.indexOfStr_000 + +rtl_str.lastIndexOfStr.lastIndexOfStr_000 + +rtl_str.replaceChar.replaceChar_000 + +rtl_str.replaceChar_WithLength.replaceChar_WithLength_000_1 + +rtl_str.toAsciiLowerCase.toAsciiLowerCase_000 + +rtl_str.toAsciiUpperCase.toAsciiUpperCase_000 + +rtl_str.valueOfChar.valueOfChar_000 diff --git a/sal/qa/rtl/ostring/rtl_string.cxx b/sal/qa/rtl/ostring/rtl_string.cxx new file mode 100644 index 000000000..71c709519 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_string.cxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/ustring.hxx> +#include <cstring> + +namespace rtl_string +{ + + class getLength : public CppUnit::TestFixture + { + public: + + void getLength_000() + { + rtl_string_getLength( NULL ); + // should not GPF + } + + void getLength_001() + { + OString aStr("Test Length."); + sal_Int32 nValue = rtl_string_getLength( aStr.pData ); + + CPPUNIT_ASSERT_MESSAGE("Length must equal getLength()", aStr.getLength() == nValue); + CPPUNIT_ASSERT_MESSAGE( + "Length must equal strlen()", + nValue >= 0 + && (strlen(aStr.getStr()) + == sal::static_int_cast< sal_uInt32 >(nValue))); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getLength); + CPPUNIT_TEST(getLength_000); + CPPUNIT_TEST(getLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class getLength + + class newFromString : public CppUnit::TestFixture + { + public: + + // void newFromString_000() + // { + // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL ); + // // should not GPF + // } + + void newFromString_001() + { + OString aStr("Test Length."); + rtl_String *pStr = NULL; + + rtl_string_newFromString( &pStr, aStr.pData ); + + OString aNewStr(pStr); + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", aStr.equals(aNewStr) == sal_True); + + rtl_string_release(pStr); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(newFromString); + // CPPUNIT_TEST(newFromString_000); + CPPUNIT_TEST(newFromString_001); + CPPUNIT_TEST_SUITE_END(); + }; // class newFromString + + class convertUStringToString : public CppUnit::TestFixture + { + public: + + // void newFromString_000() + // { + // sal_Int32 nValue = rtl_string_newFromString( NULL, NULL ); + // // should not GPF + // } + + void convertUStringToString_001() + { + OUString suString("Hello"); + OString sString; + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("Hello")) == sal_True); + } + + void convertUStringToString_002() + { + OString sStr("H\xE4llo"); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + + OString sString; + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("H\xE4llo")) == sal_True); + } + + void convertUStringToString_003() + { + OString sStr("H\xC3\xA4llo"); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_UTF8); + + OString sString; + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("H\xE4llo")) == sal_True); + } + + void convertUStringToString_004() + { + OString sStr("Tsch\xFC\xDF"); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + OString sString; + + sal_Bool bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); + /* sal_Bool */ bRet = rtl_convertUStringToString(&sString.pData, suString.getStr(), suString.getLength(), RTL_TEXTENCODING_ISO_8859_15, OUSTRING_TO_OSTRING_CVTFLAGS); + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", bRet == sal_True && sString.equals(OString("Tsch\xFC\xDF")) == sal_True); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(convertUStringToString); + CPPUNIT_TEST(convertUStringToString_001); + CPPUNIT_TEST(convertUStringToString_002); + CPPUNIT_TEST(convertUStringToString_003); + CPPUNIT_TEST(convertUStringToString_004); + CPPUNIT_TEST_SUITE_END(); + }; // class convertUStringToString + +} // namespace rtl_string + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::getLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::newFromString); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_string::convertUStringToString); + +// this macro creates an empty function, which will called by the RegisterAllFunctions() +// to let the user the possibility to also register some functions by hand. +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/ostring/rtl_string.xsce b/sal/qa/rtl/ostring/rtl_string.xsce new file mode 100644 index 000000000..7c8227e49 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_string.xsce @@ -0,0 +1,18 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +rtl_string.getLength.getLength_000 diff --git a/sal/qa/rtl/oustring/joblist.txt b/sal/qa/rtl/oustring/joblist.txt new file mode 100644 index 000000000..c309c670d --- /dev/null +++ b/sal/qa/rtl/oustring/joblist.txt @@ -0,0 +1,27 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# JobFile for rtl_OUString +# header source sal/inc/rtl/ustring.hxx + +rtl_OUString.valueOf.valueOf_double_001 +rtl_OUString.valueOf.valueOf_double_002 +rtl_OUString.valueOf.valueOf_double_003 +rtl_OUString.valueOf.valueOf_double_004 +rtl_OUString.valueOf.valueOf_double_005 +rtl_OUString.valueOf.valueOf_double_006 +rtl_OUString.valueOf.valueOf_double_007 diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx new file mode 100644 index 000000000..4a3a405d8 --- /dev/null +++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx @@ -0,0 +1,1099 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +// autogenerated file with codegen.pl + +#include <memory> +#include <math.h> +#include <stdio.h> + +#include <algorithm> +#include <limits> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <o3tl/cppunittraitshelper.hxx> + +#include <stringhelper.hxx> +#include <valueequal.hxx> + +namespace rtl_OUString +{ + +namespace { + +// Avoid -fsanitize=undefined warning e.g. "runtime error: value 1e+99 is +// outside the range of representable values of type 'float'": +float doubleToFloat(double x) { + return + x < -std::numeric_limits<float>::max() + ? -std::numeric_limits<float>::infinity() + : x > std::numeric_limits<float>::max() + ? std::numeric_limits<float>::infinity() + : static_cast<float>(x); +} + +} + +class number : public CppUnit::TestFixture +{ + void number_float_test_impl(float _nValue) + { + OUString suValue(OUString::number(_nValue)); + OString sValue; + sValue <<= suValue; + printf("nFloat := %.9f sValue := %s\n", _nValue, sValue.getStr()); + + double nValueATOF = doubleToFloat(atof( sValue.getStr() )); + + bool bEqualResult = is_float_equal(_nValue, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult); + } + + void number_float_test(float _nValue) + { + number_float_test_impl(_nValue); + + // test also the negative part. + float nNegativeValue = -_nValue; + number_float_test_impl(nNegativeValue); + } + +public: + // insert your test code here. + void number_float_test_001() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + float nValue = 3.0f; + number_float_test(nValue); + } + + void number_float_test_002() + { + float nValue = 3.5f; + number_float_test(nValue); + } + + void number_float_test_003() + { + float nValue = 3.0625f; + number_float_test(nValue); + } + + void number_float_test_004() + { + float nValue = 3.502525f; + number_float_test(nValue); + } + + void number_float_test_005() + { + float nValue = 3.141592f; + number_float_test(nValue); + } + + void number_float_test_006() + { + float nValue = 3.5025255f; + number_float_test(nValue); + } + + void number_float_test_007() + { + float nValue = 3.0039062f; + number_float_test(nValue); + } + +private: + + void number_double_test_impl(double _nValue) + { + OUString suValue = OUString::number( _nValue ); + OString sValue; + sValue <<= suValue; + printf("nDouble := %.20f sValue := %s\n", _nValue, sValue.getStr()); + + double nValueATOF = atof( sValue.getStr() ); + + bool bEqualResult = is_double_equal(_nValue, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult); + } + + void number_double_test(double _nValue) + { + number_double_test_impl(_nValue); + + // test also the negative part. + double nNegativeValue = -_nValue; + number_double_test_impl(nNegativeValue); + } +public: + + // number double + void number_double_test_001() + { + double nValue = 3.0; + number_double_test(nValue); + } + void number_double_test_002() + { + double nValue = 3.5; + number_double_test(nValue); + } + void number_double_test_003() + { + double nValue = 3.0625; + number_double_test(nValue); + } + void number_double_test_004() + { + double nValue = 3.1415926535; + number_double_test(nValue); + } + void number_double_test_005() + { + double nValue = 3.141592653589793; + number_double_test(nValue); + } + void number_double_test_006() + { + double nValue = 3.1415926535897932; + number_double_test(nValue); + } + void number_double_test_007() + { + double nValue = 3.14159265358979323; + number_double_test(nValue); + } + void number_double_test_008() + { + double nValue = 3.141592653589793238462643; + number_double_test(nValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(number); + CPPUNIT_TEST(number_float_test_001); + CPPUNIT_TEST(number_float_test_002); + CPPUNIT_TEST(number_float_test_003); + CPPUNIT_TEST(number_float_test_004); + CPPUNIT_TEST(number_float_test_005); + CPPUNIT_TEST(number_float_test_006); + CPPUNIT_TEST(number_float_test_007); + + CPPUNIT_TEST(number_double_test_001); + CPPUNIT_TEST(number_double_test_002); + CPPUNIT_TEST(number_double_test_003); + CPPUNIT_TEST(number_double_test_004); + CPPUNIT_TEST(number_double_test_005); + CPPUNIT_TEST(number_double_test_006); + CPPUNIT_TEST(number_double_test_007); + CPPUNIT_TEST(number_double_test_008); + CPPUNIT_TEST_SUITE_END(); +}; // class number + + class toInt: public CppUnit::TestFixture { + public: + void test() { + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(-0x76543210), + (OUString("-76543210"). + toInt32(16))); + // @return 0 if this string represents no number or one of too large magnitude + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(0), + (OUString("+FEDCBA98"). + toInt32(16))); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int64 >(-SAL_CONST_INT64(0x76543210FEDCBA98)), + (OUString( + "-76543210FEDCBA98"). + toInt64(16))); + // @return 0 if this string represents no number or one of too large magnitude + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int64 >(SAL_CONST_INT64(0)), + (OUString( + "+FEDCBA9876543210"). + toInt64(16))); + } + + CPPUNIT_TEST_SUITE(toInt); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + }; + + // - toDouble (tests) + class toDouble : public CppUnit::TestFixture + { + public: + void toDouble_test_impl(OString const& _sValue) + { + //printf("the original str is %s\n", _sValue.getStr()); + double nValueATOF = atof( _sValue.getStr() ); + //printf("original data is %e\n", nValueATOF); + OUString suValue = OUString::createFromAscii( _sValue.getStr() ); + double nValueToDouble = suValue.toDouble(); + //printf("result data is %e\n", nValueToDouble); + + bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult); + } + + void toDouble_test(OString const& _sValue) + { + toDouble_test_impl(_sValue); + + // test also the negative part. + OString sNegativValue("-"); + sNegativValue += _sValue; + toDouble_test_impl(sNegativValue); + } + + // insert your test code here. + void toDouble_selftest() + { + printf("Start selftest:\n"); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.01)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.0001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.00001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.0000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.00000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.000000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.0000000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.00000000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.000000000001)); + CPPUNIT_ASSERT (!is_double_equal(1.0, 1.0000000000001)); + // we check til 15 values after comma + CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001)); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001)); + CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001)); + printf("Selftest done.\n"); + } + + void toDouble_test_3() + { + OString sValue("3"); + toDouble_test(sValue); + } + void toDouble_test_3_5() + { + OString sValue("3.5"); + toDouble_test(sValue); + } + void toDouble_test_3_0625() + { + OString sValue("3.0625"); + toDouble_test(sValue); + } + void toDouble_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + OString sValue("3.141592653589793238462643383279502884197169399375"); + toDouble_test(sValue); + } + + void toDouble_test_1() + { + OString sValue("1"); + toDouble_test(sValue); + } + void toDouble_test_10() + { + OString sValue("10"); + toDouble_test(sValue); + } + void toDouble_test_100() + { + OString sValue("100"); + toDouble_test(sValue); + } + void toDouble_test_1000() + { + OString sValue("1000"); + toDouble_test(sValue); + } + void toDouble_test_10000() + { + OString sValue("10000"); + toDouble_test(sValue); + } + void toDouble_test_1e99() + { + OString sValue("1e99"); + toDouble_test(sValue); + } + void toDouble_test_1e_n99() + { + OString sValue("1e-99"); + toDouble_test(sValue); + } + void toDouble_test_1e308() + { + OString sValue("1e308"); + toDouble_test(sValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toDouble); + CPPUNIT_TEST(toDouble_selftest); + + CPPUNIT_TEST(toDouble_test_3); + CPPUNIT_TEST(toDouble_test_3_5); + CPPUNIT_TEST(toDouble_test_3_0625); + CPPUNIT_TEST(toDouble_test_pi); + CPPUNIT_TEST(toDouble_test_1); + CPPUNIT_TEST(toDouble_test_10); + CPPUNIT_TEST(toDouble_test_100); + CPPUNIT_TEST(toDouble_test_1000); + CPPUNIT_TEST(toDouble_test_10000); + CPPUNIT_TEST(toDouble_test_1e99); + CPPUNIT_TEST(toDouble_test_1e_n99); + CPPUNIT_TEST(toDouble_test_1e308); + CPPUNIT_TEST_SUITE_END(); + }; // class toDouble + + // - toFloat (tests) + class toFloat : public CppUnit::TestFixture + { + public: + void toFloat_test_impl(OString const& _sValue) + { + //printf("the original str is %s\n", _sValue.getStr()); + float nValueATOF = doubleToFloat(atof( _sValue.getStr() )); + //printf("the original str is %.10f\n", nValueATOF); + OUString suValue = OUString::createFromAscii( _sValue.getStr() ); + float nValueToFloat = suValue.toFloat(); + //printf("the result str is %.10f\n", nValueToFloat); + + bool bEqualResult = is_float_equal(nValueToFloat, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult); + } + + void toFloat_test(OString const& _sValue) + { + toFloat_test_impl(_sValue); + + // test also the negative part. + OString sNegativValue("-"); + sNegativValue += _sValue; + toFloat_test_impl(sNegativValue); + } + + // insert your test code here. + void toFloat_selftest() + { + printf("Start selftest:\n"); + CPPUNIT_ASSERT (!is_float_equal(1.0f, 1.01f)); + CPPUNIT_ASSERT (!is_float_equal(1.0f, 1.001f)); + CPPUNIT_ASSERT (!is_float_equal(1.0f, 1.0001f)); + CPPUNIT_ASSERT (!is_float_equal(1.0f, 1.00001f)); + CPPUNIT_ASSERT (!is_float_equal(1.0f, 1.000002f)); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0000001f)); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00000001f)); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000000001f)); + + printf("Selftest done.\n"); + } + + void toFloat_test_3() + { + OString sValue("3"); + toFloat_test(sValue); + } + void toFloat_test_3_5() + { + OString sValue("3.5"); + toFloat_test(sValue); + } + void toFloat_test_3_0625() + { + OString sValue("3.0625"); + toFloat_test(sValue); + } + void toFloat_test_3_0625_e() + { + OString sValue("3.0625e-4"); + toFloat_test(sValue); + } + void toFloat_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + OString sValue("3.141592653589793238462643383279502884197169399375"); + toFloat_test(sValue); + } + + void toFloat_test_1() + { + OString sValue("1"); + toFloat_test(sValue); + } + void toFloat_test_10() + { + OString sValue("10"); + toFloat_test(sValue); + } + void toFloat_test_100() + { + OString sValue("100"); + toFloat_test(sValue); + } + void toFloat_test_1000() + { + OString sValue("1000"); + toFloat_test(sValue); + } + void toFloat_test_10000() + { + OString sValue("10000"); + toFloat_test(sValue); + } + void toFloat_test_mix() + { + OString sValue("456789321455.123456789012"); + toFloat_test(sValue); + } + void toFloat_test_1e99() + { + OString sValue("1e99"); + toFloat_test(sValue); + } + void toFloat_test_1e_n99() + { + OString sValue("1e-9"); + toFloat_test(sValue); + } + void toFloat_test_1e308() + { + OString sValue("1e308"); + toFloat_test(sValue); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toFloat); + CPPUNIT_TEST(toFloat_selftest); + + CPPUNIT_TEST(toFloat_test_3); + CPPUNIT_TEST(toFloat_test_3_5); + CPPUNIT_TEST(toFloat_test_3_0625); + CPPUNIT_TEST(toFloat_test_3_0625_e); + CPPUNIT_TEST(toFloat_test_pi); + CPPUNIT_TEST(toFloat_test_1); + CPPUNIT_TEST(toFloat_test_10); + CPPUNIT_TEST(toFloat_test_100); + CPPUNIT_TEST(toFloat_test_1000); + CPPUNIT_TEST(toFloat_test_10000); + CPPUNIT_TEST(toFloat_test_mix); + CPPUNIT_TEST(toFloat_test_1e99); + CPPUNIT_TEST(toFloat_test_1e_n99); + CPPUNIT_TEST(toFloat_test_1e308); + CPPUNIT_TEST_SUITE_END(); + }; // class toFloat + +// - lastIndexOf (tests) +class lastIndexOf : public CppUnit::TestFixture +{ + +public: + void lastIndexOf_oustring(OUString const& _suStr, OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos) + { + // Algorithm + // search the string _suSearchStr (OUString) in the string _suStr. + // check if the _nExpectedResultPos occurs. + + sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr); + CPPUNIT_ASSERT_EQUAL_MESSAGE("expected position is wrong", _nExpectedResultPos, nPos); + } + + void lastIndexOf_salunicode(OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos) + { + // Algorithm + // search the unicode char _suSearchChar (sal_Unicode) in the string _suStr. + // check if the _nExpectedResultPos occurs. + + sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar); + CPPUNIT_ASSERT_EQUAL_MESSAGE("expected position is wrong", _nExpectedResultPos, nPos); + } + + void lastIndexOf_oustring_offset(OUString const& _suStr, OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset) + { + sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr, _nStartOffset); + CPPUNIT_ASSERT_EQUAL_MESSAGE("expected position is wrong", _nExpectedResultPos, nPos); + } + + void lastIndexOf_salunicode_offset(OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset) + { + sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar, _nStartOffset); + CPPUNIT_ASSERT_EQUAL_MESSAGE("expected position is wrong", _nExpectedResultPos, nPos); + } + + void lastIndexOf_test_oustring_offset_001() + { + // search for sun, start at the end, found (pos==0) + OUString aStr("sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, 0, aStr.getLength()); + } + + void lastIndexOf_test_oustring_offset_002() + { + // search for sun, start at pos = 3, found (pos==0) + OUString aStr("sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, 0, 3); + } + + void lastIndexOf_test_oustring_offset_003() + { + // search for sun, start at pos = 2, found (pos==-1) + OUString aStr("sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 2); + } + + void lastIndexOf_test_oustring_offset_004() + { + // search for sun, start at the end, found (pos==0) + OUString aStr("sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 1); + } + + void lastIndexOf_test_oustring_001() + { + // search for sun, found (pos==0) + OUString aStr("sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 0); + } + + void lastIndexOf_test_oustring_002() + { + // search for sun, found (pos==4) + OUString aStr("the sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 4); + } + + void lastIndexOf_test_oustring_003() + { + // search for sun, found (pos==8) + OUString aStr("the sun sun java system"); + OUString aSearchStr("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 8); + } + + void lastIndexOf_test_oustring_004() + { + // search for sun, found (pos==8) + OUString aStr("the sun sun"); + OUString aSearchStr("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 8); + } + + void lastIndexOf_test_oustring_005() + { + // search for sun, found (pos==4) + OUString aStr("the sun su"); + OUString aSearchStr("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 4); + } + + void lastIndexOf_test_oustring_006() + { + // search for sun, found (pos==-1) + OUString aStr("the su su"); + OUString aSearchStr("sun"); + lastIndexOf_oustring(aStr, aSearchStr, -1); + } + + void lastIndexOf_test_oustring_007() + { + // search for earth, not found (-1) + OUString aStr("the su su"); + OUString aSearchStr("earth"); + lastIndexOf_oustring(aStr, aSearchStr, -1); + } + + void lastIndexOf_test_oustring_008() + { + // search for earth, not found (-1) + OUString aStr; + OUString aSearchStr("earth"); + lastIndexOf_oustring(aStr, aSearchStr, -1); + } + + void lastIndexOf_test_oustring_009() + { + // search for earth, not found (-1) + OUString aStr; + OUString aSearchStr; + lastIndexOf_oustring(aStr, aSearchStr, -1); + + } + + void lastIndexOf_test_salunicode_001() + { + // search for 's', found (19) + OUString aStr("the sun sun java system"); + sal_Unicode suChar = L's'; + lastIndexOf_salunicode(aStr, suChar, 19); + } + + void lastIndexOf_test_salunicode_002() + { + // search for 'x', not found (-1) + OUString aStr("the sun sun java system"); + sal_Unicode suChar = L'x'; + lastIndexOf_salunicode(aStr, suChar, -1); + } + + void lastIndexOf_test_salunicode_offset_001() + { + // search for 's', start from pos last char, found (19) + OUString aStr("the sun sun java system"); + sal_Unicode cuChar = L's'; + lastIndexOf_salunicode_offset(aStr, cuChar, 19, aStr.getLength()); + } + void lastIndexOf_test_salunicode_offset_002() + { + // search for 's', start pos is last occur from search behind, found (17) + OUString aStr("the sun sun java system"); + sal_Unicode cuChar = L's'; + lastIndexOf_salunicode_offset(aStr, cuChar, 17, 19); + } + void lastIndexOf_test_salunicode_offset_003() + { + // search for 't', start pos is 1, found (0) + OUString aStr("the sun sun java system"); + sal_Unicode cuChar = L't'; + lastIndexOf_salunicode_offset(aStr, cuChar, 0, 1); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOf); + CPPUNIT_TEST(lastIndexOf_test_oustring_001); + CPPUNIT_TEST(lastIndexOf_test_oustring_002); + CPPUNIT_TEST(lastIndexOf_test_oustring_003); + CPPUNIT_TEST(lastIndexOf_test_oustring_004); + CPPUNIT_TEST(lastIndexOf_test_oustring_005); + CPPUNIT_TEST(lastIndexOf_test_oustring_006); + CPPUNIT_TEST(lastIndexOf_test_oustring_007); + CPPUNIT_TEST(lastIndexOf_test_oustring_008); + CPPUNIT_TEST(lastIndexOf_test_oustring_009); + + CPPUNIT_TEST(lastIndexOf_test_oustring_offset_001); + CPPUNIT_TEST(lastIndexOf_test_oustring_offset_002); + CPPUNIT_TEST(lastIndexOf_test_oustring_offset_003); + CPPUNIT_TEST(lastIndexOf_test_oustring_offset_004); + + CPPUNIT_TEST(lastIndexOf_test_salunicode_001); + CPPUNIT_TEST(lastIndexOf_test_salunicode_002); + + CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_001); + CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_002); + CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_003); + + CPPUNIT_TEST_SUITE_END(); +}; // class lastIndexOf + +// - getToken (tests) +class getToken : public CppUnit::TestFixture +{ + +public: + void getToken_000() + { + OUString suTokenStr; + + sal_Int32 nIndex = 0; + do + { + suTokenStr.getToken( 0, ';', nIndex ); + } + while ( nIndex >= 0 ); + printf("Index %" SAL_PRIdINT32 "\n", nIndex); + // should not GPF + } + + void getToken_001() + { + OUString suTokenStr("a;b"); + + sal_Int32 nIndex = 0; + + OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'a'", OUString("a"), suToken); + + /* OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'b'", OUString("b"), suToken); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index should be negative", static_cast<sal_Int32>(-1), nIndex); + } + + void getToken_002() + { + OUString suTokenStr("a;b.c"); + + sal_Int32 nIndex = 0; + + OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'a'", OUString("a"), suToken ); + + /* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'b'", OUString("b"), suToken ); + + /* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'c'", OUString("c"), suToken ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index should be negative", static_cast<sal_Int32>(-1), nIndex); + } + + void getToken_003() + { + OUString suTokenStr("a;;b"); + + sal_Int32 nIndex = 0; + + OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'a'", OUString("a"), suToken ); + + /* OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.isEmpty()); + + /* OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'b'", OUString("b"), suToken ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("index should be negative", static_cast<sal_Int32>(-1), nIndex); + } + + void getToken_004() + { + OUString suTokenStr("longer.then.ever."); + + sal_Int32 nIndex = 0; + + OUString suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be 'longer'", OUString("longer"), suToken ); + + /* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be 'then'", OUString("then"), suToken ); + + /* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be 'ever'", OUString("ever"), suToken ); + + /* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.isEmpty()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("index should be negative", static_cast<sal_Int32>(-1), nIndex); + } + + void getToken_005() { + OUString ab("ab"); + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "token should be 'ab'", ab, ab.getToken(0, '-', n)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("n should be -1", static_cast<sal_Int32>(-1), n); + CPPUNIT_ASSERT_MESSAGE( + "token should be empty", ab.getToken(0, '-', n).isEmpty()); + } + + CPPUNIT_TEST_SUITE(getToken); + CPPUNIT_TEST(getToken_000); + CPPUNIT_TEST(getToken_001); + CPPUNIT_TEST(getToken_002); + CPPUNIT_TEST(getToken_003); + CPPUNIT_TEST(getToken_004); + CPPUNIT_TEST(getToken_005); + CPPUNIT_TEST_SUITE_END(); +}; // class getToken + +class convertToString: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(convertToString); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void convertToString::test() { + static sal_Unicode const utf16[] = { 0x0041, 0x00E4, 0x0061 }; + OString s; + CPPUNIT_ASSERT( + OUString(utf16, SAL_N_ELEMENTS(utf16)).convertToString( + &s, RTL_TEXTENCODING_UTF7, + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | + RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))); + CPPUNIT_ASSERT_EQUAL( + OString(RTL_CONSTASCII_STRINGPARAM("A+AOQ-a")), s); +} + +// - string construction & interning (tests) + +class construction : public CppUnit::TestFixture +{ +public: + void construct() + { +#ifdef RTL_INLINE_STRINGS + OUString aFoo( "foo" ); + CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[0] == 'f'); + CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[1] == 'o'); + CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[2] == 'o'); + CPPUNIT_ASSERT_MESSAGE("string length", aFoo.getLength() == 3); + + OUString aBaa( "this is a very long string with a lot of long things inside it and it goes on and on and on forever etc." ); + CPPUNIT_ASSERT_MESSAGE("string length", aBaa.getLength() == 104); + // Dig at the internals ... FIXME: should we have the bit-flag defines public ? + CPPUNIT_ASSERT_MESSAGE("string static flags", (aBaa.pData->refCount & 1<<30) != 0); +#endif + } + + void intern() + { + // The empty string is 'static' a special case ... + OUString().intern(); + OUString::intern( "",strlen(""),RTL_TEXTENCODING_ASCII_US ); + + OUString aFoo( "foo" ); + OUString aFooIntern = aFoo.intern(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "string contents", OUString("foo"), aFooIntern); + CPPUNIT_ASSERT_EQUAL_MESSAGE("string length", static_cast<sal_Int32>(3), aFooIntern.getLength()); + // We have to dup due to no atomic 'intern' bit-set operation + CPPUNIT_ASSERT_MESSAGE("intern dups", aFoo.pData != aFooIntern.pData); + + // Test interning lots of things + int i; + static const int nSequence = 4096; + std::unique_ptr<OUString[]> pStrs(new OUString[nSequence]); + for (i = 0; i < nSequence; i++) + { + pStrs[i] = OUString( OUString::number( sqrt( static_cast<double>(i) ) ) ).intern(); + } + for (i = 0; i < nSequence; i++) + { + OUString aNew = OUString( OUString::number( sqrt( static_cast<double>(i) ) ) ).intern(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("double intern failed", + pStrs[i].pData, aNew.pData); + } + } + + CPPUNIT_TEST_SUITE(construction); + CPPUNIT_TEST(construct); + CPPUNIT_TEST(intern); + CPPUNIT_TEST_SUITE_END(); +}; + +class indexOfAscii: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(indexOfAscii); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void indexOfAscii::test() { + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), OUString().indexOf("")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), OUString().lastIndexOf("")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), OUString("foo").indexOf("foo")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), OUString("foo").lastIndexOf("foo")); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(2), OUString("fofoobar").indexOf("foo")); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), OUString("foofoofob").lastIndexOf("foo")); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), OUString("foofoobar").indexOf("foo", 1)); +} + +class endsWith: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(endsWith); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void endsWith::test() { + CPPUNIT_ASSERT_EQUAL(true, OUString().endsWith("")); + CPPUNIT_ASSERT_EQUAL(false, OUString().endsWith("foo")); + CPPUNIT_ASSERT_EQUAL(true, OUString("bar").endsWith("bar")); + CPPUNIT_ASSERT_EQUAL(true, OUString("foobar").endsWith("bar")); + CPPUNIT_ASSERT_EQUAL(false, OUString("FOOBAR").endsWith("bar")); +} + +class isEmpty: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(isEmpty); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void isEmpty::test() { + OUString aString; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Newly constructed string should be empty", true, aString.isEmpty() ); + + aString = "Not empty any more"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "String should not be empty", false, aString.isEmpty() ); + + aString.clear(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "aString.clear(), so should now be empty", true, aString.isEmpty() ); +} + + +class createFromCodePoints: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(createFromCodePoints); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void createFromCodePoints::test() { + CPPUNIT_ASSERT_EQUAL( + sal_Int32(0), + OUString(static_cast< sal_uInt32 const * >(nullptr), 0).getLength()); + static sal_uInt32 const cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF }; + OUString s(cp, SAL_N_ELEMENTS(cp)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength()); + CPPUNIT_ASSERT_EQUAL(u'\0', s[0]); + CPPUNIT_ASSERT_EQUAL(u'\xD800', s[1]); + CPPUNIT_ASSERT_EQUAL(u'\xFFFF', s[2]); + CPPUNIT_ASSERT_EQUAL(u'\xD800', s[3]); + CPPUNIT_ASSERT_EQUAL(u'\xDC00', s[4]); + CPPUNIT_ASSERT_EQUAL(u'\xDBFF', s[5]); + CPPUNIT_ASSERT_EQUAL(u'\xDFFF', s[6]); +} + +class iterateCodePoints: public CppUnit::TestFixture { +public: + void testNotWellFormed(); + + CPPUNIT_TEST_SUITE(iterateCodePoints); + CPPUNIT_TEST(testNotWellFormed); + CPPUNIT_TEST_SUITE_END(); +}; + +void iterateCodePoints::testNotWellFormed() { + static sal_Unicode const utf16[] = + { 0xD800, 0xDC00, 0x0041, 0xDBFF, 0xDFFF, 0xDDEF, 0xD9AB }; + OUString s(utf16, SAL_N_ELEMENTS(utf16)); + sal_Int32 i = 0; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i, -1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i, -1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i, -1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i, -1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + i = 1; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDC00), s.iterateCodePoints(&i, 2)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i); + i = 4; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -3)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); +} + +class convertFromString: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(convertFromString); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void convertFromString::test() { + OUString t; + CPPUNIT_ASSERT( + !rtl_convertStringToUString( + &t.pData, RTL_CONSTASCII_STRINGPARAM("\x80"), RTL_TEXTENCODING_UTF8, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))); + CPPUNIT_ASSERT( + !rtl_convertStringToUString( + &t.pData, RTL_CONSTASCII_STRINGPARAM("\xC0"), RTL_TEXTENCODING_UTF8, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))); + CPPUNIT_ASSERT( + !rtl_convertStringToUString( + &t.pData, RTL_CONSTASCII_STRINGPARAM("\xFF"), RTL_TEXTENCODING_UTF8, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))); + CPPUNIT_ASSERT( + rtl_convertStringToUString( + &t.pData, RTL_CONSTASCII_STRINGPARAM("abc"), RTL_TEXTENCODING_UTF8, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))); + CPPUNIT_ASSERT_EQUAL( OUString("abc"), t ); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::number); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::toInt); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::toDouble); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::toFloat); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::lastIndexOf); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::getToken); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertToString); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::construction); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::indexOfAscii); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::endsWith); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::isEmpty); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::createFromCodePoints); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::iterateCodePoints); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertFromString); + +} // namespace rtl_OUString + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/oustring/rtl_ustr.cxx b/sal/qa/rtl/oustring/rtl_ustr.cxx new file mode 100644 index 000000000..e73ab9124 --- /dev/null +++ b/sal/qa/rtl/oustring/rtl_ustr.cxx @@ -0,0 +1,1368 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +/** print a UNI_CODE file name. +*/ +/* +inline void printOUString( OUString const & _suStr ) +{ + OString aString; + + printf( "OUString: " ); + aString = OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US ); + printf( "%s\n", aString.getStr( ) ); +} +*/ + +namespace rtl_ustr +{ + + class compare : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_ustr_compare( NULL, NULL); + // should not GPF + } + + void compare_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_compare( aStr1.getStr(), NULL); + // should not GPF + } + void compare_001() + { + OUString aStr1; + OUString aStr2; + + sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002() + { + OUString aStr1("Line must be equal."); + OUString aStr2("Line must be equal."); + + sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_003() + { + OUString aStr1("Line must differ."); + OUString aStr2("Line foo bar, ok, differ."); + + sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(compare); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST_SUITE_END(); +}; // class compare + + class compareIgnoreAsciiCase : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_ustr_compareIgnoreAsciiCase( NULL, NULL); + } + + void compare_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + } + void compare_001() + { + OUString aStr1; + OUString aStr2; + + sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002() + { + OUString aStr1("Line must be equal."); + OUString aStr2("Line must be equal."); + + sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002_1() + { + OUString aStr1("Line must be equal."); + OUString aStr2("LINE MUST BE EQUAL."); + + sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + } + + void compare_003() + { + OUString aStr1("Line must differ."); + OUString aStr2("Line foo bar, ok, differ."); + + sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_002_1); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST_SUITE_END(); + }; // class compareIgnoreAsciiCase + + class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0); + } + + void compare_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); + } + void compare_001() + { + OUString aStr1; + OUString aStr2; + + sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002() + { + OUString aStr1("Line must be equal."); + OUString aStr2("Line must be equal."); + + sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void compare_002_1() + { + OUString aStr1("Line must be equal."); + OUString aStr2("LINE MUST BE EQUAL."); + + sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + } + + void compare_003() + { + OUString aStr1("Line must differ."); + OUString aStr2("Line foo bar, ok, differ."); + + sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + 5); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0); + } + + void compare_004() + { + OUString aStr1("Line must differ."); + OUString aStr2("Line foo bar, ok, differ."); + + sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), + aStr2.getStr(), aStr2.getLength(), + aStr1.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength); + CPPUNIT_TEST(compare_000); + CPPUNIT_TEST(compare_000_1); + CPPUNIT_TEST(compare_001); + CPPUNIT_TEST(compare_002); + CPPUNIT_TEST(compare_002_1); + CPPUNIT_TEST(compare_003); + CPPUNIT_TEST(compare_004); + CPPUNIT_TEST_SUITE_END(); +}; // class compare + +// +// +// class hashCode : public CppUnit::TestFixture +// { +// public: +// +// void hashCode_000() +// { +// sal_Int32 nHashCode = rtl_ustr_hashCode( NULL ); +// volatile int dummy = 0; +// } +// +// void hashCode_001() +// { +// OString aStr1 = "Line for a hashCode."; +// sal_Int32 nHashCode = rtl_ustr_hashCode( aStr1.getStr() ); +// printf("hashcode: %d\n", nHashCode); +// // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0); +// } +// +// void hashCode_002() +// { +// OString aStr1 = "Line for a hashCode."; +// sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); +// +// OString aStr2 = "Line for a hashCode."; +// sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() ); +// +// CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 ); +// } +// +// void hashCode_003() +// { +// OString aStr1 = "Line for a hashCode."; +// sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); +// +// OString aStr2 = "Line for another hashcode."; +// sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() ); +// +// CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 ); +// } +// +// // Change the following lines only, if you add, remove or rename +// // member functions of the current class, +// // because these macros are need by auto register mechanism. +// +// CPPUNIT_TEST_SUITE(hashCode); +// CPPUNIT_TEST(hashCode_000); +// CPPUNIT_TEST(hashCode_001); +// CPPUNIT_TEST(hashCode_002); +// CPPUNIT_TEST(hashCode_003); +// CPPUNIT_TEST_SUITE_END(); +// }; // class compare + + class indexOfChar : public CppUnit::TestFixture + { + public: + + void indexOfChar_000() + { + rtl_ustr_indexOfChar( NULL, 0 ); + } + + void indexOfChar_001() + { + OUString aStr1("Line for an indexOfChar."); + + sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'L' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'i' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1); + + /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'n' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2); + + /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'e' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3); + } + + void indexOfChar_002() + { + OUString aStr1("Line for an indexOfChar."); + sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'y' ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(indexOfChar); + CPPUNIT_TEST(indexOfChar_000); + CPPUNIT_TEST(indexOfChar_001); + CPPUNIT_TEST(indexOfChar_002); + CPPUNIT_TEST_SUITE_END(); + }; // class indexOfChar + + class lastIndexOfChar : public CppUnit::TestFixture + { + public: + + void lastIndexOfChar_000() + { + rtl_ustr_lastIndexOfChar( NULL, 0 ); + } + + void lastIndexOfChar_001() + { + OUString aStr1("Line for a lastIndexOfChar."); + + sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'C' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22); + + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'h' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23); + + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'a' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24); + + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'r' ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25); + } + + void lastIndexOfChar_002() + { + OUString aStr1("Line for a lastIndexOfChar."); + sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'y' ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOfChar); + CPPUNIT_TEST(lastIndexOfChar_000); + CPPUNIT_TEST(lastIndexOfChar_001); + CPPUNIT_TEST(lastIndexOfChar_002); + CPPUNIT_TEST_SUITE_END(); + }; // class lastIndexOfChar + + class indexOfStr : public CppUnit::TestFixture + { + public: + + void indexOfStr_000() + { + rtl_ustr_indexOfStr( NULL, 0 ); + } + + void indexOfStr_000_1() + { + OUString aStr1("Line for an indexOfStr."); + rtl_ustr_indexOfStr( aStr1.getStr(), 0 ); + } + + void indexOfStr_001() + { + OUString aStr1("Line for an indexOfStr."); + + OUString suSearch("Line"); + sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* OUString */ suSearch("for"); + /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5); + + /* OUString */ suSearch("a"); + /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9); + + /* OUString */ suSearch("an index"); + /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9); + } + + void indexOfStr_002() + { + OUString aStr1("Line for an indexOfStr."); + OUString suSearch("not exist"); + sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(indexOfStr); + CPPUNIT_TEST(indexOfStr_000); + CPPUNIT_TEST(indexOfStr_001); + CPPUNIT_TEST(indexOfStr_002); + CPPUNIT_TEST_SUITE_END(); + }; // class compare + + class lastIndexOfStr : public CppUnit::TestFixture + { + public: + + void lastIndexOfStr_000() + { + rtl_ustr_lastIndexOfStr( NULL, NULL ); + } + + void lastIndexOfStr_000_1() + { + OUString aStr1("Line for a lastIndexOfStr."); + rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL ); + } + + void lastIndexOfStr_001() + { + OUString aStr1("Line for a lastIndexOfStr."); + OUString aSearchStr("Index"); + + sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15); + + /* OString */ aSearchStr = OUString("Line"); + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* OString */ aSearchStr = OUString(); + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1); + } + + void lastIndexOfStr_002() + { + OUString aStr1("Line for a lastIndexOfStr."); + OUString aSearchStr("foo"); + sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + void lastIndexOfStr_003() + { + OUString aStr1("Line for a lastIndexOfStr."); + OUString aSearchStr("O"); + sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(lastIndexOfStr); + CPPUNIT_TEST(lastIndexOfStr_000); + CPPUNIT_TEST(lastIndexOfStr_001); + CPPUNIT_TEST(lastIndexOfStr_002); + CPPUNIT_TEST(lastIndexOfStr_003); + CPPUNIT_TEST_SUITE_END(); + }; // class lastIndexOfStr + + class replaceChar : public CppUnit::TestFixture + { + public: + + void replaceChar_000() + { + rtl_ustr_replaceChar( NULL, 0, 0 ); + } + + void replaceChar_001() + { + OUString aStr1("replace char."); + OUString aShouldStr1("ruplacu char."); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc( nLength + sizeof(sal_Unicode)); // length + 1 (null terminator) + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + memcpy(pStr, aStr1.getStr(), nLength); + pStr[aStr1.getLength()] = 0; + + rtl_ustr_replaceChar( pStr, 'e', 'u' ); + OUString suStr(pStr, aStr1.getLength()); + + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(replaceChar); + CPPUNIT_TEST(replaceChar_000); + CPPUNIT_TEST(replaceChar_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class replaceChar_WithLength : public CppUnit::TestFixture + { + public: + + void replaceChar_WithLength_000() + { + rtl_ustr_replaceChar_WithLength( NULL, 0, 0, 0 ); + } + + void replaceChar_WithLength_000_1() + { + rtl_ustr_replaceChar_WithLength( NULL, 1, 0, 0 ); + } + void replaceChar_WithLength_001() + { + OUString aStr1("replace char."); + OUString aShouldStr1("ruplace char."); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + memcpy(pStr, aStr1.getStr(), nLength); + + rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' ); + OUString suStr(pStr, aStr1.getLength()); + + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + void replaceChar_WithLength_002() + { + OUString aStr1 ("eeeeeeeeeeeee"); + OUString aShouldStr1("uuuuuueeeeeee"); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); // no null terminator is need + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + memcpy(pStr, aStr1.getStr(), nLength); + + rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' ); + OUString suStr(pStr, aStr1.getLength()); + + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(replaceChar_WithLength); + CPPUNIT_TEST(replaceChar_WithLength_000); + CPPUNIT_TEST(replaceChar_WithLength_000_1); + CPPUNIT_TEST(replaceChar_WithLength_001); + CPPUNIT_TEST(replaceChar_WithLength_002); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiLowerCase : public CppUnit::TestFixture + { + public: + + void toAsciiLowerCase_000() + { + rtl_ustr_toAsciiLowerCase( NULL ); + } + + void toAsciiLowerCase_001() + { + OUString aStr1("CHANGE THIS TO ASCII LOWER CASE."); + OUString aShouldStr1("change this to ascii lower case."); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode) ); // we need to add '\0' so one more + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + memcpy(pStr, aStr1.getStr(), nLength); + pStr[aStr1.getLength()] = 0; + + rtl_ustr_toAsciiLowerCase( pStr ); + OUString suStr(pStr, aStr1.getLength()); + + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiLowerCase); + CPPUNIT_TEST(toAsciiLowerCase_000); + CPPUNIT_TEST(toAsciiLowerCase_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiLowerCase_WithLength : public CppUnit::TestFixture + { + public: + + void toAsciiLowerCase_WithLength_000() + { + rtl_ustr_toAsciiLowerCase_WithLength( NULL, 0 ); + } + + void toAsciiLowerCase_WithLength_001() + { + OUString aStr1("CHANGE THIS TO ASCII LOWER CASE."); + OUString aShouldStr1("change thiS TO ASCII LOWER CASE."); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + memcpy(pStr, aStr1.getStr(), nLength); + + rtl_ustr_toAsciiLowerCase_WithLength( pStr, 10 ); + + OUString suStr(pStr, aStr1.getLength()); + sal_Bool bResult = aShouldStr1.equals(suStr); + + printOUString(suStr); + printf("Result length: %d\n", suStr.getLength() ); + printf("Result: %d\n", bResult); + + CPPUNIT_ASSERT_MESSAGE("failed", bResult == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength); + CPPUNIT_TEST(toAsciiLowerCase_WithLength_000); + CPPUNIT_TEST(toAsciiLowerCase_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiUpperCase : public CppUnit::TestFixture + { + public: + + void toAsciiUpperCase_000() + { + rtl_ustr_toAsciiUpperCase( NULL ); + } + + void toAsciiUpperCase_001() + { + OUString aStr1("change this to ascii upper case."); + OUString aShouldStr1("CHANGE THIS TO ASCII UPPER CASE."); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + memcpy(pStr, aStr1.getStr(), nLength); + pStr[aStr1.getLength()] = 0; + + rtl_ustr_toAsciiUpperCase( pStr ); + OUString suStr(pStr, aStr1.getLength()); + + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiUpperCase); + CPPUNIT_TEST(toAsciiUpperCase_000); + CPPUNIT_TEST(toAsciiUpperCase_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class toAsciiUpperCase_WithLength : public CppUnit::TestFixture + { + public: + + void toAsciiUpperCase_WithLength_000() + { + rtl_ustr_toAsciiUpperCase_WithLength( NULL, 0 ); + } + + void toAsciiUpperCase_WithLength_001() + { + OUString aStr1("change this to ascii lower case."); + OUString aShouldStr1("CHANGE THIs to ascii lower case."); + + sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode); + sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); + CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + + memcpy(pStr, aStr1.getStr(), nLength); + rtl_ustr_toAsciiUpperCase_WithLength( pStr, 10 ); + OUString suStr(pStr, aStr1.getLength()); + + // printf("Uppercase with length: '%s'\n", aStr1.getStr()); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength); + CPPUNIT_TEST(toAsciiUpperCase_WithLength_000); + CPPUNIT_TEST(toAsciiUpperCase_WithLength_001); + CPPUNIT_TEST_SUITE_END(); + }; // class replaceChar + + class trim_WithLength : public CppUnit::TestFixture + { + public: + void trim_WithLength_000() + { + rtl_ustr_trim_WithLength(NULL, 0); + // should not GPF + } + + void trim_WithLength_000_1() + { + OUString suStr(" trim this"); + + sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); + sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); + memcpy(pStr, suStr.getStr(), nLength); + + rtl_ustr_trim_WithLength( pStr, 0 ); + free(pStr); + } + + void trim_WithLength_001() + { + OUString suStr(" trim this"); + sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); + sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); + memcpy(pStr, suStr.getStr(), nLength); + + rtl_ustr_trim_WithLength( pStr, 2 ); + + CPPUNIT_ASSERT_MESSAGE("string should be empty", OUString(pStr).getLength() == 0); + free(pStr); + } + + void trim_WithLength_002() + { + OUString suStr("trim this"); + + sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); + sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); + memcpy(pStr, suStr.getStr(), nLength); + + rtl_ustr_trim_WithLength( pStr, 5 ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", OUString(pStr).getLength() == 4); + free(pStr); + } + + void trim_WithLength_003() + { + OUString suStr(" trim this"); + + sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); + sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); + memcpy(pStr, suStr.getStr(), nLength); + + rtl_ustr_trim_WithLength( pStr, 11 ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", OUString(pStr).getLength() == 4); + free(pStr); + } + + void trim_WithLength_004() + { + OUString suStr("\r\n\t \n\r trim \n this"); + + sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); + sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); + memcpy(pStr, suStr.getStr(), nLength); + + rtl_ustr_trim_WithLength( pStr, 17 ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", OUString(pStr).getLength() == 4); + free(pStr); + } + + void trim_WithLength_005() + { + OUString suStr("\r\n\t \n\r trim \t this \n\r\t\t "); + + sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); + sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); + memcpy(pStr, suStr.getStr(), nLength); + + rtl_ustr_trim_WithLength( pStr, suStr.getLength() ); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'trim \\t this'", OUString(pStr).getLength() == 11); + free(pStr); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(trim_WithLength); + CPPUNIT_TEST(trim_WithLength_000); + CPPUNIT_TEST(trim_WithLength_000_1); + CPPUNIT_TEST(trim_WithLength_001); + CPPUNIT_TEST(trim_WithLength_002); + CPPUNIT_TEST(trim_WithLength_003); + CPPUNIT_TEST(trim_WithLength_004); + CPPUNIT_TEST(trim_WithLength_005); + CPPUNIT_TEST_SUITE_END(); + }; + + class valueOfChar : public CppUnit::TestFixture + { + public: + void valueOfChar_000() + { + rtl_ustr_valueOfChar(NULL, 0); + // should not GPF + } + void valueOfChar_001() + { + sal_Unicode *pStr = (sal_Unicode*)malloc(RTL_USTR_MAX_VALUEOFCHAR); + if (pStr) + { + rtl_ustr_valueOfChar(pStr, 'A'); + + CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == L'A'); + free(pStr); + } + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(valueOfChar); + CPPUNIT_TEST(valueOfChar_000); + CPPUNIT_TEST(valueOfChar_001); + CPPUNIT_TEST_SUITE_END(); + }; + + class ascii_compare_WithLength : public CppUnit::TestFixture + { + public: + void zero_length() + { + sal_Unicode pUnicode[] = {0xffff, 0xffff}; + char const * pAscii = "reference"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(pUnicode, 0, pAscii); + CPPUNIT_ASSERT_MESSAGE("ref string is empty, compare failed, needs to be <0.", value < 0); + } + + void equal_ascii_shorter() + { + OUString refStr("referenceString"); + char const * pAscii = "reference"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); + CPPUNIT_ASSERT_MESSAGE("ref string is bigger, compare failed, needs to be >0.", value > 0); + } + + void equal_ascii_shorter_asciiLength() + { + OUString refStr("referenceString"); + char const * pAscii = "reference"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, rtl_str_getLength(pAscii), pAscii); + CPPUNIT_ASSERT_MESSAGE("ref string is bigger despite ascii length, compare failed, needs to be == 0.", value == 0); + } + + void equal_ref_shorter() + { + OUString refStr("reference"); + char const * pAscii = "referenceString"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); + CPPUNIT_ASSERT_MESSAGE("ascii string is bigger, but only compared to ref length, needs to be 0.", value < 0); + } + + void equal() + { + OUString refStr("reference"); + char const * pAscii = "reference"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); + CPPUNIT_ASSERT_MESSAGE("strings are equal, compare failed, needs to be 0.", value == 0); + } + + void unequal_reference_bigger() + { + OUString refStr("defghi"); + char const * pAscii = "abc"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); + CPPUNIT_ASSERT_MESSAGE("strings are unequal and ref is bigger, needs to be >0.", value > 0); + } + + void unequal_ascii_bigger() + { + OUString refStr("abc"); + char const * pAscii = "defghi"; + + sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); + + CPPUNIT_ASSERT_MESSAGE("strings are unequal and ascii is bigger, needs to be <0.", value < 0); + } + + CPPUNIT_TEST_SUITE(ascii_compare_WithLength); + CPPUNIT_TEST(zero_length); + CPPUNIT_TEST(equal_ascii_shorter); + CPPUNIT_TEST(equal_ascii_shorter_asciiLength); + CPPUNIT_TEST(equal_ref_shorter); + CPPUNIT_TEST(equal); + CPPUNIT_TEST(unequal_reference_bigger); + CPPUNIT_TEST(unequal_ascii_bigger); + CPPUNIT_TEST_SUITE_END(); + }; + + class ascii_shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture + { + public: + + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000() + { + rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0); + // should not GPF + } + + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0); + // should not GPF + } + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2() + { + OUString aStr1("Line must be equal."); + OString sStr2 = "Line is shorter."; + rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr(), 0); + // should not GPF + } + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_001() + { + OUString suStr1; + OString sStr2; + + sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr(), 0); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_002() + { + OUString suStr1("Line must be equal."); + OString sStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_003() + { + OUString suStr1("Line must differ."); + OString sStr2 = "Line must be differ and longer."; + + sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(ascii_shortenedCompareIgnoreAsciiCase_WithLength); + CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000); + CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1); + CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2); + CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_001); + CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_002); + CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_003); + CPPUNIT_TEST_SUITE_END(); + }; // class ascii_shortenedCompareIgnoreAsciiCase_WithLength + + class ascii_compareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture + { + public: + + void ascii_compareIgnoreAsciiCase_WithLength_000() + { + rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( NULL, 0, NULL); + // should not GPF + } + + void ascii_compareIgnoreAsciiCase_WithLength_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), 0, NULL); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_WithLength_000_2() + { + OUString aStr1("Line must be equal."); + OString sStr2 = "Line is shorter."; + rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr()); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_WithLength_001() + { + OUString suStr1; + OString sStr2; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compareIgnoreAsciiCase_WithLength failed, strings are equal.", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_WithLength_002() + { + OUString suStr1("Line must be equal."); + OString sStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_WithLength_003() + { + OUString suStr1("Line must differ."); + OString sStr2 = "Line must be differ and longer."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase_WithLength); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_1); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_2); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_001); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_002); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_003); + CPPUNIT_TEST_SUITE_END(); + }; // class ascii_compareIgnoreAsciiCase_WithLength + + class ascii_compare : public CppUnit::TestFixture + { + public: + + void ascii_compare_000() + { + rtl_ustr_ascii_compare( NULL, NULL); + // should not GPF + } + + void ascii_compare_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_ascii_compare( aStr1.getStr(), NULL); + // should not GPF + } + void ascii_compare_001() + { + OUString suStr1; + OString sStr2; + + sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1, sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compare_002() + { + OUString suStr1("Line must be equal."); + OString sStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compare_003() + { + OUString suStr1("Line must differ."); + OString sStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(ascii_compare); + CPPUNIT_TEST(ascii_compare_000); + CPPUNIT_TEST(ascii_compare_000_1); + CPPUNIT_TEST(ascii_compare_001); + CPPUNIT_TEST(ascii_compare_002); + CPPUNIT_TEST(ascii_compare_003); + CPPUNIT_TEST_SUITE_END(); + }; // class ascii_compare + + class ascii_compareIgnoreAsciiCase : public CppUnit::TestFixture + { + public: + + void ascii_compareIgnoreAsciiCase_000() + { + rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL); + // should not GPF + } + + void ascii_compareIgnoreAsciiCase_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_001() + { + OUString suStr1; + OString sStr2; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_002() + { + OUString suStr1("Line must be equal."); + OString sStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_002_1() + { + OUString suStr1("Line must be equal, when ignore case."); + OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_003() + { + OUString suStr1("Line must differ."); + OString sStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + //! LLA: some more tests with some high level strings + + // void ascii_compareIgnoreAsciiCase_001() + // { + // OUString suStr1("change this to ascii upper case."); + // OUString aShouldStr1("CHANGE THIS TO ASCII UPPER CASE."); + // + // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode); + // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator + // CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + // memset(pStr, 0, nLength + sizeof(sal_Unicode)); + // memcpy(pStr, suStr1.getStr(), nLength); + // + // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr ); + // OUString suStr(pStr, suStr1.getLength()); + // + // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); + // free(pStr); + // } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003); + CPPUNIT_TEST_SUITE_END(); + }; // class ascii_compareIgnoreAsciiCase + + // sample out of inc/rtl/ustring.hxx + // rtl_uString * pToken = NULL; + // sal_Int32 nIndex = 0; + // do + // { + // ... + // nIndex = rtl_uString_getToken(&pToken, pStr, 0, ';', nIndex); + // ... + // } + // while (nIndex >= 0); + + class getToken : public CppUnit::TestFixture + { + public: + + void getToken_000() + { + rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL); + // should not GPF + } + + void ascii_compareIgnoreAsciiCase_000_1() + { + OUString aStr1("Line must be equal."); + rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_001() + { + OUString suStr1; + OString sStr2; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_002() + { + OUString suStr1("Line must be equal."); + OString sStr2 = "Line must be equal."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_002_1() + { + OUString suStr1("Line must be equal, when ignore case."); + OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_003() + { + OUString suStr1("Line must differ."); + OString sStr2 = "Line foo bar, ok, differ."; + + sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); + } + + //! LLA: some more tests with some high level strings + + // void ascii_compareIgnoreAsciiCase_001() + // { + // OUString suStr1("change this to ascii upper case."); + // OUString aShouldStr1("CHANGE THIS TO ASCII UPPER CASE."); + // + // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode); + // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator + // CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL); + // memset(pStr, 0, nLength + sizeof(sal_Unicode)); + // memcpy(pStr, suStr1.getStr(), nLength); + // + // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr ); + // OUString suStr(pStr, suStr1.getLength()); + // + // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); + // free(pStr); + // } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1); + CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003); + CPPUNIT_TEST_SUITE_END(); + }; // class ascii_compareIgnoreAsciiCase + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::compare); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::compareIgnoreAsciiCase); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::ascii_compare_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::shortenedCompareIgnoreAsciiCase_WithLength); +// CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::hashCode); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::indexOfChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::lastIndexOfChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::indexOfStr); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::lastIndexOfStr); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::replaceChar); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::replaceChar_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::toAsciiLowerCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::toAsciiLowerCase_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::toAsciiUpperCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::toAsciiUpperCase_WithLength); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::trim_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::valueOfChar); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::ascii_compare); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase_WithLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ustr::ascii_shortenedCompareIgnoreAsciiCase_WithLength); + +} // namespace rtl_ustr + +// this macro creates an empty function, which will called by the RegisterAllFunctions("") +// to let the user the possibility to also register some functions by hand. +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/oustring/rtl_ustr.xsce b/sal/qa/rtl/oustring/rtl_ustr.xsce new file mode 100644 index 000000000..c7b5c99f3 --- /dev/null +++ b/sal/qa/rtl/oustring/rtl_ustr.xsce @@ -0,0 +1,50 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# functions which are gpf + +rtl_ustr.compare.compare_000 +rtl_ustr.compare.compare_000_1 + +rtl_ustr.compareIgnoreAsciiCase.compare_000 +rtl_ustr.compareIgnoreAsciiCase.compare_000_1 + +rtl_ustr.indexOfChar.indexOfChar_000 + +rtl_ustr.lastIndexOfChar.lastIndexOfChar_000 + +rtl_ustr.indexOfStr.indexOfStr_000 + +rtl_ustr.lastIndexOfStr.lastIndexOfStr_000 + +rtl_ustr.replaceChar.replaceChar_000 + +rtl_ustr.replaceChar_WithLength.replaceChar_WithLength_000_1 + +rtl_ustr.toAsciiLowerCase.toAsciiLowerCase_000 + +rtl_ustr.toAsciiUpperCase.toAsciiUpperCase_000 + +rtl_ustr.valueOfChar.valueOfChar_000 + +rtl_ustr.ascii_compare.ascii_compare_000 +rtl_ustr.ascii_compare.ascii_compare_000_1 +rtl_ustr.ascii_compareIgnoreAsciiCase.ascii_compareIgnoreAsciiCase_000 +rtl_ustr.ascii_compareIgnoreAsciiCase.ascii_compareIgnoreAsciiCase_000_1 +rtl_ustr.ascii_compareIgnoreAsciiCase_WithLength.ascii_compareIgnoreAsciiCase_WithLength_000 +rtl_ustr.ascii_compareIgnoreAsciiCase_WithLength.ascii_compareIgnoreAsciiCase_WithLength_000_1 + diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_appendchar.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_appendchar.cxx new file mode 100644 index 000000000..f5168b60d --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_appendchar.cxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <o3tl/cppunittraitshelper.hxx> +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/ustrbuf.hxx> + +namespace test::oustringbuffer { + +class AppendChar: public CppUnit::TestFixture { +private: + void testAppendChar(); + + CPPUNIT_TEST_SUITE(AppendChar); + CPPUNIT_TEST(testAppendChar); + CPPUNIT_TEST_SUITE_END(); +}; + +void AppendChar::testAppendChar() { + // Check that append('a') does not unexpectedly pick + // append(sal_Int32 i, sal_Int16 radix = 10): + OUStringBuffer s; + s.append('a'); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength()); + CPPUNIT_ASSERT_EQUAL(u'a', s[0]); +} + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::AppendChar); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_appenduninitialized.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_appenduninitialized.cxx new file mode 100644 index 000000000..7530d6a32 --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_appenduninitialized.cxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/ustrbuf.hxx> +#include <sal/types.h> + +namespace { + +class Test: public CppUnit::TestFixture { +private: + void testEmpty(); + + void testNonEmpty(); + + void testZero(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testEmpty); + CPPUNIT_TEST(testNonEmpty); + CPPUNIT_TEST(testZero); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::testEmpty() { + OUStringBuffer s; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); + sal_Unicode * p = s.appendUninitialized(5); + CPPUNIT_ASSERT_EQUAL( + static_cast<void const *>(s.getStr()), static_cast<void const *>(p)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength()); +} + +void Test::testNonEmpty() { + OUStringBuffer s("ab"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s.getLength()); + sal_Unicode * p = s.appendUninitialized(5); + CPPUNIT_ASSERT_EQUAL( + static_cast<void const *>(s.getStr() + 2), + static_cast<void const *>(p)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength()); +} + +void Test::testZero() { + OUStringBuffer s; + sal_Unicode * p = s.appendUninitialized(0); + CPPUNIT_ASSERT_EQUAL( + static_cast<void const *>(s.getStr()), static_cast<void const *>(p)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx new file mode 100644 index 000000000..0d9cd2b82 --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> + +namespace { + +class Test: public CppUnit::TestFixture { +private: + void test() { + OUStringBuffer b1; + OUString s1("123456789012345"); + b1 = s1; + CPPUNIT_ASSERT_EQUAL(s1, b1.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b1.getCapacity()); + OUString s2("abc"); + b1 = s2; + CPPUNIT_ASSERT_EQUAL(s2, b1.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b1.getCapacity()); + OUString s3("1234567890123456"); + b1 = s3; + CPPUNIT_ASSERT_EQUAL(s3, b1.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b1.getCapacity()); + OUStringBuffer b2; + b2 = "123456789012345"; + CPPUNIT_ASSERT_EQUAL(s1, b2.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b2.getCapacity()); + b2 = "abc"; + CPPUNIT_ASSERT_EQUAL(s2, b2.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b2.getCapacity()); + b2 = "1234567890123456"; + CPPUNIT_ASSERT_EQUAL(s3, b2.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b2.getCapacity()); + OUStringBuffer b3; + b3 = u"123456789012345"; + CPPUNIT_ASSERT_EQUAL(s1, b3.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b3.getCapacity()); + b3 = u"abc"; + CPPUNIT_ASSERT_EQUAL(s2, b3.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b3.getCapacity()); + b3 = u"1234567890123456"; + CPPUNIT_ASSERT_EQUAL(s3, b3.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b3.getCapacity()); + OUStringBuffer b4; + b4 = OUStringLiteral("1") + "23456789012345"; + CPPUNIT_ASSERT_EQUAL(s1, b4.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b4.getCapacity()); + b4 = OUStringLiteral("a") + "bc"; + CPPUNIT_ASSERT_EQUAL(s2, b4.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b4.getCapacity()); + b4 = OUStringLiteral("1") + "234567890123456"; + CPPUNIT_ASSERT_EQUAL(s3, b4.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b4.getCapacity()); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx new file mode 100644 index 000000000..66231d8b8 --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> + +namespace test::oustringbuffer { + +class ToString: public CppUnit::TestFixture { +private: + void testToString(); + + CPPUNIT_TEST_SUITE(ToString); + CPPUNIT_TEST(testToString); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::ToString); + +void test::oustringbuffer::ToString::testToString() { + OUStringBuffer sb("test string"); + OUString str = sb.toString(); + CPPUNIT_ASSERT_EQUAL( OUString("test string"), str ); + // returned OUString must be independent from sb + sb.append( 'a' ); + CPPUNIT_ASSERT_EQUAL( OUString("test string"), str ); + sb.setLength(0); + CPPUNIT_ASSERT_EQUAL( OUString("test string"), str ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx new file mode 100644 index 000000000..80643df2e --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/strbuf.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> + +namespace test::oustringbuffer { + +class Utf32: public CppUnit::TestFixture { +private: + void appendUtf32(); + + void insertUtf32(); + + CPPUNIT_TEST_SUITE(Utf32); + CPPUNIT_TEST(appendUtf32); + CPPUNIT_TEST(insertUtf32); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::Utf32); + +namespace { + +void appendString(OStringBuffer & buffer, OUString const & string) { + buffer.append('"'); + for (int i = 0; i < string.getLength(); ++i) { + buffer.append("\\u"); + sal_Unicode c = string[i]; + if (c < 0x1000) { + buffer.append('0'); + if (c < 0x100) { + buffer.append('0'); + if (c < 0x10) { + buffer.append('0'); + } + } + } + buffer.append( + static_cast< sal_Int32 >(c), static_cast< sal_Int16 >(16)); + } + buffer.append('"'); +} + +void createMessage( + OStringBuffer & message, OUString const & string1, + OUString const & string2) +{ + message.setLength(0); + appendString(message, string1); + message.append(" vs. "); + appendString(message, string2); +} + +} + +void test::oustringbuffer::Utf32::appendUtf32() { + int const str1Len = 3; + sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' }; + int const str2Len = 4; + sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' }; + int const str3Len = 6; + sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 }; + OStringBuffer message; + OUStringBuffer buf1(OUString(str1, str1Len)); + buf1.appendUtf32('d'); + OUString res1(buf1.makeStringAndClear()); + createMessage(message, res1, OUString(str2, str2Len)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + message.getStr(), OUString(str2, str2Len), res1); + OUStringBuffer buf2(OUString(str2, str2Len)); + buf2.appendUtf32(0x10000); + OUString res2(buf2.makeStringAndClear()); + createMessage(message, res2, OUString(str3, str3Len)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + message.getStr(), OUString(str3, str3Len), res2); +} + +void test::oustringbuffer::Utf32::insertUtf32() { + int const str1Len = 3; + sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' }; + int const str2Len = 4; + sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' }; + int const str3Len = 6; + sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' }; + OStringBuffer message; + OUStringBuffer buf1(OUString(str1, str1Len)); + buf1.insertUtf32(2, 'd'); + OUString res1(buf1.makeStringAndClear()); + createMessage(message, res1, OUString(str2, str2Len)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + message.getStr(), OUString(str2, str2Len), res1); + OUStringBuffer buf2(OUString(str2, str2Len)); + buf2.insertUtf32(2, 0x10FFFF); + OUString res2(buf2.makeStringAndClear()); + createMessage(message, res2, OUString(str3, str3Len)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + message.getStr(), OUString(str3, str3Len), res2); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/process/child_process.cxx b/sal/qa/rtl/process/child_process.cxx new file mode 100644 index 000000000..d5039b059 --- /dev/null +++ b/sal/qa/rtl/process/child_process.cxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <stdio.h> +#include "sal/main.h" +#include <rtl/process.h> +#include <rtl_Process_Const.h> + +// ----------------------------------- Main ----------------------------------- +SAL_IMPLEMENT_MAIN_WITH_ARGS(, argv) +{ + printf("# %s is called.\n", argv[0]); + + sal_Int32 nCount = rtl_getAppCommandArgCount(); + if ( nCount != 4 ) + { + printf( + "# not enough arguments found, need 4 found %ld.\n", + sal::static_int_cast< long >(nCount)); + return 0; + } + + OUString suArg[4]; + for( sal_Int32 i = 0 ; i < nCount ; i ++ ) + { + rtl_getAppCommandArg( i , &(suArg[i].pData) ); + OString aString; + aString = OUStringToOString( suArg[i], RTL_TEXTENCODING_ASCII_US ); + printf( + "# Parameter[%ld] is %s\n", sal::static_int_cast< long >(i), + aString.getStr()); + } + + if ( suArg[0] != suParam0 || + suArg[1] != suParam1 || + suArg[2] != suParam2 || + suArg[3] != suParam3 ) + { + return 0; + } + return 2; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/process/child_process_id.cxx b/sal/qa/rtl/process/child_process_id.cxx new file mode 100644 index 000000000..17f330fa7 --- /dev/null +++ b/sal/qa/rtl/process/child_process_id.cxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <stdio.h> +#include "sal/main.h" +#include <rtl/process.h> +#include <rtl_Process_Const.h> + +void printUuid( sal_uInt8 *pNode ) +{ + for( sal_Int32 i1 = 0 ; i1 < 4 ; i1++ ) + { + for( sal_Int32 i2 = 0 ; i2 < 4 ; i2++ ) + { + sal_uInt8 nValue = pNode[i1*4 +i2]; + if (nValue < 16) + { + printf( "0"); + } + printf( "%02x" ,nValue ); + } + if( i1 == 3 ) + break; + //printf( "-" ); + } +} + +// ----------------------------------- Main ----------------------------------- + +SAL_IMPLEMENT_MAIN() +{ + sal_uInt8 pTargetUUID[16]; + rtl_getGlobalProcessId( pTargetUUID ); + printUuid( pTargetUUID ); + return 1; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/process/rtl_Process.cxx b/sal/qa/rtl/process/rtl_Process.cxx new file mode 100644 index 000000000..eae3cd5c3 --- /dev/null +++ b/sal/qa/rtl/process/rtl_Process.cxx @@ -0,0 +1,254 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <memory> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sal/types.h> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> +#include <rtl/process.h> +#include <osl/process.h> +#include <osl/module.hxx> + +#include "rtl_Process_Const.h" + +using namespace osl; + +/** print a UNI_CODE String. And also print some comments of the string. +*/ +static void printUString( const OUString & str, const char * msg ) +{ + if ( msg != nullptr ) + { + printf("#%s #printUString_u# ", msg ); + } + OString aString = OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + printf("%s\n", aString.getStr( ) ); +} + +static OUString getModulePath() +{ + OUString suDirPath; + ::osl::Module::getUrlFromAddress( + reinterpret_cast< oslGenericFunction >(getModulePath), suDirPath ); + + printUString(suDirPath, "modulePath:"); + suDirPath = suDirPath.copy( 0, suDirPath.lastIndexOf('/') ); + suDirPath = suDirPath.copy( 0, suDirPath.lastIndexOf('/') + 1) + "bin"; + return suDirPath; +} + +namespace rtl_Process +{ +class getAppCommandArg : public CppUnit::TestFixture +{ +public: + void getAppCommandArg_001() + { +#if defined(_WIN32) + const OUString EXECUTABLE_NAME("child_process.exe"); +#else + const OUString EXECUTABLE_NAME("child_process"); +#endif + OUString suCWD = getModulePath(); + // OUString suCWD2 = getExecutableDirectory(); + + printUString(suCWD, "path to the current module"); + // printUString(suCWD2, "suCWD2"); + + oslProcess hProcess = nullptr; + + const int nParameterCount = 4; + rtl_uString* pParameters[ nParameterCount ]; + + pParameters[0] = suParam0.pData; + pParameters[1] = suParam1.pData; + pParameters[2] = suParam2.pData; + pParameters[3] = suParam3.pData; + + OUString suFileURL = suCWD + "/" + EXECUTABLE_NAME; + + oslProcessError osl_error = osl_executeProcess( + suFileURL.pData, + pParameters, + nParameterCount, + osl_Process_WAIT, + nullptr, /* osl_getCurrentSecurity() */ + suCWD.pData, + nullptr, + 0, + &hProcess ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createProcess failed", + osl_Process_E_None, osl_error + ); + //we could get return value only after the process terminated + osl_joinProcess(hProcess); + // CPPUNIT_ASSERT_MESSAGE + // ( + // "osl_joinProcess returned with failure", + // osl_Process_E_None == osl_error + // ); + std::unique_ptr<oslProcessInfo> pInfo( new oslProcessInfo ); + //please pay attention to initial the Size to sizeof(oslProcessInfo), or else + //you will get unknown error when call osl_getProcessInfo + pInfo->Size = sizeof(oslProcessInfo); + osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo.get() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_getProcessInfo returned with failure", + osl_Process_E_None, osl_error + ); + + printf("the exit code is %" SAL_PRIuUINT32 ".\n", pInfo->Code ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("rtl_getAppCommandArg or rtl_getAppCommandArgCount error.", static_cast<oslProcessExitCode>(2), pInfo->Code); + } + + CPPUNIT_TEST_SUITE(getAppCommandArg); + CPPUNIT_TEST(getAppCommandArg_001); + // CPPUNIT_TEST(getAppCommandArg_002); + CPPUNIT_TEST_SUITE_END(); +}; // class getAppCommandArg + +/************************************************************************ + * For diagnostics( from sal/test/testuuid.cxx ) + ************************************************************************/ +static void printUuid( const sal_uInt8 *pNode ) +{ + printf("# UUID is: "); + for( sal_Int32 i1 = 0 ; i1 < 4 ; i1++ ) + { + for( sal_Int32 i2 = 0 ; i2 < 4 ; i2++ ) + { + sal_uInt8 nValue = pNode[i1*4 +i2]; + if (nValue < 16) + { + printf( "0"); + } + printf( "%02x" ,nValue ); + } + if( i1 == 3 ) + break; + printf( "-" ); + } + printf("\n"); +} + +/************************************************************************** + * output UUID to a string + **************************************************************************/ +static void printUuidtoBuffer( const sal_uInt8 *pNode, char * pBuffer ) +{ + sal_Int8 nPtr = 0; + for( sal_Int32 i1 = 0 ; i1 < 16 ; i1++ ) + { + sal_uInt8 nValue = pNode[i1]; + if (nValue < 16) + { + sprintf( pBuffer + nPtr, "0"); + nPtr++; + } + sprintf( pBuffer + nPtr, "%02x", nValue ); + nPtr += 2 ; + } +} + +class getGlobalProcessId : public CppUnit::TestFixture +{ +public: + //gets a 16-byte fixed size identifier which is guaranteed not to change during the current process. + void getGlobalProcessId_001() + { + sal_uInt8 pTargetUUID1[16]; + sal_uInt8 pTargetUUID2[16]; + rtl_getGlobalProcessId( pTargetUUID1 ); + rtl_getGlobalProcessId( pTargetUUID2 ); + CPPUNIT_ASSERT_MESSAGE("getGlobalProcessId: got two same ProcessIds.", !memcmp( pTargetUUID1 , pTargetUUID2 , 16 ) ); + } + //different processes different pids + void getGlobalProcessId_002() + { +#if defined(_WIN32) + const OUString EXEC_NAME("child_process_id.exe"); +#else + const OUString EXEC_NAME("child_process_id"); +#endif + sal_uInt8 pTargetUUID1[16]; + rtl_getGlobalProcessId( pTargetUUID1 ); + printUuid( pTargetUUID1 ); + char pUUID1[32]; + printUuidtoBuffer( pTargetUUID1, pUUID1 ); + printf("# UUID to String is %s\n", pUUID1); + + OUString suCWD = getModulePath(); + oslProcess hProcess = nullptr; + OUString suFileURL = suCWD + "/" + EXEC_NAME; + oslFileHandle* pChildOutputRead = new oslFileHandle(); + oslProcessError osl_error = osl_executeProcess_WithRedirectedIO( + suFileURL.pData, + nullptr, + 0, + osl_Process_WAIT, + nullptr, + suCWD.pData, + nullptr, + 0, + &hProcess, + nullptr, + pChildOutputRead, + nullptr); + + CPPUNIT_ASSERT_EQUAL_MESSAGE + ( + "osl_createProcess failed", + osl_Process_E_None, osl_error + ); + //we could get return value only after the process terminated + osl_joinProcess(hProcess); + + char pUUID2[33] {}; + sal_uInt64 nRead = 0; + osl_readFile( *pChildOutputRead, pUUID2, 32, &nRead ); + printf("read buffer is %s, nRead is %" SAL_PRIdINT64 "\n", pUUID2, nRead ); + OUString suUUID2 = OUString::createFromAscii( pUUID2 ); + CPPUNIT_ASSERT_MESSAGE("getGlobalProcessId: got two same ProcessIds.", !suUUID2.equalsAsciiL( pUUID1, 32) ); + } + + CPPUNIT_TEST_SUITE(getGlobalProcessId); + CPPUNIT_TEST(getGlobalProcessId_001); + CPPUNIT_TEST(getGlobalProcessId_002); + CPPUNIT_TEST_SUITE_END(); + +}; // class getGlobalProcessId + +} // namespace rtl_Process + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Process::getAppCommandArg, "rtl_Process"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Process::getGlobalProcessId, "rtl_Process"); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/process/rtl_Process_Const.h b/sal/qa/rtl/process/rtl_Process_Const.h new file mode 100644 index 000000000..50c38eb97 --- /dev/null +++ b/sal/qa/rtl/process/rtl_Process_Const.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_QA_RTL_PROCESS_RTL_PROCESS_CONST_H +#define INCLUDED_SAL_QA_RTL_PROCESS_RTL_PROCESS_CONST_H + +#include <rtl/ustring.hxx> + +#ifdef __cplusplus +extern "C" +{ +#endif + +OUString suParam0("-join"); +OUString suParam1("-with"); +OUString suParam2("-child"); +OUString suParam3("-process"); + +#ifdef __cplusplus +} +#endif + +#endif /* RTL_PROCESS_CONST_H*/ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/random/random.txt b/sal/qa/rtl/random/random.txt new file mode 100644 index 000000000..c5546df9b --- /dev/null +++ b/sal/qa/rtl/random/random.txt @@ -0,0 +1,22 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +rtl_random.createPool.createPool_001 +rtl_random.destroyPool.destroyPool_001 +rtl_random.addBytes.addBytes_001 +rtl_random.getBytes.getBytes_001 + diff --git a/sal/qa/rtl/random/rtl_random.cxx b/sal/qa/rtl/random/rtl_random.cxx new file mode 100644 index 000000000..c43638277 --- /dev/null +++ b/sal/qa/rtl/random/rtl_random.cxx @@ -0,0 +1,357 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <memory> +#include <algorithm> + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <rtl/random.h> + +#include <string.h> + +namespace rtl_random +{ + +class createPool : public CppUnit::TestFixture +{ +public: + // insert your test code here. + // this is only demonstration code + void createPool_001() + { + // this is demonstration code + + rtlRandomPool aPool = rtl_random_createPool(); + + // LLA: seems to be that another test is not possible for createPool() + CPPUNIT_ASSERT_MESSAGE("create failed", aPool != nullptr); + + rtl_random_destroyPool(aPool); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(createPool); + CPPUNIT_TEST(createPool_001); + CPPUNIT_TEST_SUITE_END(); +}; // class createPool + +class destroyPool : public CppUnit::TestFixture +{ +public: + // insert your test code here. + void destroyPool_000() + { + // GPF, if failed + rtl_random_destroyPool(nullptr); + } + + void destroyPool_001() + { + rtlRandomPool aPool = rtl_random_createPool(); + + // LLA: seems to be that another test is not possible for createPool() + CPPUNIT_ASSERT_MESSAGE("create failed", aPool != nullptr); + + rtl_random_destroyPool(aPool); + } + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(destroyPool); + CPPUNIT_TEST(destroyPool_000); + CPPUNIT_TEST(destroyPool_001); + CPPUNIT_TEST_SUITE_END(); +}; // class destroyPool + +class addBytes : public CppUnit::TestFixture +{ +public: + // insert your test code here. + // this is only demonstration code + void addBytes_000() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); + + rtlRandomError aError = rtl_random_addBytes(nullptr, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); + + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); + + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); + + rtl_random_destroyPool(aPool); + } + + void addBytes_001() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + + memset(pBuffer.get(), 0, nBufLen); + + rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); + + printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); + + rtl_random_destroyPool(aPool); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(addBytes); + CPPUNIT_TEST(addBytes_000); + CPPUNIT_TEST(addBytes_001); + CPPUNIT_TEST_SUITE_END(); +}; // class addBytes + +namespace { + +class Statistics +{ + int m_nDispensation[256]; + + int m_nMin; + int m_nMax; + int m_nAverage; + int m_nMinDeviation; + int m_nMaxDeviation; + +public: + void clearDispensation() + { + for (int i = 0;i < 256;++i) // clear array + { + m_nDispensation[i] = 0; + } + } + Statistics() + : m_nMin(0) + , m_nMax(0) + , m_nAverage(0) + , m_nMinDeviation(0) + , m_nMaxDeviation(0) + { + clearDispensation(); + } + + void addValue(sal_uInt8 _nIndex, sal_Int32 _nValue) + { + m_nDispensation[_nIndex] += _nValue; + } + + void build(sal_Int32 _nCountMax) + { + m_nMin = _nCountMax; + m_nMax = 0; + + m_nAverage = _nCountMax / 256; + + m_nMinDeviation = _nCountMax; + m_nMaxDeviation = 0; + + for (int i = 0;i < 256;++i) // show dispensation + { + m_nMin = std::min(m_nMin, m_nDispensation[i]); + m_nMax = std::max(m_nMax, m_nDispensation[i]); + + m_nMinDeviation = std::min(m_nMinDeviation, abs(m_nAverage - m_nDispensation[i])); + m_nMaxDeviation = std::max(m_nMaxDeviation, abs(m_nAverage - m_nDispensation[i])); + } + } + + void print() + { + // LLA: these are only info values + printf("\nSome statistics\n"); + printf("Min: %d\n", m_nMin); + printf("Max: %d\n", m_nMax); + printf("Average: %d\n", m_nAverage); + printf("Min abs deviation: %d\n", m_nMinDeviation); + printf("Max abs deviation: %d\n", m_nMaxDeviation); + } + + sal_Int32 getAverage() const {return m_nAverage;} + sal_Int32 getMaxDeviation() const {return m_nMaxDeviation;} + +}; + +} + +class getBytes : public CppUnit::TestFixture +{ +public: + // insert your test code here. + void getBytes_000() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); + + rtlRandomError aError = rtl_random_getBytes(nullptr, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); + + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, nullptr, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); + + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); + + rtl_random_destroyPool(aPool); + } + + void getBytes_001() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); + + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); + + printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); + + rtl_random_destroyPool(aPool); + } + + void getBytes_002() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen << 1 ] ); + memset(pBuffer.get(), 0, nBufLen << 1); + + CPPUNIT_ASSERT_MESSAGE("memset failed", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); + + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); + + printf("%2x %2x %2x %2x %2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3], pBuffer[4], pBuffer[5], pBuffer[6], pBuffer[7]); + + CPPUNIT_ASSERT_MESSAGE("internal memory overwrite", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); + + rtl_random_destroyPool(aPool); + } + + void getBytes_003() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 1; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); + + Statistics aStat; + + CPPUNIT_ASSERT_EQUAL_MESSAGE("memset failed", static_cast<sal_uInt8>(0), pBuffer[0]); + + int nCount = 0; + + int nCountMax = 1000000; + for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) + { + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); + /* CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); */ + + aStat.addValue(pBuffer[0], 1); + } + + aStat.build(nCountMax); + aStat.print(); + + CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); + + rtl_random_destroyPool(aPool); + } + + void getBytes_003_1() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 256; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); + + Statistics aStat; + + CPPUNIT_ASSERT_EQUAL_MESSAGE("memset failed", static_cast<sal_uInt8>(0), pBuffer[0]); + + int nCount = 0; + + int nCountMax = 10000; + for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) + { + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); + // CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); + + for (sal_uInt32 i=0;i<nBufLen;++i) + aStat.addValue(pBuffer[i], 1); + } + + aStat.build(nCountMax * nBufLen); + aStat.print(); + + CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); + + rtl_random_destroyPool(aPool); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(getBytes); + CPPUNIT_TEST(getBytes_000); + CPPUNIT_TEST(getBytes_001); + CPPUNIT_TEST(getBytes_002); + CPPUNIT_TEST(getBytes_003); + CPPUNIT_TEST(getBytes_003_1); + CPPUNIT_TEST_SUITE_END(); +}; // class getBytes + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::createPool); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::destroyPool); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::addBytes); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::getBytes); +} // namespace rtl_random + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/ref/rtl_ref.cxx b/sal/qa/rtl/ref/rtl_ref.cxx new file mode 100644 index 000000000..2bf7c9803 --- /dev/null +++ b/sal/qa/rtl/ref/rtl_ref.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <rtl/ref.hxx> +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +namespace rtl_ref +{ + +namespace { + +class MoveTestClass +{ +private: + bool m_bIncFlag; + long m_nRef; +public: + MoveTestClass(): m_bIncFlag(false), m_nRef(0) { } + + // There should never be more than two references to this class as it + // is used as a test class for move functions. One reference being the + // original reference and the second being the test reference + void acquire() + { + if(m_bIncFlag) + { + ++m_nRef; + m_bIncFlag = false; + } + else + CPPUNIT_FAIL("RC was incremented when in should not have been"); + } + + void release() { --m_nRef; } + + long use_count() { return m_nRef; } + + void set_inc_flag() { m_bIncFlag = true; } +}; + +} + +static rtl::Reference< MoveTestClass > get_reference( MoveTestClass* pcTestClass ) +{ + // constructor will increment the reference count + pcTestClass->set_inc_flag(); + rtl::Reference< MoveTestClass > tmp(pcTestClass); + return tmp; +} + +class TestReferenceRefCounting : public CppUnit::TestFixture +{ + void testMove() + { + MoveTestClass cTestClass; + + // constructor will increment the reference count + cTestClass.set_inc_flag(); + rtl::Reference< MoveTestClass > test1( &cTestClass ); + + // move should not increment the reference count + rtl::Reference< MoveTestClass > test2( std::move(test1) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test2.use_count() == 1", + static_cast<long>(1), test2->use_count()); + + // test1 now contains a null pointer + CPPUNIT_ASSERT_MESSAGE("!test1.is()", + !test1.is()); // NOLINT(bugprone-use-after-move) + + // function return should move the reference + test2 = get_reference( &cTestClass ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test2.use_count() == 1", + static_cast<long>(1), test2->use_count()); + + // normal copy + test2->set_inc_flag(); + test1 = test2; + CPPUNIT_ASSERT_EQUAL_MESSAGE("test2.use_count() == 2", + static_cast<long>(2), test2->use_count()); + + // use count should decrement + test2 = rtl::Reference< MoveTestClass >(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("test1.use_count() == 1", + static_cast<long>(1), test1->use_count()); + + // move of a null pointer should not cause an error + test1 = std::move(test2); + + CPPUNIT_ASSERT_MESSAGE("!test1.is()", + !test1.is()); + CPPUNIT_ASSERT_MESSAGE("!test2.is()", + !test2.is()); // NOLINT(bugprone-use-after-move) + + CPPUNIT_ASSERT_EQUAL_MESSAGE("cTestClass.use_count() == 0", + static_cast<long>(0), cTestClass.use_count()); + } + + CPPUNIT_TEST_SUITE(TestReferenceRefCounting); + CPPUNIT_TEST(testMove); + CPPUNIT_TEST_SUITE_END(); +}; + +} // namespace rtl_ref +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_ref::TestReferenceRefCounting); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_ostring.cxx b/sal/qa/rtl/strings/test_ostring.cxx new file mode 100644 index 000000000..0d0d07be7 --- /dev/null +++ b/sal/qa/rtl/strings/test_ostring.cxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/string.hxx> + +namespace { + +class Test: public CppUnit::TestFixture { +private: + void testStartsWithIgnoreAsciiCase(); + void testCompareTo(); + void testUtf8StringLiterals(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testStartsWithIgnoreAsciiCase); + CPPUNIT_TEST(testCompareTo); + CPPUNIT_TEST(testUtf8StringLiterals); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::testStartsWithIgnoreAsciiCase() { + { + OString r; + CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase(OString(), &r)); + CPPUNIT_ASSERT(r.isEmpty()); + } + { + OString r; + CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase(OString(), &r)); + CPPUNIT_ASSERT_EQUAL(OString("foo"), r); + } + { + OString r; + CPPUNIT_ASSERT( + OString("foo").startsWithIgnoreAsciiCase("F", &r)); + CPPUNIT_ASSERT_EQUAL(OString("oo"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("bar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("foobar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } + + { + OString r; + CPPUNIT_ASSERT(OString().startsWithIgnoreAsciiCase("", &r)); + CPPUNIT_ASSERT(r.isEmpty()); + } + { + OString r; + CPPUNIT_ASSERT(OString("foo").startsWithIgnoreAsciiCase("", &r)); + CPPUNIT_ASSERT_EQUAL(OString("foo"), r); + } + { + OString r; + CPPUNIT_ASSERT( + OString("foo").startsWithIgnoreAsciiCase("F", &r)); + CPPUNIT_ASSERT_EQUAL(OString("oo"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("bar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } + { + OString r("other"); + CPPUNIT_ASSERT( + !OString("foo").startsWithIgnoreAsciiCase("foobar", &r)); + CPPUNIT_ASSERT_EQUAL(OString("other"), r); + } +} + +void Test::testCompareTo() +{ + // test that embedded NUL does not stop the compare + char str1[2] = { '\0', 'x' }; + char str2[2] = { '\0', 'y' }; + + OString s1(str1, 2); + OString s2(str2, 2); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s1.compareTo(s1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s2.compareTo(s2)); + CPPUNIT_ASSERT(s1.compareTo(s2) < 0); + CPPUNIT_ASSERT(s2.compareTo(s1) > 0); + CPPUNIT_ASSERT(s1.compareTo(OString(s2 + "y")) < 0); + CPPUNIT_ASSERT(s2.compareTo(OString(s1 + "x")) > 0); + CPPUNIT_ASSERT(OString(s1 + "x").compareTo(s2) < 0); + CPPUNIT_ASSERT(OString(s2 + "y").compareTo(s1) > 0); +} + +void Test::testUtf8StringLiterals() +{ + const OString sIn(u8"ßa"); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), sIn.getLength()); + CPPUNIT_ASSERT_EQUAL(195, int(static_cast<unsigned char>(sIn[0]))); + CPPUNIT_ASSERT_EQUAL(159, int(static_cast<unsigned char>(sIn[1]))); + CPPUNIT_ASSERT_EQUAL(97, int(static_cast<unsigned char>(sIn[2]))); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_ostring_concat.cxx b/sal/qa/rtl/strings/test_ostring_concat.cxx new file mode 100644 index 000000000..bcb4a3e3b --- /dev/null +++ b/sal/qa/rtl/strings/test_ostring_concat.cxx @@ -0,0 +1,183 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// activate support for detecting errors instead of getting compile errors +#define RTL_STRING_UNITTEST_CONCAT + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +#include <string> +#include <typeinfo> + +bool rtl_string_unittest_invalid_concat = false; + +using namespace rtl; + +namespace CppUnit +{ +template<> struct assertion_traits<std::type_info> +{ + static bool equal(std::type_info const & x, std::type_info const & y) { return x == y; } + + static std::string toString(std::type_info const & x) { return x.name(); } +}; +} // namespace + +namespace test::ostring { + +class StringConcat : public CppUnit::TestFixture +{ +private: + void checkConcat(); + void checkEnsureCapacity(); + void checkAppend(); + void checkInvalid(); + +CPPUNIT_TEST_SUITE(StringConcat); +CPPUNIT_TEST(checkConcat); +CPPUNIT_TEST(checkEnsureCapacity); +CPPUNIT_TEST(checkAppend); +CPPUNIT_TEST(checkInvalid); +CPPUNIT_TEST_SUITE_END(); +}; + +void test::ostring::StringConcat::checkConcat() +{ +// All the extra () are to protect commas against being treated as separators of macro arguments. + CPPUNIT_ASSERT_EQUAL( OString(), OString(OString() + OString())); + CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OString( "foo" ) + OString( "bar" ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, OString > )), typeid( OString( "foo" ) + OString( "bar" ))); + CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OString( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char[ 4 ] > )), typeid( OString( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL( OString( "foobarbaz" ), OString( OString( "foo" ) + "bar" + "baz" )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OStringConcat< OString, const char[ 4 ] >, const char[ 4 ] > )), typeid( OString( "foo" ) + "bar" + "baz" )); + CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OStringLiteral( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OStringLiteral, const char[ 4 ] > )), typeid( OStringLiteral( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OStringLiteral( "foo" ) + static_cast<const char*>("bar") )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OStringLiteral, const char* > )), typeid( OStringLiteral( "foo" ) + static_cast<const char*>("bar") )); + const char d1[] = "xyz"; + char d2[] = "abc"; + const char* d3 = d1; + char* d4 = d2; + CPPUNIT_ASSERT_EQUAL( OString( "fooxyz" ), OString( OString( "foo" ) + d1 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char[ 4 ] > )), typeid( OString( "foo" ) + d1 )); + CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d2 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, char[ 4 ] > )), typeid( OString( "foo" ) + d2 )); + CPPUNIT_ASSERT_EQUAL( OString( "fooxyz" ), OString( OString( "foo" ) + d3 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char* > )), typeid( OString( "foo" ) + d3 )); + CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d4 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, char* > )), typeid( OString( "foo" ) + d4 )); + CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d4 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, char* > )), typeid( OString( "foo" ) + d4 )); + CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( rtl::OStringView( "foo" ) + d4 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< rtl::OStringView, char* > )), typeid( rtl::OStringView( "foo" ) + d4 )); + + CPPUNIT_ASSERT_EQUAL( OString( "num10" ), OString( OString( "num" ) + OString::number( 10 ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, OStringNumber< int > > )), typeid( OString( "num" ) + OString::number( 10 ))); + CPPUNIT_ASSERT_EQUAL( OString( "num10" ), OString( OString( "num" ) + OString::number( 10L ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, OStringNumber< long long > > )), typeid( OString( "num" ) + OString::number( 10L ))); + CPPUNIT_ASSERT_EQUAL( OString( "num10" ), OString( OString( "num" ) + OString::number( 10ULL ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, OStringNumber< unsigned long long > > )), typeid( OString( "num" ) + OString::number( 10ULL ))); + CPPUNIT_ASSERT_EQUAL( OString( "num10.5" ), OString( OString( "num" ) + OString::number( 10.5f ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, OStringNumber< float > > )), typeid( OString( "num" ) + OString::number( 10.5f ))); + CPPUNIT_ASSERT_EQUAL( OString( "num10.5" ), OString( OString( "num" ) + OString::number( 10.5 ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, OStringNumber< double > > )), typeid( OString( "num" ) + OString::number( 10.5 ))); +} + +void test::ostring::StringConcat::checkEnsureCapacity() +{ + rtl_String* str = nullptr; + rtl_string_newFromLiteral( &str, "test", strlen( "test" ), 0 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + + rtl_String* oldStr = str; + rtl_string_ensureCapacity( &str, 4 ); // should be no-op + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + CPPUNIT_ASSERT_EQUAL( str, oldStr ); + + rtl_string_acquire( oldStr ); + CPPUNIT_ASSERT_EQUAL( 2, int( str->refCount )); + rtl_string_ensureCapacity( &str, 4 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + // a copy was forced because of refcount + CPPUNIT_ASSERT( oldStr != str ); + CPPUNIT_ASSERT_EQUAL( 0, strcmp( oldStr->buffer, str->buffer ) ); + CPPUNIT_ASSERT_EQUAL( 1, int( oldStr->refCount )); + rtl_string_release( str ); + str = oldStr; + + rtl_string_acquire( oldStr ); + rtl_string_ensureCapacity( &str, 1024 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); // size is still 4 + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + CPPUNIT_ASSERT( oldStr != str ); + CPPUNIT_ASSERT_EQUAL( 0, strcmp( oldStr->buffer, str->buffer ) ); + CPPUNIT_ASSERT_EQUAL( 1, int( oldStr->refCount )); + strcpy( str->buffer, "01234567890123456789" ); // but there should be extra capacity + str->length += 20; + rtl_string_release( str ); + rtl_string_release( oldStr ); +} + +void test::ostring::StringConcat::checkAppend() +{ + OString str( "foo" ); + str += OStringLiteral( "bar" ) + "baz"; + CPPUNIT_ASSERT_EQUAL( OString( "foobarbaz" ), str ); + OStringBuffer buf( "foo" ); + buf.append( OStringLiteral( "bar" ) + "baz" ); + CPPUNIT_ASSERT_EQUAL( OString( "foobarbaz" ), buf.makeStringAndClear()); +} + +#define INVALID_CONCAT( expression ) \ + ( \ + rtl_string_unittest_invalid_concat = false, \ + ( void ) OString( expression ), \ + rtl_string_unittest_invalid_concat ) + +void test::ostring::StringConcat::checkInvalid() +{ + CPPUNIT_ASSERT( !INVALID_CONCAT( OString() + OString())); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OStringBuffer( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUString( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUStringBuffer( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUStringLiteral( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + rtl::OUStringView( u"b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + 1 )); + rtl_String* rs = nullptr; + rtl_uString* rus = nullptr; + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "b" ) + rs )); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "b" ) + rus )); + CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUString::number( 10 ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OString::number( 0 ) + OUString::number( 10 ))); + +#if 0 + // Should fail to compile, to avoid use of OStringConcat lvalues that + // contain dangling references to temporaries: + auto const conc = OStringLiteral("foo") + "bar"; + (void) OString(conc); +#endif +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(test::ostring::StringConcat); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx new file mode 100644 index 000000000..e513d56a5 --- /dev/null +++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx @@ -0,0 +1,263 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// activate the extra needed ctor +#define RTL_STRING_UNITTEST + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/string.h> +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> + +bool rtl_string_unittest_const_literal; +bool rtl_string_unittest_const_literal_function; +static bool rtl_string_unittest_non_const_literal_function; + +namespace test::ostring { + +class StringLiterals: public CppUnit::TestFixture +{ +private: + void checkCtors(); + void checkUsage(); + void checkNonConstUsage(); + void checkBuffer(); + + void testcall( const char str[] ); + + static const char bad5[]; + static char bad6[]; + +CPPUNIT_TEST_SUITE(StringLiterals); +CPPUNIT_TEST(checkCtors); +CPPUNIT_TEST(checkUsage); +CPPUNIT_TEST(checkNonConstUsage); +CPPUNIT_TEST(checkBuffer); +CPPUNIT_TEST_SUITE_END(); +}; + +// reset the flag, call OString ctor with the given argument and return +// whether the string literal ctor was used +#define CONST_CTOR_USED( argument ) \ + ( \ + rtl_string_unittest_const_literal = false, \ + ( void ) rtl::OString( argument ), \ + result_tmp = rtl_string_unittest_const_literal, \ + rtl_string_unittest_const_literal = false, \ + ( void ) rtl::OStringBuffer( argument ), \ + rtl_string_unittest_const_literal && result_tmp ) + +void test::ostring::StringLiterals::checkCtors() +{ + bool result_tmp; + CPPUNIT_ASSERT( CONST_CTOR_USED( "test" )); + const char good1[] = "test"; + CPPUNIT_ASSERT( CONST_CTOR_USED( good1 )); + + CPPUNIT_ASSERT( !CONST_CTOR_USED( static_cast<const char*>("test") )); + const char* bad1 = good1; + CPPUNIT_ASSERT( !CONST_CTOR_USED( bad1 )); + char bad2[] = "test"; + CPPUNIT_ASSERT( !CONST_CTOR_USED( bad2 )); + char* bad3 = bad2; + CPPUNIT_ASSERT( !CONST_CTOR_USED( bad3 )); + const char* bad4[] = { "test1" }; + CPPUNIT_ASSERT( !CONST_CTOR_USED( bad4[ 0 ] )); + testcall( good1 ); +#ifndef _MSC_VER + // this is actually not supposed to work (see discussion in stringutils.hxx), + // but gcc and clang somehow manage, so keep it used, just in case some other problem + // shows up somewhen in the future + CPPUNIT_ASSERT( !CONST_CTOR_USED( bad5 )); // size is not known here + CPPUNIT_ASSERT( !CONST_CTOR_USED( bad6 )); +#endif + +// This one is technically broken, since the first element is 6 characters test\0\0, +// but there does not appear a way to detect this by compile time (runtime will assert()). +// RTL_CONSTASCII_USTRINGPARAM() has the same flaw. + const char bad7[][ 6 ] = { "test", "test2" }; +// CPPUNIT_ASSERT( CONST_CTOR_USED( bad7[ 0 ] )); + CPPUNIT_ASSERT( CONST_CTOR_USED( bad7[ 1 ] )); + +// Check that contents are correct and equal to the case when const char* ctor is used. + CPPUNIT_ASSERT_EQUAL( rtl::OString( "" ), rtl::OString( static_cast<const char*>("") ) ); + CPPUNIT_ASSERT_EQUAL( rtl::OString( "ab" ), rtl::OString( static_cast<const char*>("ab") ) ); + +// Check that contents are correct and equal to the case when RTL_CONSTASCII_STRINGPARAM is used. + CPPUNIT_ASSERT_EQUAL( rtl::OString( "" ), rtl::OString( RTL_CONSTASCII_STRINGPARAM( "" )) ); + CPPUNIT_ASSERT_EQUAL( rtl::OString( "ab" ), rtl::OString( RTL_CONSTASCII_STRINGPARAM( "ab" )) ); +} + +const char test::ostring::StringLiterals::bad5[] = "test"; +char test::ostring::StringLiterals::bad6[] = "test"; + +void test::ostring::StringLiterals::testcall( const char str[] ) +{ +#ifndef _MSC_VER + bool result_tmp; + CPPUNIT_ASSERT( !CONST_CTOR_USED( str )); +#else + // MSVC just errors out on this for some reason, which is fine as well + (void)str; +#endif +} + +void test::ostring::StringLiterals::checkUsage() +{ +// simply check that all string literal based calls work as expected +// also check that they really use string literal overload and do not convert to OString + rtl::OString foo( "foo" ); + rtl::OString FoO( "FoO" ); + rtl::OString foobarfoo( "foobarfoo" ); + rtl::OString foobar( "foobar" ); + rtl::OString FooBaRfoo( "FooBaRfoo" ); + rtl::OString FooBaR( "FooBaR" ); + rtl::OString bar( "bar" ); + + rtl_string_unittest_const_literal = false; // start checking for OString conversions + rtl_string_unittest_non_const_literal_function = false; // and check for non-const variants + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT_EQUAL( foo, rtl::OString() = "foo" ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( FoO.equalsIgnoreAsciiCase( "fOo" )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( foobarfoo.match( "bar", 3 )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( foobar.match( "foo" )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( "bAr", 3 )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( "fOo" )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( foobar.startsWith( "foo" )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( foobar.endsWith( "bar" )); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); +// rtl_string_unittest_const_literal_function = false; +// CPPUNIT_ASSERT( FooBaR.endsWithIgnoreAsciiCase( "bar" )); +// CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( bool(foo == "foo") ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( bool("foo" == foo) ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( foo != "bar" ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT( "foo" != bar ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + rtl_string_unittest_const_literal_function = false; + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(6), foobarfoo.indexOf( "foo", 1 ) ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); +// rtl_string_unittest_const_literal_function = false; +// CPPUNIT_ASSERT( foobarfoo.lastIndexOf( "foo" ) == 6 ); +// CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true ); + // if this is not true, some of the calls above converted to OString + CPPUNIT_ASSERT( !rtl_string_unittest_const_literal ); + // if this is not true, some of the calls above used non-const variants + CPPUNIT_ASSERT( !rtl_string_unittest_non_const_literal_function ); +} + +void test::ostring::StringLiterals::checkNonConstUsage() +{ +// check that (non-const) char[] overloads work and do not use const char[] overloads + rtl::OString foo( "foo" ); + rtl::OString FoO( "FoO" ); + rtl::OString foobarfoo( "foobarfoo" ); + rtl::OString foobar( "foobar" ); + rtl::OString FooBaRfoo( "FooBaRfoo" ); + rtl::OString FooBaR( "FooBaR" ); + rtl::OString bar( "bar" ); + char foo_c[] = "foo"; + char bar_c[] = "bar"; + char fOo_c[] = "fOo"; + char bAr_c[] = "bAr"; + + rtl_string_unittest_const_literal = false; // start checking for OString conversions + rtl_string_unittest_const_literal_function = false; // and check for const variants + CPPUNIT_ASSERT_EQUAL( foo, rtl::OString() = static_cast<const char*>(foo_c) ); + CPPUNIT_ASSERT_EQUAL( foo, rtl::OString() = foo_c ); + CPPUNIT_ASSERT( FoO.equalsIgnoreAsciiCase( static_cast<const char*>(fOo_c) )); + CPPUNIT_ASSERT( FoO.equalsIgnoreAsciiCase( fOo_c )); + CPPUNIT_ASSERT( foobarfoo.match( static_cast<const char*>(bar_c), 3 )); + CPPUNIT_ASSERT( foobarfoo.match( bar_c, 3 )); + CPPUNIT_ASSERT( foobar.match( static_cast<const char*>(foo_c) )); + CPPUNIT_ASSERT( foobar.match( foo_c )); + CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( static_cast<const char*>(bAr_c), 3 )); + CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( bAr_c, 3 )); + CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( static_cast<const char*>(fOo_c) )); + CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( fOo_c )); + CPPUNIT_ASSERT( foobar.startsWith( static_cast<const char*>(foo_c) )); + CPPUNIT_ASSERT( foobar.startsWith( foo_c )); + CPPUNIT_ASSERT( foobar.endsWith( static_cast<const char*>(bar_c) )); + CPPUNIT_ASSERT( foobar.endsWith( bar_c )); +// CPPUNIT_ASSERT( FooBaR.endsWithIgnoreAsciiCase( (const char*)bar_c )); +// CPPUNIT_ASSERT( FooBaR.endsWithIgnoreAsciiCase( bar_c )); + CPPUNIT_ASSERT( bool(foo == static_cast<const char*>(foo_c)) ); + CPPUNIT_ASSERT( bool(foo == foo_c) ); + CPPUNIT_ASSERT( bool(static_cast<const char*>(foo_c) == foo) ); + CPPUNIT_ASSERT( bool(foo_c == foo) ); + CPPUNIT_ASSERT( foo != static_cast<const char*>(bar_c) ); + CPPUNIT_ASSERT( foo != bar_c ); + CPPUNIT_ASSERT( static_cast<const char*>(foo_c) != bar ); + CPPUNIT_ASSERT( foo_c != bar ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(6), foobarfoo.indexOf( static_cast<const char*>(foo_c), 1 ) ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(6), foobarfoo.indexOf( foo_c, 1 ) ); +// CPPUNIT_ASSERT( foobarfoo.lastIndexOf( (const char*)foo_c ) == 6 ); +// CPPUNIT_ASSERT( foobarfoo.lastIndexOf( foo_c ) == 6 ); + // if this is not true, some of the calls above used const variants + CPPUNIT_ASSERT( !rtl_string_unittest_const_literal ); + CPPUNIT_ASSERT( !rtl_string_unittest_const_literal_function ); +} + +void test::ostring::StringLiterals::checkBuffer() +{ + rtl::OStringBuffer buf; + rtl_string_unittest_const_literal_function = false; + buf.append( "foo" ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + CPPUNIT_ASSERT_EQUAL( rtl::OString( "foo" ), buf.toString()); + rtl_string_unittest_const_literal_function = false; + buf.append( "bar" ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + CPPUNIT_ASSERT_EQUAL( rtl::OString( "foobar" ), buf.toString()); + rtl_string_unittest_const_literal_function = false; + buf.insert( 3, "baz" ); + CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function ); + CPPUNIT_ASSERT_EQUAL( rtl::OString( "foobazbar" ), buf.toString()); + + rtl::OString foobazbard( "foobazbard" ); + rtl::OString foodbazbard( "foodbazbard" ); + rtl_string_unittest_const_literal = false; // start checking for OString conversions + rtl_string_unittest_const_literal_function = false; // and check for const variants + char d[] = "d"; + CPPUNIT_ASSERT_EQUAL( foobazbard, buf.append( d ).toString()); + CPPUNIT_ASSERT_EQUAL( foodbazbard, buf.insert( 3, d ).toString() ); + CPPUNIT_ASSERT( !rtl_string_unittest_const_literal ); + CPPUNIT_ASSERT( !rtl_string_unittest_const_literal_function ); +} + +#undef CONST_CTOR_USED + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(test::ostring::StringLiterals); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_compare.cxx b/sal/qa/rtl/strings/test_oustring_compare.cxx new file mode 100644 index 000000000..c06d40c4d --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_compare.cxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/string.h> +#include <rtl/ustring.hxx> + +namespace test::oustring { + +class Compare: public CppUnit::TestFixture +{ +private: + void equalsIgnoreAsciiCaseAscii(); + void compareToIgnoreAsciiCase(); + void compareTo(); + +CPPUNIT_TEST_SUITE(Compare); +CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii); +CPPUNIT_TEST(compareToIgnoreAsciiCase); +CPPUNIT_TEST(compareTo); +CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare); + +void test::oustring::Compare::equalsIgnoreAsciiCaseAscii() +{ + const char* const abc = "abc"; + const char* const abcd = "abcd"; + const char* const empty = ""; + CPPUNIT_ASSERT(!OUString().equalsIgnoreAsciiCaseAscii(abc)); + CPPUNIT_ASSERT(!OUString().equalsIgnoreAsciiCaseAsciiL(abc,3)); + CPPUNIT_ASSERT(!OUString("abc"). + equalsIgnoreAsciiCaseAscii(empty)); + CPPUNIT_ASSERT(!OUString("abc"). + equalsIgnoreAsciiCaseAsciiL(empty,0)); + + CPPUNIT_ASSERT(OUString("abc"). + equalsIgnoreAsciiCaseAscii(abc)); + CPPUNIT_ASSERT(!OUString("abcd"). + equalsIgnoreAsciiCaseAscii(abc)); + CPPUNIT_ASSERT(!OUString("abc"). + equalsIgnoreAsciiCaseAscii(abcd)); +} + +void test::oustring::Compare::compareToIgnoreAsciiCase() +{ + CPPUNIT_ASSERT_EQUAL( + sal_Int32(0), + OUString("abc").compareToIgnoreAsciiCase("ABC")); + CPPUNIT_ASSERT( + OUString("ABC").compareToIgnoreAsciiCase("abcdef") + < 0); + CPPUNIT_ASSERT( + OUString("A").compareToIgnoreAsciiCase("_") > 0); +} + +void test::oustring::Compare::compareTo() +{ + // test that embedded NUL does not stop the compare + // this sort of thing is how we assign shape ids in oox + sal_Unicode str1[2] = { '\0', 'x' }; + sal_Unicode str2[2] = { '\0', 'y' }; + + OUString s1(str1, 2); + OUString s2(str2, 2); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s1.compareTo(s1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s2.compareTo(s2)); + CPPUNIT_ASSERT(s1.compareTo(s2) < 0); + CPPUNIT_ASSERT(s2.compareTo(s1) > 0); + CPPUNIT_ASSERT(s1.compareTo(OUString(s2 + "y")) < 0); + CPPUNIT_ASSERT(s2.compareTo(OUString(s1 + "x")) > 0); + CPPUNIT_ASSERT(OUString(s1 + "x").compareTo(s2) < 0); + CPPUNIT_ASSERT(OUString(s2 + "y").compareTo(s1) > 0); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_concat.cxx b/sal/qa/rtl/strings/test_oustring_concat.cxx new file mode 100644 index 000000000..bae7b65be --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_concat.cxx @@ -0,0 +1,194 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// activate support for detecting errors instead of getting compile errors +#define RTL_STRING_UNITTEST_CONCAT +extern bool rtl_string_unittest_invalid_concat; + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> + +#include <string> +#include <typeinfo> + +using namespace rtl; + +namespace CppUnit +{ +template<> struct assertion_traits<std::type_info> +{ + static bool equal(std::type_info const & x, std::type_info const & y) { return x == y; } + + static std::string toString(std::type_info const & x) { return x.name(); } +}; +} // namespace + +namespace test::oustring { + +class StringConcat : public CppUnit::TestFixture +{ +private: + void checkConcat(); + void checkConcatAsciiL(); + void checkEnsureCapacity(); + void checkAppend(); + void checkInvalid(); + +CPPUNIT_TEST_SUITE(StringConcat); +CPPUNIT_TEST(checkConcat); +CPPUNIT_TEST(checkConcatAsciiL); +CPPUNIT_TEST(checkEnsureCapacity); +CPPUNIT_TEST(checkAppend); +CPPUNIT_TEST(checkInvalid); +CPPUNIT_TEST_SUITE_END(); +}; + +void test::oustring::StringConcat::checkConcat() +{ +// All the extra () are to protect commas against being treated as separators of macro arguments. + CPPUNIT_ASSERT_EQUAL( OUString(), OUString(OUString() + OUString())); + CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUString( "foo" ) + OUString( "bar" ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUString > )), typeid( OUString( "foo" ) + OUString( "bar" ))); + CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUString( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL( OUString( "foobarbaz" ), OUString( OUString( "foo" ) + "bar" + "baz" )); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUStringConcat< OUString, const char[ 4 ] >, const char[ 4 ] > )), typeid( OUString( "foo" ) + "bar" + "baz" )); + CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUStringLiteral( "foo" ) + "bar" )); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUStringLiteral, const char[ 4 ] > )), typeid( OUStringLiteral( "foo" ) + "bar" )); + const char d1[] = "xyz"; + CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d1 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + d1 )); + const sal_Unicode* d2 = u"xyz"; + CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d2 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const sal_Unicode* > )), typeid( OUString( "foo" ) + d2 )); + CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( rtl::OUStringView( u"foo" ) + d2 )); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< rtl::OUStringView, const sal_Unicode* > )), typeid( rtl::OUStringView( u"foo" ) + d2 )); + + CPPUNIT_ASSERT_EQUAL( OUString( "num10" ), OUString( OUString( "num" ) + OUString::number( 10 ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUStringNumber< int > > )), typeid( OUString( "num" ) + OUString::number( 10 ))); + CPPUNIT_ASSERT_EQUAL( OUString( "num10" ), OUString( OUString( "num" ) + OUString::number( 10L ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUStringNumber< long long > > )), typeid( OUString( "num" ) + OUString::number( 10L ))); + CPPUNIT_ASSERT_EQUAL( OUString( "num10" ), OUString( OUString( "num" ) + OUString::number( 10ULL ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUStringNumber< unsigned long long > > )), typeid( OUString( "num" ) + OUString::number( 10ULL ))); + CPPUNIT_ASSERT_EQUAL( OUString( "num10.5" ), OUString( OUString( "num" ) + OUString::number( 10.5f ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUStringNumber< float > > )), typeid( OUString( "num" ) + OUString::number( 10.5f ))); + CPPUNIT_ASSERT_EQUAL( OUString( "num10.5" ), OUString( OUString( "num" ) + OUString::number( 10.5 ))); + CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUStringNumber< double > > )), typeid( OUString( "num" ) + OUString::number( 10.5 ))); +} + +void test::oustring::StringConcat::checkConcatAsciiL() +{ + { + OUString s("foo"); + CPPUNIT_ASSERT_EQUAL(OUString("foo"), s += ""); + } + { + OUString s("foo"); + CPPUNIT_ASSERT_EQUAL(OUString("foobar"), s += "bar"); + } +} + +void test::oustring::StringConcat::checkEnsureCapacity() +{ + rtl_uString* str = nullptr; + rtl_uString_newFromLiteral( &str, "test", strlen( "test" ), 0 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + + rtl_uString* oldStr = str; + rtl_uString_ensureCapacity( &str, 4 ); // should be no-op + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + CPPUNIT_ASSERT_EQUAL( str, oldStr ); + + rtl_uString_acquire( oldStr ); + CPPUNIT_ASSERT_EQUAL( 2, int( str->refCount )); + rtl_uString_ensureCapacity( &str, 4 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + // a copy was forced because of refcount + CPPUNIT_ASSERT( oldStr != str ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(0), rtl_ustr_compare( oldStr->buffer, str->buffer ) ); + CPPUNIT_ASSERT_EQUAL( 1, int( oldStr->refCount )); + rtl_uString_release( str ); + str = oldStr; + + rtl_uString_acquire( oldStr ); + rtl_uString_ensureCapacity( &str, 1024 ); + CPPUNIT_ASSERT_EQUAL( sal_Int32( 4 ), str->length ); // size is still 4 + CPPUNIT_ASSERT_EQUAL( 1, int( str->refCount )); + CPPUNIT_ASSERT( oldStr != str ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(0), rtl_ustr_compare( oldStr->buffer, str->buffer ) ); + CPPUNIT_ASSERT_EQUAL( 1, int( oldStr->refCount )); + // but there should be extra capacity + for( int i = 0; + i < 20; + ++i ) + str->buffer[ str->length + i ] = '0'; + str->length += 20; + rtl_uString_release( str ); + rtl_uString_release( oldStr ); +} + +void test::oustring::StringConcat::checkAppend() +{ + OUString str( "foo" ); + str += OUStringLiteral( "bar" ) + "baz"; + CPPUNIT_ASSERT_EQUAL( OUString( "foobarbaz" ), str ); + OUStringBuffer buf( "foo" ); + buf.append( OUStringLiteral( "bar" ) + "baz" ); + CPPUNIT_ASSERT_EQUAL( OUString( "foobarbaz" ), buf.makeStringAndClear()); +} + +#define INVALID_CONCAT( expression ) \ + ( \ + rtl_string_unittest_invalid_concat = false, \ + ( void ) OUString( expression ), \ + rtl_string_unittest_invalid_concat ) + +void test::oustring::StringConcat::checkInvalid() +{ + CPPUNIT_ASSERT( !INVALID_CONCAT( OUString() + OUString())); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OUStringBuffer( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OString( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OStringBuffer( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + static_cast<const char*>("b") )); + char d[] = "b"; + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + d )); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + static_cast<char*>(d) )); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OStringLiteral( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + rtl::OStringView( "b" ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + 1 )); + rtl_String* rs = nullptr; + rtl_uString* rus = nullptr; + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "b" ) + rs )); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "b" ) + rus )); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OString::number( 10 ))); + CPPUNIT_ASSERT( INVALID_CONCAT( OUString::number( 0 ) + OString::number( 10 ))); + +#if 0 + // Should fail to compile, to avoid use of OUStringConcat lvalues that + // contain dangling references to temporaries: + auto const conc = OUStringLiteral("foo") + "bar"; + (void) OUString(conc); +#endif +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::StringConcat); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_convert.cxx b/sal/qa/rtl/strings/test_oustring_convert.cxx new file mode 100644 index 000000000..bfd1a2aac --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_convert.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/strbuf.hxx> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <sal/macros.h> + +namespace test::oustring { + +class Convert: public CppUnit::TestFixture +{ +private: + void convertToString(); + + CPPUNIT_TEST_SUITE(Convert); + CPPUNIT_TEST(convertToString); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Convert); + +namespace { + +struct TestConvertToString +{ + sal_Unicode aSource[100]; + sal_Int32 nLength; + rtl_TextEncoding nEncoding; + sal_uInt32 nFlags; + char const * pStrict; + char const * pRelaxed; +}; + +void testConvertToString(TestConvertToString const & rTest) +{ + const OUString aSource(rTest.aSource, rTest.nLength); + OString aStrict(RTL_CONSTASCII_STRINGPARAM("12345")); + bool bSuccess = aSource.convertToString(&aStrict, rTest.nEncoding, + rTest.nFlags); + OString aRelaxed(OUStringToOString(aSource, rTest.nEncoding, + rTest.nFlags)); + + OStringBuffer aPrefix; + aPrefix.append("{"); + for (sal_Int32 i = 0; i < rTest.nLength; ++i) + { + aPrefix.append("U+"); + aPrefix.append(static_cast< sal_Int32 >(rTest.aSource[i]), 16); + if (i + 1 < rTest.nLength) + aPrefix.append(","); + } + aPrefix.append("}, "); + aPrefix.append(static_cast< sal_Int32 >(rTest.nEncoding)); + aPrefix.append(", 0x"); + aPrefix.append(static_cast< sal_Int32 >(rTest.nFlags), 16); + aPrefix.append(" -> "); + + if (bSuccess) + { + if (rTest.pStrict == nullptr || aStrict != rTest.pStrict) + { + OStringBuffer aMessage(aPrefix); + aMessage.append("strict = \""); + aMessage.append(aStrict); + aMessage.append("\""); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } + } + else + { + if (aStrict != OString(RTL_CONSTASCII_STRINGPARAM("12345"))) + { + OStringBuffer aMessage(aPrefix); + aMessage.append("modified output"); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } + if (rTest.pStrict != nullptr) + { + OStringBuffer aMessage(aPrefix); + aMessage.append("failed"); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } + } + if (aRelaxed != rTest.pRelaxed) + { + OStringBuffer aMessage(aPrefix); + aMessage.append("relaxed = \""); + aMessage.append(aRelaxed); + aMessage.append("\""); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } +} + +} + +void test::oustring::Convert::convertToString() +{ + TestConvertToString const aTests[] + = { { { 0 }, + 0, + RTL_TEXTENCODING_ASCII_US, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR, + "", + "" }, + { { 0 }, + 0, + RTL_TEXTENCODING_ASCII_US, + OUSTRING_TO_OSTRING_CVTFLAGS, + "", + "" }, + { { 0x0041,0x0042,0x0043 }, + 3, + RTL_TEXTENCODING_ASCII_US, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR, + "ABC", + "ABC" }, + { { 0x0041,0x0042,0x0043 }, + 3, + RTL_TEXTENCODING_ASCII_US, + OUSTRING_TO_OSTRING_CVTFLAGS, + "ABC", + "ABC" }, + { { 0xB800 }, + 1, + RTL_TEXTENCODING_ISO_2022_JP, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR, + nullptr, + "" }, + { { 0x3001, 0xB800 }, + 2, + RTL_TEXTENCODING_ISO_2022_JP, + OUSTRING_TO_OSTRING_CVTFLAGS, + "\x1b\x24\x42\x21\x22\x1b\x28\x42\x3f", + "\x1b\x24\x42\x21\x22\x1b\x28\x42\x3f" }, + { { 0x0041,0x0100,0x0042 }, + 3, + RTL_TEXTENCODING_ISO_8859_1, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR, + nullptr, + "A" }, + { { 0x0041,0x0100,0x0042 }, + 3, + RTL_TEXTENCODING_ISO_8859_1, + OUSTRING_TO_OSTRING_CVTFLAGS, + "A?B", + "A?B" } }; + for (size_t i = 0; i < SAL_N_ELEMENTS(aTests); ++i) + testConvertToString(aTests[i]); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_endswith.cxx b/sal/qa/rtl/strings/test_oustring_endswith.cxx new file mode 100644 index 000000000..bf01577e2 --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_endswith.cxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/strbuf.hxx> +#include <rtl/string.h> +#include <rtl/string.hxx> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> +#include <sal/macros.h> + +namespace test::oustring { + +class EndsWith: public CppUnit::TestFixture +{ +private: + void endsWith(); + + CPPUNIT_TEST_SUITE(EndsWith); + CPPUNIT_TEST(endsWith); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::EndsWith); + +namespace { + +void appendString(OStringBuffer & buffer, OString const & string) +{ + buffer.append('"'); + for (int i = 0; i < string.getLength(); ++i) { + char c = string[i]; + if (c < ' ' || c == '"' || c == '\\' || c > '~') { + buffer.append('\\'); + sal_Int32 n = static_cast< sal_Int32 >( + static_cast< unsigned char >(c)); + if (n < 16) { + buffer.append('0'); + } + buffer.append(n, 16); + } else { + buffer.append(c); + } + } + buffer.append('"'); +} + +} + +void test::oustring::EndsWith::endsWith() +{ + struct Data { + char const * str1; + sal_Int32 str1Len; + char const * str2; + sal_Int32 str2Len; + bool endsWith; + }; + Data const data[] = { + { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""), + true }, + { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""), + true }, + { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"), + false }, + { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"), + true }, + { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"), + true }, + { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"), + false }, + { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"), + RTL_CONSTASCII_STRINGPARAM("b\0c"), true }, + { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"), + RTL_CONSTASCII_STRINGPARAM("b"), false } }; + for (size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + OStringBuffer msg; + appendString(msg, OString(data[i].str1, data[i].str1Len)); + msg.append(".endsWithIgnoreAsciiCaseAsciiL("); + appendString(msg, OString(data[i].str2, data[i].str2Len)); + msg.append(") == "); + msg.append(data[i].endsWith); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + msg.getStr(), + data[i].endsWith, + OUString( + data[i].str1, data[i].str1Len, + RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL( + data[i].str2, data[i].str2Len)); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_startswith.cxx b/sal/qa/rtl/strings/test_oustring_startswith.cxx new file mode 100644 index 000000000..a74671e6e --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_startswith.cxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/ustring.hxx> + +namespace test::oustring { + +class StartsWith: public CppUnit::TestFixture +{ +private: + void startsWith(); + + CPPUNIT_TEST_SUITE(StartsWith); + CPPUNIT_TEST(startsWith); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::StartsWith); + +void test::oustring::StartsWith::startsWith() +{ + CPPUNIT_ASSERT( OUString( "foobar" ).startsWith( "foo" )); + CPPUNIT_ASSERT( !OUString( "foo" ).startsWith( "foobar" )); + CPPUNIT_ASSERT( !OUString( "foobar" ).startsWith( "oo" )); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx new file mode 100644 index 000000000..9a014557f --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx @@ -0,0 +1,431 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// activate the extra needed ctor +#define RTL_STRING_UNITTEST + +#include <sal/config.h> + +#include <utility> + +#include <o3tl/cppunittraitshelper.hxx> +#include <sal/types.h> +#include <config_global.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/string.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +extern bool rtl_string_unittest_const_literal; +bool rtl_string_unittest_invalid_conversion; + +namespace test::oustring { + +class StringLiterals: public CppUnit::TestFixture +{ +private: + void checkCtors(); + void checkUsage(); + void checkExtraIntArgument(); + void checkNonconstChar(); + void checkBuffer(); + void checkOUStringLiteral(); + void checkOUStringChar(); + void checkUtf16(); + + void testcall( const char str[] ); + + // Check that OUStringLiteral ctor is actually constexpr: + static constexpr rtlunittest::OUStringLiteral dummy{"dummy"}; + +CPPUNIT_TEST_SUITE(StringLiterals); +CPPUNIT_TEST(checkCtors); +CPPUNIT_TEST(checkUsage); +CPPUNIT_TEST(checkExtraIntArgument); +CPPUNIT_TEST(checkNonconstChar); +CPPUNIT_TEST(checkBuffer); +CPPUNIT_TEST(checkOUStringLiteral); +CPPUNIT_TEST(checkOUStringChar); +CPPUNIT_TEST(checkUtf16); +CPPUNIT_TEST_SUITE_END(); +}; + +// reset the flag, evaluate the expression and return +// whether the string literal ctor was used (i.e. whether the conversion was valid) +template<typename T> static bool VALID_CONVERSION( T && expression ) +{ + rtl_string_unittest_invalid_conversion = false; + // OK to std::forward expression twice; what is relevant in both ctor calls + // is not the content of the passed argument (which is ignored anyway by the + // special RTL_STRING_UNITTEST ctors) but only its type: + ( void ) rtl::OUString( std::forward<T>(expression) ); + ( void ) rtl::OUStringBuffer( std::forward<T>(expression) ); + return !rtl_string_unittest_invalid_conversion; +} +template<typename T> static bool VALID_CONVERSION_CALL( T f ) +{ + rtl_string_unittest_invalid_conversion = false; + ( void ) rtl::OUString( f() ); + ( void ) rtl::OUStringBuffer( f() ); + return !rtl_string_unittest_invalid_conversion; +} + +void test::oustring::StringLiterals::checkCtors() +{ + CPPUNIT_ASSERT( VALID_CONVERSION( "test" )); + const char good1[] = "test"; + CPPUNIT_ASSERT( VALID_CONVERSION( good1 )); + + CPPUNIT_ASSERT( !VALID_CONVERSION( static_cast<const char*>("test") )); + const char* bad1 = good1; + CPPUNIT_ASSERT( !VALID_CONVERSION( bad1 )); + char bad2[] = "test"; + CPPUNIT_ASSERT( !VALID_CONVERSION( bad2 )); + char* bad3 = bad2; + CPPUNIT_ASSERT( !VALID_CONVERSION( bad3 )); + const char* bad4[] = { "test1" }; + CPPUNIT_ASSERT( !VALID_CONVERSION( bad4[ 0 ] )); + testcall( good1 ); + +// This one is technically broken, since the first element is 6 characters test\0\0, +// but there does not appear a way to detect this by compile time (runtime will assert()). +// RTL_CONSTASCII_USTRINGPARAM() has the same flaw. + const char bad5[][ 6 ] = { "test", "test2" }; +// CPPUNIT_ASSERT( VALID_CONVERSION( bad5[ 0 ] )); + CPPUNIT_ASSERT( VALID_CONVERSION( bad5[ 1 ] )); + +// Check that contents are correct and equal to the case when RTL_CONSTASCII_USTRINGPARAM is used. + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "" ), rtl::OUString( "" )); + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "ab" ), rtl::OUString( "ab" )); +#if 0 +// Also check that embedded \0 is included. +// In fact, allowing this is probably just trouble, so this now asserts. + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "\0" ), rtl::OUString( "\0" )); + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "a\0b" ), rtl::OUString( "a\0b" )); +#endif +} + +void test::oustring::StringLiterals::testcall( const char str[] ) +{ + CPPUNIT_ASSERT( + !VALID_CONVERSION_CALL([&str]() { return rtl::OUString(str); })); +} + +void test::oustring::StringLiterals::checkUsage() +{ +// simply check that all string literal based calls work as expected +// also check that they really use string literal overload and do not convert to OUString + rtl::OUString foo( "foo" ); + rtl::OUString FoO( "FoO" ); + rtl::OUString foobarfoo( "foobarfoo" ); + rtl::OUString foobar( "foobar" ); + rtl::OUString FooBaRfoo( "FooBaRfoo" ); + rtl::OUString FooBaR( "FooBaR" ); + rtl::OUString bar( "bar" ); + rtl::OUString test( "test" ); + + rtl_string_unittest_const_literal = false; // start checking for OUString conversions + CPPUNIT_ASSERT_EQUAL( foo, rtl::OUString() = "foo" ); + CPPUNIT_ASSERT( FoO.equalsIgnoreAsciiCase( "fOo" )); + CPPUNIT_ASSERT( foobarfoo.match( "bar", 3 )); + CPPUNIT_ASSERT( foobar.match( "foo" )); + CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( "bAr", 3 )); + CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( "fOo" )); + CPPUNIT_ASSERT( foobar.startsWith( "foo" )); + CPPUNIT_ASSERT( FooBaR.startsWithIgnoreAsciiCase( "foo" )); + CPPUNIT_ASSERT( foobar.endsWith( "bar" )); + CPPUNIT_ASSERT( FooBaR.endsWithIgnoreAsciiCase( "bar" )); + CPPUNIT_ASSERT( bool(foo == "foo") ); + CPPUNIT_ASSERT( bool("foo" == foo) ); + CPPUNIT_ASSERT( foo != "bar" ); + CPPUNIT_ASSERT( "foo" != bar ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(6), foobarfoo.indexOf( "foo", 1 ) ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(6), foobarfoo.lastIndexOf( "foo" ) ); + CPPUNIT_ASSERT( bool(foobarfoo.replaceFirst( "foo", test ) == "testbarfoo") ); + CPPUNIT_ASSERT( bool(foobarfoo.replaceFirst( "foo", "test" ) == "testbarfoo") ); + CPPUNIT_ASSERT( bool(foobarfoo.replaceAll( "foo", test ) == "testbartest") ); + CPPUNIT_ASSERT( bool(foobarfoo.replaceAll( "foo", "test" ) == "testbartest") ); + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(0), foo.reverseCompareTo( "foo" ) ); + // if this is not true, some of the calls above converted to OUString + CPPUNIT_ASSERT( !rtl_string_unittest_const_literal ); +} + +void test::oustring::StringLiterals::checkExtraIntArgument() +{ + // This makes sure that using by mistake RTL_CONSTASCII_STRINGPARAM does not trigger a different + // overload, i.e. the second argument to match() in this case is the indexFrom argument, + // but with the macro it would contain the length of the string. Therefore + // match( RTL_CONSTASCII_STRINGPARAM( "bar" )) would be match( "bar", 3 ), which would be + // true when called for OUString( "foobar" ). But this should not happen because of the + // &foo[0] trick in the RTL_CONSTASCII_STRINGPARAM macro. + CPPUNIT_ASSERT( !rtl::OUString("foobar").match( "bar" )); + CPPUNIT_ASSERT( !rtl::OUString("foobar").match( RTL_CONSTASCII_STRINGPARAM( "bar" ))); +} + +void test::oustring::StringLiterals::checkNonconstChar() +{ // check that non-const char[] data do not trigger string literal overloads + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "foobar" ), rtl::OUString( "footest" ).replaceAll( "test", "bar" )); + char test[] = "test"; + char bar[] = "bar"; + const char consttest[] = "test"; + const char constbar[] = "bar"; + CPPUNIT_ASSERT( + !VALID_CONVERSION_CALL( + [&test, &bar]() { + return rtl::OUString("footest").replaceAll(test, bar); })); + CPPUNIT_ASSERT( + !VALID_CONVERSION_CALL( + [&consttest, &bar]() { + return rtl::OUString("footest").replaceAll(consttest, bar); })); + CPPUNIT_ASSERT( + !VALID_CONVERSION( + [&test, &constbar]() { + return rtl::OUString("footest").replaceAll(test, constbar); })); + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "foobar" ), rtl::OUString( "footest" ).replaceAll( consttest, constbar )); +} + +void test::oustring::StringLiterals::checkBuffer() +{ + rtl::OUStringBuffer buf; + buf.append( "foo" ); + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "foo" ), buf.toString()); + buf.append( "bar" ); + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "foobar" ), buf.toString()); + buf.insert( 3, "baz" ); + CPPUNIT_ASSERT_EQUAL( rtl::OUString( "foobazbar" ), buf.toString()); + char d[] = "d"; + CPPUNIT_ASSERT( !VALID_CONVERSION( buf.append( rtl::OUString( d )))); + CPPUNIT_ASSERT( !VALID_CONVERSION( buf.append( rtl::OUStringBuffer( d )))); +} + +namespace { + +rtl::OUString conditional(bool flag) { + return flag + ? rtlunittest::OUStringLiteral("a") + : rtlunittest::OUStringLiteral("bb"); +} + +} + +void test::oustring::StringLiterals::checkOUStringLiteral() +{ + CPPUNIT_ASSERT(bool(conditional(true) == "a")); + CPPUNIT_ASSERT(bool(conditional(false) == "bb")); + + rtl::OUString s1(rtlunittest::OUStringLiteral("abc")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), s1); + s1 = rtlunittest::OUStringLiteral("de"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("de"), s1); + s1 += rtlunittest::OUStringLiteral("fde"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("defde"), s1); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(0), + s1.reverseCompareTo(rtlunittest::OUStringLiteral("defde"))); + CPPUNIT_ASSERT( + s1.equalsIgnoreAsciiCase(rtlunittest::OUStringLiteral("DEFDE"))); + CPPUNIT_ASSERT(s1.match(rtlunittest::OUStringLiteral("fde"), 2)); + CPPUNIT_ASSERT( + s1.matchIgnoreAsciiCase(rtlunittest::OUStringLiteral("FDE"), 2)); + rtl::OUString s2; + CPPUNIT_ASSERT(s1.startsWith(rtlunittest::OUStringLiteral("de"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("fde"), s2); + CPPUNIT_ASSERT( + s1.startsWithIgnoreAsciiCase( + rtlunittest::OUStringLiteral("DEFD"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("e"), s2); + CPPUNIT_ASSERT(s1.endsWith(rtlunittest::OUStringLiteral("de"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("def"), s2); + CPPUNIT_ASSERT( + s1.endsWithIgnoreAsciiCase(rtlunittest::OUStringLiteral("EFDE"), &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("d"), s2); + CPPUNIT_ASSERT(bool(s1 == rtlunittest::OUStringLiteral("defde"))); + CPPUNIT_ASSERT(bool(rtlunittest::OUStringLiteral("defde") == s1)); + CPPUNIT_ASSERT(s1 != rtlunittest::OUStringLiteral("abc")); + CPPUNIT_ASSERT(rtlunittest::OUStringLiteral("abc") != s1); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), s1.indexOf(rtlunittest::OUStringLiteral("de"), 1)); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), s1.lastIndexOf(rtlunittest::OUStringLiteral("de"))); + sal_Int32 i = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst( + rtlunittest::OUStringLiteral("de"), rtl::OUString("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst( + rtl::OUString("de"), rtlunittest::OUStringLiteral("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst( + rtlunittest::OUStringLiteral("de"), + rtlunittest::OUStringLiteral("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst(rtlunittest::OUStringLiteral("de"), "abc", &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfde"), + s1.replaceFirst("de", rtlunittest::OUStringLiteral("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll( + rtlunittest::OUStringLiteral("de"), rtl::OUString("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll( + rtl::OUString("de"), rtlunittest::OUStringLiteral("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll( + rtlunittest::OUStringLiteral("de"), + rtlunittest::OUStringLiteral("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll(rtlunittest::OUStringLiteral("de"), "abc")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcfabc"), + s1.replaceAll("de", rtlunittest::OUStringLiteral("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcdef"), + rtl::OUString( + rtl::OUString("abc") + rtlunittest::OUStringLiteral("def"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcdef"), + rtl::OUString( + rtlunittest::OUStringLiteral("abc") + rtl::OUString("def"))); + rtl::OUStringBuffer b(rtlunittest::OUStringLiteral("abc")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), b.toString()); + b.append(rtlunittest::OUStringLiteral("def")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abcdef"), b.toString()); + b.insert(2, rtlunittest::OUStringLiteral("gabab")); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abgababcdef"), b.toString()); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), b.indexOf(rtlunittest::OUStringLiteral("ab"), 1)); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(5), b.lastIndexOf(rtlunittest::OUStringLiteral("ab"))); +} + +void test::oustring::StringLiterals::checkOUStringChar() +{ + auto l1 = rtlunittest::OUStringChar('A'); + CPPUNIT_ASSERT_EQUAL(u'A', l1.c); + + char const c2 = 'A'; + auto l2 = rtlunittest::OUStringChar(c2); + CPPUNIT_ASSERT_EQUAL(u'A', l2.c); + + char c3 = 'A'; auto l3 = rtlunittest::OUStringChar(c3); + CPPUNIT_ASSERT_EQUAL(u'A', l3.c); + + auto l4 = rtlunittest::OUStringChar(u'A'); + CPPUNIT_ASSERT_EQUAL(u'A', l4.c); + + sal_Unicode const c5 = 0x100; + auto l5 = rtlunittest::OUStringChar(c5); + CPPUNIT_ASSERT_EQUAL(c5, l5.c); + + rtl::OUString s1{rtlunittest::OUStringChar('A')}; + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getLength()); + CPPUNIT_ASSERT_EQUAL(u'A', s1[0]); + + CPPUNIT_ASSERT_EQUAL( + true, rtl::OUString("A") == rtlunittest::OUStringChar('A')); + CPPUNIT_ASSERT_EQUAL( + false, rtl::OUString("AB") == rtlunittest::OUStringChar('A')); + CPPUNIT_ASSERT_EQUAL( + false, rtl::OUString("A") != rtlunittest::OUStringChar('A')); + CPPUNIT_ASSERT_EQUAL( + true, rtl::OUString("AB") != rtlunittest::OUStringChar('A')); + + rtl::OUString s2("A" + rtlunittest::OUStringChar('b')); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s2.getLength()); + CPPUNIT_ASSERT_EQUAL(u'A', s2[0]); + CPPUNIT_ASSERT_EQUAL(u'b', s2[1]); +} + +void test::oustring::StringLiterals::checkUtf16() { + rtl::OUString s1(u"abc"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), s1); + s1 = u"de"; + CPPUNIT_ASSERT_EQUAL(rtl::OUString("de"), s1); + s1 += u"fde"; + CPPUNIT_ASSERT_EQUAL(rtl::OUString("defde"), s1); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s1.reverseCompareTo(u"defde")); + CPPUNIT_ASSERT(s1.equalsIgnoreAsciiCase(u"DEFDE")); + CPPUNIT_ASSERT(s1.match(u"fde", 2)); + CPPUNIT_ASSERT(s1.matchIgnoreAsciiCase(u"FDE", 2)); + rtl::OUString s2; + CPPUNIT_ASSERT(s1.startsWith(u"de", &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString(u"fde"), s2); + CPPUNIT_ASSERT(s1.startsWithIgnoreAsciiCase(u"DEFD", &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString(u"e"), s2); + CPPUNIT_ASSERT(s1.endsWith(u"de", &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString(u"def"), s2); + CPPUNIT_ASSERT(s1.endsWithIgnoreAsciiCase(u"EFDE", &s2)); + CPPUNIT_ASSERT_EQUAL(rtl::OUString(u"d"), s2); + CPPUNIT_ASSERT(bool(s1 == u"defde")); + CPPUNIT_ASSERT(bool(u"defde" == s1)); + CPPUNIT_ASSERT(s1 != u"abc"); + CPPUNIT_ASSERT(u"abc" != s1); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), s1.indexOf(u"de", 1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), s1.lastIndexOf(u"de")); + sal_Int32 i = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfde"), + s1.replaceFirst(u"de", rtl::OUString("abc"), &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfde"), + s1.replaceFirst(rtl::OUString("de"), u"abc", &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfde"), s1.replaceFirst(u"de", u"abc", &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfde"), s1.replaceFirst(u"de", "abc", &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfde"), s1.replaceFirst("de", u"abc", &i)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfabc"), s1.replaceAll(u"de", rtl::OUString("abc"))); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfabc"), s1.replaceAll(rtl::OUString("de"), u"abc")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfabc"), s1.replaceAll(u"de", u"abc")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfabc"), s1.replaceAll(u"de", "abc")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(u"abcfabc"), s1.replaceAll("de", u"abc")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcdef"), rtl::OUString(rtl::OUString("abc") + u"def")); + CPPUNIT_ASSERT_EQUAL( + rtl::OUString("abcdef"), rtl::OUString(u"abc" + rtl::OUString("def"))); + rtl::OUStringBuffer b(u"abc"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), b.toString()); + b.append(u"def"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abcdef"), b.toString()); + b.insert(2, u"gabab"); + CPPUNIT_ASSERT_EQUAL(rtl::OUString("abgababcdef"), b.toString()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), b.indexOf(u"ab", 1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), b.lastIndexOf(u"ab")); +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::StringLiterals); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_strings_replace.cxx b/sal/qa/rtl/strings/test_strings_replace.cxx new file mode 100644 index 000000000..a27f5f142 --- /dev/null +++ b/sal/qa/rtl/strings/test_strings_replace.cxx @@ -0,0 +1,336 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <sal/types.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/string.h> +#include <rtl/string.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> + +namespace { + +OUString s_empty; +OUString s_bar("bar"); +OUString s_bars("bars"); +OUString s_foo("foo"); +OUString s_other("other"); +OUString s_xa("xa"); +OUString s_xx("xx"); + +class Test: public CppUnit::TestFixture { +private: + void stringReplaceFirst(); + + void stringReplaceAll(); + + void ustringReplaceFirst(); + + void ustringReplaceFirstAsciiL(); + + void ustringReplaceFirstToAsciiL(); + + void ustringReplaceFirstAsciiLAsciiL(); + + void ustringReplaceAll(); + + void ustringReplaceAllAsciiL(); + + void ustringReplaceAllToAsciiL(); + + void ustringReplaceAllAsciiLAsciiL(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(stringReplaceFirst); + CPPUNIT_TEST(stringReplaceAll); + CPPUNIT_TEST(ustringReplaceFirst); + CPPUNIT_TEST(ustringReplaceFirstAsciiL); + CPPUNIT_TEST(ustringReplaceFirstToAsciiL); + CPPUNIT_TEST(ustringReplaceFirstAsciiLAsciiL); + CPPUNIT_TEST(ustringReplaceAll); + CPPUNIT_TEST(ustringReplaceAllAsciiL); + CPPUNIT_TEST(ustringReplaceAllToAsciiL); + CPPUNIT_TEST(ustringReplaceAllAsciiLAsciiL); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::stringReplaceFirst() { + CPPUNIT_ASSERT_EQUAL( + OString("otherbarfoo"), + OString("foobarfoo").replaceFirst("foo", "other")); + + CPPUNIT_ASSERT_EQUAL( + OString("foobarfoo"), + OString("foobarfoo").replaceFirst("bars", "other")); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + OString("otherbarfoo"), + OString("foobarfoo").replaceFirst("foo", "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + OString("foobarother"), + OString("foobarfoo").replaceFirst("foo", "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + OString("foobarfoo"), + OString("foobarfoo").replaceFirst("bar", "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } +} + +void Test::stringReplaceAll() { + CPPUNIT_ASSERT_EQUAL( + OString("otherbarother"), + OString("foobarfoo").replaceAll("foo", "other")); + + CPPUNIT_ASSERT_EQUAL( + OString("foobarfoo"), + OString("foobarfoo").replaceAll("bars", "other")); + + CPPUNIT_ASSERT_EQUAL( + OString("xxa"), OString("xaa").replaceAll("xa", "xx")); +} + +void Test::ustringReplaceFirst() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + OUString("foobarfoo").replaceFirst(s_foo, s_other)); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceFirst(s_bars, s_other)); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + OUString("foobarfoo").replaceFirst(s_foo, s_other, &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarother"), + OUString("foobarfoo").replaceFirst(s_foo, s_other, &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceFirst(s_bar, s_other, &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } +} + +void Test::ustringReplaceFirstAsciiL() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + OUString("foobarfoo").replaceFirst("foo", s_other)); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceFirst("bars", s_other)); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + OUString("foobarfoo").replaceFirst("foo", s_other, &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarother"), + OUString("foobarfoo").replaceFirst("foo", s_other, &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceFirst("bar", s_other, &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } + + CPPUNIT_ASSERT_EQUAL( + OUString(), OUString("xa").replaceFirst("xa", s_empty)); +} + +void Test::ustringReplaceFirstToAsciiL() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + OUString("foobarfoo").replaceFirst(s_foo, "other")); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceFirst(s_bars, "other")); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + OUString("foobarfoo").replaceFirst(s_foo, "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarother"), + OUString("foobarfoo").replaceFirst(s_foo, "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceFirst(s_bar, "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } + + CPPUNIT_ASSERT_EQUAL( + OUString(), OUString("xa").replaceFirst(s_xa, "")); +} + +void Test::ustringReplaceFirstAsciiLAsciiL() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + (OUString("foobarfoo"). + replaceFirst("foo", "other"))); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + (OUString("foobarfoo"). + replaceFirst("bars", "other"))); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarfoo"), + (OUString("foobarfoo"). + replaceFirst("foo", "other", &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarother"), + (OUString("foobarfoo"). + replaceFirst("foo", "other", &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + (OUString("foobarfoo"). + replaceFirst("bar", "other", &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } + + CPPUNIT_ASSERT_EQUAL( + OUString(), OUString("xa").replaceFirst("xa", "")); +} + +void Test::ustringReplaceAll() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarother"), + OUString("foobarfoo").replaceAll(s_foo, s_other)); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceAll(s_bars, s_other)); + + CPPUNIT_ASSERT_EQUAL( + OUString("xxa"), + OUString("xaa").replaceAll(s_xa, s_xx)); +} + +void Test::ustringReplaceAllAsciiL() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarother"), + OUString("foobarfoo").replaceAll("foo", s_other)); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceAll("bars", s_other)); + + CPPUNIT_ASSERT_EQUAL( + OUString("xxa"), + OUString("xaa").replaceAll("xa", s_xx)); + + CPPUNIT_ASSERT_EQUAL( + OUString(), OUString("xa").replaceAll("xa", s_empty)); +} + +void Test::ustringReplaceAllToAsciiL() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarother"), + OUString("foobarfoo").replaceAll(s_foo, "other")); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + OUString("foobarfoo").replaceAll(s_bars, "other")); + + CPPUNIT_ASSERT_EQUAL( + OUString("xxa"), + OUString("xaa").replaceAll(s_xa, "xx")); + + CPPUNIT_ASSERT_EQUAL( + OUString(), OUString("xa").replaceAll(s_xa, "")); +} + +void Test::ustringReplaceAllAsciiLAsciiL() { + CPPUNIT_ASSERT_EQUAL( + OUString("otherbarother"), + (OUString("foobarfoo"). + replaceAll("foo", "other"))); + + CPPUNIT_ASSERT_EQUAL( + OUString("foobarfoo"), + (OUString("foobarfoo"). + replaceAll("bars", "other"))); + + CPPUNIT_ASSERT_EQUAL( + OUString("xxa"), + (OUString("xaa"). + replaceAll("xa", "xx"))); + + CPPUNIT_ASSERT_EQUAL( + OUString(), OUString("xa").replaceAll("xa", "")); +} + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_strings_toint.cxx b/sal/qa/rtl/strings/test_strings_toint.cxx new file mode 100644 index 000000000..d81525b94 --- /dev/null +++ b/sal/qa/rtl/strings/test_strings_toint.cxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace { + +template< typename T > class Test: public CppUnit::TestFixture { +private: + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testToInt32Overflow); + CPPUNIT_TEST(testToUInt32Overflow); + CPPUNIT_TEST(testToInt64Overflow); + CPPUNIT_TEST(testToUInt64Overflow); + CPPUNIT_TEST_SUITE_END(); + + void testToInt32Overflow() { + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("-2147483649").toInt32()); + CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32, T("-2147483648").toInt32()); + CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32 + 1, T("-2147483647").toInt32()); + CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32 - 1, T("2147483646").toInt32()); + CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32, T("2147483647").toInt32()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("2147483648").toInt32()); + } + + void testToUInt32Overflow() { + CPPUNIT_ASSERT_EQUAL(SAL_MAX_UINT32 - 1, T("4294967294").toUInt32()); + CPPUNIT_ASSERT_EQUAL(SAL_MAX_UINT32, T("4294967295").toUInt32()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), T("4294967296").toUInt32()); + } + + void testToInt64Overflow() { + CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("-9223372036854775809").toInt64()); + CPPUNIT_ASSERT_EQUAL( + SAL_MIN_INT64, T("-9223372036854775808").toInt64()); + CPPUNIT_ASSERT_EQUAL( + SAL_MIN_INT64 + 1, T("-9223372036854775807").toInt64()); + CPPUNIT_ASSERT_EQUAL( + SAL_MAX_INT64 - 1, T("9223372036854775806").toInt64()); + CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT64, T("9223372036854775807").toInt64()); + CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("9223372036854775808").toInt64()); + } + + void testToUInt64Overflow() { + CPPUNIT_ASSERT_EQUAL( + SAL_MAX_UINT64 - 1, T("18446744073709551614").toUInt64()); + CPPUNIT_ASSERT_EQUAL( + SAL_MAX_UINT64, T("18446744073709551615").toUInt64()); + CPPUNIT_ASSERT_EQUAL( + sal_uInt64(0), T("18446744073709551616").toUInt64()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(Test< OString >); +CPPUNIT_TEST_SUITE_REGISTRATION(Test< OUString >); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_strings_valuex.cxx b/sal/qa/rtl/strings/test_strings_valuex.cxx new file mode 100644 index 000000000..6c9c83644 --- /dev/null +++ b/sal/qa/rtl/strings/test_strings_valuex.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/ustring.hxx> +#include <iostream> + +namespace test::strings { + +class valueX : public CppUnit::TestFixture { +public: + void testOBoolean(); + void testOUBoolean(); + void testOUInt(); + void testOInt(); + void testOUFloat(); + void testOFloat(); + + CPPUNIT_TEST_SUITE(valueX); + CPPUNIT_TEST(testOBoolean); + CPPUNIT_TEST(testOUBoolean); + CPPUNIT_TEST(testOUInt); + CPPUNIT_TEST(testOInt); + CPPUNIT_TEST(testOUFloat); + CPPUNIT_TEST(testOFloat); + CPPUNIT_TEST_SUITE_END(); +}; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX); + +namespace { + +template< typename T > +void testBoolean() { + CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( false ) ); + CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( true ) ); +} + +} + +void test::strings::valueX::testOBoolean() { + testBoolean<OString>(); +} + +void test::strings::valueX::testOUBoolean() { + testBoolean<OUString>(); +} + +template< typename T > +static void testInt() { + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( 30039062 ))); + + // test the overloading resolution + + CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< signed char >( 30 )))); + CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< unsigned char >( 30 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< short >( 30039 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< unsigned short >( 30039 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< int >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< unsigned int >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< long >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< unsigned long >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< long long >( 30039062 )))); + // The highest bit set in unsigned long long may not actually work. + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< unsigned long long >( 30039062 )))); + + CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< sal_Int8 >( 30 )))); + CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< sal_uInt8 >( 30 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< sal_Int16 >( 30039 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< sal_uInt16 >( 30039 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_Int32 >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_uInt32 >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_Int64 >( 30039062 )))); + CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_uInt64 >( 30039062 )))); + + // The implementation internally uses sal_Int64 etc. types, so check ranges. + assert( sizeof( int ) <= sizeof( sal_Int32 )); + assert( sizeof( long ) <= sizeof( sal_Int64 )); + assert( sizeof( long long ) <= sizeof( sal_Int64 )); + assert( sizeof( unsigned int ) < sizeof( sal_Int64 )); +} + +void test::strings::valueX::testOUInt() { + testInt<OUString>(); +} + +void test::strings::valueX::testOInt() { + testInt<OString>(); +} + +template< typename T > +static void testFloat() { + CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T( T::number( 39062.2f ))); + CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T( T::number( 30039062.2 ))); + // long double not supported +} + +void test::strings::valueX::testOUFloat() { + testFloat<OUString>(); +} + +void test::strings::valueX::testOFloat() { + testFloat<OString>(); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/textenc/rtl_tencinfo.cxx b/sal/qa/rtl/textenc/rtl_tencinfo.cxx new file mode 100644 index 000000000..eaa16c6eb --- /dev/null +++ b/sal/qa/rtl/textenc/rtl_tencinfo.cxx @@ -0,0 +1,1667 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_locales.h> + +#include <string.h> + +#include <rtl/tencinfo.h> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +namespace +{ + class testBestMime : public CppUnit::TestFixture + { + public: + void check(rtl_TextEncoding eIn, rtl_TextEncoding eOut) + { + const char *pCharSet = rtl_getBestMimeCharsetFromTextEncoding(eIn); + rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromMimeCharset(pCharSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("rtl_getBestMimeCharsetFromTextEncoding && rtl_getTextEncodingFromMimeCharset differdiffer", eOut, eTextEnc ); + } + + // the defines for the follows test could be found in file inc/rtl/textenc.h + + void MimeCharsetFromTextEncoding_MS_1252() + { + check( RTL_TEXTENCODING_MS_1252, RTL_TEXTENCODING_MS_1252 ); + } + + void MimeCharsetFromTextEncoding_APPLE_ROMAN() + { + check( RTL_TEXTENCODING_APPLE_ROMAN, RTL_TEXTENCODING_APPLE_ROMAN); + } + + void MimeCharsetFromTextEncoding_IBM_437() + { + check( RTL_TEXTENCODING_IBM_437, RTL_TEXTENCODING_IBM_437 ); + } + + void MimeCharsetFromTextEncoding_IBM_850() + { + check( RTL_TEXTENCODING_IBM_850, RTL_TEXTENCODING_IBM_850 ); + } + + void MimeCharsetFromTextEncoding_IBM_860() + { + check( RTL_TEXTENCODING_IBM_860, RTL_TEXTENCODING_IBM_860 ); + } + + void MimeCharsetFromTextEncoding_IBM_861() + { + check( RTL_TEXTENCODING_IBM_861, RTL_TEXTENCODING_IBM_861 ); + } + + void MimeCharsetFromTextEncoding_IBM_863() + { + check( RTL_TEXTENCODING_IBM_863, RTL_TEXTENCODING_IBM_863 ); + } + + void MimeCharsetFromTextEncoding_IBM_865() + { + check( RTL_TEXTENCODING_IBM_865, RTL_TEXTENCODING_IBM_865 ); + } + + void MimeCharsetFromTextEncoding_SYMBOL() + { + check( RTL_TEXTENCODING_SYMBOL, RTL_TEXTENCODING_DONTKNOW ); + } + + void MimeCharsetFromTextEncoding_ASCII_US() + { + check( RTL_TEXTENCODING_ASCII_US, RTL_TEXTENCODING_ASCII_US ); + } + + void MimeCharsetFromTextEncoding_ISO_8859_1() + { + check( RTL_TEXTENCODING_ISO_8859_1, RTL_TEXTENCODING_ISO_8859_1 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_2() + { + check( RTL_TEXTENCODING_ISO_8859_2, RTL_TEXTENCODING_ISO_8859_2 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_3() + { + check( RTL_TEXTENCODING_ISO_8859_3, RTL_TEXTENCODING_ISO_8859_3 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_4() + { + check( RTL_TEXTENCODING_ISO_8859_4, RTL_TEXTENCODING_ISO_8859_4 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_5() + { + check( RTL_TEXTENCODING_ISO_8859_5, RTL_TEXTENCODING_ISO_8859_5 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_6() + { + check( RTL_TEXTENCODING_ISO_8859_6, RTL_TEXTENCODING_ISO_8859_6 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_7() + { + check( RTL_TEXTENCODING_ISO_8859_7, RTL_TEXTENCODING_ISO_8859_7 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_8() + { + check( RTL_TEXTENCODING_ISO_8859_8, RTL_TEXTENCODING_ISO_8859_8 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_9() + { + check( RTL_TEXTENCODING_ISO_8859_9, RTL_TEXTENCODING_ISO_8859_9 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_14() + { + check( RTL_TEXTENCODING_ISO_8859_14, RTL_TEXTENCODING_ISO_8859_14 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_15() + { + check( RTL_TEXTENCODING_ISO_8859_15, RTL_TEXTENCODING_ISO_8859_15 ); + } + void MimeCharsetFromTextEncoding_IBM_737() + { + check( RTL_TEXTENCODING_IBM_737, RTL_TEXTENCODING_ISO_8859_7 ); + } + void MimeCharsetFromTextEncoding_IBM_775() + { + check( RTL_TEXTENCODING_IBM_775, RTL_TEXTENCODING_ISO_8859_4 ); + } + void MimeCharsetFromTextEncoding_IBM_852() + { + check( RTL_TEXTENCODING_IBM_852, RTL_TEXTENCODING_IBM_852 ); + } + void MimeCharsetFromTextEncoding_IBM_855() + { + check( RTL_TEXTENCODING_IBM_855, RTL_TEXTENCODING_ISO_8859_5 ); + } + void MimeCharsetFromTextEncoding_IBM_857() + { + check( RTL_TEXTENCODING_IBM_857, RTL_TEXTENCODING_ISO_8859_9 ); + } + void MimeCharsetFromTextEncoding_IBM_862() + { + check( RTL_TEXTENCODING_IBM_862, RTL_TEXTENCODING_IBM_862 ); + } + void MimeCharsetFromTextEncoding_IBM_864() + { + check( RTL_TEXTENCODING_IBM_864, RTL_TEXTENCODING_IBM_864 ); + } + void MimeCharsetFromTextEncoding_IBM_866() + { + check( RTL_TEXTENCODING_IBM_866, RTL_TEXTENCODING_IBM_866 ); + } + void MimeCharsetFromTextEncoding_IBM_869() + { + check( RTL_TEXTENCODING_IBM_869, RTL_TEXTENCODING_ISO_8859_7 ); + } + void MimeCharsetFromTextEncoding_MS_874() + { + check( RTL_TEXTENCODING_MS_874, RTL_TEXTENCODING_MS_874 ); + } + void MimeCharsetFromTextEncoding_MS_1250() + { + check( RTL_TEXTENCODING_MS_1250, RTL_TEXTENCODING_MS_1250 ); + } + void MimeCharsetFromTextEncoding_MS_1251() + { + check( RTL_TEXTENCODING_MS_1251, RTL_TEXTENCODING_MS_1251 ); + } + void MimeCharsetFromTextEncoding_MS_1253() + { + check( RTL_TEXTENCODING_MS_1253, RTL_TEXTENCODING_MS_1253 ); + } + void MimeCharsetFromTextEncoding_MS_1254() + { + check( RTL_TEXTENCODING_MS_1254, RTL_TEXTENCODING_MS_1254 ); + } + void MimeCharsetFromTextEncoding_MS_1255() + { + check( RTL_TEXTENCODING_MS_1255, RTL_TEXTENCODING_MS_1255 ); + } + void MimeCharsetFromTextEncoding_MS_1256() + { + check( RTL_TEXTENCODING_MS_1256, RTL_TEXTENCODING_MS_1256 ); + } + void MimeCharsetFromTextEncoding_MS_1257() + { + check( RTL_TEXTENCODING_MS_1257, RTL_TEXTENCODING_MS_1257 ); + } + void MimeCharsetFromTextEncoding_MS_1258() + { + check( RTL_TEXTENCODING_MS_1258, RTL_TEXTENCODING_MS_1258 ); + } + void MimeCharsetFromTextEncoding_APPLE_CENTEURO() + { + check( RTL_TEXTENCODING_APPLE_CENTEURO, RTL_TEXTENCODING_ISO_8859_2 ); + } + void MimeCharsetFromTextEncoding_APPLE_CROATIAN() + { + check( RTL_TEXTENCODING_APPLE_CROATIAN, RTL_TEXTENCODING_ISO_8859_2 ); + } + void MimeCharsetFromTextEncoding_APPLE_CYRILLIC() + { + check( RTL_TEXTENCODING_APPLE_CYRILLIC, RTL_TEXTENCODING_ISO_8859_5 ); + } + void MimeCharsetFromTextEncoding_APPLE_GREEK() + { + check( RTL_TEXTENCODING_APPLE_GREEK, RTL_TEXTENCODING_ISO_8859_7 ); + } + void MimeCharsetFromTextEncoding_APPLE_ICELAND() + { + check( RTL_TEXTENCODING_APPLE_ICELAND, RTL_TEXTENCODING_ISO_8859_1 ); + } + void MimeCharsetFromTextEncoding_APPLE_ROMANIAN() + { + check( RTL_TEXTENCODING_APPLE_ROMANIAN, RTL_TEXTENCODING_ISO_8859_2 ); + } + void MimeCharsetFromTextEncoding_APPLE_TURKISH() + { + check( RTL_TEXTENCODING_APPLE_TURKISH, RTL_TEXTENCODING_ISO_8859_9 ); + } + void MimeCharsetFromTextEncoding_APPLE_UKRAINIAN() + { + check( RTL_TEXTENCODING_APPLE_UKRAINIAN, RTL_TEXTENCODING_ISO_8859_5 ); + } + void MimeCharsetFromTextEncoding_MS_932() + { + check( RTL_TEXTENCODING_MS_932, RTL_TEXTENCODING_SHIFT_JIS ); + } + void MimeCharsetFromTextEncoding_MS_936() + { + check( RTL_TEXTENCODING_MS_936, RTL_TEXTENCODING_GB_2312 ); + } + void MimeCharsetFromTextEncoding_MS_949() + { + check( RTL_TEXTENCODING_MS_949, RTL_TEXTENCODING_EUC_KR ); + } + void MimeCharsetFromTextEncoding_MS_950() + { + check( RTL_TEXTENCODING_MS_950, RTL_TEXTENCODING_BIG5 ); + } + void MimeCharsetFromTextEncoding_KOI8_R() + { + check( RTL_TEXTENCODING_KOI8_R, RTL_TEXTENCODING_KOI8_R ); + } + void MimeCharsetFromTextEncoding_UTF7() + { + check( RTL_TEXTENCODING_UTF7, RTL_TEXTENCODING_UTF7 ); + } + void MimeCharsetFromTextEncoding_UTF8() + { + check( RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_UTF8 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_10() + { + check( RTL_TEXTENCODING_ISO_8859_10, RTL_TEXTENCODING_ISO_8859_10 ); + } + void MimeCharsetFromTextEncoding_ISO_8859_13() + { + check( RTL_TEXTENCODING_ISO_8859_13, RTL_TEXTENCODING_ISO_8859_13 ); + } + void MimeCharsetFromTextEncoding_MS_1361() + { + check( RTL_TEXTENCODING_MS_1361, RTL_TEXTENCODING_EUC_KR ); + } + void MimeCharsetFromTextEncoding_TIS_620() + { + check( RTL_TEXTENCODING_TIS_620, RTL_TEXTENCODING_TIS_620 ); + } + void MimeCharsetFromTextEncoding_KOI8_U() + { + check( RTL_TEXTENCODING_KOI8_U, RTL_TEXTENCODING_KOI8_U ); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + void MimeCharsetFromTextEncoding_APPLE_JAPANESE() + { + check( RTL_TEXTENCODING_APPLE_JAPANESE, RTL_TEXTENCODING_SHIFT_JIS ); + } + void MimeCharsetFromTextEncoding_SHIFT_JIS() + { + check( RTL_TEXTENCODING_SHIFT_JIS, RTL_TEXTENCODING_SHIFT_JIS ); + } + void MimeCharsetFromTextEncoding_EUC_JP() + { + check( RTL_TEXTENCODING_EUC_JP, RTL_TEXTENCODING_EUC_JP ); + } + void MimeCharsetFromTextEncoding_ISO_2022_JP() + { + check( RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_ISO_2022_JP ); + } + void MimeCharsetFromTextEncoding_JIS_X_0201() + { + check( RTL_TEXTENCODING_JIS_X_0201, RTL_TEXTENCODING_EUC_JP ); + } + void MimeCharsetFromTextEncoding_JIS_X_0208() + { + check( RTL_TEXTENCODING_JIS_X_0208, RTL_TEXTENCODING_EUC_JP ); + } + void MimeCharsetFromTextEncoding_JIS_X_0212() + { + check( RTL_TEXTENCODING_JIS_X_0212, RTL_TEXTENCODING_EUC_JP ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + void MimeCharsetFromTextEncoding_APPLE_KOREAN() + { + check( RTL_TEXTENCODING_APPLE_KOREAN, RTL_TEXTENCODING_EUC_KR ); + } + void MimeCharsetFromTextEncoding_EUC_KR() + { + check( RTL_TEXTENCODING_EUC_KR, RTL_TEXTENCODING_EUC_KR ); + } + void MimeCharsetFromTextEncoding_ISO_2022_KR() + { + check( RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_ISO_2022_KR ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + void MimeCharsetFromTextEncoding_APPLE_CHINSIMP() + { + check( RTL_TEXTENCODING_APPLE_CHINSIMP, RTL_TEXTENCODING_GB_2312 ); + } + void MimeCharsetFromTextEncoding_APPLE_CHINTRAD() + { + check( RTL_TEXTENCODING_APPLE_CHINTRAD, RTL_TEXTENCODING_BIG5 ); + } + void MimeCharsetFromTextEncoding_GB_2312() + { + check( RTL_TEXTENCODING_GB_2312, RTL_TEXTENCODING_GB_2312 ); + } + void MimeCharsetFromTextEncoding_GBT_12345() + { + check( RTL_TEXTENCODING_GBT_12345, RTL_TEXTENCODING_GBT_12345 ); + } + void MimeCharsetFromTextEncoding_GBK() + { + check( RTL_TEXTENCODING_GBK, RTL_TEXTENCODING_GBK ); + } + void MimeCharsetFromTextEncoding_BIG5() + { + check( RTL_TEXTENCODING_BIG5, RTL_TEXTENCODING_BIG5 ); + } + void MimeCharsetFromTextEncoding_EUC_CN() + { + check( RTL_TEXTENCODING_EUC_CN, RTL_TEXTENCODING_GB_2312 ); + } + void MimeCharsetFromTextEncoding_EUC_TW() + { + check( RTL_TEXTENCODING_EUC_TW, RTL_TEXTENCODING_BIG5 ); + } + void MimeCharsetFromTextEncoding_ISO_2022_CN() + { + check( RTL_TEXTENCODING_ISO_2022_CN, RTL_TEXTENCODING_ISO_2022_CN ); + } + void MimeCharsetFromTextEncoding_GB_18030() + { + check( RTL_TEXTENCODING_GB_18030, RTL_TEXTENCODING_GB_18030 ); + } + void MimeCharsetFromTextEncoding_BIG5_HKSCS() + { + check( RTL_TEXTENCODING_BIG5_HKSCS, RTL_TEXTENCODING_BIG5_HKSCS ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_FOR_SCRIPT_Deva + void MimeCharsetFromTextEncoding_ISCII_DEVANAGARI() + { + check( RTL_TEXTENCODING_ISCII_DEVANAGARI, RTL_TEXTENCODING_ISCII_DEVANAGARI ); + } +#endif + CPPUNIT_TEST_SUITE( testBestMime ); + + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1252 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_ROMAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_437 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_850 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_860 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_861 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_863 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_865 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_SYMBOL ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ASCII_US ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_1 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_2 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_3 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_4 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_5 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_6 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_7 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_8 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_9 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_14 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_15 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_737 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_775 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_852 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_855 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_857 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_862 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_864 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_866 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_IBM_869 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_874 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1250 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1251 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1253 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1254 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1255 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1256 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1257 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1258 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CENTEURO ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CROATIAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CYRILLIC ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_GREEK ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_ICELAND ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_ROMANIAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_TURKISH ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_UKRAINIAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_932 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_936 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_949 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_950 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_KOI8_R ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_UTF7 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_UTF8 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_10 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_8859_13 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1361 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_TIS_620 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_KOI8_U ); +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_JAPANESE ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_SHIFT_JIS ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_JP ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_2022_JP ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JIS_X_0201 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JIS_X_0208 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JIS_X_0212 ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_KOREAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_KR ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_2022_KR ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CHINSIMP ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CHINTRAD ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GB_2312 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GBT_12345 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GBK ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_BIG5 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_CN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_TW ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_2022_CN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GB_18030 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_BIG5_HKSCS ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_FOR_SCRIPT_Deva + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISCII_DEVANAGARI ); +#endif + CPPUNIT_TEST_SUITE_END( ); + }; + + class testBestUnix : public CppUnit::TestFixture + { + public: + void check(rtl_TextEncoding eIn, rtl_TextEncoding eOut) + { + const char *pCharSet = rtl_getBestUnixCharsetFromTextEncoding(eIn); + rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromUnixCharset(pCharSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("rtl_getBestUnixCharsetFromTextEncoding && rtl_getTextEncodingFromUnixCharset", eOut, eTextEnc ); + } + + void UnixCharsetFromTextEncoding_MS_1252() + { + check( RTL_TEXTENCODING_MS_1252, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_APPLE_ROMAN() + { + check( RTL_TEXTENCODING_APPLE_ROMAN, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_IBM_437() + { + check( RTL_TEXTENCODING_IBM_437, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_IBM_850() + { + check( RTL_TEXTENCODING_IBM_850, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_IBM_860() + { + check( RTL_TEXTENCODING_IBM_860, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_IBM_861() + { + check( RTL_TEXTENCODING_IBM_861, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_IBM_863() + { + check( RTL_TEXTENCODING_IBM_863, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_IBM_865() + { + check( RTL_TEXTENCODING_IBM_865, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_SYMBOL() + { + check( RTL_TEXTENCODING_SYMBOL, RTL_TEXTENCODING_SYMBOL ); + } + + void UnixCharsetFromTextEncoding_ASCII_US() + { + check( RTL_TEXTENCODING_ASCII_US, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_1() + { + check( RTL_TEXTENCODING_ISO_8859_1, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_2() + { + check( RTL_TEXTENCODING_ISO_8859_2, RTL_TEXTENCODING_ISO_8859_2 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_3() + { + check( RTL_TEXTENCODING_ISO_8859_3, RTL_TEXTENCODING_ISO_8859_3 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_4() + { + check( RTL_TEXTENCODING_ISO_8859_4, RTL_TEXTENCODING_ISO_8859_4 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_5() + { + check( RTL_TEXTENCODING_ISO_8859_5, RTL_TEXTENCODING_ISO_8859_5 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_6() + { + check( RTL_TEXTENCODING_ISO_8859_6, RTL_TEXTENCODING_ISO_8859_6 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_7() + { + check( RTL_TEXTENCODING_ISO_8859_7, RTL_TEXTENCODING_ISO_8859_7 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_8() + { + check( RTL_TEXTENCODING_ISO_8859_8, RTL_TEXTENCODING_ISO_8859_8 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_9() + { + check( RTL_TEXTENCODING_ISO_8859_9, RTL_TEXTENCODING_ISO_8859_9 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_14() + { + check( RTL_TEXTENCODING_ISO_8859_14, RTL_TEXTENCODING_ISO_8859_14 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_15() + { + check( RTL_TEXTENCODING_ISO_8859_15, RTL_TEXTENCODING_ISO_8859_15 ); + } + + void UnixCharsetFromTextEncoding_IBM_737() + { + check( RTL_TEXTENCODING_IBM_737, RTL_TEXTENCODING_ISO_8859_7 ); + } + + void UnixCharsetFromTextEncoding_IBM_775() + { + check( RTL_TEXTENCODING_IBM_775, RTL_TEXTENCODING_ISO_8859_4 ); + } + + void UnixCharsetFromTextEncoding_IBM_852() + { + check( RTL_TEXTENCODING_IBM_852, RTL_TEXTENCODING_ISO_8859_2 ); + } + + void UnixCharsetFromTextEncoding_IBM_855() + { + check( RTL_TEXTENCODING_IBM_855, RTL_TEXTENCODING_ISO_8859_5 ); + } + + void UnixCharsetFromTextEncoding_IBM_857() + { + check( RTL_TEXTENCODING_IBM_857, RTL_TEXTENCODING_ISO_8859_9 ); + } + + void UnixCharsetFromTextEncoding_IBM_862() + { + check( RTL_TEXTENCODING_IBM_862, RTL_TEXTENCODING_ISO_8859_8 ); + } + + void UnixCharsetFromTextEncoding_IBM_864() + { + check( RTL_TEXTENCODING_IBM_864, RTL_TEXTENCODING_ISO_8859_6 ); + } + + void UnixCharsetFromTextEncoding_IBM_866() + { + check( RTL_TEXTENCODING_IBM_866, RTL_TEXTENCODING_ISO_8859_5 ); + } + + void UnixCharsetFromTextEncoding_IBM_869() + { + check( RTL_TEXTENCODING_IBM_869, RTL_TEXTENCODING_ISO_8859_7 ); + } + + void UnixCharsetFromTextEncoding_MS_874() + { + check( RTL_TEXTENCODING_MS_874, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_MS_1250() + { + check( RTL_TEXTENCODING_MS_1250, RTL_TEXTENCODING_ISO_8859_2 ); + } + + void UnixCharsetFromTextEncoding_MS_1251() + { + check( RTL_TEXTENCODING_MS_1251, RTL_TEXTENCODING_ISO_8859_5 ); + } + + void UnixCharsetFromTextEncoding_MS_1253() + { + check( RTL_TEXTENCODING_MS_1253, RTL_TEXTENCODING_ISO_8859_7 ); + } + + void UnixCharsetFromTextEncoding_MS_1254() + { + check( RTL_TEXTENCODING_MS_1254, RTL_TEXTENCODING_ISO_8859_9 ); + } + + void UnixCharsetFromTextEncoding_MS_1255() + { + check( RTL_TEXTENCODING_MS_1255, RTL_TEXTENCODING_ISO_8859_8 ); + } + + void UnixCharsetFromTextEncoding_MS_1256() + { + check( RTL_TEXTENCODING_MS_1256, RTL_TEXTENCODING_ISO_8859_6 ); + } + + void UnixCharsetFromTextEncoding_MS_1257() + { + check( RTL_TEXTENCODING_MS_1257, RTL_TEXTENCODING_ISO_8859_4 ); + } + + void UnixCharsetFromTextEncoding_MS_1258() + { + check( RTL_TEXTENCODING_MS_1258, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_APPLE_CENTEURO() + { + check( RTL_TEXTENCODING_APPLE_CENTEURO, RTL_TEXTENCODING_ISO_8859_2 ); + } + + void UnixCharsetFromTextEncoding_APPLE_CROATIAN() + { + check( RTL_TEXTENCODING_APPLE_CROATIAN, RTL_TEXTENCODING_ISO_8859_2 ); + } + + void UnixCharsetFromTextEncoding_APPLE_CYRILLIC() + { + check( RTL_TEXTENCODING_APPLE_CYRILLIC, RTL_TEXTENCODING_ISO_8859_5 ); + } + + void UnixCharsetFromTextEncoding_APPLE_GREEK() + { + check( RTL_TEXTENCODING_APPLE_GREEK, RTL_TEXTENCODING_ISO_8859_7 ); + } + + void UnixCharsetFromTextEncoding_APPLE_ICELAND() + { + check( RTL_TEXTENCODING_APPLE_ICELAND, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_APPLE_ROMANIAN() + { + check( RTL_TEXTENCODING_APPLE_ROMANIAN, RTL_TEXTENCODING_ISO_8859_2 ); + } + + void UnixCharsetFromTextEncoding_APPLE_TURKISH() + { + check( RTL_TEXTENCODING_APPLE_TURKISH, RTL_TEXTENCODING_ISO_8859_9 ); + } + + void UnixCharsetFromTextEncoding_APPLE_UKRAINIAN() + { + check( RTL_TEXTENCODING_APPLE_UKRAINIAN, RTL_TEXTENCODING_ISO_8859_5 ); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + void UnixCharsetFromTextEncoding_APPLE_CHINSIMP() + { + check( RTL_TEXTENCODING_APPLE_CHINSIMP, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_APPLE_CHINTRAD() + { + check( RTL_TEXTENCODING_APPLE_CHINTRAD, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + void UnixCharsetFromTextEncoding_APPLE_JAPANESE() + { + check( RTL_TEXTENCODING_APPLE_JAPANESE, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + void UnixCharsetFromTextEncoding_APPLE_KOREAN() + { + check( RTL_TEXTENCODING_APPLE_KOREAN, RTL_TEXTENCODING_DONTKNOW ); + } +#endif + void UnixCharsetFromTextEncoding_MS_932() + { + check( RTL_TEXTENCODING_MS_932, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_MS_936() + { + check( RTL_TEXTENCODING_MS_936, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_MS_949() + { + check( RTL_TEXTENCODING_MS_949, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_MS_950() + { + check( RTL_TEXTENCODING_MS_950, RTL_TEXTENCODING_DONTKNOW ); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + void UnixCharsetFromTextEncoding_SHIFT_JIS() + { + check( RTL_TEXTENCODING_SHIFT_JIS, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + void UnixCharsetFromTextEncoding_GB_2312() + { + check( RTL_TEXTENCODING_GB_2312, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_GBT_12345() + { + check( RTL_TEXTENCODING_GBT_12345, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_GBK() + { + check( RTL_TEXTENCODING_GBK, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_BIG5() + { + check( RTL_TEXTENCODING_BIG5, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + void UnixCharsetFromTextEncoding_EUC_JP() + { + check( RTL_TEXTENCODING_EUC_JP, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + void UnixCharsetFromTextEncoding_EUC_CN() + { + check( RTL_TEXTENCODING_EUC_CN, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_EUC_TW() + { + check( RTL_TEXTENCODING_EUC_TW, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + void UnixCharsetFromTextEncoding_ISO_2022_JP() + { + check( RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + void UnixCharsetFromTextEncoding_ISO_2022_CN() + { + check( RTL_TEXTENCODING_ISO_2022_CN, RTL_TEXTENCODING_DONTKNOW ); + } +#endif + void UnixCharsetFromTextEncoding_KOI8_R() + { + check( RTL_TEXTENCODING_KOI8_R, RTL_TEXTENCODING_KOI8_R ); + } + + void UnixCharsetFromTextEncoding_UTF7() + { + check( RTL_TEXTENCODING_UTF7, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_UTF8() + { + check( RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_10() + { + check( RTL_TEXTENCODING_ISO_8859_10, RTL_TEXTENCODING_ISO_8859_10 ); + } + + void UnixCharsetFromTextEncoding_ISO_8859_13() + { + check( RTL_TEXTENCODING_ISO_8859_13, RTL_TEXTENCODING_ISO_8859_13 ); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + void UnixCharsetFromTextEncoding_EUC_KR() + { + check( RTL_TEXTENCODING_EUC_KR, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_ISO_2022_KR() + { + check( RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_DONTKNOW ); + } +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + void UnixCharsetFromTextEncoding_JIS_X_0201() + { + check( RTL_TEXTENCODING_JIS_X_0201, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_JIS_X_0208() + { + check( RTL_TEXTENCODING_JIS_X_0208, RTL_TEXTENCODING_DONTKNOW ); + } + + void UnixCharsetFromTextEncoding_JIS_X_0212() + { + check( RTL_TEXTENCODING_JIS_X_0212, RTL_TEXTENCODING_DONTKNOW ); + } +#endif + void UnixCharsetFromTextEncoding_MS_1361() + { + check( RTL_TEXTENCODING_MS_1361, RTL_TEXTENCODING_DONTKNOW ); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + void UnixCharsetFromTextEncoding_GB_18030() + { + check( RTL_TEXTENCODING_GB_18030, RTL_TEXTENCODING_GBK ); + } + + void UnixCharsetFromTextEncoding_BIG5_HKSCS() + { + check( RTL_TEXTENCODING_BIG5_HKSCS, RTL_TEXTENCODING_DONTKNOW ); + } +#endif + void UnixCharsetFromTextEncoding_TIS_620() + { + check( RTL_TEXTENCODING_TIS_620, RTL_TEXTENCODING_ISO_8859_1 ); + } + + void UnixCharsetFromTextEncoding_KOI8_U() + { + check( RTL_TEXTENCODING_KOI8_U, RTL_TEXTENCODING_KOI8_U ); + } + + CPPUNIT_TEST_SUITE( testBestUnix ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1252 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_ROMAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_437 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_850 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_860 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_861 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_863 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_865 ); + + CPPUNIT_TEST( UnixCharsetFromTextEncoding_SYMBOL ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ASCII_US ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_1 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_2 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_3 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_4 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_5 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_6 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_7 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_8 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_9 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_14 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_15 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_737 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_775 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_852 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_855 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_857 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_862 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_864 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_866 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_IBM_869 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_874 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1250 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1251 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1253 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1254 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1255 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1256 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1257 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1258 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CENTEURO ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CROATIAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CYRILLIC ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_GREEK ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_ICELAND ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_ROMANIAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_TURKISH ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_UKRAINIAN ); +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CHINSIMP ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CHINTRAD ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_JAPANESE ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_KOREAN ); +#endif + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_932 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_936 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_949 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_950 ); +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + CPPUNIT_TEST( UnixCharsetFromTextEncoding_SHIFT_JIS ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GB_2312 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GBT_12345 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GBK ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_BIG5 ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_JP ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_CN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_TW ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_2022_JP ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_2022_CN ); +#endif + CPPUNIT_TEST( UnixCharsetFromTextEncoding_KOI8_R ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_UTF7 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_UTF8 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_10 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_8859_13 ); +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_KR ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_2022_KR ); +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JIS_X_0201 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JIS_X_0208 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JIS_X_0212 ); +#endif + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1361 ); +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GB_18030 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_BIG5_HKSCS ); +#endif + CPPUNIT_TEST( UnixCharsetFromTextEncoding_TIS_620 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_KOI8_U ); + + CPPUNIT_TEST_SUITE_END( ); + }; + + class testBestWindows : public CppUnit::TestFixture + { + public: + void check(rtl_TextEncoding nIn, rtl_TextEncoding nOut) + { + const sal_uInt8 nCharSet = rtl_getBestWindowsCharsetFromTextEncoding(nIn); + rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromWindowsCharset(nCharSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("rtl_getBestWindowsCharsetFromTextEncoding && rtl_getTextEncodingFromWindowsCharset differ", nOut, eTextEnc ); + } + + void WindowsCharsetFromTextEncoding_MS_1252() + { + check( RTL_TEXTENCODING_MS_1252, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_ROMAN() + { + check( RTL_TEXTENCODING_APPLE_ROMAN, RTL_TEXTENCODING_APPLE_ROMAN ); + } + + void WindowsCharsetFromTextEncoding_IBM_437() + { + check( RTL_TEXTENCODING_IBM_437, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_850() + { + check( RTL_TEXTENCODING_IBM_850, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_860() + { + check( RTL_TEXTENCODING_IBM_860, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_861() + { + check( RTL_TEXTENCODING_IBM_861, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_863() + { + check( RTL_TEXTENCODING_IBM_863, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_865() + { + check( RTL_TEXTENCODING_IBM_865, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_SYMBOL() + { + check( RTL_TEXTENCODING_SYMBOL, RTL_TEXTENCODING_SYMBOL ); + } + + void WindowsCharsetFromTextEncoding_ASCII_US() + { + check( RTL_TEXTENCODING_ASCII_US, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_1() + { + check( RTL_TEXTENCODING_ISO_8859_1, RTL_TEXTENCODING_MS_1252 ); + } +#if 0 + void WindowsCharsetFromTextEncoding_ISO_8859_2() + { + check( RTL_TEXTENCODING_ISO_8859_2, RTL_TEXTENCODING_MS_1252 ); + } +#endif + void WindowsCharsetFromTextEncoding_ISO_8859_3() + { + check( RTL_TEXTENCODING_ISO_8859_3, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_4() + { + check( RTL_TEXTENCODING_ISO_8859_4, RTL_TEXTENCODING_MS_1257 ); + } +#if 0 + void WindowsCharsetFromTextEncoding_ISO_8859_5() + { + check( RTL_TEXTENCODING_ISO_8859_5, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_6() + { + check( RTL_TEXTENCODING_ISO_8859_6, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_7() + { + check( RTL_TEXTENCODING_ISO_8859_7, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_8() + { + check( RTL_TEXTENCODING_ISO_8859_8, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_9() + { + check( RTL_TEXTENCODING_ISO_8859_9, RTL_TEXTENCODING_MS_1252 ); + } +#endif + void WindowsCharsetFromTextEncoding_ISO_8859_14() + { + check( RTL_TEXTENCODING_ISO_8859_14, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_15() + { + check( RTL_TEXTENCODING_ISO_8859_15, RTL_TEXTENCODING_MS_1252 ); + } +#if 0 + void WindowsCharsetFromTextEncoding_IBM_737() + { + check( RTL_TEXTENCODING_IBM_737, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_775() + { + check( RTL_TEXTENCODING_IBM_775, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_852() + { + check( RTL_TEXTENCODING_IBM_852, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_855() + { + check( RTL_TEXTENCODING_IBM_855, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_857() + { + check( RTL_TEXTENCODING_IBM_857, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_862() + { + check( RTL_TEXTENCODING_IBM_862, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_864() + { + check( RTL_TEXTENCODING_IBM_864, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_866() + { + check( RTL_TEXTENCODING_IBM_866, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_IBM_869() + { + check( RTL_TEXTENCODING_IBM_869, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_874() + { + check( RTL_TEXTENCODING_MS_874, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1250() + { + check( RTL_TEXTENCODING_MS_1250, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1251() + { + check( RTL_TEXTENCODING_MS_1251, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1253() + { + check( RTL_TEXTENCODING_MS_1253, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1254() + { + check( RTL_TEXTENCODING_MS_1254, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1255() + { + check( RTL_TEXTENCODING_MS_1255, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1256() + { + check( RTL_TEXTENCODING_MS_1256, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1257() + { + check( RTL_TEXTENCODING_MS_1257, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1258() + { + check( RTL_TEXTENCODING_MS_1258, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_ARABIC() + { + check( RTL_TEXTENCODING_APPLE_ARABIC, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_CENTEURO() + { + check( RTL_TEXTENCODING_APPLE_CENTEURO, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_CROATIAN() + { + check( RTL_TEXTENCODING_APPLE_CROATIAN, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_CYRILLIC() + { + check( RTL_TEXTENCODING_APPLE_CYRILLIC, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_DEVANAGARI() + { + check( RTL_TEXTENCODING_APPLE_DEVANAGARI, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_FARSI() + { + check( RTL_TEXTENCODING_APPLE_FARSI, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_GREEK() + { + check( RTL_TEXTENCODING_APPLE_GREEK, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_GUJARATI() + { + check( RTL_TEXTENCODING_APPLE_GUJARATI, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_GURMUKHI() + { + check( RTL_TEXTENCODING_APPLE_GURMUKHI, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_HEBREW() + { + check( RTL_TEXTENCODING_APPLE_HEBREW, RTL_TEXTENCODING_MS_1252 ); + } +#endif + void WindowsCharsetFromTextEncoding_APPLE_ICELAND() + { + check( RTL_TEXTENCODING_APPLE_ICELAND, RTL_TEXTENCODING_MS_1252 ); + } +#if 0 + void WindowsCharsetFromTextEncoding_APPLE_ROMANIAN() + { + check( RTL_TEXTENCODING_APPLE_ROMANIAN, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_THAI() + { + check( RTL_TEXTENCODING_APPLE_THAI, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_TURKISH() + { + check( RTL_TEXTENCODING_APPLE_TURKISH, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_UKRAINIAN() + { + check( RTL_TEXTENCODING_APPLE_UKRAINIAN, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_CHINSIMP() + { + check( RTL_TEXTENCODING_APPLE_CHINSIMP, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_CHINTRAD() + { + check( RTL_TEXTENCODING_APPLE_CHINTRAD, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_JAPANESE() + { + check( RTL_TEXTENCODING_APPLE_JAPANESE, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_APPLE_KOREAN() + { + check( RTL_TEXTENCODING_APPLE_KOREAN, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_932() + { + check( RTL_TEXTENCODING_MS_932, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_936() + { + check( RTL_TEXTENCODING_MS_936, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_949() + { + check( RTL_TEXTENCODING_MS_949, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_950() + { + check( RTL_TEXTENCODING_MS_950, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_SHIFT_JIS() + { + check( RTL_TEXTENCODING_SHIFT_JIS, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_GB_2312() + { + check( RTL_TEXTENCODING_GB_2312, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_GBT_12345() + { + check( RTL_TEXTENCODING_GBT_12345, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_GBK() + { + check( RTL_TEXTENCODING_GBK, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_BIG5() + { + check( RTL_TEXTENCODING_BIG5, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_EUC_JP() + { + check( RTL_TEXTENCODING_EUC_JP, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_EUC_CN() + { + check( RTL_TEXTENCODING_EUC_CN, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_EUC_TW() + { + check( RTL_TEXTENCODING_EUC_TW, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_2022_JP() + { + check( RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_2022_CN() + { + check( RTL_TEXTENCODING_ISO_2022_CN, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_KOI8_R() + { + check( RTL_TEXTENCODING_KOI8_R, RTL_TEXTENCODING_MS_1252 ); + } +#endif + void WindowsCharsetFromTextEncoding_UTF7() + { + check( RTL_TEXTENCODING_UTF7, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_UTF8() + { + check( RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_MS_1252 ); + } +#if 0 + void WindowsCharsetFromTextEncoding_ISO_8859_10() + { + check( RTL_TEXTENCODING_ISO_8859_10, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_8859_13() + { + check( RTL_TEXTENCODING_ISO_8859_13, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_EUC_KR() + { + check( RTL_TEXTENCODING_EUC_KR, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISO_2022_KR() + { + check( RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_JIS_X_0201() + { + check( RTL_TEXTENCODING_JIS_X_0201, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_JIS_X_0208() + { + check( RTL_TEXTENCODING_JIS_X_0208, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_JIS_X_0212() + { + check( RTL_TEXTENCODING_JIS_X_0212, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_MS_1361() + { + check( RTL_TEXTENCODING_MS_1361, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_GB_18030() + { + check( RTL_TEXTENCODING_GB_18030, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_BIG5_HKSCS() + { + check( RTL_TEXTENCODING_BIG5_HKSCS, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_TIS_620() + { + check( RTL_TEXTENCODING_TIS_620, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_KOI8_U() + { + check( RTL_TEXTENCODING_KOI8_U, RTL_TEXTENCODING_MS_1252 ); + } + + void WindowsCharsetFromTextEncoding_ISCII_DEVANAGARI() + { + check( RTL_TEXTENCODING_ISCII_DEVANAGARI, RTL_TEXTENCODING_MS_1252 ); + } +#endif + void WindowsCharsetFromTextEncoding_JAVA_UTF8() + { + check( RTL_TEXTENCODING_JAVA_UTF8, RTL_TEXTENCODING_MS_1252 ); + } + + CPPUNIT_TEST_SUITE( testBestWindows ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1252 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_ROMAN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_437 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_850 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_860 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_861 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_863 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_865 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_SYMBOL ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ASCII_US ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_1 ); +#if 0 + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_2 ); +#endif + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_3 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_4 ); +#if 0 + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_5 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_6 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_7 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_8 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_9 ); +#endif + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_14 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_15 ); +#if 0 + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_737 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_775 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_852 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_855 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_857 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_862 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_864 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_866 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_IBM_869 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_874 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1250 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1251 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1253 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1254 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1255 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1256 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1257 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1258 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_ARABIC ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_CENTEURO ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_CROATIAN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_CYRILLIC ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_DEVANAGARI ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_FARSI ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_GREEK ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_GUJARATI ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_GURMUKHI ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_HEBREW ); +#endif + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_ICELAND ); +#if 0 + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_ROMANIAN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_THAI ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_TURKISH ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_UKRAINIAN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_CHINSIMP ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_CHINTRAD ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_JAPANESE ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_KOREAN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_932 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_936 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_949 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_950 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_SHIFT_JIS ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_GB_2312 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_GBT_12345 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_GBK ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_BIG5 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_EUC_JP ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_EUC_CN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_EUC_TW ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_2022_JP ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_2022_CN ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_KOI8_R ); +#endif + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_UTF7 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_UTF8 ); +#if 0 + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_10 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_13 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_EUC_KR ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_2022_KR ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_JIS_X_0201 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_JIS_X_0208 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_JIS_X_0212 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_MS_1361 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_GB_18030 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_BIG5_HKSCS ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_TIS_620 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_KOI8_U ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISCII_DEVANAGARI ); +#endif + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_JAVA_UTF8 ); + + CPPUNIT_TEST_SUITE_END( ); + }; + + class testTextEncodingInfo: public CppUnit::TestFixture + { + public: + // not implemented encoding test + void testTextEncodingInfo_001() + { + rtl_TextEncodingInfo aInfo1, aInfo2, aInfo3, aInfo4, aInfo5; + aInfo1.StructSize = 4; + // not implemented + bool bRes1 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo1 ); + // implemented + bool bRes11 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo1 ); + CPPUNIT_ASSERT_MESSAGE("should return sal_False.", !bRes1 && !bRes11); + + aInfo2.StructSize = 5; + bool bRes2 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo2 ); + bool bRes21 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo2 ); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes2 && bRes21 && aInfo2.MinimumCharSize >=1 ); + + aInfo3.StructSize = 6; + bool bRes3 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo3 ); + bool bRes31 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo3 ); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes3 && bRes31); +//&& aInfo2.MinimumCharSize >=1 ); + + aInfo4.StructSize = 8; + bool bRes4 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo4 ); + bool bRes41 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo4); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes4 && bRes41); +// && aInfo2.MinimumCharSize >=1 ); + + aInfo5.StructSize = sizeof aInfo5; + bool bRes5 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo5 ); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", !bRes5 && aInfo5.Flags == 0); + + } + CPPUNIT_TEST_SUITE(testTextEncodingInfo); + CPPUNIT_TEST(testTextEncodingInfo_001); + CPPUNIT_TEST_SUITE_END(); + }; + + class testEncodingFromUnix: public CppUnit::TestFixture + { + public: + void testIso8859() { + check(RTL_TEXTENCODING_DONTKNOW, "ISO8859"); + check(RTL_TEXTENCODING_DONTKNOW, "ISO8859-0"); + check(RTL_TEXTENCODING_DONTKNOW, "ISO8859-01"); + check(RTL_TEXTENCODING_DONTKNOW, "ISO8859_1"); + check(RTL_TEXTENCODING_DONTKNOW, "ISO88591"); + check(RTL_TEXTENCODING_ISO_8859_1, "ISO8859-1"); + check(RTL_TEXTENCODING_ISO_8859_2, "ISO8859-2"); + check(RTL_TEXTENCODING_ISO_8859_3, "ISO8859-3"); + check(RTL_TEXTENCODING_ISO_8859_4, "ISO8859-4"); + check(RTL_TEXTENCODING_ISO_8859_5, "ISO8859-5"); + check(RTL_TEXTENCODING_ISO_8859_6, "ISO8859-6"); + check(RTL_TEXTENCODING_ISO_8859_7, "ISO8859-7"); + check(RTL_TEXTENCODING_ISO_8859_8, "ISO8859-8"); + check(RTL_TEXTENCODING_ISO_8859_9, "ISO8859-9"); + check(RTL_TEXTENCODING_ISO_8859_10, "ISO8859-10"); + check(RTL_TEXTENCODING_TIS_620, "ISO8859-11"); + check(RTL_TEXTENCODING_ISO_8859_13, "ISO8859-13"); + check(RTL_TEXTENCODING_ISO_8859_14, "ISO8859-14"); + check(RTL_TEXTENCODING_ISO_8859_15, "ISO8859-15"); + } + + void testTis620() { + check(RTL_TEXTENCODING_DONTKNOW, "TIS620"); + check(RTL_TEXTENCODING_TIS_620, "TIS620-0"); + check(RTL_TEXTENCODING_DONTKNOW, "TIS620-1"); + check(RTL_TEXTENCODING_TIS_620, "TIS620-2529"); + check(RTL_TEXTENCODING_TIS_620, "TIS620-2533"); + check(RTL_TEXTENCODING_DONTKNOW, "TIS620.2529-0"); + check(RTL_TEXTENCODING_TIS_620, "TIS620.2529-1"); + check(RTL_TEXTENCODING_DONTKNOW, "TIS620.2529-2"); + check(RTL_TEXTENCODING_TIS_620, "TIS620.2533-0"); + check(RTL_TEXTENCODING_TIS_620, "TIS620.2533-1"); + check(RTL_TEXTENCODING_DONTKNOW, "TIS620.2533-2"); + } + + CPPUNIT_TEST_SUITE(testEncodingFromUnix); + CPPUNIT_TEST(testIso8859); + CPPUNIT_TEST(testTis620); + CPPUNIT_TEST_SUITE_END(); + + private: + void check(rtl_TextEncoding expected, char const * input) { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + input, expected, rtl_getTextEncodingFromUnixCharset(input)); + } + }; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(testBestMime); +CPPUNIT_TEST_SUITE_REGISTRATION(testBestUnix); +CPPUNIT_TEST_SUITE_REGISTRATION(testBestWindows); +CPPUNIT_TEST_SUITE_REGISTRATION(testTextEncodingInfo); +CPPUNIT_TEST_SUITE_REGISTRATION(testEncodingFromUnix); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx new file mode 100644 index 000000000..8e619a23e --- /dev/null +++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx @@ -0,0 +1,3313 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_locales.h> + +#include <sal/config.h> + +#include <cstddef> +#include <cstring> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <o3tl/cppunittraitshelper.hxx> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <rtl/tencinfo.h> +#include <rtl/textcvt.h> +#include <rtl/textenc.h> +#include <sal/types.h> +#include <sal/macros.h> +#include <osl/diagnose.h> + +namespace { + +struct SingleByteCharSet { + rtl_TextEncoding m_nEncoding; + sal_Unicode m_aMap[256]; +}; + +void testSingleByteCharSet(SingleByteCharSet const & rSet) { + char aText[256]; + sal_Unicode aUnicode[256]; + sal_Size nNumber = 0; + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] != 0xFFFF) { + aText[nNumber++] = static_cast< char >(i); + } + } + { + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rSet.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != nullptr); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertTextToUnicode( + aConverter, aContext, aText, nNumber, aUnicode, nNumber, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &nInfo, &nConverted); + CPPUNIT_ASSERT_EQUAL(nNumber, nSize); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), nInfo); + CPPUNIT_ASSERT_EQUAL(nNumber, nConverted); + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + } + { + int j = 0; + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] != 0xFFFF && aUnicode[j] != rSet.m_aMap[i]) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " + + OUString::number(rSet.m_aMap[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + u'\xFFFF', rSet.m_aMap[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(j) + "] == " + + OUString::number(aUnicode[j], 16) + + ", rSet.m_aMap[" + OUString::number(i) + "] == " + + OUString::number(rSet.m_aMap[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + rSet.m_aMap[i], aUnicode[j]); + } + if (rSet.m_aMap[i] != 0xFFFF) + j++; + } + } + if (rSet.m_nEncoding == RTL_TEXTENCODING_ASCII_US) { + nNumber = 128; + } + { + rtl_UnicodeToTextConverter aConverter + = rtl_createUnicodeToTextConverter(rSet.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + rtl_UnicodeToTextContext aContext + = rtl_createUnicodeToTextContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != nullptr); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertUnicodeToText( + aConverter, aContext, aUnicode, nNumber, aText, nNumber, + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR), + &nInfo, &nConverted); + CPPUNIT_ASSERT_EQUAL(nNumber, nSize); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), nInfo); + CPPUNIT_ASSERT_EQUAL(nNumber, nConverted); + rtl_destroyUnicodeToTextContext(aConverter, aContext); + rtl_destroyUnicodeToTextConverter(aConverter); + } + { + int j = 0; + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] != 0xFFFF + && aText[j] != static_cast< char >(i)) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " + + OUString::number(rSet.m_aMap[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + u'\xFFFF', rSet.m_aMap[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(j) + "] == " + + OUString::number(i, 16)), + RTL_TEXTENCODING_UTF8).getStr(), + static_cast< char >(i), aText[j]); + } + if (rSet.m_aMap[i] != 0xFFFF) + j++; + } + } + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] == 0xFFFF) { + aText[0] = static_cast< char >(i); + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rSet.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != nullptr); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertTextToUnicode( + aConverter, aContext, aText, 1, aUnicode, 1, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &nInfo, &nConverted); + + sal_uInt32 nExpectedInfo = (RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_UNDEFINED); + + CPPUNIT_ASSERT_EQUAL(sal_Size(0), nSize); + CPPUNIT_ASSERT_EQUAL(nExpectedInfo, nInfo); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), nConverted); + + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + } + } +} + +int const TEST_STRING_SIZE = 1000; + +struct ComplexCharSetTest { + rtl_TextEncoding m_nEncoding; + char const * m_pText; + sal_Size m_nTextSize; + sal_Unicode m_aUnicode[TEST_STRING_SIZE]; + sal_Size m_nUnicodeSize; + bool m_bNoContext; + bool m_bForward; + bool m_bReverse; + bool m_bGlobalSignature; + sal_uInt32 m_nReverseUndefined; +}; + +void doComplexCharSetTest(ComplexCharSetTest const & rTest) { + if (rTest.m_bForward) { + sal_Unicode aUnicode[TEST_STRING_SIZE]; + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rTest.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != nullptr); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertTextToUnicode( + aConverter, aContext, + reinterpret_cast< char const * >(rTest.m_pText), + rTest.m_nTextSize, aUnicode, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR + | RTL_TEXTTOUNICODE_FLAGS_FLUSH + | (rTest.m_bGlobalSignature ? + RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE : 0)), + &nInfo, &nConverted); + CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nSize); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), nInfo); + CPPUNIT_ASSERT_EQUAL(rTest.m_nTextSize, nConverted); + + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + + for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " + + OUString::number(aUnicode[i], 16) + + ", rTest.m_aUnicode[" + OUString::number(i) + "] == " + + OUString::number(rTest.m_aUnicode[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + rTest.m_aUnicode[i], aUnicode[i]); + } + } + if (rTest.m_bForward) { + sal_Unicode aUnicode[TEST_STRING_SIZE]; + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rTest.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != nullptr); + if (aContext != reinterpret_cast<rtl_TextToUnicodeContext>(1)) { + sal_Size nInput = 0; + sal_Size nOutput = 0; + for (bool bFlush = true; nInput < rTest.m_nTextSize || bFlush;) { + sal_Size nSrcBytes = 1; + sal_uInt32 nFlags + = (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR + | (rTest.m_bGlobalSignature ? + RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE : 0)); + if (nInput >= rTest.m_nTextSize) { + nSrcBytes = 0; + nFlags |= RTL_TEXTTOUNICODE_FLAGS_FLUSH; + bFlush = false; + } + sal_uInt32 nInfo; + sal_Size nConverted; + sal_Size nSize = rtl_convertTextToUnicode( + aConverter, aContext, + reinterpret_cast< char const * >(rTest.m_pText + nInput), + nSrcBytes, aUnicode + nOutput, TEST_STRING_SIZE - nOutput, + nFlags, &nInfo, &nConverted); + nOutput += nSize; + nInput += nConverted; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), + (nInfo & ~RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL)); + } + CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nOutput); + CPPUNIT_ASSERT_EQUAL(rTest.m_nTextSize, nInput); + + for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " + + OUString::number(aUnicode[i], 16) + + ", rTest.m_aUnicode[" + OUString::number(i) + "] == " + + OUString::number(rTest.m_aUnicode[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + rTest.m_aUnicode[i], aUnicode[i]); + } + } + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + } + if (rTest.m_bNoContext && rTest.m_bForward) { + sal_Unicode aUnicode[TEST_STRING_SIZE] = { 0, }; + int nSize = 0; + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rTest.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + for (sal_Size i = 0;;) { + if (i == rTest.m_nTextSize) { + goto done; + } + char c1 = rTest.m_pText[i++]; + sal_Unicode aUC[2]; + sal_uInt32 nInfo = 0; + sal_Size nCvtBytes; + sal_Size nChars = rtl_convertTextToUnicode( + aConverter, nullptr, &c1, 1, aUC, 2, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR + | (rTest.m_bGlobalSignature ? + RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE : 0)), + &nInfo, &nCvtBytes); + if ((nInfo & RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL) != 0) { + char sBuffer[10]; + sBuffer[0] = c1; + sal_uInt16 nLen = 1; + while ((nInfo & RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL) != 0 + && nLen < 10) + { + if (i == rTest.m_nTextSize) { + goto done; + } + c1 = rTest.m_pText[i++]; + sBuffer[nLen++] = c1; + nChars = rtl_convertTextToUnicode( + aConverter, nullptr, sBuffer, nLen, aUC, 2, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR + | (rTest.m_bGlobalSignature ? + RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE : 0)), + &nInfo, &nCvtBytes); + } + if (nChars == 1 && nInfo == 0) { + OSL_ASSERT(nCvtBytes == nLen); + aUnicode[nSize++] = aUC[0]; + } else if (nChars == 2 && nInfo == 0) { + OSL_ASSERT(nCvtBytes == nLen); + aUnicode[nSize++] = aUC[0]; + aUnicode[nSize++] = aUC[1]; + } else { + OSL_ASSERT( + (nInfo & RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL) == 0 + && nChars == 0 && nInfo != 0); + aUnicode[nSize++] = sBuffer[0]; + i -= nLen - 1; + } + } else if (nChars == 1 && nInfo == 0) { + OSL_ASSERT(nCvtBytes == 1); + aUnicode[nSize++] = aUC[0]; + } else if (nChars == 2 && nInfo == 0) { + OSL_ASSERT(nCvtBytes == 1); + aUnicode[nSize++] = aUC[0]; + aUnicode[nSize++] = aUC[1]; + } else { + OSL_ASSERT(nChars == 0 && nInfo != 0); + aUnicode[nSize++] = c1; + } + } + done: + rtl_destroyTextToUnicodeConverter(aConverter); + for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " + + OUString::number(aUnicode[i], 16) + + ", rTest.m_aUnicode[" + OUString::number(i) + "] == " + + OUString::number(rTest.m_aUnicode[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + rTest.m_aUnicode[i], aUnicode[i]); + } + } + if (rTest.m_bReverse) { + char aText[TEST_STRING_SIZE]; + rtl_UnicodeToTextConverter aConverter + = rtl_createUnicodeToTextConverter(rTest.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + rtl_UnicodeToTextContext aContext + = rtl_createUnicodeToTextContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != nullptr); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertUnicodeToText( + aConverter, aContext, rTest.m_aUnicode, rTest.m_nUnicodeSize, aText, + TEST_STRING_SIZE, + (rTest.m_nReverseUndefined | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR + | RTL_UNICODETOTEXT_FLAGS_FLUSH + | (rTest.m_bGlobalSignature ? + RTL_UNICODETOTEXT_FLAGS_GLOBAL_SIGNATURE : 0)), + &nInfo, &nConverted); + CPPUNIT_ASSERT_EQUAL(rTest.m_nTextSize, nSize); + if (nInfo != 0) + { + CPPUNIT_ASSERT_EQUAL(RTL_UNICODETOTEXT_INFO_UNDEFINED, nInfo); + CPPUNIT_ASSERT_MESSAGE("rTest.m_nReverseUndefined should not be RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR", + rTest.m_nReverseUndefined != RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR); + } + CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nConverted); + rtl_destroyUnicodeToTextContext(aConverter, aContext); + rtl_destroyUnicodeToTextConverter(aConverter); + for (sal_Size i = 0; i < rTest.m_nTextSize; ++i) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(i) + "] == " + + OUString::number(aText[i], 16) + + ", rTest.m_pText[" + OUString::number(i) + "] == " + + OUString::number(rTest.m_pText[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + rTest.m_pText[i], aText[i]); + } + } +} + +void doComplexCharSetCutTest(ComplexCharSetTest const & rTest) { + if (rTest.m_bNoContext) { + sal_Unicode aUnicode[TEST_STRING_SIZE]; + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rTest.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"), + RTL_TEXTENCODING_UTF8).getStr(), + aConverter != nullptr); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertTextToUnicode( + aConverter, nullptr, reinterpret_cast< char const * >(rTest.m_pText), + rTest.m_nTextSize, aUnicode, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &nInfo, &nConverted); + + CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nSize); + if (nInfo != RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL) + { + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL, + nInfo); + } + CPPUNIT_ASSERT_MESSAGE("nConverted should be less than rTest.m_nTextSize", nConverted < rTest.m_nTextSize); + + rtl_destroyTextToUnicodeConverter(aConverter); + for (sal_Size i = 0; i < nSize; ++i) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " + + OUString::number(aUnicode[i], 16) + + ", rTest.m_aUnicode[" + OUString::number(i) + "] == " + + OUString::number(rTest.m_aUnicode[i], 16)), + RTL_TEXTENCODING_UTF8).getStr(), + rTest.m_aUnicode[i], aUnicode[i]); + } + } +} + +class Test: public CppUnit::TestFixture { +public: + void testSingleByte(); + + void testComplex(); + + void testComplexCut(); + + void testInvalidUtf7(); + + void testInvalidUtf8(); + + void testInvalidUnicode(); + + void testSRCBUFFERTOSMALL(); + + void testMime(); + + void testWindows(); + + void testInfo(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testSingleByte); + CPPUNIT_TEST(testComplex); + CPPUNIT_TEST(testComplexCut); + CPPUNIT_TEST(testInvalidUtf7); + CPPUNIT_TEST(testInvalidUtf8); + CPPUNIT_TEST(testInvalidUnicode); + CPPUNIT_TEST(testSRCBUFFERTOSMALL); + CPPUNIT_TEST(testMime); + CPPUNIT_TEST(testWindows); + CPPUNIT_TEST(testInfo); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::testSingleByte() { + static SingleByteCharSet const data[] + = { { RTL_TEXTENCODING_MS_1250, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0xFFFF,0x201E,0x2026,0x2020,0x2021, + 0xFFFF,0x2030,0x0160,0x2039,0x015A,0x0164,0x017D,0x0179, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0xFFFF,0x2122,0x0161,0x203A,0x015B,0x0165,0x017E,0x017A, + 0x00A0,0x02C7,0x02D8,0x0141,0x00A4,0x0104,0x00A6,0x00A7, + 0x00A8,0x00A9,0x015E,0x00AB,0x00AC,0x00AD,0x00AE,0x017B, + 0x00B0,0x00B1,0x02DB,0x0142,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x0105,0x015F,0x00BB,0x013D,0x02DD,0x013E,0x017C, + 0x0154,0x00C1,0x00C2,0x0102,0x00C4,0x0139,0x0106,0x00C7, + 0x010C,0x00C9,0x0118,0x00CB,0x011A,0x00CD,0x00CE,0x010E, + 0x0110,0x0143,0x0147,0x00D3,0x00D4,0x0150,0x00D6,0x00D7, + 0x0158,0x016E,0x00DA,0x0170,0x00DC,0x00DD,0x0162,0x00DF, + 0x0155,0x00E1,0x00E2,0x0103,0x00E4,0x013A,0x0107,0x00E7, + 0x010D,0x00E9,0x0119,0x00EB,0x011B,0x00ED,0x00EE,0x010F, + 0x0111,0x0144,0x0148,0x00F3,0x00F4,0x0151,0x00F6,0x00F7, + 0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9 } }, + { RTL_TEXTENCODING_MS_1251, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0402,0x0403,0x201A,0x0453,0x201E,0x2026,0x2020,0x2021, + 0x20AC,0x2030,0x0409,0x2039,0x040A,0x040C,0x040B,0x040F, + 0x0452,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0xFFFF,0x2122,0x0459,0x203A,0x045A,0x045C,0x045B,0x045F, + 0x00A0,0x040E,0x045E,0x0408,0x00A4,0x0490,0x00A6,0x00A7, + 0x0401,0x00A9,0x0404,0x00AB,0x00AC,0x00AD,0x00AE,0x0407, + 0x00B0,0x00B1,0x0406,0x0456,0x0491,0x00B5,0x00B6,0x00B7, + 0x0451,0x2116,0x0454,0x00BB,0x0458,0x0405,0x0455,0x0457, + 0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417, + 0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E,0x041F, + 0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427, + 0x0428,0x0429,0x042A,0x042B,0x042C,0x042D,0x042E,0x042F, + 0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437, + 0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E,0x043F, + 0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447, + 0x0448,0x0449,0x044A,0x044B,0x044C,0x044D,0x044E,0x044F } }, + { RTL_TEXTENCODING_MS_1252, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, + 0x02C6,0x2030,0x0160,0x2039,0x0152,0xFFFF,0x017D,0xFFFF, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0x02DC,0x2122,0x0161,0x203A,0x0153,0xFFFF,0x017E,0x0178, + 0x00A0,0x00A1,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x00AA,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x00BA,0x00BB,0x00BC,0x00BD,0x00BE,0x00BF, + 0x00C0,0x00C1,0x00C2,0x00C3,0x00C4,0x00C5,0x00C6,0x00C7, + 0x00C8,0x00C9,0x00CA,0x00CB,0x00CC,0x00CD,0x00CE,0x00CF, + 0x00D0,0x00D1,0x00D2,0x00D3,0x00D4,0x00D5,0x00D6,0x00D7, + 0x00D8,0x00D9,0x00DA,0x00DB,0x00DC,0x00DD,0x00DE,0x00DF, + 0x00E0,0x00E1,0x00E2,0x00E3,0x00E4,0x00E5,0x00E6,0x00E7, + 0x00E8,0x00E9,0x00EA,0x00EB,0x00EC,0x00ED,0x00EE,0x00EF, + 0x00F0,0x00F1,0x00F2,0x00F3,0x00F4,0x00F5,0x00F6,0x00F7, + 0x00F8,0x00F9,0x00FA,0x00FB,0x00FC,0x00FD,0x00FE,0x00FF } }, + { RTL_TEXTENCODING_MS_1253, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, + 0xFFFF,0x2030,0xFFFF,0x2039,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0xFFFF,0x2122,0xFFFF,0x203A,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x00A0,0x0385,0x0386,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0xFFFF,0x00AB,0x00AC,0x00AD,0x00AE,0x2015, + 0x00B0,0x00B1,0x00B2,0x00B3,0x0384,0x00B5,0x00B6,0x00B7, + 0x0388,0x0389,0x038A,0x00BB,0x038C,0x00BD,0x038E,0x038F, + 0x0390,0x0391,0x0392,0x0393,0x0394,0x0395,0x0396,0x0397, + 0x0398,0x0399,0x039A,0x039B,0x039C,0x039D,0x039E,0x039F, + 0x03A0,0x03A1,0xFFFF,0x03A3,0x03A4,0x03A5,0x03A6,0x03A7, + 0x03A8,0x03A9,0x03AA,0x03AB,0x03AC,0x03AD,0x03AE,0x03AF, + 0x03B0,0x03B1,0x03B2,0x03B3,0x03B4,0x03B5,0x03B6,0x03B7, + 0x03B8,0x03B9,0x03BA,0x03BB,0x03BC,0x03BD,0x03BE,0x03BF, + 0x03C0,0x03C1,0x03C2,0x03C3,0x03C4,0x03C5,0x03C6,0x03C7, + 0x03C8,0x03C9,0x03CA,0x03CB,0x03CC,0x03CD,0x03CE,0xFFFF } }, + { RTL_TEXTENCODING_MS_1254, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, + 0x02C6,0x2030,0x0160,0x2039,0x0152,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0x02DC,0x2122,0x0161,0x203A,0x0153,0xFFFF,0xFFFF,0x0178, + 0x00A0,0x00A1,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x00AA,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x00BA,0x00BB,0x00BC,0x00BD,0x00BE,0x00BF, + 0x00C0,0x00C1,0x00C2,0x00C3,0x00C4,0x00C5,0x00C6,0x00C7, + 0x00C8,0x00C9,0x00CA,0x00CB,0x00CC,0x00CD,0x00CE,0x00CF, + 0x011E,0x00D1,0x00D2,0x00D3,0x00D4,0x00D5,0x00D6,0x00D7, + 0x00D8,0x00D9,0x00DA,0x00DB,0x00DC,0x0130,0x015E,0x00DF, + 0x00E0,0x00E1,0x00E2,0x00E3,0x00E4,0x00E5,0x00E6,0x00E7, + 0x00E8,0x00E9,0x00EA,0x00EB,0x00EC,0x00ED,0x00EE,0x00EF, + 0x011F,0x00F1,0x00F2,0x00F3,0x00F4,0x00F5,0x00F6,0x00F7, + 0x00F8,0x00F9,0x00FA,0x00FB,0x00FC,0x0131,0x015F,0x00FF } }, + { RTL_TEXTENCODING_APPLE_ROMAN, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E, 0x7F, + 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1, + 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8, + 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3, + 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC, + 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF, + 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8, + 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211, + 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8, + 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB, + 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153, + 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA, + 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02, + 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1, + 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4, + 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC, + 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7 } }, + { RTL_TEXTENCODING_IBM_437, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7, + 0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9, + 0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20a7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba, + 0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556, + 0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f, + 0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b, + 0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4, + 0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248, + 0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 } }, + + { RTL_TEXTENCODING_ASCII_US, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, // ! + 0x02C6,0x2030,0x0160,0x2039,0x0152,0xFFFF,0x017D,0xFFFF, // ! + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, // ! + 0x02DC,0x2122,0x0161,0x203A,0x0153,0xFFFF,0x017E,0x0178, // ! + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, + 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, + 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, + 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, + 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF } }, + { RTL_TEXTENCODING_ISO_8859_1, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, + 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097, + 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F, + 0x00A0,0x00A1,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x00AA,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x00BA,0x00BB,0x00BC,0x00BD,0x00BE,0x00BF, + 0x00C0,0x00C1,0x00C2,0x00C3,0x00C4,0x00C5,0x00C6,0x00C7, + 0x00C8,0x00C9,0x00CA,0x00CB,0x00CC,0x00CD,0x00CE,0x00CF, + 0x00D0,0x00D1,0x00D2,0x00D3,0x00D4,0x00D5,0x00D6,0x00D7, + 0x00D8,0x00D9,0x00DA,0x00DB,0x00DC,0x00DD,0x00DE,0x00DF, + 0x00E0,0x00E1,0x00E2,0x00E3,0x00E4,0x00E5,0x00E6,0x00E7, + 0x00E8,0x00E9,0x00EA,0x00EB,0x00EC,0x00ED,0x00EE,0x00EF, + 0x00F0,0x00F1,0x00F2,0x00F3,0x00F4,0x00F5,0x00F6,0x00F7, + 0x00F8,0x00F9,0x00FA,0x00FB,0x00FC,0x00FD,0x00FE,0x00FF } }, + { RTL_TEXTENCODING_ISO_8859_2, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, + 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097, + 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F, + 0x00A0,0x0104,0x02D8,0x0141,0x00A4,0x013D,0x015A,0x00A7, + 0x00A8,0x0160,0x015E,0x0164,0x0179,0x00AD,0x017D,0x017B, + 0x00B0,0x0105,0x02DB,0x0142,0x00B4,0x013E,0x015B,0x02C7, + 0x00B8,0x0161,0x015F,0x0165,0x017A,0x02DD,0x017E,0x017C, + 0x0154,0x00C1,0x00C2,0x0102,0x00C4,0x0139,0x0106,0x00C7, + 0x010C,0x00C9,0x0118,0x00CB,0x011A,0x00CD,0x00CE,0x010E, + 0x0110,0x0143,0x0147,0x00D3,0x00D4,0x0150,0x00D6,0x00D7, + 0x0158,0x016E,0x00DA,0x0170,0x00DC,0x00DD,0x0162,0x00DF, + 0x0155,0x00E1,0x00E2,0x0103,0x00E4,0x013A,0x0107,0x00E7, + 0x010D,0x00E9,0x0119,0x00EB,0x011B,0x00ED,0x00EE,0x010F, + 0x0111,0x0144,0x0148,0x00F3,0x00F4,0x0151,0x00F6,0x00F7, + 0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9 } }, + { RTL_TEXTENCODING_ISO_8859_3, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, + 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097, + 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F, + 0x00A0,0x0126,0x02D8,0x00A3,0x00A4,0xFFFF,0x0124,0x00A7, + 0x00A8,0x0130,0x015E,0x011E,0x0134,0x00AD,0xFFFF,0x017B, + 0x00B0,0x0127,0x00B2,0x00B3,0x00B4,0x00B5,0x0125,0x00B7, + 0x00B8,0x0131,0x015F,0x011F,0x0135,0x00BD,0xFFFF,0x017C, + 0x00C0,0x00C1,0x00C2,0xFFFF,0x00C4,0x010A,0x0108,0x00C7, + 0x00C8,0x00C9,0x00CA,0x00CB,0x00CC,0x00CD,0x00CE,0x00CF, + 0xFFFF,0x00D1,0x00D2,0x00D3,0x00D4,0x0120,0x00D6,0x00D7, + 0x011C,0x00D9,0x00DA,0x00DB,0x00DC,0x016C,0x015C,0x00DF, + 0x00E0,0x00E1,0x00E2,0xFFFF,0x00E4,0x010B,0x0109,0x00E7, + 0x00E8,0x00E9,0x00EA,0x00EB,0x00EC,0x00ED,0x00EE,0x00EF, + 0xFFFF,0x00F1,0x00F2,0x00F3,0x00F4,0x0121,0x00F6,0x00F7, + 0x011D,0x00F9,0x00FA,0x00FB,0x00FC,0x016D,0x015D,0x02D9 } }, + + { RTL_TEXTENCODING_ISO_8859_6, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, + 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097, + 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F, + 0x00A0,0xFFFF,0xFFFF,0xFFFF,0x00A4,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x060C,0x00AD,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0x061B,0xFFFF,0xFFFF,0xFFFF,0x061F, + 0xFFFF,0x0621,0x0622,0x0623,0x0624,0x0625,0x0626,0x0627, + 0x0628,0x0629,0x062A,0x062B,0x062C,0x062D,0x062E,0x062F, + 0x0630,0x0631,0x0632,0x0633,0x0634,0x0635,0x0636,0x0637, + 0x0638,0x0639,0x063A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x0640,0x0641,0x0642,0x0643,0x0644,0x0645,0x0646,0x0647, + 0x0648,0x0649,0x064A,0x064B,0x064C,0x064D,0x064E,0x064F, + 0x0650,0x0651,0x0652,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF } }, + + { RTL_TEXTENCODING_ISO_8859_8, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, + 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097, + 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F, + 0x00A0,0xFFFF,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x00D7,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x00F7,0x00BB,0x00BC,0x00BD,0x00BE,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x2017, + 0x05D0,0x05D1,0x05D2,0x05D3,0x05D4,0x05D5,0x05D6,0x05D7, + 0x05D8,0x05D9,0x05DA,0x05DB,0x05DC,0x05DD,0x05DE,0x05DF, + 0x05E0,0x05E1,0x05E2,0x05E3,0x05E4,0x05E5,0x05E6,0x05E7, + 0x05E8,0x05E9,0x05EA,0xFFFF,0xFFFF,0x200E,0x200F,0xFFFF } }, + + { RTL_TEXTENCODING_TIS_620, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, + 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097, + 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F, + 0x00A0,0x0E01,0x0E02,0x0E03,0x0E04,0x0E05,0x0E06,0x0E07, // ! + 0x0E08,0x0E09,0x0E0A,0x0E0B,0x0E0C,0x0E0D,0x0E0E,0x0E0F, + 0x0E10,0x0E11,0x0E12,0x0E13,0x0E14,0x0E15,0x0E16,0x0E17, + 0x0E18,0x0E19,0x0E1A,0x0E1B,0x0E1C,0x0E1D,0x0E1E,0x0E1F, + 0x0E20,0x0E21,0x0E22,0x0E23,0x0E24,0x0E25,0x0E26,0x0E27, + 0x0E28,0x0E29,0x0E2A,0x0E2B,0x0E2C,0x0E2D,0x0E2E,0x0E2F, + 0x0E30,0x0E31,0x0E32,0x0E33,0x0E34,0x0E35,0x0E36,0x0E37, + 0x0E38,0x0E39,0x0E3A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0E3F, + 0x0E40,0x0E41,0x0E42,0x0E43,0x0E44,0x0E45,0x0E46,0x0E47, + 0x0E48,0x0E49,0x0E4A,0x0E4B,0x0E4C,0x0E4D,0x0E4E,0x0E4F, + 0x0E50,0x0E51,0x0E52,0x0E53,0x0E54,0x0E55,0x0E56,0x0E57, + 0x0E58,0x0E59,0x0E5A,0x0E5B,0xFFFF,0xFFFF,0xFFFF,0xFFFF } }, + { RTL_TEXTENCODING_MS_874, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x2026,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x00A0,0x0E01,0x0E02,0x0E03,0x0E04,0x0E05,0x0E06,0x0E07, + 0x0E08,0x0E09,0x0E0A,0x0E0B,0x0E0C,0x0E0D,0x0E0E,0x0E0F, + 0x0E10,0x0E11,0x0E12,0x0E13,0x0E14,0x0E15,0x0E16,0x0E17, + 0x0E18,0x0E19,0x0E1A,0x0E1B,0x0E1C,0x0E1D,0x0E1E,0x0E1F, + 0x0E20,0x0E21,0x0E22,0x0E23,0x0E24,0x0E25,0x0E26,0x0E27, + 0x0E28,0x0E29,0x0E2A,0x0E2B,0x0E2C,0x0E2D,0x0E2E,0x0E2F, + 0x0E30,0x0E31,0x0E32,0x0E33,0x0E34,0x0E35,0x0E36,0x0E37, + 0x0E38,0x0E39,0x0E3A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0E3F, + 0x0E40,0x0E41,0x0E42,0x0E43,0x0E44,0x0E45,0x0E46,0x0E47, + 0x0E48,0x0E49,0x0E4A,0x0E4B,0x0E4C,0x0E4D,0x0E4E,0x0E4F, + 0x0E50,0x0E51,0x0E52,0x0E53,0x0E54,0x0E55,0x0E56,0x0E57, + 0x0E58,0x0E59,0x0E5A,0x0E5B,0xFFFF,0xFFFF,0xFFFF,0xFFFF } }, + { RTL_TEXTENCODING_MS_1255, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, + 0x02C6,0x2030,0xFFFF,0x2039,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0x02DC,0x2122,0xFFFF,0x203A,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x00A0,0x00A1,0x00A2,0x00A3,0x20AA,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x00D7,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x00F7,0x00BB,0x00BC,0x00BD,0x00BE,0x00BF, + 0x05B0,0x05B1,0x05B2,0x05B3,0x05B4,0x05B5,0x05B6,0x05B7, + 0x05B8,0x05B9,0xFFFF,0x05BB,0x05BC,0x05BD,0x05BE,0x05BF, + 0x05C0,0x05C1,0x05C2,0x05C3,0x05F0,0x05F1,0x05F2,0x05F3, + 0x05F4,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x05D0,0x05D1,0x05D2,0x05D3,0x05D4,0x05D5,0x05D6,0x05D7, + 0x05D8,0x05D9,0x05DA,0x05DB,0x05DC,0x05DD,0x05DE,0x05DF, + 0x05E0,0x05E1,0x05E2,0x05E3,0x05E4,0x05E5,0x05E6,0x05E7, + 0x05E8,0x05E9,0x05EA,0xFFFF,0xFFFF,0x200E,0x200F,0xFFFF } }, + { RTL_TEXTENCODING_MS_1256, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0x067E,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, + 0x02C6,0x2030,0x0679,0x2039,0x0152,0x0686,0x0698,0x0688, + 0x06AF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0x06A9,0x2122,0x0691,0x203A,0x0153,0x200C,0x200D,0x06BA, + 0x00A0,0x060C,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x06BE,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x061B,0x00BB,0x00BC,0x00BD,0x00BE,0x061F, + 0x06C1,0x0621,0x0622,0x0623,0x0624,0x0625,0x0626,0x0627, + 0x0628,0x0629,0x062A,0x062B,0x062C,0x062D,0x062E,0x062F, + 0x0630,0x0631,0x0632,0x0633,0x0634,0x0635,0x0636,0x00D7, + 0x0637,0x0638,0x0639,0x063A,0x0640,0x0641,0x0642,0x0643, + 0x00E0,0x0644,0x00E2,0x0645,0x0646,0x0647,0x0648,0x00E7, + 0x00E8,0x00E9,0x00EA,0x00EB,0x0649,0x064A,0x00EE,0x00EF, + 0x064B,0x064C,0x064D,0x064E,0x00F4,0x064F,0x0650,0x00F7, + 0x0651,0x00F9,0x0652,0x00FB,0x00FC,0x200E,0x200F,0x06D2 } }, + { RTL_TEXTENCODING_MS_1257, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0xFFFF,0x201E,0x2026,0x2020,0x2021, + 0xFFFF,0x2030,0xFFFF,0x2039,0xFFFF,0x00A8,0x02C7,0x00B8, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0xFFFF,0x2122,0xFFFF,0x203A,0xFFFF,0x00AF,0x02DB,0xFFFF, + 0x00A0,0xFFFF,0x00A2,0x00A3,0x00A4,0xFFFF,0x00A6,0x00A7, + 0x00D8,0x00A9,0x0156,0x00AB,0x00AC,0x00AD,0x00AE,0x00C6, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00F8,0x00B9,0x0157,0x00BB,0x00BC,0x00BD,0x00BE,0x00E6, + 0x0104,0x012E,0x0100,0x0106,0x00C4,0x00C5,0x0118,0x0112, + 0x010C,0x00C9,0x0179,0x0116,0x0122,0x0136,0x012A,0x013B, + 0x0160,0x0143,0x0145,0x00D3,0x014C,0x00D5,0x00D6,0x00D7, + 0x0172,0x0141,0x015A,0x016A,0x00DC,0x017B,0x017D,0x00DF, + 0x0105,0x012F,0x0101,0x0107,0x00E4,0x00E5,0x0119,0x0113, + 0x010D,0x00E9,0x017A,0x0117,0x0123,0x0137,0x012B,0x013C, + 0x0161,0x0144,0x0146,0x00F3,0x014D,0x00F5,0x00F6,0x00F7, + 0x0173,0x0142,0x015B,0x016B,0x00FC,0x017C,0x017E,0x02D9 } }, + { RTL_TEXTENCODING_MS_1258, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x20AC,0xFFFF,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021, + 0x02C6,0x2030,0xFFFF,0x2039,0x0152,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0x02DC,0x2122,0xFFFF,0x203A,0x0153,0xFFFF,0xFFFF,0x0178, + 0x00A0,0x00A1,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7, + 0x00A8,0x00A9,0x00AA,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF, + 0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7, + 0x00B8,0x00B9,0x00BA,0x00BB,0x00BC,0x00BD,0x00BE,0x00BF, + 0x00C0,0x00C1,0x00C2,0x0102,0x00C4,0x00C5,0x00C6,0x00C7, + 0x00C8,0x00C9,0x00CA,0x00CB,0x0300,0x00CD,0x00CE,0x00CF, + 0x0110,0x00D1,0x0309,0x00D3,0x00D4,0x01A0,0x00D6,0x00D7, + 0x00D8,0x00D9,0x00DA,0x00DB,0x00DC,0x01AF,0x0303,0x00DF, + 0x00E0,0x00E1,0x00E2,0x0103,0x00E4,0x00E5,0x00E6,0x00E7, + 0x00E8,0x00E9,0x00EA,0x00EB,0x0301,0x00ED,0x00EE,0x00EF, + 0x0111,0x00F1,0x0323,0x00F3,0x00F4,0x01A1,0x00F6,0x00F7, + 0x00F8,0x00F9,0x00FA,0x00FB,0x00FC,0x01B0,0x20AB,0x00FF } }, + { RTL_TEXTENCODING_KOI8_U, // RFC 2319 + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x2500,0x2502,0x250C,0x2510,0x2514,0x2518,0x251C,0x2524, + 0x252C,0x2534,0x253C,0x2580,0x2584,0x2588,0x258C,0x2590, + 0x2591,0x2592,0x2593,0x2320,0x25A0,0x2219,0x221A,0x2248, + 0x2264,0x2265,0x00A0,0x2321,0x00B0,0x00B2,0x00B7,0x00F7, + 0x2550,0x2551,0x2552,0x0451,0x0454,0x2554,0x0456,0x0457, + 0x2557,0x2558,0x2559,0x255A,0x255B,0x0491,0x255D,0x255E, + 0x255F,0x2560,0x2561,0x0401,0x0404,0x2563,0x0406,0x0407, + 0x2566,0x2567,0x2568,0x2569,0x256A,0x0490,0x256C,0x00A9, + 0x044E,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433, + 0x0445,0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E, + 0x043F,0x044F,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432, + 0x044C,0x044B,0x0437,0x0448,0x044D,0x0449,0x0447,0x044A, + 0x042E,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413, + 0x0425,0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E, + 0x041F,0x042F,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412, + 0x042C,0x042B,0x0417,0x0428,0x042D,0x0429,0x0427,0x042A } }, + { RTL_TEXTENCODING_ADOBE_STANDARD, + { 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x2019, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x2018,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x00A1,0x00A2,0x00A3,0x2215,0x00A5,0x0192,0x00A7, + 0x00A4,0x0027,0x201C,0x00AB,0x2039,0x203A,0xFB01,0xFB02, + 0xFFFF,0x2013,0x2020,0x2021,0x00B7,0xFFFF,0x00B6,0x2022, + 0x201A,0x201E,0x201D,0x00BB,0x2026,0x2030,0xFFFF,0x00BF, + 0xFFFF,0x0060,0x00B4,0x02C6,0x02DC,0x00AF,0x02D8,0x02D9, + 0x00A8,0xFFFF,0x02DA,0x00B8,0xFFFF,0x02DD,0x02DB,0x02C7, + 0x2014,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x00C6,0xFFFF,0x00AA,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x0141,0x00D8,0x0152,0x00BA,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x00E6,0xFFFF,0xFFFF,0xFFFF,0x0131,0xFFFF,0xFFFF, + 0x0142,0x00F8,0x0153,0x00DF,0xFFFF,0xFFFF,0xFFFF,0xFFFF } }, + { RTL_TEXTENCODING_ADOBE_SYMBOL, + { 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x0020,0x0021,0x2200,0x0023,0x2203,0x0025,0x0026,0x220B, + 0x0028,0x0029,0x2217,0x002B,0x002C,0x2212,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x2245,0x0391,0x0392,0x03A7,0x0394,0x0395,0x03A6,0x0393, + 0x0397,0x0399,0x03D1,0x039A,0x039B,0x039C,0x039D,0x039F, + 0x03A0,0x0398,0x03A1,0x03A3,0x03A4,0x03A5,0x03C2,0x03A9, + 0x039E,0x03A8,0x0396,0x005B,0x2234,0x005D,0x22A5,0x005F, + 0xF8E5,0x03B1,0x03B2,0x03C7,0x03B4,0x03B5,0x03C6,0x03B3, + 0x03B7,0x03B9,0x03D5,0x03BA,0x03BB,0x03BC,0x03BD,0x03BF, + 0x03C0,0x03B8,0x03C1,0x03C3,0x03C4,0x03C5,0x03D6,0x03C9, + 0x03BE,0x03C8,0x03B6,0x007B,0x007C,0x007D,0x223C,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0x20AC,0x03D2,0x2032,0x2264,0x2215,0x221E,0x0192,0x2663, + 0x2666,0x2665,0x2660,0x2194,0x2190,0x2191,0x2192,0x2193, + 0x00B0,0x00B1,0x2033,0x2265,0x00D7,0x221D,0x2202,0x2022, + 0x00F7,0x2260,0x2261,0x2248,0x2026,0x23AF,0x23D0,0x21B5, + 0x2135,0x2111,0x211C,0x2118,0x2297,0x2295,0x2205,0x2229, + 0x222A,0x2283,0x2287,0x2284,0x2282,0x2286,0x2208,0x2209, + 0x2220,0x2207,0xF6DA,0xF6D9,0xF6DB,0x220F,0x221A,0x22C5, + 0x00AC,0x2227,0x2228,0x21D4,0x21D0,0x21D1,0x21D2,0x21D3, + 0x25CA,0x2329,0xF8E8,0xF8E9,0xF8EA,0x2211,0x239B,0x239C, + 0x239D,0x23A1,0x23A2,0x23A3,0x23A7,0x23A8,0x23A9,0x23AA, + 0xFFFF,0x232A,0x222B,0x2320,0x23AE,0x2321,0x239E,0x239F, + 0x23A0,0x23A4,0x23A5,0x23A6,0x23AB,0x23AC,0x23AD,0xFFFF } }, + { RTL_TEXTENCODING_ADOBE_DINGBATS, + { 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, +// 20 + 0x0020,0x2701,0x2702,0x2703,0x2704,0x260E,0x2706,0x2707, + 0x2708,0x2709,0x261B,0x261E,0x270C,0x270D,0x270E,0x270F, + 0x2710,0x2711,0x2712,0x2713,0x2714,0x2715,0x2716,0x2717, + 0x2718,0x2719,0x271A,0x271B,0x271C,0x271D,0x271E,0x271F, +// 40 + 0x2720,0x2721,0x2722,0x2723,0x2724,0x2725,0x2726,0x2727, + 0x2605,0x2729,0x272A,0x272B,0x272C,0x272D,0x272E,0x272F, + 0x2730,0x2731,0x2732,0x2733,0x2734,0x2735,0x2736,0x2737, + 0x2738,0x2739,0x273A,0x273B,0x273C,0x273D,0x273E,0x273F, +// 60 + 0x2740,0x2741,0x2742,0x2743,0x2744,0x2745,0x2746,0x2747, + 0x2748,0x2749,0x274A,0x274B,0x25CF,0x274D,0x25A0,0x274F, + 0x2750,0x2751,0x2752,0x25B2,0x25BC,0x25C6,0x2756,0x25D7, + 0x2758,0x2759,0x275A,0x275B,0x275C,0x275D,0x275E,0xFFFF, +// 80 + 0xF8D7,0xF8D8,0xF8D9,0xF8DA,0xF8DB,0xF8DC,0xF8DD,0xF8DE, + 0xF8DF,0xF8E0,0xF8E1,0xF8E2,0xF8E3,0xF8E4,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, +// A0 + 0xFFFF,0x2761,0x2762,0x2763,0x2764,0x2765,0x2766,0x2767, + 0x2663,0x2666,0x2665,0x2660,0x2460,0x2461,0x2462,0x2463, + 0x2464,0x2465,0x2466,0x2467,0x2468,0x2469,0x2776,0x2777, + 0x2778,0x2779,0x277A,0x277B,0x277C,0x277D,0x277E,0x277F, +// C0 + 0x2780,0x2781,0x2782,0x2783,0x2784,0x2785,0x2786,0x2787, + 0x2788,0x2789,0x278A,0x278B,0x278C,0x278D,0x278E,0x278F, + 0x2790,0x2791,0x2792,0x2793,0x2794,0x2795,0x2796,0x2797, + 0x2798,0x2799,0x279A,0x279B,0x279C,0x279D,0x279E,0x279F, +// E0 + 0x27A0,0x27A1,0x27A2,0x27A3,0x27A4,0x27A5,0x27A6,0x27A7, + 0x27A8,0x27A9,0x27AA,0x27AB,0x27AC,0x27AD,0x27AE,0x27AF, + 0xFFFF,0x27B1,0x27B2,0x27B3,0x27B4,0x27B5,0x27B6,0x27B7, + 0x27B8,0x27B9,0x27BA,0x27BB,0x27BC,0x27BD,0x27BE,0xFFFF } }, + { RTL_TEXTENCODING_PT154, + { 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007, + 0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x000F, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017, + 0x0018,0x0019,0x001A,0x001B,0x001C,0x001D,0x001E,0x001F, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027, + 0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037, + 0x0038,0x0039,0x003A,0x003B,0x003C,0x003D,0x003E,0x003F, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047, + 0x0048,0x0049,0x004A,0x004B,0x004C,0x004D,0x004E,0x004F, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057, + 0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067, + 0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077, + 0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F, + 0x0496,0x0492,0x04EE,0x0493,0x201E,0x2026,0x04B6,0x04AE, + 0x04B2,0x04AF,0x04A0,0x04E2,0x04A2,0x049A,0x04BA,0x04B8, + 0x0497,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014, + 0x04B3,0x04B7,0x04A1,0x04E3,0x04A3,0x049B,0x04BB,0x04B9, + 0x00A0,0x040E,0x045E,0x0408,0x04E8,0x0498,0x04B0,0x00A7, + 0x0401,0x00A9,0x04D8,0x00AB,0x00AC,0x04EF,0x00AE,0x049C, + 0x00B0,0x04B1,0x0406,0x0456,0x0499,0x04E9,0x00B6,0x00B7, + 0x0451,0x2116,0x04D9,0x00BB,0x0458,0x04AA,0x04AB,0x049D, + 0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417, + 0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E,0x041F, + 0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427, + 0x0428,0x0429,0x042A,0x042B,0x042C,0x042D,0x042E,0x042F, + 0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437, + 0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E,0x043F, + 0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447, + 0x0448,0x0449,0x044A,0x044B,0x044C,0x044D,0x044E,0x044F } } }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + testSingleByteCharSet(data[i]); + } +} + +void Test::testComplex() { + static ComplexCharSetTest const data[] + = { { RTL_TEXTENCODING_ASCII_US, + RTL_CONSTASCII_STRINGPARAM("\x01\"3De$~"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E }, + 7, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_EUC_CN, + RTL_CONSTASCII_STRINGPARAM("\x01\"3De$~\xA1\xB9\xF0\xC5"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E, + 0x300D,0x9E4B }, + 9, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_TW, + RTL_CONSTASCII_STRINGPARAM( + "\x01\"3De$~\xC5\xF0\x8E\xA4\xDC\xD9"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E, + 0x4ED9,0xD87E,0xDD68 }, + 10, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_GB_18030, + RTL_CONSTASCII_STRINGPARAM("\x01\"3De$~"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E }, + 7, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_GB_18030, + RTL_CONSTASCII_STRINGPARAM("\x81\x40\xFE\xFE"), + { 0x4E02,0xE4C5 }, + 2, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_GB_18030, + RTL_CONSTASCII_STRINGPARAM( + "\x81\x30\xB1\x33\x81\x30\xD3\x30\x81\x36\xA5\x31"), + { 0x028A,0x0452,0x200F }, + 3, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_GB_18030, + RTL_CONSTASCII_STRINGPARAM( + "\xFE\x50\xFE\x51\xFE\x52\xFE\x53\xFE\x54\xFE\x55\xFE\x56" + "\xFE\x57\xFE\x58\xFE\x59\xFE\x5A\xFE\x5B\xFE\x5C\xFE\x5D" + "\xFE\x5E\xFE\x5F\xFE\x60\xFE\x61\xFE\x62\xFE\x63\xFE\x64" + "\xFE\x65\xFE\x66\xFE\x67\xFE\x68\xFE\x69\xFE\x6A\xFE\x6B" + "\xFE\x6C\xFE\x6D\xFE\x6E\xFE\x6F\xFE\x70\xFE\x71\xFE\x72" + "\xFE\x73\xFE\x74\xFE\x75\xFE\x76\xFE\x77\xFE\x78\xFE\x79" + "\xFE\x7A\xFE\x7B\xFE\x7C\xFE\x7D\xFE\x7E\xFE\x80\xFE\x81" + "\xFE\x82\xFE\x83\xFE\x84\xFE\x85\xFE\x86\xFE\x87\xFE\x88" + "\xFE\x89\xFE\x8A\xFE\x8B\xFE\x8C\xFE\x8D\xFE\x8E\xFE\x8F" + "\xFE\x90\xFE\x91\xFE\x92\xFE\x93\xFE\x94\xFE\x95\xFE\x96" + "\xFE\x97\xFE\x98\xFE\x99\xFE\x9A\xFE\x9B\xFE\x9C\xFE\x9D" + "\xFE\x9E\xFE\x9F\xFE\xA0"), + { 0x2E81,0xE816,0xE817,0xE818,0x2E84,0x3473,0x3447,0x2E88, + 0x2E8B,0xE81E,0x359E,0x361A,0x360E,0x2E8C,0x2E97,0x396E, + 0x3918,0xE826,0x39CF,0x39DF,0x3A73,0x39D0,0xE82B,0xE82C, + 0x3B4E,0x3C6E,0x3CE0,0x2EA7,0xE831,0xE832,0x2EAA,0x4056, + 0x415F,0x2EAE,0x4337,0x2EB3,0x2EB6,0x2EB7,0xE83B,0x43B1, + 0x43AC,0x2EBB,0x43DD,0x44D6,0x4661,0x464C,0xE843,0x4723, + 0x4729,0x477C,0x478D,0x2ECA,0x4947,0x497A,0x497D,0x4982, + 0x4983,0x4985,0x4986,0x499F,0x499B,0x49B7,0x49B6,0xE854, + 0xE855,0x4CA3,0x4C9F,0x4CA0,0x4CA1,0x4C77,0x4CA2,0x4D13, + 0x4D14,0x4D15,0x4D16,0x4D17,0x4D18,0x4D19,0x4DAE,0xE864 }, + 80, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + { RTL_TEXTENCODING_ISO_2022_JP, + RTL_CONSTASCII_STRINGPARAM("\x01\"3De$\\~"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x005C,0x007E }, + 8, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_JP, + RTL_CONSTASCII_STRINGPARAM("\x1B(B\x01\"3De$\\~"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x005C,0x007E }, + 8, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_JP, + RTL_CONSTASCII_STRINGPARAM("\x1B(J\x01\"3De$\\~"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x00A5,0x00AF }, + 8, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_JP, + RTL_CONSTASCII_STRINGPARAM("\x1B$B\x26\x21\x27\x71\x1B(B"), + { 0x0391,0x044F }, + 2, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + { RTL_TEXTENCODING_ISO_2022_KR, + RTL_CONSTASCII_STRINGPARAM("\x1B$)C\x01\"3De$\\~"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x005C,0x007E }, + 8, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_KR, + RTL_CONSTASCII_STRINGPARAM( + "\x1B$)C\x0E\x25\x21\x0F\x0D\x0Ax\x0E\x48\x7E\x0F"), + { 0x2170,0x000D,0x000A,0x0078,0xD79D }, + 5, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_ISO_2022_CN, + RTL_CONSTASCII_STRINGPARAM( + "\x01\"3De$\\~\x1B$)G\x0E\x45\x70\x1B$*H\x1BN\x22\x22" + "\x45\x70\x0F\x1B$)A\x0E\x26\x21\x0F"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x005C,0x007E, + 0x4ED9,0x531F,0x4ED9,0x0391 }, + 12, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_CN, + RTL_CONSTASCII_STRINGPARAM( + "\x01\"3De$\\~\x1B$)A\x0E\x26\x21\x1B$*H\x1BN\x22\x22" + "\x26\x21\x0F\x0D\x0A\x1B$)A\x0E\x26\x21\x0F"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x005C,0x007E, + 0x0391,0x531F,0x0391,0x000D,0x000A,0x0391 }, + 14, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif + // The following does not work as long as Big5-HKSCS maps to + // Unicode PUA instead of Plane 2. Use the next two tests + // instead: +// { RTL_TEXTENCODING_BIG5_HKSCS, +// RTL_CONSTASCII_STRINGPARAM( +// "\x01\"3De$~\x88\x56\xF9\xFE\xFA\x5E\xA1\x40\xF9\xD5"), +// { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E,0x0100, +// 0xFFED,0xD849,0xDD13,0x3000,0x9F98 }, +// 13, +// true, +// true, +// true, +// false, +// RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM( + "\x01\"3De$~\x88\x56\xF9\xFE\xFA\x5E\xA1\x40\xF9\xD5"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E,0x0100, + 0xFFED,0xE01E,0x3000,0x9F98 }, + 12, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM( + "\x01\"3De$~\x88\x56\xF9\xFE\xFA\x5E\xA1\x40\xF9\xD5"), + { 0x0001,0x0022,0x0033,0x0044,0x0065,0x0024,0x007E,0x0100, + 0xFFED,0xD849,0xDD13,0x3000,0x9F98 }, + 13, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM( + "\xC6\xA1\xC6\xCF\xC6\xD3\xC6\xD5\xC6\xD7\xC6\xDE\xC6\xDF" + "\xC6\xFE\xC7\x40\xC7\x7E\xC7\xA1\xC7\xFE"), + { 0x2460,0xF6E0,0xF6E4,0xF6E6,0xF6E8,0xF6EF,0xF6F0,0x3058, + 0x3059,0x30A4,0x30A5,0x041A }, + 12, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM("\x81\x40\x84\xFE"), + { 0xEEB8,0xF12B }, + 2, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM( + "\x81\x40\x8D\xFE\x8E\x40\xA0\xFE\xC6\xA1\xC8\xFE\xFA\x40" + "\xFE\xFE"), + { 0xEEB8,0xF6B0,0xE311,0xEEB7,0xF6B1,0xF848,0xE000,0xE310 }, + 8, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM("\xAD\xC5\x94\x55"), + { 0x5029,0x7250 }, + 2, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM("\xFA\x5F\xA0\xE4"), + { 0x5029,0x7250 }, + 2, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM("\xA0\x40\xA0\x7E\xA0\xA1\xA0\xFE"), + { 0xEE1B,0xEE59,0xEE5A,0xEEB7 }, + 4, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5, + RTL_CONSTASCII_STRINGPARAM("\xA1\x45"), + { 0x2027 }, + 1, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5, + RTL_CONSTASCII_STRINGPARAM( + "\xC6\xCF\xC6\xD3\xC6\xD5\xC6\xD7\xC6\xDE\xC6\xDF"), + { 0x306B,0x306F,0x3071,0x3073,0x307A,0x307B }, + 6, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5, + RTL_CONSTASCII_STRINGPARAM( + "\xC7\xFD\xC7\xFE\xC8\x40\xC8\x7E\xC8\xA1\xC8\xFE"), + { 0xF7AA,0xF7AB,0xF7AC,0xF7EA,0xF7EB,0xF848 }, + 6, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5, + RTL_CONSTASCII_STRINGPARAM("\xA0\x40\xA0\x7E\xA0\xA1\xA0\xFE"), + { 0xEE1B,0xEE59,0xEE5A,0xEEB7 }, + 4, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif + { RTL_TEXTENCODING_MS_950, + RTL_CONSTASCII_STRINGPARAM( + "\xC6\xA1\xC6\xFE\xC7\x40\xC7\x7E\xC7\xA1\xC7\xFE\xC8\x40" + "\xC8\x7E\xC8\xA1\xC8\xFE"), + { 0xF6B1,0xF70E,0xF70F,0xF74D,0xF74E,0xF7AB,0xF7AC,0xF7EA, + 0xF7EB,0xF848 }, + 10, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_MS_950, + RTL_CONSTASCII_STRINGPARAM("\xA0\x40\xA0\x7E\xA0\xA1\xA0\xFE"), + { 0xEE1B,0xEE59,0xEE5A,0xEEB7 }, + 4, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + + // Test Unicode beyond BMP: + + // FIXME The second m_bForward test (requiring a context) does not + // work for UTF7: +// { RTL_TEXTENCODING_UTF7, +// RTL_CONSTASCII_STRINGPARAM("+2EndEw-"), +// { 0xD849,0xDD13 }, +// 2, +// true, +// true, +// true, +// false, +// RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xF0\xA2\x94\x93"), + { 0xD849,0xDD13 }, + 2, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_GB_18030, + RTL_CONSTASCII_STRINGPARAM("\x95\x39\xC5\x37"), + { 0xD849,0xDD13 }, + 2, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_BIG5_HKSCS, + RTL_CONSTASCII_STRINGPARAM("\xFA\x5E"), + { 0xD849,0xDD13 }, + 2, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + + // Test GBK (aka CP936): + + { RTL_TEXTENCODING_GBK, + RTL_CONSTASCII_STRINGPARAM("\xFD\x7C\xC1\xFA\xFD\x9B"), + { 0x9F76,0x9F99,0x9FA5 }, + 3, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif + { RTL_TEXTENCODING_MS_936, + RTL_CONSTASCII_STRINGPARAM("\xFD\x7C\xC1\xFA\xFD\x9B"), + { 0x9F76,0x9F99,0x9FA5 }, + 3, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_GBK, + RTL_CONSTASCII_STRINGPARAM( + "\xFE\x50\xFE\x54\xFE\x55\xFE\x56" + "\xFE\x57\xFE\x58\xFE\x5A\xFE\x5B\xFE\x5C\xFE\x5D" + "\xFE\x5E\xFE\x5F\xFE\x60\xFE\x62\xFE\x63\xFE\x64" + "\xFE\x65\xFE\x68\xFE\x69\xFE\x6A\xFE\x6B" + "\xFE\x6E\xFE\x6F\xFE\x70\xFE\x71\xFE\x72" + "\xFE\x73\xFE\x74\xFE\x75\xFE\x77\xFE\x78\xFE\x79" + "\xFE\x7A\xFE\x7B\xFE\x7C\xFE\x7D\xFE\x80\xFE\x81" + "\xFE\x82\xFE\x83\xFE\x84\xFE\x85\xFE\x86\xFE\x87\xFE\x88" + "\xFE\x89\xFE\x8A\xFE\x8B\xFE\x8C\xFE\x8D\xFE\x8E\xFE\x8F" + "\xFE\x92\xFE\x93\xFE\x94\xFE\x95\xFE\x96" + "\xFE\x97\xFE\x98\xFE\x99\xFE\x9A\xFE\x9B\xFE\x9C\xFE\x9D" + "\xFE\x9E\xFE\x9F"), + { 0x2E81,0x2E84,0x3473,0x3447,0x2E88,0x2E8B,0x359E,0x361A, + 0x360E,0x2E8C,0x2E97,0x396E,0x3918,0x39CF,0x39DF,0x3A73, + 0x39D0,0x3B4E,0x3C6E,0x3CE0,0x2EA7,0x2EAA,0x4056,0x415F, + 0x2EAE,0x4337,0x2EB3,0x2EB6,0x2EB7,0x43B1,0x43AC,0x2EBB, + 0x43DD,0x44D6,0x4661,0x464C,0x4723,0x4729,0x477C,0x478D, + 0x2ECA,0x4947,0x497A,0x497D,0x4982,0x4983,0x4985,0x4986, + 0x499F,0x499B,0x49B7,0x49B6,0x4CA3,0x4C9F,0x4CA0,0x4CA1, + 0x4C77,0x4CA2,0x4D13,0x4D14,0x4D15,0x4D16,0x4D17,0x4D18, + 0x4D19,0x4DAE }, + 66, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("?"), + { 0xFF0D }, + 1, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK }, +#endif + // Test of "JIS X 0208 row 13" (taken from CP932; added to + // ISO-2022-JP and EUC-JP; 74 of the 83 characters introduce + // mappings to new Unicode characters): + { RTL_TEXTENCODING_MS_932, + RTL_CONSTASCII_STRINGPARAM( + "\x87\x40\x87\x41\x87\x42\x87\x43\x87\x44\x87\x45\x87\x46" + "\x87\x47\x87\x48\x87\x49\x87\x4A\x87\x4B\x87\x4C\x87\x4D" + "\x87\x4E\x87\x4F\x87\x50\x87\x51\x87\x52\x87\x53\x87\x54" + "\x87\x55\x87\x56\x87\x57\x87\x58\x87\x59\x87\x5A\x87\x5B" + "\x87\x5C\x87\x5D\x87\x5F\x87\x60\x87\x61\x87\x62\x87\x63" + "\x87\x64\x87\x65\x87\x66\x87\x67\x87\x68\x87\x69\x87\x6A" + "\x87\x6B\x87\x6C\x87\x6D\x87\x6E\x87\x6F\x87\x70\x87\x71" + "\x87\x72\x87\x73\x87\x74\x87\x75\x87\x7E\x87\x80\x87\x81" + "\x87\x82\x87\x83\x87\x84\x87\x85\x87\x86\x87\x87\x87\x88" + "\x87\x89\x87\x8A\x87\x8B\x87\x8C\x87\x8D\x87\x8E\x87\x8F" + "\x87\x90\x87\x91\x87\x92\x87\x93\x87\x94\x87\x95\x87\x96" + "\x87\x97\x87\x98\x87\x99\x87\x9A\x87\x9B\x87\x9C"), + { 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467,0x2468, + 0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F,0x2470,0x2471, + 0x2472,0x2473,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166, + 0x2167,0x2168,0x2169,0x3349,0x3314,0x3322,0x334D,0x3318,0x3327, + 0x3303,0x3336,0x3351,0x3357,0x330D,0x3326,0x3323,0x332B,0x334A, + 0x333B,0x339C,0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x337B, + 0x301D,0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, + 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x2252,0x2261, + 0x222B,0x222E,0x2211,0x221A,0x22A5,0x2220,0x221F,0x22BF,0x2235, + 0x2229,0x222A }, + 83, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + { RTL_TEXTENCODING_SHIFT_JIS, + RTL_CONSTASCII_STRINGPARAM("\x00\xFA\x6F\xFA\x71"), + {0x0000, 0x4F92, 0x4F9A}, + 3, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_SHIFT_JIS, + RTL_CONSTASCII_STRINGPARAM( + "\x87\x40\x87\x41\x87\x42\x87\x43\x87\x44\x87\x45\x87\x46" + "\x87\x47\x87\x48\x87\x49\x87\x4A\x87\x4B\x87\x4C\x87\x4D" + "\x87\x4E\x87\x4F\x87\x50\x87\x51\x87\x52\x87\x53\x87\x54" + "\x87\x55\x87\x56\x87\x57\x87\x58\x87\x59\x87\x5A\x87\x5B" + "\x87\x5C\x87\x5D\x87\x5F\x87\x60\x87\x61\x87\x62\x87\x63" + "\x87\x64\x87\x65\x87\x66\x87\x67\x87\x68\x87\x69\x87\x6A" + "\x87\x6B\x87\x6C\x87\x6D\x87\x6E\x87\x6F\x87\x70\x87\x71" + "\x87\x72\x87\x73\x87\x74\x87\x75\x87\x7E\x87\x80\x87\x81" + "\x87\x82\x87\x83\x87\x84\x87\x85\x87\x86\x87\x87\x87\x88" + "\x87\x89\x87\x8A\x87\x8B\x87\x8C\x87\x8D\x87\x8E\x87\x8F" + "\x87\x90\x87\x91\x87\x92\x87\x93\x87\x94\x87\x95\x87\x96" + "\x87\x97\x87\x98\x87\x99\x87\x9A\x87\x9B\x87\x9C"), + { 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467,0x2468, + 0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F,0x2470,0x2471, + 0x2472,0x2473,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166, + 0x2167,0x2168,0x2169,0x3349,0x3314,0x3322,0x334D,0x3318,0x3327, + 0x3303,0x3336,0x3351,0x3357,0x330D,0x3326,0x3323,0x332B,0x334A, + 0x333B,0x339C,0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x337B, + 0x301D,0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, + 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x2252,0x2261, + 0x222B,0x222E,0x2211,0x221A,0x22A5,0x2220,0x221F,0x22BF,0x2235, + 0x2229,0x222A }, + 83, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_JP, + RTL_CONSTASCII_STRINGPARAM( + "\x1B$B\x2D\x21\x2D\x22\x2D\x23\x2D\x24\x2D\x25\x2D\x26" + "\x2D\x27\x2D\x28\x2D\x29\x2D\x2A\x2D\x2B\x2D\x2C\x2D\x2D" + "\x2D\x2E\x2D\x2F\x2D\x30\x2D\x31\x2D\x32\x2D\x33\x2D\x34" + "\x2D\x35\x2D\x36\x2D\x37\x2D\x38\x2D\x39\x2D\x3A\x2D\x3B" + "\x2D\x3C\x2D\x3D\x2D\x3E\x2D\x40\x2D\x41\x2D\x42\x2D\x43" + "\x2D\x44\x2D\x45\x2D\x46\x2D\x47\x2D\x48\x2D\x49\x2D\x4A" + "\x2D\x4B\x2D\x4C\x2D\x4D\x2D\x4E\x2D\x4F\x2D\x50\x2D\x51" + "\x2D\x52\x2D\x53\x2D\x54\x2D\x55\x2D\x56\x2D\x5F\x2D\x60" + "\x2D\x61\x2D\x62\x2D\x63\x2D\x64\x2D\x65\x2D\x66\x2D\x67" + "\x2D\x68\x2D\x69\x2D\x6A\x2D\x6B\x2D\x6C\x2D\x6D\x2D\x6E" + "\x2D\x6F\x2D\x70\x2D\x71\x2D\x72\x2D\x73\x2D\x74\x2D\x75" + "\x2D\x76\x2D\x77\x2D\x78\x2D\x79\x2D\x7A\x2D\x7B\x2D\x7C" + "\x1B(B"), + { 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467,0x2468, + 0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F,0x2470,0x2471, + 0x2472,0x2473,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166, + 0x2167,0x2168,0x2169,0x3349,0x3314,0x3322,0x334D,0x3318,0x3327, + 0x3303,0x3336,0x3351,0x3357,0x330D,0x3326,0x3323,0x332B,0x334A, + 0x333B,0x339C,0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x337B, + 0x301D,0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, + 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x2252,0x2261, + 0x222B,0x222E,0x2211,0x221A,0x22A5,0x2220,0x221F,0x22BF,0x2235, + 0x2229,0x222A }, + 83, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_2022_JP, + RTL_CONSTASCII_STRINGPARAM( + "\x1B$B\x2D\x21\x2D\x22\x2D\x23\x2D\x24\x2D\x25\x2D\x26" + "\x2D\x27\x2D\x28\x2D\x29\x2D\x2A\x2D\x2B\x2D\x2C\x2D\x2D" + "\x2D\x2E\x2D\x2F\x2D\x30\x2D\x31\x2D\x32\x2D\x33\x2D\x34" + "\x2D\x35\x2D\x36\x2D\x37\x2D\x38\x2D\x39\x2D\x3A\x2D\x3B" + "\x2D\x3C\x2D\x3D\x2D\x3E\x2D\x40\x2D\x41\x2D\x42\x2D\x43" + "\x2D\x44\x2D\x45\x2D\x46\x2D\x47\x2D\x48\x2D\x49\x2D\x4A" + "\x2D\x4B\x2D\x4C\x2D\x4D\x2D\x4E\x2D\x4F\x2D\x50\x2D\x51" + "\x2D\x52\x2D\x53\x2D\x54\x2D\x55\x2D\x56\x2D\x5F\x2D\x60" + "\x2D\x61\x2D\x62\x2D\x63\x2D\x64\x2D\x65\x2D\x66\x2D\x67" + "\x2D\x68\x2D\x69\x2D\x6A\x2D\x6B\x2D\x6C\x2D\x6D\x2D\x6E" + "\x2D\x6F\x2D\x73\x2D\x74\x2D\x78\x2D\x79\x1B(B"), + { 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467,0x2468, + 0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F,0x2470,0x2471, + 0x2472,0x2473,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166, + 0x2167,0x2168,0x2169,0x3349,0x3314,0x3322,0x334D,0x3318,0x3327, + 0x3303,0x3336,0x3351,0x3357,0x330D,0x3326,0x3323,0x332B,0x334A, + 0x333B,0x339C,0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x337B, + 0x301D,0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, + 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x222E,0x2211, + 0x221F,0x22BF }, + 74, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM( + "\xAD\xA1\xAD\xA2\xAD\xA3\xAD\xA4\xAD\xA5\xAD\xA6\xAD\xA7" + "\xAD\xA8\xAD\xA9\xAD\xAA\xAD\xAB\xAD\xAC\xAD\xAD\xAD\xAE" + "\xAD\xAF\xAD\xB0\xAD\xB1\xAD\xB2\xAD\xB3\xAD\xB4\xAD\xB5" + "\xAD\xB6\xAD\xB7\xAD\xB8\xAD\xB9\xAD\xBA\xAD\xBB\xAD\xBC" + "\xAD\xBD\xAD\xBE\xAD\xC0\xAD\xC1\xAD\xC2\xAD\xC3\xAD\xC4" + "\xAD\xC5\xAD\xC6\xAD\xC7\xAD\xC8\xAD\xC9\xAD\xCA\xAD\xCB" + "\xAD\xCC\xAD\xCD\xAD\xCE\xAD\xCF\xAD\xD0\xAD\xD1\xAD\xD2" + "\xAD\xD3\xAD\xD4\xAD\xD5\xAD\xD6\xAD\xDF\xAD\xE0\xAD\xE1" + "\xAD\xE2\xAD\xE3\xAD\xE4\xAD\xE5\xAD\xE6\xAD\xE7\xAD\xE8" + "\xAD\xE9\xAD\xEA\xAD\xEB\xAD\xEC\xAD\xED\xAD\xEE\xAD\xEF" + "\xAD\xF0\xAD\xF1\xAD\xF2\xAD\xF3\xAD\xF4\xAD\xF5\xAD\xF6" + "\xAD\xF7\xAD\xF8\xAD\xF9\xAD\xFA\xAD\xFB\xAD\xFC"), + { 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467,0x2468, + 0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F,0x2470,0x2471, + 0x2472,0x2473,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166, + 0x2167,0x2168,0x2169,0x3349,0x3314,0x3322,0x334D,0x3318,0x3327, + 0x3303,0x3336,0x3351,0x3357,0x330D,0x3326,0x3323,0x332B,0x334A, + 0x333B,0x339C,0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x337B, + 0x301D,0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, + 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x2252,0x2261, + 0x222B,0x222E,0x2211,0x221A,0x22A5,0x2220,0x221F,0x22BF,0x2235, + 0x2229,0x222A }, + 83, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM( + "\xAD\xA1\xAD\xA2\xAD\xA3\xAD\xA4\xAD\xA5\xAD\xA6\xAD\xA7" + "\xAD\xA8\xAD\xA9\xAD\xAA\xAD\xAB\xAD\xAC\xAD\xAD\xAD\xAE" + "\xAD\xAF\xAD\xB0\xAD\xB1\xAD\xB2\xAD\xB3\xAD\xB4\xAD\xB5" + "\xAD\xB6\xAD\xB7\xAD\xB8\xAD\xB9\xAD\xBA\xAD\xBB\xAD\xBC" + "\xAD\xBD\xAD\xBE\xAD\xC0\xAD\xC1\xAD\xC2\xAD\xC3\xAD\xC4" + "\xAD\xC5\xAD\xC6\xAD\xC7\xAD\xC8\xAD\xC9\xAD\xCA\xAD\xCB" + "\xAD\xCC\xAD\xCD\xAD\xCE\xAD\xCF\xAD\xD0\xAD\xD1\xAD\xD2" + "\xAD\xD3\xAD\xD4\xAD\xD5\xAD\xD6\xAD\xDF\xAD\xE0\xAD\xE1" + "\xAD\xE2\xAD\xE3\xAD\xE4\xAD\xE5\xAD\xE6\xAD\xE7\xAD\xE8" + "\xAD\xE9\xAD\xEA\xAD\xEB\xAD\xEC\xAD\xED\xAD\xEE\xAD\xEF" + "\xAD\xF3\xAD\xF4\xAD\xF8\xAD\xF9"), + { 0x2460,0x2461,0x2462,0x2463,0x2464,0x2465,0x2466,0x2467,0x2468, + 0x2469,0x246A,0x246B,0x246C,0x246D,0x246E,0x246F,0x2470,0x2471, + 0x2472,0x2473,0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166, + 0x2167,0x2168,0x2169,0x3349,0x3314,0x3322,0x334D,0x3318,0x3327, + 0x3303,0x3336,0x3351,0x3357,0x330D,0x3326,0x3323,0x332B,0x334A, + 0x333B,0x339C,0x339D,0x339E,0x338E,0x338F,0x33C4,0x33A1,0x337B, + 0x301D,0x301F,0x2116,0x33CD,0x2121,0x32A4,0x32A5,0x32A6,0x32A7, + 0x32A8,0x3231,0x3232,0x3239,0x337E,0x337D,0x337C,0x222E,0x2211, + 0x221F,0x22BF }, + 74, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("\xB9\xF5"), + { 0x9ED2 }, + 1, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif + // Test ISO-8859-x/MS-125x range 0x80--9F: + + { RTL_TEXTENCODING_ISO_8859_1, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_2, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_3, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_4, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_5, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_6, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_7, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_8, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_9, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_14, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISO_8859_15, + RTL_CONSTASCII_STRINGPARAM( + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E" + "\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D" + "\x9E\x9F"), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_MS_874, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1250, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1251, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1252, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1253, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1254, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1255, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1256, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1257, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_1258, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088, + 0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,0x0090,0x0091, + 0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009A, + 0x009B,0x009C,0x009D,0x009E,0x009F }, + 32, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_MS_949, + RTL_CONSTASCII_STRINGPARAM( + "\xB0\xA1\xB0\xA2\x81\x41\x81\x42\xB0\xA3\x81\x43\x81\x44" + "\xB0\xA4\xB0\xA5\xB0\xA6\xB0\xA7\x81\x45\x81\x46\x81\x47" + "\x81\x48\x81\x49\xB0\xA8\xB0\xA9\xB0\xAA\xB0\xAB\xB0\xAC" + "\xB0\xAD\xB0\xAE\xB0\xAF\x81\x4A\xB0\xB0\xB0\xB1\xB0\xB2"), + { 0xAC00,0xAC01,0xAC02,0xAC03,0xAC04,0xAC05,0xAC06,0xAC07,0xAC08, + 0xAC09,0xAC0A,0xAC0B,0xAC0C,0xAC0D,0xAC0E,0xAC0F,0xAC10,0xAC11, + 0xAC12,0xAC13,0xAC14,0xAC15,0xAC16,0xAC17,0xAC18,0xAC19,0xAC1A, + 0xAC1B }, + 28, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_MS_949, + RTL_CONSTASCII_STRINGPARAM( + "\xC9\xA1\xC9\xA2\xC9\xA3\xC9\xFC\xC9\xFD\xC9\xFE" + "\xFE\xA1\xFE\xA2\xFE\xA3\xFE\xFC\xFE\xFD\xFE\xFE"), + { 0xE000,0xE001,0xE002,0xE05B,0xE05C,0xE05D, + 0xE05E,0xE05F,0xE060,0xE0B9,0xE0BA,0xE0BB }, + 12, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + { RTL_TEXTENCODING_EUC_KR, + RTL_CONSTASCII_STRINGPARAM( + "\xB0\xA1\xB0\xA2" "\xB0\xA3" + "\xB0\xA4\xB0\xA5\xB0\xA6\xB0\xA7" + "\xB0\xA8\xB0\xA9\xB0\xAA\xB0\xAB\xB0\xAC" + "\xB0\xAD\xB0\xAE\xB0\xAF" "\xB0\xB0\xB0\xB1\xB0\xB2"), + { 0xAC00,0xAC01, 0xAC04, 0xAC07,0xAC08, + 0xAC09,0xAC0A, 0xAC10,0xAC11, + 0xAC12,0xAC13,0xAC14,0xAC15,0xAC16,0xAC17, 0xAC19,0xAC1A, + 0xAC1B }, + 18, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_KR, + RTL_CONSTASCII_STRINGPARAM( + "\xB0\xA1\xB0\xA2" "\xB0\xA3" + "\xB0\xA4\xB0\xA5\xB0\xA6\xB0\xA7" + "\xB0\xA8\xB0\xA9\xB0\xAA\xB0\xAB\xB0\xAC" + "\xB0\xAD\xB0\xAE\xB0\xAF" "\xB0\xB0\xB0\xB1\xB0\xB2"), + { 0xAC00,0xAC01,0xAC02,0xAC03,0xAC04,0xAC05,0xAC06,0xAC07,0xAC08, + 0xAC09,0xAC0A,0xAC0B,0xAC0C,0xAC0D,0xAC0E,0xAC0F,0xAC10,0xAC11, + 0xAC12,0xAC13,0xAC14,0xAC15,0xAC16,0xAC17,0xAC18,0xAC19,0xAC1A, + 0xAC1B }, + 28, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_EUC_KR, + RTL_CONSTASCII_STRINGPARAM( + "\xC9\xA1\xC9\xA2\xC9\xA3\xC9\xFC\xC9\xFD\xC9\xFE" + "\xFE\xA1\xFE\xA2\xFE\xA3\xFE\xFC\xFE\xFD\xFE\xFE"), + { 0xE000,0xE001,0xE002,0xE05B,0xE05C,0xE05D, + 0xE05E,0xE05F,0xE060,0xE0B9,0xE0BA,0xE0BB }, + 12, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif + // Test UTF-8: + + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\x00"), + { 0x0000 }, + 1, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xEF\xBB\xBF"), + { 0xFEFF }, + 1, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xEF\xBB\xBF\xEF\xBB\xBF"), + { 0xFEFF,0xFEFF }, + 2, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xEF\xBB\xBF"), + { 0 }, + 0, + false, + true, + true, + true, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xEF\xBB\xBF\xEF\xBB\xBF"), + { 0xFEFF }, + 1, + false, + true, + true, + true, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\x01\x02\x7E\x7F"), + { 0x0001,0x0002,0x007E,0x007F }, + 4, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xEF\xBF\xBF"), + {0xFFFF}, + 1, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + + // Test Java UTF-8: + + { RTL_TEXTENCODING_JAVA_UTF8, + RTL_CONSTASCII_STRINGPARAM( + "\xEF\xBB\xBF\xC0\x80\x01\x20\x41\x7F\xED\xA0\x80" + "\xED\xB0\x80"), + { 0xFEFF,0x0000,0x0001,0x0020,0x0041,0x007F,0xD800,0xDC00 }, + 8, + false, + true, + true, + true, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + // Bug #112949#: + { RTL_TEXTENCODING_SHIFT_JIS, + RTL_CONSTASCII_STRINGPARAM("\x81\x63"), + { 0x2026 }, + 1, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_SHIFT_JIS, + RTL_CONSTASCII_STRINGPARAM("\xA0\xFD\xFE\xFF"), + { 0x00A0, 0x00A9, 0x2122, 0x2026 }, + 4, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_SHIFT_JIS, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x00A0, 0x00A9, 0x2122 }, + 3, + false, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, +#endif + { RTL_TEXTENCODING_MS_932, + RTL_CONSTASCII_STRINGPARAM("\x81\x63"), + { 0x2026 }, + 1, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_MS_932, + RTL_CONSTASCII_STRINGPARAM("\xA0\xFD\xFE\xFF"), + { 0x00A0, 0x00A9, 0x2122, 0x2026 }, + 4, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_MS_932, + RTL_CONSTASCII_STRINGPARAM(""), + { 0x00A0, 0x00A9, 0x2122 }, + 3, + false, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE }, + { RTL_TEXTENCODING_APPLE_JAPANESE, + RTL_CONSTASCII_STRINGPARAM("\xA0\xFD\xFE\x81\x63"), + { 0x00A0, 0x00A9, 0x2122, 0x2026 }, + 4, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_APPLE_JAPANESE, + RTL_CONSTASCII_STRINGPARAM("\xFF"), + { 0x2026 }, + 1, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + + { RTL_TEXTENCODING_ADOBE_STANDARD, + RTL_CONSTASCII_STRINGPARAM("\x20\x2D\xA4\xB4\xC5"), + { 0x0020, 0x002D, 0x2215, 0x00B7, 0x00AF }, + 5, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ADOBE_STANDARD, + RTL_CONSTASCII_STRINGPARAM("\x20\x2D\xA4\xB4\xC5"), + { 0x00A0, 0x00AD, 0x2044, 0x2219, 0x02C9 }, + 5, + false, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + + { RTL_TEXTENCODING_ADOBE_SYMBOL, + RTL_CONSTASCII_STRINGPARAM("\x20\x44\x57\x6D\xA4"), + { 0x0020, 0x0394, 0x03A9, 0x03BC, 0x2215 }, + 5, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ADOBE_SYMBOL, + RTL_CONSTASCII_STRINGPARAM("\x20\x44\x57\x6D\xA4"), + { 0x00A0, 0x2206, 0x2126, 0x00B5, 0x2044 }, + 5, + false, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + // Bug #i62310#: + { RTL_TEXTENCODING_SHIFT_JIS, + RTL_CONSTASCII_STRINGPARAM( + "\xF0\x40\xF0\x7E\xF0\x80\xF0\xFC\xF1\x40\xF9\xFC"), + { 0xE000, 0xE03E, 0xE03F, 0xE0BB, 0xE0BC, 0xE757 }, + 6, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif + // Bug #i73103#: + { RTL_TEXTENCODING_MS_1258, + RTL_CONSTASCII_STRINGPARAM( + "\xC0\x41\xDE\xE3\xD2\xD4\xEC\xFD\xF2"), + { 0x00C0, 0x0041, 0x0303, 0x0103, 0x0309, 0x00D4, 0x0301, 0x01B0, + 0x0323 }, + 9, + true, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_MS_1258, + RTL_CONSTASCII_STRINGPARAM( + "\xC0\x41\xDE\xE3\xD2\xD4\xEC\xFD\xF2"), + { 0x00C0, 0x00C3, 0x1EB3, 0x1ED0, 0x1EF1 }, + 5, + false, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#if WITH_LOCALE_ALL || WITH_LOCALE_FOR_SCRIPT_Deva + { RTL_TEXTENCODING_ISCII_DEVANAGARI, + RTL_CONSTASCII_STRINGPARAM( + "\xD7\xE6\x20\xD4\xCF\xE8\xD6\x20" + "\xC8\xD8\xD1\xE1\x20\xB3\xCA\xDC" + "\xCF\xC4\xDA\xD7\x20\xD8\xDB\xA2" + "\xC4\xDE\x20\xB1\xCF\x20\xCC\xDD" + "\xD7\xD1\xCC\xDA\xC6\x20\xC4\xE5" + "\xC6\xE5\xA2\x20\xB3\xE1\x20\xB3" + "\xBD\xE8\xBD\xCF\xC8\xC6\x20\xB3" + "\xE5\x20\xC9\xBD\xB3\xDA\xCF\x20" + "\xB8\xDD\xB3\xE1\x20\xC3\xE1\x20" + "\xEA"), + { 0x0938, 0x094C, 0x0020, 0x0935, 0x0930, 0x094D, 0x0937, 0x0020, + 0x092A, 0x0939, 0x0932, 0x0947, 0x0020, 0x0915, 0x092C, 0x0940, + 0x0930, 0x0926, 0x093E, 0x0938, 0x0020, 0x0939, 0x093F, 0x0902, + 0x0926, 0x0942, 0x0020, 0x0914, 0x0930, 0x0020, 0x092E, 0x0941, + 0x0938, 0x0932, 0x092E, 0x093E, 0x0928, 0x0020, 0x0926, 0x094B, + 0x0928, 0x094B, 0x0902, 0x0020, 0x0915, 0x0947, 0x0020, 0x0915, + 0x091F, 0x094D, 0x091F, 0x0930, 0x092A, 0x0928, 0x0020, 0x0915, + 0x094B, 0x0020, 0x092B, 0x091F, 0x0915, 0x093E, 0x0930, 0x0020, + 0x091A, 0x0941, 0x0915, 0x0947, 0x0020, 0x0925, 0x0947, 0x0020, + 0x0964 }, + 73, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_ISCII_DEVANAGARI, + RTL_CONSTASCII_STRINGPARAM("\xE8\xE8\xE8\xE9\xA1\xE9\xEA\xE9"), + { 0x094D, 0x200C, 0x094D, 0x200D, 0x0950, 0x93D }, + 6, + false, + true, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR } +#endif + }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + doComplexCharSetTest(data[i]); + } +} + +void Test::testComplexCut() { +#if WITH_LOCALE_ALL || WITH_LOCALE_ja || WITH_LOCALE_zh + static ComplexCharSetTest const data[] + = { +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("\x8E"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("\x8F"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("\x8F\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_EUC_CN, + RTL_CONSTASCII_STRINGPARAM("\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, +#endif +/* , + { RTL_TEXTENCODING_EUC_TW, + RTL_CONSTASCII_STRINGPARAM("\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_TW, + RTL_CONSTASCII_STRINGPARAM("\x8E"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_TW, + RTL_CONSTASCII_STRINGPARAM("\x8E\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_EUC_TW, + RTL_CONSTASCII_STRINGPARAM("\x8E\xA1\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR } */ }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + doComplexCharSetCutTest(data[i]); + } +#endif +} + +void Test::testInvalidUtf7() { + auto const converter = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF7); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\x80"), buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL(OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), converted); + rtl_destroyTextToUnicodeConverter(converter); +} + +void Test::testInvalidUtf8() { + // UTF-8, invalid bytes: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\x80\xBF\xFE\xFF"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(4), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD\uFFFD\uFFFD\uFFFD"), + OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(4), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, non-shortest two-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xC0\x80"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(2), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, cut two-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xC0"), buf, + TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(0), size); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL, info); + CPPUNIT_ASSERT(converted <= 1); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, non-shortest three-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xE0\x9F\xBF"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(3), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, cut three-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xE0\x80"), buf, + TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(0), size); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL, info); + CPPUNIT_ASSERT(converted <= 2); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, cut three-byte sequence followed by more: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xE0\x80."), buf, + TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(2), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD."), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(3), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, surrogates: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, + RTL_CONSTASCII_STRINGPARAM("\xED\xA0\x80\xED\xB0\x80"), buf, + TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(2), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(6), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, non-shortest four-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xF0\x8F\xBF\xBF"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(4), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, too-large four-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\xF4\x90\x80\x80"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(4), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, five-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, + RTL_CONSTASCII_STRINGPARAM("\xFB\xBF\xBF\xBF\xBF"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(5), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // UTF-8, six-byte sequence: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, + RTL_CONSTASCII_STRINGPARAM("\xFD\xBF\xBF\xBF\xBF\xBF"), + buf, TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(6), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // Java UTF-8, U+0000: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_JAVA_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\0"), buf, + TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), converted); + rtl_destroyTextToUnicodeConverter(converter); + } + // Java UTF-8, U+10000: + { + auto const converter = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_JAVA_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + OStringLiteral const input(u8"\U00010000"); + sal_Unicode buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertTextToUnicode( + converter, nullptr, input.data, input.size, buf, + TEST_STRING_SIZE, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT + | RTL_TEXTTOUNICODE_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), size); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\uFFFD"), OUString(buf, sal_Int32(size))); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(4), converted); + rtl_destroyTextToUnicodeConverter(converter); + } +} + +void Test::testInvalidUnicode() { + auto const converter = rtl_createUnicodeToTextConverter(RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT(converter != nullptr); + sal_Unicode const input[] = {0xDC00}; // lone low surrogate + char buf[TEST_STRING_SIZE]; + sal_uInt32 info; + sal_Size converted; + auto const size = rtl_convertUnicodeToText( + converter, nullptr, input, SAL_N_ELEMENTS(input), buf, TEST_STRING_SIZE, + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR + | RTL_UNICODETOTEXT_FLAGS_FLUSH), + &info, &converted); + CPPUNIT_ASSERT_EQUAL(sal_Size(0), size); + CPPUNIT_ASSERT_EQUAL(RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_INVALID, info); + CPPUNIT_ASSERT_EQUAL(sal_Size(1), converted); + rtl_destroyTextToUnicodeConverter(converter); +} + +void Test::testSRCBUFFERTOSMALL() { + rtl_TextToUnicodeConverter cv = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_EUC_JP); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeConverter(EUC-JP) failed", + cv != nullptr); + rtl_TextToUnicodeContext cx = rtl_createTextToUnicodeContext(cv); + CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", cx != nullptr); + char src = '\xA1'; + sal_Unicode dst[10]; + sal_uInt32 info; + sal_Size cvt; + CPPUNIT_ASSERT_EQUAL( + sal_Size(0), + rtl_convertTextToUnicode( + cv, cx, &src, 1, dst, SAL_N_ELEMENTS(dst), + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &info, &cvt)); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL, info); + CPPUNIT_ASSERT(cvt <= 1); + rtl_destroyTextToUnicodeContext(cv, cx); + rtl_destroyTextToUnicodeConverter(cv); +} + +void Test::testMime() { + struct Data { + char const * mime; + rtl_TextEncoding encoding; + bool reverse; + }; + static Data const data[] = { + { "GBK", RTL_TEXTENCODING_GBK, false }, + { "CP936", RTL_TEXTENCODING_GBK, false }, + { "MS936", RTL_TEXTENCODING_GBK, false }, + { "windows-936", RTL_TEXTENCODING_GBK, false }, + + { "GB18030", RTL_TEXTENCODING_GB_18030, false }, + + { "TIS-620", RTL_TEXTENCODING_TIS_620, true }, + { "ISO-8859-11", RTL_TEXTENCODING_TIS_620, false }, // not registered + + { "CP874", RTL_TEXTENCODING_MS_874, false }, // not registered + { "MS874", RTL_TEXTENCODING_MS_874, false }, // not registered + { "windows-874", RTL_TEXTENCODING_MS_874, true }, // not registered + + { "ISO_8859-8:1988", RTL_TEXTENCODING_ISO_8859_8, false }, + { "iso-ir-138", RTL_TEXTENCODING_ISO_8859_8, false }, + { "ISO_8859-8", RTL_TEXTENCODING_ISO_8859_8, false }, + { "ISO-8859-8", RTL_TEXTENCODING_ISO_8859_8, true }, + { "hebrew", RTL_TEXTENCODING_ISO_8859_8, false }, + { "csISOLatinHebrew", RTL_TEXTENCODING_ISO_8859_8, false }, + + { "windows-1255", RTL_TEXTENCODING_MS_1255, true }, + + { "IBM862", RTL_TEXTENCODING_IBM_862, true }, + { "cp862", RTL_TEXTENCODING_IBM_862, false }, + { "862", RTL_TEXTENCODING_IBM_862, false }, + { "csPC862LatinHebrew", RTL_TEXTENCODING_IBM_862, false }, + + { "ISO_8859-6:1987", RTL_TEXTENCODING_ISO_8859_6, false }, + { "iso-ir-127", RTL_TEXTENCODING_ISO_8859_6, false }, + { "ISO_8859-6", RTL_TEXTENCODING_ISO_8859_6, false }, + { "ISO-8859-6", RTL_TEXTENCODING_ISO_8859_6, true }, + { "ECMA-114", RTL_TEXTENCODING_ISO_8859_6, false }, + { "ASMO-708", RTL_TEXTENCODING_ISO_8859_6, false }, + { "arabic", RTL_TEXTENCODING_ISO_8859_6, false }, + { "csISOLatinArabic", RTL_TEXTENCODING_ISO_8859_6, false }, + + { "windows-1256", RTL_TEXTENCODING_MS_1256, true }, + + { "IBM864", RTL_TEXTENCODING_IBM_864, true }, + { "cp864", RTL_TEXTENCODING_IBM_864, false }, + { "csIBM864", RTL_TEXTENCODING_IBM_864, false }, + + { "KOI8-R", RTL_TEXTENCODING_KOI8_R, false }, + { "csKOI8R", RTL_TEXTENCODING_KOI8_R, false }, + { "koi8-r", RTL_TEXTENCODING_KOI8_R, true }, + + { "KOI8-U", RTL_TEXTENCODING_KOI8_U, true }, + + { "IBM860", RTL_TEXTENCODING_IBM_860, true }, + { "cp860", RTL_TEXTENCODING_IBM_860, false }, + { "860", RTL_TEXTENCODING_IBM_860, false }, + { "csIBM860", RTL_TEXTENCODING_IBM_860, false }, + + { "IBM861", RTL_TEXTENCODING_IBM_861, true }, + { "cp861", RTL_TEXTENCODING_IBM_861, false }, + { "861", RTL_TEXTENCODING_IBM_861, false }, + { "cp-is", RTL_TEXTENCODING_IBM_861, false }, + { "csIBM861", RTL_TEXTENCODING_IBM_861, false }, + + { "IBM863", RTL_TEXTENCODING_IBM_863, true }, + { "cp863", RTL_TEXTENCODING_IBM_863, false }, + { "863", RTL_TEXTENCODING_IBM_863, false }, + { "csIBM863", RTL_TEXTENCODING_IBM_863, false }, + + { "IBM865", RTL_TEXTENCODING_IBM_865, true }, + { "cp865", RTL_TEXTENCODING_IBM_865, false }, + { "865", RTL_TEXTENCODING_IBM_865, false }, + { "csIBM865", RTL_TEXTENCODING_IBM_865, false }, + + { "Latin-9", RTL_TEXTENCODING_ISO_8859_15, false }, + + { "KS_C_5601-1987", RTL_TEXTENCODING_MS_949, false }, + { "iso-ir-149", RTL_TEXTENCODING_MS_949, false }, + { "KS_C_5601-1989", RTL_TEXTENCODING_MS_949, false }, + { "KSC_5601", RTL_TEXTENCODING_MS_949, false }, + { "korean", RTL_TEXTENCODING_MS_949, false }, + { "csKSC56011987", RTL_TEXTENCODING_MS_949, false }, + { nullptr, RTL_TEXTENCODING_MS_949, true }, + + { "Adobe-Standard-Encoding", RTL_TEXTENCODING_ADOBE_STANDARD, false }, + { "csAdobeStandardEncoding", RTL_TEXTENCODING_ADOBE_STANDARD, false }, + { "Adobe-Symbol-Encoding", RTL_TEXTENCODING_ADOBE_SYMBOL, false }, + { "csHPPSMath", RTL_TEXTENCODING_ADOBE_SYMBOL, false }, + + { "PTCP154", RTL_TEXTENCODING_PT154, true }, + { "csPTCP154", RTL_TEXTENCODING_PT154, false }, + { "PT154", RTL_TEXTENCODING_PT154, false }, + { "CP154", RTL_TEXTENCODING_PT154, false }, + { "Cyrillic-Asian", RTL_TEXTENCODING_PT154, false } + }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + if (data[i].mime == nullptr) { + OSL_ASSERT(data[i].reverse); + CPPUNIT_ASSERT_EQUAL( + static_cast< char const * >(nullptr), + rtl_getMimeCharsetFromTextEncoding(data[i].encoding)); + } else { + CPPUNIT_ASSERT_EQUAL( + data[i].encoding, + rtl_getTextEncodingFromMimeCharset(data[i].mime)); + if (data[i].reverse) { + CPPUNIT_ASSERT_EQUAL( + OString(data[i].mime), + OString( + rtl_getMimeCharsetFromTextEncoding(data[i].encoding))); + } + } + } +} + +void Test::testWindows() { + struct Data { + sal_uInt32 codePage; + rtl_TextEncoding encoding; + bool reverse; + }; + static Data const data[] = { + { 42, RTL_TEXTENCODING_SYMBOL, true }, + { 437, RTL_TEXTENCODING_IBM_437, true }, + { 708, RTL_TEXTENCODING_ISO_8859_6, false }, + { 737, RTL_TEXTENCODING_IBM_737, true }, + { 775, RTL_TEXTENCODING_IBM_775, true }, + { 850, RTL_TEXTENCODING_IBM_850, true }, + { 852, RTL_TEXTENCODING_IBM_852, true }, + { 855, RTL_TEXTENCODING_IBM_855, true }, + { 857, RTL_TEXTENCODING_IBM_857, true }, + { 860, RTL_TEXTENCODING_IBM_860, true }, + { 861, RTL_TEXTENCODING_IBM_861, true }, + { 862, RTL_TEXTENCODING_IBM_862, true }, + { 863, RTL_TEXTENCODING_IBM_863, true }, + { 864, RTL_TEXTENCODING_IBM_864, true }, + { 865, RTL_TEXTENCODING_IBM_865, true }, + { 866, RTL_TEXTENCODING_IBM_866, true }, + { 869, RTL_TEXTENCODING_IBM_869, true }, + { 874, RTL_TEXTENCODING_MS_874, true }, + { 932, RTL_TEXTENCODING_MS_932, true }, + { 936, RTL_TEXTENCODING_MS_936, true }, + { 949, RTL_TEXTENCODING_MS_949, true }, + { 950, RTL_TEXTENCODING_MS_950, true }, + { 1250, RTL_TEXTENCODING_MS_1250, true }, + { 1251, RTL_TEXTENCODING_MS_1251, true }, + { 1252, RTL_TEXTENCODING_MS_1252, true }, + { 1253, RTL_TEXTENCODING_MS_1253, true }, + { 1254, RTL_TEXTENCODING_MS_1254, true }, + { 1255, RTL_TEXTENCODING_MS_1255, true }, + { 1256, RTL_TEXTENCODING_MS_1256, true }, + { 1257, RTL_TEXTENCODING_MS_1257, true }, + { 1258, RTL_TEXTENCODING_MS_1258, true }, + { 1361, RTL_TEXTENCODING_MS_1361, true }, + { 10000, RTL_TEXTENCODING_APPLE_ROMAN, true }, + { 10001, RTL_TEXTENCODING_APPLE_JAPANESE, true }, + { 10002, RTL_TEXTENCODING_APPLE_CHINTRAD, true }, + { 10003, RTL_TEXTENCODING_APPLE_KOREAN, true }, + { 10004, RTL_TEXTENCODING_APPLE_ARABIC, true }, + { 10005, RTL_TEXTENCODING_APPLE_HEBREW, true }, + { 10006, RTL_TEXTENCODING_APPLE_GREEK, true }, + { 10007, RTL_TEXTENCODING_APPLE_CYRILLIC, true }, + { 10008, RTL_TEXTENCODING_APPLE_CHINSIMP, true }, + { 10010, RTL_TEXTENCODING_APPLE_ROMANIAN, true }, + { 10017, RTL_TEXTENCODING_APPLE_UKRAINIAN, true }, + { 10029, RTL_TEXTENCODING_APPLE_CENTEURO, true }, + { 10079, RTL_TEXTENCODING_APPLE_ICELAND, true }, + { 10081, RTL_TEXTENCODING_APPLE_TURKISH, true }, + { 10082, RTL_TEXTENCODING_APPLE_CROATIAN, true }, + { 20127, RTL_TEXTENCODING_ASCII_US, true }, + { 20866, RTL_TEXTENCODING_KOI8_R, true }, + { 21866, RTL_TEXTENCODING_KOI8_U, true }, + { 28591, RTL_TEXTENCODING_ISO_8859_1, true }, + { 28592, RTL_TEXTENCODING_ISO_8859_2, true }, + { 28593, RTL_TEXTENCODING_ISO_8859_3, true }, + { 28594, RTL_TEXTENCODING_ISO_8859_4, true }, + { 28595, RTL_TEXTENCODING_ISO_8859_5, true }, + { 28596, RTL_TEXTENCODING_ISO_8859_6, true }, + { 28597, RTL_TEXTENCODING_ISO_8859_7, true }, + { 28598, RTL_TEXTENCODING_ISO_8859_8, true }, + { 28599, RTL_TEXTENCODING_ISO_8859_9, true }, + { 28605, RTL_TEXTENCODING_ISO_8859_15, true }, + { 50220, RTL_TEXTENCODING_ISO_2022_JP, true }, + { 50225, RTL_TEXTENCODING_ISO_2022_KR, true }, + { 51932, RTL_TEXTENCODING_EUC_JP, true }, + { 51936, RTL_TEXTENCODING_EUC_CN, true }, + { 51949, RTL_TEXTENCODING_EUC_KR, true }, + { 65000, RTL_TEXTENCODING_UTF7, true }, + { 65001, RTL_TEXTENCODING_UTF8, true }, + { 1200, RTL_TEXTENCODING_DONTKNOW, false }, // UTF_16LE + { 1201, RTL_TEXTENCODING_DONTKNOW, false }, // UTF_16LE + { 0, RTL_TEXTENCODING_DONTKNOW, true }, + { 0, RTL_TEXTENCODING_UCS4, true }, + { 0, RTL_TEXTENCODING_UCS2, true }, + { 57002, RTL_TEXTENCODING_ISCII_DEVANAGARI, true } + }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + OSL_ASSERT(data[i].codePage != 0 || data[i].reverse); + if (data[i].codePage != 0) { + CPPUNIT_ASSERT_EQUAL( + data[i].encoding, + rtl_getTextEncodingFromWindowsCodePage(data[i].codePage)); + } + if (data[i].reverse) { + CPPUNIT_ASSERT_EQUAL( + data[i].codePage, + rtl_getWindowsCodePageFromTextEncoding(data[i].encoding)); + } + } +} + +void Test::testInfo() { + struct Data { + rtl_TextEncoding encoding; + sal_uInt32 flag; + bool value; + }; + static Data const data[] = { +#if WITH_LOCALE_ALL || WITH_LOCALE_ja + { RTL_TEXTENCODING_APPLE_JAPANESE, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_EUC_JP, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_INFO_CONTEXT, true }, + { RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_SHIFT_JIS, RTL_TEXTENCODING_INFO_ASCII, false }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_ko + { RTL_TEXTENCODING_APPLE_KOREAN, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_EUC_KR, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_INFO_CONTEXT, true }, + { RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_INFO_ASCII, false }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { RTL_TEXTENCODING_APPLE_CHINTRAD, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_BIG5, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_BIG5_HKSCS, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_EUC_CN, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_EUC_TW, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_GBK, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_GB_18030, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_GB_18030, RTL_TEXTENCODING_INFO_UNICODE, true }, + { RTL_TEXTENCODING_ISO_2022_CN, RTL_TEXTENCODING_INFO_CONTEXT, true }, + { RTL_TEXTENCODING_ISO_2022_CN, RTL_TEXTENCODING_INFO_ASCII, false }, +#endif +#if WITH_LOCALE_ALL || WITH_LOCALE_FOR_SCRIPT_Deva + { RTL_TEXTENCODING_ISCII_DEVANAGARI, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_ISCII_DEVANAGARI, RTL_TEXTENCODING_INFO_MIME, false }, +#endif + { RTL_TEXTENCODING_MS_1361, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_MS_874, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_MS_932, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_MS_936, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_MS_949, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_MS_950, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_KOI8_R, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_KOI8_R, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_KOI8_U, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_KOI8_U, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_IBM_860, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_IBM_861, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_IBM_863, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_IBM_865, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_ADOBE_STANDARD, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_ADOBE_STANDARD, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_ADOBE_STANDARD, RTL_TEXTENCODING_INFO_SYMBOL, false }, + { RTL_TEXTENCODING_ADOBE_SYMBOL, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_ADOBE_SYMBOL, RTL_TEXTENCODING_INFO_MIME, true }, + { RTL_TEXTENCODING_ADOBE_SYMBOL, RTL_TEXTENCODING_INFO_SYMBOL, true }, + { RTL_TEXTENCODING_PT154, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_PT154, RTL_TEXTENCODING_INFO_MIME, true } + }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + rtl_TextEncodingInfo info; + info.StructSize = sizeof info; + CPPUNIT_ASSERT(rtl_getTextEncodingInfo(data[i].encoding, &info)); + CPPUNIT_ASSERT_EQUAL(data[i].value, ((info.Flags & data[i].flag) != 0)); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/uri/rtl_Uri.cxx b/sal/qa/rtl/uri/rtl_Uri.cxx new file mode 100644 index 000000000..81ec98345 --- /dev/null +++ b/sal/qa/rtl/uri/rtl_Uri.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <stdlib.h> +#include <rtl/strbuf.hxx> +#include <rtl/uri.hxx> +#include <osl/thread.h> +#include <osl/file.hxx> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +namespace Stringtest +{ + + class Convert : public CppUnit::TestFixture + { + public: + OString convertToOString(OUString const& _suStr) + { + return OUStringToOString(_suStr, osl_getThreadTextEncoding()/*RTL_TEXTENCODING_ASCII_US*/); + } + + void showContent(OUString const& _suStr) + { + OString sStr = convertToOString(_suStr); + printf("%s\n", sStr.getStr()); + } + + void test_FromUTF8_001() + { + // string --> ustring + OString sStrUTF8("h%C3%A4llo"); + OUString suStrUTF8 = OStringToOUString(sStrUTF8, RTL_TEXTENCODING_ASCII_US); + + // UTF8 --> real ustring + OUString suStr_UriDecodeToIuri = rtl::Uri::decode(suStrUTF8, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8); + showContent(suStr_UriDecodeToIuri); + + // string --> ustring + OString sStr("h\xE4llo", strlen("h\xE4llo")); + OUString suString = OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must be equal", suString, suStr_UriDecodeToIuri); + + // ustring --> ustring (UTF8) + OUString suStr2 = rtl::Uri::encode(suStr_UriDecodeToIuri, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + showContent(suStr2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must be equal", suStr2, suStrUTF8); + // suStr should be equal to suStr2 + } + + CPPUNIT_TEST_SUITE( Convert ); + CPPUNIT_TEST( test_FromUTF8_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; + +} + +CPPUNIT_TEST_SUITE_REGISTRATION( Stringtest::Convert ); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/uri/rtl_testuri.cxx b/sal/qa/rtl/uri/rtl_testuri.cxx new file mode 100644 index 000000000..fc7e1d30a --- /dev/null +++ b/sal/qa/rtl/uri/rtl_testuri.cxx @@ -0,0 +1,514 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config_locales.h> + +#include <rtl/strbuf.hxx> +#include <rtl/uri.hxx> +#include <rtl/ustrbuf.hxx> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <cstddef> +#include <stdio.h> + +namespace { + +struct Test: public CppUnit::TestFixture { + void test_Uri(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test_Uri); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::test_Uri() { + rtl_UriCharClass const eFirstCharClass = rtl_UriCharClassNone; + rtl_UriCharClass const eLastCharClass = rtl_UriCharClassUnoParamValue; + + OUString aText1; + OUString aText2; + + // Check that all characters map back to themselves when encoded/decoded: + + aText1 = OUString( + RTL_CONSTASCII_USTRINGPARAM( + "\x00\x01\x02\x03\x04\x05\x06\x07" + "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + "\x10\x11\x12\x13\x14\x15\x16\x17" + "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" + "\x20\x21\x22\x23\x24\x25\x26\x27" + "\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F" + "\x30\x31\x32\x33\x34\x35\x36\x37" + "\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F" + "\x40\x41\x42\x43\x44\x45\x46\x47" + "\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F" + "\x50\x51\x52\x53\x54\x55\x56\x57" + "\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F" + "\x60\x61\x62\x63\x64\x65\x66\x67" + "\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F" + "\x70\x71\x72\x73\x74\x75\x76\x77" + "\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F")); + aText2 = aText1; + for (rtl_UriCharClass eCharClass = eFirstCharClass; + eCharClass <= eLastCharClass; + eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1)) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 1", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 2", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 3", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 4", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 5", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 6", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)); + } + + aText1 = OUString( + ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" + "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F" + "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F" + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F" + "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F" + "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F" + "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F" + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F" + "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F" + "\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF" + "\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF" + "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF" + "\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF" + "\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF" + "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"), + 256, RTL_TEXTENCODING_ISO_8859_1); + aText2 = aText1; + for (rtl_UriCharClass eCharClass = eFirstCharClass; + eCharClass <= eLastCharClass; + eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1)) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 7", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 8", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 9", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_UTF8), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 10", + aText2, + rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)); + } + + // Check surrogate handling: + + aText1 = u"\xD800" // %ED%A0%80 + u"\U000103FF" // 0xD800,0xDFFF -> %F0%90%8F%BF + u"\xDFFF" // %ED%BF%BF + u"A"; // A + aText2 = "%ED%A0%80" "%F0%90%8F%BF" "%ED%BF%BF" "A"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 11", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_UTF8)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 12", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_UTF8)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 13", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8)); + + aText1 = "%ed%a0%80" "%f0%90%8f%bf" "%ed%bf%bf" "A"; + aText2 = u"%ED%A0%80" u"\U000103FF" u"%ED%BF%BF" u"A"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 14", + aText2, + rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 15", + aText2, + rtl::Uri::decode( + aText1, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)); + + // Check UTF-8 handling: + + aText1 = "%E0%83%BF"; + // \U+00FF encoded with three instead of two bytes + aText2 = aText1; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 16", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8)); + + aText1 = "%EF%BF%BF"; + // \U+FFFF is no legal character + aText2 = aText1; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 17", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8)); + + // Check IURI handling: + + aText1 = "%30%C3%BF"; + aText2 = u"%30\u00FF"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 18", + aText2, + rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8)); + + // Check modified rtl_UriCharClassUnoParamValue (removed '[' and ']'): + + aText1 = "[]%5B%5D"; + aText2 = "%5B%5D%5B%5D"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 19", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUnoParamValue, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ASCII_US)); + + // Check Uri::convertRelToAbs: + + struct RelToAbsTest + { + char const * pBase; + char const * pRel; + char const * pAbs; + }; + static RelToAbsTest const aRelToAbsTest[] + = { // The following tests are taken from RFC 3986: + { "http://a/b/c/d;p?q", "g:h", "g:h" }, + { "http://a/b/c/d;p?q", "g", "http://a/b/c/g" }, + { "http://a/b/c/d;p?q", "./g", "http://a/b/c/g" }, + { "http://a/b/c/d;p?q", "g/", "http://a/b/c/g/" }, + { "http://a/b/c/d;p?q", "/g", "http://a/g" }, + { "http://a/b/c/d;p?q", "//g", "http://g" }, + { "http://a/b/c/d;p?q", "?y", "http://a/b/c/d;p?y" }, + { "http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y" }, + { "http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s" }, + { "http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s" }, + { "http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s" }, + { "http://a/b/c/d;p?q", ";x", "http://a/b/c/;x" }, + { "http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x" }, + { "http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s" }, + { "http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q" }, + { "http://a/b/c/d;p?q", ".", "http://a/b/c/" }, + { "http://a/b/c/d;p?q", "./", "http://a/b/c/" }, + { "http://a/b/c/d;p?q", "..", "http://a/b/" }, + { "http://a/b/c/d;p?q", "../", "http://a/b/" }, + { "http://a/b/c/d;p?q", "../g", "http://a/b/g" }, + { "http://a/b/c/d;p?q", "../..", "http://a/" }, + { "http://a/b/c/d;p?q", "../../", "http://a/" }, + { "http://a/b/c/d;p?q", "../../g", "http://a/g" }, + { "http://a/b/c/d;p?q", "../../../g", "http://a/g" }, + { "http://a/b/c/d;p?q", "../../../../g", "http://a/g" }, + { "http://a/b/c/d;p?q", "/./g", "http://a/g" }, + { "http://a/b/c/d;p?q", "/../g", "http://a/g" }, + { "http://a/b/c/d;p?q", "g.", "http://a/b/c/g." }, + { "http://a/b/c/d;p?q", ".g", "http://a/b/c/.g" }, + { "http://a/b/c/d;p?q", "g..", "http://a/b/c/g.." }, + { "http://a/b/c/d;p?q", "..g", "http://a/b/c/..g" }, + { "http://a/b/c/d;p?q", "./../g", "http://a/b/g" }, + { "http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/" }, + { "http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h" }, + { "http://a/b/c/d;p?q", "g/../h", "http://a/b/c/h" }, + { "http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y" }, + { "http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y" }, + { "http://a/b/c/d;p?q", "g?y/./x", "http://a/b/c/g?y/./x" }, + { "http://a/b/c/d;p?q", "g?y/../x", "http://a/b/c/g?y/../x" }, + { "http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x" }, + { "http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x" }, + { "http://a/b/c/d;p?q", "http:g", "http:g" }, + + { "http!://a/b/c/d;p?q", "g:h", "g:h" }, + { "http!://a/b/c/d;p?q", "g", nullptr }, + { "http:b/c/d;p?q", "g:h", "g:h" }, + { "http:b/c/d;p?q", "g", "http:b/c/g" }, + { "http://a/b/../", "../c", "http://a/c" }, + { "http://a/b/..", "../c", "http://a/c" }, + { "http://a/./b/", ".././.././../c", "http://a/c" }, + { "http://a", "b", "http://a/b" }, + { "", "http://a/b/../c", "http://a/c" }, + + { "http://a/b/c", "d", "http://a/b/d" }, + { "http://a/b/c/", "d", "http://a/b/c/d" }, + { "http://a/b/c//", "d", "http://a/b/c//d" } }; + + for (std::size_t i = 0; i < SAL_N_ELEMENTS(aRelToAbsTest); ++i) + { + OUString aAbs; + bool bMalformed = false; + try { + aAbs = rtl::Uri::convertRelToAbs( + OUString::createFromAscii(aRelToAbsTest[i].pBase), + OUString::createFromAscii(aRelToAbsTest[i].pRel)); + } catch (const rtl::MalformedUriException &) { + bMalformed = true; + } + if (bMalformed + ? aRelToAbsTest[i].pAbs != nullptr + : (aRelToAbsTest[i].pAbs == nullptr + || !aAbs.equalsAscii(aRelToAbsTest[i].pAbs))) + { + printf( + "FAILED convertRelToAbs(%s, %s) -> %s != %s\n", + aRelToAbsTest[i].pBase, aRelToAbsTest[i].pRel, + (bMalformed + ? "<MALFORMED>" + : OUStringToOString( + aAbs, RTL_TEXTENCODING_UTF8).getStr()), + (aRelToAbsTest[i].pAbs == nullptr + ? "<MALFORMED>" : aRelToAbsTest[i].pAbs)); + CPPUNIT_ASSERT(false); + } + } + + // Check encode with unusual text encodings: + + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x045F, 0 }; + aText1 = OUString(aText1U); + aText2 = "%20!%A1%FF"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 20", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_ISO_8859_5)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 20a", + aText1, + rtl::Uri::decode( + aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)); + } + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; + aText1 = OUString(aText1U); + sal_Unicode const aText2U[] = { + '%', '2', '0', '!', '%', 'A', '1', 0x0700, '%', 'F', 'F', 0 }; + aText2 = OUString(aText2U); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 21", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_ISO_8859_5)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 21a", + aText1, + rtl::Uri::decode( + aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { + sal_Unicode const aText1U[] = { ' ', '!', 0x028A, 0xD849, 0xDD13, 0 }; + aText1 = OUString(aText1U); + aText2 = "%20!%81%30%B1%33%95%39%C5%37"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 22", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_GB_18030)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 22a", + aText1, + rtl::Uri::decode( + aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030)); + } +#endif + // Check strict mode: + + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; + aText1 = OUString(aText1U); + aText2 = OUString(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 23", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict, + RTL_TEXTENCODING_ISO_8859_5)); + } + { + aText1 = "%20%C4%80%FF"; + aText2 = OUString(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 24", + aText2, + rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8)); + } +#if WITH_LOCALE_ALL || WITH_LOCALE_zh + { + aText1 = "%81 "; + aText2 = OUString(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 25", + aText2, + rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)); + } + { + aText1 = "%81%20"; + aText2 = OUString(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 26", + aText2, + rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)); + } + { + aText1 = "%81%30%B1%33"; + sal_Unicode const aText2U[] = { 0x028A, 0 }; + aText2 = OUString(aText2U); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 27", + aText2, + rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)); + } + { + aText1 = "%810%B13"; + sal_Unicode const aText2U[] = { 0x028A, 0 }; + aText2 = OUString(aText2U); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 28", + aText2, + rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)); + } +#endif + // Check rtl_UriEncodeStrictKeepEscapes mode: + + { + aText1 = "%%ea%c3%aa"; + aText2 = "%25%EA%C3%AA"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 29", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, + RTL_TEXTENCODING_UTF8)); + } + { + sal_Unicode const aText1U[] = { 0x00EA, 0 }; + aText1 = OUString(aText1U); + aText2 = "%C3%AA"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 30", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, + RTL_TEXTENCODING_UTF8)); + } + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; + aText1 = OUString(aText1U); + aText2 = OUString(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "failure 23", + aText2, + rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, + RTL_TEXTENCODING_ISO_8859_5)); + } +} + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/uuid/rtl_Uuid.cxx b/sal/qa/rtl/uuid/rtl_Uuid.cxx new file mode 100644 index 000000000..b77e84afe --- /dev/null +++ b/sal/qa/rtl/uuid/rtl_Uuid.cxx @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <math.h> +#include <stdio.h> +#include <string.h> + +#include <rtl/uuid.h> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#elif defined UNX +#include <unistd.h> +#include <time.h> +#endif + + +namespace rtl_Uuid +{ +class createUuid : public CppUnit::TestFixture +{ +public: +#define TEST_UUID 20 + void createUuid_001() + { + sal_uInt8 aNode[TEST_UUID][16]; + sal_Int32 i,i2; + for( i = 0 ; i < TEST_UUID ; i ++ ) + { + rtl_createUuid( aNode[i], nullptr, false ); + } + bool bRes = true; + for( i = 0 ; i < TEST_UUID ; i ++ ) + { + for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ ) + { + if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 ) + { + bRes = false; + break; + } + } + if ( !bRes ) + break; + } + CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes); + } + /* + void createUuid_002() + { + sal_uInt8 pNode[16]; + sal_uInt8 aNode[TEST_UUID][16]; + sal_Int32 i,i2; + for( i = 0 ; i < TEST_UUID ; i ++ ) + { + rtl_createUuid( aNode[i], pNode, sal_True ); + } + sal_Bool bRes = sal_True; + for( i = 0 ; i < TEST_UUID ; i ++ ) + { + //printUuid( aNode[i] ); + for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ ) + { + if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 ) + { + bRes = sal_False; + break; + } + } + if ( bRes == sal_False ) + break; + } + CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True ); + }*/ + + CPPUNIT_TEST_SUITE(createUuid); + CPPUNIT_TEST(createUuid_001); + //CPPUNIT_TEST(createUuid_002); + CPPUNIT_TEST_SUITE_END(); +}; // class createUuid + +class createNamedUuid : public CppUnit::TestFixture +{ +public: + void createNamedUuid_001() + { + sal_uInt8 NameSpace_DNS[16] = RTL_UUID_NAMESPACE_DNS; + sal_uInt8 NameSpace_URL[16] = RTL_UUID_NAMESPACE_URL; + sal_uInt8 pPriorCalculatedUUID[16] = { + 0x52,0xc9,0x30,0xa5, + 0xd1,0x61,0x3b,0x16, + 0x98,0xc5,0xf8,0xd1, + 0x10,0x10,0x6d,0x4d }; + + sal_uInt8 pNamedUUID[16], pNamedUUID2[16]; + + // Same name does generate the same uuid + rtl_String *pName = nullptr; + rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Name" ); + rtl_createNamedUuid( pNamedUUID , NameSpace_DNS , pName ); + rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName ); + CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) == 0 ); + CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pPriorCalculatedUUID , 16 ) ); + + // Different names does not generate the same uuid + rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Namf" ); + rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName ); + CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID , pNamedUUID2 , 16 ) ); + + // the same name with different namespace uuid produces different uuids + rtl_createNamedUuid( pNamedUUID , NameSpace_URL , pName ); + CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) != 0); + + //test compareUuid + if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 ) + { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0); + } + else + CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) > 0); + + rtl_string_release( pName ); + } + + CPPUNIT_TEST_SUITE(createNamedUuid); + CPPUNIT_TEST(createNamedUuid_001); + CPPUNIT_TEST_SUITE_END(); +}; // class createNamedUuid + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createUuid); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createNamedUuid); +} // namespace rtl_Uuid + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/sal/test_types.cxx b/sal/qa/sal/test_types.cxx new file mode 100644 index 000000000..f863247b6 --- /dev/null +++ b/sal/qa/sal/test_types.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cstddef> +#include <stdio.h> +#include <string.h> + +#include <sal/types.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +namespace { + +template< typename T > void testPrintf( + char const * result, char const * format, T argument) +{ + std::size_t const bufsize = 1000; + char buf[bufsize]; + int n = snprintf(buf, bufsize, format, argument); + CPPUNIT_ASSERT(n >= 0 && sal::static_int_cast< unsigned int >(n) < bufsize); + CPPUNIT_ASSERT_EQUAL(0, strcmp(buf, result)); +} + +class Test: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::test() { + testPrintf("-2147483648", "%" SAL_PRIdINT32, SAL_MIN_INT32); + testPrintf("4294967295", "%" SAL_PRIuUINT32, SAL_MAX_UINT32); + testPrintf("ffffffff", "%" SAL_PRIxUINT32, SAL_MAX_UINT32); + testPrintf("FFFFFFFF", "%" SAL_PRIXUINT32, SAL_MAX_UINT32); + testPrintf("-9223372036854775808", "%" SAL_PRIdINT64, SAL_MIN_INT64); + testPrintf("18446744073709551615", "%" SAL_PRIuUINT64, SAL_MAX_UINT64); + testPrintf("ffffffffffffffff", "%" SAL_PRIxUINT64, SAL_MAX_UINT64); + testPrintf("FFFFFFFFFFFFFFFF", "%" SAL_PRIXUINT64, SAL_MAX_UINT64); + testPrintf("123", "%" SAL_PRI_SIZET "u", static_cast< std::size_t >(123)); + testPrintf( + "-123", "%" SAL_PRI_PTRDIFFT "d", static_cast< std::ptrdiff_t >(-123)); + testPrintf("-123", "%" SAL_PRIdINTPTR, static_cast< sal_IntPtr >(-123)); + testPrintf("123", "%" SAL_PRIuUINTPTR, static_cast< sal_uIntPtr >(123)); + testPrintf("abc", "%" SAL_PRIxUINTPTR, static_cast< sal_uIntPtr >(0xabc)); + testPrintf("ABC", "%" SAL_PRIXUINTPTR, static_cast< sal_uIntPtr >(0xabc)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/systools/test_comtools.cxx b/sal/qa/systools/test_comtools.cxx new file mode 100644 index 000000000..694a4a665 --- /dev/null +++ b/sal/qa/systools/test_comtools.cxx @@ -0,0 +1,239 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <systools/win32/comtools.hxx> + +namespace { + +class COMObject : public IUnknown +{ +public: + COMObject() : ref_count_(0) + { + } + + virtual ~COMObject() + { + } + + ULONG __stdcall AddRef() override + { + ref_count_++; + return ref_count_; + } + + ULONG __stdcall Release() override + { + ULONG cnt = --ref_count_; + if (cnt == 0) + delete this; + return cnt; + } + + HRESULT __stdcall QueryInterface(REFIID riid, void** ppv) override + { + if (riid == IID_IUnknown) + { + AddRef(); + *ppv = this; + return S_OK; + } + return E_NOINTERFACE; + } + + ULONG GetRefCount() const + { + return ref_count_; + } + +private: + ULONG ref_count_; +}; + +} + +static sal::systools::COMReference<IUnknown> comObjectSource() +{ + return sal::systools::COMReference<IUnknown>(new COMObject); +} + +static bool comObjectSink(sal::systools::COMReference<IUnknown> r, ULONG expectedRefCountOnReturn) +{ + r = sal::systools::COMReference<IUnknown>(); + COMObject* p = reinterpret_cast<COMObject*>(r.get()); + if (p) + return (p->GetRefCount() == expectedRefCountOnReturn); + else + return (0 == expectedRefCountOnReturn); +} + +static void comObjectSource2(LPVOID* ppv) +{ + COMObject* p = new COMObject; + p->AddRef(); + *ppv = p; +} + +namespace test_comtools +{ + + class test_COMReference : public CppUnit::TestFixture + { + + public: + /// test of COMReference<IUnknown> r; + void default_ctor() + { + sal::systools::COMReference<IUnknown> r; + CPPUNIT_ASSERT_EQUAL_MESSAGE("COMReference should be empty", static_cast<IUnknown *>(nullptr), r.get()); + } + + void test_ctor_manual_AddRef() + { + COMObject* p = new COMObject; + p->AddRef(); + sal::systools::COMReference<IUnknown> r(p, false); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + } + + void test_copy_ctor() + { + sal::systools::COMReference<IUnknown> r(comObjectSource()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + } + + void test_copy_assignment() + { + sal::systools::COMReference<IUnknown> r; + CPPUNIT_ASSERT_EQUAL_MESSAGE("COMReference should be empty", static_cast<IUnknown *>(nullptr), r.get()); + + r = comObjectSource(); + CPPUNIT_ASSERT_MESSAGE("COMReference should be empty", r.get() != nullptr); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + } + + void test_ref_to_ref_assignment() + { + sal::systools::COMReference<IUnknown> r1 = comObjectSource(); + sal::systools::COMReference<IUnknown> r2 = r1; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 2 is expected", ULONG(2), reinterpret_cast<COMObject*>(r2.get())->GetRefCount()); + } + + void test_pointer_to_ref_assignment() + { + sal::systools::COMReference<IUnknown> r; + r = new COMObject; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + } + + void test_pointer_to_ref_assignment2() + { + sal::systools::COMReference<IUnknown> r = comObjectSource(); + r = new COMObject; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + } + + void test_source_sink() + { + CPPUNIT_ASSERT_MESSAGE("Wrong reference count, 0 is expected", comObjectSink(comObjectSource(), 0)); + } + + void test_address_operator() + { + sal::systools::COMReference<IUnknown> r; + comObjectSource2(reinterpret_cast<LPVOID*>(&r)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count, 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + } + + void test_address_operator2() + { + sal::systools::COMReference<IUnknown> r1 = comObjectSource(); + sal::systools::COMReference<IUnknown> r2 = r1; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 2 is expected", ULONG(2), reinterpret_cast<COMObject*>(r2.get())->GetRefCount()); + comObjectSource2(reinterpret_cast<LPVOID*>(&r1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r1.get())->GetRefCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r2.get())->GetRefCount()); + } + + void test_clear() + { + sal::systools::COMReference<IUnknown> r = comObjectSource(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count 1 is expected", ULONG(1), reinterpret_cast<COMObject*>(r.get())->GetRefCount()); + r.clear(); + CPPUNIT_ASSERT_MESSAGE("Expect reference to be empty", !r.is()); + } + + void test_query_interface() + { + try + { + sal::systools::COMReference<IUnknown> r1 = comObjectSource(); + sal::systools::COMReference<IUnknown> r2 = r1.QueryInterface<IUnknown>(IID_IUnknown); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count, 2 is expected", ULONG(2), reinterpret_cast<COMObject*>(r2.get())->GetRefCount()); + } + catch(const sal::systools::ComError&) + { + CPPUNIT_ASSERT_MESSAGE("Exception should not have been thrown", false); + } + } + + void test_query_interface_throw() + { + try + { + sal::systools::COMReference<IUnknown> r1 = comObjectSource(); + sal::systools::COMReference<IPersistFile> r2 = r1.QueryInterface<IPersistFile>(IID_IPersistFile); + } + catch(const sal::systools::ComError&) + { + return; + } + CPPUNIT_ASSERT_MESSAGE("Exception should have been thrown", false); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(test_COMReference); + CPPUNIT_TEST(default_ctor); + CPPUNIT_TEST(test_ctor_manual_AddRef); + CPPUNIT_TEST(test_copy_ctor); + CPPUNIT_TEST(test_copy_assignment); + CPPUNIT_TEST(test_ref_to_ref_assignment); + CPPUNIT_TEST(test_pointer_to_ref_assignment); + CPPUNIT_TEST(test_pointer_to_ref_assignment2); + CPPUNIT_TEST(test_source_sink); + CPPUNIT_TEST(test_address_operator); + CPPUNIT_TEST(test_address_operator2); + CPPUNIT_TEST(test_clear); + CPPUNIT_TEST(test_query_interface); + CPPUNIT_TEST(test_query_interface_throw); + CPPUNIT_TEST_SUITE_END(); + }; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_comtools::test_COMReference); + +} // namespace rtl_OUString + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |