diff options
Diffstat (limited to 'sal/qa')
172 files changed, 81670 insertions, 0 deletions
diff --git a/sal/qa/ByteSequence/ByteSequence.cxx b/sal/qa/ByteSequence/ByteSequence.cxx new file mode 100644 index 000000000000..f1105298deaf --- /dev/null +++ b/sal/qa/ByteSequence/ByteSequence.cxx @@ -0,0 +1,610 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ByteSequence.cxx,v $ + * $Revision: 1.13 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <Byte_Const.h> +#include <rtl/byteseq.h> + +#include <rtl/byteseq.hxx> + +#include <testshl/simpleheader.hxx> + +using namespace rtl; + +namespace rtl_ByteSequence +{ + +//------------------------------------------------------------------------ +// testing constructors +//------------------------------------------------------------------------ + +class ctor : public CppUnit::TestFixture + { + public: + + void ctor_001() + { + ::rtl::ByteSequence aByteSeq1; + ::rtl::ByteSequence aByteSeq2( &kTestEmptyByteSeq ); + CPPUNIT_ASSERT_MESSAGE + ( + "Creates an empty sequence", + aByteSeq1.getLength() == 0 && + aByteSeq1 == aByteSeq2 + ); + } + + void ctor_002() + { + ::rtl::ByteSequence aByteSeq; + ::rtl::ByteSequence aByteSeqtmp( aByteSeq ); + CPPUNIT_ASSERT_MESSAGE + ( + "Creates a copy of given sequence", + aByteSeq == aByteSeqtmp + ); + + } + + void ctor_003() + { + ::rtl::ByteSequence aByteSeq( &kTestByteSeq1 ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Copy constructor Creates a copy from the C-Handle ", + nNewLen == kTestSeqLen1 + ); + } + + void ctor_003_1() + { + ::rtl::ByteSequence aByteSeq( &kTestByteSeq2 ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Copy constructor Creates a copy from the C-Handle: reference count > 1 ", + nNewLen == kTestSeqLen2 + ); + } + + void ctor_004() + { + sal_Int8 * pElements = &kTestByte4; + sal_Int32 len = kTestByteCount1; + ::rtl::ByteSequence aByteSeq( pElements, len); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Creates a copy of given data bytes", + aByteSeq[1] == pElements[1] && + len == nNewLen + + ); + } + + void ctor_005() + { + sal_Int32 len = 50; + ::rtl::ByteSequence aByteSeq( len ); + sal_Int32 nNewLen = aByteSeq.getLength(); + sal_Bool res = sal_True; + for (sal_Int32 i=0; i<len; i++) + { + if (aByteSeq[i] != 0) + res = sal_False; + } + CPPUNIT_ASSERT_MESSAGE + ( + "Creates sequence of given length and initializes all bytes to 0", + nNewLen == len && res + + ); + } + + void ctor_006() + { + sal_Int32 len = 39; + ::rtl::ByteSequence aByteSeq( len , BYTESEQ_NODEFAULT ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Creates sequence of given length and does NOT initialize data", + nNewLen == len + + ); + } + + void ctor_007() + { + ::rtl::ByteSequence aByteSeq( &kTestByteSeq3, BYTESEQ_NOACQUIRE ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Creates a sequence from a C-Handle without acquiring the handle, thus taking over ownership", + nNewLen == kTestSeqLen3 + ); + } + + CPPUNIT_TEST_SUITE(ctor); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST(ctor_003); + CPPUNIT_TEST(ctor_003_1); + CPPUNIT_TEST(ctor_004); + CPPUNIT_TEST(ctor_005); + CPPUNIT_TEST(ctor_006); + CPPUNIT_TEST(ctor_007); + CPPUNIT_TEST_SUITE_END(); + }; + +class assign : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void assign_001() + { + sal_Int32 len = kTestByteCount1; + sal_Int32 len2 = len - 1; + sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq1( kTestByte5, len); + ::rtl::ByteSequence aByteSeq2( pElements, len2); + aByteSeq2 = aByteSeq1; + sal_Int32 nNewLen = aByteSeq2.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Assignment operator: assign longer sequence to another", + aByteSeq1 == aByteSeq2 && + nNewLen == len + ); + } + + void assign_002() + { + sal_Int32 len = kTestByteCount1 - 1 ; + ::rtl::ByteSequence aByteSeq1( len ); + sal_Int8 * pElements = &kTestByte1; + ::rtl::ByteSequence aByteSeq2( pElements, len + 1); + aByteSeq2 = aByteSeq1; + sal_Int32 nNewLen = aByteSeq2.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Assignment operator: assign shorter sequence to another", + aByteSeq1 == aByteSeq2 && + nNewLen == len + ); + } + + void assign_003() + { + sal_Int32 len = kTestByteCount1 - 1 ; + const sal_Int8 * pElements = &kTestByte2; + ::rtl::ByteSequence aByteSeq1( pElements, len + 1 ); + ::rtl::ByteSequence aByteSeq2( len, BYTESEQ_NODEFAULT ); + aByteSeq2 = aByteSeq1; + sal_Int32 nNewLen = aByteSeq2.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Assignment operator: assign sequence to another sequence having no data initialized", + aByteSeq1 == aByteSeq2 && + nNewLen == kTestByteCount1 + ); + } + + void assign_004() + { + ::rtl::ByteSequence aByteSeq1; + sal_Int32 len = kTestByteCount1 ; + const sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq2( pElements, len); + aByteSeq2 = aByteSeq1; + sal_Int32 nNewLen = aByteSeq2.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Assignment operator: assign empty sequence to another not empty sequence", + aByteSeq1 == aByteSeq2 && + nNewLen == 0 + ); + } + + CPPUNIT_TEST_SUITE(assign); + CPPUNIT_TEST(assign_001); + CPPUNIT_TEST(assign_002); + CPPUNIT_TEST(assign_003); + CPPUNIT_TEST(assign_004); + CPPUNIT_TEST_SUITE_END(); +}; // class operator= + + +class equal : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void equal_001() + { + sal_Int32 len = kTestByteCount1 ; + sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq1( pElements, len-1); + ::rtl::ByteSequence aByteSeq2( pElements, len); + sal_Bool res = aByteSeq1 == aByteSeq2; + CPPUNIT_ASSERT_MESSAGE + ( + "Equality operator: compare two sequences 1", + !res + ); + } + + void equal_002() + { + sal_Int32 len = kTestByteCount1 ; + const sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq1( pElements, len); + ::rtl::ByteSequence aByteSeq2( pElements, len); + sal_Bool res = aByteSeq1 == aByteSeq2; + CPPUNIT_ASSERT_MESSAGE + ( + "Equality operator: compare two sequences 2", + res + ); + } + + void equal_003() + { + sal_Int32 len = kTestByteCount1 ; + const sal_Int8 * pElements = kTestByte5; + ::rtl::ByteSequence aByteSeq1( pElements, len); + pElements = kTestByte6; + ::rtl::ByteSequence aByteSeq2( pElements, len); + sal_Bool res = aByteSeq1 == aByteSeq2; + CPPUNIT_ASSERT_MESSAGE + ( + "Equality operator: compare two sequences 2", + !res + ); + } + CPPUNIT_TEST_SUITE(equal); + CPPUNIT_TEST(equal_001); + CPPUNIT_TEST(equal_002); + CPPUNIT_TEST(equal_003); + CPPUNIT_TEST_SUITE_END(); +}; // class equal + + +class notequal : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void notequal_001() + { + sal_Int32 len = kTestByteCount1 ; + const sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq1( pElements, len-1); + ::rtl::ByteSequence aByteSeq2( pElements, len); + sal_Bool res = aByteSeq1 != aByteSeq2; + CPPUNIT_ASSERT_MESSAGE + ( + "Equality operator: compare two sequences 1", + res + ); + } + + void notequal_002() + { + sal_Int32 len = kTestByteCount1 ; + const sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq1( pElements, len); + ::rtl::ByteSequence aByteSeq2( pElements, len); + sal_Bool res = aByteSeq1 != aByteSeq2; + CPPUNIT_ASSERT_MESSAGE + ( + "Equality operator: compare two sequences 2", + !res + ); + } + + CPPUNIT_TEST_SUITE(notequal); + CPPUNIT_TEST(notequal_001); + CPPUNIT_TEST(notequal_002); + CPPUNIT_TEST_SUITE_END(); +}; // class notequal + + +class getArray : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getArray_001() + { + sal_Int32 len = kTestByteCount1 ; + sal_Int8 * pElements = &kTestByte; + ::rtl::ByteSequence aByteSeq1( pElements, len); + sal_Int8 * pArray = aByteSeq1.getArray(); + sal_Bool res = sal_True; + for (sal_Int32 i = 0; i < len; i++) + { + if (pElements[i] != pArray[i]) + res = sal_False; + } + CPPUNIT_ASSERT_MESSAGE + ( + "Gets the pointer to byte array: one element sequence", + res == sal_True + ); + } + + void getArray_002() + { + sal_Int8 * pElements = kTestByte6; + ::rtl::ByteSequence aByteSeq(pElements, 5); + sal_Int8 * pArray = aByteSeq.getArray(); + sal_Bool res = sal_True; + for (sal_Int32 i = 0; i < 5; i++) + { + if (pElements[i] != pArray[i]) + res = sal_False; + } + CPPUNIT_ASSERT_MESSAGE + ( + "Gets the pointer to byte array: more elements sequence", + res == sal_True + ); + } + + CPPUNIT_TEST_SUITE(getArray); + CPPUNIT_TEST(getArray_001); + CPPUNIT_TEST(getArray_002); + CPPUNIT_TEST_SUITE_END(); +}; // class getArray + + +class realloc : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void realloc_001() + { + ::rtl::ByteSequence aByteSeq; + sal_Int32 nSize = 20; + aByteSeq.realloc( nSize ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Reallocates sequence to new length: empty sequence", + nNewLen == nSize + ); + } + + void realloc_002() + { + //reference count > 1 + ::rtl::ByteSequence aByteSeq( &kTestByteSeq2 ); //34 + sal_Int32 nSize = 20; + aByteSeq.realloc( nSize ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Reallocates sequence: reference count > 1 && nSize < nElements", + nNewLen == nSize + ); + } + + void realloc_003() + { + //reference count > 1 + ::rtl::ByteSequence aByteSeq( &kTestByteSeq2 ); //34 + sal_Int32 nSize = kTestSeqLen2 + 5; + sal_Int32 nElements = kTestSeqLen2; + aByteSeq.realloc( nSize ); + sal_Int32 nNewLen = aByteSeq.getLength(); + sal_Bool res = sal_True; + for (int i = nSize; i < nElements; i++) + { + sal_Int8 nValue = aByteSeq[i]; + if (nValue != 0) + res = sal_False; + } + CPPUNIT_ASSERT_MESSAGE + ( + "Reallocates sequence: reference count > 1 && nSize > nElements", + nNewLen == nSize + && res == sal_True + ); + } + + void realloc_004() + { + sal_Int8 * pElements = &kTestByte3; + sal_Int32 len = kTestByteCount3; + ::rtl::ByteSequence aByteSeq( pElements, len); + sal_Int32 nSize = kTestByteCount3 - 10 ; + aByteSeq.realloc( nSize ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Reallocates sequence: nSize < nElements", + nNewLen == nSize + ); + } + + void realloc_005() + { + sal_Int8 * pElements = kTestByte6; + sal_Int32 len = 4; + ::rtl::ByteSequence aByteSeq( pElements, len); + sal_Int32 nSize = len + 10 ; + aByteSeq.realloc( nSize ); + sal_Int32 nNewLen = aByteSeq.getLength(); + CPPUNIT_ASSERT_MESSAGE + ( + "Reallocates sequence: nSize > nElements", + nNewLen == nSize + ); + } + + CPPUNIT_TEST_SUITE(realloc); + CPPUNIT_TEST(realloc_001); + CPPUNIT_TEST(realloc_002); + CPPUNIT_TEST(realloc_003); + CPPUNIT_TEST(realloc_004); + CPPUNIT_TEST(realloc_005); + //CPPUNIT_TEST(realloc_006); + CPPUNIT_TEST_SUITE_END(); +}; // class realloc + + +class getData : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getData_001() + { + sal_Int8 * pElements = kTestByte5; + ::rtl::ByteSequence aByteSeq(pElements, 4); + sal_Bool res = sal_True; + if (aByteSeq[0] != kTestByte) + res = sal_False; + + if (aByteSeq[1] != kTestByte1) + res = sal_False; + + if (aByteSeq[2] != kTestByte2) + res = sal_False; + + if (aByteSeq[3] != kTestByte3) + res = sal_False; + + CPPUNIT_ASSERT_MESSAGE + ( + "Obtains a reference to byte indexed at given position: empty sequence", + res == sal_True + ); + } + + void getData_002() + { + ::rtl::ByteSequence aByteSeq( &kTestByteSeq2 ); + sal_Int8 nValue = aByteSeq[0]; + CPPUNIT_ASSERT_MESSAGE + ( + "Obtains a reference to byte indexed at given position: reference count > 1", + nValue == kTestChar2 //not sure what is right,hehe + ); + } + + void getData_003() + { + ::rtl::ByteSequence aByteSeq( &kTestByteSeq3 ); + sal_Int8 nValue = aByteSeq[0]; + CPPUNIT_ASSERT_MESSAGE + ( + "Obtains a reference to byte indexed at given position: reference count = 1", + nValue == kTestChar3 //not sure what is right,hehe + ); + } + + CPPUNIT_TEST_SUITE(getData); + CPPUNIT_TEST(getData_001); + CPPUNIT_TEST(getData_002); + CPPUNIT_TEST(getData_003); + CPPUNIT_TEST_SUITE_END(); +}; // class getData + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::ctor, "rtl_ByteSequence"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::assign, "rtl_ByteSequence"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::equal, "rtl_ByteSequence"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::notequal, "rtl_ByteSequence"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::getArray, "rtl_ByteSequence"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::realloc, "rtl_ByteSequence"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ByteSequence::getData, "rtl_ByteSequence"); +} // namespace ByteSequence + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/ByteSequence/Byte_Const.h b/sal/qa/ByteSequence/Byte_Const.h new file mode 100644 index 000000000000..2d167b7d673c --- /dev/null +++ b/sal/qa/ByteSequence/Byte_Const.h @@ -0,0 +1,95 @@ +#ifndef _BYTE_CONST_H_ +#define _BYTE_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#include <sal/types.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +extern "C" +{ +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +const sal_Int32 kTestByteCount1 = 7; +const sal_Int32 kTestByteCount2 = 0; +const sal_Int32 kTestByteCount3 = 45; +const sal_Int32 kTestByteCount4 = 100; +const sal_Int32 kTestByteCount5 = 23; +const sal_Int32 kTestByteCount6 = 90; + + +sal_Int8 kTestByte = 100; +sal_Int8 kTestByte1 = 0; +sal_Int8 kTestByte2 = 1; +sal_Int8 kTestByte3 = 2; +sal_Int8 kTestByte4 = -98; + +sal_Int8 kTestByte5[] = {kTestByte, kTestByte1, kTestByte2, kTestByte3, kTestByte4}; + +sal_Int8 kTestByte60 = 56; +sal_Int8 kTestByte61 = -1; +sal_Int8 kTestByte62 = -23; +sal_Int8 kTestByte63 = 21; +sal_Int8 kTestByte64 = -128; +sal_Int8 kTestByte65 = 127; +sal_Int8 kTestByte6[] = {kTestByte60, kTestByte61, kTestByte62, kTestByte63, kTestByte64, kTestByte65}; + +//------------------------------------------------------------------------ + +char kTestChar = 45; +char kTestChar0 = 0; + char kTestChar1 = (char)((500 & 0xff) - 256); +char kTestChar2 = 78; + char kTestChar3 = (char)(-155 & 0xff); + +sal_Int32 kTestSeqLen0 = 0; +sal_Int32 kTestSeqLen1 = 5; +sal_Int32 kTestSeqLen2 = 34; +sal_Int32 kTestSeqLen3 = 270; + +sal_Sequence kTestEmptyByteSeq = +{ + 1, /* sal_Int32 refCount; */ + kTestSeqLen0, /* sal_Int32 length; */ + { kTestChar0 } /* sal_Unicode buffer[1]; */ +}; + +sal_Sequence kTestByteSeq1 = +{ + 1, /* sal_Int32 refCount; */ + kTestSeqLen1, /* sal_Int32 length; */ + { kTestChar1 } /* sal_Unicode buffer[1]; */ +}; + +sal_Sequence kTestByteSeq2 = +{ + 3, /* sal_Int32 refCount; */ + kTestSeqLen2, /* sal_Int32 length; */ + { kTestChar2 } /* sal_Unicode buffer[1]; */ +}; + +sal_Sequence kTestByteSeq3 = +{ + 2, /* sal_Int32 refCount; */ + kTestSeqLen3, /* sal_Int32 length; */ + { kTestChar3 } /* sal_Unicode buffer[1]; */ +}; + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +} +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#endif /* _BYTE_CONST_H_ */ + + diff --git a/sal/qa/ByteSequence/export.exp b/sal/qa/ByteSequence/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/ByteSequence/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/ByteSequence/makefile.mk b/sal/qa/ByteSequence/makefile.mk new file mode 100644 index 000000000000..0f1b88ac6e6a --- /dev/null +++ b/sal/qa/ByteSequence/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.13 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=sal +TARGET=qa_bytesequence +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +#----------------------------------- OStringBuffer ----------------------------------- + +SHL1OBJS= \ + $(SLO)$/ByteSequence.obj + +SHL1TARGET= rtl_ByteSequence +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# --- BEGIN -------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/rtl_old_testbyteseq.obj +SHL2TARGET= rtl_old_testbyteseq +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) + +DEF2NAME =$(SHL2TARGET) +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map +# END -------------------------------------------------------------- + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/ByteSequence/rtl_old_testbyteseq.cxx b/sal/qa/ByteSequence/rtl_old_testbyteseq.cxx new file mode 100644 index 000000000000..2cea6fa3a878 --- /dev/null +++ b/sal/qa/ByteSequence/rtl_old_testbyteseq.cxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_old_testbyteseq.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx +// ----------------------------------------------------------------------------- + +#include <stdio.h> + +// #include <osl/diagnose.h> +#include <rtl/byteseq.hxx> + +using namespace ::rtl; + +#include <testshl/simpleheader.hxx> + + +namespace rtl_testbyteseq +{ + +// ----------------------------------------------------------------------------- + +class oldbyteseq : public CppUnit::TestFixture +{ +public: + void test_bytesequence_001(); + + CPPUNIT_TEST_SUITE( oldbyteseq ); + CPPUNIT_TEST( test_bytesequence_001 ); + CPPUNIT_TEST_SUITE_END( ); +}; + +// ----------------------------------------------------------------------------- + +void oldbyteseq::test_bytesequence_001() +{ + signed char a[5] = { 1 , 2 , 3 , 4 , 5 }; + + // test the c++ wrapper + { + ByteSequence seq; + OSL_ENSURE( ! seq.getLength() , "" ); + + ByteSequence seq2( a , 5 ); + + OSL_ENSURE( !( seq == seq2) , "" ); + + seq = seq2; + OSL_ENSURE( seq == seq2 , "" ); + + seq[0] = 2; + OSL_ENSURE( !(seq == seq2) , "" ); + + seq = ByteSequence( a , 5 ); + OSL_ENSURE( seq == seq2 , "" ); + + seq = ByteSequence( 5 ); // default value is 0 for each byte + OSL_ENSURE( !( seq == seq2 ) , "" ); + } + + { + sal_Sequence *pSeq = 0; + rtl_byte_sequence_construct( &pSeq , 0 ); + + // implementation dependent test. + OSL_ENSURE( pSeq->nRefCount == 2 , "invalid refcount for empty sequence" ); + + sal_Sequence *pSeq2 = 0; + rtl_byte_sequence_constructFromArray( &pSeq2 , a , 5 ); + + OSL_ENSURE( ! rtl_byte_sequence_equals( pSeq , pSeq2 ) , "" ); + + rtl_byte_sequence_assign( &pSeq , pSeq2 ); + OSL_ENSURE( pSeq == pSeq2 , "" ); + OSL_ENSURE( rtl_byte_sequence_equals( pSeq , pSeq2 ) , "" ); + + rtl_byte_sequence_reference2One( &pSeq ); + (( sal_Int8*) rtl_byte_sequence_getConstArray( pSeq ) )[0] = 2; + + OSL_ENSURE( ! rtl_byte_sequence_equals( pSeq , pSeq2 ) , "" ); + + rtl_byte_sequence_constructFromArray( &pSeq , a , 5 ); + OSL_ENSURE( rtl_byte_sequence_equals( pSeq , pSeq2 ) , "" ); + + rtl_byte_sequence_construct( &pSeq , 5 ); + OSL_ENSURE( ! rtl_byte_sequence_equals( pSeq , pSeq2 ) , "" ); + + + + rtl_byte_sequence_release( pSeq2 ); + rtl_byte_sequence_release( pSeq ); + } + + + printf( "test bytesequence OK\n" ); + +} + +} // namespace osl_test_file + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_testbyteseq::oldbyteseq, "rtl_ByteSequence" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; diff --git a/sal/qa/OStringBuffer/export.exp b/sal/qa/OStringBuffer/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/OStringBuffer/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/OStringBuffer/makefile.mk b/sal/qa/OStringBuffer/makefile.mk new file mode 100644 index 000000000000..d20c011a552e --- /dev/null +++ b/sal/qa/OStringBuffer/makefile.mk @@ -0,0 +1,77 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.13 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=sal +TARGET=qa_ostringbuffer +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES= \ +# $(SLO)$/OStringBuffer.obj + +#----------------------------------- OStringBuffer ----------------------------------- + +SHL1OBJS= \ + $(SLO)$/rtl_OStringBuffer.obj \ + $(SLO)$/rtl_String_Utils.obj + +SHL1TARGET= rtl_OStringBuffer +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx new file mode 100644 index 000000000000..2b3bbfd6caa3 --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx @@ -0,0 +1,18473 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OStringBuffer.cxx,v $ + * $Revision: 1.17 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// ----------------------------------------------------------------------------- +#include <rtl/string.hxx> +#include <rtl_String_Const.h> +#include <rtl_String_Utils.hxx> + +#include <rtl/strbuf.hxx> + +#include <testshl/simpleheader.hxx> + +using namespace rtl; + +//------------------------------------------------------------------------ +// test classes +//------------------------------------------------------------------------ +// const MAXBUFLENGTH = 255; +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +//------------------------------------------------------------------------ +// testing constructors +//------------------------------------------------------------------------ + +// LLA: there exist some #if WITH_CORE #endif envelopes, which contain test code, which will core dump +// due to the fact, that we can't handle MAXINT32 right. + +namespace rtl_OStringBuffer +{ + class ctors : public CppUnit::TestFixture + { + public: + + void ctor_001() + { + ::rtl::OStringBuffer aStrBuf; + const sal_Char* pStr = aStrBuf.getStr(); + + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters", + aStrBuf.getLength() == 0 && + *pStr == '\0' && aStrBuf.getCapacity() == 16 + ); + } + + void ctor_002() + { + ::rtl::OString aStrtmp( kTestStr1 ); + ::rtl::OStringBuffer aStrBuftmp( aStrtmp ); + ::rtl::OStringBuffer aStrBuf( aStrBuftmp ); + // sal_Bool res = cmpstr(aStrBuftmp.getStr(),aStrBuf.getStr()); + + sal_Int32 nLenStrBuftmp = aStrBuftmp.getLength(); + + rtl::OString sStr(aStrBuftmp.getStr()); + sal_Bool res = aStrtmp.equals( sStr ); + + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer from another OStringBuffer", + aStrBuf.getLength() == nLenStrBuftmp && + aStrBuf.getCapacity() == aStrBuftmp.getCapacity() && + res + ); + + } + + void ctor_003() + { + ::rtl::OStringBuffer aStrBuf1(kTestStr2Len); +#ifdef WITH_CORE + ::rtl::OStringBuffer aStrBuf2(kSInt32Max); //will core dump + // LLA: will core, due to the fact, that ksint32max is too big, the max length can't + // use, because there are some internal bytes, which we can't calculate. + +#else + ::rtl::OStringBuffer aStrBuf2(0); +#endif + + const sal_Char* pStr1 = aStrBuf1.getStr(); + const sal_Char* pStr2 = aStrBuf2.getStr(); + +#ifdef WITH_CORE + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + aStrBuf1.getLength() == 0 && + ! *(aStrBuf1.getStr()) && aStrBuf1.getCapacity() == kTestStr2Len && + aStrBuf2.getLength() == 0 && + ! *(aStrBuf2.getStr()) && aStrBuf2.getCapacity() == kSInt32Max + + ); +#else + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + aStrBuf1.getLength() == 0 && + *pStr1 == '\0' && + aStrBuf1.getCapacity() == kTestStr2Len && + aStrBuf2.getLength() == 0 && + *pStr2 == '\0' && + aStrBuf2.getCapacity() == 0 + ); +#endif + + } + + void ctor_003_1() + { + // LLA: StringBuffer with created negativ size are the same as empty StringBuffers + ::rtl::OStringBuffer aStrBuf3(kNonSInt32Max); + + const sal_Char* pStr = aStrBuf3.getStr(); + + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer containing no characters and contain assigned capacity", + aStrBuf3.getLength() == 0 && + *pStr == '\0' && + aStrBuf3.getCapacity() == kNonSInt32Max + ); + } + + void ctor_004() + { + ::rtl::OString aStrtmp( kTestStr1 ); + ::rtl::OStringBuffer aStrBuf( aStrtmp ); + sal_Int32 leg = aStrBuf.getLength(); + + CPPUNIT_ASSERT_MESSAGE + ( + "New OStringBuffer from Ostring", + aStrBuf.getStr() == aStrtmp && + leg == aStrtmp.pData->length && + aStrBuf.getCapacity() == leg+16 + + ); + } + + void ctor_005() { + rtl::OStringBuffer b1; + b1.makeStringAndClear(); + rtl::OStringBuffer b2(b1); + } + + CPPUNIT_TEST_SUITE(ctors); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST(ctor_003); + CPPUNIT_TEST(ctor_003_1); + CPPUNIT_TEST(ctor_004); + CPPUNIT_TEST(ctor_005); + CPPUNIT_TEST_SUITE_END(); + }; + + + +// ----------------------------------------------------------------------------- + + class makeStringAndClear : public CppUnit::TestFixture + { + OString* arrOUS[6]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr1 ); + arrOUS[1] = new OString( kTestStr14 ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( kTestStr27 ); + arrOUS[4] = new OString( kTestStr29 ); + arrOUS[5] = new OString( "\0" ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; delete arrOUS[5]; + } + + void makeStringAndClear_001() + { + ::rtl::OStringBuffer aStrBuf1; + ::rtl::OString aStr1; + + sal_Bool lastRes = (aStrBuf1.makeStringAndClear() == aStr1 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "two empty strings(def. constructor)", + lastRes && ( aStrBuf1.getCapacity() == 0 ) && + ( *(aStrBuf1.getStr()) == '\0' ) + ); + + } + + void makeStringAndClear_002() + { + ::rtl::OStringBuffer aStrBuf2(26); + ::rtl::OString aStr2; + + sal_Bool lastRes = (aStrBuf2.makeStringAndClear() == aStr2 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "two empty strings(with a argu)", + lastRes && ( aStrBuf2.getCapacity() == 0 ) && + ( *(aStrBuf2.getStr()) == '\0' ) + ); + + } + + void makeStringAndClear_003() + { + ::rtl::OStringBuffer aStrBuf3(*arrOUS[0]); + ::rtl::OString aStr3(*arrOUS[0]); + + sal_Bool lastRes = (aStrBuf3.makeStringAndClear() == aStr3 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "normal string", + lastRes && ( aStrBuf3.getCapacity() == 0 ) && + ( *(aStrBuf3.getStr()) == '\0' ) + ); + + } + + void makeStringAndClear_004() + { + ::rtl::OStringBuffer aStrBuf4(*arrOUS[1]); + ::rtl::OString aStr4(*arrOUS[1]); + + sal_Bool lastRes = (aStrBuf4.makeStringAndClear() == aStr4 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string with space ", + lastRes && ( aStrBuf4.getCapacity() == 0 ) && + ( *(aStrBuf4.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_005() + { + ::rtl::OStringBuffer aStrBuf5(*arrOUS[2]); + ::rtl::OString aStr5(*arrOUS[2]); + + sal_Bool lastRes = (aStrBuf5.makeStringAndClear() == aStr5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "empty string", + lastRes && ( aStrBuf5.getCapacity() == 0 ) && + ( *(aStrBuf5.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_006() + { + ::rtl::OStringBuffer aStrBuf6(*arrOUS[3]); + ::rtl::OString aStr6(*arrOUS[3]); + + sal_Bool lastRes = (aStrBuf6.makeStringAndClear() == aStr6 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string with a character", + lastRes && ( aStrBuf6.getCapacity() == 0 ) && + ( *(aStrBuf6.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_007() + { + ::rtl::OStringBuffer aStrBuf7(*arrOUS[4]); + ::rtl::OString aStr7(*arrOUS[4]); + + sal_Bool lastRes = (aStrBuf7.makeStringAndClear() == aStr7 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "string with special characters", + lastRes && ( aStrBuf7.getCapacity() == 0 ) && + ( *(aStrBuf7.getStr()) == '\0' ) + ); + } + + void makeStringAndClear_008() + { + ::rtl::OStringBuffer aStrBuf8(*arrOUS[5]); + ::rtl::OString aStr8(*arrOUS[5]); + + sal_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 getLength : public CppUnit::TestFixture + { + OString* arrOUS[6]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr1 ); + arrOUS[1] = new OString( "1" ); + arrOUS[2] = new OString( ); + arrOUS[3] = new OString( "" ); + arrOUS[4] = new OString( "\0" ); + arrOUS[5] = new OString( kTestStr2 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; delete arrOUS[5]; + } + + void getLength_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal = kTestStr1Len; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of ascii string", + aStrBuf.getLength() == expVal + ); + + } + + void getLength_002() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 expVal = 1; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of ascci string of size 1", + aStrBuf.getLength() == expVal + ); + } + + void getLength_003() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of empty string", + aStrBuf.getLength() == expVal + ); + } + + void getLength_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of empty string (empty ascii string arg)", + aStrBuf.getLength() == expVal + ); + } + + void getLength_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of empty string (string arg = '\\0')", + aStrBuf.getLength() == expVal + ); + } + + void getLength_006() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal = kTestStr2Len; + + CPPUNIT_ASSERT_MESSAGE + ( + "length(>16) of ascii string", + aStrBuf.getLength() == expVal + ); + } + + void getLength_007() + { + ::rtl::OStringBuffer aStrBuf; + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of empty string (default constructor)", + aStrBuf.getLength()== expVal + ); + } + + void getLength_008() + { + ::rtl::OStringBuffer aStrBuf( 26 ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "length of empty string (with capacity)", + aStrBuf.getLength()== expVal + ); + } + + 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() + { + arrOUS[0] = new OString( kTestStr1 ); + arrOUS[1] = new OString( "1" ); + arrOUS[2] = new OString( ); + arrOUS[3] = new OString( "" ); + arrOUS[4] = new OString( "\0" ); + arrOUS[5] = new OString( kTestStr2 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; delete arrOUS[5]; + } + + void getCapacity_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal = kTestStr1Len+16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of ascii string", + aStrBuf.getCapacity()== expVal + ); + + } + + void getCapacity_002() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 expVal = 1+16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of ascci string of size 1", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_003() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 expVal = 0+16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 expVal = 0+16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (empty ascii string arg)", + aStrBuf.getCapacity()== expVal + ); + } + + void getCapacity_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Int32 expVal = 0+16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (string arg = '\\0')", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_006() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal = kTestStr2Len+16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity(>16) of ascii string", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_007() + { + ::rtl::OStringBuffer aStrBuf; + sal_Int32 expVal = 16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (default constructor)", + aStrBuf.getCapacity() == expVal + ); + } +#ifdef WITH_CORE + void getCapacity_008() + { + ::rtl::OStringBuffer aStrBuf ( kSInt32Max ); + sal_Int32 expVal = kSInt32Max; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (with capacity 2147483647)(code will core dump)", + aStrBuf.getCapacity() == expVal + ); + } +#endif + void getCapacity_009() + { + ::rtl::OStringBuffer aStrBuf( kNonSInt32Max ); + sal_Int32 expVal = kNonSInt32Max; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (with capacity -2147483648)", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_010() + { + ::rtl::OStringBuffer aStrBuf( 16 ); + sal_Int32 expVal = 16; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (with capacity 16)", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_011() + { + ::rtl::OStringBuffer aStrBuf( 6 ); + sal_Int32 expVal = 6; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (with capacity 6)", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_012() + { + ::rtl::OStringBuffer aStrBuf( 0 ); + sal_Int32 expVal = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (with capacity 0)", + aStrBuf.getCapacity() == expVal + ); + } + + void getCapacity_013() + { + ::rtl::OStringBuffer aStrBuf( -2 ); + sal_Int32 expVal = -2; + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity of empty string (with capacity -2)", + aStrBuf.getCapacity() == expVal + ); + } + + 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 ); +#ifdef WITH_CORE + CPPUNIT_TEST( getCapacity_008 ); +#endif + CPPUNIT_TEST( getCapacity_009 ); + CPPUNIT_TEST( getCapacity_010 ); + CPPUNIT_TEST( getCapacity_011 ); + CPPUNIT_TEST( getCapacity_012 ); + CPPUNIT_TEST( getCapacity_013 ); + CPPUNIT_TEST_SUITE_END(); + }; +// ----------------------------------------------------------------------------- + + class ensureCapacity : public CppUnit::TestFixture + { + void ensureCapacity_001() + { + sal_Int32 expVal = 16; + ::rtl::OStringBuffer aStrBuf; + sal_Int32 input = 5; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 16, minimum is 5", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_002() + { + sal_Int32 expVal = 16; + ::rtl::OStringBuffer aStrBuf; + sal_Int32 input = -5; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 16, minimum is -5", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_003() + { + sal_Int32 expVal = 16; + ::rtl::OStringBuffer aStrBuf; + sal_Int32 input = 0; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 16, minimum is 0", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_004() //the testcase is based on comments + { + sal_Int32 expVal = 20; + ::rtl::OStringBuffer aStrBuf; + sal_Int32 input = 20; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 16, minimum is 20", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_005() + { + sal_Int32 expVal = 50; + ::rtl::OStringBuffer aStrBuf; + sal_Int32 input = 50; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 16, minimum is 50", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_006() + { + sal_Int32 expVal = 20; + ::rtl::OStringBuffer aStrBuf( 6 ); + sal_Int32 input = 20; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 6, minimum is 20", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_007() + { + sal_Int32 expVal = 6; + ::rtl::OStringBuffer aStrBuf( 6 ); + sal_Int32 input = 2; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 6, minimum is 2", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_008() + { + sal_Int32 expVal = 6; + ::rtl::OStringBuffer aStrBuf( 6 ); + sal_Int32 input = -6; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 6, minimum is -6", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_009() //the testcase is based on comments + { + sal_Int32 expVal = 10; + ::rtl::OStringBuffer aStrBuf( 6 ); + sal_Int32 input = 10; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 6, minimum is -6", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_010() + { + sal_Int32 expVal = 6; + ::rtl::OStringBuffer aStrBuf( 0 ); + sal_Int32 input = 6; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 0, minimum is 6", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_011() //the testcase is based on comments + { + sal_Int32 expVal = 2; // capacity is x = (str->length + 1) * 2; minimum < x ? x : minimum + ::rtl::OStringBuffer aStrBuf( 0 ); + sal_Int32 input = 1; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 0, minimum is 1", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_012() + { + sal_Int32 expVal = 0; + ::rtl::OStringBuffer aStrBuf( 0 ); + sal_Int32 input = -1; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 0, minimum is -1", + aStrBuf.getCapacity() == expVal + ); + + } +#ifdef WITH_CORE + void ensureCapacity_013() //will core dump + { + sal_Int32 expVal = kSInt32Max; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Int32 input = 65535; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 2147483647, minimum is 65535", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_014() //will core dump + { + sal_Int32 expVal = kSInt32Max; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Int32 input = kSInt32Max; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 2147483647, minimum is 2147483647", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_015() //will core dump + { + sal_Int32 expVal = kSInt32Max; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Int32 input = -1; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 2147483647, minimum is -1", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_016() //will core dump + { + sal_Int32 expVal = kSInt32Max; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Int32 input = 0; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 2147483647, minimum is 0", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_017() //will core dump + { + sal_Int32 expVal = kSInt32Max; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Int32 input = kNonSInt32Max; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to 2147483647, minimum is -2147483648", + aStrBuf.getCapacity() == expVal + ); + + } +#endif + void ensureCapacity_018() + { + sal_Int32 expVal = 65535; + ::rtl::OStringBuffer aStrBuf( kNonSInt32Max ); + sal_Int32 input = 65535; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to -2147483648, minimum is 65535", + aStrBuf.getCapacity() == expVal + ); + + } +#ifdef WITH_CORE + void ensureCapacity_019() //will core dump + { + sal_Int32 expVal = 2147483647; + ::rtl::OStringBuffer aStrBuf( kNonSInt32Max ); + sal_Int32 input = 2147483647; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to -2147483648, minimum is 2147483647", + aStrBuf.getCapacity() == expVal + ); + + } +#endif + void ensureCapacity_020() + { + sal_Int32 expVal = 2; + ::rtl::OStringBuffer aStrBuf( kNonSInt32Max ); + sal_Int32 input = -1; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to -2147483648, minimum is -1", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_021() + { + sal_Int32 expVal = 2; + ::rtl::OStringBuffer aStrBuf( kNonSInt32Max ); + sal_Int32 input = 0; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to -2147483648, minimum is 0", + aStrBuf.getCapacity() == expVal + ); + + } + + void ensureCapacity_022() + { + sal_Int32 expVal = kNonSInt32Max; + ::rtl::OStringBuffer aStrBuf( kNonSInt32Max ); + sal_Int32 input = kNonSInt32Max; + + aStrBuf.ensureCapacity( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "capacity equal to -2147483648, minimum is -2147483648", + aStrBuf.getCapacity() == expVal + ); + + } + + 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 ); +#ifdef WITH_CORE + CPPUNIT_TEST( ensureCapacity_013 ); + CPPUNIT_TEST( ensureCapacity_014 ); + CPPUNIT_TEST( ensureCapacity_015 ); + CPPUNIT_TEST( ensureCapacity_016 ); + CPPUNIT_TEST( ensureCapacity_017 ); +#endif + CPPUNIT_TEST( ensureCapacity_018 ); +#ifdef WITH_CORE + CPPUNIT_TEST( ensureCapacity_019 ); +#endif + CPPUNIT_TEST( ensureCapacity_020 ); + CPPUNIT_TEST( ensureCapacity_021 ); + CPPUNIT_TEST( ensureCapacity_022 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// ----------------------------------------------------------------------------- + + class setLength : public CppUnit::TestFixture + { + OString* arrOUS[6]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr1 ); + arrOUS[1] = new OString( "1" ); + arrOUS[2] = new OString( ); + arrOUS[3] = new OString( "" ); + arrOUS[4] = new OString( "\0" ); + arrOUS[5] = new OString( kTestStr2 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; delete arrOUS[5]; + } + + void setLength_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal1 = 50; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal1 = kTestStr13Len; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal1 = kTestStr1Len; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal1 = kTestStr7Len; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 expVal1 = 0; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 expVal1 = 25; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 expVal1 = kTestStr27Len; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 expVal1 = 0; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 expVal1 = 20; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 expVal1 = 3; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 expVal1 = 0; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 expVal1 = 20; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 expVal1 = 5; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 expVal1 = 0; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Int32 expVal1 = 20; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Int32 expVal1 = 5; + ::rtl::OString expVal2; + sal_Int32 expVal3 = 16; + 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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Int32 expVal1 = 0; + ::rtl::OString expVal2; + sal_Int32 expVal3 = 16; + 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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal1 = 50; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal1 = 40; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal1 = kTestStr2Len; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal1 = kTestStr7Len; + ::rtl::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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[5] ); + sal_Int32 expVal1 = 0; + ::rtl::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 charAt : public CppUnit::TestFixture + { + OString* arrOUS[4]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr1 ); + arrOUS[1] = new OString( kTestStr27 ); + arrOUS[2] = new OString( kTestStr28 ); + arrOUS[3] = new OString( ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; + } + + void charAt_001() + { + sal_Unicode expVal = 83; + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 input = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "return the first character of OStringBuffer(kTestStr1)", + aStrBuf.charAt(input) == expVal + ); + + } + + void charAt_002() + { + sal_Unicode expVal = 32; + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 input = 3; + + CPPUNIT_ASSERT_MESSAGE + ( + "return the middle character of OStringBuffer(kTestStr1)", + aStrBuf.charAt(input) == expVal + ); + + } + + void charAt_003() + { + sal_Unicode expVal = 115; + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 input = 15; + + CPPUNIT_ASSERT_MESSAGE + ( + "return the last character of OStringBuffer(kTestStr1)", + aStrBuf.charAt(input) == expVal + ); + + } + + void charAt_004() + { + sal_Unicode expVal = 115; + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 input = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "return the only character of OStringBuffer(kTestStr27)", + aStrBuf.charAt(input) == expVal + ); + + } + + void charAt_005() + { + sal_Unicode expVal = 40; + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 input = 0; + + CPPUNIT_ASSERT_MESSAGE + ( + "return the first of OStringBuffer(kTestStr28) with special character", + aStrBuf.charAt(input) == expVal + ); + + } + + void charAt_006() + { + sal_Unicode expVal = 11; + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 input = 5; + + CPPUNIT_ASSERT_MESSAGE + ( + "return the mid of OStringBuffer(kTestStr28) with special character", + aStrBuf.charAt(input) == expVal + ); + + } + + void charAt_007() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + + CPPUNIT_ASSERT_MESSAGE + ( + "invalid character of OStringBuffer()", + sal_True + ); + + } + + void charAt_008() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + + CPPUNIT_ASSERT_MESSAGE + ( + "invalid character of OStringBuffer()", + sal_True + ); + + } + + CPPUNIT_TEST_SUITE( charAt ); + CPPUNIT_TEST( charAt_001 ); + CPPUNIT_TEST( charAt_002 ); + CPPUNIT_TEST( charAt_003 ); + CPPUNIT_TEST( charAt_004 ); + CPPUNIT_TEST( charAt_005 ); + CPPUNIT_TEST( charAt_006 ); + CPPUNIT_TEST( charAt_007 ); + CPPUNIT_TEST( charAt_008 ); + CPPUNIT_TEST_SUITE_END(); + }; +// ----------------------------------------------------------------------------- + + + class csuc : public CppUnit::TestFixture + { + void csuc_001() + { + const sal_Char* expVal = kTestStr1; + ::rtl::OStringBuffer aStrBuf( kTestStr1 ); + sal_Int32 cmpLen = kTestStr1Len; + + // LLA: wrong access! const sal_Char* pstr = *&aStrBuf; + const sal_Char* pstr = aStrBuf.getStr(); + int nEqual = strncmp(pstr, expVal, cmpLen); + + CPPUNIT_ASSERT_MESSAGE + ( + "test normal string", + /* cmpstr( pstr, expVal, cmpLen ) */ + nEqual == 0 + ); + + } + + void csuc_002() + { + ::rtl::OStringBuffer aStrBuf; + + // LLA: wrong access! const sal_Char* pstr = *&aStrBuf; + const sal_Char* pstr = aStrBuf.getStr(); + sal_Int32 nLen = strlen(pstr); + + CPPUNIT_ASSERT_MESSAGE + ( + "test empty string", + // cmpstr( pstr, &expVal, cmpLen ) + nLen == 0 + ); + + } + + + 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 sal_Char* expVal = kTestStr1; + ::rtl::OStringBuffer aStrBuf( kTestStr1 ); + sal_Int32 cmpLen = kTestStr1Len; + + const sal_Char* pstr = aStrBuf.getStr(); + int nEqual = strncmp(pstr, expVal, cmpLen); + + CPPUNIT_ASSERT_MESSAGE + ( + "test normal string", + nEqual == 0 + ); + + } + + void getStr_002() + { + // const sal_Char tmpUC=0x0; + // const sal_Char* expVal=&tmpUC; + ::rtl::OStringBuffer aStrBuf; + // sal_Int32 cmpLen = 1; + + const sal_Char* pstr = aStrBuf.getStr(); + sal_Int32 nLen = strlen(pstr); + + CPPUNIT_ASSERT_MESSAGE + ( + "test empty string", + pstr != 0 && + nLen == 0 + ); + + } + + + CPPUNIT_TEST_SUITE( getStr ); + CPPUNIT_TEST( getStr_001 ); + CPPUNIT_TEST( getStr_002 ); + CPPUNIT_TEST_SUITE_END(); + }; + +// ----------------------------------------------------------------------------- + + class setCharAt : public CppUnit::TestFixture + { + OString* arrOUS[4]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr1 ); + arrOUS[1] = new OString( kTestStr27 ); + arrOUS[2] = new OString( kTestStr28 ); + arrOUS[3] = new OString( ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; + } + + void setCharAt_001() + { + OString expVal( kTestStr31 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 input1 = 0; + sal_Char input2 = 's'; + + CPPUNIT_ASSERT_MESSAGE + ( + "set the first character of OStringBuffer(kTestStr1) with s", + (aStrBuf.setCharAt(input1, input2)).getStr() == expVal + ); + + } + + void setCharAt_002() + { + OString expVal( kTestStr3 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 input1 = 4; + sal_Char input2 = 'm'; + + CPPUNIT_ASSERT_MESSAGE + ( + "set the middle character of OStringBuffer(kTestStr1) with m", + (aStrBuf.setCharAt(input1, input2)).getStr() == expVal + ); + + } + + void setCharAt_003() + { + OString expVal( kTestStr32 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Int32 input1 = 15; + sal_Char input2 = ' '; + + CPPUNIT_ASSERT_MESSAGE + ( + "set the last character of OStringBuffer(kTestStr1) with ' '", + (aStrBuf.setCharAt(input1, input2)).getStr() == expVal + ); + + } + + + void setCharAt_004() + { + OString expVal( kTestStr33 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Int32 input1 = 0; + sal_Char input2 = ' '; + + CPPUNIT_ASSERT_MESSAGE + ( + "set the only character of OStringBuffer(kTestStr27) with ' '", + (aStrBuf.setCharAt(input1, input2)).getStr() == expVal + ); + + } + + + void setCharAt_005() + { + OString expVal( kTestStr34 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 input1 = 1; + sal_Char input2 = (sal_Char)5; + + CPPUNIT_ASSERT_MESSAGE + ( + "set the only of OStringBuffer(kTestStr28) with special character", + (aStrBuf.setCharAt(input1, input2)).getStr() == expVal + ); + + } + + void setCharAt_006() + { + OString expVal( kTestStr35 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Int32 input1 = 1; + sal_Char input2 = (sal_Char)-5; + + CPPUNIT_ASSERT_MESSAGE + ( + "set the only of OStringBuffer(kTestStr28) with special character", + (aStrBuf.setCharAt(input1, input2)).getStr() == expVal + ); + + } +#ifdef WITH_CORE + void setCharAt_007() + { + OString* expVal = 0; + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 input1 = 0; + sal_Char input2 = (sal_Char)5; + + CPPUNIT_ASSERT_MESSAGE + ( + "invalid character of OStringBuffer()", + sal_True + ); + + delete expVal; + + } + + void setCharAt_008() + { + OString* expVal = 0; + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 input1 = -2; + sal_Char input2 = (sal_Char)5; + + CPPUNIT_ASSERT_MESSAGE + ( + "invalid character of OStringBuffer()", + sal_True + ); + + delete expVal; + + } + + void setCharAt_009() + { + OString* expVal = 0; + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Int32 input1 = 3; + sal_Char input2 = (sal_Char)5; + + CPPUNIT_ASSERT_MESSAGE + ( + "invalid character of OStringBuffer()", + sal_True + ); + + delete expVal; + + } +#endif + CPPUNIT_TEST_SUITE( setCharAt ); + CPPUNIT_TEST( setCharAt_001 ); + CPPUNIT_TEST( setCharAt_002 ); + CPPUNIT_TEST( setCharAt_003 ); + CPPUNIT_TEST( setCharAt_004 ); + CPPUNIT_TEST( setCharAt_005 ); + CPPUNIT_TEST( setCharAt_006 ); +#ifdef WITH_CORE + CPPUNIT_TEST( setCharAt_007 ); + CPPUNIT_TEST( setCharAt_008 ); + CPPUNIT_TEST( setCharAt_009 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// ----------------------------------------------------------------------------- + + class append_001 : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001_001() + { + OString expVal( kTestStr1 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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; + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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; + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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; + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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 ); + ::rtl::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() + ); + + } + +#ifdef WITH_CORE + void append_001_021() + { + OString expVal; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + 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() + ); + + } +#endif + + 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 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_001_021 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; + +// ----------------------------------------------------------------------------- + + class append_002 : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_002_001() + { + OString expVal( kTestStr1 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + const sal_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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_003_001() + { + OString expVal( kTestStr1 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + const sal_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_005() + { + // LLA: this is an illegal test, the input2 value must non-negative + // LLA: OString expVal( kTestStr41 ); + // LLA: ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: const sal_Char* input1 = kTestStr2; + // LLA: sal_Int32 input2 = -1; + // LLA: + // LLA: aStrBuf.append( input1, input2 ); + // LLA: + // LLA: CPPUNIT_ASSERT_MESSAGE + // LLA: ( + // LLA: "Appends the string(length less than 0) to the string buffer arrOUS[0]", + // LLA: ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + // LLA: ); + + } + + void append_003_006() + { + OString expVal( kTestStr7 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + const sal_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_010() + { + // LLA: this is an illegal test, the input2 value must non-negative + // LLA: OString expVal; + // LLA: ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: const sal_Char* input1 = kTestStr2; + // LLA: sal_Int32 input2 = -1; + // LLA: + // LLA: aStrBuf.append( input1, input2 ); + // LLA: + // LLA: CPPUNIT_ASSERT_MESSAGE + // LLA: ( + // LLA: "Appends the string(length less than 0) to the string buffer arrOUS[1]", + // LLA: ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + // LLA: ); + } + + void append_003_011() + { + OString expVal( kTestStr7 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + const sal_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_015() + { + // LLA: this is an illegal test, the input2 value must non-negative + // LLA: OString expVal; + // LLA: ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: const sal_Char* input1 = kTestStr2; + // LLA: sal_Int32 input2 = -1; + // LLA: + // LLA: aStrBuf.append( input1, input2 ); + // LLA: + // LLA: CPPUNIT_ASSERT_MESSAGE + // LLA: ( + // LLA: "Appends the string(length less than 0) to the string buffer arrOUS[2]", + // LLA: ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + // LLA: ); + + } + + void append_003_016() + { + OString expVal( kTestStr7 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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; + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + const sal_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_020() + { + // LLA: this is an illegal test, the input2 value must non-negative + // LLA: OString expVal; + // LLA: ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: const sal_Char* input1 = kTestStr2; + // LLA: sal_Int32 input2 = -1; + // LLA: + // LLA: aStrBuf.append( input1, input2 ); + // LLA: + // LLA: CPPUNIT_ASSERT_MESSAGE + // LLA: ( + // LLA: "Appends the string(length less than 0) to the string buffer arrOUS[3]", + // LLA: ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + // LLA: ); + + } + + void append_003_021() + { + OString expVal( kTestStr29 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + const sal_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() ) + ); + + } + + void append_003_025() + { + // LLA: this is an illegal test, the input2 value must non-negative + // LLA: OString expVal( kTestStr42 ); + // LLA: ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: const sal_Char* input1 = kTestStr2; + // LLA: sal_Int32 input2 = -1; + // LLA: + // LLA: aStrBuf.append( input1, input2 ); + // LLA: + // LLA: CPPUNIT_ASSERT_MESSAGE + // LLA: ( + // LLA: "Appends the string(length less than 0) to the string buffer arrOUS[4]", + // LLA: ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + // LLA: ); + + } + +#ifdef WITH_CORE + void append_003_026() + { + OString expVal; + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + const sal_Char* input1 = kTestStr25; + sal_Int32 input2 = 0; + + aStrBuf.append( input1, input2 ); + + 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_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_005 ); + CPPUNIT_TEST( append_003_006 ); + CPPUNIT_TEST( append_003_007 ); + CPPUNIT_TEST( append_003_008 ); + CPPUNIT_TEST( append_003_009 ); + CPPUNIT_TEST( append_003_010 ); + CPPUNIT_TEST( append_003_011 ); + CPPUNIT_TEST( append_003_012 ); + CPPUNIT_TEST( append_003_013 ); + CPPUNIT_TEST( append_003_014 ); + CPPUNIT_TEST( append_003_015 ); + CPPUNIT_TEST( append_003_016 ); + CPPUNIT_TEST( append_003_017 ); + CPPUNIT_TEST( append_003_018 ); + CPPUNIT_TEST( append_003_019 ); + CPPUNIT_TEST( append_003_020 ); + CPPUNIT_TEST( append_003_021 ); + CPPUNIT_TEST( append_003_022 ); + CPPUNIT_TEST( append_003_023 ); + CPPUNIT_TEST( append_003_024 ); + CPPUNIT_TEST( append_003_025 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_003_026 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; +// ----------------------------------------------------------------------------- + + class append_004 : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_004_001() + { + OString expVal( kTestStr45 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Bool input = sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Bool input = sal_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 ); + ::rtl::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 ); + ::rtl::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(sal_Char c) +//------------------------------------------------------------------------ + class append_005 : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + OString expVal( kTestStr51 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Char input = 'M'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(M) to the string buffer arrOUS[0]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_002() + { + OString expVal( kTestStr143 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + sal_Char input = static_cast<sal_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 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(s) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_004() + { + OString expVal( kTestStr144 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + sal_Char input = static_cast<sal_Char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(kSInt8Max) to the string buffer arrOUS[1]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_005_005() + { + OString expVal( kTestStr27 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(s) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_006() + { + OString expVal( kTestStr144 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + sal_Char input = static_cast<sal_Char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(kSInt8Max) to the string buffer arrOUS[2]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_007() + { + OString expVal( kTestStr27 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(s) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_008() + { + OString expVal( kTestStr144 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + sal_Char input = static_cast<sal_Char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(kSInt8Max) to the string buffer arrOUS[3]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_009() + { + OString expVal( kTestStr56 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(s) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_010() + { + OString expVal( kTestStr145 ); + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + sal_Char input = static_cast<sal_Char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(kSInt8Max) to the string buffer arrOUS[4]", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + +#ifdef WITH_CORE + void append_011() + { + OString expVal( kTestStr27 ); + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Char input = 's'; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_Char(s) to the string buffer(with INT_MAX)", + ( aStrBuf.getStr()== expVal) &&( aStrBuf.getLength() == expVal.getLength() ) + ); + + } + + void append_012() + { + OString expVal( kTestStr144 ); + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + sal_Char input = static_cast<sal_Char>(SAL_MAX_UINT8); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the sal_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(); + }; +/** + * Calls the method append(T, radix) and compares + * returned OUString with OUString that passed in the array resArray. + * + * @param T, type of argument, passed to append + * @param resArray, array of result ustrings to compare to + * @param n the number of elements in the array resArray (testcases) + * @param pTestResult the instance of the class TestResult + * @param inArray [optional], array of value that is passed as first argument + * to append + * + * @return true, if all returned OUString are equal to corresponding OUString in + * resArray else, false. + */ +/*template <class T> +sal_Bool test_append( const char** resArray, int n, sal_Int16 radix, + const T *inArray, OStringBuffer &aStr1 ) +{ + sal_Bool bRes = sal_True; + + //sal_Char methName[MAXBUFLENGTH]; + //sal_Char* pMeth = methName; + sal_Int32 i; +// static sal_Unicode aUchar[80]={0x12}; + + for (i = 0; i < n; i++) + { + + OSL_ENSURE( i < 80, "ERROR: leave aUchar bound"); + +// AStringToUStringCopy(aUchar,resArray[i]); + + ::rtl::OString aStr2(aStr1.getStr()); + ::rtl::OString aStr3( "-" ); + + if (inArray == 0) + { + aStr2 += OString(resArray[i]); + aStr1.append((T)i, radix); + } + else + { + // sal_Unicode aStr4[100]; + if ( inArray[i] < 0 ) + { + aStr2 += aStr3; + + } +// if(AStringToUStringCopy(aStr4,resArray[i])) +// { + aStr2 += OString(resArray[i]); +// } + aStr1.append((T)inArray[i], radix); + } + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[0]", + aStr1.getStr()== aStr2 && + aStr1.getLength() == aStr2.getLength() + ); + } + + return (bRes); +} +#define test_append_Int32 test_append<sal_Int32> +#define test_append_Int64 test_append<sal_Int64> +#define test_append_float test_append<float> +#define test_append_double test_append<double>*/ +//------------------------------------------------------------------------ +// testing the method append( sal_Int32 i, sal_Int16 radix=2 ) +// testing the method append( sal_Int32 i, sal_Int16 radix=8 ) +// testing the method append( sal_Int32 i, sal_Int16 radix=10 ) +// testing the method append( sal_Int32 i, sal_Int16 radix=16 ) +// testing the method append( sal_Int32 i, sal_Int16 radix=36 ) +//------------------------------------------------------------------------ + class append_006_Int32 : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( aStrBuf.getStr() ); + sal_Int32 input = 0; + sal_Int16 radix = 2; + + expVal += OString( "0" ); + aStrBuf.append( input, radix ); + + /*test_append_Int32((const char**)kBinaryNumsStr, + kBinaryNumsCount, kRadixBinary, + 0, aStrBuf );*/ + + CPPUNIT_ASSERT_MESSAGE + ( + "append(sal_Int32, radix 2)_006_kRadixBinary for arrOUS[0]", + aStrBuf.getStr()== expVal && + aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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(); + }; +//------------------------------------------------------------------------ +// testing the method append( sal_Int32 i, sal_Int16 radix ) where radix = -5 +//------------------------------------------------------------------------ + class append_006_Int32_WrongRadix : public CppUnit::TestFixture + { + OString* arrOUS[5]; + sal_Int32 intVal; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + intVal = 11; + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr59 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[0]", + sal_True + ); + + } + + void append_002() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[1]", + sal_True + ); + + } + + void append_003() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[2]", + sal_True + ); + + } + + void append_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[3]", + sal_True + ); + + } + + void append_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr61 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[4]", + sal_True + ); + + } +#ifdef WITH_CORE + void append_006() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer(with INT_MAX)", + sal_True + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_006_Int32_WrongRadix ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_006 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; +//------------------------------------------------------------------------ + class append_006_Int32_defaultParam : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } +#ifdef WITH_CORE + void append_026() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + ::rtl::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 == 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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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() + { + ::rtl::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(); + }; +//------------------------------------------------------------------------ +// testing the method append( sal_Int64 i, sal_Int16 radix ) where radix = -5 +//------------------------------------------------------------------------ + class append_007_Int64_WrongRadix : public CppUnit::TestFixture + { + OString* arrOUS[5]; + sal_Int64 intVal; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + intVal = 11; + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr59 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[0]", + sal_True + ); + + } + + void append_002() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[1]", + sal_True + ); + + } + + void append_003() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[2]", + sal_True + ); + + } + + void append_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[3]", + sal_True + ); + + } + + void append_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr61 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer arrOUS[4]", + sal_True + ); + + } +#ifdef WITH_CORE + void append_006() + { + ::rtl::OStringBuffer aStrBuf( kSInt64Max ); + OString expVal( kTestStr60 ); + + aStrBuf.append( intVal, -5 ); + + CPPUNIT_ASSERT_MESSAGE + ( + "Appends the WrongRadix to the string buffer(with INT_MAX)", + sal_True + ); + + } +#endif + + CPPUNIT_TEST_SUITE( append_007_Int64_WrongRadix ); + CPPUNIT_TEST( append_001 ); + CPPUNIT_TEST( append_002 ); + CPPUNIT_TEST( append_003 ); + CPPUNIT_TEST( append_004 ); + CPPUNIT_TEST( append_005 ); +#ifdef WITH_CORE + CPPUNIT_TEST( append_006 ); +#endif + CPPUNIT_TEST_SUITE_END(); + }; +//------------------------------------------------------------------------ + class append_007_Int64_defaultParam : public CppUnit::TestFixture + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_002() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr116 ); +#if defined(UNX) || defined(OS2) + sal_Int64 input = 9223372036854775807LL; +#else + sal_Int64 input = 9223372036854775807; +#endif + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[0]+9223372036854775807", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr117 ); + sal_Int64 input = SAL_MIN_INT64/*-9223372036854775808*/; // LLA: this is not the same :-( kNonSInt64Max; + + aStrBuf.append( input ); + + sal_Bool bRes = expVal.equals( aStrBuf.getStr() ); + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 -9223372036854775808 and return OStringBuffer[0]+(-9223372036854775808)", + bRes && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr118 ); +#if defined(UNX) || defined(OS2) + sal_Int64 input = 9223372036854775807LL; +#else + sal_Int64 input = 9223372036854775807; +#endif + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[1]+9223372036854775807", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr118 ); +#if defined(UNX) || defined(OS2) + sal_Int64 input = 9223372036854775807LL; +#else + sal_Int64 input = 9223372036854775807; +#endif + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[2]+9223372036854775807", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr118 ); +#if defined(UNX) || defined(OS2) + sal_Int64 input = 9223372036854775807LL; +#else + sal_Int64 input = 9223372036854775807; +#endif + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[3]+9223372036854775807", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr120 ); +#if defined(UNX) || defined(OS2) + sal_Int64 input = 9223372036854775807LL; +#else + sal_Int64 input = 9223372036854775807; +#endif + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "input Int64 9223372036854775807 and return OStringBuffer[4]+9223372036854775807", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } +#ifdef WITH_CORE + void append_026() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + ::rtl::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 == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + ::rtl::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 == 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(rtl::OStringBuffer const& _sStrBuf, sal_Int32 _nLen, float _nFloat) + { + OString sFloatValue; + sFloatValue = rtl::OString::valueOf(_nFloat); + + OString sBufferString(_sStrBuf.getStr()); + sal_Int32 nPos = sBufferString.indexOf(sFloatValue); + if ( nPos >= 0 && nPos == _nLen) + { + return true; + } + return false; + } + }; +// ----------------------------------------------------------------------------- + class append_008_float : public checkfloat + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr74 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr75 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr76 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr77 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr78 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr79 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr80 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr81 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr82 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr83 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr84 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr85 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr86 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr87 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr81 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr82 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr83 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr84 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr85 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr86 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr87 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr81 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr82 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr83 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr84 ); + float input = (float)atof("3.502525"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_026() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr85 ); + float input = (float)atof("3.141592"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_027() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr86 ); + float input = (float)atof("3.5025255"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_028() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr87 ); + float input = (float)atof("3.00390625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_029() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr88 ); + float input = (float)atof("3.0"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_030() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr89 ); + float input = (float)atof("3.5"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_031() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr90 ); + float input = (float)atof("3.0625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_032() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr91 ); + float input = (float)atof("3.502525"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_033() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr92 ); + float input = (float)atof("3.141592"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_034() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr93 ); + float input = (float)atof("3.5025255"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_035() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr94 ); + float input = (float)atof("3.00390625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } +#ifdef WITH_CORE + void append_036() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr81 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr82 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr83 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr84 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr85 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr86 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr87 ); + 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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr95 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr96 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr97 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr98 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr99 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr100 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr101 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr102 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr103 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr104 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr105 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr106 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr107 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + // LLA: OString expVal( kTestStr108 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr102 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr103 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr104 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr105 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr106 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr107 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + // LLA: OString expVal( kTestStr108 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr102 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr103 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr104 ); + float input = (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() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr105 ); + float input = (float)atof("-3.502525"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_026() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr106 ); + float input = (float)atof("-3.141592"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_027() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr107 ); + float input = (float)atof("-3.5025255"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_028() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + // LLA: OString expVal( kTestStr108 ); + float input = (float)atof("-3.00390625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_029() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr109 ); + float input = (float)atof("-3.0"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.0", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_030() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr110 ); + float input = (float)atof("-3.5"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.5", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_031() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr111 ); + float input = (float)atof("-3.0625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.0625", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_032() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr112 ); + float input = (float)atof("-3.502525"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.502525", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_033() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr113 ); + float input = (float)atof("-3.141592"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.141592", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_034() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr114 ); + float input = (float)atof("-3.5025255"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.5025255", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } + + void append_035() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr115 ); + float input = (float)atof("-3.00390625"); + + sal_Int32 nLen = aStrBuf.getLength(); + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.0039062", + checkIfStrBufContainAtPosTheFloat(aStrBuf, nLen, input) + ); + + } +#ifdef WITH_CORE + void append_036() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr102 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr103 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr104 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr105 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr106 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr107 ); + 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() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + // LLA: OString expVal( kTestStr108 ); + 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(rtl::OStringBuffer const& _sStrBuf, sal_Int32 _nLen, double _nDouble) + { + OString sDoubleValue; + sDoubleValue = rtl::OString::valueOf(_nDouble); + + OString sBufferString(_sStrBuf.getStr()); + sal_Int32 nPos = sBufferString.indexOf(sDoubleValue); + if ( nPos >= 0 && nPos == _nLen) + { + return true; + } + return false; + } + }; + + class append_009_double : public checkdouble + { + OString* arrOUS[5]; + + public: + void setUp() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr74 ); + 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_002() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr75 ); + double input = atof("3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr76 ); + double input = atof("3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr122 ); + double input = atof("3.1415926535"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.1415926535", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr123 ); + double input = atof("3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr124 ); + double input = atof("3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr125 ); + double input = atof("3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append 3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr81 ); + double input = atof("3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr82 ); + double input = atof("3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr83 ); + double input = atof("3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr126 ); + double input = atof("3.1415926535"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.1415926535", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr127 ); + double input = atof("3.141592653589793"); + + aStrBuf.append( input ); + OString *result = new OString( aStrBuf.getStr()); + double output = result->toDouble(); + OString *final = new OString(); + *final = final->valueOf(output); +t_print("the OStringvalus is:"); +for(int m=0;m<final->getLength();m++) +{ + t_print("%c",final->pData->buffer[m]); +} +t_print("\n"); +t_print("the OStringBuffer is %d\n", aStrBuf.getLength()); +t_print("the expVal is %d\n", expVal.getLength()); +t_print("the OStringbuffervalus is:"); +for(int j=0;j<aStrBuf.getLength();j++) +{ + t_print("%c",*(aStrBuf.getStr()+j)); +} +t_print("\n"); +t_print("the expVlavalus is:"); +for(int k=0;k<expVal.getLength();k++) +{ + t_print("%c",expVal.pData->buffer[k]); +} +t_print("\n"); + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr128 ); + double input = atof("3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr129 ); + double input = atof("3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr81 ); + double input = atof("3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr82 ); + double input = atof("3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr83 ); + double input = atof("3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr126 ); + double input = atof("3.1415926535"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.1415926535", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr127 ); + double input = atof("3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr128 ); + double input = atof("3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr129 ); + double input = atof("3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append 3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr81 ); + double input = atof("3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr82 ); + double input = atof("3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr83 ); + double input = atof("3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr126 ); + double input = atof("3.1415926535"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.1415926535", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr127 ); + double input = atof("3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr128 ); + double input = atof("3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append 3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr129 ); + double input = atof("3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append 3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr88 ); + double input = atof("3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr89 ); + double input = atof("3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr90 ); + double input = atof("3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr130 ); + double input = atof("3.1415926535"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.1415926535", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr131 ); + double input = atof("3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr132 ); + double input = atof("3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append 3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } +*/ + void append_035() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr133 ); + 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) + ); + + } +/* +#ifdef WITH_CORE + void append_036() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr81 ); + double input = atof("3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr82 ); + double input = atof("3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr83 ); + double input = atof("3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr126 ); + double input = atof("3.1415926535"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.1415926535", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr127 ); + double input = atof("3.141592653589793"; + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr128 ); + double input = atof("3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr129 ); + double input = atof("3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append 3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } +#endif +*/ + CPPUNIT_TEST_SUITE( append_009_double ); + 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( 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() + { + arrOUS[0] = new OString( kTestStr7 ); + arrOUS[1] = new OString( ); + arrOUS[2] = new OString( kTestStr25 ); + arrOUS[3] = new OString( "\0" ); + arrOUS[4] = new OString( kTestStr28 ); + + } + + void tearDown() + { + delete arrOUS[0]; delete arrOUS[1]; delete arrOUS[2]; + delete arrOUS[3]; delete arrOUS[4]; + } + + void append_001() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + // LLA: OString expVal( kTestStr95 ); + 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_002() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr96 ); + double input = atof("-3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_003() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr97 ); + double input = atof("-3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_004() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr98 ); + double input = atof("-3.502525"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.502525", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_005() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr134 ); + double input = atof("-3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_006() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr135 ); + double input = atof("-3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_007() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[0] ); + OString expVal( kTestStr136 ); + double input = atof("-3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[0] append -3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_008() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr102 ); + double input = atof("-3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_009() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr103 ); + double input = atof("-3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_010() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr104 ); + double input = atof("-3.0625"); + + aStrBuf.append( input ); + OString *result = new OString( aStrBuf.getStr()); + double output = result->toDouble(); + OString *final = new OString(); + *final = final->valueOf(output); +t_print("the OStringvalus is:"); +for(int m=0;m<final->getLength();m++) +{ + t_print("%c",final->pData->buffer[m]); +} +t_print("\n"); +t_print("the OStringBuffer is %d\n", aStrBuf.getLength()); +t_print("the expVal is %d\n", expVal.getLength()); +t_print("the OStringbuffervalus is:"); +for(int j=0;j<aStrBuf.getLength();j++) +{ + t_print("%c",*(aStrBuf.getStr()+j)); +} +t_print("\n"); +t_print("the expVlavalus is:"); +for(int k=0;k<expVal.getLength();k++) +{ + t_print("%c",expVal.pData->buffer[k]); +} +t_print("\n"); + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_011() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr105 ); + double input = atof("-3.502525"); + + aStrBuf.append( input ); + + double output = atof("-3.50252"); + OString *final = new OString(); + *final = final->valueOf(output); +t_print("the OStringvalus is:"); +for(int m=0;m<final->getLength();m++) +{ + t_print("%c",final->pData->buffer[m]); +} +t_print("\n"); +t_print("the OStringBuffer is %d\n", aStrBuf.getLength()); +t_print("the expVal is %d\n", expVal.getLength()); +t_print("the OStringbuffervalus is:"); +for(int j=0;j<aStrBuf.getLength();j++) +{ + t_print("%c",*(aStrBuf.getStr()+j)); +} +t_print("\n"); +t_print("the expVlavalus is:"); +for(int k=0;k<expVal.getLength();k++) +{ + t_print("%c",expVal.pData->buffer[k]); +} +t_print("\n"); + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.502525", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_012() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr137 ); + double input = atof("-3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_013() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr138 ); + double input = atof("-3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_014() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[1] ); + OString expVal( kTestStr139 ); + double input = atof("-3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_015() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr102 ); + double input = atof("-3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_016() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr103 ); + double input = atof("-3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_017() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr104 ); + double input = atof("-3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_018() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr105 ); + double input = atof("-3.502525"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.502525", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_019() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr137 ); + double input = atof("-3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_020() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr138 ); + double input = atof("-3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_021() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[2] ); + OString expVal( kTestStr139 ); + double input = atof("-3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[2] append -3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_022() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr102 ); + double input = atof("-3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_023() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr103 ); + double input = atof("-3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_024() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr104 ); + double input = atof("-3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_025() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr105 ); + double input = atof("-3.502525"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.502525", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_026() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr137 ); + double input = atof("-3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_027() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr138 ); + double input = atof("-3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[1] append -3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_028() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[3] ); + OString expVal( kTestStr139 ); + double input = atof("-3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[3] append -3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_029() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr109 ); + double input = atof("-3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_030() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr110 ); + double input = atof("-3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_031() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr111 ); + double input = atof("-3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_032() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr112 ); + double input = atof("-3.502525"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.502525", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_033() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr140 ); + double input = atof("-3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_034() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + OString expVal( kTestStr141 ); + double input = atof("-3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "arrOUS[4] append -3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + +*/ + void append_035() + { + ::rtl::OStringBuffer aStrBuf( *arrOUS[4] ); + // LLA: OString expVal( kTestStr142 ); + 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) + ); + + } +/* +#ifdef WITH_CORE + void append_036() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr102 ); + double input = atof("-3.0"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.0", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_037() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr103 ); + double input = atof("-3.5"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.5", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_038() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr104 ); + double input = atof("-3.0625"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.0625", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_039() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr105 ); + double input = atof("-3.502525"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.502525", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_040() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr137 ); + double input = atof("-3.141592653589793"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.141592653589793", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_041() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr138 ); + double input = atof("-3.14159265358979323"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.14159265358979323", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } + + void append_042() + { + ::rtl::OStringBuffer aStrBuf( kSInt32Max ); + OString expVal( kTestStr139 ); + double input = atof("-3.141592653589793238462643"); + + aStrBuf.append( input ); + + CPPUNIT_ASSERT_MESSAGE + ( + "OStringBuffer( kSInt32Max ) append -3.141592653589793238462643", + aStrBuf == expVal && aStrBuf.getLength() == expVal.getLength() + ); + + } +#endif +*/ + CPPUNIT_TEST_SUITE( append_009_Double_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( append_035 ); + CPPUNIT_TEST_SUITE_END(); + }; +} // namespace rtl_OStringBuffer + + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::ctors, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::makeStringAndClear, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::getLength, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::getCapacity, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::ensureCapacity, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::setLength, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::charAt, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::csuc, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::getStr, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::setCharAt, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_001, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_002, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_003, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_004, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_005, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_006_Int32, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_006_Int32_Bounderies, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_006_Int32_Negative, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_006_Int32_WrongRadix, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_006_Int32_defaultParam, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_007_Int64, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_007_Int64_Bounderies, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_007_Int64_Negative, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_007_Int64_WrongRadix, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_007_Int64_defaultParam, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_008_float, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_008_Float_Negative, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_009_double, + "rtl_OStringBuffer"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OStringBuffer::append_009_Double_Negative, + "rtl_OStringBuffer"); + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/OStringBuffer/rtl_String_Const.h b/sal/qa/OStringBuffer/rtl_String_Const.h new file mode 100644 index 000000000000..c8b525e2896f --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_String_Const.h @@ -0,0 +1,560 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Const.h,v $ + * $Revision: 1.13 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_CONST_H_ +#define _RTL_STRING_CONST_H_ + +#ifndef _RTL_STRING_UTILS_HXX_ + #include <rtl_String_Utils.hxx> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <limits.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +#ifndef _RTL_TEXTENC_H + #include <rtl/textenc.h> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#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 sal_Char *kTestStr1 = "Sun Microsystems"; +static const sal_Char *kTestStr2 = "Sun Microsystems Java Technology"; +static const sal_Char *kTestStr3 = "Sun microsystems"; +static const sal_Char *kTestStr7 = "Sun "; +static const sal_Char *kTestStr8 = "Microsystems"; +static const sal_Char *kTestStr14 = " Sun Microsystems"; +static const sal_Char *kTestStr17 = " Sun Microsystems "; +static const sal_Char *kTestStr23 = " Java Technology"; +static const sal_Char *kTestStr25 = ""; +static const sal_Char *kTestStr27 = "s"; +static const sal_Char *kTestStr28 = "\50\3\5\7\11\13\15\17sun"; +static const sal_Char *kTestStr29 = "\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50"; +static const sal_Char *kTestStr31 = "sun Microsystems"; +static const sal_Char *kTestStr32 = "Sun Microsystem "; +static const sal_Char *kTestStr33 = " "; +static const sal_Char *kTestStr34 = "\50\5\5\7\11\13\15\17sun"; +static const sal_Char *kTestStr35 = "\50\373\5\7\11\13\15\17sun"; +static const sal_Char *kTestStr36 = "Microsystems Java Technology"; +static const sal_Char *kTestStr37 = "Sun Java Technology"; +static const sal_Char *kTestStr38 = "\21\23\25\27\31\33\50"; +static const sal_Char *kTestStr39 = "\50\3\5\7\11\13\15\17sun Sun Microsystems "; +static const sal_Char *kTestStr40 = "\50\3\5\7\11\13\15\17sunsun Microsystems"; +static const sal_Char *kTestStr45 = "Sun true"; +static const sal_Char *kTestStr46 = "Sun false"; +static const sal_Char *kTestStr47 = "true"; +static const sal_Char *kTestStr48 = "false"; +static const sal_Char *kTestStr49 = "\50\3\5\7\11\13\15\17suntrue"; +static const sal_Char *kTestStr50 = "\50\3\5\7\11\13\15\17sunfalse"; +static const sal_Char *kTestStr51 = "Sun M"; +//static const sal_Char *kTestStr52 = "Sun \077777"; +//static const sal_Char *kTestStr53 = "Sun \100000"; +//static const sal_Char *kTestStr54 = "\77777"; +//static const sal_Char *kTestStr55 = "\100000"; +static const sal_Char *kTestStr56 = "\50\3\5\7\11\13\15\17suns"; +//static const sal_Char *kTestStr57 = "\50\3\5\7\11\13\15\17sun\77777"; +//static const sal_Char *kTestStr58 = "\50\3\5\7\11\13\15\17sun\10000"; +static const sal_Char *kTestStr59 = "Sun 11"; +static const sal_Char *kTestStr60 = "11"; +static const sal_Char *kTestStr61 = "\50\3\5\7\11\13\15\17sun11"; +static const sal_Char *kTestStr62 = "Sun 0"; +static const sal_Char *kTestStr63 = "Sun -11"; +static const sal_Char *kTestStr64 = "Sun 2147483647"; +static const sal_Char *kTestStr65 = "Sun -2147483648"; +static const sal_Char *kTestStr66 = "0"; +static const sal_Char *kTestStr67 = "-11"; +static const sal_Char *kTestStr68 = "2147483647"; +static const sal_Char *kTestStr69 = "-2147483648"; +static const sal_Char *kTestStr70 = "\50\3\5\7\11\13\15\17sun0"; +static const sal_Char *kTestStr71 = "\50\3\5\7\11\13\15\17sun-11"; +static const sal_Char *kTestStr72 = "\50\3\5\7\11\13\15\17sun2147483647"; +static const sal_Char *kTestStr73 = "\50\3\5\7\11\13\15\17sun-2147483648"; +static const sal_Char *kTestStr116 = "Sun 9223372036854775807"; +static const sal_Char *kTestStr117 = "Sun -9223372036854775808"; +static const sal_Char *kTestStr118 = "9223372036854775807"; +static const sal_Char *kTestStr119 = "-9223372036854775808"; +static const sal_Char *kTestStr120 = "\50\3\5\7\11\13\15\17sun9223372036854775807"; +static const sal_Char *kTestStr121 = "\50\3\5\7\11\13\15\17sun-9223372036854775808"; +static const sal_Char *kTestStr143 = "Sun \377"; +static const sal_Char *kTestStr144 = "\377"; +static const sal_Char *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; +#if defined(UNX) || defined(OS2) +static const sal_Int64 kSInt64Max = 9223372036854775807LL; +#else +static const sal_Int64 kSInt64Max = 9223372036854775807; +#endif + +//------------------------------------------------------------------------ + +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 kNonSInt64Max = LONG_MIN; +static const sal_Int32 kNonSInt32Max = INT_MIN; +static const sal_Int32 kNonSInt16Max = SHRT_MIN; +//------------------------------------------------------------------------ +#ifdef __cplusplus +} +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#endif /* _RTL_STRING_CONST_H_ */ + diff --git a/sal/qa/OStringBuffer/rtl_String_Utils.cxx b/sal/qa/OStringBuffer/rtl_String_Utils.cxx new file mode 100644 index 000000000000..a8698ff1bbc8 --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_String_Utils.cxx @@ -0,0 +1,618 @@ +/************************************************************************* +# + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Utils.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * +#*************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <math.h> +#include <stdlib.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +#ifndef _RTL_STRING_HXX_ + #include <rtl/string.hxx> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_UTILS_CONST_H_ + #include <rtl_String_Utils_Const.h> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +using namespace rtl; + +sal_uInt32 AStringLen( const sal_Char *pAStr ) +{ + sal_uInt32 nStrLen = 0; + + if ( pAStr != NULL ) + { + const sal_Char *pTempStr = pAStr; + + while( *pTempStr ) + { + pTempStr++; + } // while + + nStrLen = (sal_uInt32)( pTempStr - pAStr ); + } // if + + return nStrLen; +} // AStringLen +/* disable assignment within condition expression */ +#ifdef WNT +#pragma warning( disable : 4706 ) +#endif +sal_Char* cpystr( sal_Char* dst, const sal_Char* src ) +{ + const sal_Char* psrc = src; + sal_Char* pdst = dst; + + while( *pdst++ = *psrc++ ); + return ( dst ); +} + +sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt ) +{ + + const sal_Char* psrc = src; + sal_Char* pdst = dst; + sal_uInt32 len = cnt; + sal_uInt32 i; + + if ( len >= AStringLen(src) ) + { + return( cpystr( dst, src ) ); + } + + // copy string by char + for( i = 0; i < len; i++ ) + *pdst++ = *psrc++; + *pdst = '\0'; + + return ( dst ); +} + +//------------------------------------------------------------------------ +sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len ) +{ + const sal_Char* pBuf1 = str1; + const sal_Char* pBuf2 = str2; + sal_uInt32 i = 0; + + while ( (*pBuf1 == *pBuf2) && i < len ) + { + (pBuf1)++; + (pBuf2)++; + i++; + } + return( i == len ); +} +//----------------------------------------------------------------------- +sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2 ) +{ + const sal_Char* pBuf1 = str1; + const sal_Char* pBuf2 = str2; + sal_Bool res = sal_True; + + while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0') + { + (pBuf1)++; + (pBuf2)++; + } + if (*pBuf1 == '\0' && *pBuf2 == '\0') + res = sal_True; + else + res = sal_False; + return (res); +} +//------------------------------------------------------------------------ +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len ) +{ + const sal_Unicode* pBuf1 = str1; + const sal_Unicode* pBuf2 = str2; + sal_uInt32 i = 0; + + while ( (*pBuf1 == *pBuf2) && i < len ) + { + (pBuf1)++; + (pBuf2)++; + i++; + } + return( i == len ); +} + +//----------------------------------------------------------------------- +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 ) +{ + const sal_Unicode* pBuf1 = str1; + const sal_Unicode* pBuf2 = str2; + sal_Bool res = sal_True; + + while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0') + { + (pBuf1)++; + (pBuf2)++; + } + if (*pBuf1 == '\0' && *pBuf2 == '\0') + res = sal_True; + else + res = sal_False; + return (res); +} + +sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt ) +{ + sal_Char* pdst = dst; + sal_Char nstr[16]; + sal_Char* pstr = nstr; + rtl_str_valueOfInt32( pstr, cnt, 10 ); + + cpystr( pdst, meth ); + cpystr( pdst+ AStringLen(meth), "_" ); + + if ( cnt < 100 ) + { + cpystr(pdst + AStringLen(pdst), "0" ); + } + if ( cnt < 10 ) + { + cpystr(pdst + AStringLen(pdst), "0" ); + } + + cpystr( pdst + AStringLen(pdst), nstr ); + return( pdst ); +} + +//------------------------------------------------------------------------ +// testing the method compareTo( const OString & aStr ) +//------------------------------------------------------------------------ +void makeComment( char *com, const char *str1, const char *str2, + sal_Int32 sgn ) +{ + cpystr(com, str1); + int str1Length = AStringLen( str1 ); + const char *sign = (sgn == 0) ? " == " : (sgn > 0) ? " > " : " < " ; + cpystr(com + str1Length, sign); + int signLength = AStringLen(sign); + cpystr(com + str1Length + signLength, str2); + com[str1Length + signLength + AStringLen(str2)] = 0; +} + + +//------------------------------------------------------------------------ + +sal_Bool AStringToFloatCompare ( const sal_Char *pStr, + const float nX, + const float nEPS + ) +{ + sal_Bool cmp = sal_False; + + if ( pStr != NULL ) + { + ::rtl::OString aStr(pStr); + + float actNum = 0; + float expNum = nX; + float eps = nEPS; + + actNum = aStr.toFloat(); + + if ( abs( (int)(actNum - expNum) ) <= eps ) + { + cmp = sal_True; + } // if + } // if + + return cmp; +} // AStringToFloatCompare + +//------------------------------------------------------------------------ + +sal_Bool AStringToDoubleCompare ( const sal_Char *pStr, + const double nX, + const double nEPS + ) +{ + sal_Bool cmp = sal_False; + + if ( pStr != NULL ) + { + ::rtl::OString aStr(pStr); + + double actNum = 0; + double expNum = nX; + double eps = nEPS; + + actNum = aStr.toDouble(); + + if ( abs( (int)(actNum - expNum) ) <= eps ) + { + cmp = sal_True; + } // if + } // if + + return cmp; +} // AStringToDoubleCompare + +//------------------------------------------------------------------------ + + +//------------------------------------------------------------------------ + +sal_uInt32 UStringLen( const sal_Unicode *pUStr ) +{ + sal_uInt32 nUStrLen = 0; + + if ( pUStr != NULL ) + { + const sal_Unicode *pTempUStr = pUStr; + + while( *pTempUStr ) + { + pTempUStr++; + } // while + + nUStrLen = (sal_uInt32)( pTempUStr - pUStr ); + } // if + + return nUStrLen; +} // UStringLen + +//------------------------------------------------------------------------ + +sal_Bool AStringIsValid( const sal_Char *pAStr ) +{ + if ( pAStr != NULL ) + { + sal_uInt32 nLen = AStringLen( pAStr ); + sal_uChar uChar = 0; + + while ( *pAStr ) + { + uChar = (unsigned char)*pAStr; + + if ( uChar > 127 ) + { + return sal_False; + } // if + + pAStr++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nLen > 0 ) + { + nLen--; + } // if + else + { + break; + } // else + } // while + } // if + + return sal_True; +} // AStringIsValid + +//------------------------------------------------------------------------ + +sal_Bool AStringNIsValid( const sal_Char *pAStr, + const sal_uInt32 nStrLen + ) +{ + sal_uInt32 nLen = nStrLen; + sal_uChar uChar = 0; + + while ( *pAStr ) + { + uChar = (unsigned char)*pAStr; + + if ( uChar > 127 ) + { + return sal_False; + } // if + + pAStr++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nLen > 0 ) + { + nLen--; + } // if + else + { + break; + } // else + } // while + + return sal_True; +} // AStringNIsValid + +//------------------------------------------------------------------------ + +static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr + ) +{ + sal_Int32 nCmp = 0; + sal_Int32 nUChar = (sal_Int32)*pUStr; + sal_Int32 nChar = (sal_Int32)((unsigned char)*pAStr); + + nCmp = nUChar - nChar; + + return nCmp; +} // ACharToUCharCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToUStringCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr + ) +{ + sal_Int32 nCmp = kErrCompareAStringToUString; + + if ( ( pUStr != NULL ) && ( pAStr != NULL ) ) + { + nCmp = ACharToUCharCompare( pUStr, pAStr ); + + while ( ( nCmp == 0 ) && ( *pAStr ) ) + { + pUStr++; + pAStr++; + + nCmp = ACharToUCharCompare( pUStr, pAStr ); + } // while + } // if + + return nCmp; +} // AStringToUStringCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToUStringNCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ) +{ + sal_Int32 nCmp = kErrCompareNAStringToUString; + + if ( ( pUStr != NULL ) && ( pAStr != NULL ) ) + { + sal_uInt32 nCount = nAStrCount; + + nCmp = ACharToUCharCompare( pUStr, pAStr ); + + while ( ( nCmp == 0 ) && ( *pAStr ) && ( nCount ) ) + { + pUStr++; + pAStr++; + + nCmp = ACharToUCharCompare( pUStr, pAStr ); + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nCount > 0 ) + { + nCount--; + } // if + else + { + break; + } // else + } // while + } // if + + return nCmp; +} // AStringToUStringNCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToRTLUStringCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr + ) +{ + sal_Int32 nCmp = kErrCompareAStringToRTLUString; + + if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) ) + { + rtl_uString *pRTLUStrCopy = NULL; + + rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr ); + + if ( pRTLUStrCopy != NULL ) + { + const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy ); + + if ( pUStr != NULL ) + { + nCmp = AStringToUStringCompare( pUStr, pAStr ); + } // if + + rtl_uString_release( pRTLUStrCopy ); + + pRTLUStrCopy = NULL; + } // if + } // if + + return nCmp; +} // AStringToRTLUStringCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToRTLUStringNCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ) +{ + sal_Int32 nCmp = kErrCompareNAStringToRTLUString; + + if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) ) + { + rtl_uString *pRTLUStrCopy = NULL; + + rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr ); + + if ( pRTLUStrCopy != NULL ) + { + const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy ); + + if ( pUStr != NULL ) + { + nCmp = AStringToUStringNCompare( pUStr, pAStr, nAStrCount ); + } // if + + rtl_uString_release( pRTLUStrCopy ); + + pRTLUStrCopy = NULL; + } // if + } // if + + return nCmp; +} // AStringToRTLUStringNCompare + +//------------------------------------------------------------------------ + +sal_Bool AStringToUStringCopy( sal_Unicode *pDest, + const sal_Char *pSrc + ) +{ + sal_Bool bCopied = sal_False; + sal_uInt32 nCount = AStringLen( pSrc ); + sal_uInt32 nLen = nCount; + + if ( ( pDest != NULL ) + && ( pSrc != NULL ) + && ( AStringNIsValid( pSrc, nLen ) ) + ) + { + for (;;) + { + *pDest = (unsigned char)*pSrc; + + pDest++; + pSrc++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nCount > 0 ) + { + nCount--; + } // if + else + { + break; + } // else + } // while + + if ( nCount == 0 ) + { + bCopied = sal_True; + } // if + } // if + + return bCopied; +} // AStringToUStringCopy + +//------------------------------------------------------------------------ + +sal_Bool AStringToUStringNCopy( sal_Unicode *pDest, + const sal_Char *pSrc, + const sal_uInt32 nSrcLen + ) +{ + sal_Bool bCopied = sal_False; + sal_uInt32 nCount = nSrcLen; + sal_uInt32 nLen = nSrcLen; + + if ( ( pDest != NULL ) + && ( pSrc != NULL ) + && ( AStringNIsValid( pSrc, nLen ) ) + ) + { + for (;;) + { + *pDest = (unsigned char)*pSrc; + + pDest++; + pSrc++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nCount > 0 ) + { + nCount--; + } // if + else + { + break; + } // else + } // while + + if ( nCount == 0 ) + { + bCopied = sal_True; + } // if + } // if + + return bCopied; +} // AStringToUStringNCopy + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + diff --git a/sal/qa/OStringBuffer/rtl_String_Utils.hxx b/sal/qa/OStringBuffer/rtl_String_Utils.hxx new file mode 100644 index 000000000000..a1d456b4c072 --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_String_Utils.hxx @@ -0,0 +1,141 @@ +/************************************************************************* +# + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Utils.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * +#*************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_UTILS_HXX_ +#define _RTL_STRING_UTILS_HXX_ + +#ifdef __cplusplus + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <math.h> +#include <stdlib.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +#ifndef _RTL_STRING_HXX_ + #include <rtl/string.hxx> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +sal_Char* cpystr( sal_Char* dst, const sal_Char* src ); +sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt ); + +sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len ); +sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2 ); +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len ); +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 ); + +sal_Char* createName( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt ); +void makeComment(char *com, const char *str1, const char *str2, sal_Int32 sgn); + + +sal_uInt32 AStringLen( const sal_Char *pAStr ); + +sal_uInt32 UStringLen( const sal_Unicode *pUStr ); + +//------------------------------------------------------------------------ + +sal_Bool AStringToFloatCompare ( const sal_Char *pStr, + const float nX, + const float nEPS + ); + +sal_Bool AStringToDoubleCompare ( const sal_Char *pStr, + const double nX, + const double nEPS + ); + +//------------------------------------------------------------------------ + +sal_Bool AStringIsValid( const sal_Char *pAStr ); + +sal_Bool AStringNIsValid( const sal_Char *pAStr, + const sal_uInt32 nStrLen + ); + +//------------------------------------------------------------------------ + +sal_Int32 AStringToUStringCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr + ); + +sal_Int32 AStringToUStringNCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ); + +sal_Int32 AStringToRTLUStringCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr + ); + +sal_Int32 AStringToRTLUStringNCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ); + +//------------------------------------------------------------------------ + +sal_Bool AStringToUStringCopy( sal_Unicode *pDest, + const sal_Char *pSrc + ); + +sal_Bool AStringToUStringNCopy( sal_Unicode *pDest, + const sal_Char *pSrc, + const sal_uInt32 nSrcLen + ); + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#endif /* __cplusplus */ + +#endif /* _RTL_STRING_UTILS_HXX */ + + + + + + + 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 000000000000..a768bb770b19 --- /dev/null +++ b/sal/qa/OStringBuffer/rtl_String_Utils_Const.h @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Utils_Const.h,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_UTILS_CONST_H_ +#define _RTL_STRING_UTILS_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#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 /* _RTL_STRING_UTILS_CONST_H_ */ + + + diff --git a/sal/qa/buildall.pl b/sal/qa/buildall.pl new file mode 100644 index 000000000000..2d63a63edb58 --- /dev/null +++ b/sal/qa/buildall.pl @@ -0,0 +1,511 @@ +eval 'exec perl -wS $0 ${1+"$@"}' + if 0; +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: buildall.pl,v $ +# +# $Revision: 1.7 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************ + +# #!/usr/bin/perl -w + +use strict; +use POSIX; +use Cwd; +use File::Path; +use English; +use Cwd 'chdir'; + +my $cwd = getcwd(); + +# Prototypes +sub initEnvironment(); +sub main($); +sub checkForKillobj(); +sub checkARGVFor($); + +my $g_sTempDir = ""; +my $FS = ""; + +my $nGlobalFailures = 0; + +my %libraryRunThrough; +my $bBuildAll = 0; + +# LLA: this does not exist, ... use a little bit simpler method. +# use File::Temp qw/ :POSIX /; + +my $params; +my $param; + +if ($#ARGV < 0) +{ + $params = "test "; # debug=t TESTOPTADD=\"-boom\" TESTOPTADD=\"-noerroronexit\" + + # my $nNumber = 55; + # my $sLocalParams = $params; + # $sLocalParams =~ s/test\s/test$nNumber /; + # print "Testparams: $sLocalParams\n"; + # exit 1; + print "Default "; +} +else +{ + # special hack! + if (checkForKillobj() == 1) + { + $params = "killobj"; + } + elsif (checkARGVFor("buildall") == 1) + { + $bBuildAll = 1; + $params = "test"; + } + else + { + # always run test, but envelope the other in 'TESTOPT="..."' + $params = "test TESTOPT=\""; + + foreach $param (@ARGV) + { + $params = $params . " " . $param; + } + $params = $params . "\""; + } + print "User defined "; +} + +print "parameters for dmake: $params\n"; + +initEnvironment(); +main($params); + +# ------------------------------------------------------------------------------ +sub checkARGVFor($) +{ + my $sCheckValue = shift; + my $sLocalParam; + my $nBackValue = 0; + foreach $sLocalParam (@ARGV) + { + if ($sLocalParam =~ /^${sCheckValue}$/) + { + $nBackValue = 1; + last; + } + } + return $nBackValue; +} +# ------------------------------------------------------------------------------ +sub checkForKillobj() +{ + my $sLocalParam; + my $nBackValue = 0; + foreach $sLocalParam (@ARGV) + { + if ($sLocalParam =~ /^killobj$/) + { + $nBackValue = 1; + last; + } + } + return $nBackValue; +} + +# ------------------------------------------------------------------------------ +sub initEnvironment() +{ + my $gui = $ENV{GUI}; + # no error output in forms of message boxes + $ENV{'DISABLE_SAL_DBGBOX'}="t"; + + SWITCH: { + if ( $gui eq "WNT" ) { + $FS = "\\"; + $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}"; + last SWITCH; + } + if ( $gui eq "WIN" ) { + $FS = "\\"; + $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}"; + last SWITCH; + } + if ( $gui eq "OS2" ) { + $FS = "\\"; + $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}"; + last SWITCH; + } + if ( $gui eq "UNX" ) { + $FS = "/"; + $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}"; + last SWITCH; + } + print STDERR "buildall.pl: unkown platform\n"; + exit(1); + } +} +# ------------------------------------------------------------------------------ + +sub trim($) +{ + my $oldstr = shift; + $oldstr =~ s/^\s*(.*?)\s*$/$1/; + return $oldstr; +} + +# ------------------------------------------------------------------------------ +sub getLibName($) +{ + my $sFile = shift; + if ($OSNAME eq "linux" || $OSNAME eq "solaris") + { + return "lib" . $sFile . ".so"; + } + if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2") + { + return $sFile . ".dll"; + } + return $sFile; +} +# ------------------------------------------------------------------------------ +sub giveOutAll($) +{ + my $sFailureFile = shift; + local *IN; + if (! open(IN, $sFailureFile)) + { + print "ERROR: Can't open output file $sFailureFile\n"; + return; + } + my $line; + while ($line = <IN>) + { + chomp($line); + print "$line\n"; + } + close(IN); +} +# ------------------------------------------------------------------------------ +sub giveOutFailures($$) +{ + my $sTest = shift; + my $sFailureFile = shift; + + my $bBegin = 0; + my $nFailures = 0; + + my $line; + local *IN; + if (! open(IN, $sFailureFile)) + { + print "ERROR: Can't open output file $sFailureFile\n"; + return; + } + + my $bStartUnitTest = 0; + while ($line = <IN>) + { + chomp($line); + if ( $line =~ /^- start unit test/) + { + $bStartUnitTest = 1; + } + } + close(IN); + + if ($bStartUnitTest == 0) + { + print "\nFailure: Unit test not started. Maybe compiler error.\n"; + giveOutAll($sFailureFile); + $nFailures++; + # exit(1); + } + else + { + open(IN, $sFailureFile); + # check if testshl2 was started + while ($line = <IN>) + { + chomp($line); + + # handling of the states + if ( $line =~ /^\# -- BEGIN:/) + { + $bBegin = 1; + } + elsif ( $line =~ /^\# -- END:/) + { + $bBegin = 0; + } + else + { + if ($bBegin == 1) + { + print "$line\n"; + $nFailures++; + } + } + } + close(IN); + } + + if ($nFailures > 0) + { + # extra return for a better output + print "\nFailures occured: $nFailures\n"; + print "The whole output can be found in $sFailureFile\n"; + print "\n"; + + # Statistics + $nGlobalFailures += $nFailures; + } +} +# ------------------------------------------------------------------------------ +sub printOnLibrary($) +{ + my $sTarget = shift; + print " on library: " . getLibName($sTarget); +} +# ------------------------------------------------------------------------------ +sub runASingleTest($$) +{ + my $sTarget = shift; + my $params = shift; + my $dmake = "dmake $params"; + + my $sLogPath = $g_sTempDir . "dmake_out_$$"; + mkdir($sLogPath); + my $sLogFile = $sLogPath . "/" . $sTarget . ".out"; + + # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and + # supress same libraries, if they occur one more. + + if (exists $libraryRunThrough{getLibName($sTarget)}) + { + # already done + return; + } + printOnLibrary($sTarget); + print "\n"; + +# redirect tcsh ">&" (stdout, stderr) +# redirect 4nt ">" (stdout), "2>" (stderr) +# print "OSNAME: $OSNAME\n"; +# LLA: redirect check canceled, seems to be not work as I want. +# my $redirect = ""; +# if ($OSNAME eq "linux" || $OSNAME eq "solaris") +# { +# # print "UNIX, linux or solaris\n"; +# $redirect = '>>&!' . $sLogFile; +# } +# else +# { +# if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2") +# { +# # test +# $redirect = ">>$sLogFile 2>>$sLogFile"; +# } +# } +# print "$dmake $redirect\n"; + +# LLA: so system does also not work as I imagine +# system("$dmake $redirect"); + +# LLA: next check, use open with pipe + + local *LOGFILE; + if (! open( LOGFILE, '>' . "$sLogFile")) + { + print "ERROR: can't open logfile: $sLogFile\n"; + return; + } + + my $line; + local *DMAKEOUTPUT; + if (! open( DMAKEOUTPUT, "$dmake 2>&1 |")) + { + print "ERROR: can't open dmake\n"; + return; + } + while ($line = <DMAKEOUTPUT>) + { + chomp($line); + print LOGFILE "$line\n"; + } + close(DMAKEOUTPUT); + close(LOGFILE); + + giveOutFailures($sTarget, $sLogFile); + + $libraryRunThrough{getLibName($sTarget)} = "done"; +} + +# ------------------------------------------------------------------------------ +sub interpretLine($) +{ + my $line = shift; + + my $path; + my $file; + + if ($line =~ /^\#/ || $line =~ /^$/) + { + # remark or empty line + } + else + { + # special format, $file == $path + ($path, $file) = split(/;/, $line); + if (! $file) + { + $file = $path; + } + $file = trim($file); + $path = trim($path); + } + return $path, $file; +} +# ------------------------------------------------------------------------------ +sub runTestsOnPath($$$) +{ + my $path = shift; + my $file = shift; + my $params = shift; + + # empty values + if (!$path || $path eq "") + { + # DBG: print "empty path '$path'\n"; + return; + } + if (!$file || $file eq "") + { + # DBG: print "empty file '$file'\n"; + return; + } + +# print "File: '$file', Path: '$path'\n"; + print "Work in directory: $path\n"; + my $newpath = $cwd . $FS . $path; +# print "chdir to $newpath\n"; + + my $error = chdir($newpath); + cwd(); + + # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>" + + local *MAKEFILE_MK; + if (! open(MAKEFILE_MK, "makefile.mk")) + { + print "ERROR: can't open makefile.mk in path: $newpath\n"; + print "please check your libs2test.txt file in qa directory.\n"; + } + my $line; + my $nNumber; + my $sTarget; + my $sLocalParams; + + while($line = <MAKEFILE_MK>) + { + chomp($line); + + if ($line =~ /SHL(\d)TARGET=(.*)/) + { + $nNumber = $1; + $sTarget = trim($2); + + # DBG: print "test$number is lib: $target\n"; + $sLocalParams = $params . " "; # append a whitespace, so we can check if 'test' exist without additional digits + $sLocalParams =~ s/test\s/test$nNumber/; + # DBG: print "$sLocalParams\n"; + if ($bBuildAll == 1 || + $file eq $sTarget) + { + # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n"; + runASingleTest($sTarget, $sLocalParams); + } + else + { + # printOnLibrary($sTarget); + # print " suppressed, not in libs2test.txt\n"; + } + } + } + close(MAKEFILE_MK); +} + +# ------------------------------------------------------------------------------ + +sub main($) +{ + my $params = shift; +# my $sLogFile = shift; # "buildall_$$.out"; + local *LIBS2TEST; + my $filename = "libs2test.txt"; + my $line; + + open(LIBS2TEST, $filename) || die "can't open $filename\n"; + + while($line = <LIBS2TEST>) + { + chomp($line); + # DOS Hack grrrr... + while ($line =~ / +$/) + { + $line = substr($line, 0, -1); + } + + # print "$line\n"; + my $path; + my $file; + ($path, $file) = interpretLine($line); + runTestsOnPath($path, $file, $params); + } + close(LIBS2TEST); + + print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n"; + + if ($nGlobalFailures > 0) + { + print "\nFailures over all occured: $nGlobalFailures\n"; + print "\nPASSED FAILED.\n"; + } + else + { + print "\nPASSED OK.\n"; + } +} + +# ------------------------------------------------------------------------------ + +# TODO: +# -verbose +# -fan - \ | / + +# END! + diff --git a/sal/qa/export.map b/sal/qa/export.map new file mode 100755 index 000000000000..ab2e7cd007b0 --- /dev/null +++ b/sal/qa/export.map @@ -0,0 +1,38 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: export.map,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3.0 { + global: + registerAllTestFunction; + + local: + *; +}; diff --git a/sal/qa/helper/gcov/build_coverage b/sal/qa/helper/gcov/build_coverage new file mode 100755 index 000000000000..8948789a87e7 --- /dev/null +++ b/sal/qa/helper/gcov/build_coverage @@ -0,0 +1,23 @@ + +# this is a helper, to build sal with the right compiler parameters +# IMPORTANT, this works only within Linux + +if ( `uname` == "Linux" ) then + echo "running on Linux Intel, ok." + + build killobj + + # setenv OLDCFLAGS $ENVCFLAGS + + setenv ENVCFLAGS "-fprofile-arcs -ftest-coverage" + + build + + # setenv ENVCFLAGS $OLDCFLAGS + +else + + echo "Sorry, gcov works only within Linux environment." + +endif + diff --git a/sal/qa/helper/gcov/deprecated.txt b/sal/qa/helper/gcov/deprecated.txt new file mode 100644 index 000000000000..a46a94acca65 --- /dev/null +++ b/sal/qa/helper/gcov/deprecated.txt @@ -0,0 +1,213 @@ +# contain all functions, which are mark as deprecated +# this function will removed from the allexportlist +# Format of a line MUST be / (.*);/ + + rtl_ustr_trim; + rtl_str_trim; + +# since 16.9.2003 +# Function List: +# A. deprecated functions: +# 1) Profile class and all its sub C API: + osl_openProfile; + osl_closeProfile; + osl_flushProfile; + osl_readProfileString; + + osl_readProfileBool; + osl_readProfileIdent; + osl_writeProfileString; + + osl_writeProfileBool; + osl_writeProfileIdent; + osl_removeProfileEntry; + + osl_getProfileSectionEntries; + osl_getProfileSections; + +# 2) VolumeDevice class and all this sub C API: + osl_unmountVolumeDevice; + osl_automountVolumeDevice; + osl_releaseVolumeDeviceHandle; + + osl_acquireVolumeDeviceHandle; + osl_getVolumeDeviceMountPath; + +# 3) in FileBase class: + osl_getCanonicalName; + +# B. untested functions: +# functions need Client/Server model and blocking mode of transmission. some of the functions +# can not run through on testshl2 env while the same code can run successfully in normal seperate +# files. +# 1) in DatagramSocket class: +# osl_receiveFromSocket; +# osl_sendToSocket; + +# 2) in StreamSocket class: +# osl_readSocket; +# osl_writeSocket; +# osl_receiveSocket; +# osl_sendSocket; + +# 3) in Socket class: + osl_isExceptionPending; +# osl_shutdownSocket; + +# 4) in Pipe class: +# osl_acceptPipe; + +# 5) in StreamPipe class: +# osl_readPipe; +# osl_writePipe; +# osl_receivePipe; +# osl_sendPipe; + +#C. unreachable functions +# (*)in .map file but does not appear in.hxx header file thus unreachable, +# mostly for internal use, can not be reached by accessing class, so need +# not be tested. +# 1) in file module*: + osl_abbreviateSystemPath; + +# 2) in socket module*: + osl_addToSocketSet; + osl_clearSocketSet; + osl_createSocketSet; + osl_destroySocketSet; + osl_isInSocketSet; + osl_removeFromSocketSet + + osl_createHostAddrByName; + osl_createHostAddrByAddr; + + osl_createHostAddr; + osl_copyHostAddr; + osl_destroyHostAddr; + osl_getHostnameOfHostAddr; + osl_getSocketAddrOfHostAddr; + osl_createInetBroadcastAddr; + + osl_demultiplexSocketEvents; + osl_getDottedInetAddrOfSocketAddr; + osl_getFamilyOfSocketAddr; + +# 3) in thread module*: + osl_createThread; + osl_setThreadTextEncoding; + +# or (#)does not wrapper into a class, only in C API. does not in our Class +# check list. +# 1) all diagnose module#: + osl_breakDebug; + osl_assertFailedLine; + osl_trace; + osl_reportError; + + osl_setDebugMessageFunc; + +# 2) all signal module#: + osl_addSignalHandler; + osl_removeSignalHandler; + osl_raiseSignal; + +# 3) all time module#: + osl_getSystemTime; + osl_getDateTimeFromTimeValue; + + osl_getTimeValueFromDateTime; + osl_getLocalTimeFromSystemTime; + + osl_getSystemTimeFromLocalTime; + osl_getGlobalTimer; + +# 4) all process module#: + osl_executeProcess; + osl_executeProcess_WithRedirectedIO; + + osl_terminateProcess; + osl_getProcess; + + osl_freeProcessHandle; + osl_joinProcess; + osl_joinProcessWithTimeout; + + osl_getProcessInfo; + osl_getExecutableFile; + osl_getCommandArgCount; + + osl_getCommandArg; + osl_getEnvironment; + osl_getProcessWorkingDir; + + osl_getProcessLocale; + osl_setProcessLocale; + osl_sendResourcePipe; + + osl_receiveResourcePipe; + +# 5) all util module#: + osl_getEthernetAddress; + + + +### +# LLA: +# this functions are not deprecated, they only marked as deprecated, to say that +# there is no test need. +### + rtl_zeroMemory; + rtl_fillMemory; + rtl_copyMemory; + rtl_moveMemory; + rtl_compareMemory; + rtl_findInMemory; + +# LLA: +# Marked as deprecated by Stephan Bergmann + + rtl_byte_sequence_reference2One; + rtl_byte_sequence_realloc; + rtl_byte_sequence_acquire; + rtl_byte_sequence_release; + rtl_byte_sequence_construct; + rtl_byte_sequence_constructNoDefault; + rtl_byte_sequence_constructFromArray; + rtl_byte_sequence_assign; + rtl_byte_sequence_equals; + rtl_byte_sequence_getConstArray; + rtl_byte_sequence_getLength; + +# LLA: +# old test environment need no extra test + rtl_tres_create; + rtl_tres_destroy; + +# LLA: +# found in source code, marked as deprecated +# rtl_locale_getDefault; +# rtl_locale_setDefault; + +# LLA: +# marked as deprecated, due to the fact there is no access from outside +# so this functions are not really accessable +# They are used in rtl/source/locale.c + rtl_hashentry_destroy; + rtl_hashfunc; + rtl_hashtable_add; + rtl_hashtable_destroy; + rtl_hashtable_find; + rtl_hashtable_grow; + rtl_hashtable_init; + +# LLA: +# marked as deprecated by Joachim Lingner 20040414 + rtl_moduleCount_acquire; + rtl_moduleCount_release; + rtl_moduleCount_canUnload; + rtl_registerModuleForUnloading; + rtl_unregisterModuleForUnloading; + rtl_unloadUnusedModules; + rtl_addUnloadingListener; + rtl_removeUnloadingListener; + diff --git a/sal/qa/helper/gcov/gcov_all b/sal/qa/helper/gcov/gcov_all new file mode 100755 index 000000000000..dad1f736c688 --- /dev/null +++ b/sal/qa/helper/gcov/gcov_all @@ -0,0 +1,15 @@ +#!/bin/bash +# $Id: gcov_all,v 1.4 2005-11-02 17:23:43 kz Exp $ +# This helper run lists all c and cxx files from selected directories. + +# PRJ points to the flat project directory +PRJ='../../..' + +# selected directories +FILES=`/bin/ls $PRJ/osl/unx/*.c $PRJ/osl/unx/*.cxx $PRJ/rtl/source/*.c $PRJ/rtl/source/*.cxx $PRJ/osl/all/*.c $PRJ/osl/all/*.cxx $PRJ/textenc/*.c` + +# Use gcov_filter on every c/cxx file. +for file in $FILES; do + # echo $file + perl gcov_filter.pl -o $PRJ/unxlngi6/slo -i $PRJ/util/sal.map $file $* +done diff --git a/sal/qa/helper/gcov/gcov_filter.pl b/sal/qa/helper/gcov/gcov_filter.pl new file mode 100755 index 000000000000..5074c0251ce5 --- /dev/null +++ b/sal/qa/helper/gcov/gcov_filter.pl @@ -0,0 +1,427 @@ +#!/usr/bin/perl -w +# +# $Id: gcov_filter.pl,v 1.4 2005-11-02 17:23:57 kz Exp $ +# + +# GCOV_FILTER +# +# Helper to filter the gcov output. +# Handle a compare between the hole gcov output and a given select list of exported functions. +# +# Q: Why perl? +# A: regexp ;-) +# + + +use strict; +use File::Basename; +use Getopt::Long; + +# Global constants +our $version_info = 'gcov helper $Revision: 1.4 $ '; +our $help; # Help option flag +our $version; # Version option flag +our $cwd = `pwd`; # current working directory +chomp($cwd); +# our $tool_dir = dirname($0); +# our $tool_file = basename($0); + +# our $output_filename; +our $input_allfunc; +# our $input_filename; + +our $allfuncinfo; # allfuncinfo option flag +our $showallfunc; # showallfunc option flag +our $no_percentage; # no_percentage option flag +our $donotfilter; # donotfilter option flag +our $objectdir; + +# Prototypes +sub print_usage(*); +sub read_gcov_function_file($); +sub get_PRJ_from_makefile_mk(); +# sub read_ExportedFunctionList(); +sub read_List($); + +# if (! ($tool_dir =~ /^\/(.*)$/)) +# { +# $tool_dir = "$cwd/$tool_dir"; +# } + +# Parse command line options +if (!GetOptions( "input-allfunc=s" => \$input_allfunc, + "allfuncinfo" => \$allfuncinfo, + "showallfunc" => \$showallfunc, + "no-percentage" => \$no_percentage, + "do-not-filter" => \$donotfilter, + "objectdir=s" => \$objectdir, + "help" => \$help, + "version" => \$version + )) +{ + print_usage(*STDERR); + exit(1); +} + +# Check for help option +if ($help) +{ + print_usage(*STDOUT); + exit(0); +} + +# Check for version option +if ($version) +{ + print("$version_info\n"); + exit(0); +} + +# check if enough parameters +if ($#ARGV < 0) +{ + print("No input filename specified\n"); + print_usage(*STDERR); + exit(1); +} + +# special case: +# the filename contains a . or '/' at the beginning +my $startdir = $ARGV[0]; +if ( ($startdir =~ /^\.\./) || + ($startdir =~ /^\//) ) +{ + $startdir = dirname($startdir); + # print("start directory is $startdir\n"); + # chdir $startdir; +} +else +{ + $startdir = ""; +} + +# check for sal.map +if ( ! $input_allfunc ) +{ + # this is a try, to get the project directory form a found makefile.mk + # may work, but fails due to some disunderstandings may be problems in perl :-( + my $sDir = get_PRJ_from_makefile_mk(); + # chomp($sDir); + # HDW: print("PRJ is $dir\n"); + + # $sDir2 = "../.."; + my $sMapFile = "$sDir" . "/util/sal.map"; + # $sMapFile = "$sDir2" . "/util/sal.map"; + + if ( -e $sMapFile) + { + $input_allfunc = $sMapFile; + } + else + { + print("No input-allfunc filename specified\n"); + print_usage(*STDERR); + exit(1); + } +} +our @aDeprecatedList; +our @aExportedFunctionList; +# read_ExportedFunctionList(); +@aExportedFunctionList = read_List($input_allfunc); +@aDeprecatedList = read_List("deprecated.txt"); + +if ($allfuncinfo) +{ + print("Count of all functions: $#aExportedFunctionList\n"); + exit(0); +} + +if ($showallfunc) +{ + my $func; + foreach $func (@aExportedFunctionList) + { + print("$func\n"); + } + exit(0); +} + +# back to current directory +# this chdir was for a before chdir (in $startdir creation) but due to the fact, +# that the get_PRJ_from_makefile_mk works but the after concat of strings not, this +# chdir is also remarked. +# chdir $cwd; + +# HWD: print "count of param: \n"; +# $input_filename = $ARGV[0]; + +my $nCount = $#ARGV + 1; +my $nIdx; + +for ($nIdx = 0; $nIdx < $nCount ; ++$nIdx) +{ + my $file = $ARGV[$nIdx]; + # print("processing: $file\n"); + + # change directory, to the current file, due to the fact, that we may be need to call gcov + # and gcov will create some extra files, like *.gcov near the current file. + # if ( $startdir ne "" ) + # { + # chdir $startdir; + # $file = basename($file); + # } + + my $OBJECTS=""; + if ($objectdir) + { + $OBJECTS = "-o " . $objectdir; + } + + if (! ($file =~ /\.f$/ )) + { + my $filef = "$file.f"; + # if (! -e $filef ) + # { + # print "gcov $OBJECTS -l -f $file >$filef\n"; + my $blah = `gcov $OBJECTS -n -f $file >$filef`; + # } + $file = $filef; + } + read_gcov_function_file($file); + + # go back to old directory, because it's possible to change relative to an other directory. + if ( $startdir ne "" ) + { + chdir $cwd; + } +} + +# print "$tool_dir\n"; +# print "all is right\n"; +exit(0); + + +# -------------------------------------------------------------------------------- +# Read the map file, which should contain all exported functions. +sub read_List($) +{ + local *INPUT_HANDLE; + my $filename = $_[0]; + my @list; + my $line = ""; + open(INPUT_HANDLE, $filename); + # or die("ERROR: cannot open $filename!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # reg exp: [spaces]functionname[semicolon][line end] + if ($line =~ /^\s+(\w*);$/) + { + # print("$1\n"); + push(@list, $1); + } + } + close(INPUT_HANDLE); + return @list; +} + +# -------------------------------------------------------------------------------- +# Helper function, test is a given value is found in the global exported function list. +# the given value format could be a simple function name +# or a prototype +# e.g. +# osl_getSystemPathFromFileURL +# or +# void getSystemPathFromFileURL( const char* rtl_...) +# +sub contain_in_List($$) +{ + my $func; + my $value = $_[0]; + my $list = $_[1]; + + if ($donotfilter) + { + return $value; + } + + foreach $func (@$list) # (@aExportedFunctionList) + { + # first try, direct check + if ($value eq $func) + { + # HWD: print("$value eq $func\n"); + return $value; + } + + # value not found, second try, may be we found it if we search word wise. + # helper, to insert a space after the word, before '(' + $value =~ s/\(/ \(/g; + # may be here we should replace all white spaces by ' ' + + # split by 'space' + my @list = split(' ', $value); + for(@list) + { + # HWD: print "$list[$n]\n"; + if ($_ eq $func) + { + # HWD: print ("found $func in $value\n"); + return $_; + } + } + } + # not found + return ""; +} +# -------------------------------------------------------------------------------- +# Read the gcov function (gcov -f) file +# and compare line by line with the export function list +# so we get a list of functions, which are only exported, and not all stuff. +# sample of output +# new gcov gcc 3.4 format +sub read_gcov_function_file($) +{ + local *INPUT_HANDLE; + my $file = $_[0]; + my $line = ""; + open(INPUT_HANDLE, $file) + or die("ERROR: cannot open $file!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line (for reg exp:) + # 100.00% of 3 source lines executed in function osl_thread_init_Impl + if ($line =~ /^Function \`(.*)\'$/ ) + { + my $sFunctionName = $1; + my $sPercentage; + $line = <INPUT_HANDLE>; + if ($line =~ /^Lines executed:(.*)% of/ ) + { + $sPercentage = $1; + } + my $value = contain_in_List( $sFunctionName, \@aExportedFunctionList ); + if ($value) + { + my $isDeprecated = contain_in_List( $sFunctionName, \@aDeprecatedList ); + if ($isDeprecated) + { + # Function is deprecated, do not export it. + } + else + { + if ($no_percentage) + { + print("$value\n"); + } + else + { + print("$sPercentage $value\n"); + } + } + } + # push(@aExportedFunctionList, $1); + } + } + close(INPUT_HANDLE); +} + +# gcov format since gcc 3.3.6 +# 100.00% von 3 Zeilen in function helloworld ausgefhrt +# 100.00% von 5 Zeilen in function main ausgefhrt +# 100.00% von 8 Zeilen in file tmp.c ausgefhrt +sub read_gcov_function_file_old_gcc_3($) +{ + local *INPUT_HANDLE; + my $file = $_[0]; + my $line = ""; + open(INPUT_HANDLE, $file) + or die("ERROR: cannot open $file!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line (for reg exp:) + # 100.00% of 3 source lines executed in function osl_thread_init_Impl + if ($line =~ /^(.*)% of \d+ source lines executed in function (.*)$/ ) + { + my $value = contain_in_List( $2, \@aExportedFunctionList ); + if ($value) + { + my $isDeprecated = contain_in_List( $2, \@aDeprecatedList ); + if ($isDeprecated) + { + # Function is deprecated, do not export it. + } + else + { + if ($no_percentage) + { + print("$value\n"); + } + else + { + print("$1 $value\n"); + } + } + } + # push(@aExportedFunctionList, $1); + } + } + close(INPUT_HANDLE); +} + +# ------------------------------------------------------------------------------ +# helper, to read the PRJ value out of a makefile.mk file +sub get_PRJ_from_makefile_mk() +{ + local *INPUT_HANDLE; + # my $startdir = @_[0]; + my $line = ""; + my $value = ""; + open(INPUT_HANDLE, "makefile.mk") + or die("ERROR: cannot open makefile.mk\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line + # PRJ= + # HWD: print("$line\n"); + if ($line =~ /^PRJ\s*=(.*)\s*$/) + { + # HWD: print("FOUND #####\n"); + $value = $1; + chomp($value); + $value =~ s/\$\//\//g; + } + } + close(INPUT_HANDLE); + return $value; +} + +# ---------------------------------------------------------------------------- +sub print_usage(*) +{ + local *HANDLE = $_[0]; + my $tool_name = basename($0); + + print(HANDLE <<END_OF_USAGE); + +Usage: $tool_name [OPTIONS] INPUTFILE + + -h, --help Print this help, then exit + -v, --version Print version number, then exit + -i, --input-allfunc FILENAME Map file, which contain all exported functions + -s, --showallfunc Shows all exported functions then exit + -a, --allfuncinfo Shows the count of all exported functions then quit + -n, --no-percentage Suppress the output of the percent value for tested functions + -d, --do-not-filter Show all functions, which gcov -f produce + +END_OF_USAGE + ; +} + diff --git a/sal/qa/helper/gcov/gcov_result.pl b/sal/qa/helper/gcov/gcov_result.pl new file mode 100644 index 000000000000..414eac2c828b --- /dev/null +++ b/sal/qa/helper/gcov/gcov_result.pl @@ -0,0 +1,232 @@ +#!/usr/bin/perl -w +# +# $Id: gcov_result.pl,v 1.2 2003-06-11 16:36:30 vg Exp $ +# + +# GCOV_RESULT +# +# Helper, to interpret the result and put the result via html in a database. +# Put into DB works via php. +# +# Q: Why perl? +# A: regexp ;-) +# + +use strict; +use File::Basename; +use Getopt::Long; +use Time::localtime; + +our $version_info = 'gcov helper $Revision: 1.2 $ '; + +our $help; # Help option flag +our $version; # Version option flag +# our $infile; + +our $usedFunctions; # name of all functions filename, which have a value > 0 +our $nonusedFunctions; # name of all functions filename, which have a value == 0 +our $complete; # name of all functions filename, which have a value == 100 +our $incomplete; # name of all functions filename, which have a value > 0 && < 100 + +our $environment; +our $major; +our $minor; +our $cwsname; +our $outputDir; + +# Prototypes +sub print_usage(*); +sub read_gcov_function_file($); +sub create2DigitNumber($); + +# Parse command line options +if (!GetOptions( + "help" => \$help, + "version" => \$version, + + "usedfunctions=s" => \$usedFunctions, + "nonusedfunctions=s" => \$nonusedFunctions, + "complete=s" => \$complete, + "incomplete=s" => \$incomplete, + "cwsname=s" => \$cwsname, + "major=s" => \$major, + "minor=s" => \$minor, + "environment=s" => \$environment, + "outputdir=s" => \$outputDir + )) +{ + print_usage(*STDERR); + exit(1); +} + +# Check for help option +if ($help) +{ + print_usage(*STDOUT); + exit(0); +} + +# Check for version option +if ($version) +{ + print("$version_info\n"); + exit(0); +} + +# check if enough parameters +# if ($#ARGV < 0) +# { +# print("No input filename specified\n"); +# print_usage(*STDERR); +# exit(1); +# } + +# ------------------------------------------------------------------------------ + +my $sURL = "http://mahler.germany.sun.com/qadev/baselib/gcov_result_in_db_putter.php"; + +my $next = "?"; + +if ($complete) +{ + my $result = `cat $complete | wc -l`; + chomp($result); + $result =~ / *(\d+)/; + $sURL = $sURL . "$next" . "complete=$1"; + $next = "&"; +} + +if ($nonusedFunctions) +{ + my $result = `cat $nonusedFunctions | wc -l`; + chomp($result); + $result =~ / *(\d+)/; + $sURL = $sURL . "$next" . "notused=$1"; + $next = "&"; +} +if ($usedFunctions) +{ + my $result = `cat $usedFunctions | wc -l`; + chomp($result); + $result =~ / *(\d+)/; + $sURL = $sURL . "$next" . "used=$1"; + $next = "&"; +} +if ($incomplete) +{ + my $result = `cat $incomplete | wc -l`; + chomp($result); + $result =~ / *(\d+)/; + $sURL = $sURL . "$next" . "incomplete=$1"; + $next = "&"; +} + +if ($cwsname) +{ + # qadev8 + $sURL = $sURL . "$next" . "cwsname=$cwsname"; + $next = "&"; +} +if ($major) +{ + # srx645 + $sURL = $sURL . "$next" . "major=$major"; + $next = "&"; +} +if ($minor) +{ + # m3s1 + $sURL = $sURL . "$next" . "minor=$minor"; + $next = "&"; +} + +if ($environment) +{ + # unxlngi5 + $sURL = $sURL . "$next" . "environment=$environment"; + $next = "&"; +} + +my $year = localtime->year() + 1900; +my $month = create2DigitNumber(localtime->mon() + 1); +my $day = create2DigitNumber(localtime->mday()); +$sURL = $sURL . "$next" . "date=$year-$month-$day"; +$next = "&"; + +my $output; +if ($outputDir) +{ + chomp($outputDir); + $output = $outputDir; +} + +# check if output ends with "/" +if ( $output =~ /\/$/ ) +{ + print "Output name ends with '/'\n"; +} +else +{ + print "Output name does not end with '/'\n"; + $output = $output . "/"; +} +$output = $output . "php_result.txt"; + +my $result = `wget -O $output "$sURL"`; +print "$sURL\n"; + +print `cat $output`; + + +# ---------------------------------------------------------------------------- +sub print_usage(*) +{ + local *HANDLE = $_[0]; + my $tool_name = basename($0); + + print(HANDLE <<END_OF_USAGE); + +Usage: $tool_name [OPTIONS] + + -u, --usedfunctions count of all functions, which have a value > 0 + -n, --nonusedfunctions count of all functions, which have a value == 0 + -co, --complete count of all functions, which have a value == 100 + -i, --incomplete count of all functions, which have a value > 0 && < 100 + + -cw, --cwsname set cwsname + -ma, --major set major number + -mi, --minor set minor number + -e, --environment set environment + + -o, --outputdir set the directory, where to store the wget result + + -h, --help Print this help, then exit + -v, --version Print version number, then exit + +END_OF_USAGE + ; +} +# ------------------------------------------------------------------------------ +sub create2DigitNumber($) +{ + my $digit = $_[0]; + my $str; + my $nDigitLen = length $digit; + + if ($nDigitLen == 1) + { + $str = "0" . $digit; + } + else + { + if ($nDigitLen > 2) + { + $str = substr $digit, $nDigitLen - 2, 2; + } + else + { + $str = $digit; + } + } + return $str; +} diff --git a/sal/qa/helper/gcov/gcov_resultcompare.pl b/sal/qa/helper/gcov/gcov_resultcompare.pl new file mode 100644 index 000000000000..d52316fac0e7 --- /dev/null +++ b/sal/qa/helper/gcov/gcov_resultcompare.pl @@ -0,0 +1,151 @@ +#!/usr/bin/perl -w +# +# $Id: gcov_resultcompare.pl,v 1.2 2004-03-19 14:46:51 obo Exp $ +# + +# GCOV_RESULTCOMPARE +# +# Helper, to compare two different results +# +# Q: Why perl? +# A: regexp ;-) +# + +use strict; +use File::Basename; +use Getopt::Long; + +our $version_info = 'gcov_resultcompare $Revision: 1.2 $ '; + +our $help; # Help option flag +our $version; # Version option flag +# our $infile; + +our $orig; +our $compare; + +# Prototypes +sub print_usage(*); +sub read_gcov_function_file($); + +# Parse command line options +if (!GetOptions( + "o=s" => \$orig, + "c=s" => \$compare, + "help" => \$help, + "version" => \$version + )) +{ + print_usage(*STDERR); + exit(1); +} + +# Check for help option +if ($help) +{ + print_usage(*STDOUT); + exit(0); +} + +# Check for version option +if ($version) +{ + print("$version_info\n"); + exit(0); +} + +# check if enough parameters +# if ($#ARGV < 1) +# { +# print("No input filenames specified\n"); +# print_usage(*STDERR); +# exit(1); +# } + +if (! $orig) +{ + print_usage(*STDOUT); + exit(0); +} +if (! $compare) +{ + print_usage(*STDOUT); + exit(0); +} + +# ------------------------------------------------------------------------------ + +my %origlist = read_gcov_function_file($orig); +my %cmplist = read_gcov_function_file($compare); + +my $key; +my $value; + +while (($key, $value) = each %origlist) +{ + my $cmpvalue = $cmplist{$key}; + + if ($cmpvalue != 0.00) + { + if ($value < 100.00) + { + if ($cmpvalue > $value && $value < 90.0) + { + print "$key, $value, CMP:$cmpvalue\n"; + } + } + } +} + +# -------------------------------------------------------------------------------- +# Read the gcov function (gcov -f) file +# and compare line by line with the export function list +# so we get a list of functions, which are only exported, and not all stuff. + +sub read_gcov_function_file($) +{ + local *INPUT_HANDLE; + my $file = shift; + my %list; + my $line = ""; + + open(INPUT_HANDLE, $file) + or die("ERROR: cannot open $file!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line (for reg exp:) + # 100.00 rtl_ustr_toDouble + if ($line =~ /^(.{6}) (\w+)$/ ) + { + my $percent = $1; + my $value = $2; + + $list{$value} = $percent; + } + } + close(INPUT_HANDLE); + return %list; +} + +# ---------------------------------------------------------------------------- +sub print_usage(*) +{ + local *HANDLE = $_[0]; + my $tool_name = basename($0); + + print(HANDLE <<END_OF_USAGE); + +Usage: $tool_name [OPTIONS] INPUTFILE + + -o Original File, which gives the main values + if here a value is smaller than in compare, the found value is a candidate for better check. + -c Compare file. + + -h, --help Print this help, then exit + -v, --version Print version number, then exit + +END_OF_USAGE + ; +} diff --git a/sal/qa/helper/gcov/gcov_resultinterpreter.pl b/sal/qa/helper/gcov/gcov_resultinterpreter.pl new file mode 100644 index 000000000000..b01506b20634 --- /dev/null +++ b/sal/qa/helper/gcov/gcov_resultinterpreter.pl @@ -0,0 +1,172 @@ +#!/usr/bin/perl -w +# +# $Id: gcov_resultinterpreter.pl,v 1.3 2005-11-02 17:24:12 kz Exp $ +# + +# GCOV_RESULTINTERPRETER +# +# Helper, to interpret the result +# +# Q: Why perl? +# A: regexp ;-) +# + +use strict; +use File::Basename; +use Getopt::Long; + +our $version_info = 'gcov helper $Revision: 1.3 $ '; + +our $help; # Help option flag +our $version; # Version option flag +# our $infile; + +our $usedFunctions; # show all functions, which have a value > 0 +our $nonusedFunctions; # show all functions, which have a value == 0 +our $nPercent; # show all functions, which have a value > $nPercent +our $complete; # show all functions, which have a value == 100 +our $incomplete; # show all functions, which have a value > 0 && < 100 + +# Prototypes +sub print_usage(*); +sub read_gcov_function_file($); + +# Parse command line options +if (!GetOptions( + "usedfunctions" => \$usedFunctions, + "nonusedfunctions" => \$nonusedFunctions, + "percent=s" => \$nPercent, + "complete" => \$complete, + "incomplete" => \$incomplete, + "help" => \$help, + "version" => \$version + )) +{ + print_usage(*STDERR); + exit(1); +} + +# Check for help option +if ($help) +{ + print_usage(*STDOUT); + exit(0); +} + +# Check for version option +if ($version) +{ + print("$version_info\n"); + exit(0); +} + +# check if enough parameters +if ($#ARGV < 0) +{ + print("No input filename specified\n"); + print_usage(*STDERR); + exit(1); +} + +if ($complete) +{ + $nPercent = 100.00; +} +# ------------------------------------------------------------------------------ + +my %list = read_gcov_function_file($ARGV[0]); + +my $key; +my $value; + +while (($key, $value) = each %list) +{ + # print "function: $key = $value\n"; + if ($nonusedFunctions) + { + if ($value <= 0.00) + { + print "$key\n"; + } + } + elsif ($usedFunctions) + { + if ($value != 0.00) + { + print "$key, $value\n"; + } + } + elsif ($nPercent) + { + if ($value >= $nPercent) + { + print "$key, $value\n"; + } + } + elsif ($incomplete) + { + if ($value > 0.00 && $value < 100.00) + { + print "$key, $value\n"; + } + } + else + { + print "$key, $value\n"; + } +} + +# -------------------------------------------------------------------------------- +# Read the gcov function (gcov -f) file +# and compare line by line with the export function list +# so we get a list of functions, which are only exported, and not all stuff. + +sub read_gcov_function_file($) +{ + local *INPUT_HANDLE; + my $file = $_[0]; + my %list; + my $line = ""; + + open(INPUT_HANDLE, $file) + or die("ERROR: cannot open $file!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line (for reg exp:) + # 100.00 rtl_ustr_toDouble + if ($line =~ /^(.*) (\w+)$/ ) + { + my $percent = $1; + my $value = $2; + + $list{$value} = $percent; + } + } + close(INPUT_HANDLE); + return %list; +} + +# ---------------------------------------------------------------------------- +sub print_usage(*) +{ + local *HANDLE = $_[0]; + my $tool_name = basename($0); + + print(HANDLE <<END_OF_USAGE); + +Usage: $tool_name [OPTIONS] INPUTFILE + + -u, --usedFunctions show all functions, which have a value > 0 + -n, --nonusedFunctions show all functions, which have a value == 0 + -p, --percent show all functions, which have a value > percent + -c, --complete show all functions, which have a value == 100 + -i, --incomplete show all functions, which have a value > 0 && < 100 + + -h, --help Print this help, then exit + -v, --version Print version number, then exit + +END_OF_USAGE + ; +} diff --git a/sal/qa/helper/gcov/gcov_run.sh b/sal/qa/helper/gcov/gcov_run.sh new file mode 100755 index 000000000000..31a4c4e44dec --- /dev/null +++ b/sal/qa/helper/gcov/gcov_run.sh @@ -0,0 +1,64 @@ +#!/bin/tcsh -f + +# This is a helper file, to start a coverage test by hand + +# ----- INIT ENVIRONMENT ----- +# setup a complete build environment, copy from our beanshell environment +setenv SHELL /bin/tcsh +source /net/margritte/usr/qaapi/workspace/qadev/scripts/init/staroffice.cshrc + +# do a setsolar + +setenv SOURCE_ROOT /cws/so-cwsserv06/qadev16 +setsolar -cwsname qadev16 -sourceroot -src680 -ver m25 -jdk14 unxlngi5 + + +# ----- CLEAN OLD COVERAGE INFOS ----- + +setenv SALDIR /cws/so-cwsserv06/qadev16/SRC680/src.m25/sal + +# this is a patch for sal, to see also "ustr" in string +cd $SALDIR/rtl/source + +# strtmpl.c contains code, which is used for strings and ustrings. This file contain lot of makros +# which unpacked at compile time. Due to the fact, gcov has some problems with such things, an idea is +# to copy strtmpl.c to ustrtmpl.c and replace the include command in ustring.c +# this is done be the follows lines. + +# cat ustring.c | sed -e "s/strtmpl.c/ustrtmpl.c/" > ustring.c.new ; mv -f ustring.c.new ustring.c +# cp strtmpl.c ustrtmpl.c + +cd $SALDIR + +rm -f `find . -type f -name '*.bb' -print` +rm -f `find . -type f -name '*.bbg' -print` +rm -f `find . -type f -name '*.f' -print` +rm -f `find . -type f -name '*.da' -print` +rm -f `find . -type f -name '*.gcov' -print` + +rm -rf unxlngi5 + +# ----- START A NEW BUILD WITH COVERAGE ----- +setenv ENVCFLAGS "-O0 -ftest-coverage -fprofile-arcs" +build TESTCOVERAGE=t +deliver + + +# ----- START THE TESTS ----- + +# unsetenv ENVCFLAGS +cd cd $SALDIR/qa +# cd qa/osl/file +dmake test + + +# ----- BUILD GCOV (coverage) FILES ----- +cd cd $SALDIR/qa/helper/gcov +statistics + +# the statistics file create some *.txt files, the most interesting one is realallchecked.txt, +# which contain only the interface functions and it's run through in percent. +# the gcov_resultcompare.pl use two of these files to give out a compare. + +# usage: gcov_resultcompare.pl -o realallchecked.txt -c <other>/realallchecked.txt + diff --git a/sal/qa/helper/gcov/readme.txt b/sal/qa/helper/gcov/readme.txt new file mode 100644 index 000000000000..6c9f46b225cb --- /dev/null +++ b/sal/qa/helper/gcov/readme.txt @@ -0,0 +1,13 @@ +GCOV Coverage information helper functions + +# Files: +deprecated.txt +gcov_all +gcov_filter.pl +gcov_result.pl +gcov_resultinterpreter.pl +statistics + +\\mahler\automat\docs\qadev\baselib\gcov_result_in_db_putter.php + + diff --git a/sal/qa/helper/gcov/statistics b/sal/qa/helper/gcov/statistics new file mode 100755 index 000000000000..cbb374c172d2 --- /dev/null +++ b/sal/qa/helper/gcov/statistics @@ -0,0 +1,20 @@ +#!/bin/bash +# $Id: statistics,v 1.3 2003-06-11 16:38:03 vg Exp $ + +./gcov_filter.pl -i ../../../util/sal.map --showallfunc FOO | sort | uniq >exportedfunctions.txt + +# gives the number off all files. +./gcov_filter.pl -i ../../../util/sal.map --allfuncinfo FOO + +./gcov_all --no-percentage | sort | uniq >allchecked.txt + +# gives the number of all testable functions +echo -n " testable functions: " +cat allchecked.txt | wc -l + +# gives a list of all checked functions within gcov. +./gcov_all | sort +1 | uniq >realallchecked.txt + +# output all functions, which are not tested by gcov -f, due to the fact, that they where not found +comm -3 exportedfunctions.txt allchecked.txt >notfound.txt + diff --git a/sal/qa/inc/stringhelper.hxx b/sal/qa/inc/stringhelper.hxx new file mode 100644 index 000000000000..b284d1c0c06c --- /dev/null +++ b/sal/qa/inc/stringhelper.hxx @@ -0,0 +1,16 @@ +#ifndef STRINGHELPER_HXX +#define STRINGHELPER_HXX + +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> + +inline void operator <<= (rtl::OString& _rAsciiString, rtl::OUString const & _rUnicodeString) +{ + _rAsciiString = rtl::OUStringToOString(_rUnicodeString,RTL_TEXTENCODING_ASCII_US); +} +inline void operator <<= (rtl::OUString& _rUnicodeString, rtl::OString const & _rAsciiString ) +{ + _rUnicodeString = rtl::OStringToOUString(_rAsciiString, RTL_TEXTENCODING_ASCII_US); +} + +#endif diff --git a/sal/qa/inc/valueequal.hxx b/sal/qa/inc/valueequal.hxx new file mode 100644 index 000000000000..df989c1e90a8 --- /dev/null +++ b/sal/qa/inc/valueequal.hxx @@ -0,0 +1,133 @@ +#include <math.h> + +#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) +{ + // 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; + } + + // LLA: due to a bug in printf with '%f' and long double within linux environment + // we have to use %lf instead. + + if (_nPrec != PREC_long_double) + { + t_print(T_VERBOSE, "double equal: %.20f\n", x); + t_print(T_VERBOSE, " %.20f\n", y); + } + //here nPrecOfN is the number after dot + sal_Int32 nBeforeDot = sal_Int32( log10(x) ); + if ( nBeforeDot < 0) + { + nBeforeDot = 0; + } + //t_print(T_VERBOSE, "nPRECISION is %d\n", nPRECISION); + sal_Int32 nPrecOfN = -nPRECISION + nBeforeDot; + + if (_nPrec != PREC_long_double) + t_print(T_VERBOSE, "nPrecOfN is %d\n", nPrecOfN); + + long double nPrec = pow(0.1, -nPrecOfN); + + if (_nPrec != PREC_long_double) + t_print(T_VERBOSE, " prec: %.20f\n", nPrec); + + long double nDelta = fabs( x - y ) ; + + if (_nPrec != PREC_long_double) + { + t_print(T_VERBOSE, " delta: %.20f\n", nDelta); + t_print(T_VERBOSE, " nPrec: %.20f\n", nPrec); + t_print(T_VERBOSE, "delta must be less or equal to prec!\n\n"); + } + + if (nDelta > nPrec) + { + // t_print(T_VERBOSE, "values are not equal! ndelta:%.20f\n", nDelta); + return false; + } + // else + // { + // t_print(T_VERBOSE, "values are equal. ndelta:%.20f\n", nDelta); + return true; + // } +} + +// LLA: bool is_float_equal(float x, float y) +// LLA: { +// LLA: // due to the fact that this check looks only if both values are equal +// LLA: // we only need to look on one value +// LLA: +// LLA: // 6 digits will announce the checkPrecisionSize +// LLA: +// LLA: const sal_Int32 nPRECISION = 6; +// LLA: if (x < 0) +// LLA: { +// LLA: x = -x; +// LLA: } +// LLA: if (y < 0) +// LLA: { +// LLA: y = -y; +// LLA: } +// LLA: +// LLA: t_print(T_VERBOSE, "double equal: %.20f\n# %.20f\n", x, y); +// LLA: sal_Int32 nPrecOfN = -nPRECISION + sal_Int32( log10(x) ); +// LLA: +// LLA: t_print(T_VERBOSE, "prec: %d\n", nPrecOfN); +// LLA: double nPrec = pow(10, nPrecOfN) * 1; +// LLA: +// LLA: t_print(T_VERBOSE, " prec: %.20f\n", nPrec); +// LLA: +// LLA: double nDelta = fabs( x - y ); +// LLA: t_print(T_VERBOSE, " delta: %.20f\n\n", nDelta); +// LLA: +// LLA: if (nDelta > nPrec) +// LLA: { +// LLA: // t_print(T_VERBOSE, "values are not equal! ndelta:%.20f\n", nDelta); +// LLA: return false; +// LLA: } +// LLA: // else +// LLA: // { +// LLA: // t_print(T_VERBOSE, "values are equal. ndelta:%.20f\n", nDelta); +// LLA: return true; +// LLA: // } +// LLA: } + +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); +} diff --git a/sal/qa/libs2test.txt b/sal/qa/libs2test.txt new file mode 100644 index 000000000000..36a9f7f70c98 --- /dev/null +++ b/sal/qa/libs2test.txt @@ -0,0 +1,86 @@ +# This file contain a list of todos for testshl2 automated tests. +# +# $Id: libs2test.txt,v 1.13 2007-11-20 19:25:30 ihi Exp $ +# +# 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: temporaly 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/semaphore ; osl_Semaphore +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 seams 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/makefile.mk b/sal/qa/makefile.mk new file mode 100644 index 000000000000..cbf40966f185 --- /dev/null +++ b/sal/qa/makefile.mk @@ -0,0 +1,66 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.18 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=.. + +PRJNAME=sal +TARGET=whole_sal_qa + +# LLA: irrelevant +# ENABLE_EXCEPTIONS=TRUE +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# BEGIN ------------------------------------------------------------ +# END -------------------------------------------------------------- + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +.IF "$(runtests)"!="" +ALLTAR : test_all +.ENDIF + +# OTHER STUFF ------------------------------------------------------ +# test : test_all + +# start tests with consideration of libs2test.txt with 'dmake test' +# run through all tests directories (from libs2test.txt) and try to start all tests +# use 'dmake test TESTOPT="buildall"' + +# ALLTAR +test_all: + @echo ---------------------------------------------------------- + @echo - start sal unit tests + @echo ---------------------------------------------------------- + $(PERL) buildall.pl $(TESTOPT) diff --git a/sal/qa/osl/condition/makefile.mk b/sal/qa/osl/condition/makefile.mk new file mode 100644 index 000000000000..586908e93032 --- /dev/null +++ b/sal/qa/osl/condition/makefile.mk @@ -0,0 +1,64 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_condition + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Condition by codegen.pl +SHL1OBJS= \ + $(SLO)$/osl_Condition.obj + +SHL1TARGET= osl_Condition +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Condition +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/condition/osl_Condition.cxx b/sal/qa/osl/condition/osl_Condition.cxx new file mode 100644 index 000000000000..0e4516f6839b --- /dev/null +++ b/sal/qa/osl/condition/osl_Condition.cxx @@ -0,0 +1,387 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Condition.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <osl_Condition_Const.h> + +using namespace osl; +using namespace rtl; + + +//------------------------------------------------------------------------ +// helper functions and classes +//------------------------------------------------------------------------ + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("TRUE!\n" ): t_print("FALSE!\n" ); +} + +/** print a UNI_CODE String. +*/ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printUString_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +/** wait _nSec seconds. +*/ +void thread_sleep( sal_Int32 _nSec ) +{ + /// print statement in thread process must use fflush() to force display. + t_print("# wait %d seconds. ", _nSec ); + fflush( stdout ); + +#ifdef WNT //Windows + Sleep( _nSec * 1000 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + sleep( _nSec ); +#endif + t_print("# done\n" ); +} + +enum ConditionType +{ + thread_type_set, + thread_type_reset, + thread_type_wait, + thread_type_check +}; + +/** 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 ) { } + + ~ConditionThread( ) + { + // LLA: do not throw in DTors! + // LLA: CPPUNIT_ASSERT_MESSAGE( "#ConditionThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + ::osl::Condition& m_MyCon; + ConditionType m_MyType; + + void SAL_CALL run() + { + 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; + } + } +}; + + +//------------------------------------------------------------------------ +// test code start here +//------------------------------------------------------------------------ + +namespace osl_Condition +{ + + /** testing the method: + Condition() + */ + class ctors : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void ctors_001( ) + { + ::osl::Condition aCond; + bRes = aCond.check( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create a condition its initial check state should be sal_False.", + sal_False == bRes ); + } + + void ctors_002( ) + { + ::osl::Condition aCond; + aCond.set( ); + bRes = aCond.check( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create a condition and set it.", + sal_True == bRes ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class ctors + + + /** testing the method: + void set() + */ + class set : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2; + + void set_001( ) + { + ::osl::Condition aCond; + aCond.set( ); + bRes = aCond.check( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: check state should be sal_True after set.", + sal_True == bRes ); + } + + void set_002( ) + { + ::osl::Condition aCond; + ConditionThread myThread1( aCond, thread_type_wait ); + myThread1.create(); + bRes = myThread1.isRunning( ); + + ConditionThread myThread2( aCond, thread_type_set ); + myThread2.create(); + thread_sleep(1); + bRes1 = myThread1.isRunning( ); + bRes2 = aCond.check( ); + + myThread1.join( ); + myThread2.join( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: use one thread to set the condition in order to release another thread.", + sal_True == bRes && sal_False == bRes1 && sal_True == bRes2 ); + } + + + CPPUNIT_TEST_SUITE( set ); + CPPUNIT_TEST( set_001 ); + CPPUNIT_TEST( set_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class set + + + /** testing the method: + void reset() + */ + class reset : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2; + + void reset_001( ) + { + ::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.", + sal_True == bRes && sal_False == bRes1 && sal_False == bRes2 ); + } + + void reset_002( ) + { + ::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.", + ( sal_False == bRes && sal_True == bRes1 ) ); + } + + CPPUNIT_TEST_SUITE( reset ); + CPPUNIT_TEST( reset_001 ); + CPPUNIT_TEST( reset_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class reset + + + /** testing the method: + Result wait(const TimeValue *pTimeout = 0) + */ + class wait : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2; + TimeValue *tv1; + + void setUp( ) + { + tv1 = (TimeValue*)malloc(sizeof(TimeValue)); + tv1->Seconds = 1; + + } + + void tearDown( ) + { + free( tv1 ); + } + + + void wait_001( ) + { + ::osl::Condition cond1; + ::osl::Condition cond2; + ::osl::Condition cond3; + + cond1.set(); + cond2.set(); + +osl::Condition::Result r1=cond1.wait(tv1); +osl::Condition::Result r2=cond2.wait(); +osl::Condition::Result r3=cond3.wait(tv1); +fprintf(stderr,"%d %d %d\n",r1,r2,r3); + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test three types of wait.", + (cond1.wait(tv1) == ::osl::Condition::result_ok) && + (cond2.wait() == ::osl::Condition::result_ok) && + (cond3.wait(tv1) == ::osl::Condition::result_timeout) ); + + } + + void wait_002( ) + { + ::osl::Condition aCond; + ::osl::Condition::Result wRes, wRes1; + + aCond.reset( ); + bRes = aCond.check( ); + wRes = aCond.wait( tv1 ); + + aCond.set( ); + wRes1 = aCond.wait( tv1 ); + bRes1 = aCond.check( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: wait a condition after set/reset.", + ( sal_False == bRes ) && ( sal_True == bRes1 ) && + ( ::osl::Condition::result_timeout == wRes ) && + ( ::osl::Condition::result_ok == wRes1 ) ); + } + + CPPUNIT_TEST_SUITE( wait ); + CPPUNIT_TEST( wait_001 ); + CPPUNIT_TEST( wait_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class wait + + + /** testing the method: + sal_Bool check() + */ + class check : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2; + + void check_001( ) + { + ::osl::Condition aCond; + + aCond.reset( ); + bRes = aCond.check( ); + aCond.set( ); + bRes1 = aCond.check( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: check the condition states.", + ( sal_False == bRes && sal_True == bRes1 ) ); + } + + void check_002( ) + { + ::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.", + ( sal_True == bRes && sal_False == bRes1 ) ); + } + + CPPUNIT_TEST_SUITE( check ); + CPPUNIT_TEST( check_001 ); + CPPUNIT_TEST( check_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class check + + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Condition::ctors, "osl_Condition"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Condition::set, "osl_Condition"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Condition::reset, "osl_Condition"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Condition::wait, "osl_Condition"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Condition::check, "osl_Condition"); +// ----------------------------------------------------------------------------- + +} // namespace osl_Condition + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; 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 000000000000..608bd38e3a64 --- /dev/null +++ b/sal/qa/osl/condition/osl_Condition_Const.h @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Condition_Const.h,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_CONDITION_CONST_H_ +#define _OSL_CONDITION_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +#ifndef _OSL_THREAD_HXX_ +#include <osl/thread.hxx> +#endif +#include <osl/mutex.hxx> +#include <osl/pipe.hxx> + +#ifndef _OSL_SEMAPHOR_HXX_ +#include <osl/semaphor.hxx> +#endif + +#ifndef _OSL_CONDITION_HXX_ +#include <osl/conditn.hxx> +#endif +#include <osl/time.h> + +#ifdef UNX +#include <unistd.h> +#endif + +#include <testshl/simpleheader.hxx> + +#define OSLTEST_DECLARE_USTRING( str_name, str_value ) \ + ::rtl::OUString a##str_name = rtl::OUString::createFromAscii( str_value ) + +//------------------------------------------------------------------------ +// condition names +//------------------------------------------------------------------------ +OSLTEST_DECLARE_USTRING( TestCon, "testcondition" ); + +const char pTestString[17] = "Sun Microsystems"; + + +#endif /* _OSL_CONDITION_CONST_H_ */ diff --git a/sal/qa/osl/file/makefile.mk b/sal/qa/osl/file/makefile.mk new file mode 100644 index 000000000000..0d83a06b7124 --- /dev/null +++ b/sal/qa/osl/file/makefile.mk @@ -0,0 +1,89 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.13 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_file + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# --- BEGIN -------------------------------------------------------- +SHL1OBJS= \ + $(SLO)$/osl_File.obj +SHL1TARGET= osl_File +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +#------------------------------------------------------------------- + +SHL2OBJS=$(SLO)$/test_cpy_wrt_file.obj +SHL2TARGET=tcwf +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +SHL2IMPLIB=i$(SHL2TARGET) +SHL2DEF=$(MISC)$/$(SHL2TARGET).def +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map +DEF2NAME =$(SHL2TARGET) + + +# END -------------------------------------------------------------- + +# --- BEGIN -------------------------------------------------------- +SHL3OBJS= \ + $(SLO)$/osl_old_test_file.obj +SHL3TARGET= osl_old_test_file +SHL3STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL3IMPLIB= i$(SHL3TARGET) + +DEF3NAME =$(SHL3TARGET) +SHL3VERSIONMAP = $(PRJ)$/qa$/export.map +# END -------------------------------------------------------------- + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/file/osl_File.cxx b/sal/qa/osl/file/osl_File.cxx new file mode 100644 index 000000000000..a1cb3fa54e9e --- /dev/null +++ b/sal/qa/osl/file/osl_File.cxx @@ -0,0 +1,6859 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_File.cxx,v $ + * $Revision: 1.14 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +#include "osl/thread.h" + +#include "rtl/ustrbuf.hxx" +#include <osl/file.hxx> +#include <osl_File_Const.h> + +#include <testshl/simpleheader.hxx> + +// #ifdef WNT +// # define UNICODE +// # define WIN32_LEAN_AND_MEAN +// # include <windows.h> +// # include <tchar.h> +// #endif + + +using namespace osl; +using namespace rtl; + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +/** detailed wrong message. +*/ +inline ::rtl::OString errorToString( const ::osl::FileBase::RC _nError ) +{ + ::rtl::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; +} + +rtl::OUString errorToStr( ::osl::FileBase::RC const& nError) +{ + rtl::OUStringBuffer suBuf; + suBuf.append( rtl::OUString::createFromAscii("The returned error is: ") ); + suBuf.append( rtl::OStringToOUString(errorToString(nError), RTL_TEXTENCODING_ASCII_US) ); + suBuf.append( rtl::OUString::createFromAscii("!\n") ); + return suBuf.makeStringAndClear(); +} + +/** print a file type name. +*/ +inline void printFileType( const ::osl::FileStatus::Type nType ) +{ + t_print( "#printFileType# " ); + switch ( nType ) { + case ::osl::FileStatus::Directory: + t_print( "This file is a: Directory.\n" ); + break; + case ::osl::FileStatus::Volume: + t_print( "This file is a: volume device.\n" ); + break; + case ::osl::FileStatus::Regular: + t_print( "This file is a: regular file.\n" ); + break; + case ::osl::FileStatus::Fifo: + t_print( "This file is a: fifo.\n" ); + break; + case ::osl::FileStatus::Socket: + t_print( "This file is a: socket.\n" ); + break; + case ::osl::FileStatus::Link: + t_print( "This file is a: link file.\n" ); + break; + case ::osl::FileStatus::Special: + t_print( "This file is a: special.\n" ); + break; + case ::osl::FileStatus::Unknown: + t_print( "The file type is unknown %d \n", nType ); + break; + } +} + +/** print a file attributes. +*/ +inline void printFileAttributes( const sal_Int64 nAttributes ) +{ + t_print( "#printFileAttributes# This file is a: (" ); + if ( ( nAttributes | Attribute_ReadOnly ) == nAttributes ) + t_print( " ReadOnly " ); + if ( ( nAttributes | Attribute_Hidden ) == nAttributes ) + t_print( " Hidden " ); + if ( ( nAttributes | Attribute_Executable ) == nAttributes ) + t_print( " Executable " ); + if ( ( nAttributes | Attribute_GrpWrite ) == nAttributes ) + t_print( " GrpWrite " ); + if ( ( nAttributes | Attribute_GrpRead ) == nAttributes ) + t_print( " GrpRead " ); + if ( ( nAttributes | Attribute_GrpExe ) == nAttributes ) + t_print( " GrpExe " ); + if ( ( nAttributes | Attribute_OwnWrite ) == nAttributes ) + t_print( " OwnWrite " ); + if ( ( nAttributes | Attribute_OwnRead ) == nAttributes ) + t_print( " OwnRead " ); + if ( ( nAttributes | Attribute_OwnExe ) == nAttributes ) + t_print( " OwnExe " ); + if ( ( nAttributes | Attribute_OthWrite ) == nAttributes ) + t_print( " OthWrite " ); + if ( ( nAttributes | Attribute_OthRead ) == nAttributes ) + t_print( " OthRead " ); + if ( ( nAttributes | Attribute_OthExe ) == nAttributes ) + t_print( " OthExe " ); + t_print( ") file!\n" ); +} + +/** print a UNI_CODE file name. +*/ +inline void printFileName( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print( "#printFileName_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print( "%s\n", aString.getStr( ) ); +} + +/** print a ASCII_CODE file name. +*/ +inline void printFileName( const sal_Char * str ) +{ + t_print( "#printFileName_a# " ); + t_print( "%s\n", str ); +} + +/** print an output wrong message. +*/ +inline void printError( const ::osl::FileBase::RC nError ) +{ + t_print( "#printError# " ); + printFileName( errorToStr(nError) ); +} + +/** print an signed Integer Number. +*/ +inline void printInt( sal_Int64 i ) +{ + t_print( "#printInt_i64# " ); + t_print( "The Integer64 is %lld\n", i); +} + +/** print an unsigned Integer Number. +*/ +inline void printInt( sal_uInt64 i ) +{ + t_print( "#printInt_u64# " ); + t_print( "The unsigned Integer64 is %llu\n", i); +} + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + t_print( "#printBool# " ); + ( sal_True == bOk ) ? t_print( "YES!\n" ): t_print( "NO!\n" ); +} + +/** print struct TimeValue in local time format. +*/ +inline void printTime( TimeValue *tv ) +{ + oslDateTime *pDateTime = ( oslDateTime* )malloc( sizeof( oslDateTime ) ) ; + CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pDateTime != NULL ); + TimeValue *pLocalTV = ( TimeValue* )malloc( sizeof( TimeValue ) ); + CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pLocalTV != NULL ); + + CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_getLocalTimeFromSystemTime ",sal_True == osl_getLocalTimeFromSystemTime( tv, pLocalTV ) ); + CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_gepDateTimeFromTimeValue ",sal_True == osl_getDateTimeFromTimeValue( pLocalTV, pDateTime ) ); + + t_print( "#printTime# " ); + t_print( " Time is: %d/%d/%d ", pDateTime->Month, pDateTime->Day, pDateTime->Year); + switch ( pDateTime->DayOfWeek ) + { + case 0: t_print("Sun. "); break; + case 1: t_print("Mon. "); break; + case 2: t_print("Tue. "); break; + case 3: t_print("Thr. "); break; + case 4: t_print("Wen. "); break; + case 5: t_print("Fri. "); break; + case 6: t_print("Sat. "); break; + } + t_print( " %d:%d:%d %d nsecs\n", pDateTime->Hours, pDateTime->Minutes, pDateTime->Seconds, pDateTime->NanoSeconds); + + free( pDateTime ); + free( pLocalTV ); +} + +/** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX. +*/ + +#if ( defined UNX ) || ( defined OS2 ) //precision of time in Windows is better than UNX +# define delta 2000 //time precision, 2000ms +#else +# define delta 1800 //time precision, 1.8s +#endif + +inline sal_Int64 t_abs64(sal_Int64 _nValue) +{ + // std::abs() seems to have some ambiguity problems (so-texas) + // return abs(_nValue); + t_print("t_abs64(%ld)\n", _nValue); + // CPPUNIT_ASSERT(_nValue < 2147483647); + + if (_nValue < 0) + { + _nValue = -_nValue; + } + return _nValue; +} + +inline sal_Bool t_compareTime( TimeValue *m_aEndTime, TimeValue *m_aStartTime, sal_Int32 nDelta) +{ + // sal_uInt64 uTimeValue; + // sal_Int64 iTimeValue; + // + // iTimeValue = t_abs64(( tv1->Seconds - tv2->Seconds) * 1000000000 + tv1->Nanosec - tv2->Nanosec); + // uTimeValue = ( iTimeValue / 1000000 ); + + 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. +*/ +inline sal_Bool compareFileName( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ) +{ + sal_Bool bOk; +//on Windows, the seperatar is '\', so here change to '/', then compare +#if defined (WNT ) + ::rtl::OUString ustr1new,ustr2new; + sal_Unicode reverseSlash = (sal_Unicode)'\\'; + + if (ustr1.lastIndexOf(reverseSlash) != -1) + ustr1new = ustr1.replace(reverseSlash,(sal_Unicode)'/'); + else + ustr1new = ustr1; + if (ustr2.lastIndexOf(reverseSlash) != -1) + ustr2new = ustr2.replace(reverseSlash,(sal_Unicode)'/'); + else + ustr2new = ustr2; + bOk = ustr1new.equalsIgnoreAsciiCase( ustr2new ) ; +#else + bOk = ustr1.equalsIgnoreAsciiCase( ustr2 ); +#endif + return bOk; +} + +/** compare a OUString and an ASCII file name. +*/ +inline sal_Bool compareFileName( const ::rtl::OUString & ustr, const sal_Char *astr ) +{ + (void)ustr; + ::rtl::OUString ustr1 = rtl::OUString::createFromAscii( astr ); + sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr1 ); + + 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:///";. +*/ +inline sal_Bool isURL( const sal_Char *pathname ) +{ + return ( 0 == strncmp( pathname, FILE_PREFIX, sizeof( FILE_PREFIX ) - 1 ) ); +} + +/** 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:///";. +*/ +inline sal_Bool isURL( const ::rtl::OUString pathname ) +{ + return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False ); +} + +/** concat two part to form a URL or system path, add PATH_SEPERATOR between them if necessary, add "file:///" to begining if necessary. +*/ +inline void concatURL( ::rtl::OUString & pathname1, const ::rtl::OUString & pathname2 ) +{ + //check if pathname1 is full qualified URL; + if ( !isURL( pathname1 ) ) + { + ::rtl::OUString aPathName = pathname1.copy( 0 ); + ::osl::FileBase::getFileURLFromSystemPath( pathname1, aPathName ); //convert if not full qualified URL + pathname1 = aPathName.copy( 0 ); + } + + sal_Int32 index = 0; + //check if '/' is in the end of pathname1 or at the begin of pathname2; + if ( ( ( index = pathname1.lastIndexOf( aSlashURL ) ) != ( pathname1.getLength( ) - 1 ) ) && + ( ( index = pathname2.indexOf( aSlashURL ) ) != 0 ) ) + pathname1 += aSlashURL; + pathname1 += pathname2; +} + +/** create a temp test file using OUString name of full qualified URL or system path. +*/ +inline void createTestFile( const ::rtl::OUString filename ) +{ + ::rtl::OUString aPathURL = filename.copy( 0 ); + ::osl::FileBase::RC nError; + + if ( !isURL( filename ) ) + ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL + + //::std::auto_ptr<File> pFile( new File( aPathURL ) ); + File aFile(aPathURL); + //nError = pFile->open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create ); + nError = aFile.open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create ); + //CPPUNIT_ASSERT_MESSAGE( "In createTestFile Function: creation ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) ); + if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST )) + { + t_print("createTestFile failed!\n"); + } + aFile.close(); + +} + +/** create a temp test file using OUString name of full qualified URL or system path in a base directory. +*/ +inline void createTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename ) +{ + ::rtl::OUString aBaseURL = basename.copy( 0 ); + + concatURL( aBaseURL, filename ); + createTestFile( aBaseURL ); +} + +/** detete a temp test file using OUString name. +*/ +inline void deleteTestFile( const ::rtl::OUString filename ) +{ + // LLA: t_print("deleteTestFile\n"); + ::rtl::OUString aPathURL = filename.copy( 0 ); + ::osl::FileBase::RC nError; + + if ( !isURL( filename ) ) + ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL + + nError = ::osl::File::setAttributes( aPathURL, Attribute_GrpWrite| Attribute_OwnWrite| Attribute_OthWrite ); // if readonly, make writtenable. + CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) ); + + nError = ::osl::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. +*/ +inline void deleteTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename ) +{ + ::rtl::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. +*/ +inline void createTestDirectory( const ::rtl::OUString dirname ) +{ + ::rtl::OUString aPathURL = dirname.copy( 0 ); + ::osl::FileBase::RC nError; + + if ( !isURL( dirname ) ) + ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL + nError = ::osl::Directory::create( aPathURL ); + //CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) ); + if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST )) + t_print("createTestDirectory failed!\n"); +} + +/** create a temp test directory using OUString name of full qualified URL or system path in a base directory. +*/ +inline void createTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname ) +{ + ::rtl::OUString aBaseURL = basename.copy( 0 ); + ::rtl::OString aString; + + concatURL( aBaseURL, dirname ); + createTestDirectory( aBaseURL ); +} + +/** delete a temp test directory using OUString name of full qualified URL or system path. +*/ +inline void deleteTestDirectory( const ::rtl::OUString dirname ) +{ + // LLA: t_print("deleteTestDirectory\n"); + ::rtl::OUString aPathURL = dirname.copy( 0 ); + ::osl::FileBase::RC nError; + // LLA: printFileName(aPathURL); + if ( !isURL( dirname ) ) + ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL + + ::osl::Directory testDir( aPathURL ); + if ( testDir.isOpen( ) == sal_True ) + { + // LLA: t_print("#close Dir\n"); + testDir.close( ); //close if still open. + } + + nError = ::osl::Directory::remove( aPathURL ); + // LLA: printError(nError); + // LLA: if (( ::osl::FileBase::E_None == nError )) + // LLA: { + // LLA: t_print("nError == E_None\n"); + // LLA: } + // LLA: else if ( ( nError == ::osl::FileBase::E_NOENT )) + // LLA: { + // LLA: t_print("nError == E_NOENT\n"); + // LLA: } + // LLA: else + // LLA: { + // LLA: // t_print("nError == %d\n", nError); + // LLA: } + rtl::OUString strError = rtl::OUString::createFromAscii( "In deleteTestDirectory function: remove Directory "); + strError += aPathURL; + CPPUNIT_ASSERT_MESSAGE( strError, ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) ); + // LLA: if (! ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT )) + // LLA: { + // LLA: t_print("In deleteTestDirectory function: remove\n"); + // LLA: } +} + +/** delete a temp test directory using OUString name of full qualified URL or system path in a base directory. +*/ +inline void deleteTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname ) +{ + ::rtl::OUString aBaseURL = basename.copy( 0 ); + + concatURL( aBaseURL, dirname ); + deleteTestDirectory( aBaseURL ); +} + + +/** Check for the file and directory access right. +*/ +typedef enum { + osl_Check_Mode_Exist, + osl_Check_Mode_OpenAccess, + osl_Check_Mode_ReadAccess, + osl_Check_Mode_WriteAccess +} oslCheckMode; + +// not used here +inline sal_Bool checkFile( const ::rtl::OUString & str, oslCheckMode nCheckMode ) +{ + ::osl::FileBase::RC nError1, nError2; + ::osl::File testFile( str ); + sal_Bool bCheckResult; + + bCheckResult = sal_False; + nError1 = testFile.open ( OpenFlag_Read ); + if ( ( ::osl::FileBase::E_NOENT != nError1 ) && ( ::osl::FileBase::E_ACCES != nError1 ) ){ + + switch ( nCheckMode ) { + case osl_Check_Mode_Exist: + /// check if the file is exist. + if ( ::osl::FileBase::E_None == nError1 ) + bCheckResult = sal_True; + break; + case osl_Check_Mode_OpenAccess: + /// check if the file is openable. + if ( ::osl::FileBase::E_None == nError1 ) + bCheckResult = sal_True; + break; + case osl_Check_Mode_WriteAccess: + /// check the file name and whether it can be write. + /// write chars into the file. + //testFile.close( ); + //testFile.open( OpenFlag_Write ); + sal_uInt64 nCount_write; + nError2 = testFile.write( pBuffer_Char, 10, nCount_write ); + if ( ::osl::FileBase::E_None == nError2 ) + bCheckResult = sal_True; + break; + + default: + bCheckResult = sal_False; + }/// swith + + nError2 = testFile.close( ); + CPPUNIT_ASSERT_MESSAGE( " in CheckFile() function, close file ", nError2 == FileBase::E_None ); + + } + + return bCheckResult; +} + +//check if the file exist +inline sal_Bool ifFileExist( const ::rtl::OUString & str ) +{ + sal_Bool bCheckResult = sal_False; + +/*#ifdef WNT + ::rtl::OUString aUStr = str.copy( 0 ); + if ( isURL( str ) ) + ::osl::FileBase::getSystemPathFromFileURL( str, aUStr ); + + ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ); + const char *path = aString.getStr( ); + if (( _access( path, 0 ) ) != -1 ) + bCheckResult = sal_True; +#else*/ + ::rtl::OString aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + // const char *path = aString.getStr( ); + ::osl::File testFile( str ); + bCheckResult = ( osl::FileBase::E_None == testFile.open( OpenFlag_Read ) ); + //if (bCheckResult) + //t_print("%s exist!\n", path); + //else + //t_print("%s not exist!\n", path); +//#endif + return bCheckResult; + +} + +//check if the file can be writen +inline sal_Bool ifFileCanWrite( const ::rtl::OUString & str ) +{ + sal_Bool bCheckResult = sal_False; + //on Windows, the file has no write right, but can be written +#ifdef WNT + ::rtl::OUString aUStr = str.copy( 0 ); + if ( isURL( str ) ) + ::osl::FileBase::getSystemPathFromFileURL( str, aUStr ); + + ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ); + const char *path = aString.getStr( ); + if (( _access( path, 2 ) ) != -1 ) + bCheckResult = sal_True; + //on UNX, just test if open success with OpenFlag_Write +#else + ::osl::File testFile( str ); + bCheckResult = (osl::FileBase::E_None == testFile.open( OpenFlag_Write )); +#endif + return bCheckResult; +} + +inline sal_Bool checkDirectory( const ::rtl::OUString & str, oslCheckMode nCheckMode ) +{ + rtl::OUString aUString; + DirectoryItem rItem; + FileBase::RC rc; + sal_Bool bCheckResult= sal_False; + + //::std::auto_ptr<Directory> pDir( new Directory( str ) ); + Directory aDir( str ); + rc = aDir.open( ); + + if ( ( ::osl::FileBase::E_NOENT != rc ) && ( ::osl::FileBase::E_ACCES != rc ) ){ + + switch ( nCheckMode ) { + case osl_Check_Mode_Exist: + if ( rc == ::osl::FileBase::E_None ) + bCheckResult = sal_True; + break; + case osl_Check_Mode_OpenAccess: + if ( rc == ::osl::FileBase::E_None ) + bCheckResult = sal_True; + break; + case osl_Check_Mode_ReadAccess: + //rc = pDir->getNextItem( rItem, 0 ); + rc = aDir.getNextItem( rItem, 0 ); + if ( ( rc == ::osl::FileBase::E_None ) || ( rc == ::osl::FileBase::E_NOENT ) ) + bCheckResult = sal_True; + else + bCheckResult = sal_False; + break; + case osl_Check_Mode_WriteAccess: + ( ( aUString += str ) += aSlashURL ) += aTmpName2; + //if ( ( rc = pDir->create( aUString ) ) == ::osl::FileBase::E_None ) + if ( ( rc = Directory::create( aUString ) ) == ::osl::FileBase::E_None ) + { + bCheckResult = sal_True; + //rc = pDir->remove( aUString ); + rc = Directory::remove( aUString ); + CPPUNIT_ASSERT( rc == ::osl::FileBase::E_None ); + } + else + bCheckResult = sal_False; + break; + + default: + bCheckResult = sal_False; + }// switch + + rc = aDir.close( ); + CPPUNIT_ASSERT( rc == FileBase::E_None ); + + }//if + + return bCheckResult; +} + +/** construct error message +*/ +inline ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "") +{ + ::rtl::OUString aUString; + if ( returnVal.equals( rightVal ) ) + return aUString; + aUString += ::rtl::OUString::createFromAscii(msg); + aUString += ::rtl::OUString::createFromAscii(": the returned value is '"); + aUString += returnVal; + aUString += ::rtl::OUString::createFromAscii("', but the value should be '"); + aUString += rightVal; + aUString += ::rtl::OUString::createFromAscii("'."); + return aUString; +} + +/** Change file mode, two version in UNIX and Windows;. +*/ +#if ( defined UNX ) || ( defined OS2 ) //chmod() method is differ in Windows +inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode ) +{ + rtl::OString aString; + rtl::OUString aUStr = filepath.copy( 0 ); + + if ( isURL( filepath ) ) + ::osl::FileBase::getSystemPathFromFileURL( filepath, aUStr ); + aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ); + chmod( aString.getStr( ), mode ); +} +#else //Windows version +inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode ) +{ + (void)filepath; + (void)mode; + t_print("this method is not implemented yet"); +} +#endif + +inline ::rtl::OUString getCurrentPID( void ); + + + +//------------------------------------------------------------------------ +// Beginning of the test cases for FileBase class +//------------------------------------------------------------------------ +namespace osl_FileBase +{ + +#if 0 //~ this function has been deprecated + //--------------------------------------------------------------------- + // testing the method + // static inline RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL ) + // + // The illegal characters are ;+=[]',\"*\\<>/?:|. + // because getCanonicalName method is not implemented yet and will be deprecated in the future, this test is not necessary. + //--------------------------------------------------------------------- + + class getCanonicalName:public CppUnit::TestFixture + { + + public: + ::osl::FileBase::RC nError; + + void getCanonicalName_001( ) + { + ::rtl::OUString aUStr_ValidURL; + nError = ::osl::FileBase::getCanonicalName( aCanURL1, aUStr_ValidURL ); + + CPPUNIT_ASSERT_MESSAGE("test for getCanonicalName function: check valid and unused file name", + ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL1 ) ); + } + + void getCanonicalName_002( ) + { + ::rtl::OUString aUStr_ValidURL; + + createTestFile( aCanURL1 ); + nError = ::osl::FileBase::getCanonicalName( aCanURL1, aUStr_ValidURL ); + deleteTestFile( aCanURL1 ); + + CPPUNIT_ASSERT_MESSAGE( " test for getCanonicalName function: an existed file name, should different from the request, it did not passed(W32)(UNX)", + ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL1 ) ); + } + + void getCanonicalName_003( ) + { + ::rtl::OUString aUStr_ValidURL; + nError = ::osl::FileBase::getCanonicalName ( aCanURL2, aUStr_ValidURL ); + + CPPUNIT_ASSERT_MESSAGE( " test for getCanonicalName function: invalid file name, should different from the request, it did not passed(W32)(UNX)", + ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL2 ) ); + } + + CPPUNIT_TEST_SUITE( getCanonicalName ); + CPPUNIT_TEST( getCanonicalName_001 ); + CPPUNIT_TEST( getCanonicalName_002 ); + CPPUNIT_TEST( getCanonicalName_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getCanonicalName +#endif + + //--------------------------------------------------------------------- + // testing the method + // static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL, + // const ::rtl::OUString& ustrRelativeFileURL, + // ::rtl::OUString& ustrAbsoluteFileURL ) + //--------------------------------------------------------------------- + + class getAbsoluteFileURL:public CppUnit::TestFixture + { + //::osl::FileBase aFileBase; + ::rtl::OUString aResultURL1, aResultURL2, aResultURL3, aResultURL4, aResultURL5, aResultURL6; + // ::osl::FileBase::RC nError; + sal_Bool bOk; + + public: + + void check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL, rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::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( ); + + }; //class getAbsoluteFileURL + +/* use coding format as same as getSystemPathFromFileURL + // initialization + void setUp( ) + { + sal_Char pResultURL1[] = "/relative/file1"; + sal_Char pResultURL2[] = "/relative/file2"; + sal_Char pResultURL3[] = "/file3"; + sal_Char pResultURL4[] = "/file4"; + sal_Char pResultURL5[] = "/canonical.name"; + sal_Char pResultURL6[] = "/relative/"; + aResultURL1 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL1 ) ); + aResultURL2 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL2 ) ); + aResultURL3 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL3 ) ); + aResultURL4 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL4 ) ); + aResultURL5 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL5 ) ); + aResultURL6 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL6 ) ); + } + + void tearDown( ) + { + } + + // test code + void getAbsoluteFileURL_001( ) + { + ::rtl::OUString aUStr_AbsURL; + + ::osl::FileBase::RC nError11 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL1, aUStr_AbsURL ); + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL(' "); + suError += aUserDirectoryURL; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aRelURL1; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aUStr_AbsURL; + suError += outputError( aUStr_AbsURL, aResultURL1, "' ),"); + + sal_Bool nError12 = aUStr_AbsURL.equals( aResultURL1 ); + ::osl::FileBase::RC nError21 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL2, aUStr_AbsURL ); + sal_Bool nError22 = aUStr_AbsURL.equals( aResultURL2 ); + ::osl::FileBase::RC nError31 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL3, aUStr_AbsURL ); + sal_Bool nError32 = aUStr_AbsURL.equals( aResultURL3 ); + ::osl::FileBase::RC nError41 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL4, aUStr_AbsURL ); + sal_Bool nError42 = aUStr_AbsURL.equals( aResultURL4 ); + ::osl::FileBase::RC nError61 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL6, aUStr_AbsURL ); + sal_Bool nError62 = aUStr_AbsURL.equals( aResultURL6 ); + printFileName( aUStr_AbsURL ); + printFileName( aResultURL6 ); + + CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: valid file name with valid directory", + ( ::osl::FileBase::E_None == nError11 ) && ( sal_True == nError12 ) && + ( ::osl::FileBase::E_None == nError21 ) && ( sal_True == nError22 ) && + ( ::osl::FileBase::E_None == nError31 ) && ( sal_True == nError32 ) && + ( ::osl::FileBase::E_None == nError41 ) && ( sal_True == nError42 ) && + ( ::osl::FileBase::E_None == nError61 ) && ( sal_True == nError62 ) ); + } + + +#if ( defined UNX ) || ( defined OS2 ) //Link is not defined in Windows + void getAbsoluteFileURL_002( ) + { + ::rtl::OUString aUStr_AbsURL, aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys ); + ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file"); + ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/canonical.name"); + + rtl::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( fd == 0 ); + + nError = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aLnkURL1, aUStr_AbsURL ); + bOk = aUStr_AbsURL.equals( aResultURL5 ); + + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL(' "); + suError += aUserDirectoryURL; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aLnkURL1; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aUStr_AbsURL; + suError += outputError( aUStr_AbsURL, aResultURL5, "' ),"); + //printFileName(suError); + + deleteTestFile( aCanURL1 ); + fd = remove( strLinkFileName.getStr() ); + CPPUNIT_ASSERT( fd == 0 ); + + CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: URL contain link( Solaris version )", + ( ::osl::FileBase::E_None == nError ) && ( sal_True == bOk ) ); + } +#else //Windows version + void getAbsoluteFileURL_002( ) + { + CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: URL contain link( Windows version )", + 1 ); + } +#endif + + void getAbsoluteFileURL_003( ) + { +// LLA: may be a wrong test, aTmpName1 not a real URL +#if 0 + ::rtl::OUString aUStr_AbsURL; + + nError = aFileBase.getAbsoluteFileURL( aTmpName1, aRelURL1, aUStr_AbsURL ); //base dir invalid error + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL('"); + suError += aTmpName1; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aRelURL1; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aUStr_AbsURL; + suError += ::rtl::OUString::createFromAscii("' ),Parameter is invalid. it ignore the invalid base in Windows, did not pass in (W32), the reason maybe caused by the similar bug with getSystemPathFromFileURL() "); + + CPPUNIT_ASSERT_MESSAGE( suError, ( ::osl::FileBase::E_INVAL == nError ) ); +#endif + } + + //use ".." in relartive path, the BasePath must exist on the file system + void getAbsoluteFileURL_004( ) + { + //create two level directories under $Temp/PID/ + ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1"); + createTestDirectory( aUStrUpBase ); + ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1/dir1"); + createTestDirectory( aUStrBase ); + + ::rtl::OUString aUStrRelar = ::rtl::OUString::createFromAscii("../../mytestfile"); + ::rtl::OUString aUStr_AbsURL; + ::rtl::OUString aResultURL6 = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/mytestfile"); + + nError = aFileBase.getAbsoluteFileURL( aUStrBase, aUStrRelar, aUStr_AbsURL ); + bOk = aUStr_AbsURL.equals( aResultURL6 ); + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL('"); + suError += aUStrBase; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aUStrRelar; + suError += ::rtl::OUString::createFromAscii("', '"); + suError += aUStr_AbsURL; + suError += outputError( aUStr_AbsURL, aResultURL6, "' ), did not pass on Win32 "); + + deleteTestDirectory( aUStrBase ); + deleteTestDirectory( aUStrUpBase ); + + CPPUNIT_ASSERT_MESSAGE( suError, ( ::osl::FileBase::E_None == nError ) && ( sal_True == bOk ) ); + } + + CPPUNIT_TEST_SUITE( getAbsoluteFileURL ); + CPPUNIT_TEST( getAbsoluteFileURL_001 ); + CPPUNIT_TEST( getAbsoluteFileURL_002 ); + CPPUNIT_TEST( getAbsoluteFileURL_003 ); + CPPUNIT_TEST( getAbsoluteFileURL_004 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getAbsoluteFileURL*/ + + void getAbsoluteFileURL::check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL, rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr ) + { + rtl::OUString suRelativeURL = rtl::OStringToOUString(_sRelativeURL, RTL_TEXTENCODING_UTF8); + rtl::OString sBaseURL = rtl::OUStringToOString(_suBaseURL, RTL_TEXTENCODING_UTF8); + rtl::OUString suResultURL; + osl::FileBase::RC nError = FileBase::getAbsoluteFileURL( _suBaseURL, suRelativeURL, suResultURL ); + rtl::OString sResultURL = rtl::OUStringToOString( suResultURL, RTL_TEXTENCODING_UTF8); + rtl::OString sError = errorToString(nError); + t_print("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n", sBaseURL.getStr(), _sRelativeURL.getStr(),sResultURL.getStr(), sError.getStr() ); + CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: error number is wrong", nError == _nAssumeError ); + if ( nError == ::osl::FileBase::E_None ) + { + sal_Bool bStrAreEqual = _suAssumeResultStr.equals( suResultURL ); + CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: ResultURL is not equal to expected URL ", bStrAreEqual == sal_True ); + } + } + + void getAbsoluteFileURL::getAbsoluteFileURL_001_1() + { + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/file1") ); + check_getAbsoluteFileURL( aUserDirectoryURL, "relative/file1",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_2() + { + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/file2") ); + check_getAbsoluteFileURL( aUserDirectoryURL, "relative/./file2",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_3() + { + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/file3") ); + check_getAbsoluteFileURL( aUserDirectoryURL, "relative/../file3",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_4() + { + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/file4") ); + check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/../file4",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_5() + { + rtl::OUString suAssume; +#if ( defined UNX ) + suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/") ); +#else + suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative") ); +#endif + check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/.",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_6() + { + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.relative") ); + check_getAbsoluteFileURL( aUserDirectoryURL, "./.relative",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_7() + { + rtl::OUString suAssume; +#if (defined UNX ) + suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.a/") ); +#else //windows + suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.a") ); +#endif + check_getAbsoluteFileURL( aUserDirectoryURL, "./.a/mydir/..",::osl::FileBase::E_None, suAssume ); + } + void getAbsoluteFileURL::getAbsoluteFileURL_001_8() + { + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/tmp/ok") ); +#if ( defined UNX ) || ( defined OS2 ) + 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 ) || ( defined OS2 ) //Link is not defined in Windows + ::rtl::OUString aUStr_AbsURL, aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys ); + ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file"); + ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/canonical.name"); + + rtl::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( fd == 0 ); + rtl::OString sLnkURL = OUStringToOString( aLnkURL1, RTL_TEXTENCODING_ASCII_US ); + rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/canonical.name") ); + check_getAbsoluteFileURL( aUserDirectoryURL, sLnkURL, ::osl::FileBase::E_None, suAssume ); + deleteTestFile( aCanURL1 ); + fd = remove( strLinkFileName.getStr() ); + CPPUNIT_ASSERT( fd == 0 ); +#endif + } + //please see line# 930 + void getAbsoluteFileURL::getAbsoluteFileURL_003() + { + } + void getAbsoluteFileURL::getAbsoluteFileURL_004() + { + //create two level directories under $Temp/PID/ + ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1"); + createTestDirectory( aUStrUpBase ); + ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1/dir1"); + createTestDirectory( aUStrBase ); + + ::rtl::OUString suAssume = aUserDirectoryURL.concat( ::rtl::OUString::createFromAscii("/mytestfile") ); + check_getAbsoluteFileURL( aUStrBase, "../../mytestfile" , ::osl::FileBase::E_None, suAssume ); + deleteTestDirectory( aUStrBase ); + deleteTestDirectory( aUStrUpBase ); + } + //--------------------------------------------------------------------- + // testing two methods: + // static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL, + // ::rtl::OUString& ustrSystemPath ) + // static RC getFileURLFromSystemPath( const ::rtl::OUString & ustrSystemPath, + // ::rtl::OUString & ustrFileURL ); + //--------------------------------------------------------------------- + class SystemPath_FileURL:public CppUnit::TestFixture + { + //::osl::FileBase aFileBase; + // ::rtl::OUString aUStr; + // ::osl::FileBase::RC nError; + + //void check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr); + void check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection = sal_True ); + void checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString ); + void checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString ); + void checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString); + void checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString); + + public: + // test code. + 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 fot getFileURLFromSystemPath + void getFileURLFromSystemPath_001( ); + void getFileURLFromSystemPath_002( ); + void getFileURLFromSystemPath_003( ); + void getFileURLFromSystemPath_004( ); + 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_005 ); + CPPUNIT_TEST_SUITE_END( ); + };// class SystemPath_FileURL + + + // test code. + + /* void getSystemPathFromFileURL::check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr) + { + // PRE: URL as String + rtl::OUString suURL; + rtl::OUString suStr; + suURL = rtl::OStringToOUString(_sURL, RTL_TEXTENCODING_UTF8); + ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( suURL, suStr ); // start with / + + // if the given string is gt length 0, + // we check also this string + rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8); + rtl::OString sError = errorToString(nError); + t_print("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sURL.getStr(), sStr.getStr(), sError.getStr() ); + + // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8); + // t_print("UTF8: %s\n", sStr.getStr() ); + + if (_sAssumeResultStr.getLength() > 0) + { + sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr); + CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", + nError == _nAssumeError && bStrAreEqual == sal_True ); + } + else + { + CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError ); + } + }*/ + + // if bDirection==sal_True, check getSystemPathFromFileURL + // if bDirection==sal_False, check getFileURLFromSystemPath + void SystemPath_FileURL::check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection) + { + // PRE: URL as String + rtl::OUString suSource; + rtl::OUString suStr; + suSource = rtl::OStringToOUString(_sSource, RTL_TEXTENCODING_UTF8); + ::osl::FileBase::RC nError; + if ( bDirection == sal_True ) + 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 + rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8); + rtl::OString sError = errorToString(nError); + if ( bDirection == sal_True ) + t_print("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() ); + else + t_print("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() ); + + // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8); + // t_print("UTF8: %s\n", sStr.getStr() ); + + if (_sAssumeResultStr.getLength() > 0) + { + sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr); + CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", + nError == _nAssumeError && bStrAreEqual == sal_True ); + } + else + { + CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError ); + } + } + void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString) + { +#if ( defined WNT ) + check_SystemPath_FileURL(_sURL, _nAssumeError, _sWNTAssumeResultString); +#else + (void)_sURL; + (void)_nAssumeError; + (void)_sWNTAssumeResultString; +#endif + } + + void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::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(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString) + { +#if ( defined WNT ) + check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sWNTAssumeResultString, sal_False ); +#else + (void)_sSysPath; + (void)_nAssumeError; + (void)_sWNTAssumeResultString; +#endif + } + + void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString) + { +#if ( defined UNX ) + check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sUnixAssumeResultString, sal_False ); +#else + (void)_sSysPath; + (void)_nAssumeError; + (void)_sUnixAssumeResultString; +#endif + } + + /** LLA: Test for getSystemPathFromFileURL() + this test is splitted 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 thrid parameter is the assumed result string, the string will only test, if it's length is greater 0 + */ + + void SystemPath_FileURL::getSystemPathFromFileURL_001_1() + { + rtl::OString sURL(""); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + + void SystemPath_FileURL::getSystemPathFromFileURL_001_2() + { + rtl::OString sURL("/"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\"); + } + void SystemPath_FileURL::getSystemPathFromFileURL_001_21() + { + // rtl::OString sURL("%2f"); + rtl::OString sURL("%2F"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/"); // LLA: this is may be a BUG + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + void SystemPath_FileURL::getSystemPathFromFileURL_001_22() + { + rtl::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() + { + rtl::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() + { + rtl::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() + { + rtl::OString sURL("file://"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + void SystemPath_FileURL::getSystemPathFromFileURL_001_41() + { + rtl::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() + { + rtl::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() + { + rtl::OString sURL("file://c:/tmp"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:/tmp"); // LLA: this is may be a BUG + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + void SystemPath_FileURL::getSystemPathFromFileURL_001_52() + { + rtl::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() + { +// LLA: is this a legal file path? + rtl::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() + { + rtl::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() + { + rtl::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() + { + rtl::OString sURL("file:///tmp/../second"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/../second"); // LLA: may be a BUG + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + void SystemPath_FileURL::getSystemPathFromFileURL_001_71() + { + rtl::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() + { + rtl::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() + { + rtl::OString sURL("file://~/tmp"); + char* home_path; + home_path = getenv("HOME"); + rtl::OString expResult(home_path); + expResult += "/tmp"; + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, expResult ); + // checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\tmp"); + } + void SystemPath_FileURL::getSystemPathFromFileURL_001_9() + { + rtl::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() + { + rtl::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() + { + rtl::OString sURL("ca@#;+.,$///78no%01ni..name"); + checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, ""); + checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""); + } + +#if 0 + void SystemPath_FileURL::getSystemPathFromFileURL_003( ) + { +// LLA: ??? +//!! seams to be, that the directories do not pass together + ::rtl::OUString aUStr; + ::rtl::OUString aRelativeURL = ::rtl::OUString::createFromAscii("../../relartive/file3"); + ::rtl::OUString aResultURL ( aSysPath4 ); + ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aRelativeURL, aUStr ); + + sal_Bool bOk = compareFileName( aUStr, aResultURL ); + + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL("); + suError += aRelativeURL; + suError += ::rtl::OUString::createFromAscii(") function:use a relative file URL, did not pass in(W32), it did not specified in method declaration of relative path issue, "); + suError += outputError(aUStr, aResultURL); + CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) ); + } +#endif + + //normal legal case + void SystemPath_FileURL::getSystemPathFromFileURL_004( ) + { + ::rtl::OUString aUStr; + ::rtl::OUString aNormalURL( aTmpName6 ); + ::rtl::OUString aResultURL ( aSysPath4 ); + ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aNormalURL, aUStr ); + + sal_Bool bOk = compareFileName( aUStr, aResultURL ); + + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(' "); + suError += aNormalURL; + suError += ::rtl::OUString::createFromAscii(" ') function:use an absolute file URL, "); + suError += outputError(aUStr, aResultURL); + + CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) ); + + } + + //CJK charactors case + void SystemPath_FileURL::getSystemPathFromFileURL_005( ) + { + ::rtl::OUString aUStr; + createTestDirectory( aTmpName10 ); + ::rtl::OUString aNormalURL( aTmpName10 ); + ::rtl::OUString aResultURL ( aSysPath5 ); + + ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aNormalURL, aUStr ); + + sal_Bool bOk = compareFileName( aUStr, aResultURL ); + + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(' "); + suError += aNormalURL; + suError += ::rtl::OUString::createFromAscii(" ') function:use a CJK coded absolute URL, "); + suError += outputError(aUStr, aResultURL); + deleteTestDirectory( aTmpName10 ); + + CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) ); + } + void SystemPath_FileURL::getFileURLFromSystemPath_001() + { + rtl::OString sSysPath("~/tmp"); + char* home_path; + home_path = getenv("HOME"); + rtl::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() + { + rtl::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() + { + rtl::OString sSysPath("file:///temp"); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + } + void SystemPath_FileURL::getFileURLFromSystemPath_004() + { + rtl::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() + { + rtl::OString sSysPath(""); + checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""); + } + // start with "~user", not impletment + // void SystemPath_FileURL::getFileURLFromSystemPath_006() + + + + + //--------------------------------------------------------------------- + // testing the method + // static inline RC searchFileURL( const ::rtl::OUString& ustrFileName, + // const ::rtl::OUString& ustrSearchPath, + // ::rtl::OUString& ustrFileURL ) + //--------------------------------------------------------------------- + class searchFileURL:public CppUnit::TestFixture + { + //::osl::FileBase aFileBase; + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2, nError3,nError4; + + public: + + // test code. + 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_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 ) && + ( osl::FileBase::E_NOENT == nError2 ) && + ( osl::FileBase::E_NOENT == nError3 )); + } + + void searchFileURL_002( ) + { + /* search file is passed by system filename */ + nError1 = ::osl::FileBase::searchFileURL( aTempDirectorySys, aRootSys, aUStr ); + sal_Bool bOk1 = compareFileName( aUStr, aTempDirectoryURL ); + /* search file is passed by full qualified file URL */ + nError2 = ::osl::FileBase::searchFileURL( aTempDirectoryURL, aRootSys, aUStr ); + sal_Bool bOk2 = compareFileName( aUStr, aTempDirectoryURL ); + /* search file is passed by relative file path */ + nError3 = ::osl::FileBase::searchFileURL( aRelURL5, aRootSys, aUStr ); + sal_Bool bOk3 = compareFileName( aUStr, aTempDirectoryURL ); + /* search file is passed by an exist file */ + createTestFile( aCanURL1 ); + nError4 = ::osl::FileBase::searchFileURL( aCanURL4, aUserDirectorySys, aUStr ); + sal_Bool bOk4 = compareFileName( aUStr, aCanURL1 ); + deleteTestFile( aCanURL1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.", + ( osl::FileBase::E_None == nError1 ) && + ( osl::FileBase::E_None == nError2 ) && + ( osl::FileBase::E_None == nError3 ) && + ( osl::FileBase::E_None == nError4 ) && + ( sal_True == bOk1 ) && + ( sal_True == bOk2 ) && + ( sal_True == bOk3 ) && + ( sal_True == bOk4 ) ); + } + + + void searchFileURL_003( ) + { + OSLTEST_DECLARE( SystemPathList, TEST_PLATFORM_ROOT":"TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP":"TEST_PLATFORM_ROOT"system/path" ); + nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr ); + sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL ); + CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths", + ( osl::FileBase::E_None == nError1 ) && + ( sal_True == bOk ) ); + } + + void searchFileURL_004( ) + { + OSLTEST_DECLARE( SystemPathList, TEST_PLATFORM_ROOT PATH_LIST_DELIMITER TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP PATH_LIST_DELIMITER TEST_PLATFORM_ROOT "system/path/../name" ); + nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr ); + sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL ); + CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths", + ( osl::FileBase::E_None == nError1 ) && + ( sal_True == bOk ) ); + } + + void searchFileURL_005( ) + { + nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aNullURL, aUStr ); + sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL ); + CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is NULL", + ( osl::FileBase::E_None == nError1 ) && + ( sal_True == 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( ); + };// class searchFileURL + + + //--------------------------------------------------------------------- + // testing the method + // static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL ) + //--------------------------------------------------------------------- + class getTempDirURL:public CppUnit::TestFixture + { + //::osl::FileBase aFileBase; + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError; + + public: + // initialization + void setUp( ) + { + nError = FileBase::getTempDirURL( aUStr ); + } + + void tearDown( ) + { + } + + // test code. + void getTempDirURL_001( ) + { + + CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: excution", + ( osl::FileBase::E_None == nError ) ); + } + + void getTempDirURL_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: test for open and write access rights", + checkDirectory( aUStr, osl_Check_Mode_OpenAccess ) && + checkDirectory( aUStr, osl_Check_Mode_ReadAccess ) && + checkDirectory( aUStr,osl_Check_Mode_WriteAccess ) ); + } + + CPPUNIT_TEST_SUITE( getTempDirURL ); + CPPUNIT_TEST( getTempDirURL_001 ); + CPPUNIT_TEST( getTempDirURL_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getTempDirURL + + + //--------------------------------------------------------------------- + // testing the method + // static inline RC createTempFile( ::rtl::OUString* pustrDirectoryURL, + // oslFileHandle* pHandle, + // ::rtl::OUString* pustrTempFileURL) + //--------------------------------------------------------------------- + class createTempFile:public CppUnit::TestFixture + { + //::osl::FileBase aFileBase; + ::osl::FileBase::RC nError1, nError2; + sal_Bool bOK; + + oslFileHandle *pHandle; + ::rtl::OUString *pUStr_DirURL; + ::rtl::OUString *pUStr_FileURL; + + public: + + // initialization + void setUp( ) + { + pHandle = new oslFileHandle(); + pUStr_DirURL = new ::rtl::OUString( aUserDirectoryURL ); + pUStr_FileURL = new ::rtl::OUString(); + //*pUStr_DirURL = aUserDirectoryURL; /// create temp file in /tmp/PID or c:\temp\PID.*/ + } + + void tearDown( ) + { + delete pUStr_DirURL; + delete pUStr_FileURL; + delete pHandle; + } + + // test code. + void createTempFile_001( ) + { + nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL ); + ::osl::File testFile( *pUStr_FileURL ); + //printFileName(*pUStr_FileURL); + nError2 = testFile.open( OpenFlag_Create ); + if ( osl::FileBase::E_EXIST == nError2 ) { + osl_closeFile( *pHandle ); + deleteTestFile( *pUStr_FileURL ); + } + + CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: create temp file and test the existence", + ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) && ( osl::FileBase::E_EXIST== nError2 ) ); + } + + void createTempFile_002( ) + { + bOK = sal_False; + nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL ); + ::osl::File testFile( *pUStr_FileURL ); + nError2 = testFile.open( OpenFlag_Create ); + + CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist", + ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) && + ( osl::FileBase::E_EXIST == nError2 ) ); + + //check file if have the write permission + if ( osl::FileBase::E_EXIST == nError2 ) { + 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 writtenable.", + ( sal_True == bOK ) ); + } + + void createTempFile_003( ) + { + nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, 0 ); + //the temp file will be removed when return from createTempFile + bOK = ( pHandle != NULL && pHandle != 0); + if ( sal_True == bOK ) + osl_closeFile( *pHandle ); + + CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.", + ( ::osl::FileBase::E_None == nError1 ) &&( sal_True == bOK ) ); + } + void createTempFile_004( ) + { + nError1 = FileBase::createTempFile( pUStr_DirURL, 0, pUStr_FileURL ); + bOK = ( pUStr_FileURL != 0); + ::osl::File testFile( *pUStr_FileURL ); + nError2 = testFile.open( OpenFlag_Create ); + deleteTestFile( *pUStr_FileURL ); + CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist", + ( osl::FileBase::E_None == nError1 ) && ( osl::FileBase::E_EXIST == nError2 ) &&( sal_True == 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( ); + };// class createTempFile + + // ----------------------------------------------------------------------------- +#if 0 //~ this function has been deprecated. + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getCanonicalName, "osl_FileBase" ); +#endif + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getAbsoluteFileURL, "osl_FileBase" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::SystemPath_FileURL, "osl_FileBase" ); + // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getFileURLFromSystemPath, "osl_FileBase" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::searchFileURL, "osl_FileBase" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getTempDirURL, "osl_FileBase" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::createTempFile, "osl_FileBase" ); +}// namespace osl_FileBase + + +//------------------------------------------------------------------------ +// Beginning of the test cases for VolumeDevice class +//------------------------------------------------------------------------ + +#if 0 //~ this Class has been deprecated +namespace osl_VolumeDevice +{ + + //--------------------------------------------------------------------- + // testing the method + // VolumeDevice() : _aHandle( NULL ) + //--------------------------------------------------------------------- + class ctors : public CppUnit::TestFixture + { + ::osl::VolumeDevice aVolumeDevice; + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + } + + // test code. + void ctors_001( ) + { + ::osl::VolumeDevice aVolumeDevice1; + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Constructor for VolumeDevice with no args.", + ( osl::FileBase::E_None != aVolumeDevice1.automount( ) ) && + ( osl::FileBase::E_None != aVolumeDevice1.unmount( ) ) && + ( aNullURL.equals( aVolumeDevice1.getMountPath( ) ) ) ); + } + + void ctors_002( ) + { + ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes ); + nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) ); + sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) ); + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Copy constructor for VolumeDevice, the copied VolumeDevice should have a mount path file:///, but it returned an empty OUString, it also may be the error from getDeviceHandle(), it did not pass in (UNX), (W32).", + sal_False == bOk ); + } + + void ctors_003( ) + { + ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes ); + nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + ::osl::VolumeDevice aVolumeDevice1 = aVolumeInfo.getDeviceHandle( ); + sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) ); + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Assigned operator for VolumeDevice, the assigned VolumeDevice should have a mount path file:///, but it returned an empty OUString, it also may be the error from getDeviceHandle(),it did not pass in (UNX), (W32).", + sal_False == bOk ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST( ctors_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class ctors + + + //--------------------------------------------------------------------- + // testing the method + // inline RC automount() + //--------------------------------------------------------------------- + class automount : public CppUnit::TestFixture + { + ::osl::VolumeDevice aVolumeDevice; + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + + } + + // test code. + void automount_001( ) + { + ::osl::VolumeDevice aVolumeDevice1; + nError1 = aVolumeDevice1.automount( ); + + CPPUNIT_ASSERT_MESSAGE( "test for automount function: invalid parameter.", + ( osl::FileBase::E_INVAL == nError1 ) ); + } + + void automount_002( ) + { + ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) ); + nError1 = aVolumeDevice1.unmount( ); + nError1 = aVolumeDevice1.automount( ); + CPPUNIT_ASSERT_MESSAGE( "test for automount function: this test is not implemented yet, it did not pass in (UNX), (W32).", + ( osl::FileBase::E_None == nError1 ) ); + } + + CPPUNIT_TEST_SUITE( automount ); + CPPUNIT_TEST( automount_001 ); + CPPUNIT_TEST( automount_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class automount + + + // ----------------------------------------------------------------------------- + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeDevice::ctors, "osl_VolumeDevice" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeDevice::automount, "osl_VolumeDevice" ); +}// namespace osl_VolumeDevice +#endif + + +//------------------------------------------------------------------------ +// Beginning of the test cases for VolumeInfo class +//------------------------------------------------------------------------ +namespace osl_VolumeInfo +{ + + //--------------------------------------------------------------------- + // testing the method + // VolumeInfo( sal_uInt32 nMask ): _nMask( nMask ) + //--------------------------------------------------------------------- + class ctors : public CppUnit::TestFixture + { + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + + ::osl::VolumeDevice aVolumeDevice1; + + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + } + + // test code. + void ctors_001( ) + { + ::osl::VolumeInfo aVolumeInfo( 0 ); + nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( ); + sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength( ); + aUStr = aVolumeInfo.getFileSystemName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty", + ( 0 == uiTotalSpace ) && + ( 0 == uiMaxPathLength ) && + sal_True == compareFileName( aUStr, aNullURL ) ); + } + +#if ( defined UNX ) || ( defined OS2 ) + void ctors_002( ) + { + ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_TotalSpace | + VolumeInfoMask_UsedSpace | + VolumeInfoMask_FileSystemName ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + //CPPUNIT_ASSERT( aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( ); + sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( ); + aUStr = aVolumeInfo.getFileSystemName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields", + ( 0 != uiTotalSpace ) && + ( 0 != uiUsedSpace ) && + sal_True == compareFileName( aUStr, "nfs" ) ); + } +#else /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume. + void ctors_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields( Windows version )", + 1 == 1 ); + } +#endif + + void ctors_003( ) + { + + sal_Int32 mask1 = VolumeInfoMask_FreeSpace; + ::osl::VolumeInfo aVolumeInfo1( mask1 ); + nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo1.isValid( mask1 ) ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + sal_uInt64 uiTotalSpace1 = aVolumeInfo1.getTotalSpace( ); + aUStr = aVolumeInfo1.getFileSystemName( ); + + sal_Int32 mask2 = VolumeInfoMask_TotalSpace; + ::osl::VolumeInfo aVolumeInfo2( mask2 ); + nError2 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo2 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo2.isValid( mask2 ) ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError2 ); + + sal_uInt64 uiTotalSpace2 = aVolumeInfo2.getTotalSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, but get unmasked fields, use mask to FreeSpace, but I can get TotalSpace, did not pass in (UNX)(W32)", + ( 0 == uiTotalSpace1 ) && ( 0 != uiTotalSpace2 ) && + sal_True == compareFileName( aUStr, aNullURL ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST( ctors_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class ctors + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool isValid( sal_uInt32 nMask ) const + //--------------------------------------------------------------------- + class isValid : public CppUnit::TestFixture + { + ::osl::VolumeDevice aVolumeDevice; + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + + } + + // test code. + void isValid_001( ) + { + sal_Int32 mask = 0; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified.", + sal_True == aVolumeInfo.isValid( mask ) ); + } + +#if ( defined UNX ) || ( defined OS2 ) + void isValid_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes | VolumeInfoMask_TotalSpace | osl_VolumeInfo_Mask_UsedSpace | + osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_MaxNameLength | + osl_VolumeInfo_Mask_MaxPathLength | osl_VolumeInfo_Mask_FileSystemName; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.", + sal_True == aVolumeInfo.isValid( mask ) ); + } +#else /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume. + void isValid_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.( Windows version )", + 1 == 1 ); + } +#endif + + void isValid_003( ) + { + ::osl::VolumeDevice aVolumeDevice1; + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk1 = aVolumeInfo.isValid( mask ); + + nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk2 = aVolumeInfo.isValid( mask ); + + CPPUNIT_ASSERT_MESSAGE( "test for isValid function: VolumeInfoMask_Attributes, it should be valid for some volume such as /, floppy, cdrom, etc. but it did not pass", + ( sal_True == bOk1 ) && ( sal_True == bOk2 ) ); + } + + CPPUNIT_TEST_SUITE( isValid ); + CPPUNIT_TEST( isValid_001 ); + CPPUNIT_TEST( isValid_002 ); + CPPUNIT_TEST( isValid_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class isValid + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool getRemoteFlag() const + //--------------------------------------------------------------------- + class getRemoteFlag : public CppUnit::TestFixture + { + ::osl::VolumeDevice aVolumeDevice; + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + + public: + // test code. + void getRemoteFlag_001( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getRemoteFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is not remote.", + ( sal_False == bOk ) ); + } + + #if ( defined UNX ) || ( defined OS2 ) //remote Volume is different in Solaris and Windows + void getRemoteFlag_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getRemoteFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Solaris version ).", + ( sal_True == bOk ) ); + } +#else //Windows version + void getRemoteFlag_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Windows version )", + 1 == 1 ); + } +#endif + + CPPUNIT_TEST_SUITE( getRemoteFlag ); + CPPUNIT_TEST( getRemoteFlag_001 ); + CPPUNIT_TEST( getRemoteFlag_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getRemoteFlag + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool getRemoveableFlag() const + //--------------------------------------------------------------------- + class getRemoveableFlag : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // test code. + void getRemoveableFlag_001( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getRemoveableFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is not removable.", + sal_False == bOk ); + } + + void getRemoveableFlag_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getRemoveableFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is removable, not sure, here we use floppy disk, but it did not pass.", + sal_True == bOk ); + } + CPPUNIT_TEST_SUITE( getRemoveableFlag ); + CPPUNIT_TEST( getRemoveableFlag_001 ); + CPPUNIT_TEST( getRemoveableFlag_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getRemoveableFlag + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool getCompactDiscFlag() const + //--------------------------------------------------------------------- + class getCompactDiscFlag : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getCompactDiscFlag_001( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getCompactDiscFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a volume device which is not a cdrom.", + ( sal_False == bOk ) ); + } + + void getCompactDiscFlag_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL6, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getCompactDiscFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a cdrom volume device flag, it did not pass.", + ( sal_True == bOk ) ); + } + CPPUNIT_TEST_SUITE( getCompactDiscFlag ); + CPPUNIT_TEST( getCompactDiscFlag_001 ); + CPPUNIT_TEST( getCompactDiscFlag_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getCompactDiscFlag + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool getFloppyDiskFlag() const + //--------------------------------------------------------------------- + class getFloppyDiskFlag : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getFloppyDiskFlag_001( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a volume device which is not a floppy disk.", + ( sal_False == bOk ) ); + } + + void getFloppyDiskFlag_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a floppy volume device flag, it did not pass.", + ( sal_True == bOk ) ); + } + CPPUNIT_TEST_SUITE( getFloppyDiskFlag ); + CPPUNIT_TEST( getFloppyDiskFlag_001 ); + CPPUNIT_TEST( getFloppyDiskFlag_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFloppyDiskFlag + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool getFixedDiskFlag() const + //--------------------------------------------------------------------- + class getFixedDiskFlag : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getFixedDiskFlag_001( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getFixedDiskFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a volume device which is not a fixed disk.", + ( sal_False == bOk ) ); + } + + void getFixedDiskFlag_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getFixedDiskFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a fixed disk volume device flag, it did not pass.", + ( sal_True == bOk ) ); + } + CPPUNIT_TEST_SUITE( getFixedDiskFlag ); + CPPUNIT_TEST( getFixedDiskFlag_001 ); + CPPUNIT_TEST( getFixedDiskFlag_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFixedDiskFlag + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool getRAMDiskFlag() const + //--------------------------------------------------------------------- + class getRAMDiskFlag : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getRAMDiskFlag_001( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getRAMDiskFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: get a volume device which is not a RAM disk.", + ( sal_False == bOk ) ); + } + + void getRAMDiskFlag_002( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + sal_Bool bOk = aVolumeInfo.getRAMDiskFlag( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: FIX ME, don't know how to get a RAM disk flag, perhaps Windows 98 boot disk can create a RAM disk, it did not pass in (UNX)(W32).", + ( sal_True == bOk ) ); + } + CPPUNIT_TEST_SUITE( getRAMDiskFlag ); + CPPUNIT_TEST( getRAMDiskFlag_001 ); + CPPUNIT_TEST( getRAMDiskFlag_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getRAMDiskFlag + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt64 getTotalSpace() const + //--------------------------------------------------------------------- + class getTotalSpace : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getTotalSpace_001( ) + { + sal_Int32 mask = VolumeInfoMask_TotalSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of Fixed disk volume mounted on /, it should not be 0", + 0 != uiTotalSpace ); + } + + #if defined( UNX ) + void getTotalSpace_002( ) + { + sal_Int32 mask = VolumeInfoMask_TotalSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of /proc, it should be 0", + 0 == uiTotalSpace ); + } +#else /// Windows version, in Windows, there is no /proc directory + void getTotalSpace_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not applicable for /proc( Windows version )", + 1 == 1 ); + } +#endif + + + +#if defined(SOLARIS) + void getTotalSpace_003( ) + { + struct statvfs aStatFS; + static const sal_Char name[] = "/"; + + memset (&aStatFS, 0, sizeof(aStatFS)); + statvfs( name, &aStatFS); + sal_uInt64 TotalSpace = aStatFS.f_frsize * aStatFS.f_blocks ; + + sal_Int32 mask = VolumeInfoMask_TotalSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space by hand, then compare with getTotalSpace, it did not pass", + uiTotalSpace == TotalSpace ); + } +#else /// Windows version + void getTotalSpace_003( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not implemented yet( Windows version )", + 1 == 1 ); + } +#endif + + CPPUNIT_TEST_SUITE( getTotalSpace ); + CPPUNIT_TEST( getTotalSpace_001 ); + CPPUNIT_TEST( getTotalSpace_002 ); + CPPUNIT_TEST( getTotalSpace_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getTotalSpace + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt64 getFreeSpace() const + //--------------------------------------------------------------------- + class getFreeSpace : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getFreeSpace_001( ) + { + sal_Int32 mask = VolumeInfoMask_FreeSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of Fixed disk volume mounted on /, it should not be 0, suggestion: returned value, -1 is better, since some times the free space may be 0", + 0 != uiFreeSpace ); + } + +#if defined( UNX ) + void getFreeSpace_002( ) + { + sal_Int32 mask = VolumeInfoMask_FreeSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of /proc, it should be 0", + 0 == uiFreeSpace ); + } +#else /// Windows version, in Windows, there is no /proc directory + void getFreeSpace_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not applicable for /proc( Windows version )", + 1 == 1 ); + } +#endif + + +#if defined(SOLARIS) + void getFreeSpace_003( ) + { + struct statvfs aStatFS; + static const sal_Char name[] = "/"; + + memset (&aStatFS, 0, sizeof(aStatFS)); + statvfs( name, &aStatFS); + sal_uInt64 FreeSpace = aStatFS.f_bfree * aStatFS.f_frsize ; + + sal_Int32 mask = VolumeInfoMask_FreeSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space by hand, then compare with getFreeSpace, it did not pass", + uiFreeSpace == FreeSpace ); + } +#else //Windows version + void getFreeSpace_003( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not implemented yet( Windows version )", + 1 == 1 ); + } +#endif + + + CPPUNIT_TEST_SUITE( getFreeSpace ); + CPPUNIT_TEST( getFreeSpace_001 ); + CPPUNIT_TEST( getFreeSpace_002 ); + CPPUNIT_TEST( getFreeSpace_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFreeSpace + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt64 getUsedSpace() const + //--------------------------------------------------------------------- + class getUsedSpace : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getUsedSpace_001( ) + { + sal_Int32 mask = VolumeInfoMask_UsedSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of Fixed disk volume mounted on /, it should not be 0, suggestion: returned value, -1 is better, since some times the used space may be 0", + 0 != uiUsedSpace ); + } + +#if defined( UNX ) + void getUsedSpace_002( ) + { + sal_Int32 mask = VolumeInfoMask_UsedSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of /proc, it should be 0", + 0 == uiUsedSpace ); + } +#else /// Windows version, in Windows, there is no /proc directory + void getUsedSpace_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not applicable for /proc( Windows version )", + 1 == 1 ); + } +#endif + + +#if defined(SOLARIS) + void getUsedSpace_003( ) + { + struct statvfs aStatFS; + static const sal_Char name[] = "/"; + + memset (&aStatFS, 0, sizeof(aStatFS)); + statvfs( name, &aStatFS); + sal_uInt64 UsedSpace = ( aStatFS.f_blocks - aStatFS.f_bavail ) * aStatFS.f_frsize; + + + sal_Int32 mask = VolumeInfoMask_UsedSpace; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space by hand, then compare with getUsedSpace, it did not pass", + uiUsedSpace == UsedSpace ); + } +#else //Windows version + void getUsedSpace_003( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not implemented yet( Windows version )", + 1 == 1 ); + } +#endif + + + CPPUNIT_TEST_SUITE( getUsedSpace ); + CPPUNIT_TEST( getUsedSpace_001 ); + CPPUNIT_TEST( getUsedSpace_002 ); + CPPUNIT_TEST( getUsedSpace_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getUsedSpace + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt32 getMaxNameLength() const + //--------------------------------------------------------------------- + class getMaxNameLength : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getMaxNameLength_001( ) + { + sal_Int32 mask = VolumeInfoMask_MaxNameLength; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt32 uiMaxNameLength = aVolumeInfo.getMaxNameLength( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length of Fixed disk volume mounted on /, it should not be 0", + 0 != uiMaxNameLength ); + } + + +#if ( defined UNX ) || ( defined OS2 ) + void getMaxNameLength_002( ) + { + struct statvfs aStatFS; + static const sal_Char name[] = "/"; + + memset (&aStatFS, 0, sizeof(aStatFS)); + statvfs( name, &aStatFS); + sal_uInt64 MaxNameLength = aStatFS.f_namemax; + + sal_Int32 mask = VolumeInfoMask_MaxNameLength; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiMaxNameLength = aVolumeInfo.getMaxNameLength( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length by hand, then compare with getMaxNameLength", + uiMaxNameLength == MaxNameLength ); + } +#else //Windows version + void getMaxNameLength_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: not implemented yet( Windows version )", + 1 == 1 ); + } +#endif + + CPPUNIT_TEST_SUITE( getMaxNameLength ); + CPPUNIT_TEST( getMaxNameLength_001 ); + CPPUNIT_TEST( getMaxNameLength_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getMaxNameLength + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt32 getMaxPathLength() const + //--------------------------------------------------------------------- + class getMaxPathLength : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + + public: + // test code. + void getMaxPathLength_001( ) + { + sal_Int32 mask = VolumeInfoMask_MaxPathLength; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length of Fixed disk volume mounted on /, it should not be 0", + 0 != uiMaxPathLength ); + } + + +#if ( defined UNX ) || ( defined OS2 ) + void getMaxPathLength_002( ) + { + sal_Int32 mask = VolumeInfoMask_MaxPathLength; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + sal_uInt64 uiMaxPathLength = aVolumeInfo.getMaxPathLength( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length by hand, then compare with getMaxPathLength", + uiMaxPathLength == PATH_MAX ); + } +#else //Windows version + void getMaxPathLength_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: not implemented yet( Windows version )", + 1 == 1 ); + } +#endif + + + CPPUNIT_TEST_SUITE( getMaxPathLength ); + CPPUNIT_TEST( getMaxPathLength_001 ); + CPPUNIT_TEST( getMaxPathLength_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getMaxPathLength + + + //--------------------------------------------------------------------- + // testing the method + // inline ::rtl::OUString getFileSystemName() const + //--------------------------------------------------------------------- + class getFileSystemName : public CppUnit::TestFixture + { + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1; + + public: + // test code. + void getFileSystemName_001( ) + { + sal_Int32 mask = VolumeInfoMask_FileSystemName; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + aUStr = aVolumeInfo.getFileSystemName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name of Fixed disk volume mounted on /, it should not be empty string", + sal_False == compareFileName( aNullURL, aUStr ) ); + } + + +#if defined(SOLARIS) + void getFileSystemName_002( ) + { + struct statvfs aStatFS; + static const sal_Char name[] = "/"; + + memset (&aStatFS, 0, sizeof(aStatFS)); + statvfs( name, &aStatFS); + sal_Char * astrFileSystemName = aStatFS.f_basetype; + + sal_Int32 mask = VolumeInfoMask_FileSystemName; + ::osl::VolumeInfo aVolumeInfo( mask ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) ); + aUStr = aVolumeInfo.getFileSystemName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name by hand, then compare with getFileSystemName", + sal_True == compareFileName( aUStr, astrFileSystemName ) ); + } +#else //Windows version + void getFileSystemName_002( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: not implemented yet( Windows version )", + 1 == 1 ); + } +#endif + + + CPPUNIT_TEST_SUITE( getFileSystemName ); + CPPUNIT_TEST( getFileSystemName_001 ); + CPPUNIT_TEST( getFileSystemName_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFileSystemName + + //--------------------------------------------------------------------- + // testing the method + // inline VolumeDevice getDeviceHandle() const + //--------------------------------------------------------------------- + class getDeviceHandle : public CppUnit::TestFixture + { + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1; + + public: + // test code. + void getDeviceHandle_001( ) + { + ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes ); + nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo ); + CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 ); + + ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) ); + sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getDeviceHandle function: get device handle of Fixed disk volume mounted on /, it should not be NULL, it did not pass in (W32) (UNX).", + ( sal_False == bOk ) ); + } + + CPPUNIT_TEST_SUITE( getDeviceHandle ); + CPPUNIT_TEST( getDeviceHandle_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getDeviceHandle + + + // ----------------------------------------------------------------------------- + /*CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::ctors, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::isValid, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoteFlag, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoveableFlag, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getCompactDiscFlag, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFloppyDiskFlag, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFixedDiskFlag, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRAMDiskFlag, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getTotalSpace, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFreeSpace, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getUsedSpace, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxNameLength, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxPathLength, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFileSystemName, "osl_VolumeInfo" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getDeviceHandle, "osl_VolumeInfo" );*/ +}// namespace osl_VolumeInfo + + + +//------------------------------------------------------------------------ +// Beginning of the test cases for VolumeDevice class +//------------------------------------------------------------------------ +namespace osl_FileStatus +{ + + //--------------------------------------------------------------------- + // testing the method + // FileStatus( sal_uInt32 nMask ): _nMask( nMask ) + //--------------------------------------------------------------------- + class ctors : public CppUnit::TestFixture + { + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) ); + nError1 = pDir->open( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = pDir->getNextItem( rItem, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + pDir->close(); + /* + Directory aDir( aTmpName3 ); + nError1 = aDir.open(); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = aDir.getNextItem( rItem, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + aDir.close(); + */ + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void ctors_001( ) + { + ::osl::FileStatus rFileStatus( FileStatusMask_All ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + aUStr = rFileStatus.getFileName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask all and see the file name", + sal_True == compareFileName( aUStr, aTmpName2) ); + } + + void ctors_002( ) + { + ::osl::FileStatus rFileStatus( 0 ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + aUStr = rFileStatus.getFileName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty", + sal_True == compareFileName( aUStr, aNullURL) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class ctors + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool isValid( sal_uInt32 nMask ) const + //--------------------------------------------------------------------- + class isValid : public CppUnit::TestFixture + { + ::rtl::OUString aUStr; + ::osl::Directory *pDir; + ::osl::DirectoryItem rItem_file, rItem_link; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + pDir = new Directory( aTmpName3 ); + //::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) ); + ::osl::FileBase::RC nError1 = pDir->open( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = pDir->getNextItem( rItem_file, 1 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + ::osl::FileBase::RC nError1 = pDir->close( ); + delete pDir; + CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1), ::osl::FileBase::E_None == nError1 ); + + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void isValid_001( ) + { + sal_uInt32 mask = 0; + ::osl::FileStatus rFileStatus( mask ); + ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + sal_Bool bOk = rFileStatus.isValid( mask ); + + CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified", + ( sal_True == bOk ) ); + } + + void check_FileStatus(::osl::FileStatus const& _aStatus) + { + rtl::OString sStat; + if (_aStatus.isValid(FileStatusMask_Type)) + { + sStat += "type "; + } + if (_aStatus.isValid(FileStatusMask_Attributes)) + { + sStat += "attributes "; + } + if (_aStatus.isValid(FileStatusMask_CreationTime)) + { + sStat += "ctime "; + } + if (_aStatus.isValid(FileStatusMask_AccessTime)) + { + sStat += "atime "; + } + if (_aStatus.isValid(FileStatusMask_ModifyTime)) + { + sStat += "mtime "; + } + if (_aStatus.isValid(FileStatusMask_FileSize)) + { + sStat += "filesize "; + } + if (_aStatus.isValid(FileStatusMask_FileName)) + { + sStat += "filename "; + } + if (_aStatus.isValid(FileStatusMask_FileURL)) + { + sStat += "fileurl "; + } + t_print("mask: %s\n", sStat.getStr()); + } + + void isValid_002( ) + { + createTestFile( aTmpName6 ); + sal_uInt32 mask_file = ( FileStatusMask_Type | FileStatusMask_Attributes | + FileStatusMask_CreationTime | FileStatusMask_AccessTime | + FileStatusMask_ModifyTime | FileStatusMask_FileSize | + FileStatusMask_FileName | FileStatusMask_FileURL) ; + ::osl::FileStatus rFileStatus( mask_file ); + ::osl::FileBase::RC nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem_file ); + nError1 = rItem_file.getFileStatus( rFileStatus ); + + CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1), ::osl::FileBase::E_None == nError1 ); + +// LLA: this is wrong, we never should try to check on all masks +// only on one. +// Second, it's not a bug, if a value is not valid, it's an unhandled feature. + +// sal_Bool bOk = rFileStatus.isValid( mask_file ); + + check_FileStatus(rFileStatus); + deleteTestFile( aTmpName6 ); + + // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: regular file mask fields test, #FileStatusMask_CreationTime# should be valid field for regular file, but feedback is invalid", + // ( sal_True == bOk ) ); + } + + //Link is not defined in Windows, and on Linux, we can not get the directory item of the link file + // LLA: we have to differ to filesystems, normal filesystems support links (EXT2, ...) + // castrated filesystems don't (FAT, FAT32) + // Windows NT NTFS support links, but the windows api don't :-( + + void isValid_003( ) + { +#if defined ( UNX ) + // ::osl::FileBase::RC nError; + sal_Int32 fd; + + ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys ); + ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/link.file"); + ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/tmpname"); + + rtl::OString strLinkFileName; + rtl::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( fd == 0 ); + + // testDirectory is "/tmp/PID/tmpdir/" + ::osl::Directory testDirectory( aTmpName3 ); + ::osl::FileBase::RC nError1 = testDirectory.open( ); + ::rtl::OUString aFileName = ::rtl::OUString::createFromAscii("link.file"); + sal_Bool bOk = sal_False; + while (1) { + nError1 = testDirectory.getNextItem( rItem_link, 4 ); + if (::osl::FileBase::E_None == nError1) { + sal_uInt32 mask_link = FileStatusMask_FileName | FileStatusMask_LinkTargetURL; + ::osl::FileStatus rFileStatus( mask_link ); + rItem_link.getFileStatus( rFileStatus ); + //printFileName( rFileStatus.getFileName( ) ); + if ( compareFileName( rFileStatus.getFileName( ), aFileName) == sal_True ) + { + //t_print("find the link file"); + if ( sal_True == rFileStatus.isValid( FileStatusMask_LinkTargetURL ) ) + { + bOk = sal_True; + break; + } + } + } + else + break; + }; + + fd = remove( strLinkFileName ); + CPPUNIT_ASSERT( fd == 0 ); + + CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL", + ( sal_True == bOk ) ); +#endif + } + + void isValid_004( ) + { + sal_uInt32 mask_file_all = FileStatusMask_All; + ::osl::FileStatus rFileStatus_all( mask_file_all ); + ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus_all ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + check_FileStatus(rFileStatus_all); +// LLA: this is wrong +// sal_Bool bOk1 = rFileStatus_all.isValid( mask_file_all ); + + sal_uInt32 mask_file_val = FileStatusMask_Validate; + ::osl::FileStatus rFileStatus_val( mask_file_val ); + nError1 = rItem_file.getFileStatus( rFileStatus_val ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + // sal_Bool bOk2 = rFileStatus_val.isValid( mask_file_val ); + + check_FileStatus(rFileStatus_val); + // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: check for Mask_All and Validate, really not sure what validate used for and how to use it, help me. did not pass (W32)(UNX).", + // ( sal_False == bOk1 ) && ( sal_True == bOk2 ) ); + } + + + CPPUNIT_TEST_SUITE( isValid ); + CPPUNIT_TEST( isValid_001 ); + CPPUNIT_TEST( isValid_002 ); + CPPUNIT_TEST( isValid_003 ); + CPPUNIT_TEST( isValid_004 ); + CPPUNIT_TEST_SUITE_END( ); + };// class ctors + + + //--------------------------------------------------------------------- + // testing the method + // inline Type getFileType() const + //--------------------------------------------------------------------- + class getFileType : public CppUnit::TestFixture + { + ::rtl::OUString aUStr; + ::osl::FileBase::RC nError1, nError2; + + ::osl::DirectoryItem m_aItem_1, m_aItem_2, m_aVolumeItem, m_aFifoItem; + ::osl::DirectoryItem m_aLinkItem, m_aSocketItem, m_aSpecialItem; + + public: + // initialization + void setUp( ) + { + // 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 ); + //printFileName( aTmpName2); + createTestFile( aTmpName3, aTmpName2 ); + createTestDirectory( aTmpName3, aTmpName1 ); + + ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) ); + nError1 = pDir->open( ); + CPPUNIT_ASSERT_MESSAGE("open aTmpName3 failed!", ::osl::FileBase::E_None == nError1 ); + //getNextItem can not assure which item retrieved + nError1 = pDir->getNextItem( m_aItem_1, 1 ); + CPPUNIT_ASSERT_MESSAGE("get first item failed!", ::osl::FileBase::E_None == nError1 ); + + nError1 = pDir->getNextItem( m_aItem_2 ); + CPPUNIT_ASSERT_MESSAGE("get second item failed!", ::osl::FileBase::E_None == nError1 ); + pDir->close(); + //mindy: failed on my RH9,so removed temporaly + //nError1 = ::osl::DirectoryItem::get( aVolURL2, m_aVolumeItem ); + //CPPUNIT_ASSERT_MESSAGE("get volume item failed!", ::osl::FileBase::E_None == nError1 ); + + } + + void tearDown( ) + { + // remove all in $TEMP/tmpdir. + deleteTestDirectory( aTmpName3, aTmpName1 ); + deleteTestFile( aTmpName3, aTmpName2 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void getFileType_001( ) + { + ::osl::FileStatus rFileStatus( FileStatusMask_Type | FileStatusMask_FileName ); + nError1 = m_aItem_1.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 ); + + check_FileType(rFileStatus); + } + + void check_FileType(osl::FileStatus const& _rFileStatus ) + { + sal_Bool bOK = sal_False; + if ( _rFileStatus.isValid(FileStatusMask_FileName)) + { + rtl::OUString suFilename = _rFileStatus.getFileName(); + + if ( _rFileStatus.isValid(FileStatusMask_Type)) + { + osl::FileStatus::Type eType = _rFileStatus.getFileType( ); + + if ( compareFileName( suFilename, aTmpName2) == sal_True ) + { + // regular + bOK = ( eType == osl::FileStatus::Regular ); + } + if ( compareFileName( suFilename, aTmpName1) == sal_True ) + { + // directory + bOK = ( eType == ::osl::FileStatus::Directory ); + } + + CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: ", + ( bOK == sal_True ) ); + } + } + // LLA: it's not a bug, if a FileStatus not exist, so no else + } + + void getFileType_002( ) + { + ::osl::FileStatus rFileStatus( FileStatusMask_Type | FileStatusMask_FileName ); + nError1 = m_aItem_2.getFileStatus( rFileStatus ); + + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + check_FileType(rFileStatus); + } + + void getFileType_003( ) + { +#if 0 +// LLA: this have to be discussed. + ::osl::FileStatus rFileStatus( FileStatusMask_Type ); + nError1 = m_aVolumeItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + if (rFileStatus.isValid(FileStatusMask_Type)) + { + osl::FileStatus::Type eType = rFileStatus.getFileType( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Volume, it seems the volume part of the field is not implemented, it did not pass in (W32)(UNX).", + ( eType == ::osl::FileStatus::Volume ) ); + } +#endif + } + + + void getFileType_004( ) + { +#if ( defined UNX ) || ( defined OS2 ) //Fifo creation is differ in Windows + + //create a fifo in $ROOT/tmp/tmpdir, get its DirectoryItem. + rtl::OString strFifoSys; + strFifoSys = OUStringToOString( aFifoSys, RTL_TEXTENCODING_ASCII_US ); + ::rtl::OUString aFifoURL; + + int fd = mkfifo( strFifoSys.getStr(), O_RDWR | O_CREAT ); + CPPUNIT_ASSERT_MESSAGE("mkfifo failed!", fd == 0 ); + ::osl::FileBase::getFileURLFromSystemPath( aFifoSys, aFifoURL ); + + nError1 = ::osl::DirectoryItem::get( aFifoURL, m_aFifoItem ); + CPPUNIT_ASSERT_MESSAGE("get item failed!", ::osl::FileBase::E_None == nError1 ); + + //check for File type + ::osl::FileStatus rFileStatus( FileStatusMask_Type ); + nError1 = m_aFifoItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT_MESSAGE("get Status failed!", ::osl::FileBase::E_None == nError1 ); + + //delete fifo + nError1 = ::osl::File::remove( aFifoURL ); + CPPUNIT_ASSERT_MESSAGE("remove file failed!", ::osl::FileBase::E_None == nError1 ); + + if (rFileStatus.isValid(FileStatusMask_Type)) + { + osl::FileStatus::Type eType = rFileStatus.getFileType( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Fifo, Solaris version ", + ( eType == ::osl::FileStatus::Fifo ) ); + } +#endif + } + +/* + * LLA: removed, m_aSocketItem is wrong initialised. + */ + +// LLA: void getFileType_005( ) +// LLA: { +// LLA: #if defined ( SOLARIS ) //Socket file may differ in Windows +// LLA: // nError1 = ::osl::DirectoryItem::get( aTypeURL1, m_aSocketItem ); +// LLA: nError1 = ::osl::DirectoryItem::get( rtl::OUString::createFromAscii("/dev/null"), m_aSocketItem ); +// LLA: printError(nError1); +// LLA: CPPUNIT_ASSERT_MESSAGE("get Socket type file failed", ::osl::FileBase::E_None == nError1 ); +// LLA: +// LLA: //check for File type +// LLA: ::osl::FileStatus rFileStatus( FileStatusMask_Type ); +// LLA: +// LLA: nError1 = m_aSocketItem.getFileStatus( rFileStatus ); +// LLA: CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 ); +// LLA: +// LLA: if (rFileStatus.isValid( FileStatusMask_Type )) +// LLA: { +// LLA: osl::FileStatus::Type eType = rFileStatus.getFileType( ); +// LLA: printFileType(eType); +// LLA: CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Socket, Solaris version ", +// LLA: ( eType == ::osl::FileStatus::Socket ) ); +// LLA: } +// LLA: #endif +// LLA: } + + +// deprecated since there is a same case Directory::getNextItem_004 +/*#if defined 0 //( UNX ) //( SOLARIS ) //Link file is not defined in Windows + void getFileType_006( ) + { + nError1 = ::osl::DirectoryItem::get( aTypeURL3, m_aLinkItem ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //check for File type + ::osl::FileStatus rFileStatus( FileStatusMask_Type ); + nError1 = m_aLinkItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Link, UNX version ", + ( ::osl::FileStatus::Link == rFileStatus.getFileType( ) ) ); + } +#endif */ + + void getFileType_007( ) + { +#if defined ( SOLARIS ) //Special file is differ in Windows + nError1 = ::osl::DirectoryItem::get( aTypeURL2, m_aSpecialItem ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //check for File type + ::osl::FileStatus rFileStatus( FileStatusMask_Type ); + nError1 = m_aSpecialItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + if (rFileStatus.isValid(FileStatusMask_Type)) + { + osl::FileStatus::Type eType = rFileStatus.getFileType( ); + + + CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Special, Solaris version ", + ( eType == ::osl::FileStatus::Special ) ); + } +#endif + } + + CPPUNIT_TEST_SUITE( getFileType ); + CPPUNIT_TEST( getFileType_001 ); + CPPUNIT_TEST( getFileType_002 ); + CPPUNIT_TEST( getFileType_003 ); + CPPUNIT_TEST( getFileType_004 ); + // LLA: CPPUNIT_TEST( getFileType_005 ); + //CPPUNIT_TEST( getFileType_006 ); + CPPUNIT_TEST( getFileType_007 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFileType + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt64 getAttributes() const + //--------------------------------------------------------------------- + class getAttributes : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL, aTypeURL_Hid; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem, rItem_hidden; + + public: + // initialization + void setUp( ) + { + aTypeURL = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL, aTmpName2 ); + createTestFile( aTypeURL ); + nError = ::osl::DirectoryItem::get( aTypeURL, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + aTypeURL_Hid = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL_Hid, aHidURL1 ); + createTestFile( aTypeURL_Hid ); + nError = ::osl::DirectoryItem::get( aTypeURL_Hid, rItem_hidden ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + } + + void tearDown( ) + { + deleteTestFile( aTypeURL ); + deleteTestFile( aTypeURL_Hid ); + } + + // test code. +#if ( defined UNX ) || ( defined OS2 ) +//windows only 3 file attributes: normal, readonly, hidden + void getAttributes_001( ) + { + changeFileMode( aTypeURL, S_IRUSR | S_IRGRP | S_IROTH ); + + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( UNX version ) ", + ( Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ) == + rFileStatus.getAttributes( ) ); + } +#else //Windows version + void getAttributes_001( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( Windows version )", + 1 == 1 ); + } +#endif + + + void getAttributes_002( ) + { +#if ( defined UNX ) || ( defined OS2 ) + changeFileMode( aTypeURL, S_IXUSR | S_IXGRP | S_IXOTH ); + + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Executable, GrpExe, OwnExe, OthExe, the result is Readonly, Executable, GrpExe, OwnExe, OthExe, it partly not pass( Solaris version )", + ( Attribute_ReadOnly | Attribute_Executable | Attribute_GrpExe | Attribute_OwnExe | Attribute_OthExe ) == + rFileStatus.getAttributes( ) ); +#endif + } + + +#if ( defined UNX ) || ( defined OS2 ) + void getAttributes_003( ) + { + changeFileMode( aTypeURL, S_IWUSR | S_IWGRP | S_IWOTH ); + + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Solaris version )", + ( Attribute_GrpWrite | Attribute_OwnWrite | Attribute_OthWrite ) == + rFileStatus.getAttributes( ) ); + } +#else //Windows version + void getAttributes_003( ) + { + CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Windows version )", + 1 == 1 ); + } +#endif + +#if ( defined UNX ) || ( defined OS2 ) //hidden file definition may different in Windows + void getAttributes_004( ) + { + sal_Int32 test_Attributes = Attribute_Hidden; + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError = rItem_hidden.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + test_Attributes &= rFileStatus.getAttributes( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Hidden files( Solaris version )", + test_Attributes == Attribute_Hidden ); + } +#else //Windows version + void getAttributes_004( ) + { + ::rtl::OUString aUserHiddenFileURL = ::rtl::OUString::createFromAscii("file:///c:/AUTOEXEC.BAT"); + nError = ::osl::DirectoryItem::get( aUserHiddenFileURL, rItem_hidden ); + //printFileName( aUserHiddenFileURL ); + CPPUNIT_ASSERT_MESSAGE("get item fail", nError == FileBase::E_None ); + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError = rItem_hidden.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "Hidden files(Windows version), please check if hidden file c:/AUTOEXEC.BAT exists ", + (rFileStatus.getAttributes( ) & 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( ); + };// class getAttributes + + //--------------------------------------------------------------------- + // testing the method + // inline TimeValue getAccessTime() const + //--------------------------------------------------------------------- + class getAccessTime : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + aTypeURL = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL, aTmpName2 ); + createTestFile( aTypeURL ); + nError = ::osl::DirectoryItem::get( aTypeURL, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + } + + void tearDown( ) + { + deleteTestFile( aTypeURL ); + } + + // test code. + void getAccessTime_001( ) + { + TimeValue *pTV_current = NULL; + CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + TimeValue *pTV_access = NULL; + CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + + ::osl::FileStatus rFileStatus( FileStatusMask_AccessTime ); + nError = rItem.getFileStatus( rFileStatus ); + sal_Bool bOk = osl_getSystemTime( pTV_current ); + CPPUNIT_ASSERT( sal_True == bOk && nError == FileBase::E_None ); + + *pTV_access = rFileStatus.getAccessTime( ); + + sal_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 pricision 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. ", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getAccessTime ); + CPPUNIT_TEST( getAccessTime_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getAccessTime + + //--------------------------------------------------------------------- + // testing the method + // inline TimeValue getModifyTime() const + //--------------------------------------------------------------------- + class getModifyTime : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem; + + public: + + // test code. + void getModifyTime_001( ) + { + TimeValue *pTV_current = NULL; + CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + + //create file + aTypeURL = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL, aTmpName2 ); + createTestFile( aTypeURL ); + + //get current time + sal_Bool bOk = osl_getSystemTime( pTV_current ); + CPPUNIT_ASSERT( sal_True == bOk ); + + //get instance item and filestatus + nError = ::osl::DirectoryItem::get( aTypeURL, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + ::osl::FileStatus rFileStatus( FileStatusMask_ModifyTime ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + //get modify time + TimeValue *pTV_modify = NULL; + CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + *pTV_modify = rFileStatus.getModifyTime( ); + + sal_Bool bOK = t_compareTime( pTV_modify, pTV_current, delta ); + //delete file + deleteTestFile( aTypeURL ); + free( pTV_current ); + + CPPUNIT_ASSERT_MESSAGE( "test for getModifyTime function: This test turns out that UNX pricision is no more than 1 sec, don't know how to improve this function. ", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getModifyTime ); + CPPUNIT_TEST( getModifyTime_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getModifyTime + + + //--------------------------------------------------------------------- + // testing the method + // inline sal_uInt64 getFileSize() const + //--------------------------------------------------------------------- + class getFileSize : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + aTypeURL = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL, aTmpName2 ); + createTestFile( aTypeURL ); + nError = ::osl::DirectoryItem::get( aTypeURL, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + } + + void tearDown( ) + { + deleteTestFile( aTypeURL ); + } + + // test code. + void getFileSize_001( ) + { + ::osl::FileStatus rFileStatus( FileStatusMask_FileSize ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + sal_uInt64 uFileSize = rFileStatus.getFileSize( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: empty file ", + 0 == uFileSize ); + } + + void getFileSize_002( ) + { + ::osl::File testfile( aTypeURL ); + nError = testfile.open( OpenFlag_Write | OpenFlag_Read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError ); + nError = testfile.setSize( TEST_FILE_SIZE ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError ); + + nError = ::osl::DirectoryItem::get( aTypeURL, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + ::osl::FileStatus rFileStatus( FileStatusMask_FileSize ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + sal_uInt64 uFileSize = rFileStatus.getFileSize( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: file with size of TEST_FILE_SIZE, did not pass in (W32). ", + TEST_FILE_SIZE == uFileSize ); + } + CPPUNIT_TEST_SUITE( getFileSize ); + CPPUNIT_TEST( getFileSize_001 ); + CPPUNIT_TEST( getFileSize_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFileSize + + //--------------------------------------------------------------------- + // testing the method + // inline ::rtl::OUString getFileName() const + //--------------------------------------------------------------------- + class getFileName : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + aTypeURL = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL, aTmpName2 ); + createTestFile( aTypeURL ); + nError = ::osl::DirectoryItem::get( aTypeURL, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + } + + void tearDown( ) + { + deleteTestFile( aTypeURL ); + } + + // test code. + void getFileName_001( ) + { + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + ::rtl::OUString aFileName = rFileStatus.getFileName( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileName function: name compare with specify", + sal_True == compareFileName( aFileName, aTmpName2 ) ); + } + + CPPUNIT_TEST_SUITE( getFileName ); + CPPUNIT_TEST( getFileName_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFileName + + //--------------------------------------------------------------------- + // testing the method + // inline ::rtl::OUString getFileURL() const + //--------------------------------------------------------------------- + class getFileURL : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + createTestFile( aTmpName6 ); + nError = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + } + + void tearDown( ) + { + deleteTestFile( aTmpName6 ); + } + + // test code. + void getFileURL_001( ) + { + ::osl::FileStatus rFileStatus( FileStatusMask_FileURL ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError == FileBase::E_None ); + + ::rtl::OUString aFileURL = rFileStatus.getFileURL( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileURL function: ", + sal_True == compareFileName( aFileURL, aTmpName6 ) ); + } + + CPPUNIT_TEST_SUITE( getFileURL ); + CPPUNIT_TEST( getFileURL_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFileURL + + //--------------------------------------------------------------------- + // testing the method + // inline ::rtl::OUString getLinkTargetURL() const + //--------------------------------------------------------------------- + class getLinkTargetURL : public CppUnit::TestFixture + { + ::rtl::OUString aTypeURL; + ::osl::FileBase::RC nError; + ::osl::DirectoryItem rItem; + + public: + // test code. + // initialization + void setUp( ) + { + aTypeURL = aUserDirectoryURL.copy( 0 ); + concatURL( aTypeURL, aTmpName2 ); + createTestFile( aTypeURL ); + } + + void tearDown( ) + { + deleteTestFile( aTypeURL ); + } + +#if ( defined UNX ) || ( defined OS2 ) //Link file is not define in Windows + void getLinkTargetURL_001( ) + { + //create a link file; + ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys ); + ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file"); + ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpname"); + + rtl::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_MESSAGE( "in creating link file", fd == 0 ); + + //get linkTarget URL + nError = ::osl::DirectoryItem::get( aLnkURL1, rItem ); + CPPUNIT_ASSERT_MESSAGE( "in getting link file item", nError == FileBase::E_None ); + + ::osl::FileStatus rFileStatus( FileStatusMask_LinkTargetURL ); + nError = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT_MESSAGE( "in getting link file status", nError == FileBase::E_None ); + ::rtl::OUString aFileURL = rFileStatus.getLinkTargetURL( ); + + //remove link file + fd = remove( strLinkFileName.getStr() ); + CPPUNIT_ASSERT_MESSAGE( "in deleting link file", fd == 0 ); + + CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Solaris version, creat a file, and a link file link to it, get its LinkTargetURL and compare", + sal_True == 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( ); + };// class getLinkTargetURL + + // ----------------------------------------------------------------------------- + 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_FileStatus + + + +//------------------------------------------------------------------------ +// Beginning of the test cases for File class +//------------------------------------------------------------------------ +namespace osl_File +{ + //--------------------------------------------------------------------- + // testing the method + // File( const ::rtl::OUString& ustrFileURL ) + //--------------------------------------------------------------------- + class ctors : public CppUnit::TestFixture + { + // ::osl::FileBase::RC nError1; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void ctors_001( ) + { + ::osl::File testFile( aTmpName4 ); + + ::osl::FileBase::RC nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + ::osl::FileBase::RC nError2 = testFile.close( ); + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a File and test its open and close", + ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) ); + } + + void ctors_002( ) + { + ::osl::File testFile( aTmpName5 ); + sal_Char buffer[30] = "Test for File constructor"; + sal_uInt64 nCount; + + ::osl::FileBase::RC nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + ::osl::FileBase::RC nError2 = testFile.write( buffer, 30, nCount ); + testFile.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: test relative file URL, this test show that relative file URL is also acceptable", + ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class ctors + + //--------------------------------------------------------------------- + // testing the method + // inline RC open( sal_uInt32 uFlags ) + //--------------------------------------------------------------------- + class open : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2, nError3; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void open_001( ) + { + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + nError2 = testFile.close( ); + CPPUNIT_ASSERT_MESSAGE("close error", ::osl::FileBase::E_None == nError2 ); + + CPPUNIT_ASSERT_MESSAGE( "test for open function: open a regular file", + ::osl::FileBase::E_None == nError1 ); + } + + void open_002( ) + { + ::osl::File testFile( aTmpName3 ); + + nError1 = testFile.open( OpenFlag_Read ); + + CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory", + ( File::E_INVAL == nError1 ) || ( File::E_ACCES == nError1 ) ); + } + + void open_003( ) + { + ::osl::File testFile( aCanURL1 ); + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + + CPPUNIT_ASSERT_MESSAGE( "test for open function: open a non-exist file", + File::E_NOENT == nError1 ); + } + + void open_004( ) + { + ::rtl::OUString aTestFile( aRootURL ); + concatURL( aTestFile, aTmpName2 ); + ::osl::File testFile( aTestFile ); + + nError1 = testFile.open( OpenFlag_Create ); + sal_Bool bOK = ( File::E_ACCES == nError1 ); +#if defined (WNT ) + bOK = sal_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 == sal_True ); + } + + void open_005( ) + { + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Create ); + + CPPUNIT_ASSERT_MESSAGE( "test for open function: create an exist file", + File::E_EXIST == nError1 ); + } + + void open_006( ) + { + ::osl::File testFile( aCanURL1 ); + sal_Char buffer_write[30] = "Test for File open"; + sal_Char buffer_read[30]; + sal_uInt64 nCount_write, nCount_read; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create ); + nError2 = testFile.write( buffer_write, 30, nCount_write ); + ::osl::FileBase::RC nError4 = testFile.setPos( Pos_Absolut, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError4 ); + nError3 = testFile.read( buffer_read, 10, nCount_read ); + + ::osl::FileBase::RC nError5 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError5 ); + ::osl::FileBase::RC nError6 = testFile.remove( aCanURL1 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError6 ); + + CPPUNIT_ASSERT_MESSAGE( "test for open function: test for OpenFlag_Read,OpenFlag_Write and OpenFlag_Create", + ( ::osl::FileBase::E_None == nError1 ) && + ( ::osl::FileBase::E_None == nError2 ) && + ( ::osl::FileBase::E_None == nError3 ) && + ( 30 == nCount_write ) && + ( 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( ); + };// class open + + //--------------------------------------------------------------------- + // testing the method + // inline RC close() + //--------------------------------------------------------------------- + class close : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2, nError3; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void close_001( ) + { + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError2 = testFile.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for close function: close a regular file", + ::osl::FileBase::E_None == nError2 ); + } + + void close_002( ) + { + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError2 = testFile.close( ); + + nError3 = testFile.setPos( Pos_Absolut, 0 ); + + CPPUNIT_ASSERT_MESSAGE( "test for close function: manipulate a file after it has been closed", + ( ::osl::FileBase::E_None == nError2 ) && + ( ::osl::FileBase::E_None != nError3 ) ); + } + + CPPUNIT_TEST_SUITE( close ); + CPPUNIT_TEST( close_001 ); + CPPUNIT_TEST( close_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class close + + + //--------------------------------------------------------------------- + // testing the method + // inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos ) + //--------------------------------------------------------------------- + class setPos : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void setPos_001( ) + { + ::osl::File testFile( aTmpName4 ); + sal_Char buffer_read[2]; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.setPos( Pos_Absolut, 26 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.read( buffer_read, 1, nCount_read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_Absolut, set the position to 26, test if the 26th char in file is correct", + buffer_read[0] == pBuffer_Char[26] ); + } + + void setPos_002( ) + { + ::osl::File testFile( aTmpName4 ); + sal_Char buffer_read[2]; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.setPos( Pos_Absolut, sizeof( pBuffer_Char ) - 2 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.setPos( Pos_Current, 0); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.read( buffer_read, 1, nCount_read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_Current, set the position to end, test if the ( end -1 ) char in file is correct", + buffer_read[0] == pBuffer_Char[sizeof( pBuffer_Char ) - 2] ); + } + + void setPos_003( ) + { + ::osl::File testFile( aTmpName4 ); + sal_Char buffer_read[2]; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //the file size is smaller than 100 + nError1 = testFile.setPos( Pos_End, -100 ); + CPPUNIT_ASSERT_MESSAGE( "should return error", ::osl::FileBase::E_INVAL == nError1 ); + + nError1 = testFile.setPos( Pos_End, -53 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.read( buffer_read, 1, nCount_read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_End, set the position to end, test if the first char in file is correct", + buffer_read[0] == pBuffer_Char[0] ); + } + + CPPUNIT_TEST_SUITE( setPos ); + CPPUNIT_TEST( setPos_001 ); + CPPUNIT_TEST( setPos_002 ); + CPPUNIT_TEST( setPos_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class setPos + + //--------------------------------------------------------------------- + // testing the method + // inline RC getPos( sal_uInt64& uPos ) + //--------------------------------------------------------------------- + class getPos : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void getPos_001( ) + { + ::osl::File testFile( aTmpName4 ); + sal_uInt64 nFilePointer; + + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_INVAL == nError1 ); + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.setPos( Pos_Absolut, 26 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPos function: set the position to 26, get position and check if it is right", + 26 == nFilePointer ); + } + + CPPUNIT_TEST_SUITE( getPos ); + CPPUNIT_TEST( getPos_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getPos + + + //--------------------------------------------------------------------- + // testing the method + // inline RC isEndOfFile( sal_Bool *pIsEOF ) + //--------------------------------------------------------------------- + class isEndOfFile : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void isEndOfFile_001( ) + { + ::osl::File testFile( aTmpName4 ); + sal_Bool bEOF = sal_False; + sal_Bool *pEOF = &bEOF; + + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.setPos( Pos_End, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.isEndOfFile( pEOF ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: set the position to end, check if reach end", + sal_True == *pEOF ); + } + + void isEndOfFile_002( ) + { + ::osl::File testFile( aTmpName4 ); + sal_Bool bEOF = sal_False; + sal_Bool *pEOF = &bEOF; + sal_uInt64 nFilePointer = 0; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.setPos( Pos_Absolut, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + *pEOF = sal_False; + while ( !( *pEOF ) ) + { + nError1 = testFile.isEndOfFile( pEOF ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.setPos( Pos_Current, 1 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: use isEndOfFile to move pointer step by step", + sizeof( pBuffer_Char ) + 1 == nFilePointer ); + } + CPPUNIT_TEST_SUITE( isEndOfFile ); + CPPUNIT_TEST( isEndOfFile_001 ); + CPPUNIT_TEST( isEndOfFile_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class isEndOfFile + + + //--------------------------------------------------------------------- + // testing the method + // inline RC setSize( sal_uInt64 uSize ) + //--------------------------------------------------------------------- + class setSize : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void setSize_001( ) + { + ::osl::File testFile( aTmpName4 ); + // sal_Bool bEOF = sal_False; + // sal_Bool *pEOF = &bEOF; + sal_uInt64 nFilePointer; + + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //enlarge the file to size of 100; + nError1 = testFile.setSize( 100 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //get the file size; + nError1 = testFile.setPos( Pos_End, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setSize function: enlarge the file ", + 100 == nFilePointer ); + } + + void setSize_002( ) + { + ::osl::File testFile( aTmpName4 ); + // sal_Bool bEOF = sal_False; + // sal_Bool *pEOF = &bEOF; + sal_uInt64 nFilePointer; + + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //enlarge the file to size of 100; + nError1 = testFile.setSize( 10 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //get the file size; + nError1 = testFile.setPos( Pos_End, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ", + 10 == nFilePointer ); + } + /* void setSize_003( ) + { + ::osl::File testFile( aTmpName4 ); + // sal_Bool bEOF = sal_False; + // sal_Bool *pEOF = &bEOF; + sal_uInt64 nFilePointer; + + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //enlarge the file to size of 100; + nError1 = testFile.setSize( 10 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //get the file size; + nError1 = testFile.setPos( Pos_End, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ", + 10 == nFilePointer ); + } + */ + + CPPUNIT_TEST_SUITE( setSize ); + CPPUNIT_TEST( setSize_001 ); + CPPUNIT_TEST( setSize_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class setSize + + + //--------------------------------------------------------------------- + // testing the method + // inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead ) + //--------------------------------------------------------------------- + class read : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void read_001( ) + { + ::osl::File testFile( aTmpName4 ); + sal_uInt64 nFilePointer; + sal_Char buffer_read[10]; + + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.read( buffer_read, 10, nCount_read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for read function: read whole content in the file to a buffer", + ( 10 == nFilePointer ) && ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) ); + } + + void read_002( ) + { + ::osl::File testFile( aTmpName4 ); + sal_uInt64 nFilePointer; + sal_Char buffer_read[26]; + + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.setPos( Pos_Absolut, 26 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.read( buffer_read, 26, nCount_read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for read function: read from a special positon in the file", + ( 52 == nFilePointer ) && ( 26 == nCount_read ) && ( 0 == strncmp( buffer_read, &pBuffer_Char[26], 26 ) ) ); + } + + CPPUNIT_TEST_SUITE( read ); + CPPUNIT_TEST( read_001 ); + CPPUNIT_TEST( read_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class read + + //--------------------------------------------------------------------- + // 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: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void write_001( ) + { + ::osl::File testFile( aTmpName6 ); + sal_uInt64 nFilePointer; + sal_Char buffer_read[10]; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //write chars into the file. + nError1 = testFile.write( pBuffer_Char, 10, nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //get the current pointer; + nError1 = testFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //reset pointer to the begining; + nError1 = testFile.setPos( Pos_Absolut, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.read( buffer_read, 10, nCount_read ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for write function: read whole content in the file to a buffer. Note, buffer size can not smaller than the read size", + ( 10 == nFilePointer ) && + ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) && + ( 10 == nCount_write ) ); + } + + CPPUNIT_TEST_SUITE( write ); + CPPUNIT_TEST( write_001 ); + CPPUNIT_TEST_SUITE_END( ); + };// class write + + //--------------------------------------------------------------------- + // testing the method + // inline RC readLine( ::rtl::ByteSequence& aSeq ) + //--------------------------------------------------------------------- + class readLine : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + ::rtl::ByteSequence aSequence; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpname. + createTestFile( aTmpName6 ); + + //write some strings into the file. + ::osl::File testFile( aTmpName6 ); + sal_Char ppStrSeq[3][27] = { "abcde\n", + "1234567890\n", + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + }; + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + for ( int nCount = 0; nCount < 3; nCount++ ) + { + nError1 = testFile.write( ppStrSeq[nCount], strlen( ppStrSeq[nCount] ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void readLine_001( ) + { + ::osl::File testFile( aTmpName6 ); + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.readLine( aSequence ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read the first line of the file.", + ( ::osl::FileBase::E_None == nError1 ) && + ( 0 == strncmp( ( const char * )aSequence.getArray( ), pBuffer_Char, 5 ) ) ); + } + + void readLine_002( ) + { + ::osl::File testFile( aTmpName6 ); + sal_Bool bEOF = sal_False; + sal_Bool *pEOF = &bEOF; + + nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + for ( int nCount = 0; nCount < 3; nCount++ ) + { + nError1 = testFile.readLine( aSequence ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + nError1 = testFile.isEndOfFile( pEOF ); + CPPUNIT_ASSERT( ::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 && + ( 0 == strncmp( ( const char * )aSequence.getArray( ), &pBuffer_Char[26], 26 ) ) ); + } + CPPUNIT_TEST_SUITE( readLine ); + CPPUNIT_TEST( readLine_001 ); + CPPUNIT_TEST( readLine_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class readLine + + //--------------------------------------------------------------------- + // testing the method + // inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL ) + //--------------------------------------------------------------------- + class copy : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void copy_001( ) + { + ::osl::File testFile( aTmpName6 ); + + //copy $TEMP/tmpdir/tmpname to $TEMP/tmpname. + nError1 = ::osl::File::copy( aTmpName4, aTmpName6 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //check + nError1 = testFile.open( OpenFlag_Create ); + deleteTestFile( aTmpName6 ); + + CPPUNIT_ASSERT_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 = ::osl::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 = ::osl::File::copy( aTmpName4, aTmpName7 ); +#if defined (WNT ) + nError1 = ::osl::FileBase::E_ACCES; /// for Windows, c:/ is writtenable any way. + deleteTestFile( aTmpName7); +#endif + CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy to an illigal place", + ::osl::FileBase::E_ACCES == nError1 ); + } + + void copy_004( ) + { + //copy $TEMP/tmpname to $TEMP/tmpdir/tmpname. + nError1 = ::osl::File::copy( aTmpName6, aTmpName4 ); + + CPPUNIT_ASSERT_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 = ::osl::File::copy( aTmpName6, aSysPath1 ); + + CPPUNIT_ASSERT_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 ); + FileBase::RC err = tmpFile.open( OpenFlag_Write | OpenFlag_Read ); + (void)err; + tmpFile.setSize( 200 ); + tmpFile.close(); + //copy to new path + nError1 = ::osl::File::copy( aTmpName6, aTmpName4 ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + + //check if is the new file + File newFile( aTmpName4 ); + newFile.open( OpenFlag_Write | OpenFlag_Read ); + newFile.setPos( Pos_End, 0 ); + // CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + sal_uInt64 nFilePointer; + nError1 = newFile.getPos( nFilePointer ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + newFile.close( ); + deleteTestFile( aTmpName6 ); + CPPUNIT_ASSERT_MESSAGE( "test for copy function: the dest file exist", + nFilePointer == 200 ); + } + //copyLink has not been impletmented yet + void copy_007( ) + { +#if ( defined UNX ) + + CPPUNIT_ASSERT_MESSAGE( "test for copy function: source file is link file", + ::osl::FileBase::E_INVAL == nError1 ); +#endif + } + + 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( ); + };// class copy + + //--------------------------------------------------------------------- + // testing the method + // inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL ) + //--------------------------------------------------------------------- + class move : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void move_001( ) + { + //rename $TEMP/tmpdir/tmpname to $TEMP/canonical.name. + nError1 = ::osl::File::move( aTmpName4, aCanURL1 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //check + ::osl::File testFile( aCanURL1 ); + nError2 = testFile.open( OpenFlag_Create ); + deleteTestFile( aCanURL1 ); + + CPPUNIT_ASSERT_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 = ::osl::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 = ::osl::File::move( aTmpName4, aTmpName7 ); +#if defined (WNT ) + nError1 = ::osl::FileBase::E_ACCES; /// for Windows, c:/ is writtenable any way. + deleteTestFile( aTmpName7); +#endif + + CPPUNIT_ASSERT_MESSAGE( "test for move function: move to an illigal place", + ::osl::FileBase::E_ACCES == nError1 ); + } + + void move_004( ) + { + //move $TEMP/tmpname to $TEMP/tmpdir/tmpname. + nError1 = ::osl::File::move( aTmpName6, aTmpName4 ); + + CPPUNIT_ASSERT_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 = ::osl::File::move( aTmpName6, aSysPath1 ); + + CPPUNIT_ASSERT_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 = ::osl::File::move( aTmpName6, aTmpName4 ); + //move file $TEMP/tmpdir/tmpname to $TEMP/tmpname + nError2 = ::osl::File::move( aTmpName4, aTmpName6 ); + deleteTestDirectory( aTmpName6 ); +#if defined ( WNT ) + 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_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 && ::osl::FileBase::E_ISDIR == nError2 ); + } + + void move_007( ) + { + //create directory $TEMP/tmpname. + createTestDirectory( aTmpName6 ); + //move directory $TEMP/tmpdir to $TEMP/tmpname/tmpdir + nError1 = ::osl::File::move( aTmpName3, aTmpName8 ); + //check + nError2 = ::osl::Directory::create( aTmpName8 ); + ::osl::File::move( aTmpName8, aTmpName3 ); + deleteTestDirectory( aTmpName6 ); + + CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name", + (::osl::FileBase::E_None == nError1 ) && + (::osl::FileBase::E_EXIST == nError2 ) ); + } + // oldpath and newpath are not on the same filesystem.EXDEV,no such error no on Solaris, only on linux + void move_008( ) + { + CPPUNIT_ASSERT_MESSAGE( "oldpath and newpath are not on the same filesystem, should error returns", + ::osl::FileBase::E_None == nError1 ); + } + //bugid# 115420, after the bug fix, add the case + void move_009( ) + { + //create directory $TEMP/tmpname. + createTestDirectory( aTmpName6 ); + //create directory $TEMP/tmpname/tmpdir + createTestDirectory( aTmpName8 ); + //move directory $TEMP/tmpname to $TEMP/tmpname/tmpdir/tmpname + rtl::OUString newName = aTmpName8 + OUString::createFromAscii("/tmpname"); + //printFileName( newName ); + nError1 = ::osl::File::move( aTmpName3, newName ); + //deleteTestDirectory( newName + OUString::createFromAscii("/tmpname") ); + //deleteTestDirectory( newName ); + deleteTestDirectory( aTmpName8 ); + deleteTestDirectory( aTmpName6 ); + CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to it's subdirectory", + ::osl::FileBase::E_None != nError1 ); + } + + 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( move_008 ); + //CPPUNIT_TEST( move_009 ); + CPPUNIT_TEST_SUITE_END( ); + };// class move + + + //--------------------------------------------------------------------- + // testing the method + // inline static RC remove( const ::rtl::OUString& ustrFileURL ) + //--------------------------------------------------------------------- + class remove : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + sal_uInt64 nCount_write, nCount_read; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + + //write chars into the file. + ::osl::File testFile( aTmpName4 ); + + nError1 = testFile.open( OpenFlag_Write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = testFile.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void remove_001( ) + { + //remove $TEMP/tmpdir/tmpname. + nError1 = ::osl::File::remove( aTmpName4 ); + //check + ::osl::File testFile( aTmpName4 ); + nError2 = testFile.open( OpenFlag_Create ); + + CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file", + ( ::osl::FileBase::E_None == nError1 ) && + ( ::osl::FileBase::E_EXIST != nError2 ) ); + } + + void remove_002( ) + { + //remove $TEMP/tmpname. + nError1 = ::osl::File::remove( aTmpName6 ); + + CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file not exist", + ( ::osl::FileBase::E_NOENT == nError1 ) ); + } + + void remove_003( ) + { + //remove $TEMP/system/path. + nError1 = ::osl::File::remove( aSysPath2 ); + + CPPUNIT_ASSERT_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 = ::osl::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( ); + };// class remove + + + //--------------------------------------------------------------------- + // testing the method + // inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes ) + //--------------------------------------------------------------------- + class setAttributes : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + ::osl::DirectoryItem rItem, rItem_hidden; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void setAttributes_001( ) + { + //on windows, only can set 2 attributes: Attribute_ReadOnly, Attribute_HIDDEN +#ifdef UNX + //set the file to readonly + nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ); + CPPUNIT_ASSERT( nError2 == FileBase::E_None); + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None); + //get the file attributes + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.", + ( Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ) == + rFileStatus.getAttributes( ) ); +#else + //please see GetFileAttributes + nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly ); + CPPUNIT_ASSERT( nError2 == FileBase::E_None); + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None); + //get the file attributes + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + //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 + /*::rtl::OString aString = ::rtl::OUStringToOString( aTmpName6, RTL_TEXTENCODING_ASCII_US ); + DWORD dwFileAttributes = GetFileAttributes( aString.getStr( ) ); + if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL) + t_print("has normal attribute"); + if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) + t_print("has readonly attribute"); + */ + CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes READONLY and get it to verify.", + (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 WNT + //set the file to hidden + nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_Hidden); + + CPPUNIT_ASSERT( nError2 == FileBase::E_None); + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None); + //get the file attributes + ::osl::FileStatus rFileStatus( FileStatusMask_Attributes ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.", + (Attribute_Hidden & rFileStatus.getAttributes( )) != 0 ); +#endif + } + + CPPUNIT_TEST_SUITE( setAttributes ); + CPPUNIT_TEST( setAttributes_001 ); + CPPUNIT_TEST( setAttributes_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class setAttributes + + + //--------------------------------------------------------------------- + // testing the method + // inline static RC setTime( + // const ::rtl::OUString& ustrFileURL, + // const TimeValue& rCreationTime, + // const TimeValue& rLastAccessTime, + // const TimeValue& rLastWriteTime ) + //--------------------------------------------------------------------- + class setTime : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void setTime_001( ) + { + TimeValue *pTV_current = NULL; + CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + TimeValue *pTV_creation = NULL; + CPPUNIT_ASSERT( ( pTV_creation = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + TimeValue *pTV_access = NULL; + CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + TimeValue *pTV_modify = NULL; + CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL ); + + //get current time + sal_Bool bOk = osl_getSystemTime( pTV_current ); + CPPUNIT_ASSERT( sal_True == bOk ); + + //set the file time + nError2 = ::osl::File::setTime( aTmpName6, *pTV_current, *pTV_current, *pTV_current ); + CPPUNIT_ASSERT_MESSAGE( errorToStr( nError2 ), nError2 == FileBase::E_None); + + //get the file access time, creation time, modify time + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None); + + ::osl::FileStatus rFileStatus( FileStatusMask_AccessTime ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ),nError1 == FileBase::E_None ); + *pTV_access = rFileStatus.getAccessTime( ); + + ::osl::FileStatus rFileStatus1( FileStatusMask_CreationTime ); + nError1 = rItem.getFileStatus( rFileStatus1 ); + CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None ); + *pTV_creation = rFileStatus1.getCreationTime( ); + + ::osl::FileStatus rFileStatus2( FileStatusMask_ModifyTime ); + nError1 = rItem.getFileStatus( rFileStatus2 ); + CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None ); + *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.", + sal_True == t_compareTime( pTV_access, pTV_current, delta ) ); +#if defined ( WNT ) + //Unfortunately there is no way to get the creation time of a file under Unix (its 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. ", + sal_True == t_compareTime( pTV_creation, pTV_current, delta ) ) ; +#endif + CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set modify time then get it. ", + sal_True == 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( ); + };// class setTime + + //--------------------------------------------------------------------- + // testing the method + // inline static RC sync() + //--------------------------------------------------------------------- + class sync : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestFile( aTmpName6 ); + + } + + void tearDown( ) + { + // 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 + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None); + + File tmp_file( aTmpName6 ); + FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write ); + + CPPUNIT_ASSERT_MESSAGE("File open failed", err == FileBase::E_None); + + char buffer[50000]; + sal_uInt64 written = 0; + nError1 = tmp_file.write((void*)buffer, sizeof(buffer), written); + CPPUNIT_ASSERT_MESSAGE("write failed!", nError1 == FileBase::E_None); + + //set the file to readonly + nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ); + CPPUNIT_ASSERT( nError2 == FileBase::E_None); + + nError2 = tmp_file.sync(); + + CPPUNIT_ASSERT_MESSAGE("can not sync to readonly file!", nError2 == FileBase::E_None); + + 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( ); + };// class setTime + + // ----------------------------------------------------------------------------- + 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" ); + +}// namespace osl_File + + +//------------------------------------------------------------------------ +// Beginning of the test cases for DirectoryItem class +//------------------------------------------------------------------------ +namespace osl_DirectoryItem +{ + //--------------------------------------------------------------------- + // testing the method + // DirectoryItem(): _pData( NULL ) + //--------------------------------------------------------------------- + class ctors : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void ctors_001( ) + { + ::osl::File testFile( aTmpName6 ); + ::osl::DirectoryItem rItem; //constructor + + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_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( ); + };// class ctors + + //--------------------------------------------------------------------- + // testing the method + // DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData) + //--------------------------------------------------------------------- + class copy_assin_Ctors : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void copy_assin_Ctors_001( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( FileBase::E_None == nError1 ); + + ::osl::DirectoryItem copyItem( rItem ); //copy constructor + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError1 = copyItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: use copy constructor to get an item and check filename.", + ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) ); + } + + void copy_assin_Ctors_002( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( FileBase::E_None == nError1 ); + + ::osl::DirectoryItem copyItem; + copyItem = rItem; //assinment operator + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError1 = copyItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: test assinment operator here since it is same as copy constructor in test way.", + ( sal_True == 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( ); + };// class copy_assin_Ctors + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool is() + //--------------------------------------------------------------------- + class is : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void is_001( ) + { + ::osl::DirectoryItem rItem; //constructor + + CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.", + !rItem.is( ) ); + } + + void is_002( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + CPPUNIT_ASSERT( FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.", + ( sal_True == rItem.is( ) ) ); + } + + CPPUNIT_TEST_SUITE( is ); + CPPUNIT_TEST( is_001 ); + CPPUNIT_TEST( is_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class is + + //--------------------------------------------------------------------- + // testing the method + // static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem ) + //--------------------------------------------------------------------- + class get : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpname. + createTestFile( aTmpName6 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpname. + deleteTestFile( aTmpName6 ); + } + + // test code. + void get_001( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError2 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + + //check the file name + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( nError1 == FileBase::E_None ); + + CPPUNIT_ASSERT_MESSAGE( "test for get function: use copy constructor to get an item and check filename.", + ( ::osl::FileBase::E_None == nError2 ) && + ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) ); + } + + void get_002( ) + { + ::osl::DirectoryItem rItem; + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aSysPath1, rItem ); + + CPPUNIT_ASSERT_MESSAGE( "test for get function: use a system name instead of a URL.", + FileBase::E_INVAL == nError1 ); + } + + void get_003( ) + { + ::osl::DirectoryItem rItem; + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem ); + + CPPUNIT_ASSERT_MESSAGE( "test for get function: use a non existed file URL.", + FileBase::E_NOENT == nError1 ); + } + + CPPUNIT_TEST_SUITE( get ); + CPPUNIT_TEST( get_001 ); + CPPUNIT_TEST( get_002 ); + CPPUNIT_TEST( get_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class get + + //--------------------------------------------------------------------- + // testing the method + // inline RC getFileStatus( FileStatus& rStatus ) + //--------------------------------------------------------------------- + class getFileStatus : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void getFileStatus_001( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName4, rItem ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //check the file name + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError2 = rItem.getFileStatus( rFileStatus ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get file status and check filename", + ( ::osl::FileBase::E_None == nError2 ) && + ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) ); + } + + void getFileStatus_002( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem ); + + //check the file name + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError2 = rItem.getFileStatus( rFileStatus ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: file not existed", + ( ::osl::FileBase::E_INVAL == nError2 ) ); + } + + void getFileStatus_003( ) + { + ::osl::DirectoryItem rItem; //constructor + //get the DirectoryItem. + nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //check the file name + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError2 = rItem.getFileStatus( rFileStatus ); + + CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get directory information", + ( ::osl::FileBase::E_None == nError2 ) && + ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName1 ) ) ); + } + + + CPPUNIT_TEST_SUITE( getFileStatus ); + CPPUNIT_TEST( getFileStatus_001 ); + CPPUNIT_TEST( getFileStatus_002 ); + CPPUNIT_TEST( getFileStatus_003 ); + CPPUNIT_TEST_SUITE_END( ); + };// class getFileStatus + + + + 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" ); +}// namespace osl_DirectoryItem + + +//------------------------------------------------------------------------ +// Beginning of the test cases for Directory class +//------------------------------------------------------------------------ +namespace osl_Directory +{ + //--------------------------------------------------------------------- + // testing the method + // Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath ) + //--------------------------------------------------------------------- + class ctors : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + // LLA: t_print("tearDown done.\n"); + } + + // test code. + void ctors_001( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //close a directory + nError2 = testDirectory.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: create an instance and check open and close", + ( ::osl::FileBase::E_None == nError1 ) && + ( ::osl::FileBase::E_None == nError2 ) ); + } + + void ctors_002( ) + { + ::osl::Directory testDirectory( aTmpName9 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //close a directory + nError2 = testDirectory.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors function: relative URL, :-), it is also worked", + ( ::osl::FileBase::E_None == nError1 ) && + ( ::osl::FileBase::E_None == nError2 ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class ctors + + //--------------------------------------------------------------------- + // testing the method + // inline RC open() + //--------------------------------------------------------------------- + class open : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void open_001( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + //check if directory is opened. + sal_Bool bOk = testDirectory.isOpen( ); + //close a directory + nError2 = testDirectory.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory and check for open", + ( sal_True == bOk ) && + ( ::osl::FileBase::E_None == nError1 ) && + ( ::osl::FileBase::E_None == nError2 ) ); + } + + void open_002( ) + { + ::osl::Directory testDirectory( aTmpName6 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + if ( ::osl::FileBase::E_None == nError1 ) + { + nError2 = testDirectory.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 ); + } + + CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file that is not existed", + ( ::osl::FileBase::E_NOENT == nError1 ) ); + } + + void open_003( ) + { + ::osl::Directory testDirectory( aUserDirectorySys ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + if ( ::osl::FileBase::E_None == nError1 ) + { + nError2 = testDirectory.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 ); + } + + CPPUNIT_ASSERT_MESSAGE( "test for open function: using system path", + ( ::osl::FileBase::E_INVAL == nError1 ) ); + } + + void open_004( ) + { + ::osl::Directory testDirectory( aTmpName4 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + if ( ::osl::FileBase::E_None == nError1 ) + { + nError2 = testDirectory.close( ); + CPPUNIT_ASSERT( ::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 ) ); + } + + CPPUNIT_TEST_SUITE( open ); + CPPUNIT_TEST( open_001 ); + CPPUNIT_TEST( open_002 ); + CPPUNIT_TEST( open_003 ); + CPPUNIT_TEST( open_004 ); + CPPUNIT_TEST_SUITE_END( ); + };// class open + + //--------------------------------------------------------------------- + // testing the method + // inline sal_Bool isOpen() { return _pData != NULL; }; + //--------------------------------------------------------------------- + class isOpen : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempfile in $TEMP/tmpdir/tmpname. + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + } + + void tearDown( ) + { + // remove the tempfile in $TEMP/tmpdir/tmpname. + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void isOpen_001( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + //check if directory is opened. + sal_Bool bOk = testDirectory.isOpen( ); + //close a directory + nError2 = testDirectory.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: open a directory and check for open", + ( sal_True == bOk ) ); + } + + void isOpen_002( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //check if directory is opened. + sal_Bool bOk = testDirectory.isOpen( ); + + CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: do not open a directory and check for open", + !( sal_True == bOk ) ); + } + + CPPUNIT_TEST_SUITE( isOpen ); + CPPUNIT_TEST( isOpen_001 ); + CPPUNIT_TEST( isOpen_002 ); + CPPUNIT_TEST_SUITE_END( ); + };// class isOpen + + //--------------------------------------------------------------------- + // testing the method + // inline RC close() + //--------------------------------------------------------------------- + class close : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + // initialization + void setUp( ) + { + // create a tempdirectory : $TEMP/tmpdir. + createTestDirectory( aTmpName3 ); + } + + void tearDown( ) + { + // remove a tempdirectory : $TEMP/tmpdir. + deleteTestDirectory( aTmpName3 ); + } + + // test code. + void close_001( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + //close a directory + nError2 = testDirectory.close( ); + //check if directory is opened. + sal_Bool bOk = testDirectory.isOpen( ); + + CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a directory and check for open", + !( sal_True == bOk ) ); + } + + void close_002( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //close a directory + nError1 = testDirectory.close( ); + + CPPUNIT_ASSERT_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( ); + };// class close + + //--------------------------------------------------------------------- + // testing the method + // inline RC reset() + //--------------------------------------------------------------------- + class reset : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + // 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( ) + { + // 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 ); + } + + // test code. + void reset_001( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //get first Item + nError1 = testDirectory.getNextItem( rItem, 1 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //get second Item + //mindy: nError1 = testDirectory.getNextItem( rItem, 0 ); + //mindy: CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //reset enumeration + nError2 = testDirectory.reset( ); + //get reseted Item, if reset does not work, getNextItem() should return the second Item (aTmpName1) + nError1 = testDirectory.getNextItem( rItem, 0 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //check the file name + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + nError1 = rItem.getFileStatus( rFileStatus ); + //close a directory + nError1 = testDirectory.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + sal_Bool bOK1,bOK2; + bOK1 = compareFileName( rFileStatus.getFileName( ), aTmpName2 ); + bOK2 = compareFileName( rFileStatus.getFileName( ), aHidURL1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for reset function: get two directory item, reset it, then get again, check the filename", + ( ::osl::FileBase::E_None == nError2 ) && + ( sal_True == bOK1 || bOK2 ) ); + } + + void reset_002( ) + { + ::osl::Directory testDirectory( aTmpName6 ); //constructor + + //close a directory + nError1 = testDirectory.reset( ); + + CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a non existed directory", + ( ::osl::FileBase::E_NOENT == nError1 ) ); + } + + + void reset_003( ) + { + ::osl::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( ) + { + ::osl::Directory testDirectory( aUserDirectorySys ); //constructor + + //close a directory + nError1 = testDirectory.reset( ); + + CPPUNIT_ASSERT_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( ); + };// class reset + + //--------------------------------------------------------------------- + // testing the method + // inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 ) + //--------------------------------------------------------------------- + class getNextItem : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + ::osl::DirectoryItem rItem; + + public: + // initialization + void setUp( ) + { + // 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( ) + { + // 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 ); + } + + // test code. + void getNextItem_001( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + //check the file name + ::rtl::OUString strFilename; + sal_Bool bOk1 = sal_False; + sal_Bool bOk2 = sal_False; + sal_Bool bOk3 = sal_False; + ::osl::FileStatus rFileStatus( FileStatusMask_FileName ); + for ( int nCount = 0; nCount < 3; nCount++ ) + { + //get three Items + nError1 = testDirectory.getNextItem( rItem, 2 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + nError1 = rItem.getFileStatus( rFileStatus ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + switch ( nCount ) + { + case 0: bOk1 = compareFileName( rFileStatus.getFileName( ), aTmpName2 ) || compareFileName( rFileStatus.getFileName( ), aHidURL1); + break; + case 1: bOk2 = compareFileName( rFileStatus.getFileName( ), aTmpName1 ); + break; + case 2: bOk3 = compareFileName( rFileStatus.getFileName( ), aHidURL1) || compareFileName( rFileStatus.getFileName( ), aTmpName2 ); + } + } + + //close a directory + nError1 = testDirectory.close( ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive three items and check their names.", + ( sal_True == bOk1 ) && ( sal_True == bOk2 ) && ( sal_True == bOk3 ) ); + } + + void getNextItem_002( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + nError1 = testDirectory.getNextItem( rItem ); + + CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive an item in a directory which is not opened, also test for nHint's default value.", + ( ::osl::FileBase::E_INVAL == nError1 ) ); + } + + void getNextItem_003( ) + { + ::osl::Directory testDirectory( aTmpName3 ); //constructor + + //open a directory + nError1 = testDirectory.open( ); + CPPUNIT_ASSERT( ::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( ::osl::FileBase::E_None == nError1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive 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 + sal_Bool bOK = sal_False; + ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys ); + ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/link.file"); + ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/tmpname"); + rtl::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( fd == 0 ); + ::osl::Directory testDirectory( aTmpName3 ); + + //open a directory + nError1 = testDirectory.open( ); + ::rtl::OUString aFileName = ::rtl::OUString::createFromAscii("link.file"); + + while (1) { + nError1 = testDirectory.getNextItem( rItem, 4 ); + if (::osl::FileBase::E_None == nError1) { + ::osl::FileStatus rFileStatus( FileStatusMask_FileName | FileStatusMask_Type ); + rItem.getFileStatus( rFileStatus ); + if ( compareFileName( rFileStatus.getFileName( ), aFileName) == sal_True ) + { + if ( FileStatus::Link == rFileStatus.getFileType( )) + { + bOK = sal_True; + break; + } + } + } + else + break; + }; + fd = std::remove( strLinkFileName.getStr() ); + CPPUNIT_ASSERT_MESSAGE( "remove link file failed", fd == 0 ); + CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if can retrieve the link file name", + ( bOK == sal_True ) ); +#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( ); + };// class getNextItem + + //--------------------------------------------------------------------- + // testing the method + // inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo ) + //--------------------------------------------------------------------- + class getVolumeInfo : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + + // test code. + void checkValidMask(osl::VolumeInfo const& _aVolumeInfo, sal_Int32 _nMask) + { + if (_nMask == VolumeInfoMask_FileSystemName) + { + //get file system name + ::rtl::OUString aFileSysName( aNullURL ); + aFileSysName = _aVolumeInfo.getFileSystemName( ); + + sal_Bool bRes2 = compareFileName( aFileSysName, aNullURL ); + CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: getVolumeInfo of root directory.", + ( osl::FileBase::E_None == nError1 ) && + ( sal_False == bRes2 ) ); + } + if (_nMask == VolumeInfoMask_Attributes) + { + sal_Bool b1 = _aVolumeInfo.getRemoteFlag(); + sal_Bool b2 = _aVolumeInfo.getRemoveableFlag(); + sal_Bool b3 = _aVolumeInfo.getCompactDiscFlag(); + sal_Bool b4 = _aVolumeInfo.getFloppyDiskFlag(); + sal_Bool b5 = _aVolumeInfo.getFixedDiskFlag(); + sal_Bool b6 = _aVolumeInfo.getRAMDiskFlag(); + + rtl::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"; + + t_print("Attributes: %s\n", sAttr.getStr() ); + } + if (_nMask == VolumeInfoMask_TotalSpace) + { + // within Linux, df / * 1024 bytes is the result + sal_uInt64 nSize = _aVolumeInfo.getTotalSpace(); + t_print("Total space: %lld\n", nSize); + } + if (_nMask == VolumeInfoMask_UsedSpace) + { + sal_uInt64 nSize = _aVolumeInfo.getUsedSpace(); + t_print(" Used space: %lld\n", nSize); + } + if (_nMask == VolumeInfoMask_FreeSpace) + { + sal_uInt64 nSize = _aVolumeInfo.getFreeSpace(); + t_print(" Free space: %lld\n", nSize); + } + if (_nMask == VolumeInfoMask_MaxNameLength) + { + sal_uInt32 nLength = _aVolumeInfo.getMaxNameLength(); + t_print("max name length: %ld\n", nLength); + } + if (_nMask == VolumeInfoMask_MaxPathLength) + { + sal_uInt32 nLength = _aVolumeInfo.getMaxPathLength(); + t_print("max path length: %ld\n", nLength); + } + if (_nMask == VolumeInfoMask_FileSystemCaseHandling) + { + bool bIsCase = _aVolumeInfo.isCaseSensitiveFileSystem(); + t_print("filesystem case sensitive: %s\n", bIsCase ? "yes" : "no"); + } + } + + void checkVolumeInfo(sal_Int32 _nMask) + { + ::osl::VolumeInfo aVolumeInfo( _nMask ); + //call getVolumeInfo here + nError1 = ::osl::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 = VolumeInfoMask_FileSystemName; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_2( ) + { + sal_Int32 mask = VolumeInfoMask_Attributes; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_3( ) + { + sal_Int32 mask = VolumeInfoMask_TotalSpace; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_4( ) + { + sal_Int32 mask = VolumeInfoMask_UsedSpace; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_5( ) + { + sal_Int32 mask = VolumeInfoMask_FreeSpace; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_6( ) + { + sal_Int32 mask = VolumeInfoMask_MaxNameLength; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_7( ) + { + sal_Int32 mask = VolumeInfoMask_MaxPathLength; + checkVolumeInfo(mask); + } + void getVolumeInfo_001_8( ) + { + sal_Int32 mask = VolumeInfoMask_FileSystemCaseHandling; + checkVolumeInfo(mask); + } + + void getVolumeInfo_002( ) + { + sal_Int32 mask = VolumeInfoMask_FileSystemName; + ::osl::VolumeInfo aVolumeInfo( mask ); + //call getVolumeInfo here + + // LLA: rtl::OUString aRootSysURL; + // LLA: nError1 = osl::File::getFileURLFromSystemPath(aRootSys, aRootSysURL); + // LLA: + // LLA: CPPUNIT_ASSERT_MESSAGE( "can't convert root path to file url", + // LLA: ( osl::FileBase::E_NONE == nError1 ) ); + + nError1 = ::osl::Directory::getVolumeInfo( aRootSys, aVolumeInfo ); + + CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: use system path as parameter.", + ( osl::FileBase::E_INVAL == nError1 ) ); + } + + void getVolumeInfo_003( ) + { + sal_Int32 mask = VolumeInfoMask_FileSystemName; + ::osl::VolumeInfo aVolumeInfo( mask ); + //call getVolumeInfo here + nError1 = ::osl::Directory::getVolumeInfo( aTmpName3, aVolumeInfo ); + +// LLA: in Windows, it reply no error, it did not pass in (W32). +#ifdef UNX + CPPUNIT_ASSERT_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( ); + };// class getVolumeInfo + + + //--------------------------------------------------------------------- + // testing the method + // inline static RC create( const ::rtl::OUString& ustrDirectoryURL ) + //--------------------------------------------------------------------- + class create : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + + // test code. + void create_001( ) + { + //create directory in $TEMP/tmpdir + nError1 = ::osl::Directory::create( aTmpName3 ); + //check for existence + nError2 = ::osl::Directory::create( aTmpName3 ); + //remove it + deleteTestDirectory( aTmpName3 ); + + CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory and check its existence.", + ( osl::FileBase::E_None == nError1 ) && + ( osl::FileBase::E_EXIST== nError2 ) ); + } + + void create_002( ) + { + //create directory in /tmpname + nError1 = ::osl::Directory::create( aTmpName7 ); +#if defined (WNT ) + nError1 = osl::FileBase::E_ACCES; /// in Windows, you can create directory in c:/ any way. + deleteTestDirectory( aTmpName7 ); +#endif + + CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory in root for access test.", + ( osl::FileBase::E_ACCES == nError1 ) ); + } + + void create_003( ) + { + //create directory in /tmpname + nError1 = ::osl::Directory::create( aSysPath1 ); + + CPPUNIT_ASSERT_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( ); + };// class create + + //--------------------------------------------------------------------- + // testing the method + // inline static RC remove( const ::rtl::OUString& ustrDirectoryURL ) + //--------------------------------------------------------------------- + class remove : public CppUnit::TestFixture + { + ::osl::FileBase::RC nError1, nError2; + + public: + + // test code. + void remove_001( ) + { + //create directory in $TEMP/tmpdir + nError1 = ::osl::Directory::create( aTmpName3 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //remove it + nError1 = ::osl::Directory::remove( aTmpName3 ); + //check for existence + ::osl::Directory rDirectory( aTmpName3 ); + nError2 = rDirectory.open( ); + + CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory and check its existence.", + ( osl::FileBase::E_None == nError1 ) && + ( osl::FileBase::E_NOENT == nError2 ) ); + } + + void remove_002( ) + { + //create directory in $TEMP/tmpdir + nError1 = ::osl::Directory::create( aTmpName3 ); + CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 ); + //try to remove it by system path + nError1 = ::osl::Directory::remove( aSysPath3 ); + //check for existence + ::osl::Directory rDirectory( aTmpName3 ); + nError2 = rDirectory.open( ); + if ( osl::FileBase::E_NOENT != nError2 ) + ::osl::Directory::remove( aTmpName3 ); + + CPPUNIT_ASSERT_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 = ::osl::Directory::remove( aTmpName6 ); + + CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a non-existed directory.", + ( osl::FileBase::E_NOENT == nError1 ) ); + } + + void remove_004( ) + { + createTestFile( aTmpName6 ); + sal_Bool bExist = ifFileExist( aTmpName6 ); + //try to remove file. + nError1 = ::osl::Directory::remove( aTmpName6 ); + deleteTestFile( aTmpName6 ); + + CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a file but not directory.", + bExist == sal_True &&(( osl::FileBase::E_NOTDIR == nError1 ) || ( osl::FileBase::E_NOENT == nError1 )) ); + } + + void remove_005( ) + { + createTestDirectory( aTmpName3 ); + createTestFile( aTmpName4 ); + nError1 = ::osl::Directory::remove( aTmpName3 ); + deleteTestFile( aTmpName4 ); + deleteTestDirectory( aTmpName3 ); + ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for remove function: try to remove a directory that is not empty.") + errorToStr( nError1 ); +#if defined ( SOLARIS ) + //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 "..". + t_print("#Solaris test\n"); + CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_EXIST == nError1 ) ); +#else + CPPUNIT_ASSERT_MESSAGE( suError, ( 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( ); + };// class remove + + //######################################## + // TEST Directory::createPath + //######################################## + + #ifdef WNT + # define PATH_BUFFER_SIZE MAX_PATH + #else + # define PATH_BUFFER_SIZE PATH_MAX + #endif + + char TEST_PATH_POSTFIX[] = "hello/world"; + + //######################################## + OUString get_test_path() + { + OUString tmp; + FileBase::RC rc = FileBase::getTempDirURL(tmp); + + CPPUNIT_ASSERT_MESSAGE + ( + "Test path creation failed", + rc == FileBase::E_None + ); + + OUStringBuffer b(tmp); + if (tmp.lastIndexOf('/') != (tmp.getLength() - 1)) + b.appendAscii("/"); + + b.appendAscii(TEST_PATH_POSTFIX); + + return b.makeStringAndClear(); + } + + //######################################## + void rm_test_path(const OUString& path) + { + sal_Unicode buffer[PATH_BUFFER_SIZE]; + rtl_copyMemory(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, '/'); + buffer[i] = 0; + Directory::remove(buffer); + } + + //######################################## + class DirCreatedObserver : public DirectoryCreationObserver + { + public: + DirCreatedObserver() : i(0) + { + } + + virtual void DirectoryCreated(const rtl::OUString& /*aDirectoryUrl*/) + { + i++; + }; + + int number_of_dirs_created() const + { + return i; + } + + private: + int i; + }; + + + //######################################## + class createPath : public CppUnit::TestFixture + { + public: + //########################################## + createPath() + {} + + //########################################## + void with_relative_path() + { + FileBase::RC rc = Directory::createPath( + OUString::createFromAscii(TEST_PATH_POSTFIX)); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath contract broken", + rc == FileBase::E_INVAL + ); + } + + //########################################## + void without_callback() + { + OUString tp_url = get_test_path(); + + rm_test_path(tp_url); + + FileBase::RC rc = Directory::createPath(tp_url); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath failed", + rc == FileBase::E_None + ); + } + + //########################################## + void with_callback() + { + OUString tp_url = get_test_path(); + + rm_test_path(tp_url); + + DirCreatedObserver* observer = new DirCreatedObserver; + FileBase::RC rc = Directory::createPath(tp_url, observer); + int nDirs = observer->number_of_dirs_created(); + delete observer; + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath failed", + (rc == FileBase::E_None) && (nDirs > 0) + ); + + } + +#ifdef WNT + + //########################################## + char* get_unused_drive_letter() + { + static 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 NULL; + } + + //########################################## + void at_invalid_logical_drive() + { + char* drv = get_unused_drive_letter(); + char buff[PATH_BUFFER_SIZE]; + rtl_zeroMemory(buff, sizeof(buff)); + + strncpy(buff, drv, 1); + strcat(buff, ":\\"); + strcat(buff, TEST_PATH_POSTFIX); + + OUString path = OUString::createFromAscii(buff); + OUString tp_url; + FileBase::getFileURLFromSystemPath(path, tp_url); + + FileBase::RC rc = Directory::createPath(tp_url); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath doesn't fail on unused logical drive letters", + rc != FileBase::E_None + ); + } + + //########################################## + void with_UNC_path() + { + + OUString tp_unc = OUString::createFromAscii("\\\\Tra-1\\TRA_D\\hello\\world\\"); + OUString tp_url; + FileBase::getFileURLFromSystemPath(tp_unc, tp_url); + + FileBase::RC rc = Directory::createPath(tp_url); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createDirectoryPath fails with UNC path", + rc == FileBase::E_None + ); + } + +#endif /* WNT */ + + CPPUNIT_TEST_SUITE(createPath); + CPPUNIT_TEST(with_relative_path); + CPPUNIT_TEST(without_callback); + CPPUNIT_TEST(with_callback); +#ifdef WNT + CPPUNIT_TEST(at_invalid_logical_drive); + + // adapt the UNC path in method createDirectoryPath_with_UNC_path + // in order to run this test successfully + //CPPUNIT_TEST(with_UNC_path); +#endif + CPPUNIT_TEST_SUITE_END(); + + }; // class createPath + + // ----------------------------------------------------------------------------- + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::ctors, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::open, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::isOpen, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::close, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::reset, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::getNextItem, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::getVolumeInfo, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::create, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::remove, "osl_Directory" ); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::createPath, "osl_Directory" ); +}// namespace osl_Directory + + +// ----------------------------------------------------------------------------- +// 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. +// ----------------------------------------------------------------------------- + +/// NOADDITIONAL; + + + +/** get Current PID. +*/ +inline ::rtl::OUString getCurrentPID( ) +{ + //~ Get current PID and turn it into OUString; + int nPID = 0; +#ifdef WNT + nPID = GetCurrentProcessId(); +#else + nPID = getpid(); +#endif + return ( ::rtl::OUString::valueOf( ( long )nPID ) ); +} + + +/** Insert Current PID to the URL to avoid access violation between multiuser execution. +*/ +inline void insertPID( ::rtl::OUString & pathname ) +{ + //~ check if the path contain the temp directory, do nothing changes if not; + if ( pathname.indexOf( aTempDirectoryURL ) && pathname.indexOf( aTempDirectorySys ) ) + return; + + //~ format pathname to TEMP/USERPID/URL style; + if ( !pathname.indexOf( aTempDirectoryURL ) ) + { + ::rtl::OUString strPID( getCurrentPID( ) ); + ::rtl::OUString pathLeft = aTempDirectoryURL.copy( 0 ); + ::rtl::OUString pathRight = pathname.copy( aTempDirectoryURL.getLength( ) ); + pathname = pathLeft.copy( 0 ); + ( ( pathname += aSlashURL ) += strPID ) += pathRight; + } + else + { + ::rtl::OUString strPID( getCurrentPID( ) ); + ::rtl::OUString pathLeft = aTempDirectorySys.copy( 0 ); + ::rtl::OUString pathRight = pathname.copy( aTempDirectorySys.getLength( ) ); + pathname = pathLeft.copy( 0 ); + ( ( pathname += aSlashURL ) += strPID ) += pathRight; + } + + +} + +/** to do some initialized work, we replace the NOADDITIONAL macro with the initialize work which + will check the file and directory existence. and set some variables for test use. + to simplify the initialize work, we seperate it into UNIX section and Windows section, the main task + of initialization is adapt all URL defined in osl_File_Const.h to TEMP/USERPID/URL style format, + since there may be an instance that multiuser execute test at the same time, and the temp file + may not be clean up in this case due to access right problem. +*/ +void RegisterAdditionalFunctions( FktRegFuncPtr _pFunc ) +{ + (void)_pFunc; + t_print( "Initializing..." ); + + //~ make sure the c:\temp exist, if not, create it. +#if ( defined WNT ) + if ( checkDirectory( aTempDirectoryURL, osl_Check_Mode_Exist ) != sal_True ) { + t_print( "\n#C:\\temp is not exist, now creating\n" ); + createTestDirectory( aTempDirectoryURL ); + }; +#endif + + //~ make sure the c:\temp\PID or /tmp/PID exist, if not, create it. initialize the user directory. + ( aUserDirectoryURL += aSlashURL ) += getCurrentPID( ); + ( aUserDirectorySys += aSlashURL ) += getCurrentPID( ); + + if ( checkDirectory( aUserDirectoryURL, osl_Check_Mode_Exist ) != sal_True ) { + createTestDirectory( aUserDirectoryURL ); + } + + //~ adapt all URL to the TEMP/USERPID/URL format; + insertPID( aCanURL1 ); + insertPID( aTmpName3 ); + insertPID( aTmpName4 ); + insertPID( aTmpName5 ); + insertPID( aTmpName6 ); + insertPID( aTmpName8 ); + insertPID( aTmpName9 ); + insertPID( aLnkURL1 ); + insertPID( aFifoSys ); + insertPID( aSysPath1 ); + insertPID( aSysPath2 ); + insertPID( aSysPath3 ); + insertPID( aSysPath4 ); + + t_print( "Done.\n" ); + +} + + +//~ do some clean up work after all test completed. +class GlobalObject +{ + public: + ~GlobalObject() + { + try + { + //~ make sure the c:\temp\PID or /tmp/PID exist, if yes, delete it. + t_print( "\n#Do some clean-ups ...\n" ); + if ( checkDirectory( aUserDirectoryURL, osl_Check_Mode_Exist ) == sal_True ) { + deleteTestDirectory( aUserDirectoryURL ); + } + + // LLA: t_print("after deleteTestDirectory\n"); + //~ special clean up task in Windows and Unix seperately; +#if ( defined UNX ) || ( defined OS2 ) + //~ 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 ) == sal_True ) + deleteTestFile( aTmpName6 ); + if ( ifFileExist( aTmpName4 ) == sal_True ) + deleteTestFile( aTmpName4 ); + if ( checkDirectory( aTmpName4, osl_Check_Mode_Exist ) == sal_True ) + deleteTestDirectory( aTmpName4 ); + if ( ifFileExist( aTmpName3 ) == sal_True ) + deleteTestFile( aTmpName3 ); + if ( checkDirectory( aTmpName3, osl_Check_Mode_Exist ) == sal_True ) + deleteTestDirectory( aTmpName3 ); + + ::rtl::OUString aUStr( aUserDirectoryURL ); + concatURL( aUStr, aHidURL1 ); + if ( ifFileExist( aUStr ) == sal_True ) + deleteTestFile( aUStr ); + + ::rtl::OUString aUStr1( aRootURL ); + concatURL( aUStr1, aTmpName2 ); + if ( ifFileExist( aUStr1 ) == sal_True ) + deleteTestFile( aUStr1 ); +#endif + + } + catch (CppUnit::Exception &e) + { + t_print("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber()); + } + catch (...) + { + t_print("Exception caught (...) in GlobalObject dtor()\n"); + } + } +}; + +GlobalObject theGlobalObject; 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 000000000000..2ef0b0104ad3 --- /dev/null +++ b/sal/qa/osl/file/osl_File_Const.h @@ -0,0 +1,245 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_File_Const.h,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_FILE_CONST_H_ +#define _OSL_FILE_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sal/types.h> +#include <rtl/textenc.h> + +#include <rtl/ustring.hxx> +#include <rtl/uri.hxx> + + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + + +#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, acommon test data repository will be better since it can be +// shared among all test code +//------------------------------------------------------------------------ + +const sal_Char pBuffer_Char[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const sal_Char pBuffer_Number[] = "1234567890"; +const sal_Char pBuffer_Blank[] = ""; + +#define TRUNC_LEN 10; +#define ENLARG_LEN 100; + + + +//------------------------------------------------------------------------ +// 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 seperator of path list in comrresponding platform, +// PATH_SEPERATOR for seperator 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 ) || ( defined OS2 ) //Unix +# include <unistd.h> +# include <limits.h> +# include <math.h> +# include <errno.h> +# include <fcntl.h> +# include <sys/stat.h> +# include <sys/statfs.h> +# include <sys/statvfs.h> +# include <sys/types.h> +# define TEST_PLATFORM "" +# define TEST_PLATFORM_ROOT "/" +# define TEST_PLATFORM_TEMP "tmp" +# define PATH_LIST_DELIMITER ":" +# define PATH_SEPERATOR "/" +#endif +#if (defined WNT ) // Windows +#include <tools/prewin.h> +// # include <windows.h> +# include <tchar.h> +# include <io.h> +# include <stdio.h> +# include <stdlib.h> +#include <tools/postwin.h> +# define PATH_MAX MAX_PATH +# define TEST_PLATFORM "c:/" +# define TEST_PLATFORM_ROOT "c:/" +# define TEST_PLATFORM_TEMP "temp" +# define PATH_LIST_DELIMITER ";" +# define PATH_SEPERATOR "/" +#endif + + +//------------------------------------------------------------------------ +// macro definition for the ASCII array/OUString declarations, +// we use p### for the ASCII array, +// a### for the OUString, +// n###Len for its length +//------------------------------------------------------------------------ + +#define OSLTEST_DECLARE( str_name, str_value ) \ + ::rtl::OUString a##str_name = rtl::OUString::createFromAscii( ( str_value ) ) + +#define OSLTEST_DECLARE_UTF8(str_name, str_value ) \ + ::rtl::OUString a##str_name = ::rtl::Uri::decode( ::rtl::OUString::createFromAscii( ( str_value ) ), rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8) + +//------------------------------------------------------------------------ +// OS independent file definition +//------------------------------------------------------------------------ +OSLTEST_DECLARE( NullURL, "" ); +OSLTEST_DECLARE( SlashURL, PATH_SEPERATOR ); +OSLTEST_DECLARE( PreURL, FILE_PREFIX ); +OSLTEST_DECLARE( RootURL, FILE_PREFIX TEST_PLATFORM ); + +OSLTEST_DECLARE( TempDirectoryURL, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP ); +OSLTEST_DECLARE( TempDirectorySys, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP ); +OSLTEST_DECLARE( UserDirectoryURL, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "" ); +OSLTEST_DECLARE( UserDirectorySys, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "" ); + +//------------------------------------------------------------------------ +// common used URL:temp, canonical, root, relative, link,etc +//------------------------------------------------------------------------ +OSLTEST_DECLARE( CanURL1, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/canonical.name" ); +OSLTEST_DECLARE( CanURL2, "ca@#;+.,$///78no\0ni..name" ); +OSLTEST_DECLARE( CanURL3, "ca@#;+.,$//tmp/678nonical//name" ); +OSLTEST_DECLARE( CanURL4, "canonical.name" ); +OSLTEST_DECLARE( TmpName1, "tmpdir" ); +OSLTEST_DECLARE( TmpName2, "tmpname" ); +OSLTEST_DECLARE( TmpName3, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/tmpdir" ); +OSLTEST_DECLARE( TmpName4, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/tmpdir/tmpname" ); +OSLTEST_DECLARE( TmpName5, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/tmpdir/../tmpdir/./tmpname" ); +OSLTEST_DECLARE( TmpName6, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/tmpname" ); +OSLTEST_DECLARE( TmpName7, FILE_PREFIX TEST_PLATFORM "tmpname" ); +OSLTEST_DECLARE( TmpName8, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/tmpname/tmpdir" ); +OSLTEST_DECLARE( TmpName9, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/tmpdir/../tmpdir/./" ); +OSLTEST_DECLARE_UTF8( TmpName10, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/%E6%9C%AA%E5%91%BD%E5%90%8Dzhgb18030" ); + +OSLTEST_DECLARE( RelURL1, "relative/file1" ); +OSLTEST_DECLARE( RelURL2, "relative/./file2" ); +OSLTEST_DECLARE( RelURL3, "relative/../file3" ); +OSLTEST_DECLARE( RelURL4, "././relative/../file4" ); +OSLTEST_DECLARE( RelURL5, TEST_PLATFORM_TEMP "/./../" TEST_PLATFORM_TEMP ); +OSLTEST_DECLARE( LnkURL1, FILE_PREFIX TEST_PLATFORM TEST_PLATFORM_TEMP "/link.file" ); +OSLTEST_DECLARE( HidURL1, ".hiddenfile" ); + +//------------------------------------------------------------------------ +// common used System Path:temp, root,etc +//------------------------------------------------------------------------ +OSLTEST_DECLARE( RootSys, TEST_PLATFORM_ROOT ); +OSLTEST_DECLARE( SysPath1, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "/system.path" ); +OSLTEST_DECLARE( SysPath2, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "/system/path" ); +OSLTEST_DECLARE( SysPath3, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "/tmpdir" ); +OSLTEST_DECLARE( SysPath4, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "/tmpname" ); +OSLTEST_DECLARE_UTF8( SysPath5, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "/%E6%9C%AA%E5%91%BD%E5%90%8Dzhgb18030" ); +OSLTEST_DECLARE( FifoSys, TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP "/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 ) || ( defined OS2 ) // Unix +OSLTEST_DECLARE( TypeURL1, FILE_PREFIX "dev/ccv"); //socket Solaris/Linux +OSLTEST_DECLARE( TypeURL2, FILE_PREFIX "devices/pseudo/tcp@0:tcp"); //special Solaris/Linux +OSLTEST_DECLARE( TypeURL3, FILE_PREFIX "lib" ); //link Solaris +#else // Windows +OSLTEST_DECLARE( TypeURL1, FILE_PREFIX "" ); +OSLTEST_DECLARE( TypeURL2, FILE_PREFIX "" ); +OSLTEST_DECLARE( TypeURL3, 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 ) || ( defined OS2 ) // Unix +OSLTEST_DECLARE( VolURL1, FILE_PREFIX ""); //ufs Solaris/Linux +#ifdef SOLARIS +OSLTEST_DECLARE( VolURL2, FILE_PREFIX "dev/fd" ); //fd Solaris +#else +OSLTEST_DECLARE( VolURL2, FILE_PREFIX "dev/floppy/0u1440" ); //fd0 Linux +#endif +OSLTEST_DECLARE( VolURL3, FILE_PREFIX "proc" ); //proc Solaris/Linux +OSLTEST_DECLARE( VolURL4, FILE_PREFIX "staroffice" ); //nfs Solaris/Linux +OSLTEST_DECLARE( VolURL5, FILE_PREFIX "tmp" ); //tmpfs Solaris +OSLTEST_DECLARE( VolURL6, FILE_PREFIX "cdrom" ); //cd Solaris +#else // Windows +OSLTEST_DECLARE( VolURL1, FILE_PREFIX "c:/" ); +OSLTEST_DECLARE( VolURL2, FILE_PREFIX "a:/" ); +OSLTEST_DECLARE( VolURL3, FILE_PREFIX "" ); +OSLTEST_DECLARE( VolURL4, FILE_PREFIX "" ); +OSLTEST_DECLARE( VolURL5, FILE_PREFIX "c:/temp" ); +OSLTEST_DECLARE( VolURL6, FILE_PREFIX "e:/" ); +#endif + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +} +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + + +#endif /* _OSL_FILE_CONST_H_ */ 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 000000000000..64258b8e9006 --- /dev/null +++ b/sal/qa/osl/file/osl_old_test_file.cxx @@ -0,0 +1,276 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_old_test_file.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + +#include <stdio.h> + +#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 "" +#else +// WINDOWS +#define TEST_VOLUME "c:/" +#endif + +#include <testshl/simpleheader.hxx> + +namespace osl_test_file +{ + +// ----------------------------------------------------------------------------- + +class oldtestfile : public CppUnit::TestFixture +{ +public: + void test_file_001(); + void test_file_002(); + void test_file_003(); + void test_file_004(); + + CPPUNIT_TEST_SUITE( oldtestfile ); + CPPUNIT_TEST( test_file_001 ); + CPPUNIT_TEST( test_file_002 ); + CPPUNIT_TEST( test_file_003 ); + CPPUNIT_TEST( test_file_004 ); + CPPUNIT_TEST_SUITE_END( ); +}; + +char *aSource1[] = +{ + "a" , "file:///" TEST_VOLUME "bla/a", + "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:///" TEST_VOLUME "bla/blub", + 0 , 0 +}; + +char *aSource2[ ] = +{ + "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a", + "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", + 0,0 +}; + +char *aSource3[ ] = +{ + ".." , "/a", + "../a" , "/a/a", + "e/f" , "/c/e/f", + "../..", "", + 0,0 +}; + +using namespace rtl; + +void oldtestfile::test_file_001() +{ +#ifdef WIN32 + return; +#endif + + OUString base1( RTL_CONSTASCII_USTRINGPARAM( "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_MESSAGE("failure #1", osl_File_E_None == e ); + if( osl_File_E_None == e ) + { + CPPUNIT_ASSERT_MESSAGE("failure #1.1", target.equalsAscii( aSource1[i+1] ) ); + } + OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US ); + OString obase = OUStringToOString( base1 , RTL_TEXTENCODING_ASCII_US ); + fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer ); + } + + OUString err1( RTL_CONSTASCII_USTRINGPARAM( "../.." ) ); + OUString target; + CPPUNIT_ASSERT_MESSAGE("failure #11", osl_File_E_None != osl_getAbsoluteFileURL( base1.pData , err1.pData , &target.pData ) ); + +} + +void oldtestfile::test_file_002() +{ +#ifdef WIN32 + return; +#endif + + OUString base2( RTL_CONSTASCII_USTRINGPARAM( "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_MESSAGE("failure #2", osl_File_E_None == e ); + if( osl_File_E_None == e ) + { + CPPUNIT_ASSERT_MESSAGE("failure #2.1", target.equalsAscii( aSource2[i+1] ) ); + } + OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US ); + OString obase = OUStringToOString( base2 , RTL_TEXTENCODING_ASCII_US ); +// fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource2[i], o.pData->buffer ); + } +} + +void oldtestfile::test_file_003() +{ +#ifdef WIN32 + return; +#endif + + // links ! +#ifdef UNX + int i; + char buf[PATH_MAX]; + if( getcwd( buf, PATH_MAX ) ) + { + char buf2[PATH_MAX]; + strcpy( buf2 , buf ); + strcat( buf2, "/a" ); + + if( 0 == mkdir( buf2 , S_IRWXG | S_IRWXO | S_IRWXU ) ) + { + strcat( buf2, "/b" ); + if( 0 == mkdir( buf2, S_IRWXU | S_IRWXO | S_IRWXU ) ) + { + if( 0 == symlink( buf2 , "c" ) ) + { + OUString dir; + osl_getProcessWorkingDir( &(dir.pData) ); + + OUString base3 = dir; + base3 += OUString( RTL_CONSTASCII_USTRINGPARAM( "/c" ) ); + for( i = 0 ; aSource3[i] ; i +=2 ) + { + OUString target; + OUString rel = OUString::createFromAscii( aSource3[i] ); + oslFileError e = osl_getAbsoluteFileURL( base3.pData, rel.pData , &target.pData ); + CPPUNIT_ASSERT_MESSAGE("failure #3", osl_File_E_None == e ); + if( osl_File_E_None == e ) + { + CPPUNIT_ASSERT_MESSAGE("failure #4", target.getLength() >= dir.getLength() ); + if( target.getLength() >= dir.getLength() ) + { + int j; + for( j = dir.getLength() ; + j < target.getLength() && + aSource3[i+1][j-dir.getLength()] == target[j] ; j++ ); + CPPUNIT_ASSERT_MESSAGE("failure #5", j == target.getLength() ); + } + } + OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US ); + OString obase = OUStringToOString( base3 , RTL_TEXTENCODING_ASCII_US ); + fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource3[i], o.pData->buffer ); + } + unlink( "c" ); + } + else + { + CPPUNIT_ASSERT_MESSAGE("failure #6", 0 ); + } + rmdir( "a/b" ); + } + else + { + CPPUNIT_ASSERT_MESSAGE("failure #7", 0 ); + } + rmdir( "a" ); + } + else + { + CPPUNIT_ASSERT_MESSAGE("failure #8", 0 ); + } + } + else + { + CPPUNIT_ASSERT_MESSAGE("failure #9", 0 ); + } +#endif +} + +void oldtestfile::test_file_004() +{ +#ifdef WIN32 + return; +#endif + + OUString base4( RTL_CONSTASCII_USTRINGPARAM( "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_MESSAGE("failure #10", osl_File_E_None == e ); + if( osl_File_E_None == e ) + { + CPPUNIT_ASSERT_MESSAGE("failure #10.1", target.equalsAscii( aSource1[i+1] ) ); + } + OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US ); + OString obase = OUStringToOString( base4 , RTL_TEXTENCODING_ASCII_US ); + fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer ); + } + + +// fprintf( stderr, "test_file done\n" ); +} + +} // namespace osl_test_file + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_test_file::oldtestfile, "osl_File" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; + 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 100755 index 000000000000..05910ea3ddd7 --- /dev/null +++ b/sal/qa/osl/file/test_cpy_wrt_file.cxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_cpy_wrt_file.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <testshl/simpleheader.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <rtl/ustring.hxx> + +using namespace osl; +using namespace rtl; + +//######################################## +#ifdef UNX +# define COPY_SOURCE_PATH "/home/tr109510/ucbhelper.cxx" +# define COPY_DEST_PATH "/mnt/mercury08/ucbhelper.cxx" +#else /* if WNT */ +# define COPY_SOURCE_PATH "d:\\msvcr70.dll" +# define COPY_DEST_PATH "x:\\tra\\msvcr70.dll" +#endif + +class test_osl_copyFile : public CppUnit::TestFixture +{ +public: + void cp_file() + { + rtl::OUString src_url; + FileBase::getFileURLFromSystemPath(rtl::OUString::createFromAscii(COPY_SOURCE_PATH), src_url); + + rtl::OUString dest_url; + FileBase::getFileURLFromSystemPath(rtl::OUString::createFromAscii(COPY_DEST_PATH), dest_url); + + FileBase::RC err = File::copy(src_url, dest_url); + CPPUNIT_ASSERT_MESSAGE("Copy didn't recognized disk full", err != FileBase::E_None); + } + + CPPUNIT_TEST_SUITE(test_osl_copyFile); + CPPUNIT_TEST(cp_file); + CPPUNIT_TEST_SUITE_END(); +}; + +//######################################## +#ifdef UNX +# define WRITE_DEST_PATH "/mnt/mercury08/muell.tmp" +#else /* if WNT */ +# define WRITE_DEST_PATH "d:\\tmp_data.tmp" +#endif + +class test_osl_writeFile : public CppUnit::TestFixture +{ +public: + void wrt_file() + { + rtl::OUString dest_url; + FileBase::getFileURLFromSystemPath(rtl::OUString::createFromAscii(WRITE_DEST_PATH), dest_url); + + File tmp_file(dest_url); + rtl::OUString suErrorMsg = rtl::OUString::createFromAscii("File creation failed: ")+ dest_url; + FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create); + + CPPUNIT_ASSERT_MESSAGE( suErrorMsg, err == FileBase::E_None || err == FileBase::E_EXIST ); + + char buffer[50000]; + sal_uInt64 written = 0; + err = tmp_file.write((void*)buffer, sizeof(buffer), written); + + err = tmp_file.sync(); + + CPPUNIT_ASSERT_MESSAGE("Write didn't recognized disk full", err != FileBase::E_None); + + tmp_file.close(); + } + + CPPUNIT_TEST_SUITE(test_osl_writeFile); + CPPUNIT_TEST(wrt_file); + CPPUNIT_TEST_SUITE_END(); +}; + +//##################################### +// register test suites +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_osl_writeFile, "test_osl_writeFile"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_osl_copyFile, "test_osl_copyFile"); + +NOADDITIONAL; + diff --git a/sal/qa/osl/module/export_dll.map b/sal/qa/osl/module/export_dll.map new file mode 100644 index 000000000000..0b8a37c365e6 --- /dev/null +++ b/sal/qa/osl/module/export_dll.map @@ -0,0 +1,38 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: export_dll.map,v $ +# +# $Revision: 1.5 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3.0 { + global: + firstfunc; + + local: + *; +}; diff --git a/sal/qa/osl/module/makefile.mk b/sal/qa/osl/module/makefile.mk new file mode 100644 index 000000000000..40f597bdbbc7 --- /dev/null +++ b/sal/qa/osl/module/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_module + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- + +# --- test dll ------------------------------------------------------ +SHL1TARGET = Module_DLL +SHL1OBJS = $(SLO)$/osl_Module_DLL.obj +SHL1STDLIBS = $(SALLIB) +SHL1IMPLIB = i$(SHL1TARGET) +SHL1DEF = $(MISC)$/$(SHL1TARGET).def +DEF1NAME = $(SHL1TARGET) +SHL1VERSIONMAP = export_dll.map + + +# --- main l ------------------------------------------------------ +SHL2OBJS= $(SLO)$/osl_Module.obj + +SHL2TARGET= osl_Module +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL2STDLIBS+=i$(SHL2TARGET).lib +.ENDIF +.IF "$(GUI)" == "UNX" +APP3STDLIBS+=-l$(SHL2TARGET) +.ENDIF + +SHL2DEPN= $(SHL1OBJS) +SHL2IMPLIB= i$(SHL2TARGET) +SHL2DEF= $(MISC)$/$(SHL2TARGET).def + +DEF2NAME =$(SHL2TARGET) +SHL2VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/osl/module/osl_Module.cxx b/sal/qa/osl/module/osl_Module.cxx new file mode 100644 index 000000000000..339b7230ca7c --- /dev/null +++ b/sal/qa/osl/module/osl_Module.cxx @@ -0,0 +1,525 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Module.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <osl_Module_Const.h> + +using namespace osl; +using namespace rtl; + + +//------------------------------------------------------------------------ +// helper functions and classes +//------------------------------------------------------------------------ + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("TRUE!\n" ): t_print("FALSE!\n" ); +} + +/** print a UNI_CODE String. +*/ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printUString_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +/** get dll file URL. +*/ +inline ::rtl::OUString getDllURL( void ) +{ +#if ( defined WNT ) // lib in Unix and lib in Windows are not same in file name. + ::rtl::OUString libPath( rtl::OUString::createFromAscii( "Module_DLL.dll" ) ); +#else + ::rtl::OUString libPath( rtl::OUString::createFromAscii( "libModule_DLL.so" ) ); +#endif + + ::rtl::OUString dirPath, dllPath; + osl::Module::getUrlFromAddress( ( void* ) &getDllURL, dirPath ); + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1); + osl::FileBase::getAbsoluteFileURL( dirPath, libPath, dllPath ); + + return dllPath; +} + +/** print a UNI_CODE file name. +*/ +inline void printFileName( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printFileName_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +inline sal_Bool isURL( const ::rtl::OUString pathname ) +{ + ::rtl::OUString aPreURL( rtl::OUString::createFromAscii( "file:///" ) ); + return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False ); +} + +/** create a temp test directory using OUString name of full qualified URL or system path. +*/ +inline void createTestDirectory( const ::rtl::OUString dirname ) +{ + ::rtl::OUString aPathURL = dirname.copy( 0 ); + ::osl::FileBase::RC nError; + + if ( !isURL( dirname ) ) + ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL + nError = ::osl::Directory::create( aPathURL ); + CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) ); +} + +/** delete a temp test directory using OUString name of full qualified URL or system path. +*/ +inline void deleteTestDirectory( const ::rtl::OUString dirname ) +{ + ::rtl::OUString aPathURL = dirname.copy( 0 ); + ::osl::FileBase::RC nError; + if ( !isURL( dirname ) ) + ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL + + ::osl::Directory testDir( aPathURL ); + if ( testDir.isOpen( ) == sal_True ) + { + testDir.close( ); //close if still open. + } + + nError = ::osl::Directory::remove( aPathURL ); + CPPUNIT_ASSERT_MESSAGE( "In deleteTestDirectory function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) ); +} + +//check if the file exist +inline sal_Bool ifFileExist( const ::rtl::OUString & str ) +{ + ::rtl::OUString aUStr; + if ( isURL( str ) ) + ::osl::FileBase::getSystemPathFromFileURL( str, aUStr ); + else + return sal_False; + + ::osl::File strFile( aUStr ); + ::osl::FileBase::RC nError = strFile.open( OpenFlag_Read ); + if ( ::File::E_NOENT == nError ) + return sal_False; + else{ + strFile.close( ); + return sal_True; + } +} + +/** detete a temp test file using OUString name. +*/ +inline void deleteTestFile( const ::rtl::OUString filename ) +{ + ::rtl::OUString aPathURL = filename.copy( 0 ); + ::osl::FileBase::RC nError; + + if ( !isURL( filename ) ) + ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL + + nError = ::osl::File::setAttributes( aPathURL, Attribute_GrpWrite| Attribute_OwnWrite| Attribute_OthWrite ); // if readonly, make writtenable. + CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) ); + + nError = ::osl::File::remove( aPathURL ); + CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) ); +} + + +//------------------------------------------------------------------------ +// test code start here +//------------------------------------------------------------------------ + +namespace osl_Module +{ + + /** class and member function that is available for module test : + */ + + class testClass + { + public: + static void myFunc() + { + t_print("#Sun Microsystem\n"); + }; + }; + + + /** testing the methods: + Module(); + Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT); + */ + class ctors : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void ctors_none( ) + { + ::osl::Module aMod; + bRes = aMod.is(); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor without parameter.", + sal_False == bRes ); + } + + void ctors_name_mode( ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ); + + if ( !( bRes ) ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", sal_False ); + } + + ::osl::Module aMod( aFileURL ); + bRes = aMod.is( ); + aMod.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with load action.", + sal_True == 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, ::rtl::OUString & libraryUrl) + */ + class getUrlFromAddress : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getUrlFromAddress_001( ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ) ; + if ( !( bRes ) ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", sal_False ); + } + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test get Module URL from address.", + sal_True == bRes && 0 < aFileURL.lastIndexOf('/') ); + } + + void getUrlFromAddress_002( ) + { + ::osl::Module aMod( getDllURL( ) ); + FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); + + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( ( void* )pFunc, aFileURL ); + if ( !( bRes ) ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", sal_False ); + } + aMod.unload( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load an external library, get its function address and get its URL.", + sal_True == bRes && 0 < aFileURL.lastIndexOf('/') && aFileURL.equalsIgnoreAsciiCase( getDllURL( ) ) ); + } + + /* 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 ::rtl::OUString& strModuleName, + sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) + */ + class load : public CppUnit::TestFixture + { + public: + sal_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.", + sal_True == bRes ); + } + // load lib which is under a CJK directory + void load_002( ) + { +#ifdef UNX + //Can not get a CJK directory already exist, so here create one. Perhaps reason is encoding problem. + ::rtl::OUString aPidDirURL = rtl::OUString::createFromAscii( "file:///tmp/" ) + ::rtl::OUString::valueOf( ( long )getpid( ) ); + ::rtl::OUString aMyDirURL = aPidDirURL + aKname; + createTestDirectory( aPidDirURL ); + createTestDirectory( aMyDirURL ); + + ::rtl::OUString aDLLURL = aMyDirURL + rtl::OUString::createFromAscii( "/libModule_DLL.so" ); + //check if the lib exist. + //FIXME: if assert condition is false, the case will return, so the directory will not be clean-up + CPPUNIT_ASSERT_MESSAGE( "#Source file is not exist. please manually clean-up directory and file under /tmp", ifFileExist( getDllURL( ) ) == sal_True ); + ::osl::FileBase::RC nError = ::osl::File::copy( getDllURL( ), aDLLURL ); + CPPUNIT_ASSERT_MESSAGE( "#copy failed. please manually clean-up directory and file under /tmp", nError == ::osl::FileBase::E_None ); + //ifFileExist returned false but the file exist + CPPUNIT_ASSERT_MESSAGE( "#This file is not exist, copy failed. please manually clean-up directory and file under /tmp", ifFileExist( aDLLURL ) == sal_True ); + + //test if can create a normal file + ::rtl::OUString aFileURL = aMyDirURL + rtl::OUString::createFromAscii( "/test_file" ); + ::osl::File testFile( aFileURL ); + nError = testFile.open( OpenFlag_Create ); + CPPUNIT_ASSERT_MESSAGE( "#create failed. please manually clean-up directory and file under /tmp", nError == ::osl::FileBase::E_None ); + CPPUNIT_ASSERT_MESSAGE( "#This file is not exist, create failed. please manually clean-up directory and file under /tmp", ifFileExist( aFileURL ) == sal_True ); + + //load the copied dll + ::osl::Module aMod( aDLLURL ); + ::osl::Module aMod1; + + sal_Bool bOK = aMod1.load( aDLLURL ); + bRes = oslModule(aMod) == oslModule(aMod1); + aMod.unload( ); + aMod1.unload( ); + deleteTestFile( aFileURL ); + deleteTestFile( aDLLURL ); + deleteTestDirectory( aMyDirURL ); + deleteTestDirectory( aPidDirURL ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load lib which is under a CJK directory.", + sal_True == bRes && bOK == sal_True ); +#endif + } + + CPPUNIT_TEST_SUITE( load ); + CPPUNIT_TEST( load_001 ); + CPPUNIT_TEST( load_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class load + + + /** testing the method: + void SAL_CALL unload() + */ + class unload : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void unload_001( ) + { + ::osl::Module aMod( getDllURL( ) ); + + aMod.unload( ); + bRes = oslModule(aMod) ==NULL; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: unload function should do the same thing as destructor.", + sal_True == 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: + sal_Bool bRes, bRes1; + + void is_001( ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ); + if ( !( bRes ) ) + { + CPPUNIT_ASSERT_MESSAGE("Cannot locate current module - using executable instead", sal_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.", + sal_False == bRes && sal_True == bRes1); + } + CPPUNIT_TEST_SUITE( is ); + CPPUNIT_TEST( is_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class is + + + /** testing the methods: + void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName) + */ + class getSymbol : public CppUnit::TestFixture + { + public: + sal_Bool bRes; + + void getSymbol_001( ) + { + ::osl::Module aMod( getDllURL( ) ); + FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); + bRes = sal_False; + if ( pFunc ) + bRes = pFunc( bRes ); + aMod.unload(); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and call one function in it.", + sal_True == bRes ); + } + + 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: + sal_Bool bRes, bRes1; + + void optr_oslModule_001( ) + { + ::osl::Module aMod; + bRes = ( (oslModule)aMod == NULL ); + + aMod.load( getDllURL( ) ); + bRes1 = (oslModule)aMod != NULL; + + 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.", + sal_True == bRes && sal_True == bRes1); + } + + void optr_oslModule_002( ) + { + ::osl::Module aMod( getDllURL( ) ); + ::rtl::OUString funcName(::rtl::OUString::createFromAscii( "firstfunc" ) ); + + FuncPtr pFunc = ( FuncPtr ) osl_getSymbol( (oslModule)aMod, funcName.pData ); + bRes = sal_False; + if ( pFunc ) + bRes = pFunc( bRes ); + + aMod.unload(); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: use m_Module to call osl_getSymbol() function.", + sal_True == bRes ); + } + + 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 ::rtl::OUString& ustrFunctionSymbolName ) + */ + class getFunctionSymbol : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getFunctionSymbol_001( ) + { + ::osl::Module aMod( getDllURL( ) ); + oslGenericFunction oslFunc = aMod.getFunctionSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); + ::rtl::OUString aLibraryURL; + bRes = ::osl::Module::getUrlFromAddress( oslFunc, aLibraryURL); + aMod.unload(); + printFileName( aLibraryURL ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and get its function addr and get its URL.", + sal_True == bRes && aLibraryURL.equalsIgnoreAsciiCase( getDllURL() ) ); + } + + CPPUNIT_TEST_SUITE( getFunctionSymbol ); + CPPUNIT_TEST( getFunctionSymbol_001 ); + //CPPUNIT_TEST( getFunctionSymbol_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getFunctionSymbol + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::ctors, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::getUrlFromAddress, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::load, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::unload, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::is, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::getSymbol, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::optr_oslModule, "osl_Module"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::getFunctionSymbol, "osl_Module"); +// ----------------------------------------------------------------------------- + +} // namespace osl_Module + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; 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 000000000000..ad954b5cb4ad --- /dev/null +++ b/sal/qa/osl/module/osl_Module_Const.h @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Module_Const.h,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _OSL_MODULE_CONST_H_ +#define _OSL_MODULE_CONST_H_ + + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <osl/module.hxx> +#include <osl/file.hxx> + +#include <testshl/simpleheader.hxx> + +#if ( defined UNX ) || ( defined OS2 ) //Unix +# include <unistd.h> +#endif +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +// # include <windows.h> +# include <io.h> +#include <tools/postwin.h> +#endif + +# define FILE_PREFIX "file:///" + +//Korea charactors +::rtl::OUString aKname( + RTL_CONSTASCII_STRINGPARAM( + "/\xEC\x95\x88\xEB\x85\x95\xED\x95\x98\xEC\x84\xB8\xEC\x9A\x94"), + RTL_TEXTENCODING_ISO_8859_1); + // zero-extend the individual byte-sized characters one-to-one to individual + // sal_Unicode-sized characters; not sure whether this is what was + // intended... + +//------------------------------------------------------------------------ +// function pointer type. +//------------------------------------------------------------------------ +typedef sal_Bool (* FuncPtr )( sal_Bool ); + + +#endif /* _OSL_MODULE_CONST_H_ */ 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 000000000000..46610f35f22c --- /dev/null +++ b/sal/qa/osl/module/osl_Module_DLL.cxx @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Module_DLL.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <stdio.h> +#include <sal/types.h> +#include <testshl/simpleheader.hxx> + +extern "C" sal_Bool SAL_CALL firstfunc( sal_Bool bRes ) +{ + return ( bRes = sal_True ); +} +extern "C" void SAL_CALL secondfunc() +{ + printf("second func called.\n"); +} + diff --git a/sal/qa/osl/mutex/makefile.mk b/sal/qa/osl/mutex/makefile.mk new file mode 100755 index 000000000000..7c8cfeb39037 --- /dev/null +++ b/sal/qa/osl/mutex/makefile.mk @@ -0,0 +1,72 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.11 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_mutex + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL1OBJS= \ + $(SLO)$/osl_Mutex.obj + +SHL1TARGET= osl_Mutex +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +.IF "$(GUI)" == "WNT" +SHL1STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL1STDLIBS += -ldl -lnsl +.ENDIF + +SHL1IMPLIB= i$(SHL1TARGET) + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/mutex/osl_Mutex.cxx b/sal/qa/osl/mutex/osl_Mutex.cxx new file mode 100755 index 000000000000..a615bb3ce0dc --- /dev/null +++ b/sal/qa/osl/mutex/osl_Mutex.cxx @@ -0,0 +1,950 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Mutex.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <osl_Mutex_Const.h> + +using namespace osl; +using namespace rtl; + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +/** print a UNI_CODE String. +*/ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printUString_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("YES!\n" ): t_print("NO!\n" ); +} + +/** pause nSec seconds helper function. +*/ +namespace ThreadHelper +{ + void thread_sleep( sal_Int32 _nSec ) + { + /// print statement in thread process must use fflush() to force display. + // t_print("# wait %d seconds. ", _nSec ); + fflush(stdout); + +#ifdef WNT //Windows + Sleep( _nSec * 1000 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + sleep( _nSec ); +#endif + // t_print("# done\n" ); + } + void thread_sleep_tenth_sec(sal_Int32 _nTenthSec) + { +#ifdef WNT //Windows + Sleep(_nTenthSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + TimeValue nTV; + nTV.Seconds = static_cast<sal_uInt32>( _nTenthSec/10 ); + nTV.Nanosec = ( (_nTenthSec%10 ) * 100000000 ); + osl_waitThread(&nTV); +#endif + } +} + + +//------------------------------------------------------------------------ +// Beginning of the test cases for osl_Mutex class +//------------------------------------------------------------------------ + + +/** mutually exclusive data +*/ +struct resource { + sal_Int32 data1; + sal_Int32 data2; + Mutex lock; +}; + +/** IncreaseThread provide data. +*/ +class IncreaseThread : public Thread +{ +public: + IncreaseThread( struct resource *pData ): pResource( pData ) { } + + ~IncreaseThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#IncreaseThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + struct resource *pResource; + + void SAL_CALL run( ) + { + 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: + DecreaseThread( struct resource *pData ): pResource( pData ) { } + + ~DecreaseThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#DecreaseThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + struct resource *pResource; + + void SAL_CALL run( ) + { + 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 + PutThread( struct chain* pData ): pChain( pData ) { } + + ~PutThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#PutThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + struct chain* pChain; + + void SAL_CALL run( ) + { + //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 + HoldThread( Mutex* pMutex ): pMyMutex( pMutex ) { } + + ~HoldThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#HoldThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run() + { + // block here if the mutex has been acquired + pMyMutex->acquire( ); + t_print("# Mutex acquired. \n" ); + pMyMutex->release( ); + } +}; + +class WaitThread : public Thread +{ +public: + //get the Mutex pointer to operate + WaitThread( Mutex* pMutex ): pMyMutex( pMutex ) { } + + ~WaitThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#WaitThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) + { + // 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( ){ } + + ~GlobalMutexThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#GlobalMutexThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + void SAL_CALL run( ) + { + // block here if the mutex has been acquired + Mutex* pGlobalMutex; + pGlobalMutex = pGlobalMutex->getGlobalMutex( ); + pGlobalMutex->acquire( ); + t_print("# 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( ) + { + 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; + } + + void tearDown() + { + } + + /** 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 datas: their thread ID, so we can check the datas + 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( ); + + sal_Bool bRes = sal_False; + + // every 5 datas 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 = sal_True; + + /*for (sal_Int8 i=0; i<BUFFER_SIZE; i++) + t_print("#data in buffer is %d\n", m_Data.buffer[i]); + */ + + CPPUNIT_ASSERT_MESSAGE("Mutex ctor", bRes == sal_True); + + } + + /** 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( ); + + sal_Bool bRes = sal_False; + + // every 5 datas should the same + if ( ( m_Res.data1 == 0 ) && ( m_Res.data2 == 3 ) ) + bRes = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test Mutex ctor function: increase and decrease a number 3 times without interrupt.", bRes == sal_True ); + } + + 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 + sal_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 + sal_Bool bRes1 = myThread.isRunning( ); + + aMutex.release( ); + ThreadHelper::thread_sleep_tenth_sec( 1 ); + // after release mutex, myThread stops blocking and will terminate immediately + sal_Bool bRes2 = myThread.isRunning( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE( "Mutex acquire", + bRes == sal_True && bRes1 == sal_True && bRes2 == sal_False ); + } + + //in the same thread, acquire twice should success + void acquire_002() + { + Mutex aMutex; + //acquire here + sal_Bool bRes = aMutex.acquire(); + sal_Bool bRes1 = aMutex.acquire(); + + sal_Bool bRes2 = aMutex.tryToAcquire(); + + aMutex.release(); + + CPPUNIT_ASSERT_MESSAGE("Mutex acquire", + bRes == sal_True && bRes1 == sal_True && bRes2 == sal_True); + + } + + 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); + + sal_Bool bRes1 = aMutex.tryToAcquire(); + + if (bRes1 == sal_True) + aMutex.release(); + // wait the child thread terminate + myThread.join(); + + sal_Bool bRes2 = aMutex.tryToAcquire(); + + if (bRes2 == sal_True) + aMutex.release(); + + CPPUNIT_ASSERT_MESSAGE("Try to acquire Mutex", + bRes1 == sal_False && bRes2 == sal_True); + } + + 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 ); + + sal_Bool bRunning = myThread.isRunning( ); + sal_Bool bRes1 = aMutex.tryToAcquire( ); + // wait the child thread terminate + myThread.join( ); + + sal_Bool bRes2 = aMutex.tryToAcquire( ); + + if ( bRes2 == sal_True ) + aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "release Mutex: try to aquire before and after the mutex has been released", + bRes1 == sal_False && bRes2 == sal_True && bRunning == sal_True ); + + } + + // how about release twice? + void release_002() + { +// LLA: is this a real test? +#if 0 + Mutex aMutex; + sal_Bool bRes1 = aMutex.release( ); + sal_Bool bRes2 = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "release Mutex: mutex should not be released without aquire, should not release twice. although the behaviour is still under discussion, this test is passed on (LINUX), not passed on (SOLARIS)&(WINDOWS)", + bRes1 == sal_False && bRes2 == sal_False ); +#endif + } + + 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 = pGlobalMutex->getGlobalMutex(); + pGlobalMutex->acquire(); + + GlobalMutexThread myThread; + myThread.create(); + + ThreadHelper::thread_sleep_tenth_sec(1); + sal_Bool bRes1 = myThread.isRunning(); + + pGlobalMutex->release(); + ThreadHelper::thread_sleep_tenth_sec(1); + // after release mutex, myThread stops blocking and will terminate immediately + sal_Bool bRes2 = myThread.isRunning(); + + CPPUNIT_ASSERT_MESSAGE("Global Mutex works", + bRes1 == sal_True && bRes2 == sal_False); + } + + void getGlobalMutex_002( ) + { + sal_Bool bRes; + + Mutex *pGlobalMutex; + pGlobalMutex = pGlobalMutex->getGlobalMutex( ); + pGlobalMutex->acquire( ); + { + Mutex *pGlobalMutex1; + pGlobalMutex1 = pGlobalMutex1->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 == sal_True ); + } + + 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 +//------------------------------------------------------------------------ + +class GuardThread : public Thread +{ +public: + //get the Mutex pointer to operate + GuardThread( Mutex* pMutex ): pMyMutex( pMutex ) { } + + ~GuardThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#GuardThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) + { + // 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); + sal_Bool bRes = aMutex.tryToAcquire(); + // after 1 second, the mutex has been guarded, and the child thread should be running + sal_Bool bRes1 = myThread.isRunning(); + + myThread.join(); + sal_Bool bRes2 = aMutex.tryToAcquire(); + + CPPUNIT_ASSERT_MESSAGE("GuardThread constructor", + bRes == sal_False && bRes1 == sal_True && bRes2 == sal_True); + } + + 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 ); + sal_Bool bRes = myThread.isRunning( ); + + /// oh, release him. + aMutex.release( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE("GuardThread constructor: reference initialization, aquire the mutex before running the thread, then check if it is blocking.", + bRes == sal_True); + } + + 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 +//------------------------------------------------------------------------ + +/** Thread for test ClearableGuard + */ +class ClearGuardThread : public Thread +{ +public: + //get the Mutex pointer to operate + ClearGuardThread( Mutex* pMutex ): pMyMutex( pMutex ) {} + + ~ClearGuardThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#ClearGuardThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) + { + // acquire the mutex + // t_print("# 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. + sal_Bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the aquire operation when initilized.", + bRes == sal_True ); + } + + 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. + sal_Bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE("ClearableMutexGuard constructor, test the aquire operation when initilized, we use reference constructor this time.", + bRes == sal_True ); + } + + 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 (1) + { + if (aMutex.tryToAcquire() == sal_True) + { + break; + } + ThreadHelper::thread_sleep(1); + } + TimeValue aTimeVal_after; + osl_getSystemTime( &aTimeVal_after ); + sal_Int32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + t_print("nSec is %d\n", nSec); + + myThread.join(); + + CPPUNIT_ASSERT_MESSAGE("ClearableGuard method: clear", + nSec < 7 && 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 ); + sal_Bool bRes = myThread.isRunning( ); + + /// use clear to release. + myMutexGuard.clear( ); + myThread.join( ); + sal_Bool bRes1 = myThread.isRunning( ); + + CPPUNIT_ASSERT_MESSAGE( "ClearableGuard method: clear, control the HoldThread's running status!", + ( sal_True == bRes ) && ( sal_False == 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 +//------------------------------------------------------------------------ + +/** Thread for test ResettableGuard + */ +class ResetGuardThread : public Thread +{ +public: + //get the Mutex pointer to operate + ResetGuardThread( Mutex* pMutex ): pMyMutex( pMutex ) {} + + ~ResetGuardThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#ResetGuardThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + Mutex* pMyMutex; + + void SAL_CALL run( ) + { + // acquire the mutex + t_print("# ResettableGuard" ); + 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. + sal_Bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE("ResettableMutexGuard constructor, test the aquire operation when initilized.", + bRes == sal_True ); + } + + 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. + sal_Bool bRes = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard constructor, test the aquire operation when initilized, we use reference constructor this time.", + bRes == sal_True ); + } + + + 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 ); + myThread.create( ); + ResettableMutexGuard myMutexGuard( aMutex ); + + /// is it running? and clear done? + myMutexGuard.clear( ); + ThreadHelper::thread_sleep_tenth_sec( 1 ); + sal_Bool bRes = myThread.isRunning( ); + + /// if reset is not success, the release will return sal_False + myMutexGuard.reset( ); + sal_Bool bRes1 = aMutex.release( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset", + ( sal_True == bRes ) && ( sal_True == bRes1 ) ); + } + + void reset_002( ) + { + Mutex aMutex; + ResettableMutexGuard myMutexGuard( &aMutex ); + + /// shouldn't release after clear; + myMutexGuard.clear( ); + sal_Bool bRes = aMutex.release( ); + + /// can release after reset. + myMutexGuard.reset( ); + sal_Bool bRes1 = aMutex.release( ); + + CPPUNIT_ASSERT_MESSAGE( "ResettableMutexGuard method: reset, release after clear and reset, on Solaris, the mutex can be release without aquire, so it can not passed on (SOLARIS), but not the reason for reset_002", + ( sal_False == bRes ) && ( sal_True == bRes1 ) ); + } + + CPPUNIT_TEST_SUITE(reset); + CPPUNIT_TEST(reset_001); +#ifdef LINUX + CPPUNIT_TEST(reset_002); +#endif + CPPUNIT_TEST_SUITE_END(); + }; // class reset + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ResettableGuard::ctor, "osl_ResettableGuard"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ResettableGuard::reset, "osl_ResettableGuard"); +} // namespace osl_ResettableGuard + +// 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. +NOADDITIONAL; + +// The following sets variables for GNU EMACS +// Local Variables: +// tab-width:4 +// End: diff --git a/sal/qa/osl/mutex/osl_Mutex_Const.h b/sal/qa/osl/mutex/osl_Mutex_Const.h new file mode 100755 index 000000000000..a13f40ab9605 --- /dev/null +++ b/sal/qa/osl/mutex/osl_Mutex_Const.h @@ -0,0 +1,61 @@ +/************************************************************************* +* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Mutex_Const.h,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_MUTEX_CONST_H_ +#define _OSL_MUTEX_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/mutex.hxx> +#endif +#include <osl/time.h> + +#include <testshl/simpleheader.hxx> + +#ifdef UNX +#include <unistd.h> +#endif + +#define BUFFER_SIZE 16 + + +#endif /* _OSL_MUTEX_CONST_H_ */ diff --git a/sal/qa/osl/pipe/export.exp b/sal/qa/osl/pipe/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/osl/pipe/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/osl/pipe/makefile.mk b/sal/qa/osl/pipe/makefile.mk new file mode 100644 index 000000000000..3d0df14bbd69 --- /dev/null +++ b/sal/qa/osl/pipe/makefile.mk @@ -0,0 +1,66 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.9 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_pipe + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Pipe by codegen.pl +SHL1OBJS= \ + $(SLO)$/osl_Pipe.obj + +SHL1TARGET= osl_Pipe +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +# DEF1EXPORTFILE= export.exp +# auto generated Target:Pipe +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/pipe/osl_Pipe.cxx b/sal/qa/osl/pipe/osl_Pipe.cxx new file mode 100644 index 000000000000..c2b2ae740527 --- /dev/null +++ b/sal/qa/osl/pipe/osl_Pipe.cxx @@ -0,0 +1,1063 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Pipe.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> +#include <sal/types.h> +#include <rtl/ustring.hxx> + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/mutex.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/pipe.hxx> +#endif +#include <osl/time.h> + +#ifdef UNX +#include <unistd.h> +#endif + +using namespace osl; +using namespace rtl; + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +/** print Boolean value. + */ +inline void printBool( sal_Bool bOk ) +{ + t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("YES!\n" ): t_print("NO!\n" ); +} + +/** print a UNI_CODE String. + */ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printUString_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +/** print last error of pipe system. + */ +inline void printPipeError( ::osl::Pipe aPipe ) +{ + oslPipeError nError = aPipe.getError( ); + t_print("#printPipeError# " ); + switch ( nError ) { + case osl_Pipe_E_None: + t_print("Success!\n" ); + break; + case osl_Pipe_E_NotFound: + t_print("The returned error is: Not found!\n" ); + break; + case osl_Pipe_E_AlreadyExists: + t_print("The returned error is: Already exist!\n" ); + break; + case osl_Pipe_E_NoProtocol: + t_print("The returned error is: No protocol!\n" ); + break; + case osl_Pipe_E_NetworkReset: + t_print("The returned error is: Network reset!\n" ); + break; + case osl_Pipe_E_ConnectionAbort: + t_print("The returned error is: Connection aborted!\n" ); + break; + case osl_Pipe_E_ConnectionReset: + t_print("The returned error is: Connection reset!\n" ); + break; + case osl_Pipe_E_NoBufferSpace: + t_print("The returned error is: No buffer space!\n" ); + break; + case osl_Pipe_E_TimedOut: + t_print("The returned error is: Timeout!\n" ); + break; + case osl_Pipe_E_ConnectionRefused: + t_print("The returned error is: Connection refused!\n" ); + break; + case osl_Pipe_E_invalidError: + t_print("The returned error is: Invalid error!\n" ); + break; + default: + t_print("The returned error is: Number %d, Unknown Error\n", nError ); + break; + } +} + + + +//------------------------------------------------------------------------ +// pipe name and transfer contents +//------------------------------------------------------------------------ +const rtl::OUString aTestPipeName = rtl::OUString::createFromAscii( "testpipe2" ); +const rtl::OUString aTestPipe1 = rtl::OUString::createFromAscii( "testpipe1" ); +const rtl::OUString aTestString = rtl::OUString::createFromAscii( "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 ::rtl::OUString& strName, oslPipeOptions Options); + inline Pipe(const ::rtl::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: + sal_Bool bRes, bRes1; + + void setUp( ) + { + } + + void tearDown( ) + { + } + + void ctors_none( ) + { + ::osl::Pipe aPipe; + bRes = aPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.", + sal_False == bRes ); + } + + void ctors_name_option( ) + { + /// create a named pipe. + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE ); + ::osl::Pipe aAssignPipe( aTestPipeName, osl_Pipe_OPEN ); + + bRes = aPipe.is( ) && aAssignPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.", + sal_True == bRes ); + } + + void ctors_name_option_security( ) + { + /// create a security pipe. + const ::osl::Security rSecurity; + ::osl::Pipe aSecurityPipe( 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.", + sal_True == bRes ); + } + + void ctors_copy( ) + { + /// create a pipe. + ::osl::Pipe aPipe( 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.", + sal_True == bRes ); + } + + /** tester comment: + + When test the following two constructors, 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::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE ); + /// constructs a pipe reference without acquiring the handle. + ::osl::Pipe aNoAcquirePipe( aPipe.getHandle( ), SAL_NO_ACQUIRE ); + + bRes = aNoAcquirePipe.is( ); + ///aPipe.clear( ); + ///bRes1 = aNoAcquirePipe.is( ); + + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.", + sal_True == bRes ); + } + + void ctors_acquire( ) + { + /// create a base pipe. + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE ); + /// constructs two pipes without acquiring the handle on the base pipe. + ::osl::Pipe aAcquirePipe( aPipe.getHandle( ) ); + ::osl::Pipe aAcquirePipe1( NULL ); + + bRes = aAcquirePipe.is( ); + bRes1 = aAcquirePipe1.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle.only validation test, do not know how to test no acquire.", + sal_True == bRes && sal_False == bRes1 ); + } + + 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( ); + }; // class ctors + + + /** 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.", sal_False == aPipe.is( ) ); + } + + void is_002( ) + { + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", sal_True == aPipe.is( ) ); + } + + void is_003( ) + { + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", sal_False == aPipe.is( ) ); + } + + void is_004( ) + { + ::osl::Pipe aPipe( NULL ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", sal_False == 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( ); + }; // class is + + + /** testing the methods: + inline sal_Bool create( const ::rtl::OUString & strName, + oslPipeOptions Options, const Security &rSec ); + nline sal_Bool create( const ::rtl::OUString & strName, + oslPipeOptions Options = osl_Pipe_OPEN ); + */ + class create : public CppUnit::TestFixture + { + public: + sal_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( aTestPipeName, osl_Pipe_CREATE, rSec ); + bRes1 = aPipe.create( aTestPipeName, osl_Pipe_CREATE, rSec ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", + sal_True == bRes && sal_False == bRes1); + } + + void create_named_security_002( ) + { + const Security rSec; + ::osl::Pipe aPipe, aPipe1; + bRes = aPipe.create( aTestPipeName, osl_Pipe_CREATE, rSec ); + bRes1 = aPipe1.create( aTestPipeName, osl_Pipe_OPEN, rSec ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", + sal_True == bRes && sal_True == bRes1); + } + + void create_named_001( ) + { + ::osl::Pipe aPipe; + bRes = aPipe.create( aTestPipeName, osl_Pipe_CREATE ); + bRes1 = aPipe.create( aTestPipeName, osl_Pipe_CREATE ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", + sal_True == bRes && sal_False == bRes1); + } + + void create_named_002( ) + { + ::osl::Pipe aPipe, aPipe1; + bRes = aPipe.create( aTestPipeName, osl_Pipe_CREATE ); + bRes1 = aPipe1.create( aTestPipeName, osl_Pipe_OPEN ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", + sal_True == bRes && sal_True == bRes1); + } + + void create_named_003( ) + { + ::osl::Pipe aPipe; + bRes = aPipe.create( aTestPipeName ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.", + sal_False == 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( ); + }; // class create + + + /** testing the method: + inline void SAL_CALL clear(); + */ + class clear : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void clear_001( ) + { + ::osl::Pipe aPipe; + aPipe.create( aTestPipeName, osl_Pipe_CREATE ); + aPipe.clear( ); + bRes = aPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.", + sal_False == bRes ); + } + + CPPUNIT_TEST_SUITE( clear ); + CPPUNIT_TEST( clear_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class clear + + + /** 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: + sal_Bool bRes, bRes1; + + void assign_ref( ) + { + ::osl::Pipe aPipe, aPipe1; + aPipe.create( 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.", + sal_True == bRes && sal_True == bRes1 ); + } + + void assign_handle( ) + { + ::osl::Pipe aPipe, aPipe1; + aPipe.create( 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.", + sal_True == bRes && sal_True == bRes1 ); + } + + CPPUNIT_TEST_SUITE( assign ); + CPPUNIT_TEST( assign_ref ); + CPPUNIT_TEST( assign_handle ); + CPPUNIT_TEST_SUITE_END( ); + }; // class assign + + + /** 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 + */ + /*class isValid : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void isValid_001( ) + { + CPPUNIT_ASSERT_MESSAGE( "#test comment#: isValid() has not been implemented on all platforms.", + sal_False ); + } + + CPPUNIT_TEST_SUITE( isValid ); + CPPUNIT_TEST( isValid_001 ); + CPPUNIT_TEST_SUITE_END( ); + };*/ // class isValid + + + /** testing the method: + inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const; + */ + class isEqual : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void isEqual_001( ) + { + ::osl::Pipe aPipe; + aPipe.create( aTestPipeName, osl_Pipe_CREATE ); + bRes = aPipe == aPipe; + aPipe.close( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare its self.", + sal_True == bRes ); + } + + void isEqual_002( ) + { + ::osl::Pipe aPipe, aPipe1, aPipe2; + aPipe.create( aTestPipeName, osl_Pipe_CREATE ); + + aPipe1 = aPipe; + aPipe2.create( 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.", + sal_True == bRes && sal_False == bRes1 ); + } + + CPPUNIT_TEST_SUITE( isEqual ); + CPPUNIT_TEST( isEqual_001 ); + CPPUNIT_TEST( isEqual_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class isEqual + + + /** testing the method: + inline void SAL_CALL close(); + */ + class close : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void close_001( ) + { + ::osl::Pipe aPipe( aTestPipe1, osl_Pipe_CREATE ); + aPipe.close( ); + bRes = aPipe.is( ); + + aPipe.clear( ); + bRes1 = aPipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.", + sal_True == bRes && sal_False == bRes1); + } + + void close_002( ) + { + ::osl::StreamPipe aPipe( aTestPipe1, osl_Pipe_CREATE ); + aPipe.close( ); + int nRet = aPipe.send( m_pTestString1.getStr(), 3 ); + + CPPUNIT_ASSERT_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( ); + }; // class close + + + /** testing the method: + inline oslPipeError SAL_CALL accept(StreamPipe& Connection); + please refer to StreamPipe::recv + */ + /* class accept : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void accept_001( ) + { + + // CPPUNIT_ASSERT_MESSAGE( "#test comment#: accept, untested.", 1 == 1 ); + //CPPUNIT_ASSERT_STUB(); + } + + CPPUNIT_TEST_SUITE( accept ); + CPPUNIT_TEST( accept_001 ); + CPPUNIT_TEST_SUITE_END( ); + };*/ // class accept + + + /** testing the method: + inline oslPipeError SAL_CALL getError() const; + */ + class getError : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + /* + PipeError[]= { + { 0, osl_Pipe_E_None }, // no error + { EPROTOTYPE, osl_Pipe_E_NoProtocol }, // Protocol wrong type for socket + { ENOPROTOOPT, osl_Pipe_E_NoProtocol }, // Protocol not available + { EPROTONOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol not supported + { ESOCKTNOSUPPORT, osl_Pipe_E_NoProtocol }, // Socket type not supported + { EPFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol family not supported + { EAFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Address family not supported by + // protocol family + { ENETRESET, osl_Pipe_E_NetworkReset }, // Network dropped connection because + // of reset + { ECONNABORTED, osl_Pipe_E_ConnectionAbort }, // Software caused connection abort + { ECONNRESET, osl_Pipe_E_ConnectionReset }, // Connection reset by peer + { ENOBUFS, osl_Pipe_E_NoBufferSpace }, // No buffer space available + { ETIMEDOUT, osl_Pipe_E_TimedOut }, // Connection timed out + { ECONNREFUSED, osl_Pipe_E_ConnectionRefused }, // Connection refused + { -1, osl_Pipe_E_invalidError } + }; + did not define osl_Pipe_E_NotFound, osl_Pipe_E_AlreadyExists + */ + + void getError_001( ) + { + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_OPEN ); + oslPipeError nError = aPipe.getError( ); + printPipeError( aPipe ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe. not passed in (W32)(LINUX)(UNX).", + osl_Pipe_E_invalidError == nError ); + } + + void getError_002( ) + { + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE ); + ::osl::Pipe aPipe1( aTestPipeName, osl_Pipe_CREATE ); + oslPipeError nError = aPipe.getError( ); + printPipeError( aPipe ); + aPipe.clear( ); + aPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.not passed in (W32)(LINUX)(UNX).", + osl_Pipe_E_invalidError == nError ); + } + + CPPUNIT_TEST_SUITE( getError ); + CPPUNIT_TEST( getError_001 ); + CPPUNIT_TEST( getError_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getError + + + /** testing the method: + inline oslPipe SAL_CALL getHandle() const; + */ + class getHandle : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getHandle_001( ) + { + ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_OPEN ); + bRes = aPipe == aPipe.getHandle( ); + aPipe.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.", + sal_True == bRes ); + } + + void getHandle_002( ) + { + ::osl::Pipe aPipe( 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.", + sal_True == bRes ); + } + + CPPUNIT_TEST_SUITE( getHandle ); + CPPUNIT_TEST( getHandle_001 ); + CPPUNIT_TEST( getHandle_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getHandle + + +// ----------------------------------------------------------------------------- + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::ctors, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::is, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::create, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::clear, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::assign, "osl_Pipe"); +//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::isValid, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::isEqual, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::close, "osl_Pipe"); + //CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::accept, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::getError, "osl_Pipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::getHandle, "osl_Pipe"); +// ----------------------------------------------------------------------------- + +} // namespace osl_Pipe + + +namespace osl_StreamPipe +{ + + /** testing the methods: + inline StreamPipe(); + inline StreamPipe(oslPipe Pipe);; + inline StreamPipe(const StreamPipe& Pipe); + inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN); + inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec ); + inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire ); + */ + class ctors : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void ctors_none( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( 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.", + sal_False == bRes && sal_True == bRes1 ); + } + + void ctors_handle( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( 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.", + sal_True == bRes ); + } + + void ctors_copy( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( 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.", + sal_True == bRes ); + } + + void ctors_name_option( ) + { + // create a pipe. + ::osl::StreamPipe aStreamPipe( aTestPipeName, osl_Pipe_CREATE ); + // create an unattached pipe. + ::osl::StreamPipe aStreamPipe1( aTestPipeName, osl_Pipe_OPEN ); + bRes = aStreamPipe1.is( ) && aStreamPipe.is( ); + aStreamPipe.clear( ); + aStreamPipe1.clear( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.", + sal_True == bRes ); + } + + void ctors_name_option_security( ) + { + /// create a security pipe. + const ::osl::Security rSecurity; + ::osl::StreamPipe aSecurityPipe( 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.", + sal_True == 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( aTestPipeName, osl_Pipe_CREATE ); + // constructs a pipe reference without acquiring the handle. + ::osl::StreamPipe aNoAcquirePipe( aPipe.getHandle( ), SAL_NO_ACQUIRE ); + + bRes = aNoAcquirePipe.is( ); + aPipe.clear( ); + // bRes1 = aNoAcquirePipe.is( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.", + sal_True == 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( ); + }; // class ctors + + + /** testing the methods: + inline StreamPipe & SAL_CALL operator=(oslPipe Pipe); + inline StreamPipe& SAL_CALL operator=(const Pipe& pipe); + mindy: not implementated in osl/pipe.hxx, so remove the cases + */ + /* + class assign : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void assign_ref( ) + { + ::osl::StreamPipe aPipe, aPipe1; + aPipe.create( 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.", + sal_True == bRes && sal_True == bRes1 ); + } + + void assign_handle( ) + { + ::osl::StreamPipe * pPipe = new ::osl::StreamPipe( aTestPipeName, osl_Pipe_CREATE ); + ::osl::StreamPipe * pAssignPipe = new ::osl::StreamPipe; + *pAssignPipe = pPipe->getHandle( ); + + bRes = pAssignPipe->is( ); + bRes1 = ( *pPipe == *pAssignPipe ); + pPipe->close( ); + + delete pAssignPipe; + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle., seems not implemented under (LINUX)(W32)", + sal_True == bRes && sal_True == bRes1 ); + } + + CPPUNIT_TEST_SUITE( assign ); + CPPUNIT_TEST( assign_ref ); + CPPUNIT_TEST( assign_handle ); + CPPUNIT_TEST_SUITE_END( ); + };*/ // class assign + + + /** wait _nSec seconds. + */ + void thread_sleep( sal_Int32 _nSec ) + { + /// print statement in thread process must use fflush() to force display. + // t_print("wait %d seconds. ", _nSec ); + fflush(stdout); + +#ifdef WNT //Windows + Sleep( _nSec * 1000 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + sleep( _nSec ); +#endif + // t_print("done\n" ); + } + // test read/write & send/recv data to pipe + // ----------------------------------------------------------------------------- + + class Pipe_DataSink_Thread : public Thread + { + public: + sal_Char buf[256]; + Pipe_DataSink_Thread( ) { } + + ~Pipe_DataSink_Thread( ) + { + } + protected: + void SAL_CALL run( ) + { + sal_Int32 nChars = 0; + + t_print("open pipe\n"); + ::osl::StreamPipe aSenderPipe( aTestPipeName, osl_Pipe_OPEN ); // aTestPipeName is a string = "TestPipe" + if ( aSenderPipe.is() == sal_False ) + { + t_print("pipe open failed! \n"); + } + else + { + t_print("read\n"); + nChars = aSenderPipe.read( buf, m_pTestString1.getLength() + 1 ); + if ( nChars < 0 ) + { + t_print("read failed! \n"); + return; + } + t_print("buffer is %s \n", buf); + t_print("send\n"); + nChars = aSenderPipe.send( m_pTestString2.getStr(), m_pTestString2.getLength() + 1 ); + if ( nChars < 0 ) + { + t_print("client send failed! \n"); + return; + } + } + } + + }; + + // ----------------------------------------------------------------------------- + + class Pipe_DataSource_Thread : public Thread + { + public: + sal_Char buf[256]; + //::osl::StreamPipe aListenPipe; //( aTestPipeName, osl_Pipe_CREATE ); + ::osl::Pipe aListenPipe; + ::osl::StreamPipe aConnectionPipe; + Pipe_DataSource_Thread( ) + { + t_print("create pipe\n"); + aListenPipe.create( aTestPipeName, osl_Pipe_CREATE ); + } + ~Pipe_DataSource_Thread( ) + { + aListenPipe.close(); + } + protected: + void SAL_CALL run( ) + { + //create pipe. + sal_Int32 nChars; + //::osl::StreamPipe aListenPipe( aTestPipeName, osl_Pipe_CREATE ); + t_print("listen\n"); + if ( aListenPipe.is() == sal_False ) + { + t_print("pipe create failed! \n"); + } + else + { + //::osl::StreamPipe aConnectionPipe; + + //start server and wait for connection. + t_print("accept\n"); + if ( osl_Pipe_E_None != aListenPipe.accept( aConnectionPipe ) ) + { + t_print("pipe accept failed!"); + return; + } + t_print("write\n"); + // write to pipe + nChars = aConnectionPipe.write( m_pTestString1.getStr(), m_pTestString1.getLength() + 1 ); + if ( nChars < 0) + { + t_print("server write failed! \n"); + return; + } + t_print("recv\n"); + nChars = aConnectionPipe.recv( buf, 256 ); + + if ( nChars < 0) + { + t_print("server receive failed! \n"); + return; + } + //thread_sleep( 2 ); + t_print("received message is: %s\n", buf ); + //aConnectionPipe.close(); + } + } + }; + + /** testing the method: read/write/send/recv and Pipe::accept + */ + class recv : public CppUnit::TestFixture + { + public: + sal_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_MESSAGE( "test send/recv/write/read.", nCompare1 == 0 && nCompare2 == 0 ); + } + //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 excuting within 1 or 2 seconds, it passes. + } + + CPPUNIT_TEST_SUITE( recv ); + CPPUNIT_TEST( recv_001 ); + CPPUNIT_TEST( recv_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class recv + +// ----------------------------------------------------------------------------- + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamPipe::ctors, "osl_StreamPipe"); +//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamPipe::assign, "osl_StreamPipe"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamPipe::recv, "osl_StreamPipe"); +// ----------------------------------------------------------------------------- + +} // namespace osl_StreamPipe + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/pipe/osl_Pipe.xsce b/sal/qa/osl/pipe/osl_Pipe.xsce new file mode 100644 index 000000000000..d96a915d8ab9 --- /dev/null +++ b/sal/qa/osl/pipe/osl_Pipe.xsce @@ -0,0 +1,9 @@ +#i23307# +osl_Pipe.getError.getError_001 wntmsci +osl_Pipe.getError.getError_002 wntmsci + +osl_StreamPipe.recv.recv_002 wntmsci unxsols +# osl_Pipe.ctors.ctors_acquire wntmsci + +#i27889# +osl_Pipe.ctors.ctors_no_acquire wntmsci diff --git a/sal/qa/osl/pipe/osl_Pipe_Const.h b/sal/qa/osl/pipe/osl_Pipe_Const.h new file mode 100644 index 000000000000..0b70655eabc0 --- /dev/null +++ b/sal/qa/osl/pipe/osl_Pipe_Const.h @@ -0,0 +1 @@ +// no longer used diff --git a/sal/qa/osl/process/batch.bat b/sal/qa/osl/process/batch.bat new file mode 100755 index 000000000000..7a47559e9b6e --- /dev/null +++ b/sal/qa/osl/process/batch.bat @@ -0,0 +1,2 @@ +@echo off +echo "Hello world"
\ No newline at end of file diff --git a/sal/qa/osl/process/export.exp b/sal/qa/osl/process/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/osl/process/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/osl/process/makefile.mk b/sal/qa/osl/process/makefile.mk new file mode 100644 index 000000000000..32e97f3c162d --- /dev/null +++ b/sal/qa/osl/process/makefile.mk @@ -0,0 +1,114 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.15 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_process +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:testjob by codegen.pl + +.IF "$(GUI)" == "WNT" + CFLAGS+=/Ob1 +.ENDIF + +SHL1OBJS= \ + $(SLO)$/osl_Thread.obj + +SHL1TARGET= osl_Thread +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) + +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) + +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# END ------------------------------------------------------------------ + +#.IF "$(GUI)" == "WNT" + +SHL2OBJS=$(SLO)$/osl_process.obj +SHL2TARGET=osl_process +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB=i$(SHL2TARGET) +SHL2DEF=$(MISC)$/$(SHL2TARGET).def +DEF2NAME=$(SHL2TARGET) +DEF2EXPORTFILE=export.exp + +# END ------------------------------------------------------------------ + +OBJ3FILES=$(OBJ)$/osl_process_child.obj +APP3TARGET=osl_process_child +APP3OBJS=$(OBJ3FILES) + +# .IF "$(GUI)" == "UNX" +# APP3STDLIBS=$(LB)$/libsal.so +# .ENDIF +# .IF "$(GUI)" == "WNT" +# APP3STDLIBS=$(KERNEL32LIB) $(LB)$/isal.lib +# .ENDIF +APP3STDLIBS=$(SALLIB) + +#.ENDIF # "$(GUI)" == "WNT" + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies + +.IF "$(GUI)" == "OS2" + +SLOFILES=$(SHL2OBJS) + +.ELSE + +SLOFILES=$(SHL1OBJS) $(SHL2OBJS) + +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx new file mode 100644 index 000000000000..88f796b6728c --- /dev/null +++ b/sal/qa/osl/process/osl_Thread.cxx @@ -0,0 +1,2347 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Thread.cxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <sal/types.h> + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/string.hxx> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/strbuf.hxx> +#endif + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/mutex.hxx> +#endif +#include <osl/time.h> + +#include <testshl/simpleheader.hxx> + +using namespace osl; +using namespace rtl; + +#ifdef UNX +#include <unistd.h> +#include <time.h> +#endif +// ----------------------------------------------------------------------------- +// Kleine Stopuhr +class StopWatch { + TimeValue t1,t2; // Start und Stopzeit + +protected: + sal_Int32 m_nNanoSec; + sal_Int32 m_nSeconds; + + bool m_bIsValid; // TRUE, wenn gestartet und gestoppt + bool m_bIsRunning; // TRUE, wenn gestartet. + +public: + StopWatch(); + ~StopWatch() {} + + void start(); // Startet Timer + void stop(); // Stoppt Timer + + double getSeconds() const; + double getTenthSec() const; +}; + +// ================================= Stop Watch ================================= + +// Eine kleine Stop-Uhr fuer den internen Gebrauch. +// (c) Lars Langhans 29.12.1996 22:10 + +StopWatch::StopWatch():m_bIsValid(false),m_bIsRunning(false) {} + +void StopWatch::start() +{ +// pre: % +// post: Start Timer + + m_bIsValid = false; + m_bIsRunning = true; + osl_getSystemTime( &t1 ); + t_print("# %d %d nsecs\n", t1.Seconds, t1.Nanosec); + // gettimeofday(&t1, 0); +} + +void StopWatch::stop() +{ +// pre: Timer should be started +// post: Timer will stopped + + // gettimeofday(&t2, 0); // Timer ausfragen + osl_getSystemTime( &t2 ); + t_print("# %d %d nsecs\n", t2.Seconds, t2.Nanosec); + + if (m_bIsRunning) + { // check ob gestartet. +// LLA: old m_nNanoSec = static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec); +// LLA: old m_nSeconds = static_cast<sal_Int32>(t2.Seconds) - static_cast<sal_Int32>(t1.Seconds); +// LLA: old if (m_nNanoSec < 0) +// LLA: old { +// LLA: old m_nNanoSec += 1000000000; +// LLA: old m_nSeconds -= 1; +// LLA: old } + //m_nNanoSec = t2.Nanosec - t1.Nanosec; + 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("# %d %d nsecs\n", m_nSeconds, m_nNanoSec ); + //if (m_nNanoSec < 0) + //{ + //m_nNanoSec += 1000000000; + //m_nSeconds -= 1; + //} + m_bIsValid = true; + m_bIsRunning = false; + } +} + +double StopWatch::getSeconds() const +{ +// pre: gueltig = TRUE +// BACK: Zeit in Sekunden. + + 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 ; +} + +// ----------------------------------------------------------------------------- +template <class T> +class ThreadSafeValue +{ + T m_nFlag; + Mutex m_aMutex; +public: + 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 addValue(T n) + { + //only one thread operate on the flag. + osl::MutexGuard g(m_aMutex); + m_nFlag += n; + } + void acquire() {m_aMutex.acquire();} + void release() {m_aMutex.release();} +}; + +// ----------------------------------------------------------------------------- +namespace ThreadHelper +{ + // typedef enum { + // QUIET=1, + // VERBOSE + // } eSleepVerboseMode; + + void thread_sleep_tenth_sec(sal_Int32 _nTenthSec/*, eSleepVerboseMode nVerbose = VERBOSE*/) + { + // if (nVerbose == VERBOSE) + // { + // t_print("wait %d tenth seconds. ", _nTenthSec ); + // fflush(stdout); + // } +#ifdef WNT //Windows + Sleep(_nTenthSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + TimeValue nTV; + nTV.Seconds = static_cast<sal_uInt32>( _nTenthSec/10 ); + nTV.Nanosec = ( (_nTenthSec%10 ) * 100000000 ); + osl_waitThread(&nTV); +#endif + // if (nVerbose == VERBOSE) + // { + // t_print("done\n"); + // } + } + + 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"); + } + } +} + +/** 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() + { + while(schedule()) + { + m_aFlag.addValue(1); + ThreadHelper::thread_sleep_tenth_sec(1); + } + } + +public: + + virtual void SAL_CALL suspend() + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } + + ~myThread() + { + 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 %d!\n", 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() + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } + +protected: + //sal_Bool m_bWait; + sal_Int32 m_nWaitSec; + + void SAL_CALL run() + { + /// if the thread should terminate, schedule return false + while (m_aFlag.getValue() < 20 && schedule() == sal_True) + { + m_aFlag.addValue(1); + ThreadHelper::thread_sleep_tenth_sec(1); + // TimeValue nTV; + // nTV.Seconds = 1; + // nTV.Nanosec = 0; + // wait(nTV); + + if (m_nWaitSec != 0) + { + //ThreadHelper::thread_sleep_tenth_sec(m_nWaitSec * 10); + TimeValue nTV; + nTV.Seconds = m_nWaitSec / 10 ; + nTV.Nanosec = ( m_nWaitSec%10 ) * 100000000 ; + wait( nTV ); + m_nWaitSec = 0; + } + } + } + void SAL_CALL onTerminated() + { + t_print("normally terminate this thread %d!\n", getIdentifier()); + } +public: + + ~OCountThread() + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } + +}; + +/** call suspend in the run method +*/ +class OSuspendThread : public Thread +{ + ThreadSafeValue<sal_Int32> m_aFlag; +public: + OSuspendThread(){ m_bSuspend = sal_False; } + sal_Int32 getValue() { return m_aFlag.getValue(); } + void setSuspend() + { + m_bSuspend = sal_True; + } + virtual void SAL_CALL suspend() + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } +protected: + sal_Bool m_bSuspend; + void SAL_CALL run() + { + //if the thread should terminate, schedule return false + while (schedule() == sal_True) + { + m_aFlag.addValue(1); + + ThreadHelper::thread_sleep_tenth_sec(1); + // m_bWait = sal_False; + // TimeValue nTV; + // nTV.Seconds = 1; + // nTV.Nanosec = 0; + // wait(nTV); + if (m_bSuspend == sal_True) + { + suspend(); + m_bSuspend = sal_False; + } + } + } +public: + + ~OSuspendThread() + { + 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() + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } +protected: + void SAL_CALL run() + { + while (m_aFlag.getValue() < 10) + { + m_aFlag.addValue(1); + ThreadHelper::thread_sleep_tenth_sec(1); + // TimeValue nTV; + // nTV.Seconds = 1; + // nTV.Nanosec = 0; + // wait(nTV); + } + } + void SAL_CALL onTerminated() + { + t_print("normally terminate this thread %d!\n", getIdentifier()); + } +public: + ONoScheduleThread() + { + t_print("new thread id %d!\n", getIdentifier()); + } + ~ONoScheduleThread() + { + 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() + { + m_aFlag.acquire(); + ::osl::Thread::suspend(); + m_aFlag.release(); + } +protected: + void SAL_CALL run() + { + //if the thread should terminate, schedule return false + while (schedule() == sal_True) + { + m_aFlag.addValue(1); + } + } + void SAL_CALL onTerminated() + { + // t_print("normally terminate this thread %d!\n", getIdentifier()); + } +public: + + ~OAddThread() + { + if (isRunning()) + { + // t_print("error: not terminated.\n"); + } + } + +}; + +namespace osl_Thread +{ + + void resumeAndWaitThread(Thread* _pThread) + { + // This functions 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 WNT + t_print("resumeAndWaitThread\n"); + _pThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(1); +#else + _pThread->resume(); +#endif + // ThreadHelper::thread_sleep_tenth_sec(1); + // _pThread->suspend(); + // ThreadHelper::thread_sleep_tenth_sec(1); + } + + // kill a running thread and join it, if it has terminated, do nothing + void termAndJoinThread(Thread* _pThread) + { + _pThread->terminate(); + +// LLA: Windows feature???, a suspended thread can not terminated, so we have to weak it up +#ifdef WNT + _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: + + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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(); + sal_Bool bRes = newthread->create(); + CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!\n", bRes == sal_True ); + + ThreadHelper::thread_sleep_tenth_sec(1); // wait short + sal_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", nValue); + t_print("isRunning = %d\n", isRunning); + + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread", + nValue >= 1 && isRunning == sal_True + ); + + } + + /** only one running thread per instance, return false if create secondly + */ + void create_002() + { + myThread* newthread = new myThread(); + sal_Bool res1 = newthread->create(); + sal_Bool res2 = newthread->create(); + t_print("In non pro, an assertion should occured. This behaviour is right.\n"); + termAndJoinThread(newthread); + delete newthread; + + CPPUNIT_ASSERT_MESSAGE( + "Creates a new thread: can not create two threads per instance", + res1 && !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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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(); + sal_Bool bRes = newthread->createSuspended(); + CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!", bRes == sal_True ); + + ThreadHelper::thread_sleep_tenth_sec(1); + sal_Bool isRunning = newthread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); + + resumeAndWaitThread(newthread); + + termAndJoinThread(newthread); + delete newthread; + + CPPUNIT_ASSERT_MESSAGE( + "Creates a new suspended thread", + nValue == 0 && isRunning + ); + } + + void createSuspended_002() + { + myThread* newthread = new myThread(); + sal_Bool res1 = newthread->createSuspended(); + sal_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 && !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. + */ + void suspendCountThread(OCountThread* _pCountThread) + { + sal_Int32 nValue = 0; + while (1) + { + nValue = _pCountThread->getValue(); + if (nValue >= 3) + { + _pCountThread->suspend(); + break; + } + } + } + + /** Test of the osl::Thread::suspend method + */ + class suspend : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + // 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 == sal_True && nValue == nLaterValue + ); + + } + /** suspend a thread in it's worker-function, the ALGORITHM is same as suspend_001 + reason of deadlocked I think: no schedule can schedule other threads to go on excuting + */ + void suspend_002() + { + OSuspendThread* aThread = new OSuspendThread(); + sal_Bool bRes = aThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + // first the thread run for some seconds, but not terminate + sal_Int32 nValue = 0; + //while (1) + //{ + ThreadHelper::thread_sleep_tenth_sec(3); + nValue = aThread->getValue(); // (1) + t_print(" getValue is %d !", nValue ); + if (nValue >= 2) + { + aThread->setSuspend(); + //break; + } + //} + t_print(" after while!"); + // the value just after calling suspend + nValue = aThread->getValue(); // (2) + + ThreadHelper::thread_sleep_tenth_sec(3); + t_print(" after sleep!"); + // the value after waiting 3 seconds + sal_Int32 nLaterValue = aThread->getValue(); // (3) + + //resumeAndWaitThread(aThread); + aThread->resume(); + termAndJoinThread(aThread); + delete aThread; + + CPPUNIT_ASSERT_MESSAGE( + "Suspend the thread", + bRes == sal_True && 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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(); + sal_Bool bRes = pCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + 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", nSuspendValue); + t_print("ResumeValue: %d\n", nResumeValue); + t_print("LaterValue: %d\n", nLaterValue); + + /* LLA: this assumption is no longer relevant: nResumeValue == nSuspendValue && */ + CPPUNIT_ASSERT_MESSAGE( + "Suspend then resume the thread", + nLaterValue >= 9 && + nResumeValue > nSuspendValue && + nLaterValue > nResumeValue + ); + + } + + /** Create a suspended thread then resume, check if the thread has run + */ + void resume_002() + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->createSuspended(); + CPPUNIT_ASSERT_MESSAGE ( "Can't create thread!", bRes == sal_True ); + + newthread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = newthread->getValue(); + + termAndJoinThread(newthread); + delete newthread; + + t_print(" nValue = %d\n", 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + 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 + sal_Bool isRunning = aCountThread->isRunning(); + aCountThread->join(); + delete aCountThread; + + t_print(" nValue = %d\n", nValue); + t_print("nLaterValue = %d\n", nLaterValue); + + CPPUNIT_ASSERT_MESSAGE( + "Terminate the thread", + isRunning == sal_False && 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(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + 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", nValue); + t_print("nLaterValue = %d\n", 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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 terminate + ALGORITHM: + recode system time at the beginning of the thread run, call join, then record system time again, + the difference of the two time should be equal or more than 20 seconds, the CountThead normally terminate + */ + void join_001() + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + 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(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + //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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** + */ + void isRunning_001() + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + sal_Bool bRun = aCountThread->isRunning(); + + ThreadHelper::thread_sleep_tenth_sec(2); + termAndJoinThread(aCountThread); + sal_Bool bTer = aCountThread->isRunning(); + delete aCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + bRun == sal_True && bTer == sal_False + ); + } + /** check the value of isRunning when suspending and after resume + */ + void isRunning_002() + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + // sal_Bool bRunning = aCountThread->isRunning(); + // sal_Int32 nValue = 0; + suspendCountThread(aCountThread); + + sal_Bool bRunning_sup = aCountThread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(2); + aCountThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Bool bRunning_res = aCountThread->isRunning(); + termAndJoinThread(aCountThread); + sal_Bool bRunning_ter = aCountThread->isRunning(); + delete aCountThread; + + CPPUNIT_ASSERT_MESSAGE( + "Test isRunning", + bRes == sal_True && + bRunning_sup == sal_True && + bRunning_res == sal_True && + bRunning_ter == sal_False + ); + + } + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + rtl::OString getPrioName(oslThreadPriority _aPriority) + { + rtl::OString sPrioStr; + switch (_aPriority) + { + case osl_Thread_PriorityHighest: + sPrioStr = "Highest"; + break; + + case osl_Thread_PriorityAboveNormal: + sPrioStr = "AboveNormal"; + + case osl_Thread_PriorityNormal: + sPrioStr = "Normal"; + + 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 = 0; + nValueNormal = pThread->getValue(); + + sal_Int32 nValueNormal2 = 0; + nValueNormal2 = p2Thread->getValue(); + + rtl::OString sPrio = getPrioName(_aPriority); + t_print("After 10 tenth seconds\n"); + + t_print("nValue in %s Prio Thread is %d\n",sPrio.getStr(), nValueNormal); + t_print("nValue in %s Prio Thread is %d\n", sPrio.getStr(), 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",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 = 0; + nValueHighest = aHighestThread.getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = aAboveNormalThread.getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = aNormalThread.getValue(); + + // sal_Int32 nValueBelowNormal = 0; + //nValueBelowNormal = aBelowNormalThread->getValue(); + // sal_Int32 nValueLowest = 0; + //nValueLowest = aLowestThread->getValue(); + t_print("After 10 tenth seconds\n"); + t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); + t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: CPPUNIT_ASSERT_MESSAGE( + // LLA: "SetPriority", + // LLA: nValueHighest >= nValueAboveNormal && + // LLA: nValueAboveNormal >= nValueNormal && + // LLA: nValueNormal > 0 + // LLA: ); + +// LLA: windows let starve threads with lower priority +#ifndef WNT + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0 + ); +#endif + } + + void setPriority_003() + { + // initial 5 threads with different priorities + OAddThread *pHighestThread = new OAddThread(); + OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //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 = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + t_print("After 10 tenth seconds\n"); + t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); + t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); + t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + delete pHighestThread; + delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: CPPUNIT_ASSERT_MESSAGE( + // LLA: "SetPriority", + // LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA: ); + +// LLA: windows let starve threads with lower priority +#ifndef WNT + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0 + ); +#endif + } + + void setPriority_004() + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //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 = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + t_print("After 5 tenth seconds\n"); + // t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); + t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); + t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + // delete pHighestThread; + delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: CPPUNIT_ASSERT_MESSAGE( + // LLA: "SetPriority", + // LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA: ); + +// LLA: windows let starve threads with lower priority +#ifndef WNT + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + /* nValueHighest > 0 && */ + nValueAboveNormal > 0 && + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0 + ); +#endif + } + void setPriority_005() + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + // OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //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 = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + t_print("After 5 tenth seconds\n"); + // t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); + // t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); + t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + // delete pHighestThread; + // delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: CPPUNIT_ASSERT_MESSAGE( + // LLA: "SetPriority", + // LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA: ); + +// LLA: windows let starve threads with lower priority +#ifndef WNT + CPPUNIT_ASSERT_MESSAGE( + "SetPriority", + /* nValueHighest > 0 && */ + /* nValueAboveNormal > 0 && */ + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0 + ); +#endif + } + + + CPPUNIT_TEST_SUITE(setPriority); +#ifndef SOLARIS + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // 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 WNT ) || ( defined SOLARIS ) + CPPUNIT_ASSERT_MESSAGE( + "getPriority", + aPriority == osl_Thread_PriorityHighest + ); +#else +// LLA: Linux +// NO_PTHREAD_PRIORITY ??? + CPPUNIT_ASSERT_MESSAGE( + "getPriority", + aPriority == osl_Thread_PriorityNormal + ); +#endif + } + + void getPriority_002() + { + + } + + CPPUNIT_TEST_SUITE(getPriority); + CPPUNIT_TEST(getPriority_001); + CPPUNIT_TEST(getPriority_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getPriority + + + class getIdentifier : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getIdentifier_001() + { + + } + + void getIdentifier_002() + { + + } + + CPPUNIT_TEST_SUITE(getIdentifier); + CPPUNIT_TEST(getIdentifier_001); + CPPUNIT_TEST(getIdentifier_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getIdentifier + + /** Test of the osl::Thread::getCurrentIdentifier method + */ + class getCurrentIdentifier : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getCurrentIdentifier_001() + { + oslThreadIdentifier oId; + OCountThread* pCountThread = new OCountThread; + //OCountThread* pCountThread2 = new OCountThread; + pCountThread->create(); + //pCountThread2->create(); + pCountThread->setWait(3); + oId = Thread::getCurrentIdentifier(); + oslThreadIdentifier oIdChild = pCountThread->getIdentifier(); + //t_print("CurrentId is %ld, Child1 id is %ld, Child2 id is %ld\n",oId, oIdChild,pCountThread2->m_id ); + termAndJoinThread(pCountThread); + delete pCountThread; + //termAndJoinThread(pCountThread2); + //delete pCountThread2; + + CPPUNIT_ASSERT_MESSAGE( + "Get the identifier for the current active thread.", + oId != oIdChild + ); + + } + + void getCurrentIdentifier_002() + { + } + + CPPUNIT_TEST_SUITE(getCurrentIdentifier); + CPPUNIT_TEST(getCurrentIdentifier_001); + //CPPUNIT_TEST(getCurrentIdentifier_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getCurrentIdentifier + + /** Test of the osl::Thread::wait method + */ + class wait : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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. + sal_Bool bRes = aCountThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + //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", nValue); + + CPPUNIT_ASSERT_MESSAGE( + "Wait: Blocks the calling thread for the given number of time.", + nTenthSec >= 5 && nValue == 1 + ); + + } +// LLA: wait_001 does the same. +// LLA: /** wait then terminate the thread +// LLA: +// LLA: ALGORITHM: +// LLA: wait nWaitSec seconds, and terminate when the wait does not finish +// LLA: Windows & UNX: thread terminates immediatlly +// LLA: */ +// LLA: void wait_002() +// LLA: { +// LLA: OCountThread aThread; +// LLA: +// LLA: sal_Int32 nWaitSec = 3; +// LLA: aThread.setWait(nWaitSec); +// LLA: +// LLA: sal_Bool bRes = aThread.create(); +// LLA: CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); +// LLA: +// LLA: StopWatch aStopWatch; +// LLA: // TimeValue aTimeVal_befor; +// LLA: // osl_getSystemTime( &aTimeVal_befor ); +// LLA: aStopWatch.start(); +// LLA: +// LLA: termAndJoinThread(&aThread); +// LLA: sal_Int32 nValue = aThread.getValue(); +// LLA: +// LLA: // TimeValue aTimeVal_after; +// LLA: // osl_getSystemTime( &aTimeVal_after ); +// LLA: aStopWatch.stop(); +// LLA: // sal_Int32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; +// LLA: double nSec = aStopWatch.getSeconds(); +// LLA: t_print("sec=%f\n", nSec); +// LLA: t_print("nValue = %d\n", nValue); +// LLA: +// LLA: CPPUNIT_ASSERT_MESSAGE( +// LLA: "Wait: Blocks the calling thread for the given number of time.", +// LLA: nSec < 1 && nValue == 0 +// LLA: ); +// LLA: } + + CPPUNIT_TEST_SUITE(wait); + CPPUNIT_TEST(wait_001); + // LLA: CPPUNIT_TEST(wait_002); + CPPUNIT_TEST_SUITE_END(); + }; // class wait + + /** osl::Thread::yield method: can not design good test scenario to test up to now + */ + class yield : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void yield_001() + { + } + + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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(); + sal_Bool bRes = aThread->create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + 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", nValue); + t_print("later value = %d\n", nLaterValue); + // if value and latervalue not equal, than the thread would not suspended + + CPPUNIT_ASSERT_MESSAGE( + "Schedule: suspend works.", + nLaterValue == nValue + ); + + 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", nValue_term); + t_print("value after join = %d\n", 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 immediatlly return + CPPUNIT_ASSERT_MESSAGE( + "Schedule: Returns False if the thread should terminate.", + nValue_join - nValue_term <= 1 && 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) + sal_Bool bRes = aThread.create(); + CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + + 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", nValue); + t_print("later value = %d\n", nLaterValue); + + //On windows, suspend works, so the values are same +#ifdef WNT + CPPUNIT_ASSERT_MESSAGE( + "Schedule: don't schedule in thread run method, suspend works.", + nLaterValue == nValue + ); +#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", nValue_term); + + CPPUNIT_ASSERT_MESSAGE( + "Schedule: don't schedule in thread run method, terminate failed.", + nValue_term == 10 + ); + } + + 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::wait, "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 +void SAL_CALL destroyCallback(void * data) +{ + t_print("destroying local data %s\n", (char *) data); + delete[] (char *) data; +} + +static ThreadData myThreadData(destroyCallback); + +/** +*/ +class myKeyThread : public Thread +{ +public: + // a public char member for test result checking + char m_Char_Test; + // for pass thread-special data to thread + myKeyThread(const char cData) + { + m_nData = cData; + } +private: + char m_nData; + + void SAL_CALL run() + { + char * pc = new char[2]; +// strcpy(pc, &m_nData); + memcpy(pc, &m_nData, 1); + pc[1] = '\0'; + + myThreadData.setData(pc); + char* pData = (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: + ~myKeyThread() + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } +}; + +static ThreadData idData; + +class idThread: public Thread +{ +public: + oslThreadIdentifier m_Id; +private: + void SAL_CALL run() + { + oslThreadIdentifier* pId = new oslThreadIdentifier; + *pId = getIdentifier(); + idData.setData(pId); + oslThreadIdentifier* pIdData = (oslThreadIdentifier*)idData.getData(); + //t_print("Thread %d has Data %d\n", getIdentifier(), *pIdData); + m_Id = *pIdData; + delete pId; + } + +public: + ~idThread() + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } +}; + +namespace osl_ThreadData +{ + + class ctors : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + /** 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_MESSAGE( + "ThreadData setData: ", + aThread1.m_Id == aThreadId1 && aThread2.m_Id == aThreadId2 + ); + + } + + void setData_002() + { + // at first, set the data a value + char* pc = new char[2]; + char m_nData = 'm'; +// LLA: this is a copy functions only and really only for \0 terminated strings +// m_nData is not a string, it's a character +// strcpy(pc, &m_nData); + memcpy(pc, &m_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, check current data, not 'a' 'b' + char* pChar = (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_MESSAGE( + "ThreadData setData: ", + cData1 == 'a' && cData2 == 'b' && aChar == 'm' + ); + + } + /** setData the second time, and then getData + */ + void setData_003() + { + // at first, set the data a value + char* pc = new char[2]; + char m_nData = 'm'; +// strcpy(pc, &m_nData); + memcpy(pc, &m_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]; + m_nData = 'o'; +// strcpy(pc2, &m_nData); + memcpy(pc2, &m_nData, 1); + pc2[1] = '\0'; + + myThreadData.setData(pc2); + char* pChar = (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_MESSAGE( + "ThreadData setData: ", + cData1 == 'a' && cData2 == 'b' && aChar == 'o' + ); + + } + + CPPUNIT_TEST_SUITE(setData); + CPPUNIT_TEST(setData_001); + CPPUNIT_TEST(setData_002); + CPPUNIT_TEST(setData_003); + CPPUNIT_TEST_SUITE_END(); + }; // class setData + + //sal_Bool buildTwoThreads(char) + + class getData : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // After setData in child threads, get Data in the main thread, should be independent + void getData_001() + { + char* pc = new char[2]; + char m_nData[] = "i"; + strcpy(pc, m_nData); + t_print("pc %s\n", pc); + 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 = (char*)myThreadData.getData(); + char aChar = *pChar; + + CPPUNIT_ASSERT_MESSAGE( + "ThreadData setData: ", + cData1 == 'c' && cData2 == 'd' && aChar == 'i' + ); + + } + + // 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 m_nData = 'i'; +// strcpy(pc, &m_nData); + memcpy(pc, &m_nData, 1); + pc[1] = '\0'; +// strncpy(pc, &m_nData, sizeof(char); + + t_print("pc %s\n", pc); + myThreadData.setData(pc); + + myKeyThread aThread1('a'); + aThread1.create(); + myKeyThread aThread2('b'); + aThread2.create(); + + // change the value which pc points + char m_nData2 = 'j'; + // strcpy(pc, &m_nData2); + memcpy(pc, &m_nData2, 1); + pc[1] = '\0'; + + //t_print("pc %s\n", pc); + void* pChar = myThreadData.getData(); + char aChar = *(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' && aChar == 'j' + ); + + } + + CPPUNIT_TEST_SUITE(getData); + CPPUNIT_TEST(getData_001); + CPPUNIT_TEST(getData_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getData + +// ----------------------------------------------------------------------------- + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ThreadData::ctors, "osl_ThreadData"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ThreadData::setData, "osl_ThreadData"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ThreadData::getData, "osl_ThreadData"); +} // namespace osl_ThreadData + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/osl/process/osl_Thread.xsce b/sal/qa/osl/process/osl_Thread.xsce new file mode 100644 index 000000000000..42d9ef269178 --- /dev/null +++ b/sal/qa/osl/process/osl_Thread.xsce @@ -0,0 +1 @@ +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 000000000000..a0fe5182daa1 --- /dev/null +++ b/sal/qa/osl/process/osl_process.cxx @@ -0,0 +1,687 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_process.cxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <testshl/simpleheader.hxx> +#include <osl/process.h> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <rtl/ustring.hxx> +#include <unistd.h> +#include <signal.h> + +#include <stdio.h> +#include <stdlib.h> +#include <osl/module.hxx> + +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +# define WIN32_LEAN_AND_MEAN +// # include <windows.h> +# include <tchar.h> +#include <tools/postwin.h> +#endif + +#include "rtl/allocator.hxx" + +#include <iostream> +#include <fstream> +#include <vector> +#include <algorithm> +#include <iterator> +#include <string> + +#if defined(WNT) || defined(OS2) + const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("osl_process_child.exe"); +#else + const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("osl_process_child"); +#endif + + +//######################################## +std::string OUString_to_std_string(const rtl::OUString& oustr) +{ + rtl::OString ostr = rtl::OUStringToOString(oustr, osl_getThreadTextEncoding()); + return std::string(ostr.getStr()); +} + +//######################################## +using namespace osl; +using namespace rtl; + +/** print a UNI_CODE String. +*/ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printUString_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +/** get binary Path. +*/ +inline ::rtl::OUString getExecutablePath( void ) +{ + ::rtl::OUString dirPath; + osl::Module::getUrlFromAddress( ( void* ) &getExecutablePath, dirPath ); + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') ); + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1); + dirPath += rtl::OUString::createFromAscii("bin"); + return dirPath; +} + +//rtl::OUString CWD = getExecutablePath(); + +//######################################## +class Test_osl_joinProcess : public CppUnit::TestFixture +{ + const OUString join_param_; + const OUString wait_time_; + OUString suCWD; + OUString suExecutableFileURL; + + rtl_uString* parameters_[2]; + int parameters_count_; + +public: + + Test_osl_joinProcess() : + join_param_(OUString::createFromAscii("-join")), + wait_time_(OUString::createFromAscii("1")), + parameters_count_(2) + { + parameters_[0] = join_param_.pData; + parameters_[1] = wait_time_.pData; + suCWD = getExecutablePath(); + suExecutableFileURL = suCWD; + suExecutableFileURL += rtl::OUString::createFromAscii("/"); + suExecutableFileURL += EXECUTABLE_NAME; + } + + /*------------------------------------- + Start a process and join with this + process specify a timeout so that + osl_joinProcessWithTimeout returns + osl_Process_E_TimedOut + -------------------------------------*/ + + void osl_joinProcessWithTimeout_timeout_failure() + { + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + TimeValue timeout; + timeout.Seconds = 1; + timeout.Nanosec = 0; + + osl_error = osl_joinProcessWithTimeout(process, &timeout); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcessWithTimeout returned without timeout failure", + osl_Process_E_TimedOut == osl_error + ); + + osl_error = osl_terminateProcess(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_terminateProcess failed", + osl_error == osl_Process_E_None + ); + + osl_freeProcessHandle(process); + } + + /*------------------------------------- + Start a process and join with this + process specify a timeout so that + osl_joinProcessWithTimeout returns + osl_Process_E_None + -------------------------------------*/ + + void osl_joinProcessWithTimeout_without_timeout_failure() + { + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + TimeValue timeout; + timeout.Seconds = 10; + timeout.Nanosec = 0; + + osl_error = osl_joinProcessWithTimeout(process, &timeout); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcessWithTimeout returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + } + + /*------------------------------------- + Start a process and join with this + process specify an infinite timeout + -------------------------------------*/ + + void osl_joinProcessWithTimeout_infinite() + { + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + osl_error = osl_joinProcessWithTimeout(process, NULL); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcessWithTimeout returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + } + + /*------------------------------------- + Start a process and join with this + process using osl_joinProcess + -------------------------------------*/ + + void osl_joinProcess() + { + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + suExecutableFileURL.pData, + parameters_, + parameters_count_, + osl_Process_NORMAL, + osl_getCurrentSecurity(), + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + } + + CPPUNIT_TEST_SUITE(Test_osl_joinProcess); + CPPUNIT_TEST(osl_joinProcessWithTimeout_timeout_failure); + CPPUNIT_TEST(osl_joinProcessWithTimeout_without_timeout_failure); + CPPUNIT_TEST(osl_joinProcessWithTimeout_infinite); + CPPUNIT_TEST(osl_joinProcess); + CPPUNIT_TEST_SUITE_END(); +}; + +//######################################################### + +typedef std::vector<std::string, rtl::Allocator<std::string> > string_container_t; +typedef string_container_t::const_iterator string_container_const_iter_t; +typedef string_container_t::iterator string_container_iter_t; + +//######################################################### +class exclude : public std::unary_function<std::string, bool> +{ +public: + //------------------------------------------------ + exclude(const string_container_t& exclude_list) + { + string_container_const_iter_t iter = exclude_list.begin(); + string_container_const_iter_t iter_end = exclude_list.end(); + for (/**/; iter != iter_end; ++iter) + exclude_list_.push_back(env_var_name(*iter)); + } + + //------------------------------------------------ + bool operator() (const std::string& 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" + std::string env_var_name(const std::string& env_var) const + { + std::string::size_type pos_equal_sign = + env_var.find_first_of("="); + + if (std::string::npos != pos_equal_sign) + return std::string(env_var, 0, pos_equal_sign); + + return std::string(); + } + +private: + string_container_t exclude_list_; +}; + +#ifdef WNT + void read_parent_environment(string_container_t* env_container) + { + LPTSTR env = reinterpret_cast<LPTSTR>(GetEnvironmentStrings()); + LPTSTR p = env; + + while (size_t l = _tcslen(p)) + { + env_container->push_back(std::string(p)); + p += l + 1; + } + FreeEnvironmentStrings(env); + } +#else + extern char** environ; + void read_parent_environment(string_container_t* env_container) + { + for (int i = 0; NULL != environ[i]; i++) + env_container->push_back(std::string(environ[i])); + } +#endif + +//######################################################### +class Test_osl_executeProcess : public CppUnit::TestFixture +{ + const OUString env_param_; + + OUString temp_file_path_; + rtl_uString* parameters_[2]; + int parameters_count_; + OUString suCWD; + OUString suExecutableFileURL; + +public: + + //------------------------------------------------ + // ctor + Test_osl_executeProcess() : + env_param_(OUString::createFromAscii("-env")), + parameters_count_(2) + { + parameters_[0] = env_param_.pData; + suCWD = getExecutablePath(); + suExecutableFileURL = suCWD; + suExecutableFileURL += rtl::OUString::createFromAscii("/"); + suExecutableFileURL += EXECUTABLE_NAME; + } + + //------------------------------------------------ + virtual void setUp() + { + temp_file_path_ = create_temp_file(); + parameters_[1] = temp_file_path_.pData; + } + + //------------------------------------------------ + OUString create_temp_file() + { + OUString temp_file_url; + FileBase::RC rc = FileBase::createTempFile(0, 0, &temp_file_url); + CPPUNIT_ASSERT_MESSAGE("createTempFile failed", FileBase::E_None == rc); + + OUString temp_file_path; + rc = FileBase::getSystemPathFromFileURL(temp_file_url, temp_file_path); + CPPUNIT_ASSERT_MESSAGE("getSystemPathFromFileURL failed", FileBase::E_None == rc); + + return temp_file_path; + } + + //------------------------------------------------ + void read_child_environment(string_container_t* 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; + while (std::getline(file, line)) + env_container->push_back(line); + } + + //------------------------------------------------ + void dump_env(const string_container_t& env, OUString file_name) + { + OString fname = OUStringToOString(file_name, osl_getThreadTextEncoding()); + std::ofstream file(fname.getStr()); + std::ostream_iterator<std::string> oi(file, "\n"); + std::copy(env.begin(), env.end(), oi); + } + + //------------------------------------------------ + // environment of the child process that was + // started. The child process writes his + // environment into a file + bool compare_environments() + { + string_container_t parent_env; + read_parent_environment(&parent_env); + + string_container_t child_env; + read_child_environment(&child_env); + + return ((parent_env.size() == child_env.size()) && + (std::equal(child_env.begin(), child_env.end(), parent_env.begin()))); + } + + //------------------------------------------------ + // compare the equal environment parts and the + // different part of the child environment + bool compare_merged_environments(const string_container_t& different_env_vars) + { + string_container_t parent_env; + read_parent_environment(&parent_env); + + //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()); + + //read the child environment and exclude the variables that + //are different + string_container_t child_env; + read_child_environment(&child_env); + + //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 + string_container_iter_t iter_logical_end = + std::stable_partition(child_env.begin(), child_env.end(), exclude(different_env_vars)); + + string_container_t different_child_env_vars(child_env.begin(), iter_logical_end); + child_env.erase(child_env.begin(), iter_logical_end); + + 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()); + + 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 with out 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, + NULL, + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "Parent an child environment not equal", + 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 = OUString::createFromAscii(ENV1); + OUString env2 = OUString::createFromAscii(ENV2); + OUString env3 = OUString::createFromAscii(ENV3); + OUString env4 = OUString::createFromAscii(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, + NULL, + suCWD.pData, + child_env, + sizeof(child_env)/sizeof(child_env[0]), + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + + string_container_t 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) + ); + } + + void osl_execProc_test_batch() + { + oslProcess process; + rtl::OUString suBatch = suCWD + rtl::OUString::createFromAscii("/") + rtl::OUString::createFromAscii("batch.bat"); + oslProcessError osl_error = osl_executeProcess( + suBatch.pData, + NULL, + 0, + osl_Process_NORMAL, + NULL, + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + } + + void osl_execProc_exe_name_in_argument_list() + { + rtl_uString* params[3]; + + params[0] = suExecutableFileURL.pData; + params[1] = env_param_.pData; + params[2] = temp_file_path_.pData; + oslProcess process; + oslProcessError osl_error = osl_executeProcess( + NULL, + params, + 3, + osl_Process_NORMAL, + NULL, + suCWD.pData, + NULL, + 0, + &process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + + osl_error = ::osl_joinProcess(process); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_joinProcess returned with failure", + osl_Process_E_None == osl_error + ); + + osl_freeProcessHandle(process); + } + + CPPUNIT_TEST_SUITE(Test_osl_executeProcess); + CPPUNIT_TEST(osl_execProc_parent_equals_child_environment); + CPPUNIT_TEST(osl_execProc_merged_child_environment); + CPPUNIT_TEST(osl_execProc_test_batch); + CPPUNIT_TEST(osl_execProc_exe_name_in_argument_list); + CPPUNIT_TEST_SUITE_END(); +}; + +//##################################### +// register test suites +//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_joinProcess, "Test_osl_joinProcess"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_executeProcess, "Test_osl_executeProcess"); + +NOADDITIONAL; + 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 000000000000..e5293bba759e --- /dev/null +++ b/sal/qa/osl/process/osl_process_child.cxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_process_child.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//######################################## +// includes + +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +# define UNICODE +# define _UNICODE +# define WIN32_LEAN_AND_MEAN +// # include <windows.h> +# include <tchar.h> +#include <tools/postwin.h> +#else +# include <unistd.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +#include <fstream> + +#include <rtl/ustring.hxx> + +//######################################## +// defines + +#ifdef WNT +# define SLEEP(t) (Sleep((t)*1000)) +#else +# define SLEEP(t) (sleep((t))) +#endif + +//######################################## +void wait_for_seconds(char* time) +{ + SLEEP(atoi(time)); +} + +//######################################## + +#ifdef WNT +//######################################## +void w_to_a(LPCTSTR _strW, LPSTR strA, DWORD size) +{ + LPCWSTR strW = reinterpret_cast<LPCWSTR>(_strW); + WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, NULL, NULL); +} +//######################################## + void dump_env(char* file_path) + { + LPTSTR env = reinterpret_cast<LPTSTR>( + GetEnvironmentStrings()); + LPTSTR p = env; + + std::ofstream file(file_path); + + char buffer[32767]; + while (size_t l = _tcslen(reinterpret_cast<wchar_t*>(p))) + { + w_to_a(p, buffer, sizeof(buffer)); + file << buffer << std::endl; + p += l + 1; + } + FreeEnvironmentStrings(env); + } +#else + extern char** environ; + + void dump_env(char* file_path) + { + std::ofstream file(file_path); + for (int i = 0; NULL != environ[i]; i++) + file << environ[i] << std::endl; + } +#endif + +//######################################## +int main(int argc, char* argv[]) +{ + rtl::OUString s; + + //t_print("Parameter: "); + printf("child process Parameter: "); + for (int i = 1; i < argc; i++) + printf("%s ", argv[i]); + printf("\n"); + + if (argc > 2) + { + if (0 == strcmp("-join", argv[1])) + { + wait_for_seconds(argv[2]); + } + else if (0 == strcmp("-env", argv[1])) + { + dump_env(argv[2]); + } + } + + return (0); +} + diff --git a/sal/qa/osl/profile/makefile.mk b/sal/qa/osl/profile/makefile.mk new file mode 100644 index 000000000000..482bc69276a2 --- /dev/null +++ b/sal/qa/osl/profile/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_profile +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +SHL1OBJS= \ + $(SLO)$/osl_old_testprofile.obj + +SHL1TARGET= osl_old_testprofile +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ + + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=\ + $(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + + 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 000000000000..27e4cbe6b35b --- /dev/null +++ b/sal/qa/osl/profile/osl_old_testprofile.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_old_testprofile.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + + +// ----------------------------------------------------------------------------- +#include <stdio.h> +#include <osl/profile.h> + +#include <testshl/simpleheader.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(void) +{ + oslProfile hProfile; + rtl_uString* ustrProfileName=0; + rtl_uString* ustrProfileName2=0; + + rtl_uString_newFromAscii(&ustrProfileName,"//./tmp/soffice.ini"); + rtl_uString_newFromAscii(&ustrProfileName2,"//./tmp/not_existing_path/soffice.ini"); + + + // successful write + if (hProfile = osl_openProfile( ustrProfileName, 0 )) + { + if (! osl_writeProfileBool( hProfile, "testsection", "testbool", 1 )) + printf( "### cannot write into init file!\n" ); + + osl_closeProfile( hProfile ); + } + + // unsuccessful write + if (hProfile = osl_openProfile( ustrProfileName2, 0 )) + { + if (osl_writeProfileBool( hProfile, "testsection", "testbool", 1 )) + printf( "### unexpected success writing into test2.ini!\n" ); + + osl_closeProfile( hProfile ); + } + + rtl_uString_release(ustrProfileName); + rtl_uString_release(ustrProfileName2); +} + +} // namespace osl_Profile + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Profile::oldtests, "osl_Profile" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; diff --git a/sal/qa/osl/security/makefile.mk b/sal/qa/osl/security/makefile.mk new file mode 100755 index 000000000000..6bcc6fc9f6d3 --- /dev/null +++ b/sal/qa/osl/security/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.11 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_security + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Security by codegen.pl +SHL1OBJS= \ + $(SLO)$/osl_Security.obj + +SHL1TARGET= osl_Security +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +.IF "$(GUI)" == "WNT" +SHL1STDLIBS+= $(ADVAPI32LIB) +.ENDIF + +SHL1IMPLIB= i$(SHL1TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:Security +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/security/osl_Security.cxx b/sal/qa/osl/security/osl_Security.cxx new file mode 100755 index 000000000000..07dbdb0d44d0 --- /dev/null +++ b/sal/qa/osl/security/osl_Security.cxx @@ -0,0 +1,681 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Security.cxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// header file +//------------------------------------------------------------------------ +#include <osl_Security_Const.h> + +using namespace osl; +using namespace rtl; + + +//------------------------------------------------------------------------ +// helper functions and classes +//------------------------------------------------------------------------ + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + //t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("TRUE!\n" ): t_print("FALSE!\n" ); +} + +/** print a UNI_CODE String. +*/ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + //t_print("#printUString_u# " ); + aString = ::rtl::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: + sal_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( ) != NULL ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class ctors + + + /** testing the methods: + inline sal_Bool SAL_CALL logonUser(const ::rtl::OUString& strName, + const ::rtl::OUString& strPasswd); + inline sal_Bool SAL_CALL logonUser(const ::rtl::OUString & strName, + const ::rtl::OUString & strPasswd, + const ::rtl::OUString & strFileServer); + */ + class logonUser : public CppUnit::TestFixture + { + public: + sal_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).", + ( sal_True == 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).", + ( sal_True == bRes ) ); + } + + + CPPUNIT_TEST_SUITE( logonUser ); + if ( !aStringForward.equals( aNullURL ) && aStringForward.indexOf( (sal_Unicode)' ' ) != -1 && ( aStringForward.indexOf( ( sal_Unicode ) ' ' ) == aStringForward.lastIndexOf( ( sal_Unicode ) ' ' ) ) ) + /// if user name and passwd are forwarded + { + CPPUNIT_TEST( logonUser_user_pwd ); + } + if ( !aStringForward.equals( aNullURL ) && aStringForward.indexOf( (sal_Unicode)' ' ) != -1 && ( aStringForward.indexOf( ( sal_Unicode ) ' ' ) != aStringForward.lastIndexOf( ( sal_Unicode ) ' ' ) ) ) + /// 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( rtl::OUString& strIdent) const + */ + class getUserIdent : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getUserIdent_001( ) + { + ::osl::Security aSec; + ::rtl::OUString strID; + bRes = aSec.getUserIdent( strID ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: get UserID and compare it with names got at the beginning of the test.", + ( sal_True == strUserID.equals( strID ) ) && ( sal_True == bRes )); + } + + CPPUNIT_TEST_SUITE( getUserIdent ); + CPPUNIT_TEST( getUserIdent_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getUserIdent + + + /** testing the method: + inline sal_Bool SAL_CALL getUserName( ::rtl::OUString& strName) const; + */ + class getUserName : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getUserName_001( ) + { + ::osl::Security aSec; +#ifdef WNT + ::rtl::OUString strName( strUserName ), strGetName; +#else + ::rtl::OUString strName( strUserName ), strGetName; +#endif + bRes = aSec.getUserName( strGetName ); + + sal_Int32 nPos = -1; + if (strName.getLength() > 0) + { + 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 ) && ( sal_True == bRes ) ); + } + + CPPUNIT_TEST_SUITE( getUserName ); + CPPUNIT_TEST( getUserName_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getUserName + + + + /** testing the method: + inline sal_Bool SAL_CALL getHomeDir( ::rtl::OUString& strDirectory) const; + */ + class getHomeDir : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getHomeDir_001( ) + { + ::osl::Security aSec; + ::rtl::OUString strHome; + bRes = aSec.getHomeDir( strHome ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: getHomeDir and compare it with the info we get at the beginning.", + ( sal_True == strHomeDirectory.equals( strHome ) ) && ( sal_True == bRes ) ); + } + + CPPUNIT_TEST_SUITE( getHomeDir ); + CPPUNIT_TEST( getHomeDir_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class getHomeDir + + /** testing the method: + inline sal_Bool Security::getConfigDir( rtl::OUString& strDirectory ) const + */ + class getConfigDir : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void getConfigDir_001( ) + { + ::osl::Security aSec; + ::rtl::OUString strConfig; + bRes = aSec.getConfigDir( strConfig ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: getHomeDir and compare it with the info we get at the beginning.", + ( sal_True == strConfigDirectory.equals( strConfig ) ) && ( sal_True == 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: + sal_Bool bRes; + + void isAdministrator_001( ) + { + ::osl::Security aSec; + bRes = aSec.isAdministrator( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: check if the user is administrator at beginning, compare here.", + bRes == isAdmin ); + } + + 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: + sal_Bool bRes; + + void getHandle_001( ) + { + ::osl::Security aSec; + bRes = aSec.isAdministrator( ) == osl_isAdministrator( aSec.getHandle( ) ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: use getHandle function to call C API.", + bRes == sal_True ); + } + + 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; + sal_Bool bValue = osl_loadUserProfile(aSec.getHandle()); + + CPPUNIT_ASSERT_MESSAGE( "empty function.", bValue == sal_False ); + } + + void unloadUserProfile( ) + { + ::osl::Security aSec; + osl_unloadUserProfile(aSec.getHandle()); + CPPUNIT_ASSERT_MESSAGE( "empty function.", sal_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( ) + { + rtl::OUString suUserName; + rtl::OUString suPassword; + rtl::OUString suFileServer; + ::osl::Security aSec; + oslSecurity pSec = aSec.getHandle(); + + oslSecurityError erg = osl_loginUserOnFileServer(suUserName.pData, suPassword.pData, suFileServer.pData, &pSec); + + CPPUNIT_ASSERT_MESSAGE( "empty function.", erg == osl_Security_E_UserUnknown ); + } + + CPPUNIT_TEST_SUITE( loginUserOnFileServer ); + CPPUNIT_TEST( loginUserOnFileServer_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class loginUserOnFileServer + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::ctors, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::logonUser, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::getUserIdent, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::getUserName, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::getHomeDir, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::getConfigDir, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::isAdministrator, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::getHandle, "osl_Security"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::UserProfile, "osl_Security"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Security::loginUserOnFileServer, "osl_Security"); + +// ----------------------------------------------------------------------------- + +} // namespace osl_Security + + +// ----------------------------------------------------------------------------- + +// 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. + +/** to do some initialized work, we replace the NOADDITIONAL macro with the initialize work which + get current user name, . +*/ + +void RegisterAdditionalFunctions(FktRegFuncPtr) +{ + /// 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 excute:\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 ) || ( defined OS2 ) + /// some initialization work for UNIX OS + + + struct passwd* pw; + CPPUNIT_ASSERT_MESSAGE( "getpwuid: no password entry\n",( pw = getpwuid( getuid() ) ) != NULL ); + + /// get user ID; + strUserID = ::rtl::OUString::valueOf( ( sal_Int32 )getuid( ) ); + + /// get user Name; + strUserName = ::rtl::OUString::createFromAscii( pw->pw_name ); + + /// get home directory; + CPPUNIT_ASSERT_MESSAGE( "#Convert from system path to URL failed.", + ::osl::File::E_None == ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( pw->pw_dir ), strHomeDirectory ) ); + + /// get config directory; + strConfigDirectory = strHomeDirectory.copy(0); + + /// is administrator; + if( !getuid( ) ) + isAdmin = sal_True; + +#endif +#if defined ( WNT ) + /// some initialization work for Windows OS + + + /// Get the user name, computer name, user home directory. + LPTSTR lpszSystemInfo; // pointer to system information string + DWORD cchBuff = BUFSIZE; // size of computer or user name + TCHAR tchBuffer[BUFSIZE]; // buffer for string + + lpszSystemInfo = tchBuffer; + cchBuff = BUFSIZE; + if( GetUserNameA(lpszSystemInfo, &cchBuff) ) + strUserName = ::rtl::OUString::createFromAscii( lpszSystemInfo ); + + if( GetComputerName(lpszSystemInfo, &cchBuff) ) + strComputerName = ::rtl::OUString::createFromAscii( lpszSystemInfo ); + + /// Get user home directory. + HKEY hRegKey; + sal_Char PathA[_MAX_PATH]; + ::rtl::OUString strHome; + if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS) + { + LONG lRet, lSize = sizeof(PathA); + DWORD Type; + + lRet = RegQueryValueEx(hRegKey, "AppData", NULL, &Type, ( unsigned char * )PathA, ( unsigned long * )&lSize); + if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _access( PathA, 0 ) == 0 ) ) + { + CPPUNIT_ASSERT_MESSAGE( "#Convert from system path to URL failed.", + ::osl::File::E_None == ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( PathA ), strConfigDirectory ) ); + } + + lRet = RegQueryValueEx(hRegKey, "Personal", NULL, &Type, ( unsigned char * )PathA, ( unsigned long * )&lSize); + if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _access( PathA, 0 ) == 0 ) ) + { + CPPUNIT_ASSERT_MESSAGE( "#Convert from system path to URL failed.", + ::osl::File::E_None == ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( PathA ), 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 = NULL; + SID_NAME_USE eSidType; + DWORD dwErrorCode = 0; + + LPCWSTR wszAccName = ( LPWSTR ) strUserName.getStr( ); + + // Create buffers for the SID and the domain name. + PSID pSid = (PSID) new WIN_BYTE[dwSidBufferSize]; + CPPUNIT_ASSERT_MESSAGE("# creating SID buffer failed.\n", pSid!= NULL ); + memset( pSid, 0, dwSidBufferSize); + + wszDomainName = new WCHAR[dwDomainBufferSize]; + CPPUNIT_ASSERT_MESSAGE("# creating Domain name buffer failed.\n", wszDomainName != NULL ); + 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( + NULL, // 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 (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"); + FreeSid( pSid); + pSid = (PSID) new WIN_BYTE[cbSid]; + CPPUNIT_ASSERT_MESSAGE("# re-creating SID buffer failed.\n", pSid!= NULL ); + 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]; + CPPUNIT_ASSERT_MESSAGE("# re-creating domain name buffer failed.\n", wszDomainName!= NULL ); + memset(wszDomainName, 0, cchDomainName*sizeof(WCHAR)); + dwDomainBufferSize = cchDomainName; + } + } + else + { + wprintf(L"# LookupAccountNameW failed. GetLastError returned: %d\n", dwErrorCode); + break; + } + } + + // now got SID successfully, only need to compare SID, so I copied the rest lines from source to convert SID to OUString. + PSID_IDENTIFIER_AUTHORITY psia; + DWORD dwSubAuthorities; + DWORD dwSidRev=SID_REVISION; + DWORD dwCounter; + DWORD dwSidSize; + sal_Char *Ident; + + /* obtain SidIdentifierAuthority */ + psia=GetSidIdentifierAuthority(pSid); + + /* obtain sidsubauthority count */ + dwSubAuthorities=*GetSidSubAuthorityCount(pSid)<=5?*GetSidSubAuthorityCount(pSid):5; + + /* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */ + Ident=(sal_Char * )malloc(88*sizeof(sal_Char)); + + /* prepare S-SID_REVISION- */ + dwSidSize=wsprintf(Ident, TEXT("S-%lu-"), dwSidRev); + + /* prepare SidIdentifierAuthority */ + if ((psia->Value[0] != 0) || (psia->Value[1] != 0)) + { + dwSidSize+=wsprintf(Ident + strlen(Ident), + TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"), + (USHORT)psia->Value[0], + (USHORT)psia->Value[1], + (USHORT)psia->Value[2], + (USHORT)psia->Value[3], + (USHORT)psia->Value[4], + (USHORT)psia->Value[5]); + } + else + { + dwSidSize+=wsprintf(Ident + strlen(Ident), + TEXT("%lu"), + (ULONG)(psia->Value[5] ) + + (ULONG)(psia->Value[4] << 8) + + (ULONG)(psia->Value[3] << 16) + + (ULONG)(psia->Value[2] << 24) ); + } + + /* loop through SidSubAuthorities */ + for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++) + { + dwSidSize+=wsprintf(Ident + dwSidSize, TEXT("-%lu"), + *GetSidSubAuthority(pSid, dwCounter) ); + } + + strUserID = ::rtl::OUString::createFromAscii( Ident ); + + free(Ident); + delete pSid; + delete [] wszDomainName; + + + /// check if logged in user is administrator: + + WIN_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( NULL, AdministratorsGroup, &b)) + { + b = FALSE; + } + FreeSid(AdministratorsGroup); + } + + isAdmin = ( sal_Bool )b; + +#endif + + /// print the information. + t_print("#\n#Retrived system information is below:\n"); + + t_print("Computer Name: "); + if ( strComputerName == aNullURL ) + t_print(" Not retrived\n" ); + else + printUString( strComputerName ); + + t_print("Current User Name: "); + if ( strUserName == aNullURL ) + t_print(" Not retrived\n" ); + else + printUString( strUserName ); + + t_print("Current User Home Directory:"); + if ( strHomeDirectory == aNullURL ) + t_print(" Not retrived\n" ); + else + printUString( strHomeDirectory ); + + t_print("Current Config Directory: "); + if ( strConfigDirectory == aNullURL ) + t_print(" Not retrived\n" ); + else + printUString( strConfigDirectory ); + + t_print("Current UserID: "); + if ( strUserID == aNullURL ) + t_print(" Not retrived\n" ); + else + printUString( strUserID ); + + t_print("Current User is"); + if ( isAdmin == sal_False ) + t_print(" NOT Administrator.\n" ); + else + t_print(" Administrator.\n" ); + + + /// get and display forwarded text if available. + aStringForward = ::rtl::OUString::createFromAscii( getForwardString() ); + if ( !aStringForward.equals( aNullURL ) && aStringForward.indexOf( (sal_Unicode)' ' ) != -1 ) + { + sal_Int32 nFirstSpacePoint = aStringForward.indexOf( (sal_Unicode)' ' );; + sal_Int32 nLastSpacePoint = aStringForward.lastIndexOf( (sal_Unicode)' ' );; + if ( nFirstSpacePoint == nLastSpacePoint ) + /// only forwarded two parameters, username and password. + { + aLogonUser = aStringForward.copy( 0, nFirstSpacePoint ); + t_print("\n#Forwarded username: "); + printUString( aLogonUser); + + aLogonPasswd = aStringForward.copy( nFirstSpacePoint +1, aStringForward.getLength( ) - 1 ); + t_print("#Forwarded password: "); + for ( int i = nFirstSpacePoint +1; i <= aStringForward.getLength( ) - 1; i++, t_print("*") ); + t_print("\n" ); + } + else + /// forwarded three parameters, username, password and fileserver. + { + aLogonUser = aStringForward.copy( 0, nFirstSpacePoint ); + t_print("#Forwarded username: "); + printUString( aLogonUser); + + aLogonPasswd = aStringForward.copy( nFirstSpacePoint +1, nLastSpacePoint ); + t_print("#Forwarded password: "); + for ( int i = nFirstSpacePoint +1; i <= nLastSpacePoint; i++, t_print("*") ); + t_print("\n" ); + + aFileServer = aStringForward.copy( nLastSpacePoint +1, aStringForward.getLength( ) - 1 ); + t_print("#Forwarded FileServer: "); + printUString( aFileServer ); + + } + } + + t_print("#\n#Initialization Done.\n" ); + +} diff --git a/sal/qa/osl/security/osl_Security_Const.h b/sal/qa/osl/security/osl_Security_Const.h new file mode 100755 index 000000000000..ca08e3025b38 --- /dev/null +++ b/sal/qa/osl/security/osl_Security_Const.h @@ -0,0 +1,83 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Security_Const.h,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_SECURITY_CONST_H_ +#define _OSL_SECURITY_CONST_H_ + +#if ( defined WNT ) // Windows +//#define UNICODE +#include <tools/prewin.h> +// #include <windows.h> +#include <io.h> +#include <tools/postwin.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 ) || ( defined OS2 ) +#include <unistd.h> +#include <pwd.h> +#endif + +#include <testshl/simpleheader.hxx> +// LLA: #include <testshl2/cmdlinebits.hxx> + + +#define BUFSIZE 1024 +const char pTestString[17] = "Sun Microsystems"; + + +#define OSLTEST_DECLARE_USTRING( str_name, str_value ) \ + ::rtl::OUString a##str_name = rtl::OUString::createFromAscii( str_value ) + +//------------------------------------------------------------------------ +// condition names +//------------------------------------------------------------------------ +OSLTEST_DECLARE_USTRING( TestSec, "testsecurity" ); +OSLTEST_DECLARE_USTRING( NullURL, "" ); + +::rtl::OUString aLogonUser( aNullURL ), aLogonPasswd( aNullURL ), aFileServer( aNullURL ), aStringForward( aNullURL ); +::rtl::OUString strUserName( aNullURL ) , strComputerName( aNullURL ) , strHomeDirectory( aNullURL ); +::rtl::OUString strConfigDirectory( aNullURL ), strUserID( aNullURL ); + +sal_Bool isAdmin = sal_False; + +#endif /* _OSL_SECURITY_CONST_H_ */ diff --git a/sal/qa/osl/semaphore/makefile.mk b/sal/qa/osl/semaphore/makefile.mk new file mode 100644 index 000000000000..a8918dcfb12b --- /dev/null +++ b/sal/qa/osl/semaphore/makefile.mk @@ -0,0 +1,65 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_semaphore + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Semaphore by codegen.pl +SHL1OBJS= \ + $(SLO)$/osl_Semaphore.obj + +SHL1TARGET= osl_Semaphore +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# auto generated Target:Semaphore +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/semaphore/osl_Semaphore.cxx b/sal/qa/osl/semaphore/osl_Semaphore.cxx new file mode 100644 index 000000000000..5769c0b52a86 --- /dev/null +++ b/sal/qa/osl/semaphore/osl_Semaphore.cxx @@ -0,0 +1,528 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Semaphore.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <osl_Semaphore_Const.h> + +using namespace osl; +using namespace rtl; + + +//------------------------------------------------------------------------ +// helper functions and classes +//------------------------------------------------------------------------ + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("YES!\n" ): t_print("NO!\n" ); +} + +/** print a UNI_CODE String. +*/ +inline void printUString( const ::rtl::OUString & str ) +{ + rtl::OString aString; + + t_print("#printUString_u# " ); + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", aString.getStr( ) ); +} + +/** wait _nSec seconds. +*/ +void thread_sleep( sal_Int32 _nSec ) +{ + /// print statement in thread process must use fflush() to force display. + // t_print("wait %d seconds. ", _nSec ); + // fflush( stdout ); + +#ifdef WNT //Windows + Sleep( _nSec * 1000 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + sleep( _nSec ); +#endif +} + + void thread_sleep_tenth_sec(sal_Int32 _nTenthSec) + { +#ifdef WNT //Windows + Sleep(_nTenthSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + TimeValue nTV; + nTV.Seconds = static_cast<sal_uInt32>( _nTenthSec/10 ); + nTV.Nanosec = ( (_nTenthSec%10 ) * 100000000 ); + osl_waitThread(&nTV); +#endif +} + +/** thread for testing Semaphore acquire. + */ +class HoldThread : public Thread +{ +public: + //get the Semaphores to operate + HoldThread( ::osl::Semaphore& Sem ): MySem( Sem ) { } + + ~HoldThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "#HoldThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + ::osl::Semaphore& MySem; + + void SAL_CALL run() + { + // block here if it tries to decrease below zero. + MySem.acquire( ); + t_print("Semaphore acquired. \n" ); + MySem.release( ); + } +}; + +/** thread for testing Semaphore release and tryToAcquire. + */ +class WaitThread : public Thread +{ +public: + //get the Semaphore pointer to operate + WaitThread( ::osl::Semaphore& Sem ): MySem( Sem ) { } + + ~WaitThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "WaitThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + Semaphore& MySem; + + void SAL_CALL run( ) + { + // block here if the semaphore has been acquired + MySem.acquire( ); + thread_sleep_tenth_sec( 2 ); + MySem.release( ); + } +}; + +/** thread for producer-consumer model. + */ +#define BSIZE 50 +class SemBuffer +{ +public: + sal_Int32 Buf[BSIZE]; + ::osl::Semaphore& aSemOccupied; + ::osl::Semaphore& aSemEmpty; + ::osl::Mutex& aMutex; + + SemBuffer( ::osl::Semaphore& Sem, ::osl::Semaphore& Sem1, ::osl::Mutex& Mut ) + :aSemOccupied( Sem ), aSemEmpty( Sem1 ), aMutex( Mut ) + { + for ( sal_Int8 iCount=0; iCount < BSIZE; iCount++ ) + Buf[iCount] = 0; + } +}; + +class WriterThread : public Thread +{ +public: + //get the Semaphores to operate + WriterThread( SemBuffer& aSemBuffer ): MySemBuffer( aSemBuffer ){ } + + ~WriterThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "WriterThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } +protected: + SemBuffer& MySemBuffer; + + void SAL_CALL run( ) + { + for ( sal_Int32 iCount = 0; iCount < BSIZE; iCount++ ) + { + MySemBuffer.aSemEmpty.acquire( ) ; + MySemBuffer.aMutex.acquire( ) ; + MySemBuffer.Buf[iCount] = iCount; + MySemBuffer.aMutex.release( ) ; + MySemBuffer.aSemOccupied.release( ) ; + } + } +}; + +class ReaderThread : public Thread +{ +public: + //get the Semaphores to operate + ReaderThread( SemBuffer& aSemBuffer ): MySemBuffer( aSemBuffer ){ } + + ~ReaderThread( ) + { + CPPUNIT_ASSERT_MESSAGE( "ReaderThread does not shutdown properly.\n", sal_False == this -> isRunning( ) ); + } + +protected: + SemBuffer& MySemBuffer; + + void SAL_CALL run( ) + { + for ( sal_Int32 iCount = 0; iCount < BSIZE; iCount++ ) + { + MySemBuffer.aSemOccupied.acquire( ) ; + MySemBuffer.aMutex.acquire( ) ; + MySemBuffer.Buf[iCount] *= MySemBuffer.Buf[iCount]; + MySemBuffer.aMutex.release( ) ; + MySemBuffer.aSemEmpty.release( ) ; + } + } +}; + + + +//------------------------------------------------------------------------ +// test code start here +//------------------------------------------------------------------------ + +namespace osl_Semaphore +{ + + /** testing the method: + Semaphore(sal_uInt32 initialCount); + */ + class ctors : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1; + + void ctors_001( ) + { + ::osl::Semaphore aSem(sal_uInt32(0)); + bRes = aSem.tryToAcquire( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create semaphore with initialCount = 0. the first acquire will block.", + sal_False == bRes ); + } + + void ctors_002( ) + { + ::osl::Semaphore aSem(sal_uInt32(1)); + bRes = aSem.tryToAcquire( ); + if ( sal_True == bRes ) + aSem.release( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create semaphore with initialCount = 1. the first acquire will not block.", + sal_True == bRes ); + } + + void ctors_003( ) + { + ::osl::Semaphore aSem(sal_uInt32(1)); + bRes = aSem.tryToAcquire( ); + bRes1 = aSem.tryToAcquire( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create semaphore with initialCount = 1. acquire twice will cause block.", + sal_True == bRes && sal_False == bRes1); + } + + void ctors_004( ) + { + oslSemaphore hSem = new ::osl::Semaphore(sal_uInt32(1)); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test return value of the constructor, it should not be NULL.", + NULL != hSem ); + } + + void ctors_005( ) + { + ::osl::Semaphore aSemaphore(sal_uInt32(2)); + bRes = aSemaphore.tryToAcquire( )&& + aSemaphore.tryToAcquire( )&& + !aSemaphore.tryToAcquire( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: create semaphore with initialCount = 2. guess what behaviour will the semaphore act like.", + sal_True == bRes ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST( ctors_002 ); + CPPUNIT_TEST( ctors_003 ); + CPPUNIT_TEST( ctors_004 ); + CPPUNIT_TEST( ctors_005 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class ctors + + + /** testing the method: + sal_Bool acquire(); + */ + class acquire : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2; + + /** tester comment: + acquire semaphore in main thread, and then call acquire again in myThread, + the child thread should block, wait 2 secs, it still block. Then release + semaphore in main thread, the child thread could return from acquire, and + go to exec next statement, so could terminate quickly. + */ + + void acquire_001( ) + { + // launch the child thread + ::osl::Semaphore aSemaphore(1); + bRes = aSemaphore.acquire( ); + HoldThread myThread( aSemaphore ); + myThread.create( ); + + // if acquire in myThread does not work, 2 secs is long enough, + // myThread should terminate now, and bRes1 should be sal_False + thread_sleep_tenth_sec( 2 ); + bRes1 = myThread.isRunning( ); + + // after release semaphore, myThread stops blocking and will terminate immediately + aSemaphore.release( ); + thread_sleep_tenth_sec( 1 ); + bRes2 = myThread.isRunning( ); + myThread.join( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test acquire of Semaphore.", + bRes == sal_True && bRes1 == sal_True && bRes2 == sal_False ); + } + + /** tester comment: + launch 3 thread for testing acquirement inter-process. + */ + + void acquire_002( ) + { + // launch three child threads + ::osl::Semaphore aSemaphore(1); + bRes = aSemaphore.acquire( ); + HoldThread myThread1( aSemaphore ); + myThread1.create( ); + HoldThread myThread2( aSemaphore ); + myThread2.create( ); + HoldThread myThread3( aSemaphore ); + myThread3.create( ); + + // if acquire in myThread does not work, 2 secs is long enough, + thread_sleep_tenth_sec( 2 ); + bRes1 = myThread1.isRunning( ) && myThread2.isRunning( ) && myThread3.isRunning( ); + + // after release semaphore, myThread stops blocking and will terminate immediately + aSemaphore.release( ); + thread_sleep_tenth_sec( 1 ); + bRes2 = myThread1.isRunning( ) || myThread2.isRunning( ) || myThread3.isRunning( ); + myThread1.join( ); + myThread2.join( ); + myThread3.join( ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test acquire of Semaphore in multithreaded environment.", + bRes == sal_True && bRes1 == sal_True && bRes2 == sal_False ); + } + + + + /** tester comment: + launch 3 thread for testing acquirement inter-process. in this test, + we use two threads as producer and consumer, operate together on an + array which is initialized to 0 for every item. producer takes action + as follow: + p(A), p(M), Buf[i]=i, v(M), v(B). + consumer's action is like: + p(B), p(M), Buf[i]=Buf[i]*Buf[i], v(M), v(A). + consumer must operate on the array after producer does sequetially, + otherwise, the array will contain items remain zero after all threads + terminate. array will be filled with index^2 in the end. + */ + + void acquire_003( ) + { + // initialization. + ::osl::Semaphore aSemOccupied( sal_uInt32(0) ); + ::osl::Semaphore aSemEmpty( BSIZE ); + ::osl::Mutex aMutex; + + // launch two threads. + SemBuffer aBuffer( aSemOccupied, aSemEmpty, aMutex ); + WriterThread myThread1( aBuffer ); + ReaderThread myThread2( aBuffer ); + myThread1.create( ); + myThread2.create( ); + + myThread1.join( ); + myThread2.join( ); + + bRes = sal_True; + for ( sal_Int32 iCount = 0; iCount < BSIZE; iCount++ ) + bRes = bRes && ( aBuffer.Buf[iCount] == iCount*iCount ); + + CPPUNIT_ASSERT_MESSAGE( "#test comment#: test acquire of Semaphore using Producer-Consumer model.", + sal_True == bRes ); + } + + CPPUNIT_TEST_SUITE( acquire ); + CPPUNIT_TEST( acquire_001 ); + CPPUNIT_TEST( acquire_002 ); + CPPUNIT_TEST( acquire_003 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class acquire + + + /** testing the method: + sal_Bool tryToAcquire(); + */ + class tryToAcquire : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2; + /** tester comment: + First let child thread acquire the semaphore, and wait 2 secs, during the 2 secs, + in main thread, tryToAcquire semaphore should return False, then after the + child thread terminated, tryToAcquire should return True + */ + void tryToAcquire_001() + { + ::osl::Semaphore aSemaphore(1); + WaitThread myThread( aSemaphore ); + myThread.create(); + + // ensure the child thread acquire the semaphore + thread_sleep_tenth_sec(1); + bRes1 = aSemaphore.tryToAcquire(); + + if (bRes1 == sal_True) + aSemaphore.release(); + // wait the child thread terminate + myThread.join(); + + bRes2 = aSemaphore.tryToAcquire(); + if (bRes2 == sal_True) + aSemaphore.release(); + + CPPUNIT_ASSERT_MESSAGE("#test comment#: Try to acquire Semaphore", + bRes1 == sal_False && bRes2 == sal_True); + } + + void tryToAcquire_002() + { + ::osl::Semaphore aSem(1); + bRes = aSem.tryToAcquire( ); + bRes1 = aSem.tryToAcquire( ); + + + CPPUNIT_ASSERT_MESSAGE("#test comment#: Try to acquire Semaphore twice should block.", + sal_True == bRes && sal_False == bRes1); + } + + CPPUNIT_TEST_SUITE( tryToAcquire ); + CPPUNIT_TEST( tryToAcquire_001 ); + CPPUNIT_TEST( tryToAcquire_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class tryToAcquire + + + /** testing the method: + sal_Bool release(); + */ + class release : public CppUnit::TestFixture + { + public: + sal_Bool bRes, bRes1, bRes2, bRunning; + sal_Int32 nCount; + /** acquire/release are not used in pairs: after child thread acquired semaphore, + the main thread release it, then any thread could acquire it. + */ + void release_001() + { + Semaphore aSemaphore(1); + WaitThread myThread( aSemaphore ); + myThread.create( ); + + // ensure the child thread acquire the mutex + thread_sleep_tenth_sec( 1 ); + + bRunning = myThread.isRunning( ); + bRes1 = aSemaphore.tryToAcquire( ); + // wait the child thread terminate + myThread.join( ); + + bRes2 = aSemaphore.tryToAcquire( ); + if ( bRes2 == sal_True ) + aSemaphore.release( ); + + CPPUNIT_ASSERT_MESSAGE( "release Semaphore: try to aquire before and after the semaphore has been released", + bRes1 == sal_False && bRes2 == sal_True && bRunning == sal_True ); + + } + + void release_002() + { + Semaphore aSemaphore(sal_uInt32(0)); + bRes1 = sal_True; + for ( nCount = 0; nCount < 10; nCount++, aSemaphore.release( ) ) { } + for ( nCount = 0; nCount < 10; nCount++, bRes1 = bRes1 && aSemaphore.tryToAcquire( ) ) { } + bRes = aSemaphore.tryToAcquire( ); + + CPPUNIT_ASSERT_MESSAGE( "release Semaphore: release ten times and acquire eleven times.", + sal_False == bRes && sal_True == bRes1); + } + + CPPUNIT_TEST_SUITE( release ); + CPPUNIT_TEST( release_001 ); + CPPUNIT_TEST( release_002 ); + CPPUNIT_TEST_SUITE_END( ); + }; // class release + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Semaphore::ctors, "osl_Semaphore"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Semaphore::acquire, "osl_Semaphore"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Semaphore::tryToAcquire, "osl_Semaphore"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Semaphore::release, "osl_Semaphore"); +// ----------------------------------------------------------------------------- + +} // namespace osl_Semaphore + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/semaphore/osl_Semaphore_Const.h b/sal/qa/osl/semaphore/osl_Semaphore_Const.h new file mode 100644 index 000000000000..c9f1149674f4 --- /dev/null +++ b/sal/qa/osl/semaphore/osl_Semaphore_Const.h @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Semaphore_Const.h,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_SEMAPHORE_CONST_H_ +#define _OSL_SEMAPHORE_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +#ifndef _OSL_THREAD_HXX_ +#include <osl/thread.hxx> +#endif +#include <osl/mutex.hxx> +#include <osl/pipe.hxx> + +#ifndef _OSL_SEMAPHOR_HXX_ +#include <osl/semaphor.hxx> +#endif +#include <osl/time.h> + +#include <testshl/simpleheader.hxx> + +#ifdef UNX +#include <unistd.h> +#endif + +//------------------------------------------------------------------------ +// most return value -1 denote a fail of operation. +//------------------------------------------------------------------------ +#define OSL_PIPE_FAIL -1 + +#define OSLTEST_DECLARE_USTRING( str_name, str_value ) \ + ::rtl::OUString a##str_name = rtl::OUString::createFromAscii( str_value ) + +//------------------------------------------------------------------------ +// semaphre names +//------------------------------------------------------------------------ +OSLTEST_DECLARE_USTRING( TestSem, "testsem" ); + +const char pTestString[17] = "Sun Microsystems"; + + +#endif /* _OSL_SEMAPHORE_CONST_H_ */ diff --git a/sal/qa/osl/socket/export.exp b/sal/qa/osl/socket/export.exp new file mode 100755 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/osl/socket/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/osl/socket/makefile.mk b/sal/qa/osl/socket/makefile.mk new file mode 100755 index 000000000000..134bcadb55aa --- /dev/null +++ b/sal/qa/osl/socket/makefile.mk @@ -0,0 +1,227 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.11 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_osl_socket + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL1OBJS= \ + $(SLO)$/osl_Socket.obj + +SHL1TARGET=osl_SocketOld +SHL1STDLIBS= $(SALLIB) $CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL1STDLIBS+= $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL1STDLIBS+= -ldl -lnsl +.ENDIF + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# --- BEGIN -------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/osl_Socket_tests.obj +SHL2TARGET= osl_Socket_tests +SHL2STDLIBS= $(SALLIB) $CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +DEF2NAME= $(SHL2TARGET) +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map + +# END -------------------------------------------------------------- + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL3OBJS= \ + $(SLO)$/sockethelper.obj \ + $(SLO)$/osl_StreamSocket.obj + +SHL3TARGET= osl_StreamSocket +SHL3STDLIBS= $(SALLIB) $CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL3STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL3STDLIBS += -ldl -lnsl +.ENDIF + +SHL3IMPLIB= i$(SHL3TARGET) +DEF3NAME= $(SHL3TARGET) +SHL3VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL4OBJS= \ + $(SLO)$/sockethelper.obj \ + $(SLO)$/osl_DatagramSocket.obj + +SHL4TARGET= osl_DatagramSocket +SHL4STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL4STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL4STDLIBS += -ldl -lnsl +.ENDIF + +SHL4IMPLIB= i$(SHL4TARGET) +DEF4NAME= $(SHL4TARGET) +SHL4VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL5OBJS= \ + $(SLO)$/sockethelper.obj \ + $(SLO)$/osl_SocketAddr.obj + +SHL5TARGET= osl_SocketAddr +SHL5STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL5STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL5STDLIBS += -ldl -lnsl +.ENDIF + +SHL5IMPLIB= i$(SHL5TARGET) +DEF5NAME= $(SHL5TARGET) +SHL5VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL6OBJS= \ + $(SLO)$/sockethelper.obj \ + $(SLO)$/osl_Socket2.obj + +SHL6TARGET= osl_Socket2 +SHL6STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL6STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL6STDLIBS += -ldl -lnsl +.ENDIF + +SHL6IMPLIB= i$(SHL6TARGET) +DEF6NAME= $(SHL6TARGET) +SHL6VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL7OBJS= \ + $(SLO)$/sockethelper.obj \ + $(SLO)$/osl_ConnectorSocket.obj + +SHL7TARGET= osl_ConnectorSocket +SHL7STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL7STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL7STDLIBS += -ldl -lnsl +.ENDIF + +SHL7IMPLIB= i$(SHL7TARGET) +DEF7NAME= $(SHL7TARGET) +SHL7VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:Socket by codegen.pl +SHL8OBJS= \ + $(SLO)$/sockethelper.obj \ + $(SLO)$/osl_AcceptorSocket.obj + +SHL8TARGET= osl_AcceptorSocket +SHL8STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +.IF "$(GUI)" == "WNT" +SHL8STDLIBS += $(WS2_32LIB) +.ENDIF + +.IF "$(GUI)" == "UNX" +SHL8STDLIBS += -ldl -lnsl +.ENDIF + +SHL8IMPLIB= i$(SHL8TARGET) +DEF8NAME= $(SHL8TARGET) +SHL8VERSIONMAP = $(PRJ)$/qa$/export.map +# auto generated Target:Socket +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) $(SHL2OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/osl/socket/osl_AcceptorSocket.cxx b/sal/qa/osl/socket/osl_AcceptorSocket.cxx new file mode 100644 index 000000000000..6325385b62ee --- /dev/null +++ b/sal/qa/osl/socket/osl_AcceptorSocket.cxx @@ -0,0 +1,305 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_AcceptorSocket.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; + */ + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> + +#include "osl_Socket_Const.h" +#include "sockethelper.hxx" + +using namespace osl; +using namespace rtl; + +#define IP_PORT_FTP 21 +#define IP_PORT_MYPORT9 8897 +#define IP_PORT_MYPORT4 8885 +#define IP_PORT_MYPORT3 8884 + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +// just used to test socket::close() when accepting +class AcceptorThread : public Thread +{ + ::osl::AcceptorSocket asAcceptorSocket; + ::rtl::OUString aHostIP; + sal_Bool bOK; +protected: + void SAL_CALL run( ) + { + ::osl::SocketAddr saLocalSocketAddr( aHostIP, IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# AcceptorSocket bind address failed.\n" ) ; + return; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# AcceptorSocket listen address failed.\n" ) ; + return; + } + + asAcceptorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + bOK = sal_True; + t_print("AcceptorThread: acceptConnection failed! \n"); + } + } +public: + AcceptorThread(::osl::AcceptorSocket & asSocket, ::rtl::OUString const& aBindIP ) + : asAcceptorSocket( asSocket ), aHostIP( aBindIP ) + { + bOK = sal_False; + } + + sal_Bool isOK() { return bOK; } + + ~AcceptorThread( ) + { + if ( isRunning( ) ) + { + asAcceptorSocket.shutdown(); + t_print("# error: Acceptor thread not terminated.\n" ); + } + } +}; + +namespace osl_AcceptorSocket +{ + + /** testing the methods: + inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet, + oslProtocol Protocol = osl_Socket_ProtocolIp, + oslSocketType Type = osl_Socket_TypeStream); + */ + + class ctors : public CppUnit::TestFixture + { + public: + + void ctors_001() + { + /// Socket constructor. + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the acceptor socket was created successfully.", + osl_Socket_TypeStream == asSocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + +#if 0 /* OBSOLETE */ + class operator_assign : public CppUnit::TestFixture + { + public: + + void assign_001() + { +#if defined(LINUX) + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::AcceptorSocket asSocketAssign( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + asSocket.setOption( osl_Socket_OptionReuseAddr, 1); + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4 ); + asSocket.bind( saSocketAddr ); + + AcceptorThread myAcceptorThread( asSocketAssign, rtl::OUString::createFromAscii("127.0.0.1") ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + //when accepting, assign another socket to the socket, the thread will not be closed, so is blocking + asSocketAssign = asSocket; + + t_print("#asSocketAssign port number is %d\n", asSocketAssign.getLocalPort() ); + + asSocketAssign.shutdown(); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK() == sal_True ); + + +#endif /* LINUX */ + } + + + CPPUNIT_TEST_SUITE( operator_assign ); + CPPUNIT_TEST( assign_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class operator_assign +#endif /* OBSOLETE */ + + /** testing the method: + inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1); + inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection); + inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr); + */ + + class listen_accept : public CppUnit::TestFixture + { + public: + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1); + // sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + // sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void listen_accept_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3 ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3 ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + CPPUNIT_ASSERT_MESSAGE( "test for listen_accept function: try to create a connection with remote host, using listen and accept.", + ( osl_Socket_Ok == eResult ) ); + } + + void listen_accept_002() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4 ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT4 ); + ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection, saPeerSocketAddr); /// waiting for incoming connection... + + CPPUNIT_ASSERT_MESSAGE( "test for listen_accept function: try to create a connection with remote host, using listen and accept, accept with peer address.", + ( sal_True == bOK2 ) && + ( osl_Socket_Ok == eResult ) && + ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) ); + } + + + CPPUNIT_TEST_SUITE( listen_accept ); + CPPUNIT_TEST( listen_accept_001 ); + CPPUNIT_TEST( listen_accept_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class listen_accept + + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::ctors, "osl_AcceptorSocket"); +//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::operator_assign, "osl_AcceptorSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::listen_accept, "osl_AcceptorSocket"); + +} // namespace osl_AcceptorSocket + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_ConnectorSocket.cxx b/sal/qa/osl/socket/osl_ConnectorSocket.cxx new file mode 100644 index 000000000000..52c1b12b687e --- /dev/null +++ b/sal/qa/osl/socket/osl_ConnectorSocket.cxx @@ -0,0 +1,267 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_ConnectorSocket.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; + */ + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> + +#include "osl_Socket_Const.h" +#include "sockethelper.hxx" + +using namespace osl; +using namespace rtl; + +#define IP_PORT_MYPORT2 8883 +#define IP_PORT_FTP 21 +#define IP_PORT_MYPORT3 8884 + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +class CloseSocketThread : public Thread +{ + ::osl::Socket &m_sSocket; +protected: + void SAL_CALL run( ) + { + thread_sleep( 1 ); + m_sSocket.close( ); + } +public: + CloseSocketThread(::osl::Socket & sSocket ) + : m_sSocket( sSocket ) + { + } + + ~CloseSocketThread( ) + { + if ( isRunning( ) ) + { + t_print("# error: CloseSocketThread not terminated.\n" ); + } + } +}; + +namespace osl_ConnectorSocket +{ + + /** testing the method: + ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet, + oslProtocol Protocol = osl_Socket_ProtocolIp, + oslSocketType Type = osl_Socket_TypeStream); + */ + + class ctors : public CppUnit::TestFixture + { + public: + void ctors_001() + { + /// Socket constructor. + ::osl::ConnectorSocket csSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the connector socket was created successfully.", + osl_Socket_TypeStream == csSocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + /** testing the method: + oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0); + */ + + class connect : public CppUnit::TestFixture + { + public: + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + // sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + // sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void connect_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT2 ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT2 ); + ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + //asAcceptorSocket.enableNonBlockingMode( sal_True ); + //oslSocketResult eResultAccept = asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + //CPPUNIT_ASSERT_MESSAGE( "accept failed.", osl_Socket_Ok == eResultAccept ); + /// launch client socket + oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + CPPUNIT_ASSERT_MESSAGE( "connect failed.", osl_Socket_Ok == eResult ); + + /// get peer information + csConnectorSocket.getPeerAddr( saPeerSocketAddr );/// connected. + + CPPUNIT_ASSERT_MESSAGE( "test for connect function: try to create a connection with remote host. and check the setup address.", + ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) && + ( osl_Socket_Ok == eResult )); + } + //non-blocking mode connect? + void connect_002() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3 ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3 ); + ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + csConnectorSocket.enableNonBlockingMode( sal_True ); + + oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + CPPUNIT_ASSERT_MESSAGE( "connect failed.", osl_Socket_InProgress == eResult || osl_Socket_Ok == eResult ); + + /// get peer information + csConnectorSocket.getPeerAddr( saPeerSocketAddr ); + + CPPUNIT_ASSERT_MESSAGE( "test for connect function: try to create a connection with remote host. and check the setup address.", + sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) ; + } + // really an error or just delayed + // how to design senarios that will return osl_Socket_Interrupted, osl_Socket_TimedOut + void connect_003() + { + ::osl::SocketAddr saTargetSocketAddr1( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT3 ); + ::osl::SocketAddr saTargetSocketAddr2( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT3 ); + + csConnectorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult1 = csConnectorSocket.connect( saTargetSocketAddr1, pTimeout ); + oslSocketResult eResult2 = csConnectorSocket.connect( saTargetSocketAddr2, pTimeout ); + CloseSocketThread myCloseThread( csConnectorSocket ); + oslSocketResult eResult3 = csConnectorSocket.connect( saTargetSocketAddr2, pTimeout ); + myCloseThread.join(); + CPPUNIT_ASSERT_MESSAGE( "connect should failed.", osl_Socket_Error == eResult1 && + osl_Socket_Error == eResult2 && osl_Socket_Error == eResult3 ); + + } + + // really an error in non-blocking mode + void connect_004() + { + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT3 ); + + csConnectorSocket.enableNonBlockingMode( sal_True ); + + oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + CPPUNIT_ASSERT_MESSAGE( "connect should failed.", osl_Socket_Error == eResult ); + } + /** here need a case: immediate connection, say in non-blocking mode connect return osl_Socket_Ok + */ + + CPPUNIT_TEST_SUITE( connect ); + CPPUNIT_TEST( connect_001 ); + CPPUNIT_TEST( connect_002 ); + CPPUNIT_TEST( connect_003 ); + CPPUNIT_TEST( connect_004 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class connect + + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ConnectorSocket::ctors, "osl_ConnectorSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ConnectorSocket::connect, "osl_ConnectorSocket"); + +} // namespace osl_ConnectorSocket + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_ConnectorSocket.xsce b/sal/qa/osl/socket/osl_ConnectorSocket.xsce new file mode 100644 index 000000000000..6c04ae2eb6f3 --- /dev/null +++ b/sal/qa/osl/socket/osl_ConnectorSocket.xsce @@ -0,0 +1 @@ +osl_ConnectorSocket.connect.connect_003 wntmsci diff --git a/sal/qa/osl/socket/osl_DatagramSocket.cxx b/sal/qa/osl/socket/osl_DatagramSocket.cxx new file mode 100644 index 000000000000..4cf27a90ad90 --- /dev/null +++ b/sal/qa/osl/socket/osl_DatagramSocket.cxx @@ -0,0 +1,319 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_DatagramSocket.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; + */ + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> + +//#include "osl_Socket_Const.h" +#include "sockethelper.hxx" + +using namespace osl; +using namespace rtl; + +#define IP_PORT_MYPORT9 8897 +#define IP_PORT_MYPORT10 8898 + +const char * pTestString1 = "test socket"; +const char * pTestString2 = " Passed#OK"; + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +class CloseSocketThread : public Thread +{ + ::osl::Socket m_sSocket; +protected: + void SAL_CALL run( ) + { + thread_sleep( 1 ); + m_sSocket.close( ); + } +public: + CloseSocketThread(::osl::Socket & sSocket ) + : m_sSocket( sSocket ) + { + } + + ~CloseSocketThread( ) + { + if ( isRunning( ) ) + { + t_print("# error: CloseSocketThread not terminated.\n" ); + } + } +}; + +//------------------------------------------------------------------------ +// tests cases begins here +//------------------------------------------------------------------------ + +namespace osl_DatagramSocket +{ + + /** testing the methods: + inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet, + oslProtocol Protocol= osl_Socket_ProtocolIp, + oslSocketType Type= osl_Socket_TypeDgram); + */ + + class ctors : public CppUnit::TestFixture + { + public: + + void ctors_001() + { + /// Socket constructor. + ::osl::DatagramSocket dsSocket; + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the datagram socket was created successfully.", + osl_Socket_TypeDgram == dsSocket.getType( ) ); + } + + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + +/**thread do sendTo, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml +*/ +class TalkerThread : public Thread +{ +protected: + ::osl::SocketAddr saTargetSocketAddr; + ::osl::DatagramSocket dsSocket; + + void SAL_CALL run( ) + { + dsSocket.sendTo( saTargetSocketAddr, pTestString1, strlen( pTestString1 ) + 1 ); // "test socket" + dsSocket.shutdown(); + } + + void SAL_CALL onTerminated( ) + { + } + +public: + TalkerThread( ): + saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9 ) + { + } + + ~TalkerThread( ) + { + if ( isRunning( ) ) + t_print("# error: TalkerThread not terminated normally.\n" ); + } +}; + +/**thread do listen, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml +*/ +class ListenerThread : public Thread +{ +protected: + ::osl::SocketAddr saTargetSocketAddr; + ::osl::DatagramSocket dsSocket; + + void SAL_CALL run( ) + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT10 ); + dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + if ( dsSocket.bind( saLocalSocketAddr ) == sal_False ) + { + t_print("DatagramSocket bind failed \n"); + return; + } + //blocking mode: default + sal_Int32 nRecv = dsSocket.recvFrom( pRecvBuffer, 30, &saTargetSocketAddr); //strlen( pTestString2 ) + 1 + t_print("After recvFrom, nRecv is %d\n", nRecv); + } + + void SAL_CALL onTerminated( ) + { + } + +public: + sal_Char pRecvBuffer[30]; + ListenerThread( ): + saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT10 ) + { + pRecvBuffer[0] = '\0'; + } + + ~ListenerThread( ) + { + if ( isRunning( ) ) + t_print("# error: ListenerThread not terminated normally.\n" ); + } + +}; + + /** testing the methods: + inline sal_Int32 DatagramSocket::recvFrom(void* pBuffer, sal_uInt32 BufferSize, + SocketAddr* pSenderAddr, oslSocketMsgFlag Flag ) + inline sal_Int32 DatagramSocket::sendTo( const SocketAddr& ReceiverAddr, + const void* pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag ) + */ + + class sendTo_recvFrom : public CppUnit::TestFixture + { + public: + + void sr_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9 ); + ::osl::DatagramSocket dsSocket; + dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + dsSocket.bind( saLocalSocketAddr ); + + sal_Char pReadBuffer[30]; + TalkerThread myTalkThread; + myTalkThread.create(); + sal_Int32 nRecv = dsSocket.recvFrom( pReadBuffer, 30, &saLocalSocketAddr); + myTalkThread.join(); + //t_print("#received buffer is %s# \n", pReadBuffer); + + sal_Bool bOk = ( strcmp(pReadBuffer, pTestString1) == 0 ); + + CPPUNIT_ASSERT_MESSAGE( "test for sendTo/recvFrom function: create a talker thread and recvFrom in the main thread, check if the datagram socket can communicate successfully.", + nRecv > 0 && bOk == sal_True ); + } + + void sr_002() + { + ::osl::SocketAddr saListenSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT10 ); + ::osl::DatagramSocket dsSocket; + + //listener thread construct a DatagramSocket, recvFrom waiting for data, then main thread sendto data + ListenerThread myListenThread; + myListenThread.create(); + //to grantee the recvFrom is before sendTo + thread_sleep( 1 ); + + sal_Int32 nSend = dsSocket.sendTo( saListenSocketAddr, pTestString2, strlen( pTestString2 ) + 1 ); + + CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo failed: nSend <= 0.", nSend > 0); + + myListenThread.join(); + //t_print("#received buffer is %s# \n", myListenThread.pRecvBuffer); + + sal_Bool bOk = ( strcmp( myListenThread.pRecvBuffer, pTestString2) == 0 ); + + CPPUNIT_ASSERT_MESSAGE( "test for sendTo/recvFrom function: create a listener thread and sendTo in the main thread, check if the datagram socket can communicate successfully.", + bOk == sal_True ); + } + + //sendTo error, return -1; recvFrom error, return -1 + void sr_003() + { + ::osl::SocketAddr saListenSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT10 ); + ::osl::DatagramSocket dsSocket; + // Transport endpoint is not connected + sal_Int32 nSend = dsSocket.sendTo( saListenSocketAddr, pTestString2, strlen( pTestString2 ) + 1 ); + CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo should fail: nSend <= 0.", + nSend == -1 ); + } + + void sr_004() + { + ::osl::SocketAddr saListenSocketAddr1( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT10 ); + ::osl::SocketAddr saListenSocketAddr2( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_MYPORT10 ); + ::osl::DatagramSocket dsSocket; + + dsSocket.enableNonBlockingMode( sal_True ); + + sal_Char pReadBuffer[30]; + //sal_Int32 nRecv1 = dsSocket.recvFrom( pReadBuffer, 30, &saListenSocketAddr1 ); + + // will block ? + CloseSocketThread myThread( dsSocket ); + myThread.create(); + sal_Int32 nRecv2 = dsSocket.recvFrom( pReadBuffer, 30, &saListenSocketAddr1 ); + myThread.join(); + //t_print("#nRecv1 is %d nRecv2 is %d\n", nRecv1, nRecv2 ); + CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo should fail: nSend <= 0.", + nRecv2 == -1 ); + } + + CPPUNIT_TEST_SUITE( sendTo_recvFrom ); + CPPUNIT_TEST( sr_001 ); + CPPUNIT_TEST( sr_002 ); + CPPUNIT_TEST( sr_003 ); + CPPUNIT_TEST( sr_004 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class sendTo_recvFrom + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DatagramSocket::ctors, "osl_DatagramSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DatagramSocket::sendTo_recvFrom, "osl_DatagramSocket"); + +} // namespace osl_DatagramSocket + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_Socket.cxx b/sal/qa/osl/socket/osl_Socket.cxx new file mode 100755 index 000000000000..ccc87ee23a1d --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket.cxx @@ -0,0 +1,3726 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Socket.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; + */ + + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#ifndef _OSL_SOCKET_CONST_H_ +#include <osl_Socket_Const_orig.h> +#endif + +#include <testshl/simpleheader.hxx> + +using namespace osl; +using namespace rtl; + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +/** compare two OUString. +*/ +inline sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ) +{ + sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr2 ); + + return bOk; +} + +/** compare a OUString and an ASCII string. +*/ +inline sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ) +{ + ::rtl::OUString ustr2 = rtl::OUString::createFromAscii( astr ); + sal_Bool bOk = ustr.equalsIgnoreAsciiCase( ustr2 ); + + return bOk; +} + +/** compare two socket address. +*/ +inline sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ) +{ + return ( ( sal_True == compareUString( addr1.getHostname( 0 ), addr2.getHostname( 0 ) ) ) && ( addr2.getPort( ) == addr2.getPort( ) ) ); +} + +inline char * oustring2char( const ::rtl::OUString & str ) +{ + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + return (char *)aString.getStr( ); +} + +/** print a UNI_CODE String. And also print some comments of the string. +*/ +inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) +{ + t_print("#%s #printUString_u# ", msg ); + t_print("%s\n", oustring2char( str ) ); +} + +/** get the local host name. + mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, + if no entry in /etc/hosts, it returns "localhost" + domain name +*/ +inline ::rtl::OUString getHost( void ) +{ + struct hostent *hptr; + + hptr = gethostbyname( "localhost" ); + CPPUNIT_ASSERT_MESSAGE( "#In getHostname function, error on gethostbyname()", hptr != NULL ); + ::rtl::OUString aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hptr->h_name ); + + return aUString; +} + +/** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu +*/ +inline ::rtl::OUString getThisHostname( void ) +{ + ::rtl::OUString aUString; +#ifdef WNT + struct hostent *hptr; + hptr = gethostbyname( "localhost" ); + CPPUNIT_ASSERT_MESSAGE( "#In getHostname function, error on gethostbyname()", hptr != NULL ); + aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hptr->h_name ); +#else + char hostname[255]; + CPPUNIT_ASSERT_MESSAGE( "#Error: gethostname failed.", gethostname(hostname, 255) == 0 ); + + struct hostent *hptr; + //first search /ets/hosts, then search from dns + hptr = gethostbyname( hostname); + if ( hptr != NULL ) + { + strcpy( hostname, hptr->h_name ); + } + + t_print("hostname is %s \n", hostname ); + aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hostname ); +#endif + return aUString; +} + +/** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") +*/ +inline ::rtl::OUString getIPbyName( rtl::OString const& str_name ) +{ + ::rtl::OUString aUString; + struct hostent *hptr; + //first search /ets/hosts, then search from dns + hptr = gethostbyname( str_name.getStr()); + if ( hptr != NULL ) + { + struct in_addr ** addrptr; + addrptr = (struct in_addr **) hptr->h_addr_list ; + //if there are more than one IPs on the same machine, we select one + for (; *addrptr; addrptr++) + { + t_print("#Local IP Address: %s\n", inet_ntoa(**addrptr)); + aUString = ::rtl::OUString::createFromAscii( (sal_Char *) (inet_ntoa(**addrptr)) ); + } + } + return aUString; +} + +/** get local ethernet IP +*/ +inline ::rtl::OUString getLocalIP( ) +{ + char hostname[255]; + gethostname(hostname, 255); + + return getIPbyName( hostname ); +} + +/** construct error message +*/ +inline ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "") +{ + ::rtl::OUString aUString; + if ( returnVal.equals( rightVal ) ) + return aUString; + aUString += ::rtl::OUString::createFromAscii(msg); + aUString += ::rtl::OUString::createFromAscii(": the returned value is '"); + aUString += returnVal; + aUString += ::rtl::OUString::createFromAscii("', but the value should be '"); + aUString += rightVal; + aUString += ::rtl::OUString::createFromAscii("'."); + return aUString; +} + +/** wait _nSec seconds. +*/ +void thread_sleep( sal_Int32 _nSec ) +{ + /// print statement in thread process must use fflush() to force display. + t_print("# wait %d seconds. ", _nSec ); + fflush(stdout); + +#ifdef WNT //Windows + Sleep( _nSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + usleep(_nSec * 100000); +#endif + t_print("# done\n" ); +} + +/** print Boolean value. +*/ +inline void printBool( sal_Bool bOk ) +{ + t_print("#printBool# " ); + ( sal_True == bOk ) ? t_print("YES!\n" ): t_print("NO!\n" ); +} + +/** print content of a ByteSequence. +*/ +inline void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ) +{ + t_print("#ByteSequence is: " ); + for ( int i = 0; i < nLen; i++ ){ + if ( bsByteSeq[i] < 0 ) + t_print("%d ", 256 + bsByteSeq[i] ); + else + t_print("%d ", bsByteSeq[i] ); + } + t_print(" .\n" ); +} + +/** convert an IP which is stored as a UString format to a ByteSequence array for later use. +*/ +inline ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ) +{ + + rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ); + const sal_Char *pChar = aString.getStr( ) ; + sal_Char tmpBuffer[4]; + sal_Int32 nCharCounter = 0; + ::rtl::ByteSequence bsByteSequence( IP_VER ); + sal_Int32 nByteSeqCounter = 0; + + for ( int i = 0; i < aString.getLength( ) + 1 ; i++ ) + { + if ( ( *pChar != '.' ) && ( i !=aString.getLength( ) ) ) + tmpBuffer[nCharCounter++] = *pChar; + else + { + tmpBuffer[nCharCounter] = '\0'; + nCharCounter = 0; + bsByteSequence[nByteSeqCounter++] = static_cast<sal_Int8>( atoi( tmpBuffer ) ); + } + pChar++; + } + return bsByteSequence; +} + +/** print a socket result name. +*/ +inline void printSocketResult( oslSocketResult eResult ) +{ + t_print("#printSocketResult# " ); + if (!eResult) + switch (eResult) + { + case osl_Socket_Ok: + t_print("client connected\n"); + break; + case osl_Socket_Error: + t_print("got an error ... exiting\r\n\r\n" ); + break; + case osl_Socket_TimedOut: + t_print("timeout\n"); + break; + + case osl_Socket_FORCE_EQUAL_SIZE: + t_print("FORCE EQUAL SIZE\n"); + break; + case osl_Socket_InProgress: + t_print("In Progress\n"); + break; + case osl_Socket_Interrupted: + t_print("Interrupted\n"); + break; + } +} + +/** Client Socket Thread, served as a temp little client to communicate with server. +*/ +class ClientSocketThread : public Thread +{ +protected: + oslThreadIdentifier m_id; + ::osl::SocketAddr saTargetSocketAddr; + ::osl::ConnectorSocket csConnectorSocket; + + void SAL_CALL run( ) + { + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 5; + pTimeout->Nanosec = 0; + + /// if the thread should terminate, schedule return false + //while ( schedule( ) == sal_True ) + //{ + if ( osl_Socket_Ok == csConnectorSocket.connect( saTargetSocketAddr, pTimeout )) + { + csConnectorSocket.send( pTestString1, 11 ); // "test socket" + csConnectorSocket.send( pTestString2, 10); + } + else + t_print("# ClientSocketThread: connect failed! \n"); + // terminate(); + //} + csConnectorSocket.close(); + free( pTimeout ); + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this thread %d!\n", m_id ); + } + +public: + ClientSocketThread( ): + saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT9 ), + csConnectorSocket( ) + { + m_id = getIdentifier( ); + //t_print("# successfully creat this client thread %d!\n", m_id ); + } + + ~ClientSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: client thread not terminated.\n" ); + } + +}; + + +/** Server Socket Thread, served as a temp little server to communicate with client. +*/ +class ServerSocketThread : public Thread +{ +protected: + oslThreadIdentifier m_id; + + void SAL_CALL run( ) + { + ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True); + while ( schedule( ) == sal_True ) + { + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# ServerSocketThread: AcceptorSocket bind address failed.\n" ) ; + break; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# ServerSocketThread: AcceptorSocket listen address failed.\n" ) ; + break; + } + + asAcceptorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + t_print("ServerSocketThread: acceptConnection failed! \n"); + break; + } + sal_Int32 nReadNumber1 = ssStreamConnection.recv( pReadBuffer, 11 ); + sal_Int32 nReadNumber2 = ssStreamConnection.recv( pReadBuffer + nReadNumber1, 11 ); + pReadBuffer[nReadNumber1 + nReadNumber2] = '\0'; + //t_print("# read buffer content: %s\n", pReadBuffer ); + break; + } + ssStreamConnection.close(); + asAcceptorSocket.close(); + + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this server thread %d!\n", m_id ); + } + +public: + // public to check if data transmition is OK + sal_Char pReadBuffer[30]; + ServerSocketThread( ) + { + m_id = getIdentifier( ); + //t_print("# successfully creat this server thread %d!\n", m_id ); + } + + ~ServerSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: server thread not terminated.\n" ); + } +}; + +// ----------------------------------------------------------------------------- +// Helper functions, to create buffers, check buffers +class ValueCheckProvider +{ + bool m_bFoundFailure; + char *m_pBuffer; + sal_Int32 m_nBufferSize; + +public: + ValueCheckProvider() + : + m_bFoundFailure(false), + m_pBuffer(NULL), + m_nBufferSize(0) + { + } + + bool isFailure() {return m_bFoundFailure;} + + const char* getBuffer() {return m_pBuffer;} + char* getWriteBuffer() {return m_pBuffer;} + + sal_Int32 getBufferSize() {return m_nBufferSize;} + + bool checkValues(sal_Int32 _nLength, int _nValue) + { + m_bFoundFailure = false; + for(sal_Int32 i=0;i<_nLength;i++) + { + if (m_pBuffer[i] != _nValue) + { + m_bFoundFailure = true; + } + } + return m_bFoundFailure; + } + + void createBuffer(sal_Int32 _nLength, int _nValue) + { + m_nBufferSize = _nLength; + m_pBuffer = (char*) malloc(m_nBufferSize); + if (m_pBuffer) + { + memset(m_pBuffer, _nValue, m_nBufferSize); + } + } + + void freeBuffer() + { + if (m_pBuffer) free(m_pBuffer); + } + +}; + +// ----------------------------------------------------------------------------- +/** Client Socket Thread, served as a temp little client to communicate with server. +*/ + +class ReadSocketThread : public Thread +{ + int m_nValue; + ValueCheckProvider m_aValues; + +protected: + oslThreadIdentifier m_id; + ::osl::SocketAddr saTargetSocketAddr; + ::osl::ConnectorSocket csConnectorSocket; + + void SAL_CALL run( ) + { + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 5; + pTimeout->Nanosec = 0; + + /// if the thread should terminate, schedule return false + //while ( schedule( ) == sal_True ) + //{ + if ( osl_Socket_Ok == csConnectorSocket.connect( saTargetSocketAddr, pTimeout )) + { + sal_Int32 nReadCount = csConnectorSocket.read( m_aValues.getWriteBuffer(), m_aValues.getBufferSize() ); + m_aValues.checkValues(nReadCount, m_nValue); + } + else + { + t_print("# ReadSocketThread: connect failed! \n"); + } + // terminate(); + //} + //remove this line for deadlock on solaris( margritte.germany ) + csConnectorSocket.close(); + free( pTimeout ); + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this thread %d!\n", m_id ); + } + +public: + sal_Int32 getCount() {return m_aValues.getBufferSize();} + bool isOk() {return m_aValues.isFailure() == true ? false : true;} + + ReadSocketThread(sal_Int32 _nBufferSize, int _nValue ) + : + m_nValue( _nValue ), + saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT10 ), + csConnectorSocket( ) + { + m_id = getIdentifier( ); + //t_print("# successfully creat this client thread %d!\n", m_id ); + m_aValues.createBuffer(_nBufferSize, 0); + } + + ~ReadSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: client thread not terminated.\n" ); + m_aValues.freeBuffer(); + } + +}; + +/** Server Socket Thread, write a file which is large +*/ +class WriteSocketThread : public Thread +{ + ValueCheckProvider m_aValues; + +protected: + oslThreadIdentifier m_id; + + void SAL_CALL run( ) + { + ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT10 ); + ::osl::StreamSocket ssStreamConnection; + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + /// if the thread should terminate, schedule return false + while ( schedule( ) == sal_True ) + { + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# WriteSocketThread: AcceptorSocket bind address failed. \n" ) ; + break; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# WriteSocketThread: AcceptorSocket listen address failed. \n" ) ; + break; + } + // blocking mode, if read/recv failed, block until success + asAcceptorSocket.enableNonBlockingMode( sal_False); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + t_print("WriteSocketThread: acceptConnection failed! \n"); + break; + } + + ssStreamConnection.write( m_aValues.getBuffer(), m_aValues.getBufferSize() ); + break; + } + ssStreamConnection.close(); + asAcceptorSocket.close(); + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this server thread %d!\n", m_id ); + } + +public: + // public to check if data transmition is OK + WriteSocketThread(sal_Int32 _nBufferSize, int _nValue ) + { + m_id = getIdentifier( ); + //t_print("# successfully creat this server thread %d!\n", m_id ); + + m_aValues.createBuffer(_nBufferSize, _nValue); + } + + ~WriteSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: server thread not terminated.\n" ); + m_aValues.freeBuffer(); + } + +}; + +// ----------------------------------------------------------------------------- +// just used to test socket::close() when accepting +class AcceptorThread : public Thread +{ + ::osl::AcceptorSocket asAcceptorSocket; + ::rtl::OUString aHostIP; + sal_Bool bOK; +protected: + void SAL_CALL run( ) + { + ::osl::SocketAddr saLocalSocketAddr( aHostIP, IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# AcceptorSocket bind address failed.\n" ) ; + return; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# AcceptorSocket listen address failed.\n" ) ; + return; + } + + asAcceptorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + bOK = sal_True; + t_print("AcceptorThread: acceptConnection failed! \n"); + } + } +public: + AcceptorThread(::osl::AcceptorSocket & asSocket, ::rtl::OUString & aBindIP ) + : asAcceptorSocket( asSocket ), aHostIP( aBindIP ) + { + bOK = sal_False; + } + + sal_Bool isOK() { return bOK; } + + ~AcceptorThread( ) + { + if ( isRunning( ) ) + { + asAcceptorSocket.shutdown(); + t_print("# error: Acceptor thread not terminated.\n" ); + } + } +}; + +class CloseSocketThread : public Thread +{ + ::osl::Socket m_sSocket; +protected: + void SAL_CALL run( ) + { + thread_sleep( 1 ); + m_sSocket.close( ); + } +public: + CloseSocketThread(::osl::Socket & sSocket ) + : m_sSocket( sSocket ) + { + } + + ~CloseSocketThread( ) + { + if ( isRunning( ) ) + { + t_print("# error: CloseSocketThread not terminated.\n" ); + } + } +}; + +//------------------------------------------------------------------------ +// tests cases begins here +//------------------------------------------------------------------------ + +namespace osl_SocketAddr +{ + + /** testing the methods: + inline SocketAddr(); + inline SocketAddr(const SocketAddr& Addr); + inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy ); + inline SocketAddr(oslSocketAddr Addr); + inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort ); + */ + + class ctors : public CppUnit::TestFixture + { + public: + + void ctors_none() + { + /// SocketAddr constructor. + ::osl::SocketAddr saSocketAddr; + + // oslSocketResult aResult; + // rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); + + // rtl::OUString suHost2 = getThisHostname(); + + CPPUNIT_ASSERT_MESSAGE("test for none parameter constructor function: check if the socket address was created successfully", + sal_True == saSocketAddr.is( ) ); + } + + void ctors_none_000() + { + /// SocketAddr constructor. + ::osl::SocketAddr saSocketAddr; + + oslSocketResult aResult; + rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); + rtl::OUString suHost2 = getThisHostname(); + + sal_Bool bOk = compareUString(suHost, suHost2); + + rtl::OUString suError = rtl::OUString::createFromAscii("Host names should be the same. From SocketAddr.getLocalHostname() it is'"); + suError += suHost; + suError += rtl::OUString::createFromAscii("', from getThisHostname() it is '"); + suError += suHost2; + suError += rtl::OUString::createFromAscii("'."); + + CPPUNIT_ASSERT_MESSAGE(suError, sal_True == bOk); + } + + void ctors_copy() + { + /// SocketAddr copy constructor. + ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 ); + ::osl::SocketAddr saCopySocketAddr( saSocketAddr ); + + sal_Int32 nPort = saCopySocketAddr.getPort( ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy constructor function: copy constructor, do an action of copy construction then check the port with original set.", + ( sal_True == saCopySocketAddr.is( ) ) && ( nPort == IP_PORT_HTTP1 ) ); + } + + void ctors_copy_no_001() + { +#if 0 + ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 ); + oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); + + ::osl::SocketAddr saSocketAddrCopy( psaOSLSocketAddr, SAL_NO_COPY ); + saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + saSocketAddr.getPort( ) == IP_PORT_HTTP2 ); +#endif + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostName1, IP_PORT_HTTP1 ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + + oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); + + ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); + + pSocketAddrCopy->setPort( IP_PORT_HTTP2 ); + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddr->getPort( ) == IP_PORT_HTTP2 ); + + delete pSocketAddrCopy; + // LLA: don't do this also: delete pSocketAddr; + } + + void ctors_copy_no_002() + { + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostName1, IP_PORT_HTTP1 ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); + ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) ); + + delete pSocketAddrCopy; + } + + void ctors_copy_handle_001() + { + ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 ); + ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, get its port to check copy effect.", + saSocketAddrCopy.getPort( ) == IP_PORT_HTTP1 ); + } + + void ctors_copy_handle_002() + { + ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_HTTP1 ); + ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); + saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, the original one should not be changed.", + saSocketAddr.getPort( ) != IP_PORT_HTTP2 ); + } + + void ctors_hostname_port_001() + { + /// tcpip-specif constructor. + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP ); + printUString(saSocketAddr.getHostname( ), "ctors_hostname_port_001:getHostname"); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specif constructor function: do a constructor using tcpip spec, check the result.", + saSocketAddr.is( ) == sal_True && + ( saSocketAddr.getPort( ) == IP_PORT_FTP )/*&& + ( sal_True == compareUString( saSocketAddr.getHostname( ), aHostName1 ) ) */); + } + + //same as is_002 + void ctors_hostname_port_002() + { + /// tcpip-specif constructor. + ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_MYPORT2 ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specif constructor function: using an invalid IP address, the socketaddr ctors should fail", sal_False == saSocketAddr.is( )); + } + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_none_000 ); + CPPUNIT_TEST( ctors_copy ); + CPPUNIT_TEST( ctors_copy_no_001 ); + CPPUNIT_TEST( ctors_copy_no_002 ); + CPPUNIT_TEST( ctors_copy_handle_001 ); + CPPUNIT_TEST( ctors_copy_handle_002 ); + CPPUNIT_TEST( ctors_hostname_port_001 ); + CPPUNIT_TEST( ctors_hostname_port_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + + /** testing the method: + inline sal_Bool is() const; + */ + + class is : public CppUnit::TestFixture + { + public: + void is_001() + { + ::osl::SocketAddr saSocketAddr; + + CPPUNIT_ASSERT_MESSAGE("test for is() function: create an unknown type socket, it should be True when call is.", + sal_True == saSocketAddr.is( ) ); + } + // refer to setPort_003() + void is_002() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_INVAL ); + + CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid port number", + sal_True == saSocketAddr.is( ) ); + } + + void is_003() + { + ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_MYPORT ); + + CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid Ip number", + sal_True != saSocketAddr.is( ) ); + } + + CPPUNIT_TEST_SUITE( is ); + CPPUNIT_TEST( is_001 ); + CPPUNIT_TEST( is_002 ); + CPPUNIT_TEST( is_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class is + + + /** testing the method: + inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const; + */ + + class getHostname : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void tearDown() + { + } + + void getHostname_000() + { + ::osl::SocketAddr saSocketAddr( aHostIp4, IP_PORT_FTP ); + + } + + /** it will search the Ip in current machine's /etc/hosts at first, if find, then return the + mapped hostname, otherwise, it will search via DNS server, and often return hostname+ Domain name + like "sceri.PRC.Sun.COM" + The process is same as Socket::getLocalHost(), but getLocalHost can only return hostname of the current machine. + */ + void getHostname_001() + { + ::osl::SocketAddr saSocketAddr( aHostIp4, IP_PORT_FTP ); + rtl::OUString suResult = saSocketAddr.getHostname( 0 ); + rtl::OUString suError = outputError(suResult, aHostName4, "test for getHostname(0)"); + sal_Bool bOK = compareUString( suResult, aHostName4 ); + // search the returned hostname in /etc/hosts, if find, and the IP in the row is same as IP + // in the Addr, it's right also. + if ( bOK == sal_False) + { + if ( compareUString( getIPbyName( oustring2char( suResult ) ), aHostIp4 ) == sal_True ) + bOK = sal_True; + } + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK); + } + +// LLA: now we have to control, if this behaviour is right. +// LLA: this function does not work in company (Linux, Windows) but at home + void getHostname_002() + { + rtl::OUString suHostname = rtl::OUString::createFromAscii("cn-1.germany.sun.com"); + rtl::OUString aHostIP = getIPbyName( oustring2char( suHostname ) ); + + ::osl::SocketAddr saSocketAddr( aHostName1, IP_PORT_FTP ); + sal_Bool bOK = saSocketAddr.setHostname( suHostname ); + CPPUNIT_ASSERT_MESSAGE("#SocketAddr.setHostname failed", sal_True == bOK ); + oslSocketResult aResult; + rtl::OUString suResult = saSocketAddr.getHostname( &aResult ); + CPPUNIT_ASSERT_MESSAGE("SocketAddr.getHostname failed.", aResult == osl_Socket_Ok); + + rtl::OUString suError = outputError(suResult, suHostname, "test for getHostname(0)"); + bOK = compareUString( suResult, suHostname ); + if ( bOK == sal_False) + { + rtl::OString aString = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); + if ( compareUString( getIPbyName( aString) , aHostIp6 ) == sal_True ) + { + bOK = sal_True; + } + } + + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + + CPPUNIT_TEST_SUITE( getHostname ); + CPPUNIT_TEST( getHostname_001 ); + CPPUNIT_TEST( getHostname_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getHostname + + + /** testing the method: + inline sal_Int32 SAL_CALL getPort() const; + */ + + class getPort : public CppUnit::TestFixture + { + public: + void getPort_001() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPort() function: get a normal port number.", + IP_PORT_FTP == saSocketAddr.getPort( ) ); + } + + void getPort_002() + { + ::osl::SocketAddr saSocketAddr( aHostIp2, IP_PORT_INVAL ); + + //t_print("#getPort_002: Port number is %d \n", saSocketAddr.getPort( )); + + CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid port to a SocketAddr, get the port to see if it can detect. it did not pass in (W32).", + saSocketAddr.getPort( )>=1 && saSocketAddr.getPort( ) <= 65535 ); + } + //two cases will return OSL_INVALID_PORT: 1. not valid SocketAddr + //2. SocketAddr family is not osl_Socket_FamilyInet, but case 2 could not be constructed + void getPort_003() + { + ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_MYPORT ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid IP to a SocketAddr, get the port to see returned value. ", + saSocketAddr.getPort( ) == OSL_INVALID_PORT ); + } + + CPPUNIT_TEST_SUITE( getPort ); + CPPUNIT_TEST( getPort_001 ); + CPPUNIT_TEST( getPort_002 ); + CPPUNIT_TEST( getPort_003 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getPort + + + /** testing the method: + inline sal_Bool SAL_CALL setPort( sal_Int32 nPort ); + rfc1413.txt: TCP port numbers are from 1-65535 + rfc1700.txt: 0/tcp Reserved ; 0/udp Reserved + */ + + class setPort : public CppUnit::TestFixture + { + public: + void setPort_001() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP ); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_TELNET ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: modify a port number setting, and check it.", + ( sal_True == bOK ) && + ( IP_PORT_TELNET == saSocketAddr.getPort( ) ) ); + } + + /** 0 to 1024 is known as the reserved port range (traditionally only root can assign programs to ports in + this range) and the ephemeral port range from 1025 to 65535. + As many of you programmers will know, when you specify the source port of 0 when you connect to a host, + the OS automatically reassigns the port number to high numbered ephemeral port. The same happens if you + try to bind a listening socket to port 0. + http://www.securiteam.com/securityreviews/5XP0Q2AAKS.html + another: http://www.muq.org/~cynbe/muq/mufref_564.html + */ + void setPort_002() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP ); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_ZERO ); + + oslSocket sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 );//sal_True); + sal_Bool bOK1 = sSocket.bind( saSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "bind SocketAddr failed", bOK1 == sal_True ); + + sal_Int32 newPort = sSocket.getLocalPort(); + //t_print("#new port is %d\n", newPort ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: port number should be in 1 ~ 65535, set port 0, it should be converted to a port number between 1024~65535.", + ( 1024 <= newPort ) && ( 65535 >= newPort ) && ( bOK == sal_True ) ); + + } + + void setPort_003() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_INVAL ); + //on Linux, getPort return 34463 + //t_print("#Port number is %d \n", saSocketAddr.getPort( )); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an address with invalid port. it should return error or convert it to a valid port.", + ( ( 1 <= saSocketAddr.getPort( ) ) && ( 65535 >= saSocketAddr.getPort( ) ) &&( bOK == sal_True ) ) || + bOK == sal_False); + } + + /* this is not a inet-addr => can't set port */ + void setPort_004() + { + ::osl::SocketAddr saSocketAddr( aHostIpInval1, IP_PORT_FTP); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_MYPORT ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an invalid address with valid port. it should return error.", + bOK == sal_False); + } + + + CPPUNIT_TEST_SUITE( setPort ); + CPPUNIT_TEST( setPort_001 ); + CPPUNIT_TEST( setPort_002 ); + CPPUNIT_TEST( setPort_003 ); + CPPUNIT_TEST( setPort_004 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class setPort + + + /** tester comment: + + In the following two functions, it use ::rtl::ByteSequence as an intermediate storage for address, + the ByteSequence object can hold sal_Int8 arrays, which is raged [-127, 127], in case of IP addr + that is greater than 127, say 129.158.217.202, it will stored as -127, -98, -39, -54, it is unique + in the range of sal_Int8, but lack of readability. + so may be a sal_uInt8 array is better. + */ + + + /** testing the method: + inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address ); + */ + + class setAddr : public CppUnit::TestFixture + { + public: + void setAddr_001() + { + ::osl::SocketAddr saSocketAddr( aHostIp2, IP_PORT_FTP ); + saSocketAddr.setAddr( UStringIPToByteSequence( aHostIp1 ) ); + ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); + sal_Bool bOK = sal_False; + + if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) && ( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for setAddr() function: construct Addr with \"129.158.217.202\", set it to \"127.0.0.1\", and check the correctness ", + sal_True == bOK ); + } + + + CPPUNIT_TEST_SUITE( setAddr ); + CPPUNIT_TEST( setAddr_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class setAddr + + + /** testing the method: + inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const; + */ + + class getAddr : public CppUnit::TestFixture + { + public: + void getAddr_001() + { + oslSocketResult SocketResult; + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_FTP ); + ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( &SocketResult ); + + sal_Bool bOK = sal_False; + + if ( ( osl_Socket_Ok == SocketResult ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for getAddr() function: construct a socketaddr with IP assigned, get the address to check correctness.Caught unknown exception on (Win32)", + sal_True == bOK && SocketResult == osl_Socket_Ok); + } + + CPPUNIT_TEST_SUITE( getAddr ); + CPPUNIT_TEST( getAddr_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getAddr + + + /** testing the methods: + inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr); + inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr); + inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy ); + inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const; + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; /// not implemented. + */ + + class operator_equal : public CppUnit::TestFixture + { + public: + void operator_equal_001() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + sal_Bool bOK = sal_False; + ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); + + if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: use operator= to assign Ip1 to Ip2, check its modification.", + sal_True == bOK ); + } + + + void operator_equal_002() + { + ::osl::SocketAddr saSocketAddr( aHostIp3, IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + CPPUNIT_ASSERT_MESSAGE( "after assign, the assigned SocketAddr is not same as the original Addr", + IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ); + saSocketAddrEqual.setPort( IP_PORT_MYPORT3 ); + saSocketAddr.setPort( IP_PORT_HTTP2 ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: perform an equal action, then try to change the original address's port. it should not be changed ( handle released), it did not pass in (W32), this is under discussion.", + IP_PORT_MYPORT3 == saSocketAddrEqual.getPort( ) ); + } + + void operator_equal_const_001() + { + const ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + sal_Bool bOK = sal_False; + ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); + + if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: use operator= const to assign Ip1 to Ip2, verify the change on the second one.", + sal_True == bOK ); + } + + void operator_equal_const_002() + { + const ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( aHostIp2, IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + saSocketAddrEqual.setPort( IP_PORT_HTTP1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: change the second instance, the first one should not be altered, since it does not released the handle.", + IP_PORT_HTTP1 != saSocketAddr.getPort( ) ); + } + + void operator_equal_assign_001() + { + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostIp1, IP_PORT_TELNET ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + ::osl::SocketAddr* pSocketAddrAssign = new ::osl::SocketAddr( aHostIp2, IP_PORT_FTP ); + oslSocketAddr poslSocketAddr = pSocketAddr->getHandle( ); + //if( m_handle ) osl_destroySocketAddr( m_handle ); so pSocketAddrAssign had been destroyed and then point to pSocketAddr + pSocketAddrAssign->assign(poslSocketAddr, SAL_NO_COPY); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddrAssign->getPort( ) == IP_PORT_TELNET ); + + delete pSocketAddrAssign; + } + + void operator_is_equal_001() + { + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrequal( aHostIp1, IP_PORT_TELNET ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two identical Address.", + sal_True == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) ); + } + + void operator_is_equal_002() + { + ::osl::SocketAddr saSocketAddr( aHostIp2, IP_PORT_FTP); + ::osl::SocketAddr saSocketAddrequal( aHostIp1, IP_PORT_TELNET ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two different Address.", + sal_False == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) ); + } + + CPPUNIT_TEST_SUITE( operator_equal ); + CPPUNIT_TEST( operator_equal_001 ); + CPPUNIT_TEST( operator_equal_002 ); + CPPUNIT_TEST( operator_equal_const_001 ); + CPPUNIT_TEST( operator_equal_const_002 ); + CPPUNIT_TEST( operator_equal_assign_001 ); + CPPUNIT_TEST( operator_is_equal_001 ); + CPPUNIT_TEST( operator_is_equal_002 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class operator_equal + + + + /** testing the method: + inline oslSocketAddr SAL_CALL getHandle() const; + */ + + class getSocketAddrHandle : public CppUnit::TestFixture + { + public: + + void getSocketAddrHandle_001() + { + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( aHostName1, IP_PORT_HTTP1 ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); + ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) ); + + delete pSocketAddrCopy; + } + + void getSocketAddrHandle_002() + { + ::osl::SocketAddr saSocketAddr( aHostName3, IP_PORT_MYPORT4 ); + oslSocketAddr poslSocketAddr = saSocketAddr.getHandle( ); + + sal_Bool bOK = ( saSocketAddr == poslSocketAddr ); + //t_print("getSocketAddrHandle_002\n"); + CPPUNIT_ASSERT_MESSAGE( "test for getHandle() function: use getHandle() function as an intermediate way to create identical address.", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getSocketAddrHandle ); + CPPUNIT_TEST( getSocketAddrHandle_001 ); + CPPUNIT_TEST( getSocketAddrHandle_002 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getSocketAddrHandle + + + /** testing the method: + static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0); + */ + + class getLocalHostname : public CppUnit::TestFixture + { + public: + /* the process of getLocalHostname: 1.gethostname (same as /bin/hostname) returned name A + 2. search A in /etc/hosts, if there is an alias name is A, return the name in the same row + */ + + void getLocalHostname_000() + { + // _osl_getFullQualifiedDomainName( ); + oslSocketResult aResult = osl_Socket_Error; + rtl::OUString suHostname = osl::SocketAddr::getLocalHostname(&aResult); + CPPUNIT_ASSERT_MESSAGE("getLocalHostname failed", aResult == osl_Socket_Ok); + } + + void getLocalHostname_001() + { + oslSocketResult *pResult = NULL; + //printSocketResult(*pResult); + ::rtl::OUString suResult = ::osl::SocketAddr::getLocalHostname( pResult ); + + // LLA: IMHO localhost, or hostname by itself should be ok. + rtl::OUString suThisHost = getThisHostname( ); + bool bOk = false; + if (suThisHost.equals(rtl::OUString::createFromAscii("localhost"))) + { + bOk = true; + } + else + { + if (suThisHost.equals(suResult)) + { + bOk = true; + } + } + + ::rtl::OUString suError; + suError = outputError(suResult, getThisHostname( ), "test for getLocalHostname() function"); + + CPPUNIT_ASSERT_MESSAGE( suError, bOk == true ); + } + + CPPUNIT_TEST_SUITE( getLocalHostname ); + CPPUNIT_TEST( getLocalHostname_000 ); + CPPUNIT_TEST( getLocalHostname_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getLocalHostname + + + /** testing the method: + static inline void SAL_CALL resolveHostname( const ::rtl::OUString & strHostName , SocketAddr & Addr ); + */ + + class resolveHostname : public CppUnit::TestFixture + { + public: + void resolveHostname_001() + { + ::osl::SocketAddr saSocketAddr; + ::osl::SocketAddr::resolveHostname( aHostIp1, saSocketAddr ); + ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); + sal_Bool bOK = sal_False; + + if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for resolveHostname() function: try to resolve localhost to 127.0.0.1.", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( resolveHostname ); + CPPUNIT_TEST( resolveHostname_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class resolveHostname + + + /** testing the method: + static inline sal_Int32 SAL_CALL getServicePort( + const ::rtl::OUString& strServiceName, + const ::rtl::OUString & strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) ); + */ + + class gettheServicePort : public CppUnit::TestFixture + { + public: + void gettheServicePort_001() + { + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get ftp service port on TCP protocol.", + IP_PORT_FTP== ::osl::SocketAddr::getServicePort( aServiceFTP, aProtocolTCP ) ); + } + + void gettheServicePort_002() + { + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get telnet service port on TCP protocol.", + IP_PORT_TELNET== ::osl::SocketAddr::getServicePort( aServiceTELNET, aProtocolTCP ) ); + } + + void gettheServicePort_003() + { + //Solaris has no service called "https", please see /etc/services + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get netbios-ssn service port on UDP protocol.", + IP_PORT_NETBIOS_DGM == ::osl::SocketAddr::getServicePort( aServiceNETBIOS, aProtocolUDP ) ); + } + + void gettheServicePort_004() + { + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get a service port which is not exist.", + OSL_INVALID_PORT == ::osl::SocketAddr::getServicePort( ::rtl::OUString::createFromAscii( "notexist" ), aProtocolUDP ) ); + } + + CPPUNIT_TEST_SUITE( gettheServicePort ); + CPPUNIT_TEST( gettheServicePort_001 ); + CPPUNIT_TEST( gettheServicePort_002 ); + CPPUNIT_TEST( gettheServicePort_003 ); + CPPUNIT_TEST( gettheServicePort_004 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class gettheServicePort + +// ----------------------------------------------------------------------------- + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::ctors, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::is, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getHostname, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getPort, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setPort, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setAddr, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getAddr, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::operator_equal, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getSocketAddrHandle, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getLocalHostname, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::resolveHostname, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::gettheServicePort, "osl_SocketAddr"); + + +} // namespace osl_SocketAddr + + + +namespace osl_Socket +{ + + /** testing the methods: + inline Socket( ); + inline Socket( const Socket & socket ); + inline Socket( oslSocket socketHandle ); + inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire ); + */ + + /** test writer's comment: + + class Socket can not be initialized by its protected constructor, though the protected + constructor is the most convenient way to create a new socket. + it only allow the method of C function osl_createSocket like: + ::osl::Socket sSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, + osl_Socket_ProtocolIp ) ); + the use of C method lost some of the transparent of tester using C++ wrapper. + */ + + + class ctors : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void ctors_none() + { + /// Socket constructor. + // ::osl::Socket sSocket; + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_none constructor function: check if the socket was created successfully, if no exception occured", + 1 == 1 ); + } + + void ctors_acquire() + { + /// Socket constructor. + ::osl::Socket sSocket( sHandle ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + void ctors_no_acquire() + { + /// Socket constructor. + ::osl::Socket sSocket( sHandle, SAL_NO_ACQUIRE ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_no_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + void ctors_copy_ctor() + { + ::osl::Socket sSocket( sHandle ); + /// Socket copy constructor. + ::osl::Socket copySocket( sSocket ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_copy_ctor constructor function: create new Socket instance using copy constructor", + osl_Socket_TypeStream == copySocket.getType( ) ); + } + + void ctors_TypeRaw() + { +#ifdef WNT + oslSocket sHandleRaw = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp ); +// LLA: ? ::osl::Socket sSocket( sHandleRaw ); + CPPUNIT_ASSERT_MESSAGE( " type osl_Socket_TypeRaw socket create failed on UNX ", sHandleRaw != NULL); +#else + oslSocket sHandleRaw = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp ); + CPPUNIT_ASSERT_MESSAGE( " can't create socket with type osl_Socket_TypeRaw within UNX is ok.", sHandleRaw == NULL); +#endif + } + + void ctors_family_Ipx() + { + oslSocket sHandleIpx = osl_createSocket( osl_Socket_FamilyIpx, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + CPPUNIT_ASSERT_MESSAGE( " family osl_Socket_FamilyIpx socket create failed! ", sHandleIpx != NULL); + ::osl::Socket sSocket( sHandleIpx ); //, SAL_NO_ACQUIRE ); + t_print("#Type is %d \n", sSocket.getType( ) ); + + CPPUNIT_ASSERT_MESSAGE(" test for create new Socket instance that family is osl_Socket_FamilyIpx", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_acquire ); + CPPUNIT_TEST( ctors_no_acquire ); + CPPUNIT_TEST( ctors_copy_ctor ); + CPPUNIT_TEST( ctors_TypeRaw ); + CPPUNIT_TEST( ctors_family_Ipx ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + + /** testing the methods: + inline Socket& SAL_CALL operator= ( oslSocket socketHandle); + inline Socket& SAL_CALL operator= (const Socket& sock); + inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ; + inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const; + */ + + class operators : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + /** test writer's comment: + + the assignment operator does not support direct assinment like: + ::osl::Socket sSocket = sHandle. + */ + void operators_assignment_handle() + { + ::osl::Socket sSocket(sHandle); + ::osl::Socket assignSocket = sSocket.getHandle(); + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment_handle function: test the assignment operator.", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + void operators_assignment() + { + ::osl::Socket sSocket( sHandle ); + ::osl::Socket assignSocket = sSocket; + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment function: assignment operator", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + void operators_equal_handle_001() + { + /// Socket constructor. + ::osl::Socket sSocket( sHandle ); + ::osl::Socket equalSocket = sSocket; + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_handle_001 function: check equal.", + equalSocket == sHandle ); + } + + void operators_equal_handle_002() + { + /// Socket constructor. + ::osl::Socket equalSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ) ); + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_handle_001 function: check unequal.", + !( equalSocket == sHandle ) ); + } + + void operators_equal_001() + { + ::osl::Socket sSocket( sHandle ); + /// Socket copy constructor. + ::osl::Socket equalSocket( sSocket ); + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal function: check equal.", + equalSocket == sSocket ); + } + + void operators_equal_002() + { + ::osl::Socket sSocket( sHandle ); + /// Socket copy constructor. + ::osl::Socket equalSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ) ); + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_002 function: check unequal.", + !( equalSocket == sSocket ) ); + } + + CPPUNIT_TEST_SUITE( operators ); + CPPUNIT_TEST( operators_assignment_handle ); + CPPUNIT_TEST( operators_assignment ); + CPPUNIT_TEST( operators_equal_handle_001 ); + CPPUNIT_TEST( operators_equal_handle_002 ); + CPPUNIT_TEST( operators_equal_001 ); + CPPUNIT_TEST( operators_equal_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class operators + + + /** testing the methods: + inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite ); + inline void SAL_CALL close(); + */ + + class close : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void close_001() + { + ::osl::Socket sSocket(sHandle); + sSocket.close(); + + CPPUNIT_ASSERT_MESSAGE( "test for close_001 function: this function is reserved for test.", + sSocket.getHandle() == sHandle ); + } + + void close_002() + { +//#if defined(LINUX) + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + AcceptorThread myAcceptorThread( asSocket, aHostIp1 ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + //when accepting, close the socket, the thread will not block for accepting + //man close:Any locks held on the file it was associated with, and owned by the process, are removed + asSocket.close(); + //thread_sleep( 2 ); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK() == sal_True ); +//#endif + } + + // to cover "if ( pSockAddrIn->sin_addr.s_addr == htonl(INADDR_ANY) )" in osl_closeSocket( ) + void close_003() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + AcceptorThread myAcceptorThread( asSocket, aHostIpZero ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + asSocket.close(); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK() == sal_True ); + } + + CPPUNIT_TEST_SUITE( close ); + CPPUNIT_TEST( close_001 ); + CPPUNIT_TEST( close_002 ); + CPPUNIT_TEST( close_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class close + + /** testing the method: + inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const; + */ + + class getLocalAddr : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + // get the Address of the local end of the socket + void getLocalAddr_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIp1, IP_PORT_MYPORT8 ); + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + + sSocket.getLocalAddr( saLocalSocketAddr ); + + sal_Bool bOK = compareUString( saLocalSocketAddr.getHostname( 0 ), sSocket.getLocalHost() ) ; + + CPPUNIT_ASSERT_MESSAGE( "test for getLocalAddr function: first create a new socket, then a socket address, bind them, and check the address.", + sal_True == bOK ); + } + + + CPPUNIT_TEST_SUITE( getLocalAddr ); + CPPUNIT_TEST( getLocalAddr_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getLocalAddr + + + /** testing the method: + inline sal_Int32 SAL_CALL getLocalPort() const; + */ + + class getLocalPort : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getLocalPort_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIp1, IP_PORT_MYPORT7 ); // aHostIp1 localhost + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + sal_Bool bOK = ( IP_PORT_MYPORT7 == sSocket.getLocalPort( ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getLocalPort function: first create a new socket, then a socket address, bind them, and check the port.", + sal_True == bOK ); + } + + /** test writer's comment: + + the invalid port number can not be set by giving invalid port number + such as 99999 or -1, it will convert to ( x mod 65535 ), so it will always be + valid, the only instance that the getLocalPort returns OSL_INVALID_PORT + is when saSocketAddr itself is an invalid one, that is , the IP or host name + can not be found, then the created socket address is not valid. + */ + void getLocalPort_002() + { + ::osl::SocketAddr saBindSocketAddr( aHostIpInval, IP_PORT_TELNET); +#ifdef WNT + ::osl::Socket sSocket(sHandle); + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); // sal_True); + sSocket.bind( saBindSocketAddr ); + //Invalid IP, so bind should fail + ::rtl::OUString suError = outputError(::rtl::OUString::valueOf(sSocket.getLocalPort( )), + ::rtl::OUString::valueOf((sal_Int32)OSL_INVALID_PORT), + "test for getLocalPort function: first create a new socket, then an invalid socket address, bind them, and check the port assigned."); + sal_Bool bOK = ( OSL_INVALID_PORT == sSocket.getLocalPort( ) ); + (void)bOK; +#else + //on Unix, if Addr is not an address of type osl_Socket_FamilyInet, it returns OSL_INVALID_PORT + ::rtl::OUString suError = ::rtl::OUString::createFromAscii( "on Unix, if Addr is not an address of type osl_Socket_FamilyInet, it returns OSL_INVALID_PORT, but can not create Addr of that case"); +#endif + CPPUNIT_ASSERT_MESSAGE( suError, sal_False ); + + } + + void getLocalPort_003() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( getLocalIP(), IP_PORT_INVAL); + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + ::rtl::OUString suError = outputError(::rtl::OUString::valueOf(sSocket.getLocalPort( )), + ::rtl::OUString::createFromAscii("34463"), + "test for getLocalPort function: first create a new socket, then an invalid socket address, bind them, and check the port assigned"); + sal_Bool bOK = ( sSocket.getLocalPort( ) >= 1 && sSocket.getLocalPort( ) <= 65535); + + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getLocalPort ); + CPPUNIT_TEST( getLocalPort_001 ); +// LLA: CPPUNIT_TEST( getLocalPort_002 ); + CPPUNIT_TEST( getLocalPort_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getLocalPort + + + /** testing the method: + inline ::rtl::OUString SAL_CALL getLocalHost() const; + + Mindyliu: on Linux, at first it will check the binded in /etc/hosts, if it has the binded IP, it will return the hostname in it; + else if the binded IP is "127.0.0.1", it will return "localhost", if it's the machine's ethernet ip such as "129.158.217.90", it + will return hostname of current processor such as "aegean.PRC.Sun.COM" + */ + + class getLocalHost : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getLocalHost_001() + { + ::osl::Socket sSocket(sHandle); + //port number from IP_PORT_HTTP1 to IP_PORT_MYPORT6, mindyliu + ::osl::SocketAddr saBindSocketAddr( aHostIp1, IP_PORT_MYPORT6 ); + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + sal_Bool bOK; + ::rtl::OUString suError; +#ifdef WNT + bOK = compareUString( sSocket.getLocalHost( ), getThisHostname( ) ) ; + suError = outputError(sSocket.getLocalHost( ), getThisHostname( ), +"test for getLocalHost function: create localhost socket and check name"); +#else + ::rtl::OUString aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) "localhost" ); + sal_Bool bRes1, bRes2; + bRes1 = compareUString( sSocket.getLocalHost( ), aUString ) ; + bRes2 = compareUString( sSocket.getLocalHost( ), saBindSocketAddr.getHostname(0) ) ; + bOK = bRes1 || bRes2; + suError = outputError(sSocket.getLocalHost( ), aUString, "test for getLocalHost function: create localhost socket and check name"); +#endif + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + void getLocalHost_002() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIpInval, IP_PORT_POP3); + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sSocket.bind( saBindSocketAddr ); + //Invalid IP, so bind should fail + sal_Bool bOK = compareUString( sSocket.getLocalHost( ), aNullURL ) ; + ::rtl::OUString suError = outputError(sSocket.getLocalHost( ), aNullURL, "test for getLocalHost function: getLocalHost with invalid SocketAddr"); + + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getLocalHost ); + CPPUNIT_TEST( getLocalHost_001 ); + CPPUNIT_TEST( getLocalHost_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getLocalHost + + + /** testing the methods: + inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const; + inline sal_Int32 SAL_CALL getPeerPort() const; + inline ::rtl::OUString SAL_CALL getPeerHost() const; + */ + class getPeer : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void getPeer_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT ); + ::osl::SocketAddr saPeerSocketAddr( aHostIp2, IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + /// launch server socket + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind '127.0.0.1' address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + /// get peer information + csConnectorSocket.getPeerAddr( saPeerSocketAddr );/// connected. + sal_Int32 peerPort = csConnectorSocket.getPeerPort( ); + ::rtl::OUString peerHost = csConnectorSocket.getPeerHost( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPeer function: setup a connection and then get the peer address, port and host from client side.", + ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) )&& + ( sal_True == compareUString( peerHost, saLocalSocketAddr.getHostname( 0 ) ) ) && + ( peerPort == saLocalSocketAddr.getPort( ) )); + } + + + CPPUNIT_TEST_SUITE( getPeer ); + CPPUNIT_TEST( getPeer_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getPeer + + + /** testing the methods: + inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface); + */ + + + class bind : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void bind_001() + { + ::osl::Socket sSocket(sHandle); + //bind must use local IP address ---mindyliu + ::osl::SocketAddr saBindSocketAddr( getLocalIP(), IP_PORT_MYPORT5 ); + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "Socket bind fail.", sal_True == bOK1 ); + + sal_Bool bOK2 = compareUString( sSocket.getLocalHost( ), saBindSocketAddr.getHostname( ) ) ; + + sSocket.close(); + CPPUNIT_ASSERT_MESSAGE( "test for bind function: bind a valid address.", sal_True == bOK2 ); + } + + void bind_002() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIpInval, IP_PORT_NETBIOS ); + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1); // sal_True); + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + sal_Bool bOK2 = compareUString( sSocket.getLocalHost( ), getThisHostname( ) ) ; + + CPPUNIT_ASSERT_MESSAGE( "test for bind function: bind a valid address.", + ( sal_False == bOK1 ) && ( sal_False == bOK2 ) ); + } + + CPPUNIT_TEST_SUITE( bind ); + CPPUNIT_TEST( bind_001 ); + CPPUNIT_TEST( bind_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class bind + + + /** testing the methods: + inline sal_Bool SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const; + + */ + class isRecvReady : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void isRecvReady_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT1 ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT1 ); + ::osl::SocketAddr saPeerSocketAddr( aHostIp2, IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); // sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + /// is receive ready? + sal_Bool bOK3 = asAcceptorSocket.isRecvReady( pTimeout ); + + CPPUNIT_ASSERT_MESSAGE( "test for isRecvReady function: setup a connection and then check if it can transmit data.", + ( sal_True == bOK3 ) ); + } + + + CPPUNIT_TEST_SUITE( isRecvReady ); + CPPUNIT_TEST( isRecvReady_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class isRecvReady + + + /** testing the methods: + inline sal_Bool SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const; + */ + class isSendReady : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void isSendReady_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT ); + ::osl::SocketAddr saPeerSocketAddr( aHostIp2, IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + /// is send ready? + sal_Bool bOK3 = csConnectorSocket.isSendReady( pTimeout ); + + CPPUNIT_ASSERT_MESSAGE( "test for isSendReady function: setup a connection and then check if it can transmit data.", + ( sal_True == bOK3 ) ); + } + + + CPPUNIT_TEST_SUITE( isSendReady ); + CPPUNIT_TEST( isSendReady_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class isSendReady + + + /** testing the methods: + inline oslSocketType SAL_CALL getType() const; + + */ + + class getType : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getType_001() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + void getType_002() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.", + osl_Socket_TypeDgram == sSocket.getType( ) ); + } + +#ifdef UNX + // mindy: since on LINUX and SOLARIS, Raw type socket can not be created, so do not test getType() here + // mindy: and add one test case to test creating Raw type socket--> ctors_TypeRaw() + void getType_003() + { + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.this is not passed in (LINUX, SOLARIS), the osl_Socket_TypeRaw, type socket can not be created.", + sal_True); + } +#else + void getType_003() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.", + osl_Socket_TypeRaw == sSocket.getType( ) ); + } +#endif + + CPPUNIT_TEST_SUITE( getType ); + CPPUNIT_TEST( getType_001 ); + CPPUNIT_TEST( getType_002 ); + CPPUNIT_TEST( getType_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getType + + + + /** testing the methods: + inline sal_Int32 SAL_CALL getOption( + oslSocketOption Option, + void* pBuffer, + sal_uInt32 BufferLen, + oslSocketOptionLevel Level= osl_Socket_LevelSocket) const; + + inline sal_Int32 getOption( oslSocketOption option ) const; + + */ + + class getOption : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + + } + + void tearDown( ) + { + sHandle = NULL; + } + + /** test writer's comment: + + in oslSocketOption, the osl_Socket_OptionType denote 1 as osl_Socket_TypeStream. + 2 as osl_Socket_TypeDgram, etc which is not mapping the oslSocketType enum. differ + in 1. + */ + + void getOption_001() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + sal_Int32 * pType = ( sal_Int32 * )malloc( sizeof ( sal_Int32 ) ); + *pType = 0; + sSocket.getOption( osl_Socket_OptionType, pType, sizeof ( sal_Int32 ) ); + sal_Bool bOK = ( SOCK_STREAM == *pType ); + // there is a TypeMap(socket.c) which map osl_Socket_TypeStream to SOCK_STREAM on UNX, and SOCK_STREAM != osl_Socket_TypeStream + //sal_Bool bOK = ( TYPE_TO_NATIVE(osl_Socket_TypeStream) == *pType ); + free( pType ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get type option of socket.", + sal_True == bOK ); + } + + // getsockopt error + void getOption_004() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + sal_Bool * pbDontRoute = ( sal_Bool * )malloc( sizeof ( sal_Bool ) ); + sal_Int32 nRes = sSocket.getOption( osl_Socket_OptionInvalid, pbDontRoute, sizeof ( sal_Bool ) ); + free( pbDontRoute ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get invalid option of socket, should return -1.", + nRes == -1 ); + } + + void getOption_simple_001() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + sal_Bool bOK = ( sal_False == sSocket.getOption( osl_Socket_OptionDontRoute ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get debug option of socket.", + sal_True == bOK ); + } + + void getOption_simple_002() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + sal_Bool bOK = ( sal_False == sSocket.getOption( osl_Socket_OptionDebug ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get debug option of socket.", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getOption ); + CPPUNIT_TEST( getOption_001 ); + CPPUNIT_TEST( getOption_004 ); + CPPUNIT_TEST( getOption_simple_001 ); + CPPUNIT_TEST( getOption_simple_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getOption + + + /** testing the methods: + inline sal_Bool SAL_CALL setOption( oslSocketOption Option, + void* pBuffer, + sal_uInt32 BufferLen, + oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const; + */ + + class setOption : public CppUnit::TestFixture + { + public: + TimeValue *pTimeout; +// LLA: maybe there is an error in the source, +// as long as I remember, if a derived class do not overload all ctors there is a problem. + + ::osl::AcceptorSocket asAcceptorSocket; + + void setUp( ) + { + + } + + void tearDown( ) + { + asAcceptorSocket.close( ); + } + + + // LLA: + // getSocketOption returns BufferLen, or -1 if something failed + + // setSocketOption returns sal_True, if option could stored + // else sal_False + + void setOption_001() + { + /// set and get option. + int nBufferLen = sizeof ( sal_Int32); + // LLA: SO_DONTROUTE expect an integer boolean, what ever it is, it's not sal_Bool! + + sal_Int32 * pbDontRouteSet = ( sal_Int32 * )malloc( sizeof ( sal_Int32 ) ); + *pbDontRouteSet = 1; // sal_True; + + sal_Int32 * pGetBuffer = ( sal_Int32 * )malloc( sizeof ( sal_Int32 ) ); + *pGetBuffer = 0; + + // maybe asAcceptorSocket is not right initialized + sal_Bool b1 = asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, pbDontRouteSet, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "setOption function failed.", ( sal_True == b1 ) ); + sal_Int32 n2 = asAcceptorSocket.getOption( osl_Socket_OptionDontRoute, pGetBuffer, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "getOption function failed.", ( n2 == nBufferLen ) ); + + // on Linux, the value of option is 1, on Solaris, it's 16, but it's not important the exact value, + // just judge it is zero or not! + sal_Bool bOK = ( 0 != *pGetBuffer ); + t_print("#setOption_001: getOption is %d \n", *pGetBuffer); + + // toggle check, set to 0 + *pbDontRouteSet = 0; + + sal_Bool b3 = asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, pbDontRouteSet, sizeof ( sal_Int32 ) ); + CPPUNIT_ASSERT_MESSAGE( "setOption function failed.", ( sal_True == b3 ) ); + sal_Int32 n4 = asAcceptorSocket.getOption( osl_Socket_OptionDontRoute, pGetBuffer, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "getOption (DONTROUTE) function failed.", ( n4 == nBufferLen ) ); + + sal_Bool bOK2 = ( 0 == *pGetBuffer ); + + t_print("#setOption_001: getOption is %d \n", *pGetBuffer); + +// LLA: sal_Bool * pbDontTouteSet = ( sal_Bool * )malloc( sizeof ( sal_Bool ) ); +// LLA: *pbDontTouteSet = sal_True; +// LLA: sal_Bool * pbDontTouteGet = ( sal_Bool * )malloc( sizeof ( sal_Bool ) ); +// LLA: *pbDontTouteGet = sal_False; +// LLA: asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, pbDontTouteSet, sizeof ( sal_Bool ) ); +// LLA: asAcceptorSocket.getOption( osl_Socket_OptionDontRoute, pbDontTouteGet, sizeof ( sal_Bool ) ); +// LLA: ::rtl::OUString suError = outputError(::rtl::OUString::valueOf((sal_Int32)*pbDontTouteGet), +// LLA: ::rtl::OUString::valueOf((sal_Int32)*pbDontTouteSet), +// LLA: "test for setOption function: set osl_Socket_OptionDontRoute and then check"); +// LLA: +// LLA: sal_Bool bOK = ( sal_True == *pbDontTouteGet ); +// LLA: free( pbDontTouteSet ); +// LLA: free( pbDontTouteGet ); + + CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check.", + ( sal_True == bOK ) && (sal_True == bOK2) ); + + free( pbDontRouteSet ); + free( pGetBuffer ); +// LLA: CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + void setOption_002() + { + /// set and get option. + + // sal_Int32 * pbLingerSet = ( sal_Int32 * )malloc( nBufferLen ); + // *pbLingerSet = 7; + // sal_Int32 * pbLingerGet = ( sal_Int32 * )malloc( nBufferLen ); + /* struct */linger aLingerSet; + sal_Int32 nBufferLen = sizeof( struct linger ); + aLingerSet.l_onoff = 1; + aLingerSet.l_linger = 7; + + linger aLingerGet; + + asAcceptorSocket.setOption( osl_Socket_OptionLinger, &aLingerSet, nBufferLen ); + + sal_Int32 n1 = asAcceptorSocket.getOption( osl_Socket_OptionLinger, &aLingerGet, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "getOption (SO_LINGER) function failed.", ( n1 == nBufferLen ) ); + + //t_print("#setOption_002: getOption is %d \n", aLingerGet.l_linger); + sal_Bool bOK = ( 7 == aLingerGet.l_linger ); + CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check. ", + sal_True == bOK ); + + } + + void setOption_003() + { + linger aLingerSet; + aLingerSet.l_onoff = 1; + aLingerSet.l_linger = 7; + + sal_Bool b1 = asAcceptorSocket.setOption( osl_Socket_OptionLinger, &aLingerSet, 0 ); + printUString( asAcceptorSocket.getErrorAsString() ); + CPPUNIT_ASSERT_MESSAGE( "setOption (SO_LINGER) function failed for optlen is 0.", + ( b1 == sal_False ) ); + } + + void setOption_simple_001() + { + /// set and get option. + asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, 1 ); //sal_True ); + sal_Bool bOK = ( 0 != asAcceptorSocket.getOption( osl_Socket_OptionDontRoute ) ); + + t_print("setOption_simple_001(): getoption is %d \n", asAcceptorSocket.getOption( osl_Socket_OptionDontRoute ) ); + CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check.", + ( sal_True == bOK ) ); + } + + void setOption_simple_002() + { + /// set and get option. + // LLA: this does not work, due to the fact that SO_LINGER is a structure +// LLA: asAcceptorSocket.setOption( osl_Socket_OptionLinger, 7 ); +// LLA: sal_Bool bOK = ( 7 == asAcceptorSocket.getOption( osl_Socket_OptionLinger ) ); + +// LLA: CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check.", +// LLA: ( sal_True == bOK ) ); + } + + CPPUNIT_TEST_SUITE( setOption ); + CPPUNIT_TEST( setOption_001 ); + CPPUNIT_TEST( setOption_002 ); + CPPUNIT_TEST( setOption_003 ); + CPPUNIT_TEST( setOption_simple_001 ); +// LLA: CPPUNIT_TEST( setOption_simple_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class setOption + + + + /** testing the method: + inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode); + */ + class enableNonBlockingMode : public CppUnit::TestFixture + { + public: + ::osl::AcceptorSocket asAcceptorSocket; + + void enableNonBlockingMode_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// if reach this statement, it is non-blocking mode, since acceptConnection will blocked by default. + sal_Bool bOK = sal_True; + asAcceptorSocket.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for enableNonBlockingMode function: launch a server socket and make it non blocking. if it can pass the acceptConnection statement, it is non-blocking", + ( sal_True == bOK ) ); + } + + + CPPUNIT_TEST_SUITE( enableNonBlockingMode ); + CPPUNIT_TEST( enableNonBlockingMode_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class enableNonBlockingMode + + + /** testing the method: + inline sal_Bool SAL_CALL isNonBlockingMode() const; + */ + class isNonBlockingMode : public CppUnit::TestFixture + { + public: + ::osl::AcceptorSocket asAcceptorSocket; + + void isNonBlockingMode_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); // sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + sal_Bool bOK3 = asAcceptorSocket.isNonBlockingMode( ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// if reach this statement, it is non-blocking mode, since acceptConnection will blocked by default. + sal_Bool bOK4 = asAcceptorSocket.isNonBlockingMode( ); + asAcceptorSocket.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for isNonBlockingMode function: launch a server socket and make it non blocking. it is expected to change from blocking mode to non-blocking mode.", + ( sal_False == bOK3 ) && ( sal_True == bOK4 ) ); + } + + + CPPUNIT_TEST_SUITE( isNonBlockingMode ); + CPPUNIT_TEST( isNonBlockingMode_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class isNonBlockingMode + + /** testing the method: + inline void SAL_CALL clearError() const; + */ + class clearError : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void clearError_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIpInval, IP_PORT_HTTP2 ); + ::osl::SocketAddr saLocalSocketAddr; + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sSocket.bind( saBindSocketAddr );//build an error "osl_Socket_E_AddrNotAvail" + oslSocketError seBind = sSocket.getError( ); + sSocket.clearError( ); + + CPPUNIT_ASSERT_MESSAGE( "test for clearError function: trick an error called sSocket.getError( ), and then clear the error states, check the result.", + osl_Socket_E_None == sSocket.getError( ) && seBind != osl_Socket_E_None ); + } + + + CPPUNIT_TEST_SUITE( clearError ); + CPPUNIT_TEST( clearError_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class clearError + + + /** testing the methods: + inline oslSocketError getError() const; + inline ::rtl::OUString getErrorAsString( ) const; + */ + class getError : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getError_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIp1, IP_PORT_FTP ); + ::osl::SocketAddr saLocalSocketAddr; + + CPPUNIT_ASSERT_MESSAGE( "test for getError function: should get no error.", + osl_Socket_E_None == sSocket.getError( ) ); + } + + void getError_002() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( aHostIpInval, IP_PORT_FTP ); + ::osl::SocketAddr saLocalSocketAddr; + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sSocket.bind( saBindSocketAddr );//build an error "osl_Socket_E_AddrNotAvail" + //on Solaris, the error no is EACCES, but it has no mapped value, so getError() returned osl_Socket_E_InvalidError. +#if defined(SOLARIS) + CPPUNIT_ASSERT_MESSAGE( "trick an error called sSocket.getError( ), check the getError result.Failed on Solaris, returned osl_Socket_E_InvalidError because no entry to map the errno EACCES. ", + osl_Socket_E_InvalidError == sSocket.getError( ) ); +#else + //while on Linux & Win32, the errno is EADDRNOTAVAIL, getError returned osl_Socket_E_AddrNotAvail. + + CPPUNIT_ASSERT_MESSAGE( "trick an error called sSocket.getError( ), check the getError result.Failed on Solaris, returned osl_Socket_E_InvalidError because no entry to map the errno EACCES. Passed on Linux & Win32", + osl_Socket_E_AddrNotAvail == sSocket.getError( ) ); +#endif + } + + CPPUNIT_TEST_SUITE( getError ); + CPPUNIT_TEST( getError_001 ); + CPPUNIT_TEST( getError_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getError + + + + /** testing the methods: + inline oslSocket getHandle() const; + */ + + class getHandle : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + void getHandle_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::Socket assignSocket = sSocket.getHandle(); + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment_handle function: test the assignment operator.", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + void getHandle_002() + { + ::osl::Socket sSocket( sHandle ); + ::osl::Socket assignSocket ( sSocket.getHandle( ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment function: assignment operator", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( getHandle ); + CPPUNIT_TEST( getHandle_001 ); + CPPUNIT_TEST( getHandle_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getHandle + + +// ----------------------------------------------------------------------------- + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::ctors, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::operators, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::close, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getLocalAddr, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getLocalPort, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getLocalHost, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getPeer, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::bind, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::isRecvReady, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::isSendReady, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getType, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getOption, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::setOption, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::enableNonBlockingMode, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::isNonBlockingMode, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::clearError, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getError, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getHandle, "osl_Socket"); + +} // namespace osl_Socket + + + +namespace osl_StreamSocket +{ + + /** testing the methods: + inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet, + oslProtocol Protocol = osl_Socket_ProtocolIp, + oslSocketType Type = osl_Socket_TypeStream); + + inline StreamSocket( const StreamSocket & ); + + inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire ); + + inline StreamSocket( oslSocket Socket ); + */ + + class ctors : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void ctors_none() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_none constructor function: check if the stream socket was created successfully.", + osl_Socket_TypeStream == ssSocket.getType( ) ); + } + + void ctors_acquire() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( sHandle ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == ssSocket.getType( ) ); + } + + void ctors_no_acquire() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( sHandle, SAL_NO_ACQUIRE ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_no_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == ssSocket.getType( ) ); + } + + void ctors_copy_ctor() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + /// Socket copy constructor. + ::osl::StreamSocket copySocket( ssSocket ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_copy_ctor constructor function: create new Socket instance using copy constructor", + osl_Socket_TypeStream == copySocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_acquire ); + CPPUNIT_TEST( ctors_no_acquire ); + CPPUNIT_TEST( ctors_copy_ctor ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + class send_recv: public CppUnit::TestFixture + { + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + + } + + void send_recv1() + { + //client sent two strings, and server received, check the order and value + ServerSocketThread myServerThread; + ClientSocketThread myClientThread; + myServerThread.create( ); + myClientThread.create( ); + + //wait until the thread terminate + myClientThread.join( ); + myServerThread.join( ); + sal_Char myStr[30] = ""; + strcat( myStr, pTestString1 ); + strcat( myStr, pTestString2 ); + sal_Int32 nRes = strcmp( myServerThread.pReadBuffer, myStr ); + CPPUNIT_ASSERT_MESSAGE(" test for send/recv with two threads: launch Server/Client threads, send data from client, check received data in Server thread.", + nRes == 0 ); + } + + // error when recv + void send_recv2() + { + ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + sal_Char pReadBuffer[30] = ""; + + ClientSocketThread myClientThread; + myClientThread.create( ); + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + + asAcceptorSocket.bind( saLocalSocketAddr ); + asAcceptorSocket.listen( 1 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection( ssStreamConnection ); + sal_Int32 nReadNumber = ssStreamConnection.recv( pReadBuffer, 11 ); + + myClientThread.join( ) ; + ssStreamConnection.close(); + asAcceptorSocket.close(); + CPPUNIT_ASSERT_MESSAGE(" test for send/recv, recv error!", nReadNumber == -1 ); + } + + void write_read(sal_Int32 _nBufferSize, int _nValue) + { + //client sent two strings, and server received, check the order and value + WriteSocketThread myServerThread(_nBufferSize, _nValue); + ReadSocketThread myClientThread(_nBufferSize, _nValue); + myServerThread.create( ); +// thread_sleep( 1 ); + myClientThread.create( ); + + //wait until the thread terminate + myClientThread.join( ); + myServerThread.join( ); + + //Maximum Packet Size is ( ARPANET, MILNET = 1007 Ethernet (10Mb) = 1500 + // Proteon PRONET = 2046), so here test read 4000 bytes + sal_Int32 nLength = myClientThread.getCount(); + bool bIsOk = myClientThread.isOk(); // check if the values are right. + + t_print("Length:=%d\n", nLength); + t_print(" bIsOk:=%d\n", bIsOk); + + CPPUNIT_ASSERT_MESSAGE(" test for write/read values with two threads: send data from server, check readed data in client.", + nLength == _nBufferSize && bIsOk == true); + } + + void write_read_001() + { + write_read(50, 10); + } + void write_read_002() + { + write_read(1024, 20); + } + void write_read_003() + { + write_read(4000, 1); + } + void write_read_004() + { + write_read(8192, 3); + } + + CPPUNIT_TEST_SUITE( send_recv ); + CPPUNIT_TEST( write_read_001 ); + CPPUNIT_TEST( write_read_002 ); + CPPUNIT_TEST( write_read_003 ); + CPPUNIT_TEST( write_read_004 ); + CPPUNIT_TEST( send_recv1 ); + CPPUNIT_TEST( send_recv2 ); +// CPPUNIT_TEST( write_read ); + CPPUNIT_TEST_SUITE_END(); + }; // class send_recv + +class SendClientThread : public ClientSocketThread +{ +protected: + + void SAL_CALL run( ) + { + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 5; + pTimeout->Nanosec = 0; + + if ( osl_Socket_Ok == csConnectorSocket.connect( saTargetSocketAddr, pTimeout )) + { + sal_Int32 nWrite1 = csConnectorSocket.write( pTestString1, 11 ); // "test socket" + + sal_Int32 nWrite2 = csConnectorSocket.write( pTestString2, strlen( pTestString2 ) + 1 ); + thread_sleep( 2 ); + csConnectorSocket.write( pTestString2, strlen( pTestString2 ) + 1 ); + t_print("nWrite1 is %d, nWrite2 is %d\n", nWrite1, nWrite2 ); + //thread_sleep( 1 ); + } + else + t_print("# SendClientThread: connect failed! \n"); + + csConnectorSocket.close(); + free( pTimeout ); + } + +}; + + class shutdown: public CppUnit::TestFixture + { + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + + } + + // similar to close_002 + void shutdown_001() + { +#if defined(LINUX) + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + AcceptorThread myAcceptorThread( asSocket, aHostIp1 ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + + //when accepting, shutdown the socket, the thread will not block for accepting + asSocket.shutdown(); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK( ) == sal_True ); +#endif + } + + void shutdown_002() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT9); + asSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: bind fail", asSocket.bind( saLocalSocketAddr ) == sal_True); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: listen fail", asSocket.listen( 1 ) == sal_True ); + sal_Char pReadBuffer[40]; + SendClientThread mySendThread; + mySendThread.create(); + + asSocket.enableNonBlockingMode( sal_False ); + ::osl::StreamSocket ssConnectionSocket; + oslSocketResult eResult = asSocket.acceptConnection( ssConnectionSocket ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: acceptConnection fail", eResult == osl_Socket_Ok ); + + /* set socket option SO_LINGER 0, so close immediatly */ + linger aLingerSet; + sal_Int32 nBufferLen = sizeof( struct linger ); + aLingerSet.l_onoff = 0; + aLingerSet.l_linger = 0; + + ssConnectionSocket.setOption( osl_Socket_OptionLinger, &aLingerSet, nBufferLen ); + thread_sleep( 1 ); + //sal_uInt32 nRecv1 = 0; + sal_Int32 nRead1 = ssConnectionSocket.read( pReadBuffer, 11 ); + + //shutdown read after client the first send complete + ssConnectionSocket.shutdown( osl_Socket_DirRead ); + + sal_Int32 nRead2 = ssConnectionSocket.read( pReadBuffer + nRead1, 12 ); + sal_Int32 nRead3 = ssConnectionSocket.read( pReadBuffer + nRead1 + nRead2, 12 ); + t_print("after read 2, nRead1 is %d, nRead2 is %d, nRead3 is %d \n", nRead1, nRead2, nRead3 ); + mySendThread.join(); + + ssConnectionSocket.close(); + asSocket.close(); + + /* on Linux, if send is before shutdown(DirRead), can read, nRecv2 still > 0, + http://dbforums.com/arch/186/2002/12/586417 + While on Solaris, after shutdown(DirRead), all read will return 0 + */ +#ifdef LINUX + CPPUNIT_ASSERT_MESSAGE( "test for shutdown read direction: the socket can not read(recv).", + nRead1 > 0 && nRead3 == 0 ); +#else + CPPUNIT_ASSERT_MESSAGE( "test for shutdown read direction: the socket can not read(recv).", + nRead1 > 0 && nRead2 == 0 && nRead3 == 0 ); +#endif + + } + + void shutdown_003() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT9); + asSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: bind fail", asSocket.bind( saLocalSocketAddr ) == sal_True); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: listen fail", asSocket.listen( 1 ) == sal_True ); + sal_Char pReadBuffer[40]; + SendClientThread mySendThread; + mySendThread.create(); + + asSocket.enableNonBlockingMode( sal_False ); + ::osl::StreamSocket ssConnectionSocket; + oslSocketResult eResult = asSocket.acceptConnection( ssConnectionSocket ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: acceptConnection fail", eResult == osl_Socket_Ok ); + + thread_sleep( 1 ); + //shutdown write after client the first send complete + ssConnectionSocket.shutdown( osl_Socket_DirWrite ); + + // recv should not shutdown + sal_Int32 nRead1 = ssConnectionSocket.read( pReadBuffer, 11 ); + + sal_Int32 nWrite = ssConnectionSocket.write( pReadBuffer, 11 ); + // still can read + sal_Int32 nRead3 = ssConnectionSocket.read( pReadBuffer + nRead1 , 12 ); + t_print("after read 2, nRead1 is %d, nWrite is %d, nRead3 is %d\n", nRead1, nWrite, nRead3 ); + mySendThread.join(); + ssConnectionSocket.close(); + asSocket.close(); + + CPPUNIT_ASSERT_MESSAGE( "test for shutdown read direction: the socket can not send(write).", + nRead1 > 0 && nWrite == 0 && nRead3 > 0); + + } + + CPPUNIT_TEST_SUITE( shutdown ); + CPPUNIT_TEST( shutdown_001 ); + CPPUNIT_TEST( shutdown_002 ); + CPPUNIT_TEST( shutdown_003 ); + CPPUNIT_TEST_SUITE_END(); + }; // class shutdown + + class isExceptionPending: public CppUnit::TestFixture + { + public: + void isExPending_001() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sal_Bool bOk = asSocket.isExceptionPending( pTimeout ); + free( pTimeout ); + + CPPUNIT_ASSERT_MESSAGE( "test for isExceptionPending.", + bOk == sal_False ); + } + + /**tester's comments: lack of a case that return sal_True, do not know when it will return sal_True*/ + + + CPPUNIT_TEST_SUITE( isExceptionPending ); + CPPUNIT_TEST( isExPending_001 ); + CPPUNIT_TEST_SUITE_END(); + }; // class isExceptionPending + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::ctors, "osl_StreamSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::send_recv, "osl_StreamSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::shutdown, "osl_StreamSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::isExceptionPending, "osl_StreamSocket"); + +} // namespace osl_StreamSocket + + +namespace osl_ConnectorSocket +{ + + /** testing the method: + ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet, + oslProtocol Protocol = osl_Socket_ProtocolIp, + oslSocketType Type = osl_Socket_TypeStream); + */ + + class ctors : public CppUnit::TestFixture + { + public: + void ctors_001() + { + /// Socket constructor. + ::osl::ConnectorSocket csSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the connector socket was created successfully.", + osl_Socket_TypeStream == csSocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + /** testing the method: + oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0); + */ + + class connect : public CppUnit::TestFixture + { + public: + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + // sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + // sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void connect_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT2 ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT2 ); + ::osl::SocketAddr saPeerSocketAddr( aHostIp2, IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + //asAcceptorSocket.enableNonBlockingMode( sal_True ); + //oslSocketResult eResultAccept = asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + //CPPUNIT_ASSERT_MESSAGE( "accept failed.", osl_Socket_Ok == eResultAccept ); + /// launch client socket + oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + CPPUNIT_ASSERT_MESSAGE( "connect failed.", osl_Socket_Ok == eResult ); + + /// get peer information + csConnectorSocket.getPeerAddr( saPeerSocketAddr );/// connected. + + CPPUNIT_ASSERT_MESSAGE( "test for connect function: try to create a connection with remote host. and check the setup address.", + ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) && + ( osl_Socket_Ok == eResult )); + } + //non-blocking mode connect? + void connect_002() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT3 ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT3 ); + ::osl::SocketAddr saPeerSocketAddr( aHostIp2, IP_PORT_FTP ); + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + csConnectorSocket.enableNonBlockingMode( sal_True ); + + oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + CPPUNIT_ASSERT_MESSAGE( "connect failed.", osl_Socket_InProgress == eResult || osl_Socket_Ok == eResult ); + + /// get peer information + csConnectorSocket.getPeerAddr( saPeerSocketAddr ); + + CPPUNIT_ASSERT_MESSAGE( "test for connect function: try to create a connection with remote host. and check the setup address.", + sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) ; + } + // really an error or just delayed + // how to design senarios that will return osl_Socket_Interrupted, osl_Socket_TimedOut + void connect_003() + { + ::osl::SocketAddr saTargetSocketAddr1( aHostIp1, IP_PORT_MYPORT3 ); + ::osl::SocketAddr saTargetSocketAddr2( aHostIpInval1, IP_PORT_MYPORT3 ); + + csConnectorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult1 = csConnectorSocket.connect( saTargetSocketAddr1, pTimeout ); + oslSocketResult eResult2 = csConnectorSocket.connect( saTargetSocketAddr2, pTimeout ); + CloseSocketThread myCloseThread( csConnectorSocket ); + oslSocketResult eResult3 = csConnectorSocket.connect( saTargetSocketAddr2, pTimeout ); + myCloseThread.join(); + CPPUNIT_ASSERT_MESSAGE( "connect should failed.", osl_Socket_Error == eResult1 && + osl_Socket_Error == eResult2 && osl_Socket_Error == eResult3 ); + + } + + // really an error in non-blocking mode + void connect_004() + { + ::osl::SocketAddr saTargetSocketAddr( aHostIpInval1, IP_PORT_MYPORT3 ); + + csConnectorSocket.enableNonBlockingMode( sal_True ); + + oslSocketResult eResult = csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + CPPUNIT_ASSERT_MESSAGE( "connect should failed.", osl_Socket_Error == eResult ); + } + /** here need a case: immediate connection, say in non-blocking mode connect return osl_Socket_Ok + */ + + CPPUNIT_TEST_SUITE( connect ); + CPPUNIT_TEST( connect_001 ); + CPPUNIT_TEST( connect_002 ); + CPPUNIT_TEST( connect_003 ); + CPPUNIT_TEST( connect_004 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class connect + + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ConnectorSocket::ctors, "osl_ConnectorSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_ConnectorSocket::connect, "osl_ConnectorSocket"); + +} // namespace osl_ConnectorSocket + + + +namespace osl_AcceptorSocket +{ + + /** testing the methods: + inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet, + oslProtocol Protocol = osl_Socket_ProtocolIp, + oslSocketType Type = osl_Socket_TypeStream); + */ + + class ctors : public CppUnit::TestFixture + { + public: + + void ctors_001() + { + /// Socket constructor. + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the acceptor socket was created successfully.", + osl_Socket_TypeStream == asSocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + +#if 0 + class operator_assign : public CppUnit::TestFixture + { + public: + + void assign_001() + { +#if defined(LINUX) + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::AcceptorSocket asSocketAssign( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + asSocket.setOption( osl_Socket_OptionReuseAddr, 1); + ::osl::SocketAddr saSocketAddr( aHostIp1, IP_PORT_MYPORT4 ); + asSocket.bind( saSocketAddr ); + + AcceptorThread myAcceptorThread( asSocketAssign, aHostIp1 ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + //when accepting, assign another socket to the socket, the thread will not be closed, so is blocking + asSocketAssign = asSocket; + + t_print("#asSocketAssign port number is %d\n", asSocketAssign.getLocalPort() ); + + asSocketAssign.shutdown(); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK() == sal_True ); + + +#endif /* LINUX */ + } + + + CPPUNIT_TEST_SUITE( operator_assign ); + CPPUNIT_TEST( assign_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class operator_assign +#endif + + /** testing the method: + inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1); + inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection); + inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr); + */ + + class listen_accept : public CppUnit::TestFixture + { + public: + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1); + // sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + // sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void listen_accept_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT3 ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT3 ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + CPPUNIT_ASSERT_MESSAGE( "test for listen_accept function: try to create a connection with remote host, using listen and accept.", + ( osl_Socket_Ok == eResult ) ); + } + + void listen_accept_002() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT4 ); + ::osl::SocketAddr saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT4 ); + ::osl::SocketAddr saPeerSocketAddr( aHostIp2, IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + oslSocketResult eResult = asAcceptorSocket.acceptConnection(ssConnection, saPeerSocketAddr); /// waiting for incoming connection... + + CPPUNIT_ASSERT_MESSAGE( "test for listen_accept function: try to create a connection with remote host, using listen and accept, accept with peer address.", + ( sal_True == bOK2 ) && + ( osl_Socket_Ok == eResult ) && + ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) ) ); + } + + void listen_accept_003() + { + + } + + CPPUNIT_TEST_SUITE( listen_accept ); + CPPUNIT_TEST( listen_accept_001 ); + CPPUNIT_TEST( listen_accept_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class listen_accept + + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::ctors, "osl_AcceptorSocket"); +//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::operator_assign, "osl_AcceptorSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_AcceptorSocket::listen_accept, "osl_AcceptorSocket"); + +} // namespace osl_AcceptorSocket + + +namespace osl_DatagramSocket +{ + + /** testing the methods: + inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet, + oslProtocol Protocol= osl_Socket_ProtocolIp, + oslSocketType Type= osl_Socket_TypeDgram); + */ + + class ctors : public CppUnit::TestFixture + { + public: + + void ctors_001() + { + /// Socket constructor. + ::osl::DatagramSocket dsSocket; + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_001 constructor function: check if the datagram socket was created successfully.", + osl_Socket_TypeDgram == dsSocket.getType( ) ); + } + + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + +/**thread do sendTo, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml +*/ +class TalkerThread : public Thread +{ +protected: + ::osl::SocketAddr saTargetSocketAddr; + ::osl::DatagramSocket dsSocket; + + void SAL_CALL run( ) + { + dsSocket.sendTo( saTargetSocketAddr, pTestString1, strlen( pTestString1 ) + 1 ); // "test socket" + dsSocket.shutdown(); + } + + void SAL_CALL onTerminated( ) + { + } + +public: + TalkerThread( ): + saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT9 ) + { + } + + ~TalkerThread( ) + { + if ( isRunning( ) ) + t_print("# error: TalkerThread not terminated normally.\n" ); + } +}; + +/**thread do listen, refer to http://www.coding-zone.co.uk/cpp/articles/140101networkprogrammingv.shtml +*/ +class ListenerThread : public Thread +{ +protected: + ::osl::SocketAddr saTargetSocketAddr; + ::osl::DatagramSocket dsSocket; + + void SAL_CALL run( ) + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT10 ); + dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + if ( dsSocket.bind( saLocalSocketAddr ) == sal_False ) + { + t_print("DatagramSocket bind failed \n"); + return; + } + //blocking mode: default + sal_Int32 nRecv = dsSocket.recvFrom( pRecvBuffer, 30, &saTargetSocketAddr); //strlen( pTestString2 ) + 1 + t_print("After recvFrom, nRecv is %d\n", nRecv); + } + + void SAL_CALL onTerminated( ) + { + } + +public: + sal_Char pRecvBuffer[30]; + ListenerThread( ): + saTargetSocketAddr( aHostIp1, IP_PORT_MYPORT10 ) + { + pRecvBuffer[0] = '\0'; + } + + ~ListenerThread( ) + { + if ( isRunning( ) ) + t_print("# error: ListenerThread not terminated normally.\n" ); + } + +}; + + /** testing the methods: + inline sal_Int32 DatagramSocket::recvFrom(void* pBuffer, sal_uInt32 BufferSize, + SocketAddr* pSenderAddr, oslSocketMsgFlag Flag ) + inline sal_Int32 DatagramSocket::sendTo( const SocketAddr& ReceiverAddr, + const void* pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag ) + */ + + class sendTo_recvFrom : public CppUnit::TestFixture + { + public: + + void sr_001() + { + ::osl::SocketAddr saLocalSocketAddr( aHostIp1, IP_PORT_MYPORT9 ); + ::osl::DatagramSocket dsSocket; + dsSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + dsSocket.bind( saLocalSocketAddr ); + + sal_Char pReadBuffer[30]; + TalkerThread myTalkThread; + myTalkThread.create(); + sal_Int32 nRecv = dsSocket.recvFrom( pReadBuffer, 30, &saLocalSocketAddr); + myTalkThread.join(); + //t_print("#received buffer is %s# \n", pReadBuffer); + + sal_Bool bOk = ( strcmp(pReadBuffer, pTestString1) == 0 ); + + CPPUNIT_ASSERT_MESSAGE( "test for sendTo/recvFrom function: create a talker thread and recvFrom in the main thread, check if the datagram socket can communicate successfully.", + nRecv > 0 && bOk == sal_True ); + } + + void sr_002() + { + ::osl::SocketAddr saListenSocketAddr( aHostIp1, IP_PORT_MYPORT10 ); + ::osl::DatagramSocket dsSocket; + + //listener thread construct a DatagramSocket, recvFrom waiting for data, then main thread sendto data + ListenerThread myListenThread; + myListenThread.create(); + //to grantee the recvFrom is before sendTo + thread_sleep( 1 ); + + sal_Int32 nSend = dsSocket.sendTo( saListenSocketAddr, pTestString2, strlen( pTestString2 ) + 1 ); + + CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo failed: nSend <= 0.", nSend > 0); + + myListenThread.join(); + //t_print("#received buffer is %s# \n", myListenThread.pRecvBuffer); + + sal_Bool bOk = ( strcmp( myListenThread.pRecvBuffer, pTestString2) == 0 ); + + CPPUNIT_ASSERT_MESSAGE( "test for sendTo/recvFrom function: create a listener thread and sendTo in the main thread, check if the datagram socket can communicate successfully.", + bOk == sal_True ); + } + + //sendTo error, return -1; recvFrom error, return -1 + void sr_003() + { + ::osl::SocketAddr saListenSocketAddr( aHostIpInval1, IP_PORT_MYPORT10 ); + ::osl::DatagramSocket dsSocket; + // Transport endpoint is not connected + sal_Int32 nSend = dsSocket.sendTo( saListenSocketAddr, pTestString2, strlen( pTestString2 ) + 1 ); + CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo should fail: nSend <= 0.", + nSend == -1 ); + } + + void sr_004() + { + ::osl::SocketAddr saListenSocketAddr1( aHostIpInval1, IP_PORT_MYPORT10 ); + ::osl::SocketAddr saListenSocketAddr2( aHostIp2, IP_PORT_MYPORT10 ); + ::osl::DatagramSocket dsSocket; + + dsSocket.enableNonBlockingMode( sal_True ); + + sal_Char pReadBuffer[30]; + //sal_Int32 nRecv1 = dsSocket.recvFrom( pReadBuffer, 30, &saListenSocketAddr1 ); + + // will block ? + CloseSocketThread myThread( dsSocket ); + myThread.create(); + sal_Int32 nRecv2 = dsSocket.recvFrom( pReadBuffer, 30, &saListenSocketAddr1 ); + myThread.join(); + //t_print("#nRecv1 is %d nRecv2 is %d\n", nRecv1, nRecv2 ); + CPPUNIT_ASSERT_MESSAGE( "DatagramSocket sendTo should fail: nSend <= 0.", + nRecv2 == -1 ); + } + + CPPUNIT_TEST_SUITE( sendTo_recvFrom ); + CPPUNIT_TEST( sr_001 ); + CPPUNIT_TEST( sr_002 ); + CPPUNIT_TEST( sr_003 ); + CPPUNIT_TEST( sr_004 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class sendTo_recvFrom + +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DatagramSocket::ctors, "osl_DatagramSocket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_DatagramSocket::sendTo_recvFrom, "osl_DatagramSocket"); + +} // namespace osl_DatagramSocket + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_Socket.xsce b/sal/qa/osl/socket/osl_Socket.xsce new file mode 100644 index 000000000000..38c02c8c75a3 --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket.xsce @@ -0,0 +1,5 @@ +osl_Socket.ctors.ctors_family_Ipx +osl_SocketAddr.getHostname.getHostname_002 + +osl_StreamSocket.send_recv.write_read_003 unxsols +osl_StreamSocket.send_recv.write_read_004 unxsols diff --git a/sal/qa/osl/socket/osl_Socket2.cxx b/sal/qa/osl/socket/osl_Socket2.cxx new file mode 100644 index 000000000000..a7b0ecfa1ef7 --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket2.cxx @@ -0,0 +1,1471 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Socket2.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; + */ + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> + +//#include "osl_Socket_Const.h" +#include "sockethelper.hxx" + +using namespace osl; +using namespace rtl; + +#define IP_PORT_FTP 21 +#define IP_PORT_TELNET 23 +#define IP_PORT_HTTP2 8080 +#define IP_PORT_INVAL 99999 +#define IP_PORT_POP3 110 +#define IP_PORT_NETBIOS 139 +#define IP_PORT_MYPORT 8881 +#define IP_PORT_MYPORT1 8882 +#define IP_PORT_MYPORT5 8886 +#define IP_PORT_MYPORT6 8887 +#define IP_PORT_MYPORT7 8895 +#define IP_PORT_MYPORT8 8896 +#define IP_PORT_MYPORT9 8897 + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +// just used to test socket::close() when accepting +class AcceptorThread : public Thread +{ + ::osl::AcceptorSocket asAcceptorSocket; + ::rtl::OUString aHostIP; + sal_Bool bOK; +protected: + void SAL_CALL run( ) + { + ::osl::SocketAddr saLocalSocketAddr( aHostIP, IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# AcceptorSocket bind address failed.\n" ) ; + return; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# AcceptorSocket listen address failed.\n" ) ; + return; + } + + asAcceptorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + bOK = sal_True; + t_print("AcceptorThread: acceptConnection failed! \n"); + } + } +public: + AcceptorThread(::osl::AcceptorSocket & asSocket, ::rtl::OUString const& aBindIP ) + : asAcceptorSocket( asSocket ), aHostIP( aBindIP ) + { + bOK = sal_False; + } + + sal_Bool isOK() { return bOK; } + + ~AcceptorThread( ) + { + if ( isRunning( ) ) + { + asAcceptorSocket.shutdown(); + t_print("# error: Acceptor thread not terminated.\n" ); + } + } +}; + +namespace osl_Socket +{ + + /** testing the methods: + inline Socket( ); + inline Socket( const Socket & socket ); + inline Socket( oslSocket socketHandle ); + inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire ); + */ + + /** test writer's comment: + + class Socket can not be initialized by its protected constructor, though the protected + constructor is the most convenient way to create a new socket. + it only allow the method of C function osl_createSocket like: + ::osl::Socket sSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, + osl_Socket_ProtocolIp ) ); + the use of C method lost some of the transparent of tester using C++ wrapper. + */ + + + class ctors : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void ctors_none() + { + /// Socket constructor. + // ::osl::Socket sSocket(); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_none constructor function: check if the socket was created successfully, if no exception occured", + 1 == 1 ); + } + + void ctors_acquire() + { + /// Socket constructor. + ::osl::Socket sSocket( sHandle ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + void ctors_no_acquire() + { + /// Socket constructor. + ::osl::Socket sSocket( sHandle, SAL_NO_ACQUIRE ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_no_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + void ctors_copy_ctor() + { + ::osl::Socket sSocket( sHandle ); + /// Socket copy constructor. + ::osl::Socket copySocket( sSocket ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_copy_ctor constructor function: create new Socket instance using copy constructor", + osl_Socket_TypeStream == copySocket.getType( ) ); + } + + void ctors_TypeRaw() + { +#ifdef WNT + oslSocket sHandleRaw = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp ); +// LLA: ? ::osl::Socket sSocket( sHandleRaw ); + CPPUNIT_ASSERT_MESSAGE( " type osl_Socket_TypeRaw socket create failed on UNX ", sHandleRaw != NULL); +#else + oslSocket sHandleRaw = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp ); + CPPUNIT_ASSERT_MESSAGE( " can't create socket with type osl_Socket_TypeRaw within UNX is ok.", sHandleRaw == NULL); +#endif + } + + void ctors_family_Ipx() + { + oslSocket sHandleIpx = osl_createSocket( osl_Socket_FamilyIpx, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + CPPUNIT_ASSERT_MESSAGE( " family osl_Socket_FamilyIpx socket create failed! ", sHandleIpx != NULL); + ::osl::Socket sSocket( sHandleIpx ); //, SAL_NO_ACQUIRE ); + t_print("#Type is %d \n", sSocket.getType( ) ); + + CPPUNIT_ASSERT_MESSAGE(" test for create new Socket instance that family is osl_Socket_FamilyIpx", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_acquire ); + CPPUNIT_TEST( ctors_no_acquire ); + CPPUNIT_TEST( ctors_copy_ctor ); + CPPUNIT_TEST( ctors_TypeRaw ); + CPPUNIT_TEST( ctors_family_Ipx ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + + /** testing the methods: + inline Socket& SAL_CALL operator= ( oslSocket socketHandle); + inline Socket& SAL_CALL operator= (const Socket& sock); + inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ; + inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const; + */ + + class operators : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + /** test writer's comment: + + the assignment operator does not support direct assinment like: + ::osl::Socket sSocket = sHandle. + */ + void operators_assignment_handle() + { + ::osl::Socket sSocket(sHandle); + ::osl::Socket assignSocket = sSocket.getHandle(); + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment_handle function: test the assignment operator.", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + void operators_assignment() + { + ::osl::Socket sSocket( sHandle ); + ::osl::Socket assignSocket = sSocket; + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment function: assignment operator", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + void operators_equal_handle_001() + { + /// Socket constructor. + ::osl::Socket sSocket( sHandle ); + ::osl::Socket equalSocket = sSocket; + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_handle_001 function: check equal.", + equalSocket == sHandle ); + } + + void operators_equal_handle_002() + { + /// Socket constructor. + ::osl::Socket equalSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ) ); + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_handle_001 function: check unequal.", + !( equalSocket == sHandle ) ); + } + + void operators_equal_001() + { + ::osl::Socket sSocket( sHandle ); + /// Socket copy constructor. + ::osl::Socket equalSocket( sSocket ); + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal function: check equal.", + equalSocket == sSocket ); + } + + void operators_equal_002() + { + ::osl::Socket sSocket( sHandle ); + /// Socket copy constructor. + ::osl::Socket equalSocket( osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ) ); + + CPPUNIT_ASSERT_MESSAGE(" test for operators_equal_002 function: check unequal.", + !( equalSocket == sSocket ) ); + } + + CPPUNIT_TEST_SUITE( operators ); + CPPUNIT_TEST( operators_assignment_handle ); + CPPUNIT_TEST( operators_assignment ); + CPPUNIT_TEST( operators_equal_handle_001 ); + CPPUNIT_TEST( operators_equal_handle_002 ); + CPPUNIT_TEST( operators_equal_001 ); + CPPUNIT_TEST( operators_equal_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class operators + + + /** testing the methods: + inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite ); + inline void SAL_CALL close(); + */ + + class close : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void close_001() + { + ::osl::Socket sSocket(sHandle); + sSocket.close(); + + CPPUNIT_ASSERT_MESSAGE( "test for close_001 function: this function is reserved for test.", + sSocket.getHandle() == sHandle ); + } + + void close_002() + { +//#if defined(LINUX) + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + AcceptorThread myAcceptorThread( asSocket, rtl::OUString::createFromAscii("127.0.0.1") ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + //when accepting, close the socket, the thread will not block for accepting + //man close:Any locks held on the file it was associated with, and owned by the process, are removed + asSocket.close(); + //thread_sleep( 2 ); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK() == sal_True ); +//#endif + } + + // to cover "if ( pSockAddrIn->sin_addr.s_addr == htonl(INADDR_ANY) )" in osl_closeSocket( ) + void close_003() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + AcceptorThread myAcceptorThread( asSocket, rtl::OUString::createFromAscii("0.0.0.0") ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + asSocket.close(); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK() == sal_True ); + } + + CPPUNIT_TEST_SUITE( close ); + CPPUNIT_TEST( close_001 ); + CPPUNIT_TEST( close_002 ); + CPPUNIT_TEST( close_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class close + + /** testing the method: + inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const; + */ + + class getLocalAddr : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + // get the Address of the local end of the socket + void getLocalAddr_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT8 ); + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + + sSocket.getLocalAddr( saLocalSocketAddr ); + + sal_Bool bOK = compareUString( saLocalSocketAddr.getHostname( 0 ), sSocket.getLocalHost() ) ; + + CPPUNIT_ASSERT_MESSAGE( "test for getLocalAddr function: first create a new socket, then a socket address, bind them, and check the address.", + sal_True == bOK ); + } + + + CPPUNIT_TEST_SUITE( getLocalAddr ); + CPPUNIT_TEST( getLocalAddr_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getLocalAddr + + + /** testing the method: + inline sal_Int32 SAL_CALL getLocalPort() const; + */ + + class getLocalPort : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getLocalPort_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT7 ); // aHostIp1 localhost + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + sal_Bool bOK = ( IP_PORT_MYPORT7 == sSocket.getLocalPort( ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getLocalPort function: first create a new socket, then a socket address, bind them, and check the port.", + sal_True == bOK ); + } + + /** test writer's comment: + + the invalid port number can not be set by giving invalid port number + such as 99999 or -1, it will convert to ( x mod 65535 ), so it will always be + valid, the only instance that the getLocalPort returns OSL_INVALID_PORT + is when saSocketAddr itself is an invalid one, that is , the IP or host name + can not be found, then the created socket address is not valid. + */ + void getLocalPort_002() + { + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("123.45.67.89"), IP_PORT_TELNET); +#ifdef WNT + ::osl::Socket sSocket(sHandle); + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); // sal_True); + sSocket.bind( saBindSocketAddr ); + //Invalid IP, so bind should fail + ::rtl::OUString suError = outputError(::rtl::OUString::valueOf(sSocket.getLocalPort( )), + ::rtl::OUString::valueOf((sal_Int32)OSL_INVALID_PORT), + "test for getLocalPort function: first create a new socket, then an invalid socket address, bind them, and check the port assigned."); + sal_Bool bOK = ( OSL_INVALID_PORT == sSocket.getLocalPort( ) ); + (void)bOK; +#else + //on Unix, if Addr is not an address of type osl_Socket_FamilyInet, it returns OSL_INVALID_PORT + ::rtl::OUString suError = ::rtl::OUString::createFromAscii( "on Unix, if Addr is not an address of type osl_Socket_FamilyInet, it returns OSL_INVALID_PORT, but can not create Addr of that case"); +#endif + CPPUNIT_ASSERT_MESSAGE( suError, sal_False ); + + } + + void getLocalPort_003() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( getLocalIP(), IP_PORT_INVAL); + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + ::rtl::OUString suError = outputError(::rtl::OUString::valueOf(sSocket.getLocalPort( )), + ::rtl::OUString::createFromAscii("34463"), + "test for getLocalPort function: first create a new socket, then an invalid socket address, bind them, and check the port assigned"); + sal_Bool bOK = ( sSocket.getLocalPort( ) >= 1 && sSocket.getLocalPort( ) <= 65535); + + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getLocalPort ); + CPPUNIT_TEST( getLocalPort_001 ); +// LLA: CPPUNIT_TEST( getLocalPort_002 ); + CPPUNIT_TEST( getLocalPort_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getLocalPort + + + /** testing the method: + inline ::rtl::OUString SAL_CALL getLocalHost() const; + + Mindyliu: on Linux, at first it will check the binded in /etc/hosts, if it has the binded IP, it will return the hostname in it; + else if the binded IP is "127.0.0.1", it will return "localhost", if it's the machine's ethernet ip such as "129.158.217.90", it + will return hostname of current processor such as "aegean.PRC.Sun.COM" + */ + + class getLocalHost : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getLocalHost_001() + { + ::osl::Socket sSocket(sHandle); + //port number from IP_PORT_HTTP1 to IP_PORT_MYPORT6, mindyliu + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT6 ); + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + ::rtl::OUString suError1 = ::rtl::OUString::createFromAscii("Socket bind fail:") + sSocket.getErrorAsString(); + CPPUNIT_ASSERT_MESSAGE( suError1, sal_True == bOK1 ); + sal_Bool bOK; + ::rtl::OUString suError; +#ifdef WNT + bOK = compareUString( sSocket.getLocalHost( ), getThisHostname( ) ) ; + suError = outputError(sSocket.getLocalHost( ), getThisHostname( ), +"test for getLocalHost function: create localhost socket and check name"); +#else + ::rtl::OUString aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) "localhost" ); + sal_Bool bRes1, bRes2; + bRes1 = compareUString( sSocket.getLocalHost( ), aUString ) ; + bRes2 = compareUString( sSocket.getLocalHost( ), saBindSocketAddr.getHostname(0) ) ; + bOK = bRes1 || bRes2; + suError = outputError(sSocket.getLocalHost( ), aUString, "test for getLocalHost function: create localhost socket and check name"); +#endif + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + void getLocalHost_002() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("123.45.67.89"), IP_PORT_POP3); + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sSocket.bind( saBindSocketAddr ); + //Invalid IP, so bind should fail + sal_Bool bOK = compareUString( sSocket.getLocalHost( ), rtl::OUString::createFromAscii("") ) ; + ::rtl::OUString suError = outputError(sSocket.getLocalHost( ), rtl::OUString::createFromAscii(""), "test for getLocalHost function: getLocalHost with invalid SocketAddr"); + + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getLocalHost ); + CPPUNIT_TEST( getLocalHost_001 ); + CPPUNIT_TEST( getLocalHost_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getLocalHost + + + /** testing the methods: + inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const; + inline sal_Int32 SAL_CALL getPeerPort() const; + inline ::rtl::OUString SAL_CALL getPeerHost() const; + */ + class getPeer : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void getPeer_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT ); + ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + /// launch server socket + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind '127.0.0.1' address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + /// get peer information + csConnectorSocket.getPeerAddr( saPeerSocketAddr );/// connected. + sal_Int32 peerPort = csConnectorSocket.getPeerPort( ); + ::rtl::OUString peerHost = csConnectorSocket.getPeerHost( ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPeer function: setup a connection and then get the peer address, port and host from client side.", + ( sal_True == compareSocketAddr( saPeerSocketAddr, saLocalSocketAddr ) )&& + ( sal_True == compareUString( peerHost, saLocalSocketAddr.getHostname( 0 ) ) ) && + ( peerPort == saLocalSocketAddr.getPort( ) )); + } + + + CPPUNIT_TEST_SUITE( getPeer ); + CPPUNIT_TEST( getPeer_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getPeer + + + /** testing the methods: + inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface); + */ + + + class bind : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void bind_001() + { + ::osl::Socket sSocket(sHandle); + //bind must use local IP address ---mindyliu + ::osl::SocketAddr saBindSocketAddr( getLocalIP(), IP_PORT_MYPORT5 ); + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "Socket bind fail.", sal_True == bOK1 ); + + sal_Bool bOK2 = compareUString( sSocket.getLocalHost( ), saBindSocketAddr.getHostname( ) ) ; + + sSocket.close(); + CPPUNIT_ASSERT_MESSAGE( "test for bind function: bind a valid address.", sal_True == bOK2 ); + } + + void bind_002() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("123.45.67.89"), IP_PORT_NETBIOS ); + ::osl::SocketAddr saLocalSocketAddr; + + sSocket.setOption( osl_Socket_OptionReuseAddr, 1); // sal_True); + sal_Bool bOK1 = sSocket.bind( saBindSocketAddr ); + sal_Bool bOK2 = compareUString( sSocket.getLocalHost( ), getThisHostname( ) ) ; + + CPPUNIT_ASSERT_MESSAGE( "test for bind function: bind a valid address.", + ( sal_False == bOK1 ) && ( sal_False == bOK2 ) ); + } + + CPPUNIT_TEST_SUITE( bind ); + CPPUNIT_TEST( bind_001 ); + CPPUNIT_TEST( bind_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class bind + + + /** testing the methods: + inline sal_Bool SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const; + + */ + class isRecvReady : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void isRecvReady_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT1 ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT1 ); + ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); // sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + /// is receive ready? + sal_Bool bOK3 = asAcceptorSocket.isRecvReady( pTimeout ); + + CPPUNIT_ASSERT_MESSAGE( "test for isRecvReady function: setup a connection and then check if it can transmit data.", + ( sal_True == bOK3 ) ); + } + + + CPPUNIT_TEST_SUITE( isRecvReady ); + CPPUNIT_TEST( isRecvReady_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class isRecvReady + + + /** testing the methods: + inline sal_Bool SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const; + */ + class isSendReady : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + TimeValue *pTimeout; + ::osl::AcceptorSocket asAcceptorSocket; + ::osl::ConnectorSocket csConnectorSocket; + + + // initialization + void setUp( ) + { + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + free( pTimeout ); + sHandle = NULL; + asAcceptorSocket.close( ); + csConnectorSocket.close( ); + } + + + void isSendReady_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT ); + ::osl::SocketAddr saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT ); + ::osl::SocketAddr saPeerSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// launch client socket + csConnectorSocket.connect( saTargetSocketAddr, pTimeout ); /// connecting to server... + + /// is send ready? + sal_Bool bOK3 = csConnectorSocket.isSendReady( pTimeout ); + + CPPUNIT_ASSERT_MESSAGE( "test for isSendReady function: setup a connection and then check if it can transmit data.", + ( sal_True == bOK3 ) ); + } + + + CPPUNIT_TEST_SUITE( isSendReady ); + CPPUNIT_TEST( isSendReady_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class isSendReady + + + /** testing the methods: + inline oslSocketType SAL_CALL getType() const; + + */ + + class getType : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getType_001() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.", + osl_Socket_TypeStream == sSocket.getType( ) ); + } + + void getType_002() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.", + osl_Socket_TypeDgram == sSocket.getType( ) ); + } + +#ifdef UNX + // mindy: since on LINUX and SOLARIS, Raw type socket can not be created, so do not test getType() here + // mindy: and add one test case to test creating Raw type socket--> ctors_TypeRaw() + void getType_003() + { + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.this is not passed in (LINUX, SOLARIS), the osl_Socket_TypeRaw, type socket can not be created.", + sal_True); + } +#else + void getType_003() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeRaw, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + CPPUNIT_ASSERT_MESSAGE( "test for getType function: get type of socket.", + osl_Socket_TypeRaw == sSocket.getType( ) ); + } +#endif + + CPPUNIT_TEST_SUITE( getType ); + CPPUNIT_TEST( getType_001 ); + CPPUNIT_TEST( getType_002 ); + CPPUNIT_TEST( getType_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getType + + + + /** testing the methods: + inline sal_Int32 SAL_CALL getOption( + oslSocketOption Option, + void* pBuffer, + sal_uInt32 BufferLen, + oslSocketOptionLevel Level= osl_Socket_LevelSocket) const; + + inline sal_Int32 getOption( oslSocketOption option ) const; + + */ + + class getOption : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + + } + + void tearDown( ) + { + sHandle = NULL; + } + + /** test writer's comment: + + in oslSocketOption, the osl_Socket_OptionType denote 1 as osl_Socket_TypeStream. + 2 as osl_Socket_TypeDgram, etc which is not mapping the oslSocketType enum. differ + in 1. + */ + + void getOption_001() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + sal_Int32 * pType = ( sal_Int32 * )malloc( sizeof ( sal_Int32 ) ); + *pType = 0; + sSocket.getOption( osl_Socket_OptionType, pType, sizeof ( sal_Int32 ) ); + sal_Bool bOK = ( SOCK_STREAM == *pType ); + // there is a TypeMap(socket.c) which map osl_Socket_TypeStream to SOCK_STREAM on UNX, and SOCK_STREAM != osl_Socket_TypeStream + //sal_Bool bOK = ( TYPE_TO_NATIVE(osl_Socket_TypeStream) == *pType ); + free( pType ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get type option of socket.", + sal_True == bOK ); + } + + // getsockopt error + void getOption_004() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + sal_Bool * pbDontRoute = ( sal_Bool * )malloc( sizeof ( sal_Bool ) ); + sal_Int32 nRes = sSocket.getOption( osl_Socket_OptionInvalid, pbDontRoute, sizeof ( sal_Bool ) ); + free( pbDontRoute ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get invalid option of socket, should return -1.", + nRes == -1 ); + } + + void getOption_simple_001() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + sal_Bool bOK = ( sal_False == sSocket.getOption( osl_Socket_OptionDontRoute ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get debug option of socket.", + sal_True == bOK ); + } + + void getOption_simple_002() + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeDgram, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + + sal_Bool bOK = ( sal_False == sSocket.getOption( osl_Socket_OptionDebug ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for getOption function: get debug option of socket.", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getOption ); + CPPUNIT_TEST( getOption_001 ); + CPPUNIT_TEST( getOption_004 ); + CPPUNIT_TEST( getOption_simple_001 ); + CPPUNIT_TEST( getOption_simple_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getOption + + + /** testing the methods: + inline sal_Bool SAL_CALL setOption( oslSocketOption Option, + void* pBuffer, + sal_uInt32 BufferLen, + oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const; + */ + + class setOption : public CppUnit::TestFixture + { + public: + TimeValue *pTimeout; +// LLA: maybe there is an error in the source, +// as long as I remember, if a derived class do not overload all ctors there is a problem. + + ::osl::AcceptorSocket asAcceptorSocket; + + void setUp( ) + { + + } + + void tearDown( ) + { + asAcceptorSocket.close( ); + } + + + // LLA: + // getSocketOption returns BufferLen, or -1 if something failed + + // setSocketOption returns sal_True, if option could stored + // else sal_False + + void setOption_001() + { + /// set and get option. + int nBufferLen = sizeof ( sal_Int32); + // LLA: SO_DONTROUTE expect an integer boolean, what ever it is, it's not sal_Bool! + + sal_Int32 * pbDontRouteSet = ( sal_Int32 * )malloc( sizeof ( sal_Int32 ) ); + *pbDontRouteSet = 1; // sal_True; + + sal_Int32 * pGetBuffer = ( sal_Int32 * )malloc( sizeof ( sal_Int32 ) ); + *pGetBuffer = 0; + + // maybe asAcceptorSocket is not right initialized + sal_Bool b1 = asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, pbDontRouteSet, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "setOption function failed.", ( sal_True == b1 ) ); + sal_Int32 n2 = asAcceptorSocket.getOption( osl_Socket_OptionDontRoute, pGetBuffer, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "getOption function failed.", ( n2 == nBufferLen ) ); + + // on Linux, the value of option is 1, on Solaris, it's 16, but it's not important the exact value, + // just judge it is zero or not! + sal_Bool bOK = ( 0 != *pGetBuffer ); + t_print("#setOption_001: getOption is %d \n", *pGetBuffer); + + // toggle check, set to 0 + *pbDontRouteSet = 0; + + sal_Bool b3 = asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, pbDontRouteSet, sizeof ( sal_Int32 ) ); + CPPUNIT_ASSERT_MESSAGE( "setOption function failed.", ( sal_True == b3 ) ); + sal_Int32 n4 = asAcceptorSocket.getOption( osl_Socket_OptionDontRoute, pGetBuffer, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "getOption (DONTROUTE) function failed.", ( n4 == nBufferLen ) ); + + sal_Bool bOK2 = ( 0 == *pGetBuffer ); + + t_print("#setOption_001: getOption is %d \n", *pGetBuffer); + +// LLA: sal_Bool * pbDontTouteSet = ( sal_Bool * )malloc( sizeof ( sal_Bool ) ); +// LLA: *pbDontTouteSet = sal_True; +// LLA: sal_Bool * pbDontTouteGet = ( sal_Bool * )malloc( sizeof ( sal_Bool ) ); +// LLA: *pbDontTouteGet = sal_False; +// LLA: asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, pbDontTouteSet, sizeof ( sal_Bool ) ); +// LLA: asAcceptorSocket.getOption( osl_Socket_OptionDontRoute, pbDontTouteGet, sizeof ( sal_Bool ) ); +// LLA: ::rtl::OUString suError = outputError(::rtl::OUString::valueOf((sal_Int32)*pbDontTouteGet), +// LLA: ::rtl::OUString::valueOf((sal_Int32)*pbDontTouteSet), +// LLA: "test for setOption function: set osl_Socket_OptionDontRoute and then check"); +// LLA: +// LLA: sal_Bool bOK = ( sal_True == *pbDontTouteGet ); +// LLA: free( pbDontTouteSet ); +// LLA: free( pbDontTouteGet ); + + CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check.", + ( sal_True == bOK ) && (sal_True == bOK2) ); + + free( pbDontRouteSet ); + free( pGetBuffer ); +// LLA: CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + void setOption_002() + { + /// set and get option. + + // sal_Int32 * pbLingerSet = ( sal_Int32 * )malloc( nBufferLen ); + // *pbLingerSet = 7; + // sal_Int32 * pbLingerGet = ( sal_Int32 * )malloc( nBufferLen ); + /* struct */linger aLingerSet; + sal_Int32 nBufferLen = sizeof( struct linger ); + aLingerSet.l_onoff = 1; + aLingerSet.l_linger = 7; + + linger aLingerGet; + + asAcceptorSocket.setOption( osl_Socket_OptionLinger, &aLingerSet, nBufferLen ); + + sal_Int32 n1 = asAcceptorSocket.getOption( osl_Socket_OptionLinger, &aLingerGet, nBufferLen ); + CPPUNIT_ASSERT_MESSAGE( "getOption (SO_LINGER) function failed.", ( n1 == nBufferLen ) ); + + //t_print("#setOption_002: getOption is %d \n", aLingerGet.l_linger); + sal_Bool bOK = ( 7 == aLingerGet.l_linger ); + CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check. ", + sal_True == bOK ); + + } + + void setOption_003() + { + linger aLingerSet; + aLingerSet.l_onoff = 1; + aLingerSet.l_linger = 7; + + sal_Bool b1 = asAcceptorSocket.setOption( osl_Socket_OptionLinger, &aLingerSet, 0 ); + printUString( asAcceptorSocket.getErrorAsString( ) ); + CPPUNIT_ASSERT_MESSAGE( "setOption (SO_LINGER) function failed for optlen is 0.", + ( b1 == sal_False ) ); + } + + void setOption_simple_001() + { + /// set and get option. + asAcceptorSocket.setOption( osl_Socket_OptionDontRoute, 1 ); //sal_True ); + sal_Bool bOK = ( 0 != asAcceptorSocket.getOption( osl_Socket_OptionDontRoute ) ); + + t_print("setOption_simple_001(): getoption is %d \n", asAcceptorSocket.getOption( osl_Socket_OptionDontRoute ) ); + CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check.", + ( sal_True == bOK ) ); + } + + void setOption_simple_002() + { + /// set and get option. + // LLA: this does not work, due to the fact that SO_LINGER is a structure +// LLA: asAcceptorSocket.setOption( osl_Socket_OptionLinger, 7 ); +// LLA: sal_Bool bOK = ( 7 == asAcceptorSocket.getOption( osl_Socket_OptionLinger ) ); + +// LLA: CPPUNIT_ASSERT_MESSAGE( "test for setOption function: set option of a socket and then check.", +// LLA: ( sal_True == bOK ) ); + } + + CPPUNIT_TEST_SUITE( setOption ); + CPPUNIT_TEST( setOption_001 ); + CPPUNIT_TEST( setOption_002 ); + CPPUNIT_TEST( setOption_003 ); + CPPUNIT_TEST( setOption_simple_001 ); +// LLA: CPPUNIT_TEST( setOption_simple_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class setOption + + + + /** testing the method: + inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode); + */ + class enableNonBlockingMode : public CppUnit::TestFixture + { + public: + ::osl::AcceptorSocket asAcceptorSocket; + + void enableNonBlockingMode_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// if reach this statement, it is non-blocking mode, since acceptConnection will blocked by default. + sal_Bool bOK = sal_True; + asAcceptorSocket.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for enableNonBlockingMode function: launch a server socket and make it non blocking. if it can pass the acceptConnection statement, it is non-blocking", + ( sal_True == bOK ) ); + } + + + CPPUNIT_TEST_SUITE( enableNonBlockingMode ); + CPPUNIT_TEST( enableNonBlockingMode_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class enableNonBlockingMode + + + /** testing the method: + inline sal_Bool SAL_CALL isNonBlockingMode() const; + */ + class isNonBlockingMode : public CppUnit::TestFixture + { + public: + ::osl::AcceptorSocket asAcceptorSocket; + + void isNonBlockingMode_001() + { + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT ); + ::osl::StreamSocket ssConnection; + + /// launch server socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); // sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket bind address failed.", sal_True == bOK1 ); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + CPPUNIT_ASSERT_MESSAGE( "AcceptorSocket listen failed.", sal_True == bOK2 ); + + sal_Bool bOK3 = asAcceptorSocket.isNonBlockingMode( ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + asAcceptorSocket.acceptConnection(ssConnection); /// waiting for incoming connection... + + /// if reach this statement, it is non-blocking mode, since acceptConnection will blocked by default. + sal_Bool bOK4 = asAcceptorSocket.isNonBlockingMode( ); + asAcceptorSocket.close( ); + + CPPUNIT_ASSERT_MESSAGE( "test for isNonBlockingMode function: launch a server socket and make it non blocking. it is expected to change from blocking mode to non-blocking mode.", + ( sal_False == bOK3 ) && ( sal_True == bOK4 ) ); + } + + + CPPUNIT_TEST_SUITE( isNonBlockingMode ); + CPPUNIT_TEST( isNonBlockingMode_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class isNonBlockingMode + + /** testing the method: + inline void SAL_CALL clearError() const; + */ + class clearError : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void clearError_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("123.45.67.89"), IP_PORT_HTTP2 ); + ::osl::SocketAddr saLocalSocketAddr; + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sSocket.bind( saBindSocketAddr );//build an error "osl_Socket_E_AddrNotAvail" + oslSocketError seBind = sSocket.getError( ); + sSocket.clearError( ); + + CPPUNIT_ASSERT_MESSAGE( "test for clearError function: trick an error called sSocket.getError( ), and then clear the error states, check the result.", + osl_Socket_E_None == sSocket.getError( ) && seBind != osl_Socket_E_None ); + } + + + CPPUNIT_TEST_SUITE( clearError ); + CPPUNIT_TEST( clearError_001 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class clearError + + + /** testing the methods: + inline oslSocketError getError() const; + inline ::rtl::OUString getErrorAsString( ) const; + */ + class getError : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void getError_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); + ::osl::SocketAddr saLocalSocketAddr; + + CPPUNIT_ASSERT_MESSAGE( "test for getError function: should get no error.", + osl_Socket_E_None == sSocket.getError( ) ); + } + + void getError_002() + { + ::osl::Socket sSocket(sHandle); + ::osl::SocketAddr saBindSocketAddr( rtl::OUString::createFromAscii("123.45.67.89"), IP_PORT_FTP ); + ::osl::SocketAddr saLocalSocketAddr; + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + sSocket.bind( saBindSocketAddr );//build an error "osl_Socket_E_AddrNotAvail" + //on Solaris, the error no is EACCES, but it has no mapped value, so getError() returned osl_Socket_E_InvalidError. +#if defined(SOLARIS) + CPPUNIT_ASSERT_MESSAGE( "trick an error called sSocket.getError( ), check the getError result.Failed on Solaris, returned osl_Socket_E_InvalidError because no entry to map the errno EACCES. ", + osl_Socket_E_InvalidError == sSocket.getError( ) ); +#else + //while on Linux & Win32, the errno is EADDRNOTAVAIL, getError returned osl_Socket_E_AddrNotAvail. + + CPPUNIT_ASSERT_MESSAGE( "trick an error called sSocket.getError( ), check the getError result.Failed on Solaris, returned osl_Socket_E_InvalidError because no entry to map the errno EACCES. Passed on Linux & Win32", + osl_Socket_E_AddrNotAvail == sSocket.getError( ) ); +#endif + } + + CPPUNIT_TEST_SUITE( getError ); + CPPUNIT_TEST( getError_001 ); + CPPUNIT_TEST( getError_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getError + + + + /** testing the methods: + inline oslSocket getHandle() const; + */ + + class getHandle : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + void getHandle_001() + { + ::osl::Socket sSocket(sHandle); + ::osl::Socket assignSocket = sSocket.getHandle(); + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment_handle function: test the assignment operator.", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + void getHandle_002() + { + ::osl::Socket sSocket( sHandle ); + ::osl::Socket assignSocket ( sSocket.getHandle( ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for operators_assignment function: assignment operator", + osl_Socket_TypeStream == assignSocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( getHandle ); + CPPUNIT_TEST( getHandle_001 ); + CPPUNIT_TEST( getHandle_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getHandle + + +// ----------------------------------------------------------------------------- + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::ctors, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::operators, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::close, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getLocalAddr, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getLocalPort, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getLocalHost, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getPeer, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::bind, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::isRecvReady, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::isSendReady, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getType, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getOption, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::setOption, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::enableNonBlockingMode, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::isNonBlockingMode, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::clearError, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getError, "osl_Socket"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::getHandle, "osl_Socket"); + +} // namespace osl_Socket + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_Socket2.xsce b/sal/qa/osl/socket/osl_Socket2.xsce new file mode 100644 index 000000000000..66e3bf1379ec --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket2.xsce @@ -0,0 +1,2 @@ +osl_Socket.ctors.ctors_family_Ipx +osl_Socket.getLocalHost.getLocalHost_001 wntmsci diff --git a/sal/qa/osl/socket/osl_SocketAddr.cxx b/sal/qa/osl/socket/osl_SocketAddr.cxx new file mode 100644 index 000000000000..63ca58f67936 --- /dev/null +++ b/sal/qa/osl/socket/osl_SocketAddr.cxx @@ -0,0 +1,898 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_SocketAddr.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; + */ + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> + +//#include "osl_Socket_Const.h" +#include "sockethelper.hxx" + +using namespace osl; +using namespace rtl; + +#define IP_PORT_ZERO 0 +#define IP_PORT_FTP 21 +#define IP_PORT_TELNET 23 +#define IP_PORT_HTTP1 80 +#define IP_PORT_HTTP2 8080 + +#define IP_PORT_MYPORT 8881 //8888 +#define IP_PORT_MYPORT2 8883 //8890 +#define IP_PORT_MYPORT3 8884 //8891 +#define IP_PORT_INVAL 99999 +#define IP_PORT_MYPORT4 8885 //8892 +#define IP_PORT_NETBIOS_DGM 138 + + +namespace osl_SocketAddr +{ + + /** testing the methods: + inline SocketAddr(); + inline SocketAddr(const SocketAddr& Addr); + inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy ); + inline SocketAddr(oslSocketAddr Addr); + inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort ); + */ + + class ctors : public CppUnit::TestFixture + { + public: + + void ctors_none() + { + /// SocketAddr constructor. + ::osl::SocketAddr saSocketAddr; + + // oslSocketResult aResult; + // rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); + + // rtl::OUString suHost2 = getThisHostname(); + + CPPUNIT_ASSERT_MESSAGE("test for none parameter constructor function: check if the socket address was created successfully", + sal_True == saSocketAddr.is( ) ); + } + + void ctors_none_000() + { + /// SocketAddr constructor. + ::osl::SocketAddr saSocketAddr; + + oslSocketResult aResult; + rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); + rtl::OUString suHost2 = getThisHostname(); + + sal_Bool bOk = compareUString(suHost, suHost2); + + rtl::OUString suError = rtl::OUString::createFromAscii("Host names should be the same. From SocketAddr.getLocalHostname() it is'"); + suError += suHost; + suError += rtl::OUString::createFromAscii("', from getThisHostname() it is '"); + suError += suHost2; + suError += rtl::OUString::createFromAscii("'."); + + CPPUNIT_ASSERT_MESSAGE(suError, sal_True == bOk); + } + + void ctors_copy() + { + /// SocketAddr copy constructor. + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + ::osl::SocketAddr saCopySocketAddr( saSocketAddr ); + + sal_Int32 nPort = saCopySocketAddr.getPort( ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy constructor function: copy constructor, do an action of copy construction then check the port with original set.", + ( sal_True == saCopySocketAddr.is( ) ) && ( nPort == IP_PORT_HTTP1 ) ); + } + + void ctors_copy_no_001() + { +#if 0 + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); + + ::osl::SocketAddr saSocketAddrCopy( psaOSLSocketAddr, SAL_NO_COPY ); + saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + saSocketAddr.getPort( ) == IP_PORT_HTTP2 ); +#endif + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + + oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); + + ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); + + pSocketAddrCopy->setPort( IP_PORT_HTTP2 ); + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddr->getPort( ) == IP_PORT_HTTP2 ); + + delete pSocketAddrCopy; + // LLA: don't do this also: delete pSocketAddr; + } + + void ctors_copy_no_002() + { + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); + ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) ); + + delete pSocketAddrCopy; + } + + void ctors_copy_handle_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, get its port to check copy effect.", + saSocketAddrCopy.getPort( ) == IP_PORT_HTTP1 ); + } + + void ctors_copy_handle_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); + saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, the original one should not be changed.", + saSocketAddr.getPort( ) != IP_PORT_HTTP2 ); + } + + void ctors_hostname_port_001() + { + /// tcpip-specif constructor. + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); + printUString( saSocketAddr.getHostname( ), "ctors_hostname_port_001:getHostname"); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specif constructor function: do a constructor using tcpip spec, check the result.", + saSocketAddr.is( ) == sal_True && + ( saSocketAddr.getPort( ) == IP_PORT_FTP )/*&& + ( sal_True == compareUString( saSocketAddr.getHostname( ), aHostName1 ) ) */); + } + + //same as is_002 + void ctors_hostname_port_002() + { + /// tcpip-specif constructor. + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT2 ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specif constructor function: using an invalid IP address, the socketaddr ctors should fail", sal_False == saSocketAddr.is( )); + } + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_none_000 ); + CPPUNIT_TEST( ctors_copy ); + CPPUNIT_TEST( ctors_copy_no_001 ); + CPPUNIT_TEST( ctors_copy_no_002 ); + CPPUNIT_TEST( ctors_copy_handle_001 ); + CPPUNIT_TEST( ctors_copy_handle_002 ); + CPPUNIT_TEST( ctors_hostname_port_001 ); + CPPUNIT_TEST( ctors_hostname_port_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + + /** testing the method: + inline sal_Bool is() const; + */ + + class is : public CppUnit::TestFixture + { + public: + void is_001() + { + ::osl::SocketAddr saSocketAddr; + + CPPUNIT_ASSERT_MESSAGE("test for is() function: create an unknown type socket, it should be True when call is.", + sal_True == saSocketAddr.is( ) ); + } + // refer to setPort_003() + void is_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_INVAL ); + + CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid port number", + sal_True == saSocketAddr.is( ) ); + } + + void is_003() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT ); + + CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid Ip number", + sal_True != saSocketAddr.is( ) ); + } + + CPPUNIT_TEST_SUITE( is ); + CPPUNIT_TEST( is_001 ); + CPPUNIT_TEST( is_002 ); + CPPUNIT_TEST( is_003 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class is + + + /** testing the method: + inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const; + */ + + class getHostname : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void tearDown() + { + } + + void getHostname_000() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.107"), IP_PORT_FTP ); + rtl::OUString suResult = saSocketAddr.getHostname( 0 ); + + } + + /** it will search the Ip in current machine's /etc/hosts at first, if find, then return the + mapped hostname, otherwise, it will search via DNS server, and often return hostname+ Domain name + like "sceri.PRC.Sun.COM" + The process is same as Socket::getLocalHost(), but getLocalHost can only return hostname of the current machine. + */ + void getHostname_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.107"), IP_PORT_FTP ); + rtl::OUString suResult = saSocketAddr.getHostname( 0 ); + rtl::OUString suError = outputError(suResult, rtl::OUString::createFromAscii("sceri.PRC.Sun.COM"), "test for getHostname(0)"); + sal_Bool bOK = compareUString( suResult, rtl::OUString::createFromAscii("sceri.PRC.Sun.COM") ); + // search the returned hostname in /etc/hosts, if find, and the IP in the row is same as IP + // in the Addr, it's right also. + if ( bOK == sal_False) + { + rtl::OString aString = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); + if ( compareUString( getIPbyName( aString ), rtl::OUString::createFromAscii("129.158.217.107") ) == sal_True ) + bOK = sal_True; + } + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK); + } + +// LLA: now we have to control, if this behaviour is right. +// LLA: this function does not work in company (Linux, Windows) but at home + void getHostname_002() + { + rtl::OUString suHostname = rtl::OUString::createFromAscii("cn-1.germany.sun.com"); + rtl::OString aString = ::rtl::OUStringToOString( suHostname, RTL_TEXTENCODING_ASCII_US ); + rtl::OUString aHostIP = getIPbyName( aString ); + + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_FTP ); + sal_Bool bOK = saSocketAddr.setHostname( suHostname ); + CPPUNIT_ASSERT_MESSAGE("#SocketAddr.setHostname failed", sal_True == bOK ); + oslSocketResult aResult; + rtl::OUString suResult = saSocketAddr.getHostname( &aResult ); + CPPUNIT_ASSERT_MESSAGE("SocketAddr.getHostname failed.", aResult == osl_Socket_Ok); + + rtl::OUString suError = outputError(suResult, suHostname, "test for getHostname(0)"); + bOK = compareUString( suResult, suHostname ); + if ( bOK == sal_False) + { + rtl::OString aStringResult = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); + rtl::OString aStringHostname = ::rtl::OUStringToOString( suHostname, RTL_TEXTENCODING_ASCII_US ); + if ( compareUString( getIPbyName( aStringResult ) , getIPbyName( aStringHostname ) ) == sal_True ) + { + bOK = sal_True; + } + } + + CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); + } + + + CPPUNIT_TEST_SUITE( getHostname ); + CPPUNIT_TEST( getHostname_001 ); + CPPUNIT_TEST( getHostname_002 ); + CPPUNIT_TEST_SUITE_END(); + + }; // class getHostname + + + /** testing the method: + inline sal_Int32 SAL_CALL getPort() const; + */ + + class getPort : public CppUnit::TestFixture + { + public: + void getPort_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPort() function: get a normal port number.", + IP_PORT_FTP == saSocketAddr.getPort( ) ); + } + + void getPort_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_INVAL ); + + //t_print("#getPort_002: Port number is %d \n", saSocketAddr.getPort( )); + + CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid port to a SocketAddr, get the port to see if it can detect. it did not pass in (W32).", + saSocketAddr.getPort( )>=1 && saSocketAddr.getPort( ) <= 65535 ); + } + //two cases will return OSL_INVALID_PORT: 1. not valid SocketAddr + //2. SocketAddr family is not osl_Socket_FamilyInet, but case 2 could not be constructed + void getPort_003() + { + rtl::OUString suInvalidIP = rtl::OUString::createFromAscii("123.345.67.89"); + ::osl::SocketAddr saSocketAddr( suInvalidIP, IP_PORT_MYPORT ); + + CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid IP to a SocketAddr, get the port to see returned value. ", + saSocketAddr.getPort( ) == OSL_INVALID_PORT ); + } + + CPPUNIT_TEST_SUITE( getPort ); + CPPUNIT_TEST( getPort_001 ); + CPPUNIT_TEST( getPort_002 ); + CPPUNIT_TEST( getPort_003 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getPort + + + /** testing the method: + inline sal_Bool SAL_CALL setPort( sal_Int32 nPort ); + rfc1413.txt: TCP port numbers are from 1-65535 + rfc1700.txt: 0/tcp Reserved ; 0/udp Reserved + */ + + class setPort : public CppUnit::TestFixture + { + public: + void setPort_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_TELNET ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: modify a port number setting, and check it.", + ( sal_True == bOK ) && + ( IP_PORT_TELNET == saSocketAddr.getPort( ) ) ); + } + + /** 0 to 1024 is known as the reserved port range (traditionally only root can assign programs to ports in + this range) and the ephemeral port range from 1025 to 65535. + As many of you programmers will know, when you specify the source port of 0 when you connect to a host, + the OS automatically reassigns the port number to high numbered ephemeral port. The same happens if you + try to bind a listening socket to port 0. + http://www.securiteam.com/securityreviews/5XP0Q2AAKS.html + another: http://www.muq.org/~cynbe/muq/mufref_564.html + */ + void setPort_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_ZERO ); + + oslSocket sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + ::osl::Socket sSocket(sHandle); + sSocket.setOption( osl_Socket_OptionReuseAddr, 1 );//sal_True); + sal_Bool bOK1 = sSocket.bind( saSocketAddr ); + CPPUNIT_ASSERT_MESSAGE( "bind SocketAddr failed", bOK1 == sal_True ); + + sal_Int32 newPort = sSocket.getLocalPort(); + //t_print("#new port is %d\n", newPort ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: port number should be in 1 ~ 65535, set port 0, it should be converted to a port number between 1024~65535.", + ( 1024 <= newPort ) && ( 65535 >= newPort ) && ( bOK == sal_True ) ); + + } + + void setPort_003() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_INVAL ); + //on Linux, getPort return 34463 + //t_print("#Port number is %d \n", saSocketAddr.getPort( )); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an address with invalid port. it should return error or convert it to a valid port.", + ( ( 1 <= saSocketAddr.getPort( ) ) && ( 65535 >= saSocketAddr.getPort( ) ) &&( bOK == sal_True ) ) || + bOK == sal_False); + } + + /* this is not a inet-addr => can't set port */ + void setPort_004() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_FTP); + sal_Bool bOK = saSocketAddr.setPort( IP_PORT_MYPORT ); + + CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an invalid address with valid port. it should return error.", + bOK == sal_False); + } + + + CPPUNIT_TEST_SUITE( setPort ); + CPPUNIT_TEST( setPort_001 ); + CPPUNIT_TEST( setPort_002 ); + CPPUNIT_TEST( setPort_003 ); + CPPUNIT_TEST( setPort_004 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class setPort + + + /** tester comment: + + In the following two functions, it use ::rtl::ByteSequence as an intermediate storage for address, + the ByteSequence object can hold sal_Int8 arrays, which is raged [-127, 127], in case of IP addr + that is greater than 127, say 129.158.217.202, it will stored as -127, -98, -39, -54, it is unique + in the range of sal_Int8, but lack of readability. + so may be a sal_uInt8 array is better. + */ + + + /** testing the method: + inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address ); + */ + + class setAddr : public CppUnit::TestFixture + { + public: + void setAddr_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + saSocketAddr.setAddr( UStringIPToByteSequence( rtl::OUString::createFromAscii("127.0.0.1") ) ); + ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); + sal_Bool bOK = sal_False; + + // if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) && ( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + // bOK = sal_True; + bOK = ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for setAddr() function: construct Addr with \"129.158.217.202\", set it to \"127.0.0.1\", and check the correctness ", + sal_True == bOK ); + } + + + CPPUNIT_TEST_SUITE( setAddr ); + CPPUNIT_TEST( setAddr_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class setAddr + + + /** testing the method: + inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const; + */ + + class getAddr : public CppUnit::TestFixture + { + public: + void getAddr_001() + { + oslSocketResult SocketResult; + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); + ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( &SocketResult ); + + sal_Bool bOK = sal_False; + + //if ( ( osl_Socket_Ok == SocketResult ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + // bOK = sal_True; + bOK = ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for getAddr() function: construct a socketaddr with IP assigned, get the address to check correctness.Caught unknown exception on (Win32)", + sal_True == bOK && SocketResult == osl_Socket_Ok); + } + + CPPUNIT_TEST_SUITE( getAddr ); + CPPUNIT_TEST( getAddr_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getAddr + + + /** testing the methods: + inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr); + inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr); + inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy ); + inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const; + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; /// not implemented. + */ + + class operator_equal : public CppUnit::TestFixture + { + public: + void operator_equal_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + sal_Bool bOK = sal_False; + ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); + + // if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) && ( ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ) == sal_True ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: use operator= to assign Ip1 to Ip2, check its modification.", + sal_True == bOK ); + } + + + void operator_equal_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.199"), IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + CPPUNIT_ASSERT_MESSAGE( "after assign, the assigned SocketAddr is not same as the original Addr", + IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ); + saSocketAddrEqual.setPort( IP_PORT_MYPORT3 ); + saSocketAddr.setPort( IP_PORT_HTTP2 ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: perform an equal action, then try to change the original address's port. it should not be changed ( handle released), it did not pass in (W32), this is under discussion.", + IP_PORT_MYPORT3 == saSocketAddrEqual.getPort( ) ); + } + + void operator_equal_const_001() + { + const ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + sal_Bool bOK = sal_False; + ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); + + // if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) && ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ) == sal_True ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: use operator= const to assign Ip1 to Ip2, verify the change on the second one.", + sal_True == bOK ); + } + + void operator_equal_const_002() + { + const ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + + saSocketAddrEqual = saSocketAddr; + saSocketAddrEqual.setPort( IP_PORT_HTTP1 ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: change the second instance, the first one should not be altered, since it does not released the handle.", + IP_PORT_HTTP1 != saSocketAddr.getPort( ) ); + } + + void operator_equal_assign_001() + { + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + ::osl::SocketAddr* pSocketAddrAssign = new ::osl::SocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); + oslSocketAddr poslSocketAddr = pSocketAddr->getHandle( ); + //if( m_handle ) osl_destroySocketAddr( m_handle ); so pSocketAddrAssign had been destroyed and then point to pSocketAddr + pSocketAddrAssign->assign(poslSocketAddr, SAL_NO_COPY); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddrAssign->getPort( ) == IP_PORT_TELNET ); + + delete pSocketAddrAssign; + } + + void operator_is_equal_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); + ::osl::SocketAddr saSocketAddrequal( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two identical Address.", + sal_True == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) ); + } + + void operator_is_equal_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP); + ::osl::SocketAddr saSocketAddrequal( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); + + CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two different Address.", + sal_False == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) ); + } + + CPPUNIT_TEST_SUITE( operator_equal ); + CPPUNIT_TEST( operator_equal_001 ); + CPPUNIT_TEST( operator_equal_002 ); + CPPUNIT_TEST( operator_equal_const_001 ); + CPPUNIT_TEST( operator_equal_const_002 ); + CPPUNIT_TEST( operator_equal_assign_001 ); + CPPUNIT_TEST( operator_is_equal_001 ); + CPPUNIT_TEST( operator_is_equal_002 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class operator_equal + + + + /** testing the method: + inline oslSocketAddr SAL_CALL getHandle() const; + */ + + class getSocketAddrHandle : public CppUnit::TestFixture + { + public: + + void getSocketAddrHandle_001() + { + ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); + oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); + ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); + + CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", + pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) ); + + delete pSocketAddrCopy; + } + + void getSocketAddrHandle_002() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("deuce.PRC.Sun.COM"), IP_PORT_MYPORT4 ); + oslSocketAddr poslSocketAddr = saSocketAddr.getHandle( ); + + sal_Bool bOK = ( saSocketAddr == poslSocketAddr ); + //t_print("getSocketAddrHandle_002\n"); + CPPUNIT_ASSERT_MESSAGE( "test for getHandle() function: use getHandle() function as an intermediate way to create identical address.", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( getSocketAddrHandle ); + CPPUNIT_TEST( getSocketAddrHandle_001 ); + CPPUNIT_TEST( getSocketAddrHandle_002 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getSocketAddrHandle + + + /** testing the method: + static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0); + */ + + class getLocalHostname : public CppUnit::TestFixture + { + public: + /* the process of getLocalHostname: 1.gethostname (same as /bin/hostname) returned name A + 2. search A in /etc/hosts, if there is an alias name is A, return the name in the same row + */ + + void getLocalHostname_000() + { + // _osl_getFullQualifiedDomainName( ); + oslSocketResult aResult = osl_Socket_Error; + rtl::OUString suHostname = osl::SocketAddr::getLocalHostname(&aResult); + CPPUNIT_ASSERT_MESSAGE("getLocalHostname failed", aResult == osl_Socket_Ok); + } + + void getLocalHostname_001() + { + oslSocketResult *pResult = NULL; + //printSocketResult(*pResult); + ::rtl::OUString suResult = ::osl::SocketAddr::getLocalHostname( pResult ); + + // LLA: IMHO localhost, or hostname by itself should be ok. + rtl::OUString suThisHost = getThisHostname( ); + bool bOk = false; + if (suThisHost.equals(rtl::OUString::createFromAscii("localhost"))) + { + bOk = true; + } + else + { + if (suThisHost.equals(suResult)) + { + bOk = true; + } + } + + ::rtl::OUString suError; + suError = outputError(suResult, getThisHostname( ), "test for getLocalHostname() function"); + + CPPUNIT_ASSERT_MESSAGE( suError, bOk == true ); + } + + CPPUNIT_TEST_SUITE( getLocalHostname ); + CPPUNIT_TEST( getLocalHostname_000 ); + CPPUNIT_TEST( getLocalHostname_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getLocalHostname + + + /** testing the method: + static inline void SAL_CALL resolveHostname( const ::rtl::OUString & strHostName , SocketAddr & Addr ); + */ + + class resolveHostname : public CppUnit::TestFixture + { + public: + void resolveHostname_001() + { + ::osl::SocketAddr saSocketAddr; + ::osl::SocketAddr::resolveHostname( rtl::OUString::createFromAscii("127.0.0.1"), saSocketAddr ); + ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); + sal_Bool bOK = sal_False; + + if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) + bOK = sal_True; + + CPPUNIT_ASSERT_MESSAGE( "test for resolveHostname() function: try to resolve localhost to 127.0.0.1.", + sal_True == bOK ); + } + + CPPUNIT_TEST_SUITE( resolveHostname ); + CPPUNIT_TEST( resolveHostname_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class resolveHostname + + + /** testing the method: + static inline sal_Int32 SAL_CALL getServicePort( + const ::rtl::OUString& strServiceName, + const ::rtl::OUString & strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) ); + */ + + class gettheServicePort : public CppUnit::TestFixture + { + public: + void gettheServicePort_001() + { + rtl::OUString suServiceFTP = rtl::OUString::createFromAscii( "ftp" ); + rtl::OUString suProtocolTCP = rtl::OUString::createFromAscii( "tcp" ); + + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get ftp service port on TCP protocol.", + IP_PORT_FTP== ::osl::SocketAddr::getServicePort( suServiceFTP, suProtocolTCP ) ); + } + + void gettheServicePort_002() + { + rtl::OUString suServiceTELNET = rtl::OUString::createFromAscii( "telnet" ); + rtl::OUString suProtocolTCP = rtl::OUString::createFromAscii( "tcp" ); + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get telnet service port on TCP protocol.", + IP_PORT_TELNET== ::osl::SocketAddr::getServicePort( suServiceTELNET, suProtocolTCP ) ); + } + + void gettheServicePort_003() + { + //Solaris has no service called "https", please see /etc/services + rtl::OUString suServiceNETBIOS = rtl::OUString::createFromAscii( "netbios-dgm" ); + rtl::OUString suProtocolUDP = rtl::OUString::createFromAscii( "udp" ); + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get netbios-ssn service port on UDP protocol.", + IP_PORT_NETBIOS_DGM == ::osl::SocketAddr::getServicePort( suServiceNETBIOS, suProtocolUDP ) ); + } + + void gettheServicePort_004() + { + rtl::OUString suProtocolUDP = rtl::OUString::createFromAscii( "udp" ); + CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get a service port which is not exist.", + OSL_INVALID_PORT == ::osl::SocketAddr::getServicePort( ::rtl::OUString::createFromAscii( "notexist" ), suProtocolUDP ) ); + } + + CPPUNIT_TEST_SUITE( gettheServicePort ); + CPPUNIT_TEST( gettheServicePort_001 ); + CPPUNIT_TEST( gettheServicePort_002 ); + CPPUNIT_TEST( gettheServicePort_003 ); + CPPUNIT_TEST( gettheServicePort_004 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class gettheServicePort + + /** testing the method: + + */ + + class getFamilyOfSocketAddr : public CppUnit::TestFixture + { + public: + void getFamilyOfSocketAddr_001() + { + ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); + oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); + CPPUNIT_ASSERT_EQUAL( + osl_Socket_FamilyInet, + osl_getFamilyOfSocketAddr( psaOSLSocketAddr ) ); + + CPPUNIT_ASSERT_MESSAGE( "test for osl_getFamilyOfSocketAddr.", + osl_getFamilyOfSocketAddr( psaOSLSocketAddr ) == osl_Socket_FamilyInet ); + } + + CPPUNIT_TEST_SUITE( getFamilyOfSocketAddr ); + CPPUNIT_TEST( getFamilyOfSocketAddr_001 ); + CPPUNIT_TEST_SUITE_END( ); + + }; // class getFamilyOfSocketAddr + +// ----------------------------------------------------------------------------- + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::ctors, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::is, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getHostname, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getPort, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setPort, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setAddr, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getAddr, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::operator_equal, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getSocketAddrHandle, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getLocalHostname, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::resolveHostname, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::gettheServicePort, "osl_SocketAddr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getFamilyOfSocketAddr, "osl_SocketAddr"); + +} // namespace osl_SocketAddr + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_SocketAddr.xsce b/sal/qa/osl/socket/osl_SocketAddr.xsce new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/sal/qa/osl/socket/osl_SocketAddr.xsce diff --git a/sal/qa/osl/socket/osl_SocketOld.xsce b/sal/qa/osl/socket/osl_SocketOld.xsce new file mode 100644 index 000000000000..3f8120fc6943 --- /dev/null +++ b/sal/qa/osl/socket/osl_SocketOld.xsce @@ -0,0 +1,14 @@ +osl_Socket.ctors.ctors_family_Ipx +osl_SocketAddr.getHostname.getHostname_002 +osl_StreamSocket.send_recv.write_read_001 + +osl_ConnectorSocket.connect.connect_003 wntmsci +osl_Socket.getLocalHost.getLocalHost_001 wntmsci + +# hangs within solaris +osl_StreamSocket.send_recv.write_read_002 unxsols +osl_StreamSocket.send_recv.write_read_003 unxsols +osl_StreamSocket.send_recv.write_read_004 unxsols + +# hangs within solaris +osl_StreamSocket.send_recv.send_recv1 unxsols diff --git a/sal/qa/osl/socket/osl_Socket_Const.h b/sal/qa/osl/socket/osl_Socket_Const.h new file mode 100755 index 000000000000..11ee32e205c9 --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket_Const.h @@ -0,0 +1,199 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Socket_Const.h,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_SOCKET_CONST_H_ +#define _OSL_SOCKET_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#include <sal/types.h> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> +#include <rtl/ustring.h> + +#ifndef _OSL_SOCLET_HXX_ +#include <osl/socket.hxx> +#endif +#include <osl/socket.h> + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif + +#ifndef _OSL_FILE_HXX +#include <osl/file.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/mutex.hxx> +#endif +#include <osl/time.h> + +const char * pTestString1 = "test socket"; +const char * pTestString2 = " Passed#OK"; +//define read count +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +extern "C" +{ +#endif + +# include <stdio.h> +//------------------------------------------------------------------------ +// OS dependent declaration and includes +//------------------------------------------------------------------------ +#if ( defined UNX ) || ( defined OS2 ) //Unix +# include <unistd.h> +# include <limits.h> +# include <string.h> +# include <math.h> +# include <errno.h> +# include <fcntl.h> +# include <sys/stat.h> +# include <sys/statfs.h> +# include <sys/statvfs.h> +# include <sys/types.h> +# include <sys/socket.h> +# include <netdb.h> +# include <netinet/in.h> +# include <arpa/inet.h> +#endif +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +// # include <windows.h> +# include <winsock.h> +# include <string.h> +#include <tools/postwin.h> +#endif + + +//------------------------------------------------------------------------ +// macro definition for the ASCII array/OUString declarations, +// we use p### for the ASCII array, +// a### for the OUString, +// n###Len for its length +//------------------------------------------------------------------------ + +#define OSLTEST_DECLARE( str_name, str_value ) \ + static const sal_Char p##str_name[] = str_value; \ + static const sal_Int32 n##str_name##Len = sizeof( p##str_name ) -1; \ + ::rtl::OUString a##str_name = rtl::OUString::createFromAscii( p##str_name ) + + +//------------------------------------------------------------------------ +// Ip version definition +//------------------------------------------------------------------------ +#define IP_VER 4 /// currently only IPv4 is considered. + +//------------------------------------------------------------------------ +// Ip port definition +//------------------------------------------------------------------------ +// #define IP_PORT_ZERO 0 +// #define IP_PORT_TELNET 23 +// #define IP_PORT_SMTP 25 +// #define IP_PORT_GOPHER 70 +// #define IP_PORT_POP3 110 +// #define IP_PORT_NETBIOS_DGM 138 +// #define IP_PORT_NETBIOS 139 +// #define IP_PORT_IMAP 143 +// #define IP_PORT_HTTPS 443 +// /**reference: http://www.iana.org/assignments/port-numbers */ +// #define IP_PORT_MYPORT 8881 //8888 +// #define IP_PORT_MYPORT1 8882 //8889 +// #define IP_PORT_MYPORT3 8884 //8891 +// #define IP_PORT_MYPORT4 8885 //8892 +// #define IP_PORT_MYPORT5 8886 //8893 +// #define IP_PORT_MYPORT6 8887 //8894 +// #define IP_PORT_MYPORT7 8895 +// #define IP_PORT_MYPORT8 8896 +// #define IP_PORT_MYPORT9 8897 +// #define IP_PORT_MYPORT10 8898 +// +// #define IP_PORT_TMP 9999 +// #define IP_PORT_INVAL 99999 + +//------------------------------------------------------------------------ +// service definitions. +//------------------------------------------------------------------------ +// OSLTEST_DECLARE( ServiceFTP, "ftp" ); +// OSLTEST_DECLARE( ServiceTELNET, "telnet" ); +// OSLTEST_DECLARE( ServiceGOPHER, "gopher" ); +// OSLTEST_DECLARE( ServiceIMAP, "imap" ); +// OSLTEST_DECLARE( ServiceHTTPS, "https" ); +// OSLTEST_DECLARE( ServiceNETBIOS, "netbios-dgm" ); + +//------------------------------------------------------------------------ +// protocol definitions. +//------------------------------------------------------------------------ +// OSLTEST_DECLARE( ProtocolTCP, "tcp" ); +// OSLTEST_DECLARE( ProtocolUDP, "udp" ); + +//------------------------------------------------------------------------ +// Hostnames. +//------------------------------------------------------------------------ +// OSLTEST_DECLARE( HostName1, "localhost" ); +// OSLTEST_DECLARE( HostIp1, "127.0.0.1" ); +OSLTEST_DECLARE( HostName2, "longshot.prc.sun.com" ); +OSLTEST_DECLARE( HostIp2, "129.158.217.202" ); +OSLTEST_DECLARE( HostName3, "deuce.prc.sun.com" ); +OSLTEST_DECLARE( HostIp3, "129.158.217.199" ); +OSLTEST_DECLARE( HostName4, "sceri.PRC.Sun.COM" ); //Beijing server for test +OSLTEST_DECLARE( HostIp4, "129.158.217.107" ); +OSLTEST_DECLARE( HostName5, "koori.SFBay.Sun.COM" ); //"grande.Germany.Sun.COM" ); //Germany server for test +OSLTEST_DECLARE( HostIp5, "10.5.32.20" ); +OSLTEST_DECLARE( HostName6, "crumple.SFBay.Sun.COM" ); //sfbay +OSLTEST_DECLARE( HostIp6, "10.6.103.83" ); +OSLTEST_DECLARE( HostIpInval, "123.45.67.89" ); //this is valid ip number,but can not arrive --mindy +// OSLTEST_DECLARE( HostIpInval1, "123.345.67.89" ); //this is real invalid ip number --mindy +OSLTEST_DECLARE( HostNameInval, "www.the_hostname_that_can_not_resolvable_to_an_IP_Address.com" ); +OSLTEST_DECLARE( HostIpZero, "0.0.0.0" ); + +//------------------------------------------------------------------------ +// OS independent file definition +//------------------------------------------------------------------------ +OSLTEST_DECLARE( NullURL, "" ); + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +} +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + + +#endif /* _OSL_SOCKET_CONST_H_ */ diff --git a/sal/qa/osl/socket/osl_Socket_Const_orig.h b/sal/qa/osl/socket/osl_Socket_Const_orig.h new file mode 100644 index 000000000000..582209cef568 --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket_Const_orig.h @@ -0,0 +1,203 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Socket_Const_orig.h,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _OSL_SOCKET_CONST_H_ +#define _OSL_SOCKET_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#include <sal/types.h> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> +#include <rtl/ustring.h> + +#ifndef _OSL_SOCLET_HXX_ +#include <osl/socket.hxx> +#endif +#include <osl/socket.h> + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif + +#ifndef _OSL_FILE_HXX +#include <osl/file.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/mutex.hxx> +#endif +#include <osl/time.h> + +const char * pTestString1 = "test socket"; +const char * pTestString2 = " Passed#OK"; +//define read count +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +extern "C" +{ +#endif + +# include <stdio.h> +//------------------------------------------------------------------------ +// OS dependent declaration and includes +//------------------------------------------------------------------------ +#if ( defined UNX ) || ( defined OS2 ) //Unix +# include <unistd.h> +# include <limits.h> +# include <string.h> +# include <math.h> +# include <errno.h> +# include <fcntl.h> +# include <sys/stat.h> +# include <sys/statfs.h> +# include <sys/statvfs.h> +# include <sys/types.h> +# include <sys/socket.h> +# include <netdb.h> +# include <netinet/in.h> +# include <arpa/inet.h> +#endif +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +// # include <windows.h> +# include <winsock.h> +# include <string.h> +#include <tools/postwin.h> +#endif + + +//------------------------------------------------------------------------ +// macro definition for the ASCII array/OUString declarations, +// we use p### for the ASCII array, +// a### for the OUString, +// n###Len for its length +//------------------------------------------------------------------------ + +#define OSLTEST_DECLARE( str_name, str_value ) \ + static const sal_Char p##str_name[] = str_value; \ + static const sal_Int32 n##str_name##Len = sizeof( p##str_name ) -1; \ + ::rtl::OUString a##str_name = rtl::OUString::createFromAscii( p##str_name ) + + +//------------------------------------------------------------------------ +// Ip version definition +//------------------------------------------------------------------------ +#define IP_VER 4 /// currently only IPv4 is considered. + +//------------------------------------------------------------------------ +// Ip port definition +//------------------------------------------------------------------------ +#define IP_PORT_ZERO 0 +#define IP_PORT_FTP 21 +#define IP_PORT_TELNET 23 +#define IP_PORT_SMTP 25 +#define IP_PORT_GOPHER 70 +#define IP_PORT_HTTP1 80 +#define IP_PORT_POP3 110 +#define IP_PORT_NETBIOS_DGM 138 +#define IP_PORT_NETBIOS 139 +#define IP_PORT_IMAP 143 +#define IP_PORT_HTTPS 443 +#define IP_PORT_HTTP2 8080 +/**reference: http://www.iana.org/assignments/port-numbers */ +#define IP_PORT_MYPORT 8881 //8888 +#define IP_PORT_MYPORT1 8882 //8889 +#define IP_PORT_MYPORT2 8883 //8890 +#define IP_PORT_MYPORT3 8884 //8891 +#define IP_PORT_MYPORT4 8885 //8892 +#define IP_PORT_MYPORT5 8886 //8893 +#define IP_PORT_MYPORT6 8887 //8894 +#define IP_PORT_MYPORT7 8895 +#define IP_PORT_MYPORT8 8896 +#define IP_PORT_MYPORT9 8897 +#define IP_PORT_MYPORT10 8898 + +#define IP_PORT_TMP 9999 +#define IP_PORT_INVAL 99999 + +//------------------------------------------------------------------------ +// service definitions. +//------------------------------------------------------------------------ +OSLTEST_DECLARE( ServiceFTP, "ftp" ); +OSLTEST_DECLARE( ServiceTELNET, "telnet" ); +OSLTEST_DECLARE( ServiceGOPHER, "gopher" ); +OSLTEST_DECLARE( ServiceIMAP, "imap" ); +OSLTEST_DECLARE( ServiceHTTPS, "https" ); +OSLTEST_DECLARE( ServiceNETBIOS, "netbios-dgm" ); + +//------------------------------------------------------------------------ +// protocol definitions. +//------------------------------------------------------------------------ +OSLTEST_DECLARE( ProtocolTCP, "tcp" ); +OSLTEST_DECLARE( ProtocolUDP, "udp" ); + +//------------------------------------------------------------------------ +// Hostnames. +//------------------------------------------------------------------------ +OSLTEST_DECLARE( HostName1, "localhost" ); +OSLTEST_DECLARE( HostIp1, "127.0.0.1" ); +OSLTEST_DECLARE( HostName2, "longshot.prc.sun.com" ); +OSLTEST_DECLARE( HostIp2, "129.158.217.202" ); +OSLTEST_DECLARE( HostName3, "deuce.prc.sun.com" ); +OSLTEST_DECLARE( HostIp3, "129.158.217.199" ); +OSLTEST_DECLARE( HostName4, "sceri.PRC.Sun.COM" ); //Beijing server for test +OSLTEST_DECLARE( HostIp4, "129.158.217.107" ); +OSLTEST_DECLARE( HostName5, "koori.SFBay.Sun.COM" ); //"grande.Germany.Sun.COM" ); //Germany server for test +OSLTEST_DECLARE( HostIp5, "10.5.32.20" ); +OSLTEST_DECLARE( HostName6, "crumple.SFBay.Sun.COM" ); //sfbay +OSLTEST_DECLARE( HostIp6, "10.6.103.83" ); +OSLTEST_DECLARE( HostIpInval, "123.45.67.89" ); //this is valid ip number,but can not arrive --mindy +OSLTEST_DECLARE( HostIpInval1, "123.345.67.89" ); //this is real invalid ip number --mindy +OSLTEST_DECLARE( HostNameInval, "www.the_hostname_that_can_not_resolvable_to_an_IP_Address.com" ); +OSLTEST_DECLARE( HostIpZero, "0.0.0.0" ); + +//------------------------------------------------------------------------ +// OS independent file definition +//------------------------------------------------------------------------ +OSLTEST_DECLARE( NullURL, "" ); + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +} +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + + +#endif /* _OSL_SOCKET_CONST_H_ */ diff --git a/sal/qa/osl/socket/osl_Socket_tests.cxx b/sal/qa/osl/socket/osl_Socket_tests.cxx new file mode 100644 index 000000000000..7f0fb5bbe87e --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket_tests.cxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_Socket_tests.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <osl_Socket_Const.h> + +#include <testshl/simpleheader.hxx> +#include <osl/socket.hxx> +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +//------------------------------------------------------------------------ +// tests cases begins here +//------------------------------------------------------------------------ + +namespace osl_Socket +{ + + class tests : public CppUnit::TestFixture + { + public: + + void test_001() + { + // _osl_getFullQualifiedDomainName( ); + oslSocketResult aResult; + rtl::OUString suHostname = osl::SocketAddr::getLocalHostname(&aResult); + CPPUNIT_ASSERT_MESSAGE("getLocalHostname failed", aResult == osl_Socket_Ok); + } + + CPPUNIT_TEST_SUITE( tests ); + CPPUNIT_TEST( test_001 ); + CPPUNIT_TEST_SUITE_END(); + }; + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Socket::tests, "osl_SocketTest"); +} + + +// ----------------------------------------------------------------------------- + +// 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. + +/*#if (defined LINUX) + +void RegisterAdditionalFunctions( FktRegFuncPtr _pFunc ) +{ + // for cover lines in _osl_getFullQualifiedDomainName( ) + // STAR_OVERRIDE_DOMAINNAME is more an internal HACK for 5.2, which should remove from sal + setenv( "STAR_OVERRIDE_DOMAINNAME", "PRC.Sun.COM", 0 ); +} + +#else*/ + +NOADDITIONAL; + +//#endif diff --git a/sal/qa/osl/socket/osl_Socket_tests.xsce b/sal/qa/osl/socket/osl_Socket_tests.xsce new file mode 100644 index 000000000000..d247b2365273 --- /dev/null +++ b/sal/qa/osl/socket/osl_Socket_tests.xsce @@ -0,0 +1 @@ +osl_SocketTest.tests.test_001 diff --git a/sal/qa/osl/socket/osl_StreamSocket.cxx b/sal/qa/osl/socket/osl_StreamSocket.cxx new file mode 100644 index 000000000000..9769d13adb0f --- /dev/null +++ b/sal/qa/osl/socket/osl_StreamSocket.cxx @@ -0,0 +1,1509 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: osl_StreamSocket.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +/** test coder preface: + 1. the BSD socket function will meet "unresolved external symbol error" on Windows platform + if you are not including ws2_32.lib in makefile.mk, the including format will be like this: + + .IF "$(GUI)" == "WNT" + SHL1STDLIBS += $(SOLARLIBDIR)$/cppunit.lib + SHL1STDLIBS += ws2_32.lib + .ENDIF + + likewise on Solaris platform. + .IF "$(GUI)" == "UNX" + SHL1STDLIBS+=$(SOLARLIBDIR)$/libcppunit$(DLLPOSTFIX).a + SHL1STDLIBS += -lsocket -ldl -lnsl + .ENDIF + + 2. since the Socket implementation of osl is only IPv4 oriented, our test are mainly focus on IPv4 + category. + + 3. some fragment of Socket source implementation are lack of comment so it is hard for testers + guess what the exact functionality or usage of a member. Hope the Socket section's comment + will be added. + + 4. following functions are declared but not implemented: + inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; +*/ + +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ + +#include <testshl/simpleheader.hxx> + +//#include "osl_Socket_Const.h" +#include "sockethelper.hxx" +#include <osl/conditn.hxx> + +using namespace osl; +using namespace rtl; + +#define IP_PORT_MYPORT9 8897 +#define IP_PORT_MYPORT10 18900 + +const char * pTestString1 = "test socket"; +const char * pTestString2 = " Passed#OK"; + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +// just used to test socket::close() when accepting +class AcceptorThread : public Thread +{ + ::osl::AcceptorSocket asAcceptorSocket; + ::rtl::OUString aHostIP; + sal_Bool bOK; +protected: + void SAL_CALL run( ) + { + ::osl::SocketAddr saLocalSocketAddr( aHostIP, IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# AcceptorSocket bind address failed.\n" ) ; + return; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# AcceptorSocket listen address failed.\n" ) ; + return; + } + + asAcceptorSocket.enableNonBlockingMode( sal_False ); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + bOK = sal_True; + t_print("AcceptorThread: acceptConnection failed! \n"); + } + } +public: + AcceptorThread(::osl::AcceptorSocket & asSocket, ::rtl::OUString const& aBindIP ) + : asAcceptorSocket( asSocket ), aHostIP( aBindIP ) + { + bOK = sal_False; + } + + sal_Bool isOK() { return bOK; } + + ~AcceptorThread( ) + { + if ( isRunning( ) ) + { + asAcceptorSocket.shutdown(); + t_print("# error: Acceptor thread not terminated.\n" ); + } + } +}; + +/** Server Socket Thread, served as a temp little server to communicate with client. + */ +class ServerSocketThread : public Thread +{ + osl::Condition &m_aCondition; +protected: + oslThreadIdentifier m_id; + + void SAL_CALL run( ) + { + ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //integer not sal_Bool : sal_True); + while ( schedule( ) == sal_True ) + { + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# ServerSocketThread: AcceptorSocket bind address failed.\n" ) ; + break; + } + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# ServerSocketThread: AcceptorSocket listen address failed.\n" ) ; + break; + } + + asAcceptorSocket.enableNonBlockingMode( sal_False ); + m_aCondition.set(); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + t_print("ServerSocketThread: acceptConnection failed! \n"); + break; + } + sal_Int32 nReadNumber1 = ssStreamConnection.recv( pReadBuffer, 11 ); + sal_Int32 nReadNumber2 = ssStreamConnection.recv( pReadBuffer + nReadNumber1, 11 ); + pReadBuffer[nReadNumber1 + nReadNumber2] = '\0'; + //t_print("# read buffer content: %s\n", pReadBuffer ); + break; + } + ssStreamConnection.close(); + asAcceptorSocket.close(); + + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this server thread %d!\n", m_id ); + } + +public: + // public to check if data transmition is OK + sal_Char pReadBuffer[30]; + ServerSocketThread( osl::Condition &_aCond ):m_aCondition(_aCond) + { + m_aCondition.reset(); + t_print("#init ServerSocketThread\n"); + m_id = getIdentifier( ); + //t_print("# successfully creat this ServerSocketThread %d!\n", m_id ); + } + + ~ServerSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: ServerSocketThread has not terminated.\n" ); + } +}; + +/** Client Socket Thread, served as a temp little client to communicate with server. + */ +class ClientSocketThread : public Thread +{ +protected: + osl::Condition &m_aCondition; + oslThreadIdentifier m_id; + ::osl::SocketAddr m_saTargetSocketAddr; + ::osl::ConnectorSocket m_csConnectorSocket; + + void SAL_CALL run( ) + { + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 5; + pTimeout->Nanosec = 0; + + /// if the thread should terminate, schedule return false + //while ( schedule( ) == sal_True ) + //{ + if ( osl::Condition::result_ok != m_aCondition.wait( pTimeout ) ) + { + free( pTimeout ); + return; + } + + if ( osl_Socket_Ok == m_csConnectorSocket.connect( m_saTargetSocketAddr, pTimeout )) + { + m_csConnectorSocket.send( pTestString1, 11 ); // "test socket" + m_csConnectorSocket.send( pTestString2, 10); + } + else + t_print("# ClientSocketThread: connect failed! \n"); + // terminate(); + //} + m_csConnectorSocket.close(); + free( pTimeout ); + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this thread %d!\n", m_id ); + } + +public: + ClientSocketThread( osl::Condition &_aCond ): + m_aCondition(_aCond), + m_saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9 ), + m_csConnectorSocket( ) + { + m_id = getIdentifier( ); + //t_print("# successfully creat this client thread %d!\n", m_id ); + } + + ~ClientSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: client thread not terminated.\n" ); + } + +}; + +// ----------------------------------------------------------------------------- +// Helper functions, to create buffers, check buffers +class ValueCheckProvider +{ + bool m_bFoundFailure; + char *m_pBuffer; + sal_Int32 m_nBufferSize; + +public: + ValueCheckProvider() + :m_bFoundFailure(false), + m_pBuffer(NULL), + m_nBufferSize(0) + { + } + + bool isFailure() {return m_bFoundFailure;} + + const char* getBuffer() {return m_pBuffer;} + char* getWriteBuffer() {return m_pBuffer;} + + sal_Int32 getBufferSize() {return m_nBufferSize;} + + bool checkValues(sal_Int32 _nLength, int _nValue) + { + m_bFoundFailure = false; + for(sal_Int32 i=0;i<_nLength;i++) + { + if (m_pBuffer[i] != _nValue) + { + m_bFoundFailure = true; + } + } + return m_bFoundFailure; + } + + void createBuffer(sal_Int32 _nLength, int _nValue) + { + m_nBufferSize = _nLength; + m_pBuffer = (char*) malloc(m_nBufferSize); + if (m_pBuffer) + { + memset(m_pBuffer, _nValue, m_nBufferSize); + } + } + + void freeBuffer() + { + if (m_pBuffer) free(m_pBuffer); + } + +}; + +// ----------------------------------------------------------------------------- +/** Client Socket Thread, served as a temp little client to communicate with server. + */ + +class ReadSocketThread : public Thread +{ + ValueCheckProvider m_aValues; + int m_nValue; + osl::Condition &m_aCondition; + +protected: + oslThreadIdentifier m_id; + + void SAL_CALL run( ) + { + ::osl::SocketAddr m_aTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT10 ); + ::osl::ConnectorSocket m_aConnectorSocket; + + if (! m_aTargetSocketAddr.is()) + { + t_print("# SocketAddr was NOT created successfully!\n"); + } + else + { + t_print("start ReadSocketThread\n"); + + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 5; + pTimeout->Nanosec = 0; + + m_aCondition.wait(); + + t_print("connect()\n"); + + oslSocketResult eResult = m_aConnectorSocket.connect( m_aTargetSocketAddr, pTimeout ); + if ( osl_Socket_Ok == eResult ) + { + sal_Int32 nReadCount = m_aConnectorSocket.read( m_aValues.getWriteBuffer(), m_aValues.getBufferSize() ); + m_aValues.checkValues(nReadCount, m_nValue); + } + else + { + t_print("# ReadSocketThread: connect failed! \n"); + printSocketResult(eResult); + } + + //remove this line for deadlock on solaris( margritte.germany ) + m_aConnectorSocket.close(); + free( pTimeout ); + } + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this thread %d!\n", m_id ); + } + +public: + sal_Int32 getCount() {return m_aValues.getBufferSize();} + bool isOk() {return m_aValues.isFailure() == true ? false : true;} + + ReadSocketThread(sal_Int32 _nBufferSize, int _nValue, osl::Condition &_aCond ) + : m_nValue( _nValue ), + m_aCondition(_aCond) + { + t_print("#init ReadSocketThread\n"); + m_id = getIdentifier( ); + + //t_print("# successfully creat this client thread %d!\n", m_id ); + m_aValues.createBuffer(_nBufferSize, 0); + } + + ~ReadSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: client thread not terminated.\n" ); + m_aValues.freeBuffer(); + } + +}; + +/** Server Socket Thread, write a file which is large + */ +class WriteSocketThread : public Thread +{ + ValueCheckProvider m_aValues; + osl::Condition &m_aCondition; + +protected: + oslThreadIdentifier m_id; + + void SAL_CALL run( ) + { + t_print("start WriteSocketThread\n"); + ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT10 ); + if (! saLocalSocketAddr.is()) + { + t_print("LocalSocketAddr was NOT created successfully!\n"); + } + + ::osl::StreamSocket ssStreamConnection; + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + /// if the thread should terminate, schedule return false + // while ( schedule( ) == sal_True ) + // { + t_print("bind()\n"); + sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); + if ( sal_True != bOK1 ) + { + t_print("# WriteSocketThread: AcceptorSocket bind address failed. \n" ) ; + } + else + { + t_print("listen()\n"); + sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); + if ( sal_True != bOK2 ) + { + t_print("# WriteSocketThread: AcceptorSocket listen address failed. \n" ) ; + } + else + { + + // blocking mode, if read/recv failed, block until success + asAcceptorSocket.enableNonBlockingMode( sal_False); + t_print("acceptConnection()\n"); + m_aCondition.set(); + + oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + t_print("WriteSocketThread: acceptConnection failed! \n"); + } + else + { + +// LLA: removed, due to the fact, this is to error prone +// LLA: char * pSrcRoot = getenv("SOURCE_ROOT"); +// LLA: // LLA: This is absolute wrong! +// LLA: // strcat( pSrcRoot, "/sal/inc/osl/file.hxx"); +// LLA: rtl::OString sSrcRoot(pSrcRoot); +// LLA: sSrcRoot += "/sal/inc/osl/file.hxx"; +// LLA: +// LLA: ::rtl::OUString sFilePath = ::rtl::OUString::createFromAscii( sSrcRoot.getStr() ); +// LLA: #ifdef WNT +// LLA: while (sFilePath.lastIndexOf('/') != -1) +// LLA: sFilePath = sFilePath.replace('/',(sal_Unicode)'\\'); +// LLA: #endif +// LLA: FILE *stream; +// LLA: sal_uInt64 nCount_read; +// LLA: sal_Char buffer_read[FILE_READ]; +// LLA: +// LLA: if( (stream = fopen( oustring2char( sFilePath ), "r+t" )) != NULL ) +// LLA: { +// LLA: /* Attempt to read in 25 characters */ +// LLA: nCount_read = fread( buffer_read, sizeof( char ), FILE_READ, stream ); +// LLA: fclose( stream ); +// LLA: } +// LLA: else +// LLA: t_print("# File $SRC_ROOT/sal/inc/osl/file.hxx could not be opened\n" ); + + t_print("write()\n"); + + ssStreamConnection.write( m_aValues.getBuffer(), m_aValues.getBufferSize() ); + t_print("done written.\n"); + } + } + } + ssStreamConnection.close(); + asAcceptorSocket.close(); + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this server thread %d!\n", m_id ); + } + +public: + // public to check if data transmition is OK + WriteSocketThread(sal_Int32 _nBufferSize, int _nValue, osl::Condition &_aCond ) + : m_aCondition(_aCond) + { + m_aCondition.reset(); + + t_print("#init WriteSocketThread\n"); + m_id = getIdentifier( ); + //t_print("# successfully creat this server thread %d!\n", m_id ); + + m_aValues.createBuffer(_nBufferSize, _nValue); + } + + ~WriteSocketThread( ) + { + if ( isRunning( ) ) + t_print("# error: server thread not terminated.\n" ); + m_aValues.freeBuffer(); + } +}; + +// ----------------------------------------------------------------------------- + +namespace osl_StreamSocket +{ + + /** testing the methods: + inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet, + oslProtocol Protocol = osl_Socket_ProtocolIp, + oslSocketType Type = osl_Socket_TypeStream); + + inline StreamSocket( const StreamSocket & ); + + inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire ); + + inline StreamSocket( oslSocket Socket ); + */ + + class ctors : public CppUnit::TestFixture + { + public: + oslSocket sHandle; + // initialization + void setUp( ) + { + sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); + } + + void tearDown( ) + { + sHandle = NULL; + } + + + void ctors_none() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_none constructor function: check if the stream socket was created successfully.", + osl_Socket_TypeStream == ssSocket.getType( ) ); + } + + void ctors_acquire() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( sHandle ); + + CPPUNIT_ASSERT_MESSAGE( "test for ctors_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == ssSocket.getType( ) ); + } + + void ctors_no_acquire() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( sHandle, SAL_NO_ACQUIRE ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_no_acquire constructor function: check if the socket was created successfully", + osl_Socket_TypeStream == ssSocket.getType( ) ); + } + + void ctors_copy_ctor() + { + /// Socket constructor. + ::osl::StreamSocket ssSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + /// Socket copy constructor. + ::osl::StreamSocket copySocket( ssSocket ); + + CPPUNIT_ASSERT_MESSAGE(" test for ctors_copy_ctor constructor function: create new Socket instance using copy constructor", + osl_Socket_TypeStream == copySocket.getType( ) ); + } + + CPPUNIT_TEST_SUITE( ctors ); + CPPUNIT_TEST( ctors_none ); + CPPUNIT_TEST( ctors_acquire ); + CPPUNIT_TEST( ctors_no_acquire ); + CPPUNIT_TEST( ctors_copy_ctor ); + CPPUNIT_TEST_SUITE_END(); + + }; // class ctors + + class send_recv: public CppUnit::TestFixture + { + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + + } + + void send_recv1() + { + osl::Condition aCondition; + //client sent two strings, and server received, check the order and value + ServerSocketThread myServerThread( aCondition ); + ClientSocketThread myClientThread( aCondition ); + myServerThread.create( ); + myClientThread.create( ); + + //wait until the thread terminate + myClientThread.join( ); + myServerThread.join( ); + sal_Char myStr[30] = ""; + strcat( myStr, pTestString1 ); + strcat( myStr, pTestString2 ); + sal_Int32 nRes = strcmp( myServerThread.pReadBuffer, myStr ); + CPPUNIT_ASSERT_MESSAGE(" test for send/recv with two threads: launch Server/Client threads, send data from client, check received data in Server thread.", + nRes == 0 ); + } + + // error when recv + void send_recv2() + { + ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9 ); + ::osl::StreamSocket ssStreamConnection; + sal_Char pReadBuffer[30] = ""; + + osl::Condition aCondition; + aCondition.reset(); + ClientSocketThread myClientThread( aCondition ); + myClientThread.create( ); + + asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + + asAcceptorSocket.bind( saLocalSocketAddr ); + asAcceptorSocket.listen( 1 ); + asAcceptorSocket.enableNonBlockingMode( sal_True ); + aCondition.set(); + + asAcceptorSocket.acceptConnection( ssStreamConnection ); + sal_Int32 nReadNumber = ssStreamConnection.recv( pReadBuffer, 11 ); + + myClientThread.join( ) ; + ssStreamConnection.close(); + asAcceptorSocket.close(); + CPPUNIT_ASSERT_MESSAGE(" test for send/recv, recv error!", nReadNumber == -1 ); + } + + // LLA: This is a helper function, which create 2 threads, a server and a client. + // the server writes the buffersize to the client. + + void write_read(sal_Int32 _nBufferSize, int _nValue) + { + //client sent two strings, and server received, check the order and value + osl::Condition aCondition; + WriteSocketThread myServerThread(_nBufferSize, _nValue, aCondition); + ReadSocketThread myClientThread(_nBufferSize, _nValue, aCondition); + myServerThread.create( ); +// thread_sleep( 1 ); + myClientThread.create( ); + + //wait until the thread terminate + myClientThread.join( ); + myServerThread.join( ); + + //Maximum Packet Size is ( ARPANET, MILNET = 1007 Ethernet (10Mb) = 1500 + // Proteon PRONET = 2046), so here test read 4000 bytes + sal_Int32 nLength = myClientThread.getCount(); + bool bIsOk = myClientThread.isOk(); // check if the values are right. + + t_print("Length:=%d\n", nLength); + t_print(" bIsOk:=%d\n", bIsOk); + + CPPUNIT_ASSERT_MESSAGE(" test for write/read values with two threads: send data from server, check readed data in client.", + nLength == _nBufferSize && bIsOk == true); + } + + // Tests with different values and sizes + void write_read_001() + { + write_read(50, 10); + } + void write_read_002() + { + write_read(1024, 20); + } + void write_read_003() + { + write_read(4000, 1); + } + void write_read_004() + { + write_read(8192, 3); + } + void write_read_005() + { + write_read(32768, 3); + } + + CPPUNIT_TEST_SUITE( send_recv ); + CPPUNIT_TEST( write_read_001 ); + CPPUNIT_TEST( write_read_002 ); + CPPUNIT_TEST( write_read_003 ); + CPPUNIT_TEST( write_read_004 ); + CPPUNIT_TEST( write_read_005 ); + CPPUNIT_TEST( send_recv1 ); + CPPUNIT_TEST( send_recv2 ); +// CPPUNIT_TEST( write_read ); + CPPUNIT_TEST_SUITE_END(); + }; // class send_recv + +// ----------------------------------------------------------------------------- + + class SendClientThread : public Thread + { + protected: + ::osl::SocketAddr m_saTargetSocketAddr; + ::osl::ConnectorSocket m_csConnectorSocket; + void SAL_CALL run( ) + { + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 5; + pTimeout->Nanosec = 0; + + if ( osl_Socket_Ok == m_csConnectorSocket.connect( m_saTargetSocketAddr, pTimeout )) + { + sal_Int32 nWrite1 = m_csConnectorSocket.write( pTestString1, 11 ); // "test socket" + + sal_Int32 nWrite2 = m_csConnectorSocket.write( pTestString2, strlen( pTestString2 ) + 1 ); + thread_sleep( 2 ); + m_csConnectorSocket.write( pTestString2, strlen( pTestString2 ) + 1 ); + t_print("nWrite1 is %d, nWrite2 is %d\n", nWrite1, nWrite2 ); + //thread_sleep( 1 ); + } + else + t_print("# SendClientThread: connect failed! \n"); + + m_csConnectorSocket.close(); + free( pTimeout ); + } + public: + SendClientThread( ): + m_saTargetSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9 ), + m_csConnectorSocket( ) + { + //t_print("# successfully creat this SendClientThread %d!\n", m_id ); + } + + ~SendClientThread( ) + { + if ( isRunning( ) ) + t_print("# error: SendClientThread has not terminated.\n" ); + } + + }; + + class shutdown: public CppUnit::TestFixture + { + public: + // initialization + void setUp( ) + { + } + + void tearDown( ) + { + + } + + // similar to close_002 + void shutdown_001() + { +#if defined(LINUX) + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + AcceptorThread myAcceptorThread( asSocket, rtl::OUString::createFromAscii("127.0.0.1") ); + myAcceptorThread.create(); + + thread_sleep( 1 ); + + //when accepting, shutdown the socket, the thread will not block for accepting + asSocket.shutdown(); + myAcceptorThread.join(); + + CPPUNIT_ASSERT_MESSAGE( "test for close when is accepting: the socket will quit accepting status.", + myAcceptorThread.isOK( ) == sal_True ); +#endif + } + + void shutdown_002() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9); + asSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: bind fail", asSocket.bind( saLocalSocketAddr ) == sal_True); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: listen fail", asSocket.listen( 1 ) == sal_True ); + sal_Char pReadBuffer[40]; +// osl::Condition aCondition; + SendClientThread mySendThread; + mySendThread.create(); + + asSocket.enableNonBlockingMode( sal_False ); + ::osl::StreamSocket ssConnectionSocket; + oslSocketResult eResult = asSocket.acceptConnection( ssConnectionSocket ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: acceptConnection fail", eResult == osl_Socket_Ok ); + + /* set socket option SO_LINGER 0, so close immediatly */ + linger aLingerSet; + sal_Int32 nBufferLen = sizeof( struct linger ); + aLingerSet.l_onoff = 0; + aLingerSet.l_linger = 0; + + ssConnectionSocket.setOption( osl_Socket_OptionLinger, &aLingerSet, nBufferLen ); + thread_sleep( 1 ); + //sal_uInt32 nRecv1 = 0; + sal_Int32 nRead1 = ssConnectionSocket.read( pReadBuffer, 11 ); + + //shutdown read after client the first send complete + ssConnectionSocket.shutdown( osl_Socket_DirRead ); + + sal_Int32 nRead2 = ssConnectionSocket.read( pReadBuffer + nRead1, 12 ); + sal_Int32 nRead3 = ssConnectionSocket.read( pReadBuffer + nRead1 + nRead2, 12 ); + t_print("after read 2, nRead1 is %d, nRead2 is %d, nRead3 is %d \n", nRead1, nRead2, nRead3 ); + mySendThread.join(); + + ssConnectionSocket.close(); + asSocket.close(); + + /* on Linux, if send is before shutdown(DirRead), can read, nRecv2 still > 0, + http://dbforums.com/arch/186/2002/12/586417 + While on Solaris, after shutdown(DirRead), all read will return 0 + */ +#ifdef LINUX + CPPUNIT_ASSERT_MESSAGE( "test for shutdown read direction: the socket can not read(recv).", + nRead1 > 0 && nRead3 == 0 ); +#else + CPPUNIT_ASSERT_MESSAGE( "test for shutdown read direction: the socket can not read(recv).", + nRead1 > 0 && nRead2 == 0 && nRead3 == 0 ); +#endif + + } + + void shutdown_003() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_MYPORT9); + asSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: bind fail", asSocket.bind( saLocalSocketAddr ) == sal_True); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: listen fail", asSocket.listen( 1 ) == sal_True ); + sal_Char pReadBuffer[40]; + osl::Condition aCondition; + SendClientThread mySendThread; + mySendThread.create(); + + asSocket.enableNonBlockingMode( sal_False ); + ::osl::StreamSocket ssConnectionSocket; + oslSocketResult eResult = asSocket.acceptConnection( ssConnectionSocket ); + CPPUNIT_ASSERT_MESSAGE("shutdown_002: acceptConnection fail", eResult == osl_Socket_Ok ); + + thread_sleep( 1 ); + //shutdown write after client the first send complete + ssConnectionSocket.shutdown( osl_Socket_DirWrite ); + + // recv should not shutdown + sal_Int32 nRead1 = ssConnectionSocket.read( pReadBuffer, 11 ); + + sal_Int32 nWrite = ssConnectionSocket.write( pReadBuffer, 11 ); + // still can read + sal_Int32 nRead3 = ssConnectionSocket.read( pReadBuffer + nRead1 , 12 ); + t_print("after read 2, nRead1 is %d, nWrite is %d, nRead3 is %d\n", nRead1, nWrite, nRead3 ); + mySendThread.join(); + ssConnectionSocket.close(); + asSocket.close(); + + CPPUNIT_ASSERT_MESSAGE( "test for shutdown read direction: the socket can not send(write).", + nRead1 > 0 && nWrite == 0 && nRead3 > 0); + + } + + CPPUNIT_TEST_SUITE( shutdown ); + CPPUNIT_TEST( shutdown_001 ); + CPPUNIT_TEST( shutdown_002 ); + CPPUNIT_TEST( shutdown_003 ); + CPPUNIT_TEST_SUITE_END(); + }; // class shutdown + + class isExceptionPending: public CppUnit::TestFixture + { + public: + void isExPending_001() + { + ::osl::AcceptorSocket asSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + sal_Bool bOk = asSocket.isExceptionPending( pTimeout ); + free( pTimeout ); + + CPPUNIT_ASSERT_MESSAGE( "test for isExceptionPending.", + bOk == sal_False ); + } + + /**tester's comments: lack of a case that return sal_True, do not know when it will return sal_True*/ + + + CPPUNIT_TEST_SUITE( isExceptionPending ); + CPPUNIT_TEST( isExPending_001 ); + CPPUNIT_TEST_SUITE_END(); + }; // class isExceptionPending + +// ----------------------------------------------------------------------------- +/** Server Socket Thread, write a file which is large + */ +// LLA: class WriteSocketThread : public Thread +// LLA: { +// LLA: ValueCheckProvider m_aValues; +// LLA: +// LLA: protected: +// LLA: oslThreadIdentifier m_id; +// LLA: +// LLA: void SAL_CALL run( ) +// LLA: { +// LLA: ::osl::AcceptorSocket asAcceptorSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); +// LLA: ::osl::SocketAddr saLocalSocketAddr( rtl::OUString::createFromAscii("10.16.66.252"), 8888 ); +// LLA: ::osl::StreamSocket ssStreamConnection; +// LLA: +// LLA: //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket +// LLA: asAcceptorSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); +// LLA: +// LLA: /// if the thread should terminate, schedule return false +// LLA: while ( schedule( ) == sal_True ) +// LLA: { +// LLA: sal_Bool bOK1 = asAcceptorSocket.bind( saLocalSocketAddr ); +// LLA: if ( sal_True != bOK1 ) +// LLA: { +// LLA: t_print("# WriteSocketThread: AcceptorSocket bind address failed. \n" ) ; +// LLA: break; +// LLA: } +// LLA: sal_Bool bOK2 = asAcceptorSocket.listen( 1 ); +// LLA: if ( sal_True != bOK2 ) +// LLA: { +// LLA: t_print("# WriteSocketThread: AcceptorSocket listen address failed. \n" ) ; +// LLA: break; +// LLA: } +// LLA: // blocking mode, if read/recv failed, block until success +// LLA: asAcceptorSocket.enableNonBlockingMode( sal_False); +// LLA: +// LLA: oslSocketResult eResult = asAcceptorSocket.acceptConnection( ssStreamConnection ); +// LLA: if (eResult != osl_Socket_Ok ) +// LLA: { +// LLA: t_print("WriteSocketThread: acceptConnection failed! \n"); +// LLA: break; +// LLA: } +// LLA: +// LLA: +// LLA: sal_Int32 nReadNumber1 = ssStreamConnection.write( m_aValues.getBuffer(), m_aValues.getBufferSize() ); +// LLA: break; +// LLA: } +// LLA: ssStreamConnection.close(); +// LLA: asAcceptorSocket.close(); +// LLA: } +// LLA: } +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +/** Client Socket Thread, served as a temp little client to communicate with server. + */ + +#define IP_PORT_TEST 8900 + + class ReadSocket2Thread : public Thread + { + osl::Condition &m_aCondition; + char* m_pBuffer; + sal_Int32 m_nBufferSize; + sal_Int32 m_nReadCount; + rtl::OString m_sAddr; + + bool m_bOk; + + void setFailed() + { + m_bOk = false; + } + + protected: + oslThreadIdentifier m_id; + + void read() + { + if (m_sAddr.getLength() == 0) + { + setFailed(); + return; + } + + // 10.16.66.252 + ::osl::SocketAddr aSocketAddr( rtl::OUString::createFromAscii(m_sAddr.getStr()), IP_PORT_TEST ); + ::osl::ConnectorSocket aSocket; // ( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + + aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True; + + m_aCondition.wait(); + t_print("wait done\n"); + + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 20; + pTimeout->Nanosec = 0; + + + // blocking mode, if read/recv failed, block until success + t_print("enableNonBlockingMode(false)\n"); + aSocket.enableNonBlockingMode( sal_False ); + + + t_print("connect()\n"); + oslSocketResult eResult = aSocket.connect( aSocketAddr, pTimeout ); + if ( osl_Socket_Ok == eResult) + { + if (m_pBuffer) + { + t_print("read()\n"); + m_nReadCount = aSocket.read( m_pBuffer, m_nBufferSize ); + t_print("%d bytes recived.\n", m_nReadCount); + } + } + else + { + t_print("# ReadSocket2Thread: connect failed! \n"); + printSocketResult(eResult); + setFailed(); + } + + //remove this line for deadlock on solaris( margritte.germany ) + aSocket.close(); + free( pTimeout ); + } + + void SAL_CALL run( ) + { + read(); + } + + void SAL_CALL onTerminated( ) + { + //t_print("# normally terminate this thread %d!\n", m_id ); + } + + public: + sal_Int32 getCount() {return m_nReadCount;} + bool isOk() {return m_nReadCount == 0 ? false : true;} + bool getFailed() {return m_bOk == false ? true : false;} + + ReadSocket2Thread(osl::Condition &_aCondition) + :m_aCondition(_aCondition), + m_nReadCount(0), + m_bOk( true ) + { + m_aCondition.reset(); + m_pBuffer = (char*) malloc(1024); + if (m_pBuffer) + { + m_nBufferSize = 1024; + } + + m_id = getIdentifier( ); + //t_print("# successfully creat this client thread %d!\n", m_id ); + } + + void setAddr(rtl::OString const& _sAddr) + { + m_sAddr = _sAddr; + } + + ~ReadSocket2Thread( ) + { + if ( isRunning( ) ) + t_print("# error: client thread not terminated.\n" ); + free(m_pBuffer); + } + + }; + + // ----------------------------------------------------------------------------- + + class justtest : public CppUnit::TestFixture + { + void send_Acceptor(rtl::OString const& _sAddr, osl::Condition &) + { + ::osl::AcceptorSocket aSocket; // ( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr aSocketAddr; + + if (! aSocketAddr.setPort(IP_PORT_TEST)) + { + t_print("# cant set port\n" ); + } + + if (! aSocketAddr.setHostname(rtl::OUString::createFromAscii(_sAddr.getStr()))) + { + t_print("# cant set hostname/ip\n" ); + } + + rtl::OUString aHostname = aSocketAddr.getHostname(); + aSocketAddr.getPort(); + + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True); + + /// if the thread should terminate, schedule return false + // while ( schedule( ) == sal_True ) + // { + if (! aSocket.bind( aSocketAddr )) + { + t_print("# can't bind.\n" ); + } + if (! aSocket.listen( )) + { + t_print("# can't listen. \n" ); + } + + // blocking mode, if read/recv failed, block until success + aSocket.enableNonBlockingMode( sal_False); + ::osl::StreamSocket ssStreamConnection; + + oslSocketResult eResult = aSocket.acceptConnection( ssStreamConnection ); + if (eResult != osl_Socket_Ok ) + { + t_print("WriteSocketThread: acceptConnection failed! \n"); + // break; + } + char const * pBuffer = "Test String\n"; + sal_Int32 nBufferSize = strlen(pBuffer); + ssStreamConnection.write( pBuffer, nBufferSize ); + // break; + // } + + // ssStreamConnection.close(); + aSocket.close(); + } + + // ----------------------------------------------------------------------------- + + void send_Connector(rtl::OString const& _sAddr, osl::Condition &/*_aCondition*/ ) + { + ::osl::ConnectorSocket aSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr aSocketAddr( rtl::OUString::createFromAscii(_sAddr.getStr()), IP_PORT_TEST ); + + if (! aSocketAddr.is()) + { + t_print("is failed.\n"); + return; + } + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True; + + oslSocketResult aResult = aSocket.connect( aSocketAddr ); + if ( aResult != osl_Socket_Ok ) + { + t_print("# send_Connector: connect failed. \n" ); + } + else + { + // blocking mode, if read/recv failed, block until success +// aSocket.enableNonBlockingMode( sal_False ); + +// _aCondition.set(); + + ::osl::StreamSocket ssStreamConnection(aSocket); + + char const * pBuffer = "GET / HTTP/1.0\015\012\015\012"; + sal_Int32 nBufferSize = strlen(pBuffer); + ssStreamConnection.write( pBuffer, nBufferSize ); + + char *pBufferPeek = (char*) malloc(1024); + sal_Int32 nReadNumber = ssStreamConnection.recv( pBufferPeek, 1024, osl_Socket_MsgPeek); + free(pBufferPeek); + + char *pBuffer2 = (char*) malloc(nReadNumber + 1); + sal_Int32 nReadNumberReal = ssStreamConnection.read( pBuffer2, nReadNumber ); + pBuffer2[nReadNumberReal] = '\0'; + + t_print("received: %s\n", pBuffer2); + + // char * pBuffer3 = "quit\n"; + // nBufferSize = strlen(pBuffer3); + // nWriteNumber = ssStreamConnection.write( pBuffer3, nBufferSize ); + + rtl::OUString suError = ssStreamConnection.getErrorAsString(); + free(pBuffer2); + // ssStreamConnection.close(); + + // ssStreamConnection.close(); + } + aSocket.shutdown(osl_Socket_DirReadWrite); + aSocket.close(); + } + + + public: +// LLA: orig void send_recv() +// LLA: orig { +// LLA: orig if ( ifAvailable(rtl::OUString::createFromAscii("margritte.germany")) == sal_True ) +// LLA: orig t_print("margritte is alive ! \n"); +// LLA: orig if ( ifAvailable(rtl::OUString::createFromAscii("10.16.66.252")) == sal_False ) +// LLA: orig { +// LLA: orig t_print("ip 10.16.66.252 is not alive! \n"); +// LLA: orig return; +// LLA: orig } +// LLA: orig ReadSocket2Thread myReadThread; +// LLA: orig myReadThread.create(); +// LLA: orig +// LLA: orig thread_sleep( 2 ); +// LLA: orig // send_Acceptor(); +// LLA: orig send_Connector(); +// LLA: orig +// LLA: orig myReadThread.join(); +// LLA: orig +// LLA: orig // statistics +// LLA: orig sal_uInt32 nLength = myReadThread.getCount(); +// LLA: orig bool bIsOk = myReadThread.isOk(); // check if the values are right. +// LLA: orig +// LLA: orig t_print("Length:=%d\n", nLength); +// LLA: orig t_print(" bIsOk:=%d\n", bIsOk); +// LLA: orig } + + // ----------------------------------------------------------------------------- + + // LLA: send_Connector_2_margritte works, it send strings to echo server on margritte + // but can not receive anything + + void send_Connector_2_margritte(rtl::OString const& _sAddr) + { + ::osl::ConnectorSocket aSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr aSocketAddr( rtl::OUString::createFromAscii(_sAddr.getStr()), IP_PORT_TEST ); + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True; + + oslSocketResult aResult = aSocket.connect( aSocketAddr ); + if ( aResult != osl_Socket_Ok ) + { + t_print("# connect failed. \n" ); + } + else + { + // blocking mode, if read/recv failed, block until success + aSocket.enableNonBlockingMode( sal_False ); + + ::osl::StreamSocket ssStreamConnection(aSocket); + + char const * pBuffer = "Test String\n"; + sal_Int32 nBufferSize = strlen(pBuffer); + sal_Int32 nWriteNumber = ssStreamConnection.write( pBuffer, nBufferSize ); + + // char * pBuffer2 = " "; + // sal_Int32 nReadNumber = ssStreamConnection.read( pBuffer2, strlen(pBuffer2) ); + + char const * pBuffer3 = "quit\n"; + nBufferSize = strlen(pBuffer3); + nWriteNumber = ssStreamConnection.write( pBuffer3, nBufferSize ); + + ssStreamConnection.close(); + } + aSocket.close(); + } + + void send_recv_2_margritte() + { + rtl::OString sAddr; + sAddr = "margritte.germany.sun.com"; + if ( ifAvailable(rtl::OUString::createFromAscii(sAddr.getStr())) == sal_True ) + { + t_print("found %s!\n", sAddr.getStr()); + } + send_Connector_2_margritte(sAddr); + } + + // ----------------------------------------------------------------------------- + + void send_recv() + { + rtl::OString sAddr; + // if ( ifAvailable(rtl::OUString::createFromAscii("margritte.germany")) == sal_True ) + // { + // t_print("margritte is alive ! \n"); + // sAddr = "margritte.germany"; + // } + + sAddr = "margritte.germany.sun.com"; + if ( ifAvailable(rtl::OUString::createFromAscii(sAddr.getStr())) == sal_True ) + { + t_print("found %s!\n", sAddr.getStr()); + } +// else +// { +// if ( ifAvailable(rtl::OUString::createFromAscii("192.168.7.2")) == sal_True ) +// { +// sAddr = "192.168.7.2"; +// t_print("moon found ! \n"); +// } +// else +// { +// if ( ifAvailable(rtl::OUString::createFromAscii("moon.linux.bogus")) == sal_True ) +// { +// sAddr = "moon.linux.bogus"; +// t_print("moon found ! \n"); +// } +// else +// { +// if ( ifAvailable(rtl::OUString::createFromAscii("moon")) == sal_True ) +// { +// sAddr = "moon"; +// t_print("moon found ! \n"); +// } +// } +// } +// } + + // if ( ifAvailable(rtl::OUString::createFromAscii("10.16.64.196")) == sal_False ) + // { + // t_print("ip 10.16.64.196 is not alive! \n"); + // return; + // } + + osl::Condition aCondition; + ReadSocket2Thread myReadThread(aCondition); + myReadThread.setAddr(sAddr); +// myReadThread.create(); + + thread_sleep( 2 ); + if (! myReadThread.getFailed()) + { + // send_Acceptor(sAddr, aCondition); + send_Connector(sAddr, aCondition); + + thread_sleep( 2 ); + if (myReadThread.isRunning()) + { + myReadThread.join(); + } + // termAndJoinThread(&myReadThread); + + // statistics + sal_uInt32 nLength = myReadThread.getCount(); + bool bIsOk = myReadThread.isOk(); // check if the values are right. + + t_print("Length:=%d\n", nLength); + t_print(" bIsOk:=%d\n", bIsOk); + } + else + { + t_print("ERROR: No echo Server on %s found.\n", sAddr.getStr()); + } + } + + + void getPage(rtl::OString const& _sAddr); + void test_getPage() + { + // rtl::OString sPage("lla-1.germany.sun.com"); + // getPage(sPage); + + rtl::OString sPage("lla-1"); + getPage(sPage); + } + + CPPUNIT_TEST_SUITE( justtest ); + CPPUNIT_TEST( send_recv ); + CPPUNIT_TEST( test_getPage ); + CPPUNIT_TEST_SUITE_END(); + }; // class isExceptionPending + + + void justtest::getPage(rtl::OString const& _sAddr) + { + rtl::OUString suAddr = rtl::OUString::createFromAscii(_sAddr.getStr()); + ::osl::ConnectorSocket aSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr aSocketAddr( suAddr, 80 ); + + { + // some checks + aSocketAddr.getPort(); + oslSocketResult aResult; + rtl::ByteSequence aSeq = aSocketAddr.getAddr(&aResult); + if (aResult != osl_Socket_Ok) + { + t_print("problem with getAddr: "); + printSocketResult(aResult); + } + + rtl::OUString sStr = aSocketAddr.getHostname(&aResult); + if (aResult != osl_Socket_Ok) + { + t_print("problem with hostname: "); + printSocketResult(aResult); + } + } + + oslSocketResult aResult; + + // SocketAddr::resolveHostname(suAddr, aSocketAddr); + // if (! aSocketAddr.is()) + // { + // t_print("Can't resolve Hostname.\n"); + // return; + // } + // rtl::OUString sStr = aSocketAddr.getHostname(&aResult); + // if (aResult != osl_Socket_Ok) + // { + // t_print("problem with hostname: "); + // printSocketResult(aResult); + // + // } + + if (! aSocketAddr.is()) + { + t_print("SocketAddr::is() failed.\n"); + return; + } + + //if has not set this option, socket addr can not be binded in some time(maybe 2 minutes) by another socket + aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True; + + aResult = aSocket.connect( aSocketAddr ); + if ( aResult != osl_Socket_Ok ) + { + t_print("# send_Connector: connect failed. \n" ); + } + else + { + // blocking mode, if read/recv failed, block until success +// aSocket.enableNonBlockingMode( sal_False ); + +// _aCondition.set(); + + ::osl::StreamSocket ssStreamConnection(aSocket); + + char const * pBuffer = "GET / HTTP/1.0\015\012\015\012"; + sal_Int32 nBufferSize = strlen(pBuffer); + ssStreamConnection.write( pBuffer, nBufferSize ); + + + char *pBufferPeek = (char*) malloc(1024); + sal_Int32 nReadNumber = 1; + while ( nReadNumber != 0) + { + nReadNumber = ssStreamConnection.recv( pBufferPeek, 1024, osl_Socket_MsgPeek); + if (nReadNumber > 0) + { + char *pBuffer2 = (char*) malloc(nReadNumber + 1); + sal_Int32 nReadNumberReal = ssStreamConnection.read( pBuffer2, nReadNumber ); + pBuffer2[nReadNumberReal] = '\0'; + t_print("%s", pBuffer2); + free(pBuffer2); + } + } + free(pBufferPeek); + + // char * pBuffer3 = "quit\n"; + // nBufferSize = strlen(pBuffer3); + // nWriteNumber = ssStreamConnection.write( pBuffer3, nBufferSize ); + + rtl::OUString suError = ssStreamConnection.getErrorAsString(); + } + aSocket.shutdown(osl_Socket_DirReadWrite); + aSocket.close(); + } + +// ----------------------------------------------------------------------------- + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::ctors, "osl_StreamSocket"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::send_recv, "osl_StreamSocket"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::shutdown, "osl_StreamSocket"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::isExceptionPending, "osl_StreamSocket"); + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamSocket::justtest, "osl_StreamSocket"); + +} // namespace osl_StreamSocket + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/osl/socket/osl_StreamSocket.xsce b/sal/qa/osl/socket/osl_StreamSocket.xsce new file mode 100644 index 000000000000..9c9513969d4a --- /dev/null +++ b/sal/qa/osl/socket/osl_StreamSocket.xsce @@ -0,0 +1,4 @@ +osl_StreamSocket.send_recv.send_recv2 +osl_StreamSocket.send_recv.write_read_001 wntmsci unxsols +osl_StreamSocket.justtest.test_getPage wntmsci + diff --git a/sal/qa/osl/socket/sockethelper.cxx b/sal/qa/osl/socket/sockethelper.cxx new file mode 100644 index 000000000000..681858f15dc1 --- /dev/null +++ b/sal/qa/osl/socket/sockethelper.cxx @@ -0,0 +1,404 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: sockethelper.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include "sockethelper.hxx" +#include <testshl/simpleheader.hxx> + +//------------------------------------------------------------------------ +// Ip version definition +//------------------------------------------------------------------------ +#define IP_VER 4 /// currently only IPv4 is considered. + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +/** compare two OUString. +*/ +sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ) +{ + sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr2 ); + + return bOk; +} + +/** compare a OUString and an ASCII string. +*/ +sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ) +{ + ::rtl::OUString ustr2 = rtl::OUString::createFromAscii( astr ); + sal_Bool bOk = ustr.equalsIgnoreAsciiCase( ustr2 ); + + return bOk; +} + +/** compare two socket address. +*/ +sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ) +{ + return ( ( sal_True == compareUString( addr1.getHostname( 0 ), addr2.getHostname( 0 ) ) ) && ( addr2.getPort( ) == addr2.getPort( ) ) ); +} + +/*char * oustring2char( const ::rtl::OUString & str ) +{ + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("oustring2char %s\n", aString.getStr( ) ); + sal_Char * sStr = aString.getStr( ); + return (char *)sStr; +}*/ + +/** print a UNI_CODE String. And also print some comments of the string. +*/ +void printUString( const ::rtl::OUString & str, const char* msg) +{ + t_print("#%s #printUString_u# ", msg ); + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + //char * sStr = aString.getStr( ); + t_print("%s\n", aString.getStr( ) ); +} + +/** get the local host name. + mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, + if no entry in /etc/hosts, it returns "localhost" + domain name +*/ +::rtl::OUString getHost( void ) +{ + struct hostent *hptr; + + hptr = gethostbyname( "localhost" ); + OSL_ENSURE( hptr != NULL, "#In getHostname function, error on gethostbyname()" ); + ::rtl::OUString aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hptr->h_name ); + + return aUString; +} + +/** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu +*/ +::rtl::OUString getThisHostname( void ) +{ + ::rtl::OUString aUString; +#ifdef WNT + struct hostent *hptr; + hptr = gethostbyname( "localhost" ); + OSL_ENSURE( hptr != NULL, "#In getHostname function, error on gethostbyname()" ); + rtl::OString sHostname(hptr->h_name); + aUString = ::rtl::OStringToOUString(sHostname, RTL_TEXTENCODING_ASCII_US); +#else + char hostname[255]; + if (gethostname(hostname, 255) != 0) { + OSL_ENSURE( false, "#Error: gethostname failed." ); + } + + struct hostent *hptr; + //first search /ets/hosts, then search from dns + hptr = gethostbyname( hostname); + if ( hptr != NULL ) + { + strcpy( hostname, hptr->h_name ); + } + + t_print("hostname is %s \n", hostname ); + rtl::OString sHostname( hostname ); + aUString = ::rtl::OStringToOUString( sHostname, RTL_TEXTENCODING_ASCII_US ); + aUString.getLength(); +#endif + return aUString; +} + +/** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") +*/ +::rtl::OUString getIPbyName( rtl::OString const& str_name ) +{ + ::rtl::OUString aUString; + struct hostent *hptr; + //first search /ets/hosts, then search from dns + hptr = gethostbyname( str_name.getStr()); + if ( hptr != NULL ) + { + struct in_addr ** addrptr; + addrptr = (struct in_addr **) hptr->h_addr_list ; + //if there are more than one IPs on the same machine, we select one + for (; *addrptr; addrptr++) + { + t_print("#Local IP Address: %s\n", inet_ntoa(**addrptr)); + aUString = ::rtl::OUString::createFromAscii( (sal_Char *) (inet_ntoa(**addrptr)) ); + } + } + return aUString; +} + +/** get local ethernet IP +*/ +::rtl::OUString getLocalIP( ) +{ + char hostname[255]; + gethostname(hostname, 255); + + return getIPbyName( hostname ); +} + +/** construct error message +*/ +::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg ) +{ + ::rtl::OUString aUString; + if ( returnVal.equals( rightVal ) ) + return aUString; + aUString += ::rtl::OUString::createFromAscii(msg); + aUString += ::rtl::OUString::createFromAscii(": the returned value is '"); + aUString += returnVal; + aUString += ::rtl::OUString::createFromAscii("', but the value should be '"); + aUString += rightVal; + aUString += ::rtl::OUString::createFromAscii("'."); + return aUString; +} + +/** wait _nSec seconds. +*/ +void thread_sleep( sal_Int32 _nSec ) +{ + /// print statement in thread process must use fflush() to force display. + // printf("wait %d seconds. ", _nSec ); + // fflush(stdout); + +#ifdef WNT //Windows + Sleep( _nSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + usleep(_nSec * 100000); +#endif + // t_print("# done\n" ); +} + +/** print Boolean value. +*/ +void printBool( sal_Bool bOk ) +{ + t_print("printBool " ); + ( sal_True == bOk ) ? t_print("YES!" ): t_print("NO!"); + t_print("\n"); +} + +/** print content of a ByteSequence. +*/ +void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ) +{ + t_print("ByteSequence is: " ); + for ( int i = 0; i < nLen; i++ ){ + if ( bsByteSeq[i] < 0 ) + t_print("%d ", 256 + bsByteSeq[i] ); + else + t_print("%d ", bsByteSeq[i] ); + } + t_print(" .\n" ); +} + +/** convert an IP which is stored as a UString format to a ByteSequence array for later use. +*/ +::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ) +{ + + rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ); + const sal_Char *pChar = aString.getStr( ) ; + sal_Char tmpBuffer[4]; + sal_Int32 nCharCounter = 0; + ::rtl::ByteSequence bsByteSequence( IP_VER ); + sal_Int32 nByteSeqCounter = 0; + + for ( int i = 0; i < aString.getLength( ) + 1 ; i++ ) + { + if ( ( *pChar != '.' ) && ( i !=aString.getLength( ) ) ) + tmpBuffer[nCharCounter++] = *pChar; + else + { + tmpBuffer[nCharCounter] = '\0'; + nCharCounter = 0; + bsByteSequence[nByteSeqCounter++] = static_cast<sal_Int8>(atoi( tmpBuffer )); + } + pChar++; + } + return bsByteSequence; +} + +/** print a socket result name. +*/ +void printSocketResult( oslSocketResult eResult ) +{ + t_print("printSocketResult: " ); + if (!eResult) + switch (eResult) + { + case osl_Socket_Ok: + t_print("client connected\n"); + break; + case osl_Socket_Error: + t_print("got an error ... exiting\r\n\r\n" ); + break; + case osl_Socket_TimedOut: + t_print("timeout\n"); + break; + case osl_Socket_Interrupted: + t_print("interrupted\n"); + break; + case osl_Socket_InProgress: + t_print("in progress\n"); + break; + default: + t_print("unknown result\n"); + break; + } +} + +/** if 4 parts of an IP addr are equal to specified values +*/ +sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 ) +{ + if ( ( Ipaddr[0] == seq1 ) && ( Ipaddr[1] == seq2 ) && ( Ipaddr[2] == seq3 ) && ( Ipaddr[3] == seq4 ) ) + return sal_True; + return sal_False; +} + +/** if the IP or hostname is availble( alive ) +*/ +/*sal_Bool ifAvailable( const char * stringAddrOrHostName ) +{ + sal_Bool result; + int p[2]; + sal_Char buffer[2000]; + char stringhost[20]; + strcpy(stringhost, stringAddrOrHostName ); + + result = sal_False; + if (pipe (p) == 0) + { + pid_t pid; + int nStatus; + pid = fork(); + if (pid == 0) + { +#if ( defined LINUX ) + char *argv[] = + { + "/bin/ping", + "-c", "3", + "-W", "3", + stringhost, + NULL + }; +#endif +#if ( defined SOLARIS ) + char *argv[] = + { + "/usr/sbin/ping", + stringhost, + "3", + NULL + }; +#endif + close (p[0]); + dup2 (p[1], 1); + close (p[1]); +#if ( defined LINUX ) + execv ("/bin/ping", argv); +#endif +#if ( defined SOLARIS ) + execv ("/usr/sbin/ping", argv); +#endif + // arriving here means exec failed + _exit(-1); + } + else if (pid > 0) + { + sal_Int32 k = 0, n = 2000; + close (p[1]); + if ((k = read (p[0], buffer, n - 1)) > 0) + { + buffer[k] = 0; + if (buffer[k - 1] == '\n') + buffer[k - 1] = 0; +#if ( defined LINUX ) + char strOK[] = "bytes from"; +#endif +#if ( defined SOLARIS ) + char strOK[] = "is alive"; +#endif + if (strstr( buffer, strOK ) != NULL ) + result = sal_True; + t_print("buffer is %s\n", buffer ); + } + close (p[0]); + waitpid (pid, &nStatus, 0); + } + else + { + close (p[0]); + close (p[1]); + } + + } + return result; +}*/ + +sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName ) +{ + ::osl::ConnectorSocket aSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); + ::osl::SocketAddr aSocketAddr( strAddrOrHostName, 7 ); + + if (! aSocketAddr.is()) + { + aSocket.close(); + return sal_False; + } + + aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True; + + TimeValue *pTimeout; + pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); + pTimeout->Seconds = 3; + pTimeout->Nanosec = 0; + + oslSocketResult aResult = aSocket.connect( aSocketAddr, pTimeout ); + free( pTimeout ); + aSocket.close(); + if ( aResult != osl_Socket_Ok ) + { + t_print("Error: "); + printSocketResult(aResult); + t_print("\n"); + + return sal_False; + } + return sal_True; +} diff --git a/sal/qa/osl/socket/sockethelper.hxx b/sal/qa/osl/socket/sockethelper.hxx new file mode 100644 index 000000000000..96dde8c91a5c --- /dev/null +++ b/sal/qa/osl/socket/sockethelper.hxx @@ -0,0 +1,168 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: sockethelper.hxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SOCKETHELPER_HXX_ +#define _SOCKETHELPER_HXX_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#include <sal/types.h> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> +#include <rtl/ustring.h> + +#ifndef _OSL_SOCLET_HXX_ +#include <osl/socket.hxx> +#endif +#include <osl/socket.h> + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif + +#ifndef _OSL_FILE_HXX +#include <osl/file.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX +#include <osl/mutex.hxx> +#endif +#include <osl/time.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +//------------------------------------------------------------------------ +// OS dependent declaration and includes +//------------------------------------------------------------------------ +#if ( defined UNX ) || ( defined OS2 ) //Unix + +#include <unistd.h> +#include <limits.h> +#include <string.h> +#include <math.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/statfs.h> +#include <sys/statvfs.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/wait.h> +#endif + +#ifndef _OSL_SOCKET_CONST_H_ + +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +// #include <windows.h> +#include <winsock.h> +#include <string.h> +#include <tools/postwin.h> +#endif + +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifdef __cplusplus +} +#endif + +/** compare two OUString. +*/ +sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ); +/** compare a OUString and an ASCII string. +*/ +sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ); +/** compare two socket address. +*/ +sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ); +//char * oustring2char( const ::rtl::OUString & str ); +/** print a UNI_CODE String. And also print some comments of the string. +*/ +void printUString( const ::rtl::OUString & str, const char * msg = "" ); +/** get the local host name. + mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, + if no entry in /etc/hosts, it returns "localhost" + domain name +*/ +::rtl::OUString getHost( void ); +/** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu +*/ +::rtl::OUString getThisHostname( void ); +/** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") +*/ +::rtl::OUString getIPbyName( rtl::OString const& str_name ); +/** get local ethernet IP +*/ +::rtl::OUString getLocalIP( ); +/** construct error message +*/ +::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = ""); +void thread_sleep( sal_Int32 _nSec ); +/** print Boolean value. +*/ +void printBool( sal_Bool bOk ); +/** print content of a ByteSequence. +*/ +void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ); +/** convert an IP which is stored as a UString format to a ByteSequence array for later use. +*/ +::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ); +/** print a socket result name. +*/ +void printSocketResult( oslSocketResult eResult ); +/** if 4 parts of an IP addr are equal to specified values +*/ +sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 ); +/** if the IP or hostname is availble( alive ) +*/ +//sal_Bool ifAvailable( const char * stringAddrOrHostName ); +sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName ); +/* +class ClientSocketThread : public Thread +class ServerSocketThread : public Thread +class ValueCheckProvider +class ClientReadSocketThread : public Thread +class ServerWriteSocketThread : public Thread +class AcceptorThread : public Thread +class CloseSocketThread : public Thread + +*/ + +#endif diff --git a/sal/qa/osl/thread/makefile.mk b/sal/qa/osl/thread/makefile.mk new file mode 100644 index 000000000000..86551fc6771b --- /dev/null +++ b/sal/qa/osl/thread/makefile.mk @@ -0,0 +1,56 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/..$/.. +PRJNAME := sal +TARGET := qa_osl_thread + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk + +DLLPRE = # no leading "lib" on .so files + +SHL1TARGET = $(TARGET) +SHL1OBJS = $(SLO)$/test_thread.obj +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +SHL1VERSIONMAP = version.map +SHL1IMPLIB = i$(SHL1TARGET) +DEF1NAME = $(SHL1TARGET) + +SLOFILES = $(SHL1OBJS) + +.INCLUDE: target.mk + +ALLTAR: test + +test .PHONY: $(SHL1TARGETN) + testshl2 $(SHL1TARGETN) diff --git a/sal/qa/osl/thread/test_thread.cxx b/sal/qa/osl/thread/test_thread.cxx new file mode 100644 index 000000000000..21fd2e297fe0 --- /dev/null +++ b/sal/qa/osl/thread/test_thread.cxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_thread.cxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "sal/config.h" + +#include "testshl/simpleheader.hxx" +#include "osl/conditn.hxx" +#include "osl/thread.hxx" +#include "osl/time.h" +#include "sal/types.h" + +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: + TimeValue const twentySeconds = { 20, 0 }; + osl::Thread::wait(twentySeconds); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); + +} + +NOADDITIONAL; diff --git a/sal/qa/osl/thread/version.map b/sal/qa/osl/thread/version.map new file mode 100644 index 000000000000..4833b67470ca --- /dev/null +++ b/sal/qa/osl/thread/version.map @@ -0,0 +1,38 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: version.map,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3_0_0 { + global: + registerAllTestFunction; + + local: + *; +}; diff --git a/sal/qa/rtl/alloc/jobfile.txt b/sal/qa/rtl/alloc/jobfile.txt new file mode 100755 index 000000000000..012ae24b4439 --- /dev/null +++ b/sal/qa/rtl/alloc/jobfile.txt @@ -0,0 +1,8 @@ +# JobFile for rtl_alloc +# header source sal/inc/rtl/alloc.h + +rtl_alloc.test.rtl_allocateMemory_001 +rtl_alloc.test.rtl_reallocateMemory_001 +rtl_alloc.test.rtl_freeMemory_001 +rtl_alloc.test.rtl_allocateZeroMemory_001 + diff --git a/sal/qa/rtl/alloc/makefile.mk b/sal/qa/rtl/alloc/makefile.mk new file mode 100755 index 000000000000..ce88442a5574 --- /dev/null +++ b/sal/qa/rtl/alloc/makefile.mk @@ -0,0 +1,72 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.9 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_alloc +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:jobfile by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_alloc.obj + +SHL1TARGET= rtl_Alloc +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:jobfile +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/alloc/rtl_alloc.cxx b/sal/qa/rtl/alloc/rtl_alloc.cxx new file mode 100755 index 000000000000..ae9a1e9e9587 --- /dev/null +++ b/sal/qa/rtl/alloc/rtl_alloc.cxx @@ -0,0 +1,182 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_alloc.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl + +#include <rtl/alloc.h> +#include <testshl/simpleheader.hxx> + +namespace rtl_alloc +{ + + // small memory check routine, which return false, if there is a problem + + bool checkMemory(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; + sal_uInt32 m_nSizeOfMemory; + +public: + Memory() + :m_pMemory(NULL), + m_nSizeOfMemory(50 * 1024 * 1024) + { + } + + // initialise your test code values here. + void setUp() + { + t_print("allocate memory\n"); + m_pMemory = (char*) rtl_allocateMemory( m_nSizeOfMemory ); + } + + void tearDown() + { + t_print("free memory\n"); + rtl_freeMemory(m_pMemory); + m_pMemory = NULL; + } + + // insert your test code here. + void rtl_allocateMemory_001() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != NULL); + memset(m_pMemory, 1, m_nSizeOfMemory); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true); + } + + void rtl_reallocateMemory_001() + { + t_print("reallocate memory\n"); + sal_uInt32 nSize = 10 * 1024 * 1024; + m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize); + + CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != NULL); + memset(m_pMemory, 2, nSize); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2) == true); + } + + // void rtl_freeMemory_001() + // { + // // CPPUNIT_ASSERT_STUB(); + // } + + // 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(Memory); + CPPUNIT_TEST(rtl_allocateMemory_001); + CPPUNIT_TEST(rtl_reallocateMemory_001); + // CPPUNIT_TEST(rtl_freeMemory_001); + CPPUNIT_TEST_SUITE_END(); +}; // class test + +class ZeroMemory : public CppUnit::TestFixture +{ + // for zero functions + char *m_pZeroMemory; + sal_uInt32 m_nSizeOfZeroMemory; + +public: + ZeroMemory() + :m_pZeroMemory(NULL), + m_nSizeOfZeroMemory( 50 * 1024 * 1024 ) + { + } + + // initialise your test code values here. + void setUp() + { + t_print("allocate zero memory\n"); + m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory ); + } + + void tearDown() + { + t_print("free zero memory\n"); + 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 != NULL); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true); + + memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory); + CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == 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(ZeroMemory); + CPPUNIT_TEST(rtl_allocateZeroMemory_001); + CPPUNIT_TEST_SUITE_END(); +}; // class test + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::Memory, "rtl_alloc"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::ZeroMemory, "rtl_alloc"); +} // namespace rtl_alloc + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/rtl/bootstrap/bootstrap_process.cxx b/sal/qa/rtl/bootstrap/bootstrap_process.cxx new file mode 100644 index 000000000000..11632aa5cd34 --- /dev/null +++ b/sal/qa/rtl/bootstrap/bootstrap_process.cxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: bootstrap_process.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <stdlib.h> +#include <stdio.h> +#include "sal/main.h" +#include <rtl/bootstrap.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> + +using namespace ::rtl; + +// ----------------------------------- Main ----------------------------------- +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + (void)argc; + Bootstrap aBootstrap; + //custom .ini/rc file + Bootstrap aBs_custom( OUString::createFromAscii(argv[3]) ); + OUString suValue; + OUString suDefault( OUString::createFromAscii("mydefault") ); + int flag = atoi( argv[1] ); + + switch( flag ) { + case 1: + // parameters may be passed by command line arguments + aBootstrap.getFrom( + OUString(RTL_CONSTASCII_USTRINGPARAM("UNO_SERVICES")), + suValue ); + if (suValue.equalsAscii("service.rdb") ) + { + return 10; + } + else + return 11; + case 2: + // parameters may be passed by ini file + aBootstrap.getFrom( + OUString(RTL_CONSTASCII_USTRINGPARAM("EXECUTABLE_RC")), + suValue ); + if (suValue.equalsAscii("true") ) + { + return 20; + } + else + return 21; + case 3: + // parameters may be passed by command line arguments + aBootstrap.getFrom( + OUString(RTL_CONSTASCII_USTRINGPARAM("QADEV_BOOTSTRAP")), + suValue ); + if (suValue.equalsAscii("sun&ms") ) + { + return 30; + } + else + return 31; + case 4: + // parameters may be passed by custom .ini/rc file + aBs_custom.getFrom( + OUString(RTL_CONSTASCII_USTRINGPARAM("RTLVALUE")), + suValue ); + if (suValue.equalsAscii("qadev17") ) + { + return 40; + } + else + return 41; + case 5: + // parameters may be passed by inheritance + aBs_custom.getFrom( + OUString(RTL_CONSTASCII_USTRINGPARAM("EXECUTABLE_RC")), + suValue ); + if (suValue.equalsAscii("true") ) + { + return 50; + } + else + return 51; + default: + // parameters may be passed by inheritance + aBs_custom.getFrom( + OUString(RTL_CONSTASCII_USTRINGPARAM("ABCDE")), + suValue, suDefault ); + if (suValue.equalsAscii("mydefault") ) + { + return 60; + } + else + return 61; + } +} diff --git a/sal/qa/rtl/bootstrap/makefile.mk b/sal/qa/rtl/bootstrap/makefile.mk new file mode 100644 index 000000000000..a492af8dd3c5 --- /dev/null +++ b/sal/qa/rtl/bootstrap/makefile.mk @@ -0,0 +1,92 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.7 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_bootstrap + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(GUI)"=="WNT" +#BOOTSTRAPSCRIPT=bootstrap.bat +BOOTSTRAPINI=testshl2.ini +MY_SCRIPTCAT=cat +.ELSE +#BOOTSTRAPSCRIPT=bootstrap +BOOTSTRAPINI=testshl2rc +MY_SCRIPTCAT=tr -d "\015" < +.ENDIF + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_Bootstrap.obj + +SHL1TARGET= rtl_Bootstrap +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ + +OBJ2FILES=$(OBJ)$/bootstrap_process.obj +APP2TARGET=bootstrap_process +APP2OBJS=$(OBJ2FILES) + +# .IF "$(GUI)" == "UNX" +# APP2STDLIBS=$(LB)$/libsal.so +# .ENDIF +# .IF "$(GUI)" == "WNT" +# APP2STDLIBS=$(KERNEL32LIB) $(LB)$/isal.lib +# .ENDIF +APP2STDLIBS=$(SALLIB) +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/bootstrap/rtl_Bootstrap.cxx b/sal/qa/rtl/bootstrap/rtl_Bootstrap.cxx new file mode 100644 index 000000000000..520c1298030f --- /dev/null +++ b/sal/qa/rtl/bootstrap/rtl_Bootstrap.cxx @@ -0,0 +1,1043 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_Bootstrap.cxx,v $ + * $Revision: 1.10.20.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// Documentation about bootstraping can be found at: +// http://udk.openoffice.org/common/man/concept/micro_deployment.html + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <algorithm> // STL + +#include "testshl/stringhelper.hxx" + +#include <testshl/simpleheader.hxx> +//#include "stringhelper.hxx" +//#include "valueequal.hxx" +#include <rtl/bootstrap.hxx> + +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <osl/file.hxx> +#include <osl/module.hxx> +#include <osl/process.h> /* osl_getExecutableFile() */ + +#include <osl/thread.hxx> + +// using namespace osl; +using namespace rtl; + +#define TESTSHL2_INI "testshl2" +#define PSEUDO_INI "pseudo" + +/** print a UNI_CODE String. And also print some comments of the string. + */ +inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) +{ + + if (strlen(msg) > 0) + { + t_print("%s: ", msg ); + } + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", (char *)aString.getStr( ) ); +} + +/** if the file exist + */ +bool t_fileExist(rtl::OUString const& _sFilename) +{ + ::osl::FileBase::RC nError1; + ::osl::File aTestFile( _sFilename ); + nError1 = aTestFile.open ( OpenFlag_Read ); + if ( ( ::osl::FileBase::E_NOENT != nError1 ) && ( ::osl::FileBase::E_ACCES != nError1 ) ) + { + aTestFile.close( ); + return true; + } + return false; +} + +/** get the exectutable path ( here is bootstrap_process), on Linux, such as "sal/unxlngi4.pro/bin/" + */ +inline ::rtl::OUString getModulePath( void ) +{ + ::rtl::OUString suDirPath; + ::osl::Module::getUrlFromAddress( ( oslGenericFunction ) &getModulePath, suDirPath ); + + suDirPath = suDirPath.copy( 0, suDirPath.lastIndexOf('/') ); + suDirPath = suDirPath.copy( 0, suDirPath.lastIndexOf('/') + 1); + suDirPath += rtl::OUString::createFromAscii("bin"); + return suDirPath; +} + +#define TESTSHL2_INI "testshl2" +#define PSEUDO_INI "pseudo" + + +static rtl::OUString getExecutableDirectory() +{ + rtl::OUString fileName; + osl_getExecutableFile(&fileName.pData); + + sal_Int32 nDirEnd = fileName.lastIndexOf('/'); + + OSL_ENSURE(nDirEnd >= 0, "Cannot locate executable directory"); + + rtl::OUString aDirURL = fileName.copy(0, nDirEnd); + return aDirURL; +} + + +// get the URL of testshl2rc/rtlrc/pseudorc +inline rtl::OUString t_getSourcePath(rtl::OString const& _sFilename) +{ + + rtl::OUString aDirURL(getExecutableDirectory()); + aDirURL += OUString::createFromAscii( "/"); + aDirURL += OUString::createFromAscii( _sFilename.getStr() ); +#if defined(WNT) || defined(OS2) + aDirURL += rtl::OUString::createFromAscii(".ini"); +#else + aDirURL += rtl::OUString::createFromAscii("rc"); +#endif + return aDirURL; + +// LLA: does not right work on my personal laptop, SRC_ROOT does not show where the source is :-(. +/* + sal_Char * pStr = getenv("SRC_ROOT"); + rtl::OUString suPath; + if (filename != "") + { + suPath = rtl::OUString::createFromAscii(pStr) + rtl::OUString::createFromAscii( "/sal/qa/rtl/bootstrap/" ) + + rtl::OUString::createFromAscii( filename ); + } + else + { + suPath = rtl::OUString::createFromAscii(pStr) + rtl::OUString::createFromAscii( "/sal/qa/rtl/bootstrap" ); + } + rtl::OUString suURL; + ::osl::FileBase::getFileURLFromSystemPath( suPath, suURL ); + return suURL; +*/ +} + +void thread_sleep_tenth_sec(sal_Int32 _nTenthSec) +{ +#ifdef WNT //Windows + Sleep(_nTenthSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + TimeValue nTV; + nTV.Seconds = static_cast<sal_uInt32>( _nTenthSec/10 ); + nTV.Nanosec = ( (_nTenthSec%10 ) * 100000000 ); + osl_waitThread(&nTV); +#endif +} + +// ----------------------------------------------------------------------------- + +namespace rtl_Bootstrap +{ + class ctor : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ctor with ini name + void ctor_001() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + printUString( suIniname ); + Bootstrap aBootstrap( suIniname ); + rtl::OUString suGetname; // = rtl::OUString::createFromAscii(""); + aBootstrap.getIniName( suGetname ); + printUString( suGetname ); + + // LLA: first: this seems to be a wrong test. + // second: there seems to be a design hole, if I give a absolute path ini file, + // but try to use ${file::KEYVALUE} than 'file' will only used out of the 'executable path'/file + // not from the path given from the absolute path. + + // Due to the fact, we create at this position a file (createTestshl2rc() ), we check for existance + bool bFileExist = t_fileExist( suGetname ); + CPPUNIT_ASSERT_MESSAGE("ctor error with initial file.", bFileExist == true ); + } + + void ctor_002() + { + rtl::Bootstrap aBootstrap; + rtl::OUString suGetname; + aBootstrap.getIniName( suGetname ); + printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("ctor error without initial file.", suGetname.getLength() != 0 ); + } + + CPPUNIT_TEST_SUITE(ctor); + CPPUNIT_TEST(ctor_001); + CPPUNIT_TEST(ctor_002); + CPPUNIT_TEST_SUITE_END(); + }; // class ctor + + class getFrom : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + // get the value of env variable + void getFrom_001() + { + Bootstrap aBootstrap; + rtl::OUString suValue; + rtl::OUString suValuename = rtl::OUString::createFromAscii( "SOLAR_JAVA" ); + //aBootstrap.getFrom( suValuename, suValue ); + aBootstrap.getFrom( suValuename, suValue ); + sal_Char * pStr = getenv("SOLAR_JAVA"); + // printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("get the value of environment variable.", suValue.compareToAscii( pStr ) == 0 ); + } + /* Notes on Windows: + void getFrom_001_1() + { + Bootstrap aBootstrap; + rtl::OUString suValue; + rtl::OUString suValuename = rtl::OUString::createFromAscii( "SRC_ROOT" ); + //aBootstrap.getFrom( suValuename, suValue ); + aBootstrap.getFrom( suValuename, suValue ); + sal_Char * pStr = getenv("SRC_ROOT"); + // printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("get the value of environment variable.", suValue.compareToAscii( pStr ) == 0 ); + } + The result on Windows: + # # the SRC_ROOT is e:\Qadev\cvs\m19 + # # suValue is e:Qadevcvsm19 + reason: + The problem is that the internally getenv()ed variable SRC_ROOT is macro expanded, + thus every \ will introduce an escape. + */ + + // get the value of a variable in ini file + void getFrom_002() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap( suIniname ); + rtl::OUString suGetname; + rtl::OUString suValuename = rtl::OUString::createFromAscii( "INHERITED_VALUE" ); + aBootstrap.getFrom( suValuename, suGetname ); + printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("get the value of a variable in ini file.", suGetname.getLength() != 0 ); + } + + //use defaut value + void getFrom_003() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap( suIniname ); + rtl::OUString suGetname; + rtl::OUString suValuename = rtl::OUString::createFromAscii( "MY_VALUE" ); + rtl::OUString myDefault = rtl::OUString::createFromAscii( "2" ); + aBootstrap.getFrom( suValuename, suGetname, myDefault ); + //printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("getFrom use default.", suGetname.compareTo( myDefault ) == 0 ); + } + + void getFrom_004() + { + t_print("1\n"); + // initialise Bootstrap with an own ini file + // PSEUDO_INI is pseudo(rc|.ini) created be create_pseudorc() + rtl::OUString suIniname = t_getSourcePath(PSEUDO_INI); + Bootstrap aBootstrap( suIniname ); + + rtl::OUString suGetIniName; + aBootstrap.getIniName( suGetIniName ); + + printUString(suGetIniName, "Current bootstrap file"); + sal_Int32 nIndex = suGetIniName.indexOf(rtl::OUString::createFromAscii( "pseudo" )); + CPPUNIT_ASSERT_MESSAGE("ini name must have 'pseudo' in name.", nIndex > 0); + + // rtlBootstrapHandle bsHandle = aBootstrap.getHandle(); + // CPPUNIT_ASSERT_MESSAGE("getHandle return NULL!", bsHandle != 0); + + rtl::OUString suValue; + rtl::OUString suKeyName = rtl::OUString::createFromAscii( "FILE" ); + aBootstrap.getFrom( suKeyName, suValue ); + printUString( suValue ); + sal_Int32 nCompare = suValue.compareTo( rtl::OUString::createFromAscii("pseudo file") ); + + CPPUNIT_ASSERT_MESSAGE("<Bootstrap('pseudo')>.getFrom('FILE', ...) result is unexpected.", nCompare == 0); + } + void getFrom_004_1() + { + // get the same key out of the default context + rtl::OUString suKeyName = rtl::OUString::createFromAscii( "FILE" ); + rtl::OUString suGetValue; + Bootstrap::get( suKeyName, suGetValue ); + printUString( suGetValue ); + + CPPUNIT_ASSERT_MESSAGE("Bootstrap::get('FILE', ...)", suGetValue.compareTo( rtl::OUString::createFromAscii("testshl2 file") ) == 0 ); + } + + /** helper function: return the child process's ret value( typedef sal_uInt32 oslProcessExitCode;) + * param1 is the process's name(only file name, not include path) + */ + oslProcessExitCode ini_execProcess( const sal_Char* process_name, const sal_Char * flag ) + { + rtl::OUString suCWD = getModulePath(); + oslProcess hProcess = NULL; + rtl::OUString suFileURL = suCWD; + suFileURL += rtl::OUString::createFromAscii("/") + rtl::OUString::createFromAscii(process_name) ; +#if defined(WNT) || defined(OS2) + suFileURL += rtl::OUString::createFromAscii(".exe"); +#endif + const int nParameterCount = 3; + rtl_uString* pParameters[ nParameterCount ]; + OUString suFlag( OUString::createFromAscii(flag) ); + OUString suEnv1( OUString::createFromAscii("-env:UNO_SERVICES=service.rdb")); + OUString suIniname = t_getSourcePath("rtl"); + printUString( suIniname, "rtl path:"); + //OUString suEnv2( OUString::createFromAscii("-env:MYENV=bootstrap_process")); + + pParameters[0] = suFlag.pData; + pParameters[1] = suEnv1.pData; + // the custom ini/rc file's URL + pParameters[2] = suIniname.pData; + + oslProcessError osl_error = osl_executeProcess( + suFileURL.pData, + pParameters, + nParameterCount, + osl_Process_WAIT, + 0, + suCWD.pData, + NULL, + 0, + &hProcess ); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + osl_joinProcess(hProcess); + oslProcessInfo* pInfo = new oslProcessInfo; + pInfo->Size = sizeof( oslProcessInfo ); + osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo ); + CPPUNIT_ASSERT_MESSAGE + ( + "osl_getProcessInfo returned with failure", + osl_Process_E_None == osl_error + ); + + t_print("the exit code is %d.\n", pInfo->Code ); + oslProcessExitCode nCode = pInfo->Code; + delete pInfo; + return nCode; + } + + void getFrom_005_1() + { + oslProcessExitCode nExitCode = ini_execProcess( "bootstrap_process", "1" ); + CPPUNIT_ASSERT_MESSAGE("Parameters passed by command line can not be gotten!", + nExitCode == 10 ); + } + void getFrom_005_2() + { + oslProcessExitCode nExitCode = ini_execProcess( "bootstrap_process", "2" ); + CPPUNIT_ASSERT_MESSAGE("Parameters passed by .ini/rc file can not be gotten!", + nExitCode == 20 ); + } + void getFrom_005_3() + { +#if (defined WNT) || (defined SOLARIS) + putenv(const_cast< char * >("QADEV_BOOTSTRAP=sun&ms")); +#else + setenv("QADEV_BOOTSTRAP", "sun&ms", 0); +#endif + oslProcessExitCode nExitCode = ini_execProcess( "bootstrap_process", "3" ); + CPPUNIT_ASSERT_MESSAGE("Parameters passed by environment variables can not be gotten!", + nExitCode == 30 ); + } + void getFrom_005_4() + { + oslProcessExitCode nExitCode = ini_execProcess( "bootstrap_process", "4" ); + CPPUNIT_ASSERT_MESSAGE("Parameters passed by customed .ini/rc file can not be gotten!", + nExitCode == 40 ); + } + void getFrom_005_5() + { + oslProcessExitCode nExitCode = ini_execProcess( "bootstrap_process", "5" ); + CPPUNIT_ASSERT_MESSAGE("Parameters passed by inheritance can not be gotten!", + nExitCode == 50 ); + } + void getFrom_005_6() + { + oslProcessExitCode nExitCode = ini_execProcess( "bootstrap_process", "6" ); + CPPUNIT_ASSERT_MESSAGE("Parameters passed by default can not be gotten!", + nExitCode == 60 ); + } + + CPPUNIT_TEST_SUITE(getFrom); + CPPUNIT_TEST(getFrom_001); + CPPUNIT_TEST(getFrom_002); + CPPUNIT_TEST(getFrom_003); + CPPUNIT_TEST(getFrom_004); + CPPUNIT_TEST(getFrom_004_1); + CPPUNIT_TEST(getFrom_005_1); + CPPUNIT_TEST(getFrom_005_2); + CPPUNIT_TEST(getFrom_005_3); + CPPUNIT_TEST(getFrom_005_4); + CPPUNIT_TEST(getFrom_005_5); + CPPUNIT_TEST(getFrom_005_6); + CPPUNIT_TEST_SUITE_END(); + }; // class getFrom + + class setIniFilename : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void setIniFilename_001() + { + Bootstrap aBootstrap; + + rtl::OUString suGetIniname; + aBootstrap.getIniName( suGetIniname ); + //which should be .....testshl2rc + //printUString( suGetIniname ); + + rtl::OUString suIniname = t_getSourcePath(PSEUDO_INI); + Bootstrap::setIniFilename( suIniname ); + + rtl::OUString suGetname; + aBootstrap.getIniName( suGetname ); + + printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("setIniFilename then get it.", suGetname.compareTo( suIniname ) == 0 + && suGetname.compareTo( suGetIniname ) != 0 ); + } + + void setIniFilename_002() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + // CPPUNIT_ASSERT_MESSAGE("test failed, Bootstrap ini does not exist.", t_fileExist(suIniname ) == true); + + Bootstrap::setIniFilename( suIniname ); + //rtl_bootstrap_args_open( suIniname.pData ); + rtl::OUString suGetname; + rtl::OUString suValuename = rtl::OUString::createFromAscii( "INHERITED_VALUE" ); + //aBootstrap.getFrom( suValuename, suGetname ); + Bootstrap::get( suValuename, suGetname ); + printUString( suGetname ); + CPPUNIT_ASSERT_MESSAGE("setIniFilename and get value of the argument.", suGetname.getLength() != 0 ); + } + + CPPUNIT_TEST_SUITE(setIniFilename); + CPPUNIT_TEST(setIniFilename_001); + CPPUNIT_TEST(setIniFilename_002); + CPPUNIT_TEST_SUITE_END(); + }; // class setIniFilename + + class getHandle : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void getHandle_001() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap; + rtlBootstrapHandle bsHandle = aBootstrap.getHandle(); + CPPUNIT_ASSERT_MESSAGE("getHandle should return 0 if the bootstrap has no ini file!", bsHandle == 0 ); + } + void getHandle_002() + { + rtl::OUString suIniname = t_getSourcePath(PSEUDO_INI); + Bootstrap aBootstrap( suIniname ); + + rtlBootstrapHandle bsHandle = aBootstrap.getHandle(); + CPPUNIT_ASSERT_MESSAGE("getHandle return NULL!", bsHandle != 0); + + //rtl::OUString iniName; + //rtl_bootstrap_get_iniName_from_handle( bsHandle, &iniName.pData ); + + rtl::OUString suValue; + rtl::OUString suKeyName = rtl::OUString::createFromAscii( "PSEUDOFILE" ); + rtl_bootstrap_get_from_handle(bsHandle, suKeyName.pData, &suValue.pData, NULL); + printUString( suValue); + + CPPUNIT_ASSERT_MESSAGE("Can not use the handle which is returned by getHandle!", suValue.equals( rtl::OUString::createFromAscii("be pseudo") ) == sal_True ); + + // CPPUNIT_ASSERT_MESSAGE("Can not use the handle which is returned by getHandle!", + // suGetname.equalsIgnoreAsciiCase( iniName ) == sal_True ); + } + + CPPUNIT_TEST_SUITE(getHandle); + CPPUNIT_TEST(getHandle_001); + CPPUNIT_TEST(getHandle_002); + CPPUNIT_TEST_SUITE_END(); + }; // class getHandle + + class set : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void set_001() + { + //in ini fle, INHERITED_VALUE=inherited_value + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap( suIniname); + rtl::OUString suName = rtl::OUString::createFromAscii( "INHERITED_VALUE" ); + rtl::OUString suValue = rtl::OUString::createFromAscii( "ok" ); + // set to another value + Bootstrap::set( suName, suValue ); + rtl::OUString suGetValue; + Bootstrap::get( suName, suGetValue); + CPPUNIT_ASSERT_MESSAGE("set and get argument failed.", suGetValue.compareTo(suValue) == 0 ); + } + void set_002() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap myBootstrap( suIniname); + rtl::OUString suName = rtl::OUString::createFromAscii( "INHERITED_VALUE" ); + rtl::OUString suGetOrientValue; + Bootstrap::get( suName, suGetOrientValue); + // ?? INHERITED_VALUE = ok now, which is set in set_001 + printUString( suGetOrientValue ); + + rtl::OUString suValue = rtl::OUString::createFromAscii( TESTSHL2_INI ); + // set to another value + Bootstrap::set( suName, suValue ); + rtl::OUString suGetValue; + Bootstrap::get( suName, suGetValue); + CPPUNIT_ASSERT_MESSAGE("set and get argument failed.", suGetValue.compareTo(suValue) == 0 ); + } + + CPPUNIT_TEST_SUITE(set); + CPPUNIT_TEST(set_001); + CPPUNIT_TEST(set_002); + CPPUNIT_TEST_SUITE_END(); + }; // class set + + class expandMacrosFrom : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void tearDown() + { + } + void expandMacrosFrom_001() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap( suIniname); + rtl::OUString suMacro = rtl::OUString::createFromAscii( "$MYVAR/expand1" ); + //printUString( suMacro ); + //expandMacro now + aBootstrap.expandMacrosFrom( suMacro ); + rtl::OUString suExpectedMacro = rtl::OUString::createFromAscii( "src680_test/expand1" ); + //printUString( suMacro ); + CPPUNIT_ASSERT_MESSAGE("expandMacrosFrom failed.", suMacro.compareTo(suExpectedMacro) == 0 ); + } + + /** here a special macro should expand + * if rtlrc is under sal/qa/rtl/bootstrap/, "${rtlrc:Bootstrap:RTLVALUE}" could be expanded + * else rtlrc is under solver/680/unxlngi4.pro/bin/, "${file:/// ....solver/680/unxlngi4.pro/bin/rtlrc:Bootstrap:RTLVALUE}" + * could not be expanded + */ + void expandMacrosFrom_002() + { + // Build a string with '${rtl.ini:RTLVALUE}' and try to expand it. + // In function 'create_rtlrc() is the content of the rtl.ini file. + + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + t_print("inifile is:"); + printUString( suIniname ); + Bootstrap aBootstrap( suIniname) ; + rtl::OUString suMacro = rtl::OUString::createFromAscii( "${" ); //rtlrc:Bootstrap:RTLVALUE}"); + + rtl::OUString aDirURL = OUString::createFromAscii( "$ORIGIN"); + aDirURL += OUString::createFromAscii( "/"); + aDirURL += OUString::createFromAscii( "rtl" ); +#if defined(WNT) || defined(OS2) + aDirURL += rtl::OUString::createFromAscii(".ini"); +#else + aDirURL += rtl::OUString::createFromAscii("rc"); +#endif + + suMacro += aDirURL;//t_getSourcePath("rtl"); + suMacro += rtl::OUString::createFromAscii( "::RTLVALUE}"); + + t_print("created macro is: "); + printUString( suMacro ); + //expandMacro now + aBootstrap.expandMacrosFrom( suMacro ); + t_print("expanded macro is:"); + printUString( suMacro ); + rtl::OUString suExpectedMacro = rtl::OUString::createFromAscii( "qadev17" ); + CPPUNIT_ASSERT_MESSAGE("failed, can't expand '${file:///.../" SAL_CONFIGFILE("rtl") "::RTLVALUE}' to 'qadev17'", suMacro.compareTo(suExpectedMacro) == 0 ); + } + void expandMacrosFrom_002_1() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + t_print("inifile is:"); + printUString( suIniname ); + Bootstrap aBootstrap( suIniname); + + rtl::OUString suMacro; + // just a simple test, if this really work. + aBootstrap.getFrom(rtl::OUString::createFromAscii( "SOFROMVALUE2" ), suMacro ); + t_print("SOFROMVALUE2:"); + printUString( suMacro ); + CPPUNIT_ASSERT_MESSAGE("'SOFROMVALUE2' seems to do not exist.", suMacro.getLength() > 0 ); + + aBootstrap.getFrom(rtl::OUString::createFromAscii( "SOFROMVALUE" ), suMacro ); + + t_print("SOFROMVALUE:"); + printUString( suMacro ); + + //expandMacro now + // seems to be, that getFrom() already expand the string + // t_print("expanded macro is:"); + // aBootstrap.expandMacrosFrom( suMacro ); + // printUString( suMacro ); + rtl::OUString suExpectedMacro = rtl::OUString::createFromAscii( "src680_qadev" ); + CPPUNIT_ASSERT_MESSAGE("failed, can't expand '${" SAL_CONFIGFILE("rtl") "::SOVALUE}' to 'src680_qadev'", suMacro.compareTo(suExpectedMacro) == 0 ); + } + void expandMacrosFrom_002_2() + { + // test, to read and expand SOFROMVALUE3 + // SOFROMVALUE3 is 'rtl(.ini|rc)::TESTSHL_SOVALUE' which should expand to 'rtlfile' if all is ok. + + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + t_print("inifile is:"); + printUString( suIniname ); + Bootstrap aBootstrap( suIniname); + + rtl::OUString suMacro; + aBootstrap.getFrom(rtl::OUString::createFromAscii( "SOFROMVALUE3" ), suMacro ); + + t_print("SOFROMVALUE3:"); + printUString( suMacro ); + + if (suMacro.equals(rtl::OUString::createFromAscii("testshl2_file") ) == sal_True) + { + CPPUNIT_ASSERT_MESSAGE("Value 'SOFROMVALUE3' is read from the wrong ini file.", 0 ); + } + else + { + CPPUNIT_ASSERT_MESSAGE("SOFROMVALUE3 should contain 'rtlfile'.", suMacro.equals(rtl::OUString::createFromAscii("rtlfile") ) == sal_True ); + } + } +//? I don't know if this is a right test. +// void expandMacrosFrom_002_3() +// { +// // test, to read and expand SOFROMVALUE4 +// // SOFROMVALUE4 is 'rtl(.ini|rc):Other_Section:TESTSHL_SOVALUE' which should expand to '' if all is ok. +// +// rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); +// t_print("inifile is:"); +// printUString( suIniname ); +// Bootstrap aBootstrap( suIniname); +// +// rtl::OUString suMacro; +// aBootstrap.getFrom(rtl::OUString::createFromAscii( "SOFROMVALUE4" ), suMacro ); +// +// t_print("SOFROMVALUE4:"); +// printUString( suMacro ); +// +// if (suMacro.equals(rtl::OUString::createFromAscii("testshl2_file") ) == sal_True) +// { +// CPPUNIT_ASSERT_MESSAGE("Value 'SOFROMVALUE4' is read from the wrong section out of the wrong ini file.", 0 ); +// } +// else if (suMacro.equals(rtl::OUString::createFromAscii("testshl2_file_other") ) == sal_True) +// { +// CPPUNIT_ASSERT_MESSAGE("Value 'SOFROMVALUE4' is read from the wrong ini file.", 0 ); +// } +// else +// { +// CPPUNIT_ASSERT_MESSAGE("Value 'SOFROMVALUE4' should contain 'rtlfile_other'.", suMacro.equals(rtl::OUString::createFromAscii("rtlfile_other") ) == sal_True ); +// } +// } + void expandMacrosFrom_003() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap( suIniname); + rtl::OUString suMacro[4]; + suMacro[0] = rtl::OUString::createFromAscii( "$SYSUSERCONFIG" ); + suMacro[1] = rtl::OUString::createFromAscii( "$SYSUSERHOME" ); + suMacro[2] = rtl::OUString::createFromAscii( "$SYSBINDIR" ); + suMacro[3] = rtl::OUString::createFromAscii( "$ORIGIN" ); + + for ( int i = 0; i < 4; i++ ) + { + aBootstrap.expandMacrosFrom( suMacro[i] ); + printUString(suMacro[i]); + } + // printUString( t_getSourcePath("") ); + // CPPUNIT_ASSERT_MESSAGE("some integral variables.", suMacro[3].equalsIgnoreAsciiCase(t_getSourcePath("")) == sal_True ); + CPPUNIT_ASSERT_MESSAGE("some integral variables.", suMacro[0].getLength() > 0 && + suMacro[1].getLength() > 0 && + suMacro[2].getLength() > 0 && + suMacro[3].getLength() > 0); + } + + void testRecursion() { + rtl::OUString t(RTL_CONSTASCII_USTRINGPARAM("$RECURSIVE")); + Bootstrap(t_getSourcePath(TESTSHL2_INI)).expandMacrosFrom(t); + CPPUNIT_ASSERT_MESSAGE( + "recursion detection", + t.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("***RECURSION DETECTED***"))); + } + + void testLink() { + rtl::OUString t(RTL_CONSTASCII_USTRINGPARAM("$LINKED")); + Bootstrap(t_getSourcePath(TESTSHL2_INI)).expandMacrosFrom(t); + CPPUNIT_ASSERT_MESSAGE( + "link file", + t.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("qadev17"))); + } + + void testOverride() { + rtl::OUString t1( + RTL_CONSTASCII_USTRINGPARAM( + "${.override:$ORIGIN/" SAL_CONFIGFILE("rtl") ":ORIGIN}")); + Bootstrap(t_getSourcePath("rtl")).expandMacrosFrom(t1); + CPPUNIT_ASSERT_MESSAGE( + "override ORIGIN", + t1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("direct"))); + rtl::OUString t2( + RTL_CONSTASCII_USTRINGPARAM( + "${.override:$ORIGIN/" SAL_CONFIGFILE("none") ":MYVAR}")); + Bootstrap::expandMacros(t2); + CPPUNIT_ASSERT_MESSAGE( + "override MYVAR", + t2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("src680_test"))); + } + + void testNonexisting() { + rtl::OUString t( + RTL_CONSTASCII_USTRINGPARAM( + "${$ORIGIN/" SAL_CONFIGFILE("none") ":MYVAR}")); + Bootstrap::expandMacros(t); + CPPUNIT_ASSERT_MESSAGE( + "nonexisting", + t.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("src680_test"))); + } + + void testSection() { + rtl::OUStringBuffer b; + b.appendAscii(RTL_CONSTASCII_STRINGPARAM("${")); + rtl::OUString p(t_getSourcePath(TESTSHL2_INI)); + for (sal_Int32 i = 0; i < p.getLength(); ++i) { + if (p[i] != 'u') { + b.append(static_cast< sal_Unicode >('\\')); + } + b.append(p[i]); + } + b.appendAscii(RTL_CONSTASCII_STRINGPARAM(":Other_Section:EXPAND}")); + rtl::OUString t(b.makeStringAndClear()); + Bootstrap(t_getSourcePath(TESTSHL2_INI)).expandMacrosFrom(t); + CPPUNIT_ASSERT_MESSAGE( + "section expansion", + t.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("$FILE"))); + // the correct answer would be "testshl2 file" instead, but + // expansion including a section currently erroneously does not + // recursively expand macros in the resulting replacement text + } + + CPPUNIT_TEST_SUITE(expandMacrosFrom); + CPPUNIT_TEST(expandMacrosFrom_001); + CPPUNIT_TEST(expandMacrosFrom_002); + CPPUNIT_TEST(expandMacrosFrom_002_1); + CPPUNIT_TEST(expandMacrosFrom_002_2); +//? CPPUNIT_TEST(expandMacrosFrom_002_3); + CPPUNIT_TEST(expandMacrosFrom_003); + CPPUNIT_TEST(testRecursion); + CPPUNIT_TEST(testLink); + CPPUNIT_TEST(testOverride); + CPPUNIT_TEST(testNonexisting); + CPPUNIT_TEST(testSection); + CPPUNIT_TEST_SUITE_END(); + }; // class expandMacrosFrom + + class expandMacros : public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void expandMacros_001() + { + rtl::OUString suIniname = t_getSourcePath(TESTSHL2_INI); + Bootstrap aBootstrap( suIniname) ; + rtl::OUString suMacro = rtl::OUString::createFromAscii( "$INHERITED_VALUE/well" ); + Bootstrap::expandMacros( suMacro ); + + rtl::OUString suName = rtl::OUString::createFromAscii( "INHERITED_VALUE" ); + OUString suGetValue; + Bootstrap::get( suName, suGetValue ); + suGetValue += OUString::createFromAscii( "/well" ); + CPPUNIT_ASSERT_MESSAGE("expandMacros failed.", suGetValue.compareTo(suMacro) == 0 ); + } + + CPPUNIT_TEST_SUITE(expandMacros); + CPPUNIT_TEST(expandMacros_001); + // CPPUNIT_TEST(expandMacros_002); + CPPUNIT_TEST_SUITE_END(); + }; // class expandMacros + + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::ctor, "rtl_Bootstrap"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::getFrom, "rtl_Bootstrap"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::setIniFilename, "rtl_Bootstrap"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::getHandle, "rtl_Bootstrap"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::set, "rtl_Bootstrap"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::expandMacrosFrom, "rtl_Bootstrap"); + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Bootstrap::expandMacros, "rtl_Bootstrap"); + +} // namespace rtl_Bootstrap + +// ----------------------------------------------------------------------------- + +// 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. +// NOADDITIONAL; + + +// Here are some helpers, which create a new file 'rtlrc' at the executable path position +// and fill the file with some information. +// static rtl::OUString getExecutableDirectory() +// { +// rtl::OUString fileName; +// osl_getExecutableFile(&fileName.pData); +// +// sal_Int32 nDirEnd = fileName.lastIndexOf('/'); +// +// OSL_ENSURE(nDirEnd >= 0, "Cannot locate executable directory"); +// +// rtl::OUString aDirURL = fileName.copy(0, nDirEnd); +// return aDirURL; +// } + +static void removeAndCreateFile(rtl::OUString const& _suFileURL, rtl::OString const& _sContent) +{ + osl::File::remove(_suFileURL); + + ::std::auto_ptr<osl::File> pFile( new osl::File( _suFileURL ) ); + ::osl::FileBase::RC nError = pFile->open( OpenFlag_Write | OpenFlag_Create ); + if ( ::osl::FileBase::E_None == nError || ::osl::FileBase::E_EXIST == nError ) + { + t_print(T_VERBOSE, "%s\n" , OString(_suFileURL, _suFileURL.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); + sal_uInt64 nWritenBytes; + pFile->write(_sContent.getStr(), _sContent.getLength(), nWritenBytes); + // t_print("nBytes: %ld\n", nBytes); + + rtl::OString sError = "can't write enough bytes to file"; + sError += OString(_suFileURL, _suFileURL.getLength(), RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(nWritenBytes == _sContent.getLength(), sError.getStr()); + + pFile->close(); + } + else + { + rtl::OString sError = "can't create file URL: '"; + rtl::OString sFile; + sFile <<= _suFileURL; + sError += sFile; + sError += "' maybe no write access. If it is true with no write access, please create a local environment and start these tests again. rtl::Bootstrap test must quit."; + t_print("%s\n", sError.getStr() ); + exit(1); + } + OSL_ASSERT(t_fileExist(_suFileURL) == true); +} + +// ----------------------------------------------------------------------------- +static void create_rtlrc() +{ + rtl::OUString aFileURL(getExecutableDirectory()); +#if defined(WNT) || defined(OS2) + aFileURL += rtl::OUString::createFromAscii("/rtl.ini"); +#else + aFileURL += rtl::OUString::createFromAscii("/rtlrc"); +#endif + + rtl::OString sLines; + sLines += "[Bootstrap]\n"; + sLines += "SOVALUE=src680_qadev\n"; + sLines += "RTLVALUE=qadev17\n"; + sLines += "TESTSHL_SOVALUE=rtlfile\n"; + sLines += "RECURSIVE=${$ORIGIN/" SAL_CONFIGFILE("testshl2") ":RECURSIVE}\n"; + sLines += "ORIGIN=direct\n"; + sLines += "[Other_Section]\n"; + sLines += "TESTSHL_SOVALUE=rtlfile_other\n"; + + removeAndCreateFile(aFileURL, sLines); +} + +// ----------------------------------------------------------------------------- +static void create_testshl2rc() +{ + rtl::OUString aFileURL(getExecutableDirectory()); +#if defined(WNT) || defined(OS2) + aFileURL += rtl::OUString::createFromAscii("/testshl2.ini"); +#else + aFileURL += rtl::OUString::createFromAscii("/testshl2rc"); +#endif + rtl::OString sLines; + sLines += "[Bootstrap]\n"; + sLines += "FILE=testshl2 file\n"; + sLines += "MYBOOTSTRAPTESTVALUE=file\n"; + sLines += "INHERITED_VALUE=inherited_value\n"; + sLines += "INHERITED_OVERWRITTEN_VALUE=not_overwritten\n"; + sLines += "MYVAR=src680_test\n"; + sLines += "SOFROMVALUE=${$ORIGIN/" SAL_CONFIGFILE("rtl") "::SOVALUE}\n"; + sLines += "SOFROMVALUE2=test\n"; + sLines += "SOFROMVALUE3=${$ORIGIN/" SAL_CONFIGFILE("rtl") "::TESTSHL_SOVALUE}\n"; + sLines += "TESTSHL_SOVALUE=testshl2_file\n"; + //? sLines += "SOFROMVALUE4=${" SAL_CONFIGFILE("rtl") ":Other_Section:TESTSHL_SOVALUE}\n"; + sLines += "ILLEGAL VALUE=test\n"; + sLines += "ILLEGAL.DOT=test\n"; + sLines += "ILLEGAL;SEMICOLON=test\n"; + sLines += "ILLEGAL:COLON=test\n"; + sLines += " KEY_FOR_TRIM_TEST = value for trim test \n"; + sLines += "RECURSIVE=${$ORIGIN/" SAL_CONFIGFILE("rtl") ":RECURSIVE}\n"; + sLines += "LINKED=${${.link:$ORIGIN/testshl2-link}:RTLVALUE}\n"; + sLines += "[Other_Section]\n"; + sLines += "FILE=testshl2 file other\n"; + sLines += "EXPAND=$FILE\n"; + //? sLines += "TESTSHL_SOVALUE=testshl2_file_other\n"; + + removeAndCreateFile(aFileURL, sLines); + + removeAndCreateFile( + (getExecutableDirectory() + + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/testshl2-link"))), + SAL_CONFIGFILE("rtl")); +} + +// ----------------------------------------------------------------------------- + +static void create_pseudorc() +{ + rtl::OUString aFileURL(getExecutableDirectory()); +#if defined(WNT) || defined(OS2) + aFileURL += rtl::OUString::createFromAscii("/pseudo.ini"); +#else + aFileURL += rtl::OUString::createFromAscii("/pseudorc"); +#endif + rtl::OString sLines; + sLines += "[Bootstrap]\n"; + sLines += "FILE=pseudo file\n"; + sLines += "PSEUDOFILE=be pseudo\n"; + + removeAndCreateFile(aFileURL, sLines); +} + +// ----------------------------------------------------------------------------- +void create_bootstrap_processrc() +{ + rtl::OUString aDirURL(getModulePath()); +#if defined(WNT) || defined(OS2) + aDirURL += rtl::OUString::createFromAscii("/bootstrap_process.ini"); +#else + aDirURL += rtl::OUString::createFromAscii("/bootstrap_processrc"); +#endif + rtl::OString sLines; + sLines += "[Bootstrap]\n"; + sLines += "EXECUTABLE_RC=true\n"; + sLines += "IF_CUSTOM_RC=false\n"; + + removeAndCreateFile(aDirURL, sLines); +} +// ----------------------------------------------------------------------------- + +void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) +{ + (void) _pFunc; + // start message + t_print(T_VERBOSE, "Initializing ...\n" ); + create_rtlrc(); + create_testshl2rc(); + create_pseudorc(); + create_bootstrap_processrc(); + + t_print(T_VERBOSE, "Initialization Done.\n" ); +} + diff --git a/sal/qa/rtl/bootstrap/rtl_Bootstrap.xsce b/sal/qa/rtl/bootstrap/rtl_Bootstrap.xsce new file mode 100644 index 000000000000..df73669613f0 --- /dev/null +++ b/sal/qa/rtl/bootstrap/rtl_Bootstrap.xsce @@ -0,0 +1,7 @@ +#i27888# +rtl_Bootstrap.getFrom.getFrom_004 + +#i27893# +#rtl_Bootstrap.expandMacrosFrom.expandMacrosFrom_002 +#rtl_Bootstrap.expandMacrosFrom.expandMacrosFrom_002_1 +rtl_Bootstrap.expandMacrosFrom.expandMacrosFrom_002_2 diff --git a/sal/qa/rtl/cipher/makefile.mk b/sal/qa/rtl/cipher/makefile.mk new file mode 100644 index 000000000000..fc7a975651f5 --- /dev/null +++ b/sal/qa/rtl/cipher/makefile.mk @@ -0,0 +1,72 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=qa_rtl_cipher + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_cipher.obj + +SHL1TARGET= rtl_cipher +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF2EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:joblist +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/cipher/rtl_cipher.cxx b/sal/qa/rtl/cipher/rtl_cipher.cxx new file mode 100644 index 000000000000..a55f4a20d6fe --- /dev/null +++ b/sal/qa/rtl/cipher/rtl_cipher.cxx @@ -0,0 +1,720 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_cipher.cxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <testshl/simpleheader.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/cipher.h> + +// ----------------------------------------------------------------------------- +namespace rtl_cipher +{ + +rtl::OString createHex(sal_uInt8 *_pKeyBuffer, sal_uInt32 _nKeyLen) +{ + // Create hex-value string from the value to keep the string size minimal + rtl::OStringBuffer aBuffer( _nKeyLen * 2 + 1 ); + for ( sal_uInt32 i = 0; i < _nKeyLen; i++ ) + { + sal_Int32 nValue = (sal_Int32)_pKeyBuffer[i]; + if (nValue < 16) // maximul hex value for 1 byte + { + aBuffer.append( sal_Int32(0), 16 /* radix */ ); + } + aBuffer.append( nValue, 16 /* radix */ ); + } + + return aBuffer.makeStringAndClear(); +} + +// ----------------------------------------------------------------------------- + +class create : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void create_001() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroy(aCipher); + } + void create_002() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); + } + void create_003() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroy(aCipher); + } + void create_004() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC); + CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); + } + void create_005() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroy(aCipher); + } + void create_006() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream); + CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); + } + void create_007() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid); + CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); + } + void create_008() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid); + CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); + } + + // 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createBF_001() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroy(aCipher); + } + void createBF_002() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroy(aCipher); + } + void createBF_003() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroy(aCipher); + } + void createBF_004() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid); + CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); + // 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr) + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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; + + t_print(T_VERBOSE, " init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, " init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + sal_uInt32 nPlainTextLen = 16; + sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ]; + memset(pPlainTextBuffer, 0, nPlainTextLen); + strncpy((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_MESSAGE("wrong encode", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr()); + t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr()); + + 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); + + // rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len); + // t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr()); + // t_print(T_VERBOSE, " ascii: %s\n", sPlainText2Str.getStr()); + // + // // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr()); + // + // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16); + // + // CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0); + // + // delete [] pPlainText2Buffer; + // + // delete [] pCipherBuffer; + // delete [] pPlainTextBuffer; + // + // delete [] pArgBuffer; + // delete [] pKeyBuffer; + // + // rtl_cipher_destroy(aCipher); + } + + void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr) + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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; + + t_print(T_VERBOSE, " init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, " init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + sal_uInt32 nPlainTextLen = 16; + sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ]; + memset(pPlainTextBuffer, 0, nPlainTextLen); + strncpy((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_MESSAGE("wrong encode", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr()); + t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr()); + + 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("wrong decode", aError == rtl_Cipher_E_None); + + rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len); + t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr()); + t_print(T_VERBOSE, " as ascii: %s\n", sPlainText2Str.getStr()); + + // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr()); + + sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16); + + CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0); + + delete [] pPlainText2Buffer; + + delete [] pCipherBuffer; + delete [] pPlainTextBuffer; + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); + } + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void destroy_001() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + 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(destroy); + CPPUNIT_TEST(destroy_001); + CPPUNIT_TEST_SUITE_END(); +}; // class destroy +// ----------------------------------------------------------------------------- +class destroyBF : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void destroyBF_001() + { + rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + rtl_cipher_destroyBF(aCipher); + // more proforma + // should 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(destroyBF); + CPPUNIT_TEST(destroyBF_001); + CPPUNIT_TEST_SUITE_END(); +}; // class destroyBF +// ----------------------------------------------------------------------------- +class encode : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue) + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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; + + t_print(T_VERBOSE, "init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + 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_MESSAGE("wrong encode", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + t_print(T_VERBOSE, "Data: %s\n", createHex(pDataBuffer, nDataLen).getStr()); + t_print(T_VERBOSE, " Buf: %s\n", createHex(pBuffer, nLen).getStr()); + + delete [] pBuffer; + delete [] pDataBuffer; + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); + } + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void init_001() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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); + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); + } + + void init_002() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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); + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); + } + void init_003() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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; + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + rtl_cipher_destroy(aCipher); + } + void init_004() + { + rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); + CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); + + 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; + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen); + CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None); + + t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); + t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); + + delete [] pArgBuffer; + delete [] pKeyBuffer; + + 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(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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + 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_NAMED_REGISTRATION(rtl_cipher::create, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::createBF, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decode, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decodeBF, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroy, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroyBF, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encode, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encodeBF, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::init, "rtl_cipher"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::initBF, "rtl_cipher"); + +} // namespace rtl_cipher + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/rtl/crc32/jobfile.txt b/sal/qa/rtl/crc32/jobfile.txt new file mode 100755 index 000000000000..ddf886ba24aa --- /dev/null +++ b/sal/qa/rtl/crc32/jobfile.txt @@ -0,0 +1,5 @@ +# JobFile for rtl_crc32 +# header source sal/inc/rtl/crc.h + +rtl_crc32.test.rtl_crc32_001 +rtl_crc32.test.rtl_crc32_002 diff --git a/sal/qa/rtl/crc32/makefile.mk b/sal/qa/rtl/crc32/makefile.mk new file mode 100755 index 000000000000..8b1ee4a6f350 --- /dev/null +++ b/sal/qa/rtl/crc32/makefile.mk @@ -0,0 +1,72 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_crc32 +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:jobfile by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_crc32.obj + +SHL1TARGET= rtl_crc32 +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:jobfile +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/crc32/rtl_crc32.cxx b/sal/qa/rtl/crc32/rtl_crc32.cxx new file mode 100755 index 000000000000..09f492376ba2 --- /dev/null +++ b/sal/qa/rtl/crc32/rtl_crc32.cxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_crc32.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl + +#include <testshl/simpleheader.hxx> +#include <rtl/crc.h> + +namespace rtl_CRC32 +{ + +class test : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + + // 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_MESSAGE("empty crc buffer", nCRC == 0); + } + + 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_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2); + } + + /** 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_NAMED_REGISTRATION(rtl_CRC32::test, "rtl_crc32"); +} // namespace rtl_CRC32 + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/rtl/digest/makefile.mk b/sal/qa/rtl/digest/makefile.mk new file mode 100644 index 000000000000..7786522901ee --- /dev/null +++ b/sal/qa/rtl/digest/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_digest +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +#----------------------------------- OStringBuffer ----------------------------------- + +SHL1OBJS= \ + $(SLO)$/rtl_digest.obj + +SHL1TARGET= rtl_digest +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME= $(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/digest/rtl_digest.cxx b/sal/qa/rtl/digest/rtl_digest.cxx new file mode 100644 index 000000000000..9f8dd3f24542 --- /dev/null +++ b/sal/qa/rtl/digest/rtl_digest.cxx @@ -0,0 +1,1454 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_digest.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <testshl/simpleheader.hxx> + +#include <rtl/digest.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/strbuf.hxx> + +// sample, how to use digest + +rtl::OUString CreateMD5FromString( const rtl::OUString& aMsg ) +{ + // PRE: aStr "file" + // BACK: Str "ababab....0f" Hexcode String + + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + if ( handle > 0 ) + { + const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() * sizeof( sal_Unicode )); + sal_uInt32 nMD5KeyLen = rtl_digest_queryLength( handle ); + sal_uInt8* pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ]; + + rtl_digest_init( handle, pData, nSize ); + rtl_digest_update( handle, pData, nSize ); + rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen ); + rtl_digest_destroy( handle ); + + // Create hex-value string from the MD5 value to keep the string size minimal + rtl::OUStringBuffer aBuffer( nMD5KeyLen * 2 + 1 ); + for ( sal_uInt32 i = 0; i < nMD5KeyLen; i++ ) + aBuffer.append( (sal_Int32)pMD5KeyBuffer[i], 16 ); + + delete [] pMD5KeyBuffer; + return aBuffer.makeStringAndClear(); + } + + return rtl::OUString(); +} + +// ----------------------------------------------------------------------------- +namespace rtl_digest +{ + + rtl::OString sSampleString = "This is a sample sentence, which we use to check some crypto functions in sal."; + rtl::OString sSampleString_MD2 = "647ee6c9d4aa5fdd374ed9d7a156acbf"; + rtl::OString sSampleString_MD5 = "b16b903e6fc0b62ae389013ed93fe531"; + rtl::OString sSampleString_SHA = "eab2814429b2613301c8a077b806af3680548914"; + rtl::OString sSampleString_SHA1 = "2bc5bdb7506a2cdc2fd27fc8b9889343012d5008"; + rtl::OString sSampleString_HMAC_MD5 = "dd9cba48c972fba0a882baa72b079674"; + rtl::OString sSampleString_HMAC_SHA1 = "5d7f43ce6abd1de4438d7e69e01495864490cf3e"; + + rtl::OString sSampleString_only_one_diff = "This is a sample sentence. which we use to check some crypto functions in sal."; + +class create : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void create_001() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle != 0); + rtl_digest_destroy( handle ); + } + void create_002() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", handle != 0); + rtl_digest_destroy( handle ); + } + void create_003() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA", handle != 0); + rtl_digest_destroy( handle ); + } + void create_004() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA1", handle != 0); + rtl_digest_destroy( handle ); + } + void create_005() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_MD5", handle != 0); + rtl_digest_destroy( handle ); + } + void create_006() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_SHA1", handle != 0); + rtl_digest_destroy( handle ); + } + + void create_007() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); + t_print("Handle is %x\n", handle); + CPPUNIT_ASSERT_MESSAGE("create with NULL", handle == 0); + rtl_digest_destroy( handle ); + } + + // 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_SUITE_END(); +}; // class create + + + + +// ----------------------------------------------------------------------------- + +class createMD5 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createMD5_001() + { + rtlDigest handle = rtl_digest_createMD5(); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5 == aAlgo); + + rtl_digest_destroy( handle ); + } + CPPUNIT_TEST_SUITE(createMD5); + CPPUNIT_TEST(createMD5_001); + CPPUNIT_TEST_SUITE_END(); +}; // class create + + +// ----------------------------------------------------------------------------- + +class createMD2 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createMD2_001() + { + rtlDigest handle = rtl_digest_createMD2( ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2 == aAlgo); + + rtl_digest_destroy( handle ); + } + CPPUNIT_TEST_SUITE(createMD2); + CPPUNIT_TEST(createMD2_001); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +// ----------------------------------------------------------------------------- + +class createSHA : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createSHA_001() + { + rtlDigest handle = rtl_digest_createSHA( ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA == aAlgo); + + rtl_digest_destroy( handle ); + } + CPPUNIT_TEST_SUITE(createSHA); + CPPUNIT_TEST(createSHA_001); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- + +class createSHA1 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createSHA1_001() + { + rtlDigest handle = rtl_digest_createSHA1(); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1 == aAlgo); + + rtl_digest_destroy( handle ); + } + CPPUNIT_TEST_SUITE(createSHA1); + CPPUNIT_TEST(createSHA1_001); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- + +class createHMAC_MD5 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createHMAC_MD5_001() + { + rtlDigest handle = rtl_digest_createHMAC_MD5(); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5 == aAlgo); + + rtl_digest_destroy( handle ); + } + CPPUNIT_TEST_SUITE(createHMAC_MD5); + CPPUNIT_TEST(createHMAC_MD5_001); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- + +class createHMAC_SHA1 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void createHMAC_SHA1_001() + { + rtlDigest handle = rtl_digest_createHMAC_SHA1(); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1 == aAlgo); + + rtl_digest_destroy( handle ); + } + + + CPPUNIT_TEST_SUITE(createHMAC_SHA1); + CPPUNIT_TEST(createHMAC_SHA1_001); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +// ----------------------------------------------------------------------------- + +class queryAlgorithm : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void query_001() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5 == aAlgo); + + rtl_digest_destroy( handle ); + } + void query_002() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2 == aAlgo); + + rtl_digest_destroy( handle ); + } + void query_003() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA == aAlgo); + + rtl_digest_destroy( handle ); + } + void query_004() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1 == aAlgo); + + rtl_digest_destroy( handle ); + } + void query_005() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5 == aAlgo); + + rtl_digest_destroy( handle ); + } + void query_006() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1 == aAlgo); + + rtl_digest_destroy( handle ); + } + void query_007() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); + + rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); + CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmInvalid == aAlgo); + + rtl_digest_destroy( handle ); + } + + // 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(queryAlgorithm); + CPPUNIT_TEST( query_001 ); + CPPUNIT_TEST( query_002 ); + CPPUNIT_TEST( query_003 ); + CPPUNIT_TEST( query_004 ); + CPPUNIT_TEST( query_005 ); + CPPUNIT_TEST( query_006 ); + CPPUNIT_TEST( query_007 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create + + +// ----------------------------------------------------------------------------- +class queryLength : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void queryLength_MD5() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query Length", RTL_DIGEST_LENGTH_MD5 == nAlgoLength); + + rtl_digest_destroy( handle ); + } + void queryLength_MD2() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_MD2 == nAlgoLength); + + rtl_digest_destroy( handle ); + } + void queryLength_SHA() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA == nAlgoLength); + + rtl_digest_destroy( handle ); + } + void queryLength_SHA1() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA1 == nAlgoLength); + + rtl_digest_destroy( handle ); + } + void queryLength_HMAC_MD5() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_MD5 == nAlgoLength); + + rtl_digest_destroy( handle ); + } + void queryLength_HMAC_SHA1() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_SHA1 == nAlgoLength); + + rtl_digest_destroy( handle ); + } + + void queryLength_Illegal() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); + + sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); + // t_print("nAlgoLength:=%d\n", nAlgoLength); + CPPUNIT_ASSERT_MESSAGE("query length", 0 == nAlgoLength); + + rtl_digest_destroy( handle ); + } + + // 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(queryLength); + CPPUNIT_TEST( queryLength_MD2 ); + CPPUNIT_TEST( queryLength_MD5 ); + CPPUNIT_TEST( queryLength_SHA ); + CPPUNIT_TEST( queryLength_SHA1 ); + CPPUNIT_TEST( queryLength_HMAC_MD5 ); + CPPUNIT_TEST( queryLength_HMAC_SHA1 ); + CPPUNIT_TEST( queryLength_Illegal ); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +// ----------------------------------------------------------------------------- + +rtl::OString createHex(sal_uInt8 *_pMD5KeyBuffer, sal_uInt32 _nMD5KeyLen) +{ + // Create hex-value string from the MD5 value to keep the string size minimal + rtl::OStringBuffer aBuffer( _nMD5KeyLen * 2 + 1 ); + for ( sal_uInt32 i = 0; i < _nMD5KeyLen; i++ ) + { + sal_Int32 nValue = (sal_Int32)_pMD5KeyBuffer[i]; + if (nValue < 16) // maximul hex value for 1 byte + { + aBuffer.append( sal_Int32(0), 16 /* radix */ ); + } + aBuffer.append( nValue, 16 /* radix */ ); + } + + return aBuffer.makeStringAndClear(); +} + + +// ----------------------------------------------------------------------------- +class init : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void init_000() + { + rtlDigest handle = NULL; + + rtlDigestError aError = rtl_digest_init(handle, NULL, 0); + + CPPUNIT_ASSERT_MESSAGE("init(NULL, 0, 0)", aError == rtl_Digest_E_Argument); + } + + void init_001() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + + rtlDigestError aError = rtl_digest_init(handle, NULL, 0); + + CPPUNIT_ASSERT_MESSAGE("init(handle, 0, 0)", aError == rtl_Digest_E_None); + + rtl_digest_destroy( handle ); + } + + // ------------------------------------ + void init_MD2() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + + rtl::OString aMsg = sSampleString; + const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + rtlDigestError aError = rtl_digest_init(handle, pData, nSize); + + CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); + + rtl_digest_update( handle, pData, nSize ); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + + rtl_digest_get( handle, pKeyBuffer, nKeyLen ); + rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); + delete [] pKeyBuffer; + + t_print("MD2 Sum: %s\n", aSum.getStr()); + // LLA: how to check right values + // samples? + + rtl_digest_destroy( handle ); + } + + void init_MD5() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + + rtl::OString aMsg = sSampleString; + const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + rtlDigestError aError = rtl_digest_init(handle, pData, nSize); + + CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); + + rtl_digest_update( handle, pData, nSize ); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + + rtl_digest_get( handle, pKeyBuffer, nKeyLen ); + rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); + delete [] pKeyBuffer; + + t_print("MD5 Sum: %s\n", aSum.getStr()); + // LLA: how to check right values + // samples? + + rtl_digest_destroy( handle ); + } + + void init_SHA() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); + + rtl::OString aMsg = sSampleString; + const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + rtlDigestError aError = rtl_digest_init(handle, pData, nSize); + + CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); + + rtl_digest_update( handle, pData, nSize ); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + + rtl_digest_get( handle, pKeyBuffer, nKeyLen ); + rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); + delete [] pKeyBuffer; + + t_print("SHA Sum: %s\n", aSum.getStr()); + // LLA: how to check right values + // samples? + + rtl_digest_destroy( handle ); + } + void init_SHA1() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); + + rtl::OString aMsg = sSampleString; + const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + rtlDigestError aError = rtl_digest_init(handle, pData, nSize); + + CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); + + rtl_digest_update( handle, pData, nSize ); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + + rtl_digest_get( handle, pKeyBuffer, nKeyLen ); + rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); + delete [] pKeyBuffer; + + t_print("SHA1 Sum: %s\n", aSum.getStr()); + // LLA: how to check right values + // samples? + + rtl_digest_destroy( handle ); + } + void init_HMAC_MD5() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); + + rtl::OString aMsg = sSampleString; + const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen ); + + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + CPPUNIT_ASSERT( pKeyBuffer ); + memset(pKeyBuffer, 0, nKeyLen); + + rtlDigestError aError = rtl_digest_init(handle, pKeyBuffer, nKeyLen ); + + CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); + + rtl_digest_update( handle, pData, nSize ); + + rtl_digest_get( handle, pKeyBuffer, nKeyLen ); + rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); + delete [] pKeyBuffer; + + t_print("HMAC_MD5 Sum: %s\n", aSum.getStr()); + // LLA: how to check right values + // samples? + + rtl_digest_destroy( handle ); + } + void init_HMAC_SHA1() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); + + rtl::OString aMsg = sSampleString; + const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); + CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen ); + + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + CPPUNIT_ASSERT( pKeyBuffer ); + memset(pKeyBuffer, 0, nKeyLen); + + rtlDigestError aError = rtl_digest_init(handle, pKeyBuffer, nKeyLen ); + + CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); + + rtl_digest_update( handle, pData, nSize ); + + rtl_digest_get( handle, pKeyBuffer, nKeyLen ); + rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); + delete [] pKeyBuffer; + + t_print("HMAC_SHA1 Sum: %s\n", aSum.getStr()); + // LLA: how to check right values + // samples? + + rtl_digest_destroy( handle ); + } + + + // 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_000 ); + CPPUNIT_TEST( init_001 ); + CPPUNIT_TEST( init_MD2 ); + CPPUNIT_TEST( init_MD5 ); + CPPUNIT_TEST( init_SHA ); + CPPUNIT_TEST( init_SHA1 ); + CPPUNIT_TEST( init_HMAC_MD5 ); + CPPUNIT_TEST( init_HMAC_SHA1 ); + CPPUNIT_TEST_SUITE_END(); +}; // class init + +// ------------------------------------ + +rtl::OString getMD5Sum(rtl::OString const& _aMsg ) +{ + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + + const sal_uInt8 *pData = (const sal_uInt8*)_aMsg.getStr(); + sal_uInt32 nSize = ( _aMsg.getLength() ); + + rtl_digest_init(handle, pData, nSize); + rtl_digest_update( handle, pData, nSize ); + + sal_uInt32 nMD5KeyLen = rtl_digest_queryLength( handle ); + sal_uInt8 *pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ]; + + rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen ); + rtl::OString aMD5Sum = createHex(pMD5KeyBuffer, nMD5KeyLen); + delete [] pMD5KeyBuffer; + + rtl_digest_destroy( handle ); + return aMD5Sum; +} + +// ----------------------------------------------------------------------------- + +class equalTests : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + void equal_001() + { + rtl::OString aMsg1 = sSampleString; + rtl::OString aMsg2 = sSampleString; + + rtl::OString aMsgMD5Sum1 = getMD5Sum(aMsg1); + rtl::OString aMsgMD5Sum2 = getMD5Sum(aMsg2); + + CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1.getLength() == 32 && aMsgMD5Sum2.getLength() == 32 ); + CPPUNIT_ASSERT_MESSAGE("source is the same, dest must be also the same", aMsgMD5Sum1.equals(aMsgMD5Sum2) == sal_True); + } + // ------------------------------------ + void equal_002() + { + rtl::OString aMsg1 = sSampleString; + rtl::OString aMsg2 = sSampleString_only_one_diff; + + rtl::OString aMsgMD5Sum1 = getMD5Sum(aMsg1); + rtl::OString aMsgMD5Sum2 = getMD5Sum(aMsg2); + + CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1.getLength() == 32 && aMsgMD5Sum2.getLength() == 32 ); + CPPUNIT_ASSERT_MESSAGE("differ only in one char", aMsgMD5Sum1.equals(aMsgMD5Sum2) == sal_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(equalTests); + CPPUNIT_TEST( equal_001 ); + CPPUNIT_TEST( equal_002 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create + + +// ----------------------------------------------------------------------------- +class digest_MD2 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + void MD2_001() + { + rtl::OString aMsg1 = sSampleString; + + sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_MD2 ]; + CPPUNIT_ASSERT( pBuffer ); + memset(pBuffer, 0, RTL_DIGEST_LENGTH_MD2 ); + + sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); + sal_Int32 nLen = aMsg1.getLength(); + + rtlDigestError aError = rtl_digest_MD2(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_MD2); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD2); + t_print("Decrypt MD2: %s\n", aStr.getStr()); + CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD2) ); + + delete [] pBuffer; + } + + // 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(digest_MD2); + CPPUNIT_TEST( MD2_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- +class digest_MD5 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + // ------------------------------------ + void MD5_001() + { + rtl::OString aMsg1 = sSampleString; + + sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_MD5 ]; + CPPUNIT_ASSERT( pBuffer ); + memset(pBuffer, 0, RTL_DIGEST_LENGTH_MD5 ); + + sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); + sal_Int32 nLen = aMsg1.getLength(); + + rtlDigestError aError = rtl_digest_MD5(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_MD5); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD5); + t_print("Decrypt MD5: %s\n", aStr.getStr()); + CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD5) ); + + delete [] pBuffer; + } + + // 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(digest_MD5); + CPPUNIT_TEST( MD5_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +// ----------------------------------------------------------------------------- +class digest_SHA : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + void SHA_001() + { + rtl::OString aMsg1 = sSampleString; + + sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_SHA ]; + CPPUNIT_ASSERT( pBuffer ); + memset(pBuffer, 0, RTL_DIGEST_LENGTH_SHA); + + sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); + sal_Int32 nLen = aMsg1.getLength(); + + rtlDigestError aError = rtl_digest_SHA(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_SHA); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA); + t_print("Decrypt SHA: %s\n", aStr.getStr()); + CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA) ); + + delete [] pBuffer; + } + + // 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(digest_SHA); + CPPUNIT_TEST( SHA_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +// ----------------------------------------------------------------------------- +class digest_SHA1 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + void SHA1_001() + { + rtl::OString aMsg1 = sSampleString; + + sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_SHA1 ]; + CPPUNIT_ASSERT( pBuffer ); + memset(pBuffer, 0, RTL_DIGEST_LENGTH_SHA1); + + sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); + sal_Int32 nLen = aMsg1.getLength(); + + rtlDigestError aError = rtl_digest_SHA1(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_SHA1); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA1); + t_print("Decrypt SHA1: %s\n", aStr.getStr()); + CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA1) ); + + delete [] pBuffer; + } + // 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(digest_SHA1); + CPPUNIT_TEST( SHA1_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- +class digest_HMAC_MD5 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + void HMAC_MD5_001() + { + rtl::OString aMsg1 = sSampleString; + + sal_uInt8 *pKeyBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_MD5 ]; + CPPUNIT_ASSERT( pKeyBuffer ); + memset(pKeyBuffer, 0, RTL_DIGEST_LENGTH_HMAC_MD5); + + sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_MD5 ]; + CPPUNIT_ASSERT( pBuffer ); + memset(pBuffer, 0, RTL_DIGEST_LENGTH_HMAC_MD5); + + sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); + sal_Int32 nLen = aMsg1.getLength(); + + rtlDigestError aError = rtl_digest_HMAC_MD5(pKeyBuffer, RTL_DIGEST_LENGTH_HMAC_MD5, pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5); + t_print("Decrypt HMAC_MD5: %s\n", aStr.getStr()); + CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_MD5) ); + + delete [] pBuffer; + } + // 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(digest_HMAC_MD5); + CPPUNIT_TEST( HMAC_MD5_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- +class digest_HMAC_SHA1 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + void HMAC_SHA1_001() + { + rtl::OString aMsg1 = sSampleString; + + sal_uInt8 *pKeyBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_SHA1 ]; + CPPUNIT_ASSERT( pKeyBuffer ); + memset(pKeyBuffer, 0, RTL_DIGEST_LENGTH_HMAC_SHA1); + + sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_SHA1 ]; + CPPUNIT_ASSERT( pBuffer ); + memset(pBuffer, 0, RTL_DIGEST_LENGTH_HMAC_SHA1); + + sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); + sal_Int32 nLen = aMsg1.getLength(); + + rtlDigestError aError = rtl_digest_HMAC_SHA1(pKeyBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1, pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1); + t_print("Decrypt HMAC_SHA1: %s\n", aStr.getStr()); + CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_SHA1) ); + + delete [] pBuffer; + } + + // 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(digest_HMAC_SHA1); + CPPUNIT_TEST( HMAC_SHA1_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- +class digest_PBKDF2 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ------------------------------------ + rtl::OString /* key */ run_check_PBKDF2(rtl::OString const& _sPassword, bool _bClearSalt, sal_uInt32 _nCount) + { + sal_uInt32 nKeyLen = RTL_DIGEST_LENGTH_HMAC_SHA1; + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + CPPUNIT_ASSERT( pKeyBuffer ); + memset(pKeyBuffer, 0, nKeyLen); + + sal_uInt8 *pPassword = (sal_uInt8*)_sPassword.getStr(); + sal_Int32 nPasswordLen = _sPassword.getLength(); + + sal_uInt32 nSaltDataLen = RTL_DIGEST_LENGTH_HMAC_SHA1; + sal_uInt8 *pSaltData = new sal_uInt8[ nSaltDataLen ]; + CPPUNIT_ASSERT( pSaltData ); + memset(pSaltData, 0, nSaltDataLen); + + if (! _bClearSalt) + { + // wilful contamination + pSaltData[0] = 1; + } + + rtlDigestError aError = rtl_digest_PBKDF2(pKeyBuffer, nKeyLen, pPassword, nPasswordLen, pSaltData, nSaltDataLen, _nCount); + + CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); + + rtl::OString aKey = createHex(pKeyBuffer, nKeyLen); + t_print("Key: %s\n", aKey.getStr()); + + // rtl::OString sSalt = createHex(pSaltData, nSaltDataLen); + // t_print("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) ); + + delete [] pSaltData; + delete [] pKeyBuffer; + return aKey; + } + + void PBKDF2_001() + { + rtl::OString aPassword = "Password"; + + // all permutations + run_check_PBKDF2(aPassword, false, 1); + run_check_PBKDF2(aPassword, false, 2); + run_check_PBKDF2(aPassword, true, 1); + run_check_PBKDF2(aPassword, true, 2); + run_check_PBKDF2(aPassword, false, 3); + run_check_PBKDF2(aPassword, false, 4); + run_check_PBKDF2(aPassword, true, 3); + run_check_PBKDF2(aPassword, true, 4); + } + // 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(digest_PBKDF2); + CPPUNIT_TEST( PBKDF2_001 ); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- + +class update : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void update_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_update(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + void updateMD2_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_updateMD2(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + void updateMD2_001() + { + rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0); + + rtl::OString aMsg = sSampleString; + const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); + + rtlDigestError aError = rtl_digest_updateMD2(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument ); + + /* rtlDigestError */ aError = rtl_digest_updateMD2(aHandle, pData, 0); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_None ); + + rtl_digest_destroyMD2(aHandle); + } + void updateMD5_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_updateMD5(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + void updateMD5_001() + { + // use wrong Algorithm!!! This is volitional! + rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0); + + rtl::OString aMsg = sSampleString; + const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); + sal_uInt32 nSize = ( aMsg.getLength() ); + + rtlDigestError aError = rtl_digest_updateMD5(aHandle, pData, nSize); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError == rtl_Digest_E_Algorithm ); + + rtl_digest_destroyMD5(aHandle); + } + + void updateMD5_002() + { + rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != 0); + + rtl::OString aMsg = sSampleString; + const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); + + rtlDigestError aError = rtl_digest_updateMD5(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument ); + + /* rtlDigestError */ aError = rtl_digest_updateMD5(aHandle, pData, 0); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_None ); + + rtl_digest_destroyMD5(aHandle); + } + + void updateSHA_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_updateSHA(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + void updateSHA1_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_updateSHA1(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + void updateHMAC_MD5_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_updateHMAC_MD5(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + void updateHMAC_SHA1_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_updateHMAC_SHA1(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + + // 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(update); + CPPUNIT_TEST(update_000); + CPPUNIT_TEST(updateMD5_000); + CPPUNIT_TEST(updateMD5_001); + CPPUNIT_TEST(updateMD5_002); + CPPUNIT_TEST(updateMD5_000); + CPPUNIT_TEST(updateSHA_000); + CPPUNIT_TEST(updateSHA1_000); + CPPUNIT_TEST(updateHMAC_MD5_000); + CPPUNIT_TEST(updateHMAC_SHA1_000); + CPPUNIT_TEST_SUITE_END(); +}; // class create +// ----------------------------------------------------------------------------- + +class get : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void get_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_get(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + void getMD5_000() + { + rtlDigest aHandle = NULL; + rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); + } + void getMD5_001() + { + // test with wrong algorithm + rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( aHandle ); + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + + rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("handle 2. parameter wrong", aError == rtl_Digest_E_Argument ); + + /* rtlDigestError */ aError = rtl_digest_getMD5(aHandle, pKeyBuffer, 0); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError == rtl_Digest_E_Algorithm ); + + rtl_digest_destroyMD2(aHandle); + } + + void getMD5_002() + { + rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != 0); + + sal_uInt32 nKeyLen = rtl_digest_queryLength( aHandle ); + sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; + + rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL /* pKeyBuffer */ , nKeyLen); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument ); + + /* rtlDigestError */ aError = rtl_digest_getMD5(aHandle, pKeyBuffer, 0); + CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_BufferSize ); + + rtl_digest_destroyMD5(aHandle); + delete [] pKeyBuffer; + } + + // 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(get); + CPPUNIT_TEST(get_000); + CPPUNIT_TEST(getMD5_000); + CPPUNIT_TEST(getMD5_001); + CPPUNIT_TEST(getMD5_002); + CPPUNIT_TEST_SUITE_END(); +}; // class create + +// ----------------------------------------------------------------------------- +class destroy : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void destroy_001() + { + rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); + CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle != 0); + + // not really testable + // LLA: good will test. + rtl_digest_destroy( handle ); + } + + // 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 create +// ----------------------------------------------------------------------------- + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::create, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD2, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD5, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA1, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_MD5, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_SHA1, "rtl_digest"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryAlgorithm, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryLength, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::init, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::equalTests, "rtl_digest"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD2, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD5, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA1, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_MD5, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_SHA1, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_PBKDF2, "rtl_digest"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::update, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::get, "rtl_digest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest"); +} // namespace rtl_digest + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/rtl/doublelock/makefile.mk b/sal/qa/rtl/doublelock/makefile.mk new file mode 100644 index 000000000000..b46518fb2e68 --- /dev/null +++ b/sal/qa/rtl/doublelock/makefile.mk @@ -0,0 +1,74 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_doublelock +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:testjob by codegen.pl + +.IF "$(GUI)" == "WNT" + CFLAGS+=/Ob1 +.ENDIF + +SHL1OBJS= \ + $(SLO)$/rtl_doublelocking.obj + +SHL1TARGET= rtl_doublelocking +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies + +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/rtl/doublelock/rtl_doublelocking.cxx b/sal/qa/rtl/doublelock/rtl_doublelocking.cxx new file mode 100644 index 000000000000..cbcc334d3134 --- /dev/null +++ b/sal/qa/rtl/doublelock/rtl_doublelocking.cxx @@ -0,0 +1,263 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_doublelocking.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +//------------------------------------------------------------------------ +// include files +//------------------------------------------------------------------------ +#include <sal/types.h> + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/string.hxx> +#endif + +#ifndef _OSL_THREAD_HXX +#include <osl/thread.hxx> +#endif +#include <osl/time.h> + +#include <rtl/instance.hxx> + +#include <testshl/simpleheader.hxx> + +// ----------------------------------------------------------------------------- +#define CONST_TEST_STRING "gregorian" + +namespace { +struct Gregorian : public rtl::StaticWithInit<const ::rtl::OUString, Gregorian> { + const ::rtl::OUString operator () () { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( CONST_TEST_STRING )); + } +}; +} + +inline void printOUString( ::rtl::OUString const & _suStr ) +{ + rtl::OString aString; + + t_print( "OUString: " ); + aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US ); + t_print( "'%s'\n", aString.getStr( ) ); +} + +// ----------------------------------------------------------------------------- +namespace ThreadHelper +{ + // typedef enum { + // QUIET=1, + // VERBOSE + // } eSleepVerboseMode; + + void thread_sleep_tenth_sec(sal_Int32 _nTenthSec/*, eSleepVerboseMode nVerbose = VERBOSE*/) + { + // if (nVerbose == VERBOSE) + // { + // t_print("wait %d tenth seconds. ", _nTenthSec ); + // fflush(stdout); + // } +#ifdef WNT //Windows + Sleep(_nTenthSec * 100 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + TimeValue nTV; + nTV.Seconds = static_cast<sal_uInt32>( _nTenthSec/10 ); + nTV.Nanosec = ( (_nTenthSec%10 ) * 100000000 ); + osl_waitThread(&nTV); +#endif + // if (nVerbose == VERBOSE) + // { + // t_print("done\n"); + // } + } +} + +// ----------------------------------------------------------------------------- + +/** Simple thread for testing Thread-create. + * Just add 1 of value 0, and after running, result is 1. + */ +class OGetThread : public osl::Thread +{ + sal_Int32 m_nOK; + sal_Int32 m_nFails; + + rtl::OUString m_sConstStr; +public: + OGetThread() + :m_nOK(0), + m_nFails(0) + { + m_sConstStr = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( CONST_TEST_STRING )); + } + + sal_Int32 getOK() { return m_nOK; } + sal_Int32 getFails() {return m_nFails;} + +protected: + + /** guarded value which initialized 0 + + @see ThreadSafeValue + */ + void SAL_CALL run() + { + while(schedule()) + { + rtl::OUString aStr = Gregorian::get(); + // printOUString(aStr); + // printOUString(m_sConstStr); + if (aStr.equals(m_sConstStr)) + { + m_nOK++; + } + else + { + m_nFails++; + } + ThreadHelper::thread_sleep_tenth_sec(1); + } + } + +public: + + virtual void SAL_CALL suspend() + { + ::osl::Thread::suspend(); + } + + ~OGetThread() + { + if (isRunning()) + { + t_print("error: not terminated.\n"); + } + } +}; + +// ----------------------------------------------------------------------------- +namespace rtl_DoubleLocking +{ + +/** Test of the osl::Thread::create method + */ + + class getValue : public CppUnit::TestFixture + { + public: + + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + + void getValue_001() + { + rtl::OUString aStr = Gregorian::get(); + printOUString(aStr); + + CPPUNIT_ASSERT_MESSAGE( + "Gregorian::get() failed, wrong value expected.", + aStr.getLength() != 0 + ); + } + + /** 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(); + + ThreadHelper::thread_sleep_tenth_sec(50); + + pThread->terminate(); + p2Thread->terminate(); + + sal_Int32 nValueOK = 0; + nValueOK = pThread->getOK(); + + sal_Int32 nValueOK2 = 0; + nValueOK2 = p2Thread->getOK(); + + t_print("Value in Thread #1 is %d\n", nValueOK); + t_print("Value in Thread #2 is %d\n", nValueOK2); + + sal_Int32 nValueFails = 0; + nValueFails = pThread->getFails(); + + sal_Int32 nValueFails2 = 0; + nValueFails2 = p2Thread->getFails(); + + t_print("Fails in Thread #1 is %d\n", nValueFails); + t_print("Fails in Thread #2 is %d\n", nValueFails2); + + // ThreadHelper::thread_sleep_tenth_sec(1); + pThread->join(); + p2Thread->join(); + + delete pThread; + delete p2Thread; + + CPPUNIT_ASSERT_MESSAGE( + "getValue() failed, wrong value expected.", + nValueOK != 0 && nValueFails == 0 && nValueFails2 == 0 + ); + } + + CPPUNIT_TEST_SUITE(getValue); + CPPUNIT_TEST(getValue_001); + CPPUNIT_TEST(getValue_002); + CPPUNIT_TEST_SUITE_END(); + }; // class create +// ----------------------------------------------------------------------------- + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_DoubleLocking::getValue, "rtl_DoubleLocking"); +} // namespace rtl_DoubleLocking + +// 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. +NOADDITIONAL; diff --git a/sal/qa/rtl/locale/makefile.mk b/sal/qa/rtl/locale/makefile.mk new file mode 100644 index 000000000000..8e4710c5ac6b --- /dev/null +++ b/sal/qa/rtl/locale/makefile.mk @@ -0,0 +1,73 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_locale +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:locale by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_locale.obj + +SHL1TARGET= rtl_locale +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:locale +# END ------------------------------------------------------------------ + + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/locale/rtl_locale.cxx b/sal/qa/rtl/locale/rtl_locale.cxx new file mode 100644 index 000000000000..c677259038f3 --- /dev/null +++ b/sal/qa/rtl/locale/rtl_locale.cxx @@ -0,0 +1,346 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_locale.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl + +#include <testshl/simpleheader.hxx> +#include <rtl/locale.hxx> +#include <osl/thread.h> + +namespace rtl_locale +{ + // default locale for test purpose + void setDefaultLocale() + { + rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), /* rtl::OUString() */ rtl::OUString::createFromAscii("hochdeutsch") ); + } + +class getDefault : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getDefault_000() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + // due to the fact, we set the default locale at first, this test is no longer possible + // ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + // CPPUNIT_ASSERT_MESSAGE("locale must be null", aLocale.getData() == NULL); + + } + + void getDefault_001() + { + // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString()); + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL); + } + + // 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_000); + CPPUNIT_TEST(getDefault_001); + CPPUNIT_TEST_SUITE_END(); +}; // class getDefault + + +class setDefault : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + setDefaultLocale(); + } + + // insert your test code here. + void setDefault_001() + { + rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL); + + // 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() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getLanguage_001() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suLanguage = aLocale.getLanguage(); + t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr()); + CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de"))); + } + void getLanguage_002() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suLanguage = rtl_locale_getLanguage(aLocale.getData()); + t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr()); + CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de"))); + } + + // 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() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getCountry_001() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suCountry = aLocale.getCountry(); + t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr()); + CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE"))); + } + void getCountry_002() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suCountry = rtl_locale_getCountry(aLocale.getData()); + t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr()); + CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE"))); + } + + // 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() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getVariant_001() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suVariant = aLocale.getVariant(); + t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr()); + CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))); + } + void getVariant_002() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + rtl::OUString suVariant = rtl_locale_getVariant(aLocale.getData()); + t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr()); + CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))); + } + + // 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() + { + } + + void tearDown() + { + } + + // insert your test code here. + void hashCode_001() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + sal_Int32 nHashCode = aLocale.hashCode(); + t_print("Hashcode: %d\n", nHashCode); + CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0); + } + void hashCode_002() + { + rtl::OLocale aLocale = ::rtl::OLocale::getDefault(); + sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData()); + t_print("Hashcode: %d\n", nHashCode); + 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() + { + } + + void tearDown() + { + } + + // insert your test code here. + void equals_001() + { + rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); + rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US")); + + sal_Bool bLocaleAreEqual = sal_False; + bLocaleAreEqual = (aLocale1 == aLocale2); + + CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True); + } + + void equals_002() + { + rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString()); + rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US")); + + sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData()); + t_print("rtl_locale_equals() result: %d\n", nEqual); + 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_NAMED_REGISTRATION(rtl_locale::getDefault, "rtl_locale"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::setDefault, "rtl_locale"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getLanguage, "rtl_locale"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getCountry, "rtl_locale"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getVariant, "rtl_locale"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::hashCode, "rtl_locale"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::equals, "rtl_locale"); +} // namespace rtl_locale + + +// ----------------------------------------------------------------------------- + +// 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. +// NOADDITIONAL; + +void RegisterAdditionalFunctions(FktRegFuncPtr) +{ + // start message + t_print("Initializing ...\n" ); + rtl_locale::setDefaultLocale(); + t_print("Initialization Done.\n" ); +} diff --git a/sal/qa/rtl/logfile/makefile.mk b/sal/qa/rtl/logfile/makefile.mk new file mode 100644 index 000000000000..da70d7533fa0 --- /dev/null +++ b/sal/qa/rtl/logfile/makefile.mk @@ -0,0 +1,65 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_logfile + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# --- BEGIN -------------------------------------------------------- +SHL1OBJS= \ + $(SLO)$/rtl_logfile.obj +SHL1TARGET= rtl_logfile +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# END -------------------------------------------------------------- + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/rtl/logfile/rtl_logfile.cxx b/sal/qa/rtl/logfile/rtl_logfile.cxx new file mode 100644 index 000000000000..d589cfb2bf04 --- /dev/null +++ b/sal/qa/rtl/logfile/rtl_logfile.cxx @@ -0,0 +1,263 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_logfile.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + + +// ----------------------------------------------------------------------------- +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if defined(UNX) || defined(OS2) +# include <unistd.h> +#endif + +#include <rtl/logfile.hxx> +#include <testshl/simpleheader.hxx> + +// #ifndef _OSL_MODULE_HXX_ +// #include <osl/module.hxx> +// #endif +#include <osl/file.hxx> +#if ( defined WNT ) // Windows +#include <tools/prewin.h> +// #define UNICODE +// #define WIN32_LEAN_AND_MEAN +// #include <windows.h> +#include <tchar.h> +#include <tools/postwin.h> +#endif + +using namespace ::osl; + +inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) +{ + + if (strlen(msg) > 0) + { + t_print("%s: ", msg ); + } + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", (char *)aString.getStr( ) ); +} + +/** get the absolute source file URL "file:///.../sal/qa/rtl/logfile/" + */ + +inline ::rtl::OUString getTempPath( void ) +{ +#ifdef UNX + rtl::OUString suDirURL(rtl::OUString::createFromAscii("file:///tmp/")); +#else /* Windows */ + rtl::OUString suDirURL(rtl::OUString::createFromAscii("file:///c:/temp/")); +#endif + return suDirURL; +} + +/** if the file exist + */ +bool t_fileExist(rtl::OUString const& _sFilename) +{ + ::osl::FileBase::RC nError1; + ::osl::File aTestFile( _sFilename ); + nError1 = aTestFile.open ( OpenFlag_Read ); + if ( ( ::osl::FileBase::E_NOENT != nError1 ) && ( ::osl::FileBase::E_ACCES != nError1 ) ) + { + aTestFile.close( ); + return true; + } + return false; +} +/** get Current PID. +*/ +inline ::rtl::OUString getCurrentPID( ) +{ + //~ Get current PID and turn it into OUString; + int nPID = 0; +#ifdef WNT + nPID = GetCurrentProcessId(); +#else + nPID = getpid(); +#endif + return ( ::rtl::OUString::valueOf( ( long )nPID ) ); +} + + +// ----------------------------------------------------------------------------- +/* + * LLA: + * check if logfile is create + * be careful with relative logfiles they will create near the source, maybe it's no write access to it. + * use absolute path to logfile instead. + */ +namespace rtl_logfile +{ + class logfile : public CppUnit::TestFixture + { + public: + + //directly call rtl_logfile_trace + void logfile_001() + { +#ifdef SOLARIS + putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1")); +#endif +#ifdef WNT + putenv("RTL_LOGFILE=c:\\temp\\logfile1"); +#endif +#ifdef LINUX + setenv("RTL_LOGFILE", "/tmp/logfile1", 0); +#endif + rtl_logfile_trace("trace %d\n", 2 ); + rtl_logfile_trace("trace %d %d\n" , 1,2 ); + rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 ); + + rtl::OUString suFilePath = getTempPath(); + suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); + suFilePath += rtl::OUString::createFromAscii(".log"); + + ::osl::FileBase::RC nError1; + ::osl::File aTestFile( suFilePath ); + printUString( suFilePath ); + nError1 = aTestFile.open ( OpenFlag_Read ); + CPPUNIT_ASSERT_MESSAGE("create the log file: but the logfile does not exist", + ( ::osl::FileBase::E_NOENT != nError1 ) && + ( ::osl::FileBase::E_ACCES != nError1 ) ); + sal_Char buffer_read[400]; + sal_uInt64 nCount_read; + nError1 = aTestFile.read( buffer_read, 400, nCount_read ); + //t_print("buffer is %s\n", buffer_read ); + CPPUNIT_ASSERT_MESSAGE("write right logs", strstr( buffer_read, "trace 1 2 3") != NULL ); + aTestFile.sync(); + aTestFile.close(); + /*// delete logfile on the disk + + nError1 = osl::File::remove( suFilePath ); + printError( nError1 ); + CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT ) ); + */ + } + //Profiling output should only be generated for a special product version of OpenOffice + // which is compiled with a defined preprocessor symbol 'TIMELOG'. Now, the symbol not defined + void logfile_002() + { +#ifdef SOLARIS + putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); +#endif +#ifdef WNT + putenv("RTL_LOGFILE=c:\\temp\\logfile2"); +#endif +#ifdef LINUX + setenv("RTL_LOGFILE", "/tmp/logfile2", 0); +#endif + RTL_LOGFILE_TRACE( "trace the log" ); + RTL_LOGFILE_TRACE1( "trace %d" , 1 ); + RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 ); + RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 ); +// TODO: assertion test! + } + + void logfile_003() + { +#ifdef SOLARIS + putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); +#endif +#ifdef WNT + putenv("RTL_LOGFILE=c:\\temp\\logfile2"); +#endif +#ifdef LINUX + setenv("RTL_LOGFILE", "/tmp/logfile2", 0); +#endif + RTL_LOGFILE_CONTEXT ( foo , "foo-function" ); + RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" ); + RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 ); + RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 ); + RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 3); +// TODO: assertion test! + } + + + CPPUNIT_TEST_SUITE( logfile ); + CPPUNIT_TEST( logfile_001 ); + CPPUNIT_TEST( logfile_002 ); + CPPUNIT_TEST( logfile_003 ); + CPPUNIT_TEST_SUITE_END( ); + }; + +} // namespace rtl_logfile + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_logfile::logfile, "rtl_logfile" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; + +//~ do some clean up work after all test completed. +class GlobalObject +{ +public: + ~GlobalObject() + { + try + { + t_print( "\n#Do some clean-ups ... only delete logfile1_*.log here!\n" ); + rtl::OUString suFilePath = getTempPath(); + suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); + suFilePath += rtl::OUString::createFromAscii(".log"); + + //if ( ifFileExist( suFilePath ) == sal_True ) + ::osl::FileBase::RC nError1; + nError1 = osl::File::remove( suFilePath ); +#ifdef WNT + t_print("Please remove logfile* manully! Error is Permision denied!"); +#endif + } + catch (CppUnit::Exception &e) + { + t_print("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber()); + } + catch (...) + { + t_print("Exception caught (...) in GlobalObject dtor()\n"); + } + } +}; + +GlobalObject theGlobalObject; + + + diff --git a/sal/qa/rtl/math/export.exp b/sal/qa/rtl/math/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/rtl/math/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/rtl/math/makefile.mk b/sal/qa/rtl/math/makefile.mk new file mode 100644 index 000000000000..5db3ffdd2028 --- /dev/null +++ b/sal/qa/rtl/math/makefile.mk @@ -0,0 +1,99 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.10 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_math +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +#----------------------------------- OStringBuffer ----------------------------------- + +SHL1OBJS= \ + $(SLO)$/test_rtl_math.obj + +SHL1TARGET= rtl_math +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# --- BEGIN -------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/rtl_math.obj +SHL2TARGET= rtl_math2 +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +DEF2NAME= $(SHL2TARGET) +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map + + + +# # --- BEGIN -------------------------------------------------------- +# LLA: this is an old test, which seems not to work +# sal_setInt64() +# sal_getInt64() +# does not exist. +# +# SHL3OBJS= \ +# $(SLO)$/rtl_old_testint64.obj +# SHL3TARGET= rtl_old_testint64 +# SHL3STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +# +# SHL3IMPLIB= i$(SHL3TARGET) +# DEF3NAME= $(SHL3TARGET) +# SHL3VERSIONMAP = $(PRJ)$/qa$/export.map +# + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/math/rtl_math.cxx b/sal/qa/rtl/math/rtl_math.cxx new file mode 100644 index 000000000000..a9c16541e524 --- /dev/null +++ b/sal/qa/rtl/math/rtl_math.cxx @@ -0,0 +1,629 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_math.cxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#ifdef WIN32 +// LLA: take a look into Microsofts math.h implementation, why this define is need +#define _USE_MATH_DEFINES +#endif + +#include <math.h> +#include <testshl/simpleheader.hxx> +#include <rtl/math.h> +#include <rtl/string.hxx> + +#include "valueequal.hxx" + +namespace rtl_math +{ + +class test : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + + void equalCheck(double _nResult, double _nExpect) /* throws Exception */ + { + bool bEqualResult = is_double_equal(_nResult, _nExpect); + + rtl::OString sError = "rtl_math_round expected result is wrong should:("; + sError += rtl::OString::valueOf(_nExpect); + sError += ") but is:("; + sError += rtl::OString::valueOf(_nResult); + sError += ")"; + + CPPUNIT_ASSERT_MESSAGE(sError.getStr(), bEqualResult == true); + } + + // insert your test code here. + void round_000() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nValue = M_PI; + double nResult = 0.0; + + nResult = rtl_math_round(nValue, 0, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(3.0)); + + nResult = rtl_math_round(nValue, 2, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(3.14)); + + nResult = rtl_math_round(nValue, 3, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(3.142)); + + nResult = rtl_math_round(nValue, 10, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(3.1415926536)); + } + + // insert your test code here. + void round_001_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(0.2)); + } + + void round_001_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_Corrected); + equalCheck(nResult, double(-0.2)); + } +// ----------------------------------------------------------------------------- + void round_002_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(0.1)); + } + + void round_002_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_Down); + equalCheck(nResult, double(-0.1)); + } +// ----------------------------------------------------------------------------- + void round_003_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(0.2)); + } + + void round_003_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_Up); + equalCheck(nResult, double(-0.2)); + } +// ----------------------------------------------------------------------------- + void round_004_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(0.1)); + } + + void round_004_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_Floor); + equalCheck(nResult, double(-0.2)); + } +// ----------------------------------------------------------------------------- + void round_005_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(0.2)); + } + + void round_005_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_Ceiling); + equalCheck(nResult, double(-0.1)); + } +// ----------------------------------------------------------------------------- + void round_006_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(0.2)); + } + + void round_006_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_HalfDown); + equalCheck(nResult, double(-0.2)); + } +// ----------------------------------------------------------------------------- + void round_007_positiv() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(0.1, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.11, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.13, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.14, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.1499999, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.1)); + + nResult = rtl_math_round(0.15, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.151, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.16, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.2)); + + nResult = rtl_math_round(0.199999999, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(0.2)); + } + + void round_007_negativ() + { + // this is demonstration code + // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); + + double nResult = 0.0; + + nResult = rtl_math_round(-0.1, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.11, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.13, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.14, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.1499999, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.1)); + + nResult = rtl_math_round(-0.15, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.151, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.16, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.2)); + + nResult = rtl_math_round(-0.19999999999, 1, rtl_math_RoundingMode_HalfUp); + equalCheck(nResult, double(-0.2)); + } + + // 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(round_000); + + CPPUNIT_TEST(round_001_positiv); + CPPUNIT_TEST(round_001_negativ); + + CPPUNIT_TEST(round_002_positiv); + CPPUNIT_TEST(round_002_negativ); + + CPPUNIT_TEST(round_003_positiv); + CPPUNIT_TEST(round_003_negativ); + + CPPUNIT_TEST(round_004_positiv); + CPPUNIT_TEST(round_004_negativ); + + CPPUNIT_TEST(round_005_positiv); + CPPUNIT_TEST(round_005_negativ); + + CPPUNIT_TEST(round_006_positiv); + CPPUNIT_TEST(round_006_negativ); + + CPPUNIT_TEST(round_007_positiv); + CPPUNIT_TEST(round_007_negativ); + + CPPUNIT_TEST_SUITE_END(); +}; // class test + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_math::test, "rtl_math"); +} // namespace rtl_math + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/rtl/math/rtl_old_testint64.cxx b/sal/qa/rtl/math/rtl_old_testint64.cxx new file mode 100644 index 000000000000..923c464186f3 --- /dev/null +++ b/sal/qa/rtl/math/rtl_old_testint64.cxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_old_testint64.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + +// fndef _OSL_DIAGNOSE_H_ +// nclude <osl/diagnose.h> +// #endif + +#include <sal/types.h> + +#define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c)) + +// #if OSL_DEBUG_LEVEL > 0 +// #define TEST_ENSURE(c, m) OSL_ENSURE(c, m) +// #else +// #define TEST_ENSURE(c, m) OSL_VERIFY(c) +// #endif + +#include <testshl/simpleheader.hxx> + +// ----------------------------------------------------------------------------- +namespace rtl_math +{ + class int64 : public CppUnit::TestFixture + { + public: + void test_int64(); + + CPPUNIT_TEST_SUITE( int64 ); + CPPUNIT_TEST( test_int64 ); + CPPUNIT_TEST_SUITE_END( ); + }; + +void int64::test_int64() +{ +#ifndef SAL_INT64_IS_STRUCT +#ifdef UNX + sal_Int64 i1 = -3223372036854775807LL; + sal_uInt64 u1 = 5223372036854775807ULL; +#else + sal_Int64 i1 = -3223372036854775807; + sal_uInt64 u1 = 5223372036854775807; +#endif + sal_Int64 i2 = 0; + sal_uInt64 u2 = 0; +#else + sal_Int64 i1; + sal_setInt64(&i1, 3965190145L, -750499787L); + + sal_Int64 i2 = { 0, 0 }; + + sal_uInt64 u1; + sal_setUInt64(&u1, 1651507199UL, 1216161073UL); + + sal_uInt64 u2 = {0, 0 }; + +#endif + sal_uInt32 low = 0; + sal_Int32 high = 0; + + sal_getInt64(i1, &low, &high); + sal_setInt64(&i2, low, high); + + sal_uInt32 ulow = 0; + sal_uInt32 uhigh = 0; + + sal_getUInt64(u1, &ulow, &uhigh); + sal_setUInt64(&u2, ulow, uhigh); + +#ifndef SAL_INT64_IS_STRUCT + TEST_ENSURE( i1 == i2, "test_int64 error 1"); + + TEST_ENSURE( u1 == u2, "test_int64 error 2"); +#else + TEST_ENSURE( (i1.Part1 == i2.Part1) && (i1.Part2 == i2.Part2), + "test_int64 error 1"); + + TEST_ENSURE( (u1.Part1 == u2.Part1) && (u1.Part2 == u2.Part2), + "test_int64 error 2"); +#endif + return; +} + +} // namespace rtl_math + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_math::int64, "rtl_math" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; + + 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 000000000000..91aa8b444425 --- /dev/null +++ b/sal/qa/rtl/math/test_rtl_math.cxx @@ -0,0 +1,677 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_rtl_math.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "rtl/math.h" +#include "rtl/math.hxx" +#include "rtl/strbuf.hxx" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "rtl/textenc.h" +// #include "rtl/tres.h" +#include <testshl/tresstatewrapper.hxx> +#include "rtl/ustring.hxx" +#include "sal/types.h" + +#include <stdlib.h> + +namespace { + +struct FloatTraits +{ + typedef float Number; + + static inline char const * getPrefix() { return "float"; } +}; + +struct DoubleTraits +{ + typedef double Number; + + static inline char const * getPrefix() { return "double"; } +}; + +struct StringTraits +{ + typedef rtl::OString String; + + static inline char const * getPrefix() { return "OString"; } + + static inline rtl::OString createFromAscii(char const * pString) + { return rtl::OString(pString); } + + static inline void appendBuffer(rtl::OStringBuffer & rBuffer, + rtl::OString const & rString) + { rBuffer.append(rString); } + + static inline rtl::OString doubleToString(double fValue, + rtl_math_StringFormat eFormat, + sal_Int32 nDecPlaces, + sal_Char cDecSeparator, + bool bEraseTrailingDecZeros) + { + return rtl::math::doubleToString(fValue, eFormat, nDecPlaces, + cDecSeparator, bEraseTrailingDecZeros); + } +}; + +struct UStringTraits +{ + typedef rtl::OUString String; + + static inline char const * getPrefix() { return "OUString"; } + + static inline rtl::OUString createFromAscii(char const * pString) + { return rtl::OUString::createFromAscii(pString); } + + static inline void appendBuffer(rtl::OStringBuffer & rBuffer, + rtl::OUString const & rString) + { rBuffer.append(rtl::OUStringToOString(rString, RTL_TEXTENCODING_UTF8)); } + + static inline rtl::OUString doubleToString(double fValue, + rtl_math_StringFormat eFormat, + sal_Int32 nDecPlaces, + sal_Unicode cDecSeparator, + bool bEraseTrailingDecZeros) + { + return rtl::math::doubleToUString(fValue, eFormat, nDecPlaces, + cDecSeparator, + bEraseTrailingDecZeros); + } +}; + +struct TestNumberToString +{ + double fValue; + rtl_math_StringFormat eFormat; + sal_Int32 nDecPlaces; + char cDecSeparator; + bool bEraseTrailingDecZeros; + char const * pResult; +}; + +template< typename StringT, typename NumberT > +bool testNumberToString(hTestResult pTestResult, + TestNumberToString const & rTest) +{ + typename NumberT::Number fValue = static_cast< typename NumberT::Number >(rTest.fValue); + if (fValue != rTest.fValue) + return true; + + // LLA: t_print("size: %d ", sizeof(fValue)); + typename StringT::String aResult1; + + aResult1 = StringT::doubleToString(fValue, rTest.eFormat, rTest.nDecPlaces, + rTest.cDecSeparator, + rTest.bEraseTrailingDecZeros); + + typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult)); + + // LLA: rtl::OStringBuffer aBuf; + // LLA: StringT::appendBuffer(aBuf, aResult1); + // LLA: t_print("aResult1: %s ", aBuf.getStr()); + // LLA: + // LLA: rtl::OStringBuffer aBuf2; + // LLA: StringT::appendBuffer(aBuf2, aResult2); + // LLA: t_print("aResult2: %s\n", aBuf2.getStr()); + + bool bSuccess = aResult1 == aResult2; + + rtl::OStringBuffer aBuffer; + aBuffer.append(StringT::getPrefix()); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM("/")); + aBuffer.append(NumberT::getPrefix()); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" doubleToString(")); + aBuffer.append(fValue); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(static_cast< sal_Int32 >(rTest.eFormat)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(rTest.nDecPlaces); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(rTest.cDecSeparator); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): ")); + StringT::appendBuffer(aBuffer, aResult1); + if (!bSuccess) + { + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != ")); + StringT::appendBuffer(aBuffer, aResult2); + } + // call to the real test checker + // pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math", + // aBuffer.getStr(), false); + c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testNumberToString"); + return bSuccess; +} + +template< typename StringT, typename NumberT > +bool testNumberToString(hTestResult pTestResult, + TestNumberToString const * pTests, size_t nCount) +{ + bool bSuccess = true; + for (size_t i = 0; i < nCount; ++i) + bSuccess &= testNumberToString< StringT, NumberT >(pTestResult, + pTests[i]); + return bSuccess; +} + +struct TestStringToNumberToString +{ + char const * pValue; + rtl_math_StringFormat eFormat; + sal_Int32 nDecPlaces; + char cDecSeparator; + bool bEraseTrailingDecZeros; + char const * pResult; +}; + +template< typename StringT > +bool testStringToNumberToString(hTestResult pTestResult, + TestStringToNumberToString const & rTest) +{ + double d = rtl::math::stringToDouble(StringT::createFromAscii(rTest.pValue), + rTest.cDecSeparator, 0, 0, 0); + typename StringT::String aResult1( + StringT::doubleToString(d, rTest.eFormat, rTest.nDecPlaces, + rTest.cDecSeparator, + rTest.bEraseTrailingDecZeros)); + typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult)); + bool bSuccess = aResult1 == aResult2; + rtl::OStringBuffer aBuffer; + aBuffer.append(StringT::getPrefix()); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM( + " doubleToString(stringToDouble(")); + aBuffer.append(rTest.pValue); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(rTest.cDecSeparator); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM("), ")); + aBuffer.append(static_cast< sal_Int32 >(rTest.eFormat)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(rTest.nDecPlaces); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(rTest.cDecSeparator); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): ")); + StringT::appendBuffer(aBuffer, aResult1); + if (!bSuccess) + { + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != ")); + StringT::appendBuffer(aBuffer, aResult2); + } + // call to the real test checker + // pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math", + // aBuffer.getStr(), false); + c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testStringToNumberToString"); + + return bSuccess; +} + +template< typename StringT > +bool testStringToNumberToString(hTestResult pTestResult, + TestStringToNumberToString const * pTests, + size_t nCount) +{ + bool bSuccess = true; + for (size_t i = 0; i < nCount; ++i) + bSuccess &= testStringToNumberToString< StringT >(pTestResult, + pTests[i]); + return bSuccess; +} + +} + +extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult) +{ + bool bReturn = true; + + { + static TestNumberToString const aTest[] + = { // 1, 1+2^-1, ..., 1+2^-52 + // Too few decimal digits are printed, so that various different + // double values lead to the same output: + { 1, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + { 1.5, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.5" }, + { 1.25, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.25" }, + { 1.125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.125" }, + { 1.0625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.0625" }, + { 1.03125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.03125" }, + { 1.015625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.015625" }, + { 1.0078125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.0078125" }, + { 1.00390625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00390625" }, + { 1.001953125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.001953125" }, + { 1.0009765625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.0009765625" }, + { 1.00048828125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00048828125" }, + { 1.000244140625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.000244140625" }, + { 1.0001220703125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.0001220703125" }, + { 1.00006103515625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00006103515625" }, + { 1.000030517578125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00003051757813" }, + { 1.0000152587890625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00001525878906" }, + { 1.00000762939453125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000762939453" }, + { 1.000003814697265625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000381469727" }, + { 1.0000019073486328125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000190734863" }, + { 1.00000095367431640625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000095367432" }, + { 1.000000476837158203125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000047683716" }, + { 1.0000002384185791015625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000023841858" }, + { 1.00000011920928955078125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000011920929" }, + { 1.000000059604644775390625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000005960464" }, + { 1.0000000298023223876953125, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000002980232" }, + { 1.00000001490116119384765625, rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1.00000001490116" }, + { 1.000000007450580596923828125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000745058" }, + { 1.0000000037252902984619140625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000372529" }, + { 1.00000000186264514923095703125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000186265" }, + { 1.000000000931322574615478515625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000093132" }, + { 1.0000000004656612873077392578125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000046566" }, + { 1.00000000023283064365386962890625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000023283" }, + { 1.000000000116415321826934814453125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000011642" }, + { 1.0000000000582076609134674072265625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000005821" }, + { 1.00000000002910383045673370361328125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.0000000000291" }, + { 1.000000000014551915228366851806640625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000001455" }, + { 1.0000000000072759576141834259033203125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000728" }, + { 1.00000000000363797880709171295166015625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000364" }, + { 1.000000000001818989403545856475830078125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000182" }, + { 1.0000000000009094947017729282379150390625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000091" }, + { 1.00000000000045474735088646411895751953125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000045" }, + { 1.000000000000227373675443232059478759765625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000023" }, + { 1.0000000000001136868377216160297393798828125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000011" }, + { 1.00000000000005684341886080801486968994140625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000006" }, + { 1.000000000000028421709430404007434844970703125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000003" }, + { 1.0000000000000142108547152020037174224853515625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000001" }, + { 1.00000000000000710542735760100185871124267578125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1.00000000000001" }, + { 1.000000000000003552713678800500929355621337890625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1" }, + { 1.0000000000000017763568394002504646778106689453125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1" }, + { 1.00000000000000088817841970012523233890533447265625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1" }, + { 1.000000000000000444089209850062616169452667236328125, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1" }, + { 1.0000000000000002220446049250313080847263336181640625, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true, "1" }, + + // 1, 1+2^-1, ..., 1+2^-52 + // Too few decimal digits are printed, so that various different + // double values lead to the same output: + { 1, rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000000000000000000000000000000000000000000000" }, + { 1.5, rtl_math_StringFormat_F, 53, '.', false, + "1.50000000000000000000000000000000000000000000000000000" }, + { 1.25, rtl_math_StringFormat_F, 53, '.', false, + "1.25000000000000000000000000000000000000000000000000000" }, + { 1.125, rtl_math_StringFormat_F, 53, '.', false, + "1.12500000000000000000000000000000000000000000000000000" }, + { 1.0625, rtl_math_StringFormat_F, 53, '.', false, + "1.06250000000000000000000000000000000000000000000000000" }, + { 1.03125, rtl_math_StringFormat_F, 53, '.', false, + "1.03125000000000000000000000000000000000000000000000000" }, + { 1.015625, rtl_math_StringFormat_F, 53, '.', false, + "1.01562500000000000000000000000000000000000000000000000" }, + { 1.0078125, rtl_math_StringFormat_F, 53, '.', false, + "1.00781250000000000000000000000000000000000000000000000" }, + { 1.00390625, rtl_math_StringFormat_F, 53, '.', false, + "1.00390625000000000000000000000000000000000000000000000" }, + { 1.001953125, rtl_math_StringFormat_F, 53, '.', false, + "1.00195312500000000000000000000000000000000000000000000" }, + { 1.0009765625, rtl_math_StringFormat_F, 53, '.', false, + "1.00097656250000000000000000000000000000000000000000000" }, + { 1.00048828125, rtl_math_StringFormat_F, 53, '.', false, + "1.00048828125000000000000000000000000000000000000000000" }, + { 1.000244140625, rtl_math_StringFormat_F, 53, '.', false, + "1.00024414062500000000000000000000000000000000000000000" }, + { 1.0001220703125, rtl_math_StringFormat_F, 53, '.', false, + "1.00012207031250000000000000000000000000000000000000000" }, + { 1.00006103515625, rtl_math_StringFormat_F, 53, '.', false, + "1.00006103515625000000000000000000000000000000000000000" }, + { 1.000030517578125, rtl_math_StringFormat_F, 53, '.', false, + "1.00003051757813000000000000000000000000000000000000000" }, + { 1.0000152587890625, rtl_math_StringFormat_F, 53, '.', false, + "1.00001525878906000000000000000000000000000000000000000" }, + { 1.00000762939453125, rtl_math_StringFormat_F, 53, '.', false, + "1.00000762939453000000000000000000000000000000000000000" }, + { 1.000003814697265625, rtl_math_StringFormat_F, 53, '.', false, + "1.00000381469727000000000000000000000000000000000000000" }, + { 1.0000019073486328125, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000190734863000000000000000000000000000000000000000" }, + { 1.00000095367431640625, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000095367432000000000000000000000000000000000000000" }, + { 1.000000476837158203125, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000047683716000000000000000000000000000000000000000" }, + { 1.0000002384185791015625, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000023841858000000000000000000000000000000000000000" }, + { 1.00000011920928955078125, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000011920929000000000000000000000000000000000000000" }, + { 1.000000059604644775390625, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000005960464000000000000000000000000000000000000000" }, + { 1.0000000298023223876953125, rtl_math_StringFormat_F, 53, '.', + false, + "1.00000002980232000000000000000000000000000000000000000" }, + { 1.00000001490116119384765625, rtl_math_StringFormat_F, 53, + '.', false, + "1.00000001490116000000000000000000000000000000000000000" }, + { 1.000000007450580596923828125, rtl_math_StringFormat_F, 53, + '.', false, + "1.00000000745058000000000000000000000000000000000000000" }, + { 1.0000000037252902984619140625, rtl_math_StringFormat_F, 53, + '.', false, + "1.00000000372529000000000000000000000000000000000000000" }, + { 1.00000000186264514923095703125, rtl_math_StringFormat_F, 53, + '.', false, + "1.00000000186265000000000000000000000000000000000000000" }, + { 1.000000000931322574615478515625, rtl_math_StringFormat_F, 53, + '.', false, + "1.00000000093132000000000000000000000000000000000000000" }, + { 1.0000000004656612873077392578125, rtl_math_StringFormat_F, + 53, '.', false, + "1.00000000046566000000000000000000000000000000000000000" }, + { 1.00000000023283064365386962890625, rtl_math_StringFormat_F, + 53, '.', false, + "1.00000000023283000000000000000000000000000000000000000" }, + { 1.000000000116415321826934814453125, rtl_math_StringFormat_F, + 53, '.', false, + "1.00000000011642000000000000000000000000000000000000000" }, + { 1.0000000000582076609134674072265625, rtl_math_StringFormat_F, + 53, '.', false, + "1.00000000005821000000000000000000000000000000000000000" }, + { 1.00000000002910383045673370361328125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000002910000000000000000000000000000000000000000" }, + { 1.000000000014551915228366851806640625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000001455000000000000000000000000000000000000000" }, + { 1.0000000000072759576141834259033203125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000728000000000000000000000000000000000000000" }, + { 1.00000000000363797880709171295166015625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000364000000000000000000000000000000000000000" }, + { 1.000000000001818989403545856475830078125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000182000000000000000000000000000000000000000" }, + { 1.0000000000009094947017729282379150390625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000091000000000000000000000000000000000000000" }, + { 1.00000000000045474735088646411895751953125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000045000000000000000000000000000000000000000" }, + { 1.000000000000227373675443232059478759765625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000023000000000000000000000000000000000000000" }, + { 1.0000000000001136868377216160297393798828125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000011000000000000000000000000000000000000000" }, + { 1.00000000000005684341886080801486968994140625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000006000000000000000000000000000000000000000" }, + { 1.000000000000028421709430404007434844970703125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000003000000000000000000000000000000000000000" }, + { 1.0000000000000142108547152020037174224853515625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000001000000000000000000000000000000000000000" }, + { 1.00000000000000710542735760100185871124267578125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000001000000000000000000000000000000000000000" }, + { 1.000000000000003552713678800500929355621337890625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000000000000000000000000000000000000000000000" }, + { 1.0000000000000017763568394002504646778106689453125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000000000000000000000000000000000000000000000" }, + { 1.00000000000000088817841970012523233890533447265625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000000000000000000000000000000000000000000000" }, + { 1.000000000000000444089209850062616169452667236328125, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000000000000000000000000000000000000000000000" }, + { 1.0000000000000002220446049250313080847263336181640625, + rtl_math_StringFormat_F, 53, '.', false, + "1.00000000000000000000000000000000000000000000000000000" } }; + size_t const nCount = sizeof aTest / sizeof aTest[0]; + +//LLA: the float tests are wrong here, due to the fact that +// we calculate with too less digits after the point + +// bReturn &= testNumberToString< StringTraits, FloatTraits >( +// pTestResult, aTest, nCount); + bReturn &= testNumberToString< StringTraits, DoubleTraits >( + pTestResult, aTest, nCount); +// bReturn &= testNumberToString< UStringTraits, FloatTraits >( +// pTestResult, aTest, nCount); + bReturn &= testNumberToString< UStringTraits, DoubleTraits >( + pTestResult, aTest, nCount); + } + + { + static TestStringToNumberToString const aTest[] + = { { "1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + { " 1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + { " 1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + { "\t1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + { "\t 1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + { " \t1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "1" }, + + { "-1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "-1" }, + { " -1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "-1" }, + { " -1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "-1" }, + { "\t-1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "-1" }, + { "\t -1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "-1" }, + { " \t-1", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', true, "-1" }, + + { "1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" }, + { " 1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" }, + { " 1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" }, + { "\t1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" }, + { "\t 1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" }, + { " \t1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#INF" }, + + { "-1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" }, + { " -1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" }, + { " -1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" }, + { "\t-1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" }, + { "\t -1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" }, + { " \t-1.#INF", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#INF" }, + + { "1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" }, + { " 1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" }, + { " 1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" }, + { "\t1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" }, + { "\t 1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" }, + { " \t1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "1.#NAN" }, + + { "-1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" }, + { " -1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" }, + { " -1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" }, + { "\t-1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" }, + { "\t -1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" }, + { " \t-1.#NAN", rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', false, "-1.#NAN" }, + + { "3.14E-2000", rtl_math_StringFormat_E, 4, '.', false, + "0.0000E+000" }, + { "3.14E-200", rtl_math_StringFormat_E, 4, '.', false, + "3.1400E-200" }, + { "3.14E-20", rtl_math_StringFormat_E, 4, '.', false, + "3.1400E-020" }, + { "3.14E-2", rtl_math_StringFormat_E, 4, '.', false, + "3.1400E-002" }, + { "3.14E2", rtl_math_StringFormat_E, 4, '.', false, + "3.1400E+002" }, + { "3.14E20", rtl_math_StringFormat_E, 4, '.', false, + "3.1400E+020" }, + { "3.14E200", rtl_math_StringFormat_E, 4, '.', false, + "3.1400E+200" }, + { "3.14E2000", rtl_math_StringFormat_E, 4, '.', false, + "1.#INF" }, + }; + size_t const nCount = sizeof aTest / sizeof aTest[0]; + bReturn &= testStringToNumberToString< StringTraits >( + pTestResult, aTest, nCount); + bReturn &= testStringToNumberToString< UStringTraits >( + pTestResult, aTest, nCount); + } + + return bReturn; +} + +// ----------------------------------------------------------------------------- +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_math2( hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "rtl_math" ); + + test_rtl_math( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "rtl_math" ); +} +// ----------------------------------------------------------------------------- +void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) +{ + if (_pFunc) + { + (_pFunc)(&test_rtl_math2, ""); + } +} diff --git a/sal/qa/rtl/ostring/joblist.txt b/sal/qa/rtl/ostring/joblist.txt new file mode 100644 index 000000000000..81d1b7a6ba8e --- /dev/null +++ b/sal/qa/rtl/ostring/joblist.txt @@ -0,0 +1,10 @@ +# JobFile for rtl_OString +# header source sal/inc/rtl/string.hxx + +rtl_OString.valueOf.valueOf_test_001 +rtl_OString.valueOf.valueOf_test_002 +rtl_OString.valueOf.valueOf_test_003 +rtl_OString.valueOf.valueOf_test_004 +rtl_OString.valueOf.valueOf_test_005 +rtl_OString.valueOf.valueOf_test_006 +rtl_OString.valueOf.valueOf_test_007 diff --git a/sal/qa/rtl/ostring/makefile.mk b/sal/qa/rtl/ostring/makefile.mk new file mode 100644 index 000000000000..d2c6049afcbc --- /dev/null +++ b/sal/qa/rtl/ostring/makefile.mk @@ -0,0 +1,95 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.8 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=qa_rtl_ostring2 + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_OString2.obj + +SHL1TARGET= rtl_OString2 +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF2EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:joblist +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/rtl_str.obj + +SHL2TARGET= rtl_str +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +DEF2NAME =$(SHL2TARGET) +SHL2VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +SHL3OBJS= \ + $(SLO)$/rtl_string.obj + +SHL3TARGET= rtl_string +SHL3STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL3IMPLIB= i$(SHL3TARGET) +DEF3NAME =$(SHL3TARGET) +SHL3VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/ostring/rtl_OString2.cxx b/sal/qa/rtl/ostring/rtl_OString2.cxx new file mode 100644 index 000000000000..2ff2ca6b434b --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_OString2.cxx @@ -0,0 +1,571 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OString2.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl +// There exist some more test code in sal/qa/rtl_strings/rtl_OString.cxx + +#include <testshl/simpleheader.hxx> +#include "valueequal.hxx" + +namespace rtl_OString +{ + +class valueOf : public CppUnit::TestFixture +{ + void valueOf_float_test_impl(float _nValue) + { + rtl::OString sValue; + sValue = rtl::OString::valueOf( _nValue ); + t_print(T_VERBOSE, "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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // 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) + { + rtl::OString sValue; + sValue = rtl::OString::valueOf( _nValue ); + t_print(T_VERBOSE, "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; + } + + + + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void toDouble_test_impl(rtl::OString const& _sValue) + { + double nValueATOF = atof( _sValue.getStr() ); + + // rtl::OUString suValue = rtl::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(rtl::OString const& _sValue) + { + toDouble_test_impl(_sValue); + + // test also the negativ part. + rtl::OString sNegativValue("-"); + sNegativValue += _sValue; + toDouble_test_impl(sNegativValue); + } + + // insert your test code here. + void toDouble_selftest() + { + t_print("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); + t_print("Selftest done.\n"); + } + + void toDouble_test_3() + { + rtl::OString sValue("3"); + toDouble_test(sValue); + } + void toDouble_test_3_5() + { + rtl::OString sValue("3.5"); + toDouble_test(sValue); + } + void toDouble_test_3_0625() + { + rtl::OString sValue("3.0625"); + toDouble_test(sValue); + } + void toDouble_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + rtl::OString sValue("3.141592653589793238462643383279502884197169399375"); + toDouble_test(sValue); + } + + void toDouble_test_1() + { + rtl::OString sValue("1"); + toDouble_test(sValue); + } + void toDouble_test_10() + { + rtl::OString sValue("10"); + toDouble_test(sValue); + } + void toDouble_test_100() + { + rtl::OString sValue("100"); + toDouble_test(sValue); + } + void toDouble_test_1000() + { + rtl::OString sValue("1000"); + toDouble_test(sValue); + } + void toDouble_test_10000() + { + rtl::OString sValue("10000"); + toDouble_test(sValue); + } + void toDouble_test_1e99() + { + rtl::OString sValue("1e99"); + toDouble_test(sValue); + } + void toDouble_test_1e_n99() + { + rtl::OString sValue("1e-99"); + toDouble_test(sValue); + } + void toDouble_test_1e308() + { + rtl::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: + + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // ----------------------------------------------------------------------------- + + void getToken_000() + { + rtl::OString sTokenStr; + + sal_Int32 nIndex = 0; + do + { + rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + } + while ( nIndex >= 0 ); + // t_print("Index %d\n", nIndex); + // should not GPF + } + + void getToken_001() + { + rtl::OString sTokenStr = "a;b"; + + sal_Int32 nIndex = 0; + + rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* rtl::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() + { + rtl::OString sTokenStr = "a;b.c"; + + sal_Int32 nIndex = 0; + + rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", sToken.equals("b") == sal_True); + + /* rtl::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() + { + rtl::OString sTokenStr = "a;;b"; + + sal_Int32 nIndex = 0; + + rtl::OString sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", sToken.equals("a") == sal_True); + + /* rtl::OString */ sToken = sTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", sToken.getLength() == 0); + + /* rtl::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() + { + rtl::OString sTokenStr = "longer.then.ever."; + + sal_Int32 nIndex = 0; + + rtl::OString sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'longer'", sToken.equals("longer") == sal_True); + + /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'then'", sToken.equals("then") == sal_True); + + /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'ever'", sToken.equals("ever") == sal_True); + + /* rtl::OString */ sToken = sTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", sToken.getLength() == 0); + + 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 +// stollen from sal/qa/rtl_strings/rtl_OString.cxx + +class replaceAt : public CppUnit::TestFixture +{ + +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + sal_Bool check_replaceAt( const rtl::OString* expVal, const rtl::OString* input, + const rtl::OString* newStr, sal_Int32 index, sal_Int32 count) + { + ::rtl::OString aStr1; + aStr1= input->replaceAt( index, count, *newStr ); + + t_print("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 rtl::OString("Java@Sun"), + new rtl::OString("Sun java"), new rtl::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 rtl::OString("Sun Java desktop system"), + new rtl::OString("Sun "), new rtl::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 rtl::OString("SuJava desktop system"), + new rtl::OString("Sun "), new rtl::OString("Java desktop system"), 2, 64 ); + CPPUNIT_ASSERT_MESSAGE("larger count", bRes == sal_True); + } + + void replaceAt_004() + { + + sal_Bool bRes = check_replaceAt(new rtl::OString("Java desktop system"), + new rtl::OString("Sun "), new rtl::OString("Java desktop system"), -4, 8 ); + CPPUNIT_ASSERT_MESSAGE("navigate index", bRes == sal_True); + } + void replaceAt_005() + { + + sal_Bool bRes = check_replaceAt(new rtl::OString("Sun Jesktop System"), + new rtl::OString("Sun Java Desktop System"), new rtl::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_NAMED_REGISTRATION(rtl_OString::valueOf, "rtl_OString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OString::toDouble, "rtl_OString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OString::getToken, "rtl_OString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OString::replaceAt, "rtl_OString"); + +} // 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. +NOADDITIONAL; + diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx new file mode 100644 index 000000000000..6ce43ae0bb9b --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_str.cxx @@ -0,0 +1,893 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_str.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <testshl/simpleheader.hxx> + +namespace rtl_str +{ + + class compare : public CppUnit::TestFixture + { + public: + + void compare_000() + { + rtl_str_compare( NULL, NULL); + } + + void compare_000_1() + { + rtl::OString aStr1 = "Line must be equal."; + rtl_str_compare( aStr1.getStr(), NULL); + } + void compare_001() + { + rtl::OString aStr1 = ""; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl::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() + { + rtl::OString aStr1 = "Line must differ."; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + } + void compare_001() + { + rtl::OString aStr1 = ""; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl::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 insensitve).", nValue == 0); + } + + void compare_003() + { + rtl::OString aStr1 = "Line must differ."; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); + } + void compare_001() + { + rtl::OString aStr1 = ""; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl::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() + { + rtl::OString aStr1 = "Line must be equal."; + rtl::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 insensitve).", nValue == 0); + } + + void compare_003() + { + rtl::OString aStr1 = "Line must differ."; + rtl::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() + { + rtl::OString aStr1 = "Line must differ."; + rtl::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() + { + rtl::OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() ); + t_print("hashcode: %d\n", nHashCode); + // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0); + } + + void hashCode_002() + { + rtl::OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() ); + + rtl::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() + { + rtl::OString aStr1 = "Line for a hashCode."; + sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() ); + + rtl::OString aStr2 = "Line for an other 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() + { + rtl::OString aStr1 = "Line for a 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() + { + rtl::OString aStr1 = "Line for a 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() + { + rtl::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() + { + rtl::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() + { + rtl::OString aStr1 = "Line for a indexOfStr."; + rtl_str_indexOfStr( aStr1.getStr(), 0 ); + } + + void indexOfStr_001() + { + rtl::OString aStr1 = "Line for a 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(), "a index" ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9); + } + + void indexOfStr_002() + { + rtl::OString aStr1 = "Line for a 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() + { + rtl::OString aStr1 = "Line for a lastIndexOfStr."; + rtl_str_lastIndexOfStr( aStr1.getStr(), NULL ); + } + + void lastIndexOfStr_001() + { + rtl::OString aStr1 = "Line for a lastIndexOfStr."; + rtl::OString aSearchStr = "Index"; + + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15); + + /* rtl::OString */ aSearchStr = "Line"; + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* rtl::OString */ aSearchStr = ""; + /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1); + } + + void lastIndexOfStr_002() + { + rtl::OString aStr1 = "Line for a lastIndexOfStr."; + rtl::OString aSearchStr = "foo"; + sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + void lastIndexOfStr_003() + { + rtl::OString aStr1 = "Line for a lastIndexOfStr."; + rtl::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() + { + rtl::OString aStr1 = "replace char."; + rtl::OString aShouldStr1 = "ruplacu char."; + + sal_Char* pStr = (sal_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(rtl::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() + { + rtl::OString aStr1 = "replace char."; + rtl::OString aShouldStr1 = "ruplace char."; + + sal_Char* pStr = (sal_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(rtl::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() + { + rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; + rtl::OString aShouldStr1 = "change this to ascii lower case."; + + sal_Char* pStr = (sal_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(rtl::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() + { + rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE."; + rtl::OString aShouldStr1 = "change thiS TO ASCII LOWER CASE."; + + sal_Char* pStr = (sal_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 ); + + t_print("Lowercase with length: '%s'\n", pStr); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::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() + { + rtl::OString aStr1 = "change this to ascii upper case."; + rtl::OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE."; + + sal_Char* pStr = (sal_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(rtl::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() + { + rtl::OString aStr1 = "change this to ascii lower case."; + rtl::OString aShouldStr1 = "CHANGE THIs to ascii lower case."; + + sal_Char* pStr = (sal_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 ); + + t_print("Uppercase with length: '%s'\n", aStr1.getStr()); + CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::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"; + sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1); + if (pStr2) + { + strcpy(pStr2, pStr); + 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"; + sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1); + if (pStr2) + { + strcpy(pStr2, pStr); + 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"; + sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1); + 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"; + sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1); + if (pStr2) + { + strcpy(pStr2, pStr); + 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 "; + sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1); + if (pStr2) + { + strcpy(pStr2, pStr); + 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() + { + sal_Char *pStr = (sal_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_NAMED_REGISTRATION(rtl_str::compare, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compareIgnoreAsciiCase, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::hashCode, "rtl_str"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfChar, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfChar, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfStr, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfStr, "rtl_str"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar_WithLength, "rtl_str"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength, "rtl_str"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::trim_WithLength, "rtl_str"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::valueOfChar, "rtl_str"); + +} // 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. +NOADDITIONAL; diff --git a/sal/qa/rtl/ostring/rtl_str.xsce b/sal/qa/rtl/ostring/rtl_str.xsce new file mode 100644 index 000000000000..e7a624ae2710 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_str.xsce @@ -0,0 +1,26 @@ +# 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 000000000000..a1fc88037f51 --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_string.cxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_string.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <testshl/simpleheader.hxx> + +namespace rtl_string +{ + + class getLength : public CppUnit::TestFixture + { + public: + + void getLength_000() + { + rtl_string_getLength( NULL ); + // should not GPF + } + + void getLength_001() + { + rtl::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() + { + rtl::OString aStr("Test Length."); + rtl_String *pStr = NULL; + + rtl_string_newFromString( &pStr, aStr.pData ); + + rtl::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() + { + rtl::OUString suString = rtl::OUString::createFromAscii("Hello"); + rtl::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(rtl::OString("Hello")) == sal_True); + } + + void convertUStringToString_002() + { + rtl::OString sStr("H\xE4llo"); + rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + + rtl::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(rtl::OString("H\xE4llo")) == sal_True); + } + + void convertUStringToString_003() + { + rtl::OString sStr("H\xC3\xA4llo"); + rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_UTF8); + + rtl::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(rtl::OString("H\xE4llo")) == sal_True); + } + + void convertUStringToString_004() + { + rtl::OString sStr("Tsch\xFC\xDF"); + rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + rtl::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(rtl::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_NAMED_REGISTRATION(rtl_string::getLength, "rtl_string"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::newFromString, "rtl_string"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_string::convertUStringToString, "rtl_string"); + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/rtl/ostring/rtl_string.xsce b/sal/qa/rtl/ostring/rtl_string.xsce new file mode 100644 index 000000000000..0e37ab00baab --- /dev/null +++ b/sal/qa/rtl/ostring/rtl_string.xsce @@ -0,0 +1 @@ +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 000000000000..5d52da1e3008 --- /dev/null +++ b/sal/qa/rtl/oustring/joblist.txt @@ -0,0 +1,10 @@ +# 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/makefile.mk b/sal/qa/rtl/oustring/makefile.mk new file mode 100644 index 000000000000..40e4ba4a0b58 --- /dev/null +++ b/sal/qa/rtl/oustring/makefile.mk @@ -0,0 +1,84 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.7 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_oustring2 + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_OUString2.obj + +SHL1TARGET= rtl_OUString2 +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:joblist +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/rtl_ustr.obj + +SHL2TARGET= rtl_ustr +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +DEF2NAME =$(SHL2TARGET) +SHL2VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx new file mode 100644 index 000000000000..8632a159ab85 --- /dev/null +++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx @@ -0,0 +1,1283 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OUString2.cxx,v $ + * $Revision: 1.16 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl + +#include <math.h> +#include <stdio.h> + +#include <algorithm> // STL + +#include <testshl/simpleheader.hxx> +#include "stringhelper.hxx" +#include "valueequal.hxx" + +inline void printOUString( ::rtl::OUString const & _suStr ) +{ + rtl::OString aString; + + t_print( "OUString: " ); + aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US ); + t_print( "'%s'\n", aString.getStr( ) ); +} + +namespace rtl_OUString +{ + + class ctors_rtl_uString : public CppUnit::TestFixture + { + + public: + /// test of OUString(rtl_uString*) + void ctors_001() + { + rtl::OUString *pStr = new rtl::OUString( rtl::OUString::createFromAscii("a String") ); + + rtl::OUString aStrToTest(pStr->pData); + delete pStr; + + // maybe here should we do something with current memory + char* pBuffer = (char*) malloc(2 * 8); + memset(pBuffer, 0, 2 * 8); + free(pBuffer); + + sal_Bool bResult = aStrToTest.equals(rtl::OUString::createFromAscii("a String")); + CPPUNIT_ASSERT_MESSAGE("String must not be empty", bResult == 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(ctors_rtl_uString); + CPPUNIT_TEST(ctors_001); + CPPUNIT_TEST_SUITE_END(); + }; + +// ----------------------------------------------------------------------------- +class valueOf : public CppUnit::TestFixture +{ + void valueOf_float_test_impl(float _nValue) + { + rtl::OUString suValue; + suValue = rtl::OUString::valueOf( _nValue ); + rtl::OString sValue; + sValue <<= suValue; + t_print(T_VERBOSE, "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) + { + rtl::OUString suValue; + suValue = rtl::OUString::valueOf( _nValue ); + rtl::OString sValue; + sValue <<= suValue; + t_print(T_VERBOSE, "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 + +//------------------------------------------------------------------------ +// testing the method toDouble() +//------------------------------------------------------------------------ +template<class T> +sal_Int16 SAL_CALL checkPrecisionSize() +{ + // sal_Int16 nSize = sizeof(T); + volatile T nCalcValue = 1.0; + + + // (i + 1) is the current precision + // numerical series + // 1.1 + // 10.1 + // 100.1 + // ... + // 1000...0.1 + + sal_Int16 i = 0; + for (i=0;i<50;i++) + { + nCalcValue *= 10; + volatile T nValue = nCalcValue + static_cast<T>(0.1); + volatile T dSub = nValue - nCalcValue; + // ----- 0.11 ---- 0.1 ---- 0.09 ----- + if (0.11 > dSub && dSub < 0.09) + { + // due to the fact, that the value is break down we sub 1 from the precision value + // but to suppress this, we start at zero, precision is i+1 till here --i; + break; + } + } + + sal_Int16 j= 0; + nCalcValue = 1.0; + + // numerical series + // 1.1 + // 1.01 + // 1.001 + // ... + // 1.000...001 + + for (j=0;j<50;j++) + { + nCalcValue /= 10; + volatile T nValue = nCalcValue + static_cast<T>(1.0); + volatile T dSub = nValue - static_cast<T>(1.0); + // ---- 0.02 ----- 0.01 ---- 0 --- -0.99 ---- -0.98 ---- + // volatile T dSubAbsolut = fabs(dSub); + // ---- 0.02 ----- 0.01 ---- 0 (cut) + if ( dSub == 0) + break; + } + if (i != j) + { + // hmmm.... + // imho i +- 1 == j is a good value + int n = i - j; + if (n < 0) n = -n; + if (n <= 1) + { + return std::min(i,j); + } + else + { + t_print("warning: presision differs more than 1!\n"); + } + } + + return i; +} + +// ----------------------------------------------------------------------------- + + class testPrecision + { + public: + testPrecision() + { + sal_Int16 nPrecision; + nPrecision = checkPrecisionSize<float>(); + t_print("precision of float: %d sizeof()=%d \n", nPrecision, sizeof(float)); + + nPrecision = checkPrecisionSize<double>(); + t_print("precision of double: %d sizeof()=%d \n", nPrecision, sizeof(double)); + + nPrecision = checkPrecisionSize<long double>(); + t_print("precision of long double: %d sizeof()=%d \n", nPrecision, sizeof(long double)); + + } + + }; + + class toInt: public CppUnit::TestFixture { + public: + void test() { + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(-0x76543210), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-76543210")). + toInt32(16))); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(0xFEDCBA98), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+FEDCBA98")). + toInt32(16))); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int64 >(-SAL_CONST_INT64(0x76543210FEDCBA98)), + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("-76543210FEDCBA98")). + toInt64(16))); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int64 >(SAL_CONST_INT64(0xFEDCBA9876543210)), + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("+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(rtl::OString const& _sValue) + { + //t_print("the original str is %s\n", _sValue.getStr()); + double nValueATOF = atof( _sValue.getStr() ); + //t_print("original data is %e\n", nValueATOF); + rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() ); + double nValueToDouble = suValue.toDouble(); + //t_print("result data is %e\n", nValueToDouble); + + bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void toDouble_test(rtl::OString const& _sValue) + { + toDouble_test_impl(_sValue); + + // test also the negativ part. + rtl::OString sNegativValue("-"); + sNegativValue += _sValue; + toDouble_test_impl(sNegativValue); + } + + // insert your test code here. + void toDouble_selftest() + { + t_print("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 15 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); + t_print("Selftest done.\n"); + } + + void toDouble_test_3() + { + rtl::OString sValue("3"); + toDouble_test(sValue); + } + void toDouble_test_3_5() + { + rtl::OString sValue("3.5"); + toDouble_test(sValue); + } + void toDouble_test_3_0625() + { + rtl::OString sValue("3.0625"); + toDouble_test(sValue); + } + void toDouble_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + rtl::OString sValue("3.141592653589793238462643383279502884197169399375"); + toDouble_test(sValue); + } + + void toDouble_test_1() + { + rtl::OString sValue("1"); + toDouble_test(sValue); + } + void toDouble_test_10() + { + rtl::OString sValue("10"); + toDouble_test(sValue); + } + void toDouble_test_100() + { + rtl::OString sValue("100"); + toDouble_test(sValue); + } + void toDouble_test_1000() + { + rtl::OString sValue("1000"); + toDouble_test(sValue); + } + void toDouble_test_10000() + { + rtl::OString sValue("10000"); + toDouble_test(sValue); + } + void toDouble_test_1e99() + { + rtl::OString sValue("1e99"); + toDouble_test(sValue); + } + void toDouble_test_1e_n99() + { + rtl::OString sValue("1e-99"); + toDouble_test(sValue); + } + void toDouble_test_1e308() + { + rtl::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(rtl::OString const& _sValue) + { + //t_print("the original str is %s\n", _sValue.getStr()); + float nValueATOF = static_cast<float>(atof( _sValue.getStr() )); + //t_print("the original str is %.10f\n", nValueATOF); + rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() ); + float nValueToFloat = suValue.toFloat(); + //t_print("the result str is %.10f\n", nValueToFloat); + + bool bEqualResult = is_float_equal(nValueToFloat, nValueATOF); + CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true); + } + + void toFloat_test(rtl::OString const& _sValue) + { + toFloat_test_impl(_sValue); + + // test also the negativ part. + rtl::OString sNegativValue("-"); + sNegativValue += _sValue; + toFloat_test_impl(sNegativValue); + } + + // insert your test code here. + void toFloat_selftest() + { + t_print("Start selftest:\n"); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.01f) == false); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.001f) == false); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0001f) == false); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00001f) == false); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000002f) == false); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0000001f) == true); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00000001f) == true); + CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000000001f) == true); + + t_print("Selftest done.\n"); + } + + void toFloat_test_3() + { + rtl::OString sValue("3"); + toFloat_test(sValue); + } + void toFloat_test_3_5() + { + rtl::OString sValue("3.5"); + toFloat_test(sValue); + } + void toFloat_test_3_0625() + { + rtl::OString sValue("3.0625"); + toFloat_test(sValue); + } + void toFloat_test_3_0625_e() + { + rtl::OString sValue("3.0625e-4"); + toFloat_test(sValue); + } + void toFloat_test_pi() + { + // value from http://www.angio.net/pi/digits/50.txt + rtl::OString sValue("3.141592653589793238462643383279502884197169399375"); + toFloat_test(sValue); + } + + void toFloat_test_1() + { + rtl::OString sValue("1"); + toFloat_test(sValue); + } + void toFloat_test_10() + { + rtl::OString sValue("10"); + toFloat_test(sValue); + } + void toFloat_test_100() + { + rtl::OString sValue("100"); + toFloat_test(sValue); + } + void toFloat_test_1000() + { + rtl::OString sValue("1000"); + toFloat_test(sValue); + } + void toFloat_test_10000() + { + rtl::OString sValue("10000"); + toFloat_test(sValue); + } + void toFloat_test_mix() + { + rtl::OString sValue("456789321455.123456789012"); + toFloat_test(sValue); + } + void toFloat_test_1e99() + { + rtl::OString sValue("1e99"); + toFloat_test(sValue); + } + void toFloat_test_1e_n99() + { + rtl::OString sValue("1e-9"); + toFloat_test(sValue); + } + void toFloat_test_1e308() + { + rtl::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(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos) + { + // Algorithm + // search the string _suSearchStr (rtl::OUString) in the string _suStr. + // check if the _nExpectedResultPos occurs. + + sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr); + CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos); + } + + void lastIndexOf_salunicode(rtl::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_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos); + } + + void lastIndexOf_oustring_offset(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset) + { + sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr, _nStartOffset); + CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos); + } + + void lastIndexOf_salunicode_offset(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset) + { + sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar, _nStartOffset); + CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos); + } + + // ----------------------------------------------------------------------------- + + void lastIndexOf_test_oustring_offset_001() + { + // search for sun, start at the end, found (pos==0) + rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("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) + rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, 0, 3); + } + + void lastIndexOf_test_oustring_offset_003() + { + // search for sun, start at pos = 2, found (pos==-1) + rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 2); + } + + void lastIndexOf_test_oustring_offset_004() + { + // search for sun, start at the end, found (pos==0) + rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring_offset(aStr, aSearchStr, -1, -1); + } + + void lastIndexOf_test_oustring_001() + { + // search for sun, found (pos==0) + rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 0); + } + + void lastIndexOf_test_oustring_002() + { + // search for sun, found (pos==4) + rtl::OUString aStr = rtl::OUString::createFromAscii("the sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 4); + } + + void lastIndexOf_test_oustring_003() + { + // search for sun, found (pos==8) + rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 8); + } + + void lastIndexOf_test_oustring_004() + { + // search for sun, found (pos==8) + rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 8); + } + + void lastIndexOf_test_oustring_005() + { + // search for sun, found (pos==4) + rtl::OUString aStr = rtl::OUString::createFromAscii("the sun su"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring(aStr, aSearchStr, 4); + } + + void lastIndexOf_test_oustring_006() + { + // search for sun, found (pos==-1) + rtl::OUString aStr = rtl::OUString::createFromAscii("the su su"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun"); + lastIndexOf_oustring(aStr, aSearchStr, -1); + } + + void lastIndexOf_test_oustring_007() + { + // search for earth, not found (-1) + rtl::OUString aStr = rtl::OUString::createFromAscii("the su su"); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("earth"); + lastIndexOf_oustring(aStr, aSearchStr, -1); + } + + void lastIndexOf_test_oustring_008() + { + // search for earth, not found (-1) + rtl::OUString aStr = rtl::OUString(); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("earth"); + lastIndexOf_oustring(aStr, aSearchStr, -1); + } + + void lastIndexOf_test_oustring_009() + { + // search for earth, not found (-1) + rtl::OUString aStr = rtl::OUString(); + rtl::OUString aSearchStr = rtl::OUString(); + lastIndexOf_oustring(aStr, aSearchStr, -1); + + } + + void lastIndexOf_test_salunicode_001() + { + // search for 's', found (19) + rtl::OUString aStr = rtl::OUString::createFromAscii("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) + rtl::OUString aStr = rtl::OUString::createFromAscii("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) + rtl::OUString aStr = rtl::OUString::createFromAscii("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) + rtl::OUString aStr = rtl::OUString::createFromAscii("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) + rtl::OUString aStr = rtl::OUString::createFromAscii("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() + { + rtl::OUString suTokenStr; + + sal_Int32 nIndex = 0; + do + { + rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + } + while ( nIndex >= 0 ); + t_print("Index %d\n", nIndex); + // should not GPF + } + + void getToken_001() + { + rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;b"); + + sal_Int32 nIndex = 0; + + rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_002() + { + rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;b.c"); + + sal_Int32 nIndex = 0; + + rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'c'", suToken.equals(rtl::OUString::createFromAscii("c")) == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_003() + { + rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;;b"); + + sal_Int32 nIndex = 0; + + rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.getLength() == 0); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True); + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_004() + { + rtl::OUString suTokenStr = rtl::OUString::createFromAscii("longer.then.ever."); + + sal_Int32 nIndex = 0; + + rtl::OUString suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'longer'", suToken.equals(rtl::OUString::createFromAscii("longer")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'then'", suToken.equals(rtl::OUString::createFromAscii("then")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be 'ever'", suToken.equals(rtl::OUString::createFromAscii("ever")) == sal_True); + + /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex ); + CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.getLength() == 0); + + CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1); + } + + void getToken_005() { + rtl::OUString ab(RTL_CONSTASCII_USTRINGPARAM("ab")); + sal_Int32 n = 0; + CPPUNIT_ASSERT_MESSAGE( + "token should be 'ab'", ab.getToken(0, '-', n) == ab); + CPPUNIT_ASSERT_MESSAGE("n should be -1", n == -1); + CPPUNIT_ASSERT_MESSAGE( + "token should be empty", ab.getToken(0, '-', n).getLength() == 0); + } + + 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 }; + rtl::OString s; + CPPUNIT_ASSERT( + rtl::OUString(utf16, sizeof utf16 / sizeof utf16[0]).convertToString( + &s, RTL_TEXTENCODING_UTF7, + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | + RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))); + CPPUNIT_ASSERT_EQUAL( + rtl::OString(RTL_CONSTASCII_STRINGPARAM("A+AOQ-a")), s); +} + +// ----------------------------------------------------------------------------- +// - string construction & interning (tests) +// ----------------------------------------------------------------------------- +class construction : public CppUnit::TestFixture +{ +public: + void construct() + { +#ifdef RTL_INLINE_STRINGS + ::rtl::OUString aFoo( RTL_CONSTASCII_USTRINGPARAM("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); + + ::rtl::OUString aBaa( RTL_CONSTASCII_USTRINGPARAM("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 ... + rtl::OUString aEmpty = rtl::OUString().intern(); + rtl::OUString aEmpty2 = rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "" ) ); + + ::rtl::OUString aFoo( RTL_CONSTASCII_USTRINGPARAM("foo") ); + ::rtl::OUString aFooIntern = aFoo.intern(); + CPPUNIT_ASSERT_MESSAGE("string contents", aFooIntern.equalsAscii("foo")); + CPPUNIT_ASSERT_MESSAGE("string length", aFooIntern.getLength() == 3); + // 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; + rtl::OUString *pStrs; + sal_uIntPtr *pValues; + + pStrs = new rtl::OUString[nSequence]; + pValues = new sal_uIntPtr[nSequence]; + for (i = 0; i < nSequence; i++) + { + pStrs[i] = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern(); + pValues[i] = reinterpret_cast<sal_uIntPtr>( pStrs[i].pData ); + } + for (i = 0; i < nSequence; i++) + { + rtl::OUString aNew = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern(); + CPPUNIT_ASSERT_MESSAGE("double intern failed", + aNew.pData == pStrs[i].pData); + } + + // Free strings to check for leaks + for (i = 0; i < nSequence; i++) + { + // Overwrite - hopefully this re-uses the memory + pStrs[i] = rtl::OUString(); + pStrs[i] = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ); + } + + for (i = 0; i < nSequence; i++) + { + rtl::OUString aIntern; + sal_uIntPtr nValue; + aIntern = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern(); + + nValue = reinterpret_cast<sal_uIntPtr>( aIntern.pData ); + // This may not be 100% reliable: memory may + // have been re-used, but it's worth checking. + CPPUNIT_ASSERT_MESSAGE("intern leaking", nValue != pValues[i]); + } + delete [] pValues; + delete [] pStrs; + } + + 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), + rtl::OUString().indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM(""))); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(-1), + rtl::OUString().lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM(""))); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(0), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")).indexOfAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(0), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")).lastIndexOfAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(2), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("fofoobar")).indexOfAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foofoofob")). + lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(3), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foofoobar")).indexOfAsciiL( + RTL_CONSTASCII_STRINGPARAM("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, + rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(""))); + CPPUNIT_ASSERT_EQUAL( + false, + rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("foo"))); + CPPUNIT_ASSERT_EQUAL( + true, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bar")).endsWithAsciiL( + RTL_CONSTASCII_STRINGPARAM("bar"))); + CPPUNIT_ASSERT_EQUAL( + true, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobar")).endsWithAsciiL( + RTL_CONSTASCII_STRINGPARAM("bar"))); + CPPUNIT_ASSERT_EQUAL( + false, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FOOBAR")).endsWithAsciiL( + RTL_CONSTASCII_STRINGPARAM("bar"))); +} + +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), + rtl::OUString(static_cast< sal_uInt32 const * >(NULL), 0).getLength()); + static sal_uInt32 const cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF }; + rtl::OUString s(cp, sizeof cp / sizeof (sal_uInt32)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength()); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0), s[0]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[1]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xFFFF), s[2]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[3]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDC00), s[4]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDBFF), s[5]); + CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDFFF), 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 }; + rtl::OUString s(utf16, sizeof utf16 / sizeof (sal_Unicode)); + 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(createFromCodePoints); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void convertFromString::test() { + rtl::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(t.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("abc"))); +} + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::valueOf, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toInt, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toDouble, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toFloat, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::lastIndexOf, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::getToken, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( + rtl_OUString::convertToString, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::construction, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( + rtl_OUString::indexOfAscii, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::endsWith, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( + rtl_OUString::createFromCodePoints, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( + rtl_OUString::iterateCodePoints, "rtl_OUString"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( + rtl_OUString::convertFromString, "rtl_OUString"); + +} // namespace rtl_OUString + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; diff --git a/sal/qa/rtl/oustring/rtl_ustr.cxx b/sal/qa/rtl/oustring/rtl_ustr.cxx new file mode 100644 index 000000000000..43610d0461f4 --- /dev/null +++ b/sal/qa/rtl/oustring/rtl_ustr.cxx @@ -0,0 +1,1427 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_ustr.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <testshl/simpleheader.hxx> + +/** print a UNI_CODE file name. +*/ +inline void printOUString( ::rtl::OUString const & _suStr ) +{ + rtl::OString aString; + + t_print( "OUString: " ); + aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US ); + t_print( "%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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_compare( aStr1.getStr(), NULL); + // should not GPF + } + void compare_001() + { + rtl::OUString aStr1; + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + } + void compare_001() + { + rtl::OUString aStr1; + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL."); + + sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); + CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0); + } + + void compare_003() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); + } + void compare_001() + { + rtl::OUString aStr1; + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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 insensitve).", nValue == 0); + } + + void compare_003() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::OUString aStr2 = rtl::OUString::createFromAscii("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() +// { +// rtl::OString aStr1 = "Line for a hashCode."; +// sal_Int32 nHashCode = rtl_ustr_hashCode( aStr1.getStr() ); +// t_print("hashcode: %d\n", nHashCode); +// // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0); +// } +// +// void hashCode_002() +// { +// rtl::OString aStr1 = "Line for a hashCode."; +// sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); +// +// rtl::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() +// { +// rtl::OString aStr1 = "Line for a hashCode."; +// sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); +// +// rtl::OString aStr2 = "Line for an other 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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a 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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a 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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); + rtl_ustr_indexOfStr( aStr1.getStr(), 0 ); + } + + void indexOfStr_001() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); + + rtl::OUString suSearch = rtl::OUString::createFromAscii("Line"); + sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("for"); + /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5); + + /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a"); + /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9); + + /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a index"); + /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9); + } + + void indexOfStr_002() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); + rtl::OUString suSearch = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); + rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL ); + } + + void lastIndexOfStr_001() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("Index"); + + sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15); + + /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("Line"); + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); + + /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii(""); + /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1); + } + + void lastIndexOfStr_002() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("foo"); + sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); + + CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); + } + + void lastIndexOfStr_003() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); + rtl::OUString aSearchStr = rtl::OUString::createFromAscii("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char."); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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); + memset(pStr, 0, nLength + sizeof(sal_Unicode)); + memcpy(pStr, aStr1.getStr(), nLength); + + rtl_ustr_replaceChar( pStr, 'e', 'u' ); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char."); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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' ); + rtl::OUString suStr(pStr, aStr1.getLength()); + + CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); + free(pStr); + } + + void replaceChar_WithLength_002() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("eeeeeeeeeeeee"); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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' ); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE."); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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); + memset(pStr, 0, nLength + sizeof(sal_Unicode)); // empty the sal_Unicode array + memcpy(pStr, aStr1.getStr(), nLength); + + rtl_ustr_toAsciiLowerCase( pStr ); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE."); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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 ); + + rtl::OUString suStr(pStr, aStr1.getLength()); + sal_Bool bResult = aShouldStr1.equals(suStr); + + printOUString(suStr); + t_print("Result length: %d\n", suStr.getLength() ); + t_print("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii upper case."); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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); + memset(pStr, 0, nLength + sizeof(sal_Unicode)); + memcpy(pStr, aStr1.getStr(), nLength); + + rtl_ustr_toAsciiUpperCase( pStr ); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii lower case."); + rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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 ); + rtl::OUString suStr(pStr, aStr1.getLength()); + + // t_print("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() + { + rtl::OUString suStr = rtl::OUString::createFromAscii(" 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() + { + rtl::OUString suStr = rtl::OUString::createFromAscii(" 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", rtl::OUString(pStr).getLength() == 0); + free(pStr); + } + + + void trim_WithLength_002() + { + rtl::OUString suStr = rtl::OUString::createFromAscii("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'", rtl::OUString(pStr).getLength() == 4); + free(pStr); + } + + + void trim_WithLength_003() + { + rtl::OUString suStr = rtl::OUString::createFromAscii(" 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'", rtl::OUString(pStr).getLength() == 4); + free(pStr); + } + + void trim_WithLength_004() + { + rtl::OUString suStr = rtl::OUString::createFromAscii("\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'", rtl::OUString(pStr).getLength() == 4); + free(pStr); + } + + void trim_WithLength_005() + { + rtl::OUString suStr = rtl::OUString::createFromAscii("\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'", rtl::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() + { + rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("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() + { + rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("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() + { + rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("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() + { + rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("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() + { + rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("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() + { + rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0); + // should not GPF + } + void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::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() + { + rtl::OUString suStr1; + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), 0, NULL); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_WithLength_000_2() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::OString sStr2 = "Line is shorter."; + rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr()); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_WithLength_001() + { + rtl::OUString suStr1; + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_ascii_compare( aStr1.getStr(), NULL); + // should not GPF + } + void ascii_compare_001() + { + rtl::OUString suStr1; + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_001() + { + rtl::OUString suStr1; + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case."); + rtl::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 insensitve).", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_003() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::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() + // { + // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case."); + // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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 ); + // rtl::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() + { + rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); + // should not GPF + } + void ascii_compareIgnoreAsciiCase_001() + { + rtl::OUString suStr1; + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); + rtl::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() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case."); + rtl::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 insensitve).", nValue == 0); + } + + void ascii_compareIgnoreAsciiCase_003() + { + rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); + rtl::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() + // { + // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case."); + // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("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 ); + // rtl::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_NAMED_REGISTRATION(rtl_ustr::compare, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compareIgnoreAsciiCase, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare_WithLength, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr"); +// CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::hashCode, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfChar, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfChar, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfStr, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfStr, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar_WithLength, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase_WithLength, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase_WithLength, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::trim_WithLength, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::valueOfChar, "rtl_ustr"); + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase_WithLength, "rtl_ustr"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr"); + +} // 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. +NOADDITIONAL; + + diff --git a/sal/qa/rtl/oustring/rtl_ustr.xsce b/sal/qa/rtl/oustring/rtl_ustr.xsce new file mode 100644 index 000000000000..0c098eb83571 --- /dev/null +++ b/sal/qa/rtl/oustring/rtl_ustr.xsce @@ -0,0 +1,33 @@ +# 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/makefile.mk b/sal/qa/rtl/oustringbuffer/makefile.mk new file mode 100644 index 000000000000..a910d7222773 --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/makefile.mk @@ -0,0 +1,72 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_oustringbuffer2 + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_OUStringBuffer2.obj + +SHL1TARGET= rtl_OUStringBuffer2 +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:joblist +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx b/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx new file mode 100644 index 000000000000..febaa2a9d552 --- /dev/null +++ b/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx @@ -0,0 +1,104 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OUStringBuffer2.cxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <testshl/simpleheader.hxx> +#include "stringhelper.hxx" +#include <rtl/ustrbuf.hxx> +#include <rtl/uri.hxx> + +namespace rtl_OUStringBuffer +{ + + +class insertUtf32 : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void insertUtf32_001() + { + ::rtl::OUStringBuffer aUStrBuf(4); + aUStrBuf.insertUtf32(0,0x10ffff); + + rtl::OUString suStr = aUStrBuf.makeStringAndClear(); + rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + + rtl::OString sStr; + sStr <<= suStr2; + t_print("%s\n", sStr.getStr()); + + CPPUNIT_ASSERT_MESSAGE("Strings must be '%F4%8F%BF%BF'", sStr.equals(rtl::OString("%F4%8F%BF%BF")) == sal_True); + } + + void insertUtf32_002() + { + ::rtl::OUStringBuffer aUStrBuf(4); + aUStrBuf.insertUtf32(0,0x41); + aUStrBuf.insertUtf32(1,0x42); + aUStrBuf.insertUtf32(2,0x43); + + rtl::OUString suStr = aUStrBuf.makeStringAndClear(); + rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + + rtl::OString sStr; + sStr <<= suStr2; + t_print("%s\n", sStr.getStr()); + + CPPUNIT_ASSERT_MESSAGE("Strings must be 'ABC'", sStr.equals(rtl::OString("ABC")) == sal_True); + } + + CPPUNIT_TEST_SUITE(insertUtf32); + CPPUNIT_TEST(insertUtf32_001); + CPPUNIT_TEST(insertUtf32_002); + CPPUNIT_TEST_SUITE_END(); +}; // class getToken + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUStringBuffer::insertUtf32, "rtl_OUStringBuffer"); + +} // namespace rtl_OUStringBuffer + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/rtl/process/child_process.cxx b/sal/qa/rtl/process/child_process.cxx new file mode 100644 index 000000000000..9fde5e25ab52 --- /dev/null +++ b/sal/qa/rtl/process/child_process.cxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: child_process.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <stdio.h> +#include "sal/main.h" +#include <rtl/process.h> +#include <rtl_Process_Const.h> + +using namespace ::rtl; + +// ----------------------------------- 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) ); + rtl::OString aString; + aString = ::rtl::OUStringToOString( suArg[i], RTL_TEXTENCODING_ASCII_US ); + printf( + "# Parameter[%ld] is %s\n", sal::static_int_cast< long >(i), + aString.getStr()); + } + + if ( suArg[0].compareTo( suParam0) != 0 || + suArg[1].compareTo( suParam1) != 0 || + suArg[2].compareTo( suParam2) != 0 || + suArg[3].compareTo( suParam3) != 0 ) + { + return 0; + } + return 2; +} 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 000000000000..bc321e9d191d --- /dev/null +++ b/sal/qa/rtl/process/child_process_id.cxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: child_process_id.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#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; +} diff --git a/sal/qa/rtl/process/makefile.mk b/sal/qa/rtl/process/makefile.mk new file mode 100644 index 000000000000..ac8d66e24b7d --- /dev/null +++ b/sal/qa/rtl/process/makefile.mk @@ -0,0 +1,95 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.7 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_Process + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_Process.obj + +SHL1TARGET= rtl_Process +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ + +OBJ3FILES=$(OBJ)$/child_process.obj +APP3TARGET=child_process +APP3OBJS=$(OBJ3FILES) + +#.IF "$(GUI)" == "UNX" +#APP3STDLIBS=$(LB)$/libsal.so +#.ENDIF +#.IF "$(GUI)" == "WNT" +#APP3STDLIBS=$(KERNEL32LIB) $(LB)$/isal.lib +#.ENDIF +APP3STDLIBS=$(SALLIB) + +OBJ4FILES=$(OBJ)$/child_process_id.obj +APP4TARGET=child_process_id +APP4OBJS=$(OBJ4FILES) + +# .IF "$(GUI)" == "UNX" +# APP4STDLIBS=$(LB)$/libsal.so +# .ENDIF +# .IF "$(GUI)" == "WNT" +# APP4STDLIBS=$(KERNEL32LIB) $(LB)$/isal.lib +# .ENDIF +APP4STDLIBS=$(SALLIB) + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/process/rtl_Process.cxx b/sal/qa/rtl/process/rtl_Process.cxx new file mode 100644 index 000000000000..e14d52905c32 --- /dev/null +++ b/sal/qa/rtl/process/rtl_Process.cxx @@ -0,0 +1,299 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_Process.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sal/types.h> + +#include <testshl/simpleheader.hxx> +#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; +using namespace rtl; + +/** print a UNI_CODE String. And also print some comments of the string. +*/ +inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = NULL ) +{ + if ( msg != NULL ) + { + t_print("#%s #printUString_u# ", msg ); + } + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", (char *)aString.getStr( ) ); +} + +// ----------------------------------------------------------------------------- +inline ::rtl::OUString getModulePath( void ) +{ + ::rtl::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); + suDirPath += rtl::OUString::createFromAscii("bin"); + return suDirPath; +} + +// ----------------------------------------------------------------------------- + +namespace rtl_Process +{ +class getAppCommandArg : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + void getAppCommandArg_001() + { +#if defined(WNT) || defined(OS2) + const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("child_process.exe"); +#else + const rtl::OUString EXECUTABLE_NAME = rtl::OUString::createFromAscii("child_process"); +#endif + rtl::OUString suCWD = getModulePath(); + // rtl::OUString suCWD2 = getExecutableDirectory(); + + printUString(suCWD, "path to the current module"); + // printUString(suCWD2, "suCWD2"); + + oslProcess hProcess = NULL; + + const int nParameterCount = 4; + rtl_uString* pParameters[ nParameterCount ]; + + pParameters[0] = suParam0.pData; + pParameters[1] = suParam1.pData; + pParameters[2] = suParam2.pData; + pParameters[3] = suParam3.pData; + + rtl::OUString suFileURL = suCWD; + suFileURL += rtl::OUString::createFromAscii("/"); + suFileURL += EXECUTABLE_NAME; + + oslProcessError osl_error = osl_executeProcess( + suFileURL.pData, + pParameters, + nParameterCount, + osl_Process_WAIT, + 0, /* osl_getCurrentSecurity() */ + suCWD.pData, + NULL, + 0, + &hProcess ); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + //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 + // ); + oslProcessInfo* pInfo = new oslProcessInfo; + //please pay attention to initial the Size to sizeof(oslProcessInfo), or else + //you will get unknow error when call osl_getProcessInfo + pInfo->Size = sizeof(oslProcessInfo); + osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo ); + CPPUNIT_ASSERT_MESSAGE + ( + "osl_getProcessInfo returned with failure", + osl_Process_E_None == osl_error + ); + + t_print("the exit code is %d.\n", pInfo->Code ); + CPPUNIT_ASSERT_MESSAGE("rtl_getAppCommandArg or rtl_getAppCommandArgCount error.", pInfo->Code == 2); + delete pInfo; + } + + + 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 ) + ************************************************************************/ +void printUuid( 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 + **************************************************************************/ +void printUuidtoBuffer( sal_uInt8 *pNode, sal_Char * pBuffer ) +{ + sal_Int8 nPtr = 0; + for( sal_Int32 i1 = 0 ; i1 < 16 ; i1++ ) + { + sal_uInt8 nValue = pNode[i1]; + if (nValue < 16) + { + sprintf( (sal_Char *)(pBuffer + nPtr), "0"); + nPtr++; + } + sprintf( (sal_Char *)(pBuffer + nPtr), "%02x", nValue ); + nPtr += 2 ; + } +} + +class getGlobalProcessId : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + //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(WNT) || defined(OS2) + const rtl::OUString EXEC_NAME = rtl::OUString::createFromAscii("child_process_id.exe"); +#else + const rtl::OUString EXEC_NAME = rtl::OUString::createFromAscii("child_process_id"); +#endif + sal_uInt8 pTargetUUID1[16]; + rtl_getGlobalProcessId( pTargetUUID1 ); + printUuid( pTargetUUID1 ); + sal_Char pUUID1[32]; + printUuidtoBuffer( pTargetUUID1, pUUID1 ); + printf("# UUID to String is %s\n", pUUID1); + + rtl::OUString suCWD = getModulePath(); + oslProcess hProcess = NULL; + rtl::OUString suFileURL = suCWD; + suFileURL += rtl::OUString::createFromAscii("/"); + suFileURL += EXEC_NAME; + oslFileHandle* pChildOutputRead = new oslFileHandle(); + oslProcessError osl_error = osl_executeProcess_WithRedirectedIO( + suFileURL.pData, + NULL, + 0, + osl_Process_WAIT, + 0, + suCWD.pData, + NULL, + 0, + &hProcess, + NULL, + pChildOutputRead, + NULL); + + CPPUNIT_ASSERT_MESSAGE + ( + "osl_createProcess failed", + osl_error == osl_Process_E_None + ); + //we could get return value only after the process terminated + osl_joinProcess(hProcess); + + sal_Char pUUID2[33]; + pUUID2[32] = '\0'; + sal_uInt64 nRead = 0; + osl_readFile( *pChildOutputRead, pUUID2, 32, &nRead ); + t_print("read buffer is %s, nRead is %d \n", pUUID2, nRead ); + OUString suUUID2 = OUString::createFromAscii( pUUID2 ); + CPPUNIT_ASSERT_MESSAGE("getGlobalProcessId: got two same ProcessIds.", suUUID2.equalsAsciiL( pUUID1, 32) == sal_False ); + } + + 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"); + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; 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 000000000000..a66d244a0cfe --- /dev/null +++ b/sal/qa/rtl/process/rtl_Process_Const.h @@ -0,0 +1,26 @@ + +#ifndef _RTL_PROCESS_CONST_H_ +#define _RTL_PROCESS_CONST_H_ + +//------------------------------------------------------------------------ +#include <rtl/ustring.hxx> + +using namespace ::rtl; + +#ifdef __cplusplus +extern "C" +{ +#endif +//------------------------------------------------------------------------ +//::rtl::OUString suParam[4]; +::rtl::OUString suParam0 = ::rtl::OUString::createFromAscii("-join"); +::rtl::OUString suParam1 = OUString::createFromAscii("-with"); +::rtl::OUString suParam2 = OUString::createFromAscii("-child"); +::rtl::OUString suParam3 = OUString::createFromAscii("-process"); + +//------------------------------------------------------------------------ +#ifdef __cplusplus +} +#endif + +#endif /* RTL_PROCESS_CONST_H*/ diff --git a/sal/qa/rtl/random/makefile.add b/sal/qa/rtl/random/makefile.add new file mode 100644 index 000000000000..eb45c312ed40 --- /dev/null +++ b/sal/qa/rtl/random/makefile.add @@ -0,0 +1,19 @@ +# BEGIN ---------------------------------------------------------------- +# auto generated Target:job by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_random.obj + +SHL1TARGET= job +SHL1STDLIBS=\ + $(SALLIB) \ + $(CPPUNITLIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= export.map +# auto generated Target:job +# END ------------------------------------------------------------------ + diff --git a/sal/qa/rtl/random/makefile.mk b/sal/qa/rtl/random/makefile.mk new file mode 100644 index 000000000000..0fc2e5e5a7f8 --- /dev/null +++ b/sal/qa/rtl/random/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_random +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:job by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_random.obj + +SHL1TARGET= rtl_Random +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:job +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/rtl/random/random.txt b/sal/qa/rtl/random/random.txt new file mode 100644 index 000000000000..d7eb1f1b2311 --- /dev/null +++ b/sal/qa/rtl/random/random.txt @@ -0,0 +1,5 @@ +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 000000000000..ae3845bd16b9 --- /dev/null +++ b/sal/qa/rtl/random/rtl_random.cxx @@ -0,0 +1,415 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_random.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl + +#include <algorithm> // STL + +#include <testshl/simpleheader.hxx> +#include <rtl/random.h> + +namespace rtl_random +{ + +class createPool : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // 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 an other test is not possible for createPool() + CPPUNIT_ASSERT_MESSAGE("create failed", aPool != NULL); + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void destroyPool_000() + { + // GPF, if failed + rtl_random_destroyPool(NULL); + } + + void destroyPool_001() + { + rtlRandomPool aPool = rtl_random_createPool(); + + // LLA: seems to be that an other test is not possible for createPool() + CPPUNIT_ASSERT_MESSAGE("create failed", aPool != NULL); + + 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: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + // this is only demonstration code + void addBytes_000() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + memset(pBuffer, 0, nBufLen); + + rtlRandomError aError = rtl_random_addBytes(NULL, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_Argument); + + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_Argument); + + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer, nBufLen); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); + + rtl_random_destroyPool(aPool); + delete [] pBuffer; + + } + + void addBytes_001() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + + memset(pBuffer, 0, nBufLen); + + rtl_random_addBytes(aPool, pBuffer, nBufLen); + + t_print("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); + + rtl_random_destroyPool(aPool); + delete [] pBuffer; + } + + + // 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 + + +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() + { + clearDispensation(); + } + ~Statistics(){} + + void addValue(sal_Int16 _nIndex, sal_Int32 _nValue) + { + OSL_ASSERT(_nIndex >= 0 && _nIndex < 256); + 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 + t_print("\nSome statistics\n"); + t_print("Min: %d\n", m_nMin); + t_print("Max: %d\n", m_nMax); + t_print("Average: %d\n", m_nAverage); + t_print("Min abs deviation: %d\n", m_nMinDeviation); + t_print("Max abs deviation: %d\n", m_nMaxDeviation); + } + + sal_Int32 getAverage() {return m_nAverage;} + sal_Int32 getMaxDeviation() {return m_nMaxDeviation;} + +}; + +class getBytes : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // insert your test code here. + void getBytes_000() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + memset(pBuffer, 0, nBufLen); + + rtlRandomError aError = rtl_random_getBytes(NULL, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_Argument); + + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, NULL, 0); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_Argument); + + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); + + rtl_random_destroyPool(aPool); + delete [] pBuffer; + } + + void getBytes_001() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + memset(pBuffer, 0, nBufLen); + + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); + + t_print("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); + + rtl_random_destroyPool(aPool); + delete [] pBuffer; + } + + void getBytes_002() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 4; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen << 1 ]; + memset(pBuffer, 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, nBufLen); + CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); + + t_print("%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); + delete [] pBuffer; + } + + void getBytes_003() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 1; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + memset(pBuffer, 0, nBufLen); + + Statistics aStat; + + CPPUNIT_ASSERT_MESSAGE("memset failed", pBuffer[0] == 0); + + int nCount = 0; + + int nCountMax = 1000000; + for(nCount = 0;nCount < nCountMax; nCount ++) // run 100000000 through getBytes(...) + { + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, 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); + delete [] pBuffer; + } + + void getBytes_003_1() + { + rtlRandomPool aPool = rtl_random_createPool(); + + sal_uInt32 nBufLen = 256; + sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + memset(pBuffer, 0, nBufLen); + + Statistics aStat; + + CPPUNIT_ASSERT_MESSAGE("memset failed", pBuffer[0] == 0); + + int nCount = 0; + + int nCountMax = 10000; + for(nCount = 0;nCount < nCountMax; nCount ++) // run 100000000 through getBytes(...) + { + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, 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); + delete [] pBuffer; + } + + // 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_NAMED_REGISTRATION(rtl_random::createPool, "rtl_random"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::destroyPool, "rtl_random"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::addBytes, "rtl_random"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::getBytes, "rtl_random"); +} // namespace rtl_random + + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/rtl/strings/makefile.mk b/sal/qa/rtl/strings/makefile.mk new file mode 100644 index 000000000000..8b2a62b82d13 --- /dev/null +++ b/sal/qa/rtl/strings/makefile.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.9 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/..$/.. +PRJNAME := sal + +TARGET := qa_rtl_strings + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +SHL1TARGET := $(TARGET) +SHL1OBJS := \ + $(SLO)$/test_oustringbuffer_utf32.obj \ + $(SLO)$/test_oustring_compare.obj \ + $(SLO)$/test_oustring_convert.obj \ + $(SLO)$/test_oustring_endswith.obj \ + $(SLO)$/test_oustring_noadditional.obj +SHL1IMPLIB := i$(SHL1TARGET) +SHL1STDLIBS := $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +SHL1VERSIONMAP := $(PRJ)$/qa$/export.map +DEF1NAME := $(SHL1TARGET) + +.INCLUDE: target.mk +.INCLUDE : _cppunit.mk 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 000000000000..582dd6a21b7a --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_compare.cxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_oustring_compare.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "testshl/simpleheader.hxx" +#include "rtl/string.h" +#include "rtl/ustring.hxx" + +namespace test { namespace oustring { + +class Compare: public CppUnit::TestFixture +{ +private: + void equalsIgnoreAsciiCaseAscii(); + + CPPUNIT_TEST_SUITE(Compare); + CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii); + CPPUNIT_TEST_SUITE_END(); +}; + +} } + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test::oustring::Compare, "alltest"); + +void test::oustring::Compare::equalsIgnoreAsciiCaseAscii() +{ + CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAscii("abc")); + CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAsciiL( + RTL_CONSTASCII_STRINGPARAM("abc"))); + CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")). + equalsIgnoreAsciiCaseAscii("")); + CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")). + equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(""))); + + CPPUNIT_ASSERT(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")). + equalsIgnoreAsciiCaseAscii("abc")); + CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abcd")). + equalsIgnoreAsciiCaseAscii("abc")); + CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")). + equalsIgnoreAsciiCaseAscii("abcd")); +} 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 000000000000..e1219c3024d6 --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_convert.cxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_oustring_convert.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "testshl/simpleheader.hxx" +#include "rtl/strbuf.hxx" +#include "rtl/string.hxx" +#include "rtl/ustring.hxx" + +namespace test { namespace oustring { + +class Convert: public CppUnit::TestFixture +{ +private: + void convertToString(); + + CPPUNIT_TEST_SUITE(Convert); + CPPUNIT_TEST(convertToString); + CPPUNIT_TEST_SUITE_END(); +}; + +} } + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test::oustring::Convert, "alltest"); + +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 rtl::OUString aSource(rTest.aSource, rTest.nLength); + rtl::OString aStrict(RTL_CONSTASCII_STRINGPARAM("12345")); + bool bSuccess = aSource.convertToString(&aStrict, rTest.nEncoding, + rTest.nFlags); + rtl::OString aRelaxed(rtl::OUStringToOString(aSource, rTest.nEncoding, + rTest.nFlags)); + + rtl::OStringBuffer aPrefix; + aPrefix.append(RTL_CONSTASCII_STRINGPARAM("{")); + for (sal_Int32 i = 0; i < rTest.nLength; ++i) + { + aPrefix.append(RTL_CONSTASCII_STRINGPARAM("U+")); + aPrefix.append(static_cast< sal_Int32 >(rTest.aSource[i]), 16); + if (i + 1 < rTest.nLength) + aPrefix.append(RTL_CONSTASCII_STRINGPARAM(",")); + } + aPrefix.append(RTL_CONSTASCII_STRINGPARAM("}, ")); + aPrefix.append(static_cast< sal_Int32 >(rTest.nEncoding)); + aPrefix.append(RTL_CONSTASCII_STRINGPARAM(", 0x")); + aPrefix.append(static_cast< sal_Int32 >(rTest.nFlags), 16); + aPrefix.append(RTL_CONSTASCII_STRINGPARAM(" -> ")); + + if (bSuccess) + { + if (rTest.pStrict == 0 || !aStrict.equals(rTest.pStrict)) + { + rtl::OStringBuffer aMessage(aPrefix); + aMessage.append(RTL_CONSTASCII_STRINGPARAM("strict = \"")); + aMessage.append(aStrict); + aMessage.append(RTL_CONSTASCII_STRINGPARAM("\"")); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } + } + else + { + if (!aStrict.equals(rtl::OString(RTL_CONSTASCII_STRINGPARAM("12345")))) + { + rtl::OStringBuffer aMessage(aPrefix); + aMessage.append(RTL_CONSTASCII_STRINGPARAM("modified output")); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } + if (rTest.pStrict != 0) + { + rtl::OStringBuffer aMessage(aPrefix); + aMessage.append(RTL_CONSTASCII_STRINGPARAM("failed")); + CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), false); + } + } + if (!aRelaxed.equals(rTest.pRelaxed)) + { + rtl::OStringBuffer aMessage(aPrefix); + aMessage.append(RTL_CONSTASCII_STRINGPARAM("relaxed = \"")); + aMessage.append(aRelaxed); + aMessage.append(RTL_CONSTASCII_STRINGPARAM("\"")); + 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, + 0, + "" }, + // the next also tests that a short source produces a long target: + { { 0xB800 }, + 1, + RTL_TEXTENCODING_ISO_2022_JP, + OUSTRING_TO_OSTRING_CVTFLAGS, + "\x1B(B?", + "\x1B(B?" }, + { { 0x0041,0x0100,0x0042 }, + 3, + RTL_TEXTENCODING_ISO_8859_1, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR, + 0, + "A" }, + { { 0x0041,0x0100,0x0042 }, + 3, + RTL_TEXTENCODING_ISO_8859_1, + OUSTRING_TO_OSTRING_CVTFLAGS, + "A?B", + "A?B" } }; + for (unsigned int i = 0; i < sizeof aTests / sizeof aTests[0]; ++i) + testConvertToString(aTests[i]); +} 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 000000000000..467878697fd2 --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_endswith.cxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_oustring_endswith.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "testshl/simpleheader.hxx" +#include "rtl/strbuf.hxx" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "rtl/textenc.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +namespace test { namespace oustring { + +class EndsWith: public CppUnit::TestFixture +{ +private: + void endsWith(); + + CPPUNIT_TEST_SUITE(EndsWith); + CPPUNIT_TEST(endsWith); + CPPUNIT_TEST_SUITE_END(); +}; + +} } + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test::oustring::EndsWith, "alltest"); + +namespace { + +void appendString(rtl::OStringBuffer & buffer, rtl::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 (int i = 0; i < sizeof data / sizeof data[0]; ++i) { + rtl::OStringBuffer msg; + appendString(msg, rtl::OString(data[i].str1, data[i].str1Len)); + msg.append( + RTL_CONSTASCII_STRINGPARAM(".endsWithIgnoreAsciiCaseAsciiL(")); + appendString(msg, rtl::OString(data[i].str2, data[i].str2Len)); + msg.append(RTL_CONSTASCII_STRINGPARAM(") == ")); + msg.append(static_cast< sal_Bool >(data[i].endsWith)); + CPPUNIT_ASSERT_MESSAGE( + msg.getStr(), + rtl::OUString( + data[i].str1, data[i].str1Len, + RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL( + data[i].str2, data[i].str2Len) + == data[i].endsWith); + } +} diff --git a/sal/qa/rtl/strings/test_oustring_noadditional.cxx b/sal/qa/rtl/strings/test_oustring_noadditional.cxx new file mode 100644 index 000000000000..dd30871b7622 --- /dev/null +++ b/sal/qa/rtl/strings/test_oustring_noadditional.cxx @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_oustring_noadditional.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "testshl/simpleheader.hxx" + +NOADDITIONAL; diff --git a/sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx b/sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx new file mode 100644 index 000000000000..71fb6def0b31 --- /dev/null +++ b/sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_oustringbuffer_utf32.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "testshl/simpleheader.hxx" +#include "rtl/ustrbuf.hxx" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" + +namespace test { namespace 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_NAMED_REGISTRATION(test::oustringbuffer::Utf32, "alltest"); + +namespace { + +void appendString(rtl::OUStringBuffer & buffer, rtl::OUString const & string) { + buffer.append(static_cast< sal_Unicode >('"')); + for (int i = 0; i < string.getLength(); ++i) { + buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("\\u")); + sal_Unicode c = string[i]; + if (c < 0x1000) { + buffer.append(static_cast< sal_Unicode >('0')); + if (c < 0x100) { + buffer.append(static_cast< sal_Unicode >('0')); + if (c < 0x10) { + buffer.append(static_cast< sal_Unicode >('0')); + } + } + } + buffer.append( + static_cast< sal_Int32 >(c), static_cast< sal_Int16 >(16)); + } + buffer.append(static_cast< sal_Unicode >('"')); +} + +void createMessage( + rtl::OUStringBuffer & message, rtl::OUString const & string1, + rtl::OUString const & string2) +{ + message.setLength(0); + appendString(message, string1); + message.appendAscii(RTL_CONSTASCII_STRINGPARAM(" 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 }; + rtl::OUStringBuffer message; + rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len)); + buf1.appendUtf32('d'); + rtl::OUString res1(buf1.makeStringAndClear()); + createMessage(message, res1, rtl::OUString(str2, str2Len)); + CPPUNIT_ASSERT_MESSAGE( + message.getStr(), res1 == rtl::OUString(str2, str2Len)); + rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len)); + buf2.appendUtf32(0x10000); + rtl::OUString res2(buf2.makeStringAndClear()); + createMessage(message, res2, rtl::OUString(str3, str3Len)); + CPPUNIT_ASSERT_MESSAGE( + message.getStr(), res2 == rtl::OUString(str3, str3Len)); +} + +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' }; + rtl::OUStringBuffer message; + rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len)); + buf1.insertUtf32(2, 'd'); + rtl::OUString res1(buf1.makeStringAndClear()); + createMessage(message, res1, rtl::OUString(str2, str2Len)); + CPPUNIT_ASSERT_MESSAGE( + message.getStr(), res1 == rtl::OUString(str2, str2Len)); + rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len)); + buf2.insertUtf32(2, 0x10FFFF); + rtl::OUString res2(buf2.makeStringAndClear()); + createMessage(message, res2, rtl::OUString(str3, str3Len)); + CPPUNIT_ASSERT_MESSAGE( + message.getStr(), res2 == rtl::OUString(str3, str3Len)); +} diff --git a/sal/qa/rtl/textenc/gcc3_export.map b/sal/qa/rtl/textenc/gcc3_export.map new file mode 100644 index 000000000000..9d838c3df0e1 --- /dev/null +++ b/sal/qa/rtl/textenc/gcc3_export.map @@ -0,0 +1,40 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: gcc3_export.map,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3_0_0 { + global: + registerAllTestFunction; + + _ZN4_STL7num_put*; # STLport + + local: + *; +}; diff --git a/sal/qa/rtl/textenc/makefile.mk b/sal/qa/rtl/textenc/makefile.mk new file mode 100644 index 000000000000..31f700b7b96a --- /dev/null +++ b/sal/qa/rtl/textenc/makefile.mk @@ -0,0 +1,85 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.8 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_textenc + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# --- BEGIN -------------------------------------------------------- +SHL1OBJS= \ + $(SLO)$/rtl_textcvt.obj +SHL1TARGET= rtl_textcvt +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +.IF "$(COMNAME)" == "gcc3" +SHL1VERSIONMAP = gcc3_export.map +.ELSE +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +.ENDIF + +# END -------------------------------------------------------------- + +# --- BEGIN -------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/rtl_tencinfo.obj +SHL2TARGET= rtl_tencinfo +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +DEF2NAME =$(SHL2TARGET) +.IF "$(COMNAME)" == "gcc3" +SHL2VERSIONMAP = gcc3_export.map +.ELSE +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map +.ENDIF + +# END -------------------------------------------------------------- + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/rtl/textenc/rtl_tencinfo.cxx b/sal/qa/rtl/textenc/rtl_tencinfo.cxx new file mode 100644 index 000000000000..2bc3f930af42 --- /dev/null +++ b/sal/qa/rtl/textenc/rtl_tencinfo.cxx @@ -0,0 +1,1904 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_tencinfo.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <string.h> + +#include <osl/thread.h> +#include <rtl/tencinfo.h> + +#include <testshl/simpleheader.hxx> + +// ----------------------------------------------------------------------------- + +namespace rtl_tencinfo +{ + class getBestMime : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void check( const sal_Char* _pRTL_TEXTENCODING, rtl_TextEncoding _aCurrentEncode ) + { + const sal_Char *pCharSet = rtl_getBestMimeCharsetFromTextEncoding( _aCurrentEncode ); + if (pCharSet == 0) + { + t_print("rtl_getBestMimeCharsetFromTextEncoding(%s) (%d) doesn't seem to exist.\n\n", _pRTL_TEXTENCODING, _aCurrentEncode); + } + else + { + t_print(T_VERBOSE, "'%s' is charset: '%s'\n", _pRTL_TEXTENCODING, pCharSet); + + rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromMimeCharset( pCharSet ); + if (_aCurrentEncode != eTextEnc && + eTextEnc != RTL_TEXTENCODING_DONTKNOW) + { + t_print("rtl_getBestMimeCharsetFromTextEncoding(%s) is charset: %s\n", _pRTL_TEXTENCODING, pCharSet); + t_print("rtl_getTextEncodingFromMimeCharset() differ: %s %d -> %d\n\n", _pRTL_TEXTENCODING, _aCurrentEncode, eTextEnc ); + } + // rtl::OString sError = "getTextEncodingFromMimeCharset("; + // sError += pCharSet; + // sError += ") returns null"; + // CPPUNIT_ASSERT_MESSAGE(sError.getStr(), eTextEnc != RTL_TEXTENCODING_DONTKNOW); + // CPPUNIT_ASSERT_MESSAGE("Does not realize itself", _aCurrentEncode == 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_SYMBOL ); + } + // ---------------------------------------- + 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_IBM_737 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_IBM_775() + { + check( "RTL_TEXTENCODING_IBM_775", RTL_TEXTENCODING_IBM_775 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_IBM_852() + { + check( "RTL_TEXTENCODING_IBM_852", RTL_TEXTENCODING_IBM_852 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_IBM_855() + { + check( "RTL_TEXTENCODING_IBM_855", RTL_TEXTENCODING_IBM_855 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_IBM_857() + { + check( "RTL_TEXTENCODING_IBM_857", RTL_TEXTENCODING_IBM_857 ); + } + // ---------------------------------------- + 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_IBM_869 ); + } + // ---------------------------------------- + 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_ARABIC() + { + check( "RTL_TEXTENCODING_APPLE_ARABIC", RTL_TEXTENCODING_APPLE_ARABIC ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_CENTEURO() + { + check( "RTL_TEXTENCODING_APPLE_CENTEURO", RTL_TEXTENCODING_APPLE_CENTEURO ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_CROATIAN() + { + check( "RTL_TEXTENCODING_APPLE_CROATIAN", RTL_TEXTENCODING_APPLE_CROATIAN ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_CYRILLIC() + { + check( "RTL_TEXTENCODING_APPLE_CYRILLIC", RTL_TEXTENCODING_APPLE_CYRILLIC ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_DEVANAGARI() + { + check( "RTL_TEXTENCODING_APPLE_DEVANAGARI", RTL_TEXTENCODING_APPLE_DEVANAGARI ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_FARSI() + { + check( "RTL_TEXTENCODING_APPLE_FARSI", RTL_TEXTENCODING_APPLE_FARSI ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_GREEK() + { + check( "RTL_TEXTENCODING_APPLE_GREEK", RTL_TEXTENCODING_APPLE_GREEK ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_GUJARATI() + { + check( "RTL_TEXTENCODING_APPLE_GUJARATI", RTL_TEXTENCODING_APPLE_GUJARATI ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_GURMUKHI() + { + check( "RTL_TEXTENCODING_APPLE_GURMUKHI", RTL_TEXTENCODING_APPLE_GURMUKHI ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_HEBREW() + { + check( "RTL_TEXTENCODING_APPLE_HEBREW", RTL_TEXTENCODING_APPLE_HEBREW ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_ICELAND() + { + check( "RTL_TEXTENCODING_APPLE_ICELAND", RTL_TEXTENCODING_APPLE_ICELAND ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_ROMANIAN() + { + check( "RTL_TEXTENCODING_APPLE_ROMANIAN", RTL_TEXTENCODING_APPLE_ROMANIAN ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_THAI() + { + check( "RTL_TEXTENCODING_APPLE_THAI", RTL_TEXTENCODING_APPLE_THAI ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_TURKISH() + { + check( "RTL_TEXTENCODING_APPLE_TURKISH", RTL_TEXTENCODING_APPLE_TURKISH ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_UKRAINIAN() + { + check( "RTL_TEXTENCODING_APPLE_UKRAINIAN", RTL_TEXTENCODING_APPLE_UKRAINIAN ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_CHINSIMP() + { + check( "RTL_TEXTENCODING_APPLE_CHINSIMP", RTL_TEXTENCODING_APPLE_CHINSIMP ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_CHINTRAD() + { + check( "RTL_TEXTENCODING_APPLE_CHINTRAD", RTL_TEXTENCODING_APPLE_CHINTRAD ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_JAPANESE() + { + check( "RTL_TEXTENCODING_APPLE_JAPANESE", RTL_TEXTENCODING_APPLE_JAPANESE ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_APPLE_KOREAN() + { + check( "RTL_TEXTENCODING_APPLE_KOREAN", RTL_TEXTENCODING_APPLE_KOREAN ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_MS_932() + { + check( "RTL_TEXTENCODING_MS_932", RTL_TEXTENCODING_MS_932 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_MS_936() + { + check( "RTL_TEXTENCODING_MS_936", RTL_TEXTENCODING_MS_936 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_MS_949() + { + check( "RTL_TEXTENCODING_MS_949", RTL_TEXTENCODING_MS_949 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_MS_950() + { + check( "RTL_TEXTENCODING_MS_950", RTL_TEXTENCODING_MS_950 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_SHIFT_JIS() + { + check( "RTL_TEXTENCODING_SHIFT_JIS", RTL_TEXTENCODING_SHIFT_JIS ); + } + // ---------------------------------------- + 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_JP() + { + check( "RTL_TEXTENCODING_EUC_JP", RTL_TEXTENCODING_EUC_JP ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_EUC_CN() + { + check( "RTL_TEXTENCODING_EUC_CN", RTL_TEXTENCODING_EUC_CN ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_EUC_TW() + { + check( "RTL_TEXTENCODING_EUC_TW", RTL_TEXTENCODING_EUC_TW ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_ISO_2022_JP() + { + check( "RTL_TEXTENCODING_ISO_2022_JP", RTL_TEXTENCODING_ISO_2022_JP ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_ISO_2022_CN() + { + check( "RTL_TEXTENCODING_ISO_2022_CN", RTL_TEXTENCODING_ISO_2022_CN ); + } + // ---------------------------------------- + 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_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 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_JIS_X_0201() + { + check( "RTL_TEXTENCODING_JIS_X_0201", RTL_TEXTENCODING_JIS_X_0201 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_JIS_X_0208() + { + check( "RTL_TEXTENCODING_JIS_X_0208", RTL_TEXTENCODING_JIS_X_0208 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_JIS_X_0212() + { + check( "RTL_TEXTENCODING_JIS_X_0212", RTL_TEXTENCODING_JIS_X_0212 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_MS_1361() + { + check( "RTL_TEXTENCODING_MS_1361", RTL_TEXTENCODING_MS_1361 ); + } + // ---------------------------------------- + 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 ); + } + // ---------------------------------------- + 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 ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_ISCII_DEVANAGARI() + { + check( "RTL_TEXTENCODING_ISCII_DEVANAGARI", RTL_TEXTENCODING_ISCII_DEVANAGARI ); + } + // ---------------------------------------- + void MimeCharsetFromTextEncoding_JAVA_UTF8() + { + check( "RTL_TEXTENCODING_JAVA_UTF8", RTL_TEXTENCODING_JAVA_UTF8 ); + } + +/* ATTENTION! Whenever some encoding is added here, make sure to update + * rtl_isOctetEncoding in tencinfo.c. + */ + +// RTL_TEXTENCODING_USER_START +// RTL_TEXTENCODING_USER_END + +// check( "RTL_TEXTENCODING_UCS4", RTL_TEXTENCODING_UCS4 ); +// check( "RTL_TEXTENCODING_UCS2", RTL_TEXTENCODING_UCS2 ); +// check( "RTL_TEXTENCODING_UNICODE", RTL_TEXTENCODING_UNICODE /* RTL_TEXTENCODING_UCS2 */ ); + + CPPUNIT_TEST_SUITE( getBestMime ); + + 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_ARABIC ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CENTEURO ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CROATIAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CYRILLIC ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_DEVANAGARI ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_FARSI ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_GREEK ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_GUJARATI ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_GURMUKHI ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_HEBREW ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_ICELAND ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_ROMANIAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_THAI ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_TURKISH ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_UKRAINIAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CHINSIMP ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_CHINTRAD ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_JAPANESE ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_APPLE_KOREAN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_932 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_936 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_949 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_950 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_SHIFT_JIS ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GB_2312 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GBT_12345 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GBK ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_BIG5 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_JP ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_CN ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_EUC_TW ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_2022_JP ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_2022_CN ); + 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_EUC_KR ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISO_2022_KR ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JIS_X_0201 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JIS_X_0208 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JIS_X_0212 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_MS_1361 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_GB_18030 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_BIG5_HKSCS ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_TIS_620 ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_KOI8_U ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_ISCII_DEVANAGARI ); + CPPUNIT_TEST( MimeCharsetFromTextEncoding_JAVA_UTF8 ); + + CPPUNIT_TEST_SUITE_END( ); + }; + + // ----------------------------------------------------------------------------- + + class getBestUnix : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void check( const sal_Char* _pRTL_TEXTENCODING, rtl_TextEncoding _aCurrentEncode ) + { + const sal_Char *pCharSet = rtl_getBestUnixCharsetFromTextEncoding( _aCurrentEncode ); + if (pCharSet == 0) + { + t_print("rtl_getBestUnixCharsetFromTextEncoding(%s) (%d) doesn't seem to exist.\n\n", _pRTL_TEXTENCODING, _aCurrentEncode); + } + else + { + t_print(T_VERBOSE, "'%s' is charset: '%s'\n", _pRTL_TEXTENCODING, pCharSet); + + rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromUnixCharset( pCharSet ); + if (_aCurrentEncode != eTextEnc && + eTextEnc != RTL_TEXTENCODING_DONTKNOW) + { + t_print("rtl_getBestUnixCharsetFromTextEncoding(%s) is charset: %s\n", _pRTL_TEXTENCODING, pCharSet); + t_print("rtl_getTextEncodingFromUnixCharset() differ: %s %d -> %d\n\n", _pRTL_TEXTENCODING, _aCurrentEncode, eTextEnc ); + } + // rtl::OString sError = "getTextEncodingFromUnixCharset("; + // sError += pCharSet; + // sError += ") returns null"; + // CPPUNIT_ASSERT_MESSAGE(sError.getStr(), eTextEnc != RTL_TEXTENCODING_DONTKNOW); + // CPPUNIT_ASSERT_MESSAGE("Does not realize itself", _aCurrentEncode == eTextEnc ); + } + } + + + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1252() + { + check( "RTL_TEXTENCODING_MS_1252", RTL_TEXTENCODING_MS_1252 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_ROMAN() + { + check( "RTL_TEXTENCODING_APPLE_ROMAN", RTL_TEXTENCODING_APPLE_ROMAN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_437() + { + check( "RTL_TEXTENCODING_IBM_437", RTL_TEXTENCODING_IBM_437 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_850() + { + check( "RTL_TEXTENCODING_IBM_850", RTL_TEXTENCODING_IBM_850 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_860() + { + check( "RTL_TEXTENCODING_IBM_860", RTL_TEXTENCODING_IBM_860 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_861() + { + check( "RTL_TEXTENCODING_IBM_861", RTL_TEXTENCODING_IBM_861 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_863() + { + check( "RTL_TEXTENCODING_IBM_863", RTL_TEXTENCODING_IBM_863 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_865() + { + check( "RTL_TEXTENCODING_IBM_865", RTL_TEXTENCODING_IBM_865 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_SYMBOL() + { + check( "RTL_TEXTENCODING_SYMBOL", RTL_TEXTENCODING_SYMBOL ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_ASCII_US() + { + check( "RTL_TEXTENCODING_ASCII_US", RTL_TEXTENCODING_ASCII_US ); + } + // ---------------------------------------- + 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_IBM_737 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_775() + { + check( "RTL_TEXTENCODING_IBM_775", RTL_TEXTENCODING_IBM_775 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_852() + { + check( "RTL_TEXTENCODING_IBM_852", RTL_TEXTENCODING_IBM_852 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_855() + { + check( "RTL_TEXTENCODING_IBM_855", RTL_TEXTENCODING_IBM_855 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_857() + { + check( "RTL_TEXTENCODING_IBM_857", RTL_TEXTENCODING_IBM_857 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_862() + { + check( "RTL_TEXTENCODING_IBM_862", RTL_TEXTENCODING_IBM_862 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_864() + { + check( "RTL_TEXTENCODING_IBM_864", RTL_TEXTENCODING_IBM_864 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_866() + { + check( "RTL_TEXTENCODING_IBM_866", RTL_TEXTENCODING_IBM_866 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_IBM_869() + { + check( "RTL_TEXTENCODING_IBM_869", RTL_TEXTENCODING_IBM_869 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_874() + { + check( "RTL_TEXTENCODING_MS_874", RTL_TEXTENCODING_MS_874 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1250() + { + check( "RTL_TEXTENCODING_MS_1250", RTL_TEXTENCODING_MS_1250 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1251() + { + check( "RTL_TEXTENCODING_MS_1251", RTL_TEXTENCODING_MS_1251 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1253() + { + check( "RTL_TEXTENCODING_MS_1253", RTL_TEXTENCODING_MS_1253 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1254() + { + check( "RTL_TEXTENCODING_MS_1254", RTL_TEXTENCODING_MS_1254 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1255() + { + check( "RTL_TEXTENCODING_MS_1255", RTL_TEXTENCODING_MS_1255 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1256() + { + check( "RTL_TEXTENCODING_MS_1256", RTL_TEXTENCODING_MS_1256 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1257() + { + check( "RTL_TEXTENCODING_MS_1257", RTL_TEXTENCODING_MS_1257 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1258() + { + check( "RTL_TEXTENCODING_MS_1258", RTL_TEXTENCODING_MS_1258 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_ARABIC() + { + check( "RTL_TEXTENCODING_APPLE_ARABIC", RTL_TEXTENCODING_APPLE_ARABIC ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_CENTEURO() + { + check( "RTL_TEXTENCODING_APPLE_CENTEURO", RTL_TEXTENCODING_APPLE_CENTEURO ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_CROATIAN() + { + check( "RTL_TEXTENCODING_APPLE_CROATIAN", RTL_TEXTENCODING_APPLE_CROATIAN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_CYRILLIC() + { + check( "RTL_TEXTENCODING_APPLE_CYRILLIC", RTL_TEXTENCODING_APPLE_CYRILLIC ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_DEVANAGARI() + { + check( "RTL_TEXTENCODING_APPLE_DEVANAGARI", RTL_TEXTENCODING_APPLE_DEVANAGARI ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_FARSI() + { + check( "RTL_TEXTENCODING_APPLE_FARSI", RTL_TEXTENCODING_APPLE_FARSI ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_GREEK() + { + check( "RTL_TEXTENCODING_APPLE_GREEK", RTL_TEXTENCODING_APPLE_GREEK ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_GUJARATI() + { + check( "RTL_TEXTENCODING_APPLE_GUJARATI", RTL_TEXTENCODING_APPLE_GUJARATI ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_GURMUKHI() + { + check( "RTL_TEXTENCODING_APPLE_GURMUKHI", RTL_TEXTENCODING_APPLE_GURMUKHI ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_HEBREW() + { + check( "RTL_TEXTENCODING_APPLE_HEBREW", RTL_TEXTENCODING_APPLE_HEBREW ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_ICELAND() + { + check( "RTL_TEXTENCODING_APPLE_ICELAND", RTL_TEXTENCODING_APPLE_ICELAND ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_ROMANIAN() + { + check( "RTL_TEXTENCODING_APPLE_ROMANIAN", RTL_TEXTENCODING_APPLE_ROMANIAN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_THAI() + { + check( "RTL_TEXTENCODING_APPLE_THAI", RTL_TEXTENCODING_APPLE_THAI ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_TURKISH() + { + check( "RTL_TEXTENCODING_APPLE_TURKISH", RTL_TEXTENCODING_APPLE_TURKISH ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_UKRAINIAN() + { + check( "RTL_TEXTENCODING_APPLE_UKRAINIAN", RTL_TEXTENCODING_APPLE_UKRAINIAN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_CHINSIMP() + { + check( "RTL_TEXTENCODING_APPLE_CHINSIMP", RTL_TEXTENCODING_APPLE_CHINSIMP ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_CHINTRAD() + { + check( "RTL_TEXTENCODING_APPLE_CHINTRAD", RTL_TEXTENCODING_APPLE_CHINTRAD ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_JAPANESE() + { + check( "RTL_TEXTENCODING_APPLE_JAPANESE", RTL_TEXTENCODING_APPLE_JAPANESE ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_APPLE_KOREAN() + { + check( "RTL_TEXTENCODING_APPLE_KOREAN", RTL_TEXTENCODING_APPLE_KOREAN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_932() + { + check( "RTL_TEXTENCODING_MS_932", RTL_TEXTENCODING_MS_932 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_936() + { + check( "RTL_TEXTENCODING_MS_936", RTL_TEXTENCODING_MS_936 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_949() + { + check( "RTL_TEXTENCODING_MS_949", RTL_TEXTENCODING_MS_949 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_950() + { + check( "RTL_TEXTENCODING_MS_950", RTL_TEXTENCODING_MS_950 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_SHIFT_JIS() + { + check( "RTL_TEXTENCODING_SHIFT_JIS", RTL_TEXTENCODING_SHIFT_JIS ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_GB_2312() + { + check( "RTL_TEXTENCODING_GB_2312", RTL_TEXTENCODING_GB_2312 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_GBT_12345() + { + check( "RTL_TEXTENCODING_GBT_12345", RTL_TEXTENCODING_GBT_12345 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_GBK() + { + check( "RTL_TEXTENCODING_GBK", RTL_TEXTENCODING_GBK ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_BIG5() + { + check( "RTL_TEXTENCODING_BIG5", RTL_TEXTENCODING_BIG5 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_EUC_JP() + { + check( "RTL_TEXTENCODING_EUC_JP", RTL_TEXTENCODING_EUC_JP ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_EUC_CN() + { + check( "RTL_TEXTENCODING_EUC_CN", RTL_TEXTENCODING_EUC_CN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_EUC_TW() + { + check( "RTL_TEXTENCODING_EUC_TW", RTL_TEXTENCODING_EUC_TW ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_ISO_2022_JP() + { + check( "RTL_TEXTENCODING_ISO_2022_JP", RTL_TEXTENCODING_ISO_2022_JP ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_ISO_2022_CN() + { + check( "RTL_TEXTENCODING_ISO_2022_CN", RTL_TEXTENCODING_ISO_2022_CN ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_KOI8_R() + { + check( "RTL_TEXTENCODING_KOI8_R", RTL_TEXTENCODING_KOI8_R ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_UTF7() + { + check( "RTL_TEXTENCODING_UTF7", RTL_TEXTENCODING_UTF7 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_UTF8() + { + check( "RTL_TEXTENCODING_UTF8", RTL_TEXTENCODING_UTF8 ); + } + // ---------------------------------------- + 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 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_EUC_KR() + { + check( "RTL_TEXTENCODING_EUC_KR", RTL_TEXTENCODING_EUC_KR ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_ISO_2022_KR() + { + check( "RTL_TEXTENCODING_ISO_2022_KR", RTL_TEXTENCODING_ISO_2022_KR ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_JIS_X_0201() + { + check( "RTL_TEXTENCODING_JIS_X_0201", RTL_TEXTENCODING_JIS_X_0201 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_JIS_X_0208() + { + check( "RTL_TEXTENCODING_JIS_X_0208", RTL_TEXTENCODING_JIS_X_0208 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_JIS_X_0212() + { + check( "RTL_TEXTENCODING_JIS_X_0212", RTL_TEXTENCODING_JIS_X_0212 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_MS_1361() + { + check( "RTL_TEXTENCODING_MS_1361", RTL_TEXTENCODING_MS_1361 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_GB_18030() + { + check( "RTL_TEXTENCODING_GB_18030", RTL_TEXTENCODING_GB_18030 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_BIG5_HKSCS() + { + check( "RTL_TEXTENCODING_BIG5_HKSCS", RTL_TEXTENCODING_BIG5_HKSCS ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_TIS_620() + { + check( "RTL_TEXTENCODING_TIS_620", RTL_TEXTENCODING_TIS_620 ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_KOI8_U() + { + check( "RTL_TEXTENCODING_KOI8_U", RTL_TEXTENCODING_KOI8_U ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_ISCII_DEVANAGARI() + { + check( "RTL_TEXTENCODING_ISCII_DEVANAGARI", RTL_TEXTENCODING_ISCII_DEVANAGARI ); + } + // ---------------------------------------- + void UnixCharsetFromTextEncoding_JAVA_UTF8() + { + check( "RTL_TEXTENCODING_JAVA_UTF8", RTL_TEXTENCODING_JAVA_UTF8 ); + } + // ---------------------------------------- + + CPPUNIT_TEST_SUITE( getBestUnix ); + 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_ARABIC ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CENTEURO ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CROATIAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CYRILLIC ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_DEVANAGARI ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_FARSI ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_GREEK ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_GUJARATI ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_GURMUKHI ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_HEBREW ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_ICELAND ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_ROMANIAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_THAI ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_TURKISH ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_UKRAINIAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CHINSIMP ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_CHINTRAD ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_JAPANESE ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_APPLE_KOREAN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_932 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_936 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_949 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_950 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_SHIFT_JIS ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GB_2312 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GBT_12345 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GBK ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_BIG5 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_JP ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_CN ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_TW ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_2022_JP ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_2022_CN ); + 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 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_EUC_KR ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISO_2022_KR ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JIS_X_0201 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JIS_X_0208 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JIS_X_0212 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_MS_1361 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_GB_18030 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_BIG5_HKSCS ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_TIS_620 ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_KOI8_U ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_ISCII_DEVANAGARI ); + CPPUNIT_TEST( UnixCharsetFromTextEncoding_JAVA_UTF8 ); + + CPPUNIT_TEST_SUITE_END( ); + }; + + // ----------------------------------------------------------------------------- + + + class getBestWindows : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void check( const sal_Char* _pRTL_TEXTENCODING, rtl_TextEncoding _aCurrentEncode ) + { + const sal_uInt8 nCharSet = rtl_getBestWindowsCharsetFromTextEncoding( _aCurrentEncode ); + if (nCharSet == 1) + { + t_print("rtl_getBestWindowsCharsetFromTextEncoding(%s) (%d) doesn't seem to exist.\n\n", _pRTL_TEXTENCODING, _aCurrentEncode); + } + else + { + t_print(T_VERBOSE, "'%s' is charset: '%d'\n", _pRTL_TEXTENCODING, nCharSet); + + rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromWindowsCharset( nCharSet ); + if (_aCurrentEncode != eTextEnc && + eTextEnc != RTL_TEXTENCODING_DONTKNOW) + { + t_print("rtl_getBestUnixCharsetFromTextEncoding(%s) is charset: %d\n", _pRTL_TEXTENCODING, nCharSet); + t_print("rtl_getTextEncodingFromWindowsCharset() differ: %s %d -> %d\n\n", _pRTL_TEXTENCODING, _aCurrentEncode, eTextEnc ); + } + // rtl::OString sError = "getTextEncodingFromWindowsCharset("; + // sError += rtl::OString::valueOf(nCharSet); + // sError += ") returns nul."; + + // CPPUNIT_ASSERT_MESSAGE(sError.getStr(), eTextEnc != RTL_TEXTENCODING_DONTKNOW); + // CPPUNIT_ASSERT_MESSAGE("Does not realize itself", _aCurrentEncode == 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_IBM_437 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_850() + { + check( "RTL_TEXTENCODING_IBM_850", RTL_TEXTENCODING_IBM_850 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_860() + { + check( "RTL_TEXTENCODING_IBM_860", RTL_TEXTENCODING_IBM_860 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_861() + { + check( "RTL_TEXTENCODING_IBM_861", RTL_TEXTENCODING_IBM_861 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_863() + { + check( "RTL_TEXTENCODING_IBM_863", RTL_TEXTENCODING_IBM_863 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_865() + { + check( "RTL_TEXTENCODING_IBM_865", RTL_TEXTENCODING_IBM_865 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_SYMBOL() + { + check( "RTL_TEXTENCODING_SYMBOL", RTL_TEXTENCODING_SYMBOL ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ASCII_US() + { + check( "RTL_TEXTENCODING_ASCII_US", RTL_TEXTENCODING_ASCII_US ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_1() + { + check( "RTL_TEXTENCODING_ISO_8859_1", RTL_TEXTENCODING_ISO_8859_1 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_2() + { + check( "RTL_TEXTENCODING_ISO_8859_2", RTL_TEXTENCODING_ISO_8859_2 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_3() + { + check( "RTL_TEXTENCODING_ISO_8859_3", RTL_TEXTENCODING_ISO_8859_3 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_4() + { + check( "RTL_TEXTENCODING_ISO_8859_4", RTL_TEXTENCODING_ISO_8859_4 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_5() + { + check( "RTL_TEXTENCODING_ISO_8859_5", RTL_TEXTENCODING_ISO_8859_5 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_6() + { + check( "RTL_TEXTENCODING_ISO_8859_6", RTL_TEXTENCODING_ISO_8859_6 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_7() + { + check( "RTL_TEXTENCODING_ISO_8859_7", RTL_TEXTENCODING_ISO_8859_7 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_8() + { + check( "RTL_TEXTENCODING_ISO_8859_8", RTL_TEXTENCODING_ISO_8859_8 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_9() + { + check( "RTL_TEXTENCODING_ISO_8859_9", RTL_TEXTENCODING_ISO_8859_9 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_14() + { + check( "RTL_TEXTENCODING_ISO_8859_14", RTL_TEXTENCODING_ISO_8859_14 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_15() + { + check( "RTL_TEXTENCODING_ISO_8859_15", RTL_TEXTENCODING_ISO_8859_15 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_737() + { + check( "RTL_TEXTENCODING_IBM_737", RTL_TEXTENCODING_IBM_737 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_775() + { + check( "RTL_TEXTENCODING_IBM_775", RTL_TEXTENCODING_IBM_775 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_852() + { + check( "RTL_TEXTENCODING_IBM_852", RTL_TEXTENCODING_IBM_852 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_855() + { + check( "RTL_TEXTENCODING_IBM_855", RTL_TEXTENCODING_IBM_855 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_857() + { + check( "RTL_TEXTENCODING_IBM_857", RTL_TEXTENCODING_IBM_857 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_862() + { + check( "RTL_TEXTENCODING_IBM_862", RTL_TEXTENCODING_IBM_862 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_864() + { + check( "RTL_TEXTENCODING_IBM_864", RTL_TEXTENCODING_IBM_864 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_866() + { + check( "RTL_TEXTENCODING_IBM_866", RTL_TEXTENCODING_IBM_866 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_IBM_869() + { + check( "RTL_TEXTENCODING_IBM_869", RTL_TEXTENCODING_IBM_869 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_874() + { + check( "RTL_TEXTENCODING_MS_874", RTL_TEXTENCODING_MS_874 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1250() + { + check( "RTL_TEXTENCODING_MS_1250", RTL_TEXTENCODING_MS_1250 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1251() + { + check( "RTL_TEXTENCODING_MS_1251", RTL_TEXTENCODING_MS_1251 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1253() + { + check( "RTL_TEXTENCODING_MS_1253", RTL_TEXTENCODING_MS_1253 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1254() + { + check( "RTL_TEXTENCODING_MS_1254", RTL_TEXTENCODING_MS_1254 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1255() + { + check( "RTL_TEXTENCODING_MS_1255", RTL_TEXTENCODING_MS_1255 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1256() + { + check( "RTL_TEXTENCODING_MS_1256", RTL_TEXTENCODING_MS_1256 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1257() + { + check( "RTL_TEXTENCODING_MS_1257", RTL_TEXTENCODING_MS_1257 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1258() + { + check( "RTL_TEXTENCODING_MS_1258", RTL_TEXTENCODING_MS_1258 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_ARABIC() + { + check( "RTL_TEXTENCODING_APPLE_ARABIC", RTL_TEXTENCODING_APPLE_ARABIC ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_CENTEURO() + { + check( "RTL_TEXTENCODING_APPLE_CENTEURO", RTL_TEXTENCODING_APPLE_CENTEURO ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_CROATIAN() + { + check( "RTL_TEXTENCODING_APPLE_CROATIAN", RTL_TEXTENCODING_APPLE_CROATIAN ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_CYRILLIC() + { + check( "RTL_TEXTENCODING_APPLE_CYRILLIC", RTL_TEXTENCODING_APPLE_CYRILLIC ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_DEVANAGARI() + { + check( "RTL_TEXTENCODING_APPLE_DEVANAGARI", RTL_TEXTENCODING_APPLE_DEVANAGARI ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_FARSI() + { + check( "RTL_TEXTENCODING_APPLE_FARSI", RTL_TEXTENCODING_APPLE_FARSI ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_GREEK() + { + check( "RTL_TEXTENCODING_APPLE_GREEK", RTL_TEXTENCODING_APPLE_GREEK ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_GUJARATI() + { + check( "RTL_TEXTENCODING_APPLE_GUJARATI", RTL_TEXTENCODING_APPLE_GUJARATI ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_GURMUKHI() + { + check( "RTL_TEXTENCODING_APPLE_GURMUKHI", RTL_TEXTENCODING_APPLE_GURMUKHI ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_HEBREW() + { + check( "RTL_TEXTENCODING_APPLE_HEBREW", RTL_TEXTENCODING_APPLE_HEBREW ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_ICELAND() + { + check( "RTL_TEXTENCODING_APPLE_ICELAND", RTL_TEXTENCODING_APPLE_ICELAND ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_ROMANIAN() + { + check( "RTL_TEXTENCODING_APPLE_ROMANIAN", RTL_TEXTENCODING_APPLE_ROMANIAN ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_THAI() + { + check( "RTL_TEXTENCODING_APPLE_THAI", RTL_TEXTENCODING_APPLE_THAI ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_TURKISH() + { + check( "RTL_TEXTENCODING_APPLE_TURKISH", RTL_TEXTENCODING_APPLE_TURKISH ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_UKRAINIAN() + { + check( "RTL_TEXTENCODING_APPLE_UKRAINIAN", RTL_TEXTENCODING_APPLE_UKRAINIAN ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_CHINSIMP() + { + check( "RTL_TEXTENCODING_APPLE_CHINSIMP", RTL_TEXTENCODING_APPLE_CHINSIMP ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_CHINTRAD() + { + check( "RTL_TEXTENCODING_APPLE_CHINTRAD", RTL_TEXTENCODING_APPLE_CHINTRAD ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_JAPANESE() + { + check( "RTL_TEXTENCODING_APPLE_JAPANESE", RTL_TEXTENCODING_APPLE_JAPANESE ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_APPLE_KOREAN() + { + check( "RTL_TEXTENCODING_APPLE_KOREAN", RTL_TEXTENCODING_APPLE_KOREAN ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_932() + { + check( "RTL_TEXTENCODING_MS_932", RTL_TEXTENCODING_MS_932 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_936() + { + check( "RTL_TEXTENCODING_MS_936", RTL_TEXTENCODING_MS_936 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_949() + { + check( "RTL_TEXTENCODING_MS_949", RTL_TEXTENCODING_MS_949 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_950() + { + check( "RTL_TEXTENCODING_MS_950", RTL_TEXTENCODING_MS_950 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_SHIFT_JIS() + { + check( "RTL_TEXTENCODING_SHIFT_JIS", RTL_TEXTENCODING_SHIFT_JIS ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_GB_2312() + { + check( "RTL_TEXTENCODING_GB_2312", RTL_TEXTENCODING_GB_2312 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_GBT_12345() + { + check( "RTL_TEXTENCODING_GBT_12345", RTL_TEXTENCODING_GBT_12345 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_GBK() + { + check( "RTL_TEXTENCODING_GBK", RTL_TEXTENCODING_GBK ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_BIG5() + { + check( "RTL_TEXTENCODING_BIG5", RTL_TEXTENCODING_BIG5 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_EUC_JP() + { + check( "RTL_TEXTENCODING_EUC_JP", RTL_TEXTENCODING_EUC_JP ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_EUC_CN() + { + check( "RTL_TEXTENCODING_EUC_CN", RTL_TEXTENCODING_EUC_CN ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_EUC_TW() + { + check( "RTL_TEXTENCODING_EUC_TW", RTL_TEXTENCODING_EUC_TW ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_2022_JP() + { + check( "RTL_TEXTENCODING_ISO_2022_JP", RTL_TEXTENCODING_ISO_2022_JP ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_2022_CN() + { + check( "RTL_TEXTENCODING_ISO_2022_CN", RTL_TEXTENCODING_ISO_2022_CN ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_KOI8_R() + { + check( "RTL_TEXTENCODING_KOI8_R", RTL_TEXTENCODING_KOI8_R ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_UTF7() + { + check( "RTL_TEXTENCODING_UTF7", RTL_TEXTENCODING_UTF7 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_UTF8() + { + check( "RTL_TEXTENCODING_UTF8", RTL_TEXTENCODING_UTF8 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_10() + { + check( "RTL_TEXTENCODING_ISO_8859_10", RTL_TEXTENCODING_ISO_8859_10 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_8859_13() + { + check( "RTL_TEXTENCODING_ISO_8859_13", RTL_TEXTENCODING_ISO_8859_13 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_EUC_KR() + { + check( "RTL_TEXTENCODING_EUC_KR", RTL_TEXTENCODING_EUC_KR ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISO_2022_KR() + { + check( "RTL_TEXTENCODING_ISO_2022_KR", RTL_TEXTENCODING_ISO_2022_KR ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_JIS_X_0201() + { + check( "RTL_TEXTENCODING_JIS_X_0201", RTL_TEXTENCODING_JIS_X_0201 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_JIS_X_0208() + { + check( "RTL_TEXTENCODING_JIS_X_0208", RTL_TEXTENCODING_JIS_X_0208 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_JIS_X_0212() + { + check( "RTL_TEXTENCODING_JIS_X_0212", RTL_TEXTENCODING_JIS_X_0212 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_MS_1361() + { + check( "RTL_TEXTENCODING_MS_1361", RTL_TEXTENCODING_MS_1361 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_GB_18030() + { + check( "RTL_TEXTENCODING_GB_18030", RTL_TEXTENCODING_GB_18030 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_BIG5_HKSCS() + { + check( "RTL_TEXTENCODING_BIG5_HKSCS", RTL_TEXTENCODING_BIG5_HKSCS ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_TIS_620() + { + check( "RTL_TEXTENCODING_TIS_620", RTL_TEXTENCODING_TIS_620 ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_KOI8_U() + { + check( "RTL_TEXTENCODING_KOI8_U", RTL_TEXTENCODING_KOI8_U ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_ISCII_DEVANAGARI() + { + check( "RTL_TEXTENCODING_ISCII_DEVANAGARI", RTL_TEXTENCODING_ISCII_DEVANAGARI ); + } + // ---------------------------------------- + void WindowsCharsetFromTextEncoding_JAVA_UTF8() + { + check( "RTL_TEXTENCODING_JAVA_UTF8", RTL_TEXTENCODING_JAVA_UTF8 ); + } + // ---------------------------------------- + + CPPUNIT_TEST_SUITE( getBestWindows ); + 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 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_2 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_3 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_4 ); + 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 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_14 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_ISO_8859_15 ); + 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 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_APPLE_ICELAND ); + 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 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_UTF7 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_UTF8 ); + 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 ); + CPPUNIT_TEST( WindowsCharsetFromTextEncoding_JAVA_UTF8 ); + + CPPUNIT_TEST_SUITE_END( ); + }; + class getTextEncodingInfo: public CppUnit::TestFixture + { + public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + // not implemented encoding test + void getTextEncodingInfo_001() + { + rtl_TextEncodingInfo aInfo1, aInfo2, aInfo3, aInfo4, aInfo5; + aInfo1.StructSize = 4; + // not implemented + sal_Bool bRes1 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo1 ); + // implemented + sal_Bool bRes11 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo1 ); + CPPUNIT_ASSERT_MESSAGE("should return sal_False.", bRes1 == sal_False && bRes11 == sal_False ); + + aInfo2.StructSize = 5; + sal_Bool bRes2 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo2 ); + sal_Bool bRes21 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo2 ); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes2 == sal_True && bRes21 == sal_True && aInfo2.MinimumCharSize >=1 ); + + aInfo3.StructSize = 6; + sal_Bool bRes3 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo3 ); + sal_Bool bRes31 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo3 ); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes3 == sal_True && bRes31 == sal_True ); +//&& aInfo2.MinimumCharSize >=1 ); + + aInfo4.StructSize = 8; + sal_Bool bRes4 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo4 ); + sal_Bool bRes41 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_CYRILLIC, &aInfo4); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes4 == sal_True && bRes41 == sal_True); +// && aInfo2.MinimumCharSize >=1 ); + + aInfo5.StructSize = sizeof aInfo5; + sal_Bool bRes5 = rtl_getTextEncodingInfo( RTL_TEXTENCODING_APPLE_ARABIC, &aInfo5 ); + CPPUNIT_ASSERT_MESSAGE("StructSize<6 should return sal_True", bRes5 == sal_False && aInfo5.Flags == 0); + + } + CPPUNIT_TEST_SUITE(getTextEncodingInfo); + CPPUNIT_TEST(getTextEncodingInfo_001); + //CPPUNIT_TEST(getTextEncodingInfo_002); + CPPUNIT_TEST_SUITE_END(); + }; +} + +namespace { + +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_NAMED_REGISTRATION( rtl_tencinfo::getBestMime, "rtl_tencinfo" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_tencinfo::getBestUnix, "rtl_tencinfo" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_tencinfo::getBestWindows, "rtl_tencinfo" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_tencinfo::getTextEncodingInfo, "rtl_tencinfo" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( + TestEncodingFromUnix, "TestEncodingFromUnix"); + +// ----------------------------------------------------------------------------- + +NOADDITIONAL; diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx new file mode 100644 index 000000000000..2129815a6779 --- /dev/null +++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx @@ -0,0 +1,2904 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_textcvt.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "sal/config.h" + +#include <cstddef> +#include <cstring> + +#include "testshl/simpleheader.hxx" +#include "rtl/string.hxx" +#include "rtl/tencinfo.h" +#include "rtl/textcvt.h" +#include "rtl/textenc.h" +#include "sal/types.h" + +namespace { + +struct SingleByteCharSet { + rtl_TextEncoding m_nEncoding; + sal_Unicode m_aMap[256]; +}; + +void testSingleByteCharSet(SingleByteCharSet const & rSet) { + sal_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< sal_Char >(i); + } + } + { + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rSet.m_nEncoding); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("failure #1", aConverter && aContext); + 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_MESSAGE( + "failure #2", + nSize == nNumber && nInfo == 0 && nConverted == nNumber); + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + } + { + bool bSuccess = true; + int j = 0; + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] != 0xFFFF && aUnicode[j++] != rSet.m_aMap[i]) { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #3", bSuccess); + } + if (rSet.m_nEncoding == RTL_TEXTENCODING_ASCII_US) { + nNumber = 128; + } + { + rtl_UnicodeToTextConverter aConverter + = rtl_createUnicodeToTextConverter(rSet.m_nEncoding); + rtl_UnicodeToTextContext aContext + = rtl_createUnicodeToTextContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("failure #4", aConverter && aContext); + 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_MESSAGE( + "failure #5", + nSize == nNumber && nInfo == 0 && nConverted == nNumber); + rtl_destroyUnicodeToTextContext(aConverter, aContext); + rtl_destroyUnicodeToTextConverter(aConverter); + } + { + bool bSuccess = true; + int j = 0; + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] != 0xFFFF + && aText[j++] != static_cast< sal_Char >(i)) + { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #6", bSuccess); + } + for (int i = 0; i < 256; ++i) { + if (rSet.m_aMap[i] == 0xFFFF) { + aText[0] = static_cast< sal_Char >(i); + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rSet.m_nEncoding); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("failure #7", aConverter && aContext); + 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); + CPPUNIT_ASSERT_MESSAGE( + "failure #9", + (nSize == 0 + && (nInfo + == (RTL_TEXTTOUNICODE_INFO_ERROR + | RTL_TEXTTOUNICODE_INFO_UNDEFINED)) + && nConverted == 0)); + 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); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("failure #10", aConverter && aContext); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertTextToUnicode( + aConverter, aContext, + reinterpret_cast< sal_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_MESSAGE( + "failure #11", + (nSize == rTest.m_nUnicodeSize && nInfo == 0 + && nConverted == rTest.m_nTextSize)); + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + bool bSuccess = true; + for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { + if (aUnicode[i] != rTest.m_aUnicode[i]) { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #12", bSuccess); + } + if (rTest.m_bForward) { + sal_Unicode aUnicode[TEST_STRING_SIZE]; + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rTest.m_nEncoding); + rtl_TextToUnicodeContext aContext + = rtl_createTextToUnicodeContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("failure #13", aConverter && aContext); + if (aContext != (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< sal_Char const * >(rTest.m_pText + nInput), + nSrcBytes, aUnicode + nOutput, TEST_STRING_SIZE - nOutput, + nFlags, &nInfo, &nConverted); + nOutput += nSize; + nInput += nConverted; + CPPUNIT_ASSERT_MESSAGE( + "failure #14", + (nInfo & ~RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL) == 0); + } + CPPUNIT_ASSERT_MESSAGE( + "failure #15", + nOutput == rTest.m_nUnicodeSize && nInput == rTest.m_nTextSize); + bool bSuccess = true; + for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { + if (aUnicode[i] != rTest.m_aUnicode[i]) { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #16", bSuccess); + } + rtl_destroyTextToUnicodeContext(aConverter, aContext); + rtl_destroyTextToUnicodeConverter(aConverter); + } + if (rTest.m_bNoContext && rTest.m_bForward) { + sal_Unicode aUnicode[TEST_STRING_SIZE]; + int nSize = 0; + rtl_TextToUnicodeConverter aConverter + = rtl_createTextToUnicodeConverter(rTest.m_nEncoding); + CPPUNIT_ASSERT_MESSAGE("failure #17", aConverter); + for (sal_Size i = 0;;) { + if (i == rTest.m_nTextSize) { + goto done; + } + sal_Char c1 = rTest.m_pText[i++]; + sal_Unicode aUC[2]; + sal_uInt32 nInfo = 0; + sal_Size nCvtBytes; + sal_Size nChars = rtl_convertTextToUnicode( + aConverter, 0, &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_SRCBUFFERTOSMALL) != 0) { + sal_Char sBuffer[10]; + sBuffer[0] = c1; + sal_uInt16 nLen = 1; + while ((nInfo & RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL) != 0 + && nLen < 10) + { + if (i == rTest.m_nTextSize) { + goto done; + } + c1 = rTest.m_pText[i++]; + sBuffer[nLen++] = c1; + nChars = rtl_convertTextToUnicode( + aConverter, 0, 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_SRCBUFFERTOSMALL) == 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); + bool bSuccess = true; + for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { + if (aUnicode[i] != rTest.m_aUnicode[i]) { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #18", bSuccess); + } + if (rTest.m_bReverse) { + sal_Char aText[TEST_STRING_SIZE]; + rtl_UnicodeToTextConverter aConverter + = rtl_createUnicodeToTextConverter(rTest.m_nEncoding); + rtl_UnicodeToTextContext aContext + = rtl_createUnicodeToTextContext(aConverter); + CPPUNIT_ASSERT_MESSAGE("failure #19", aConverter && aContext); + 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_MESSAGE( + "failure #20", + (nSize == rTest.m_nTextSize + && (nInfo == 0 + || (nInfo == RTL_UNICODETOTEXT_INFO_UNDEFINED + && (rTest.m_nReverseUndefined + != RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR))) + && nConverted == rTest.m_nUnicodeSize)); + rtl_destroyUnicodeToTextContext(aConverter, aContext); + rtl_destroyUnicodeToTextConverter(aConverter); + bool bSuccess = true; + for (sal_Size i = 0; i < rTest.m_nTextSize; ++i) { + if (aText[i] != rTest.m_pText[i]) { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #21", bSuccess); + } +} + +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("failure #22", aConverter); + sal_Size nSize; + sal_uInt32 nInfo; + sal_Size nConverted; + nSize = rtl_convertTextToUnicode( + aConverter, 0, reinterpret_cast< sal_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_MESSAGE( + "failure #23", + (nSize <= rTest.m_nUnicodeSize + && (nInfo == RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL + || (nInfo + == (RTL_TEXTTOUNICODE_INFO_ERROR + | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL))) + && nConverted < rTest.m_nTextSize)); + rtl_destroyTextToUnicodeConverter(aConverter); + bool bSuccess = true; + for (sal_Size i = 0; i < nSize; ++i) { + if (aUnicode[i] != rTest.m_aUnicode[i]) { + bSuccess = false; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("failure #24", bSuccess); + } +} + +class Test: public CppUnit::TestFixture { +public: + void testSingleByte(); + + void testComplex(); + + void testComplexCut(); + + void testSRCBUFFERTOSMALL(); + + void testMime(); + + void testWindows(); + + void testInfo(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testSingleByte); + CPPUNIT_TEST(testComplex); + CPPUNIT_TEST(testComplexCut); + 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_ISCII_DEVANAGARI, + { 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, + 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,0x0901,0x0902,0x0903,0x0905,0x0906,0x0907,0x0908, + 0x0909,0x090A,0x090B,0x090E,0x090F,0x0910,0x090D,0x0912, + 0x0913,0x0914,0x0911,0x0915,0x0916,0x0917,0x0918,0x0919, + 0x091A,0x091B,0x091C,0x091D,0x091E,0x091F,0x0920,0x0921, + 0x0922,0x0923,0x0924,0x0925,0x0926,0x0927,0x0928,0x0929, + 0x092A,0x092B,0x092C,0x092D,0x092E,0x092F,0x095F,0x0930, + 0x0931,0x0932,0x0933,0x0934,0x0935,0x0936,0x0937,0x0938, + 0x0939,0xFFFF,0x093E,0x093F,0x0940,0x0941,0x0942,0x0943, + 0x0946,0x0947,0x0948,0x0945,0x094A,0x094B,0x094C,0x0949, + 0x094D,0x093C,0x0964,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, + 0xFFFF,0x0966,0x0967,0x0968,0x0969,0x096A,0x096B,0x096C, + 0x096D,0x096E,0x096F,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF } }, + { 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,0x27CF,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 < sizeof data / sizeof data[0]; ++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 }, + { 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 }, + { 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 }, + { 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 }, + { 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 }, + // 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 }, + { 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 }, + { 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 }, + { 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 }, + { 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 }, + { 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 }, + { RTL_TEXTENCODING_EUC_JP, + RTL_CONSTASCII_STRINGPARAM("?"), + { 0xFF0D }, + 1, + true, + false, + true, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK }, + + // 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 }, + { 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 }, + + // 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 }, + { 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 }, + + // 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( + "\xC0\x80\xE0\x80\x81\xF0\x80\x80\x82\xF8\x80\x80\x80\x83" + "\xFC\x80\x80\x80\x80\x84"), + { 0x0000,0x0001,0x0002,0x0003,0x0004 }, + 5, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xED\xA1\x89\xED\xB4\x93"), + { 0xD849,0xDD13 }, + 2, + false, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR }, + { RTL_TEXTENCODING_UTF8, + RTL_CONSTASCII_STRINGPARAM("\xED\xA1\x89\x41"), + { 0xD849,0x0041 }, + 2, + false, + true, + false, + 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 }, + + // 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 }, + { 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 }, + + // 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 }, + + // 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 } + }; + for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { + doComplexCharSetTest(data[i]); + } +} + +void Test::testComplexCut() { + static ComplexCharSetTest const data[] + = { { 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 }, + { RTL_TEXTENCODING_EUC_CN, + RTL_CONSTASCII_STRINGPARAM("\xA1"), + { 0 }, + 0, + true, + true, + false, + false, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR } /* , + { 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 < sizeof data / sizeof data[0]; ++i) { + doComplexCharSetCutTest(data[i]); + } +} + +void Test::testSRCBUFFERTOSMALL() { + rtl_TextToUnicodeConverter cv = rtl_createTextToUnicodeConverter( + RTL_TEXTENCODING_EUC_JP); + OSL_ASSERT(cv != NULL); + rtl_TextToUnicodeContext cx = rtl_createTextToUnicodeContext(cv); + OSL_ASSERT(cx != NULL); + 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, sizeof dst / sizeof (sal_Unicode), + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | + RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), + &info, &cvt)); + CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL, 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 }, + { 0, 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 < sizeof data / sizeof data[0]; ++i) { + if (data[i].mime == 0) { + OSL_ASSERT(data[i].reverse); + CPPUNIT_ASSERT_EQUAL( + static_cast< char const * >(0), + rtl_getMimeCharsetFromTextEncoding(data[i].encoding)); + } else { + CPPUNIT_ASSERT_EQUAL( + data[i].encoding, + rtl_getTextEncodingFromMimeCharset(data[i].mime)); + if (data[i].reverse) { + CPPUNIT_ASSERT_EQUAL( + rtl::OString(data[i].mime), + rtl::OString( + rtl_getMimeCharsetFromTextEncoding(data[i].encoding))); + } + } + } +} + +void Test::testWindows() { + struct Data { + sal_uInt32 codePage; + rtl_TextEncoding encoding; + bool reverse; + }; + static Data const data[] = { + { 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 }, + { 0, RTL_TEXTENCODING_ISCII_DEVANAGARI, true } + }; + for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++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[] = { + { RTL_TEXTENCODING_APPLE_CHINTRAD, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_APPLE_JAPANESE, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_APPLE_KOREAN, 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_JP, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_EUC_KR, 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 }, + { RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_INFO_CONTEXT, true }, + { RTL_TEXTENCODING_ISO_2022_JP, RTL_TEXTENCODING_INFO_ASCII, false }, + { RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_INFO_CONTEXT, true }, + { RTL_TEXTENCODING_ISO_2022_KR, RTL_TEXTENCODING_INFO_ASCII, false }, + { 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_SHIFT_JIS, 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_ISCII_DEVANAGARI, RTL_TEXTENCODING_INFO_ASCII, true }, + { RTL_TEXTENCODING_ISCII_DEVANAGARI, RTL_TEXTENCODING_INFO_MIME, false }, + { 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 < sizeof data / sizeof data[0]; ++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_NAMED_REGISTRATION(Test, "rtl_textcvt"); + +} + +NOADDITIONAL; diff --git a/sal/qa/rtl/uri/makefile.mk b/sal/qa/rtl/uri/makefile.mk new file mode 100644 index 000000000000..2c536da484d7 --- /dev/null +++ b/sal/qa/rtl/uri/makefile.mk @@ -0,0 +1,77 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.8 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sal +TARGET=qa_rtl_uritest + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# --- BEGIN -------------------------------------------------------- +SHL1OBJS= \ + $(SLO)$/rtl_Uri.obj +SHL1TARGET= rtl_uri_simple +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# END -------------------------------------------------------------- + +# --- BEGIN -------------------------------------------------------- +SHL2OBJS= \ + $(SLO)$/rtl_testuri.obj +SHL2TARGET= rtl_Uri +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +DEF2NAME =$(SHL2TARGET) +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map + +# END -------------------------------------------------------------- + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/rtl/uri/rtl_Uri.cxx b/sal/qa/rtl/uri/rtl_Uri.cxx new file mode 100644 index 000000000000..cc27f956b573 --- /dev/null +++ b/sal/qa/rtl/uri/rtl_Uri.cxx @@ -0,0 +1,300 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_Uri.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <stdlib.h> +#include <rtl/ustring.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/uri.hxx> +#include <osl/thread.h> +#include <osl/file.hxx> + +#include <testshl/simpleheader.hxx> + +// ----------------------------------------------------------------------------- + +namespace Stringtest +{ + rtl::OString toHex(unsigned char _c) + { + rtl::OStringBuffer sStrBuf; + static char cHex[] = "0123456789ABCDEF"; + + int nhigh = int(_c) >> 4 & 0xf; + int nlow = int(_c) & 0xf; + sStrBuf.append( cHex[nhigh] ); + sStrBuf.append( cHex[nlow] ); + return sStrBuf.makeStringAndClear(); + } + + rtl::OString escapeString(rtl::OString const& _sStr) + { + rtl::OStringBuffer sStrBuf; + sal_Int32 nLength = _sStr.getLength(); + for(int i=0;i<nLength;++i) + { + unsigned char c = (unsigned char)_sStr[i]; + if (c > 127) + { + sStrBuf.append("%"); + sStrBuf.append(toHex(c)); + } + else + { + sStrBuf.append((char)c); + } + } + return sStrBuf.makeStringAndClear(); + } + + // ----------------------------------------------------------------------------- + + class Convert : public CppUnit::TestFixture + { + rtl::OUString m_aStr; + public: + /* + rtl::OString toUTF8(rtl::OUString const& _suStr) + { + rtl::OString sStrAsUTF8 = rtl::OUStringToOString(_suStr, RTL_TEXTENCODING_UTF8); + t_print("%s\n", escapeString(sStrAsUTF8).getStr()); + return sStrAsUTF8; + } + */ + rtl::OUString fromUTF8(rtl::OString const& _suStr) + { + rtl::OUString suStr = rtl::OStringToOUString(_suStr, RTL_TEXTENCODING_UTF8); + return suStr; + } + + rtl::OString convertToOString(rtl::OUString const& _suStr) + { + return rtl::OUStringToOString(_suStr, osl_getThreadTextEncoding()/*RTL_TEXTENCODING_ASCII_US*/); + } + + void showContent(rtl::OUString const& _suStr) + { + rtl::OString sStr = convertToOString(_suStr); + t_print("%s\n", sStr.getStr()); + } + + void toUTF8_mech(rtl::OUString const& _suStr, rtl_UriEncodeMechanism _eMechanism) + { + rtl::OUString suStr; + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassNone, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassUric, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassUricNoSlash, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassRelSegment, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassRegName, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassUserinfo, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassPchar, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + suStr = rtl::Uri::encode(_suStr, rtl_UriCharClassUnoParamValue, _eMechanism, RTL_TEXTENCODING_UTF8); + showContent(suStr); + } + + void toUTF8(rtl::OUString const& _suStr) + { + t_print("rtl_UriEncodeIgnoreEscapes \n"); + toUTF8_mech(_suStr, rtl_UriEncodeIgnoreEscapes); + t_print("\n"); + t_print("# rtl_UriEncodeKeepEscapes\n"); + toUTF8_mech(_suStr, rtl_UriEncodeKeepEscapes); + t_print("\n"); + t_print("# rtl_UriEncodeCheckEscapes\n"); + toUTF8_mech(_suStr, rtl_UriEncodeCheckEscapes); + t_print("\n"); + } + + void test_FromUTF8_001() + { + // string --> ustring + rtl::OString sStrUTF8("h%C3%A4llo"); + rtl::OUString suStrUTF8 = rtl::OStringToOUString(sStrUTF8, RTL_TEXTENCODING_ASCII_US); + + // UTF8 --> real ustring + rtl::OUString suStr_UriDecodeToIuri = rtl::Uri::decode(suStrUTF8, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8); + showContent(suStr_UriDecodeToIuri); + + // string --> ustring + rtl::OString sStr("h\xE4llo"); + rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", suString.equals(suStr_UriDecodeToIuri) == sal_True); + + // ustring --> ustring (UTF8) + rtl::OUString suStr2 = rtl::Uri::encode(suStr_UriDecodeToIuri, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + showContent(suStr2); + + CPPUNIT_ASSERT_MESSAGE("Strings must be equal", suStr2.equals(suStrUTF8) == sal_True); + // suStr should be equal to suStr2 + } + + // "%C3%84qypten"; + // testshl2 ../../../unxlngi4.pro/lib/libConvert.so "-onlyerrors" + // # Type: 'Directory' file name '%E6%89%8B%E6%9C%BA%E5%8F%B7%E7%A0%81' + // # Type: 'Directory' file name '%E6%9C%AA%E5%91%BD%E5%90%8Dzhgb18030' + // # Type: 'Regular file' file name '%E5%B7%A5%E4%BD%9C' + // # Type: 'Regular file' file name '%E4%BA%8C%E6%89%8B%E6%88%BF%E4%B9%B0%E5%8D%96%E5%90%88%E5%90%8C%E8%8D%89%E7%A8%BF.doc' + // ls + rtl::OString getFileTypeName(osl::FileStatus const& _aStatus) + { + rtl::OString sType; + if (_aStatus.isValid(osl_FileStatus_Mask_Type)) + { + osl::FileStatus::Type aType = _aStatus.getFileType(); + if (aType == osl::FileStatus::Directory) + { + sType = "Directory"; + } + else if (aType == osl::FileStatus::Regular) + { + sType = "Regular file"; + } + else if (aType == osl::FileStatus::Volume) + { + sType = "Volume"; + } + else if (aType == osl::FileStatus::Fifo) + { + sType = "Fifo"; + } + else if (aType == osl::FileStatus::Socket) + { + sType = "Socket"; + } + else if (aType == osl::FileStatus::Link) + { + sType = "Link"; + } + else if (aType == osl::FileStatus::Special) + { + sType = "Special"; + } + else if (aType == osl::FileStatus::Unknown) + { + sType = "Unknown"; + } + else + { + sType = "Not handled yet"; + } + } + else + { + sType = "ERROR: osl_FileStatus_Mask_Type not set for FileStatus!"; + } + return sType; + } + + + void test_UTF8_files() + { +#ifdef UNX + rtl::OUString suDirURL(rtl::OUString::createFromAscii("file:///tmp/atestdir")); +#else /* Windows */ + rtl::OUString suDirURL(rtl::OUString::createFromAscii("file:///c:/temp/atestdir")); +#endif + osl::Directory aDir(suDirURL); + aDir.open(); + if (aDir.isOpen()) + { + osl::DirectoryItem aItem; + osl::FileStatus aStatus(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Attributes | osl_FileStatus_Mask_Type); + while (aDir.getNextItem(aItem) == ::osl::FileBase::E_None) + { + if (osl::FileBase::E_None == aItem.getFileStatus(aStatus) && + aStatus.isValid(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Attributes)) + { + rtl::OString sType = getFileTypeName(aStatus); + + rtl::OUString suFilename = aStatus.getFileName(); + // rtl::OUString suFullFileURL; + + rtl::OUString suStrUTF8 = rtl::Uri::encode(suFilename, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8); + rtl::OString sStrUTF8 = convertToOString(suStrUTF8); + t_print("Type: '%s' file name '%s'\n", sType.getStr(), sStrUTF8.getStr()); + } + } + aDir.close(); + } + else + { + rtl::OString sStr; + sStr = rtl::OUStringToOString(suDirURL, osl_getThreadTextEncoding()); + t_print("can't open dir:'%s'\n", sStr.getStr()); + } + } + + void test_FromUTF8() + { + rtl::OString sStr("h%C3%A4llo"); + rtl::OUString suStr = rtl::OStringToOUString(sStr, osl_getThreadTextEncoding()); + +// rtl_UriEncodeIgnoreEscapes, +// rtl_UriEncodeKeepEscapes, +// rtl_UriEncodeCheckEscapes, +// rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassRegName, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8); + rtl::OUString suStr_UriDecodeNone = rtl::Uri::decode(suStr, rtl_UriDecodeNone, RTL_TEXTENCODING_UTF8); + showContent(suStr_UriDecodeNone); + toUTF8(suStr_UriDecodeNone); + + rtl::OUString suStr_UriDecodeToIuri = rtl::Uri::decode(suStr, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8); + showContent(suStr_UriDecodeToIuri); + toUTF8(suStr_UriDecodeToIuri); + + rtl::OUString suStr_UriDecodeWithCharset = rtl::Uri::decode(suStr, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8); + showContent(suStr_UriDecodeWithCharset); + toUTF8(suStr_UriDecodeWithCharset); + } + + CPPUNIT_TEST_SUITE( Convert ); + CPPUNIT_TEST( test_FromUTF8_001 ); +// CPPUNIT_TEST( test_UTF8_files ); +// CPPUNIT_TEST( test_FromUTF8 ); + CPPUNIT_TEST_SUITE_END( ); + }; + +} + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( Stringtest::Convert, "Stringtest" ); + +// LLA: doku anpassen!!! + +NOADDITIONAL; diff --git a/sal/qa/rtl/uri/rtl_testuri.cxx b/sal/qa/rtl/uri/rtl_testuri.cxx new file mode 100644 index 000000000000..4d1d80830dd3 --- /dev/null +++ b/sal/qa/rtl/uri/rtl_testuri.cxx @@ -0,0 +1,548 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_testuri.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include "rtl/strbuf.hxx" +#include "rtl/textenc.h" +#include "rtl/uri.h" +#include "rtl/uri.hxx" +#include "rtl/ustrbuf.hxx" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" + +#include "testshl/simpleheader.hxx" + +#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; + + rtl::OUStringBuffer aBuffer; + rtl::OUString aText1; + rtl::OUString aText2; + + // Check that all characters map back to themselves when encoded/decoded: + + aText1 = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "\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" + "\0x20\0x21\0x22\0x23\0x24\0x25\0x26\0x27" + "\0x28\0x29\0x2A\0x2B\0x2C\0x2D\0x2E\0x2F" + "\0x30\0x31\0x32\0x33\0x34\0x35\0x36\0x37" + "\0x38\0x39\0x3A\0x3B\0x3C\0x3D\0x3E\0x3F" + "\0x40\0x41\0x42\0x43\0x44\0x45\0x46\0x47" + "\0x48\0x49\0x4A\0x4B\0x4C\0x4D\0x4E\0x4F" + "\0x50\0x51\0x52\0x53\0x54\0x55\0x56\0x57" + "\0x58\0x59\0x5A\0x5B\0x5C\0x5D\0x5E\0x5F" + "\0x60\0x61\0x62\0x63\0x64\0x65\0x66\0x67" + "\0x68\0x69\0x6A\0x6B\0x6C\0x6D\0x6E\0x6F" + "\0x70\0x71\0x72\0x73\0x74\0x75\0x76\0x77" + "\0x78\0x79\0x7A\0x7B\0x7C\0x7D\0x7E\0x7F")); + aText2 = aText1; + {for (rtl_UriCharClass eCharClass = eFirstCharClass; + eCharClass <= eLastCharClass; + eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1)) + { + CPPUNIT_ASSERT_MESSAGE( + "failure 1", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 2", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 3", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 4", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 5", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 6", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) + == aText2)); + }} + + aText1 = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "\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" + "\0x20\0x21\0x22\0x23\0x24\0x25\0x26\0x27" + "\0x28\0x29\0x2A\0x2B\0x2C\0x2D\0x2E\0x2F" + "\0x30\0x31\0x32\0x33\0x34\0x35\0x36\0x37" + "\0x38\0x39\0x3A\0x3B\0x3C\0x3D\0x3E\0x3F" + "\0x40\0x41\0x42\0x43\0x44\0x45\0x46\0x47" + "\0x48\0x49\0x4A\0x4B\0x4C\0x4D\0x4E\0x4F" + "\0x50\0x51\0x52\0x53\0x54\0x55\0x56\0x57" + "\0x58\0x59\0x5A\0x5B\0x5C\0x5D\0x5E\0x5F" + "\0x60\0x61\0x62\0x63\0x64\0x65\0x66\0x67" + "\0x68\0x69\0x6A\0x6B\0x6C\0x6D\0x6E\0x6F" + "\0x70\0x71\0x72\0x73\0x74\0x75\0x76\0x77" + "\0x78\0x79\0x7A\0x7B\0x7C\0x7D\0x7E\0x7F" + "\0x80\0x81\0x82\0x83\0x84\0x85\0x86\0x87" + "\0x88\0x89\0x8A\0x8B\0x8C\0x8D\0x8E\0x8F" + "\0x90\0x91\0x92\0x93\0x94\0x95\0x96\0x97" + "\0x98\0x99\0x9A\0x9B\0x9C\0x9D\0x9E\0x9F" + "\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")); + aText2 = aText1; + {for (rtl_UriCharClass eCharClass = eFirstCharClass; + eCharClass <= eLastCharClass; + eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1)) + { + CPPUNIT_ASSERT_MESSAGE( + "failure 7", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 8", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ISO_8859_1), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 9", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_UTF8), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 10", + (rtl::Uri::decode( + rtl::Uri::encode( + aText1, eCharClass, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8), + rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) + == aText2)); + }} + + // Check surrogate handling: + + aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %ED%A0%80 + aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %F0%90%8F%BF + aBuffer.append(static_cast< sal_Unicode >(0xDFFF)); + aBuffer.append(static_cast< sal_Unicode >(0xDFFF)); // %ED%BF%BF + aBuffer.append(static_cast< sal_Unicode >('A')); // A + aText1 = aBuffer.makeStringAndClear(); + aText2 = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "%ED%A0%80" "%F0%90%8F%BF" "%ED%BF%BF" "A")); + CPPUNIT_ASSERT_MESSAGE( + "failure 11", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 12", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 13", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + + aText1 = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "%ed%a0%80" "%f0%90%8f%bf" "%ed%bf%bf" "A")); + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("%ED%A0%80")); + aBuffer.append(static_cast< sal_Unicode >(0xD800)); + aBuffer.append(static_cast< sal_Unicode >(0xDFFF)); + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("%ED%BF%BF")); + aBuffer.append(static_cast< sal_Unicode >('A')); + aText2 = aBuffer.makeStringAndClear(); + CPPUNIT_ASSERT_MESSAGE( + "failure 14", + (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 15", + (rtl::Uri::decode( + aText1, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) + == aText2)); + + // Check UTF-8 handling: + + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%E0%83%BF")); + // \U+00FF encoded with three instead of two bytes + aText2 = aText1; + CPPUNIT_ASSERT_MESSAGE( + "failure 16", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%EF%BF%BF")); + // \U+FFFF is no legal character + aText2 = aText1; + CPPUNIT_ASSERT_MESSAGE( + "failure 17", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + + // Check IURI handling: + + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%30%C3%BF")); + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("%30")); + aBuffer.append(static_cast< sal_Unicode >(0x00FF)); + aText2 = aBuffer.makeStringAndClear(); + CPPUNIT_ASSERT_MESSAGE( + "failure 18", + (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8) + == aText2)); + + // Check modified rtl_UriCharClassUnoParamValue (removed '[' and ']'): + + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[]%5B%5D")); + aText2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%5B%5D%5B%5D")); + CPPUNIT_ASSERT_MESSAGE( + "failure 19", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUnoParamValue, rtl_UriEncodeCheckEscapes, + RTL_TEXTENCODING_ASCII_US) + == aText2)); + + // 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 2396: + { "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/?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/" }, + { "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", "", "http://a/b/c/d;p?q" }, + { "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", 0 }, + { "http:b/c/d;p?q", "g:h", "g:h" }, + { "http:b/c/d;p?q", "g", 0 }, + { "http://a/b/../", "../c", "http://a/b/../../c" }, + { "http://a/b/..", "../c", "http://a/c" }, + { "http://a/./b/", ".././.././../c", "http://a/./../../c" } }; + for (std::size_t i = 0; i < sizeof aRelToAbsTest / sizeof (RelToAbsTest); ++i) + { + rtl::OUString aAbs; + bool bMalformed = false; + try { + aAbs = rtl::Uri::convertRelToAbs( + rtl::OUString::createFromAscii(aRelToAbsTest[i].pBase), + rtl::OUString::createFromAscii(aRelToAbsTest[i].pRel)); + } catch (rtl::MalformedUriException &) { + bMalformed = true; + } + if (bMalformed + ? aRelToAbsTest[i].pAbs != 0 + : (aRelToAbsTest[i].pAbs == 0 + || !aAbs.equalsAscii(aRelToAbsTest[i].pAbs))) + { + printf( + "FAILED convertRelToAbs(%s, %s) -> %s != %s\n", + aRelToAbsTest[i].pBase, aRelToAbsTest[i].pRel, + (bMalformed + ? "<MALFORMED>" + : rtl::OUStringToOString( + aAbs, RTL_TEXTENCODING_UTF8).getStr()), + (aRelToAbsTest[i].pAbs == 0 + ? "<MALFORMED>" : aRelToAbsTest[i].pAbs)); + CPPUNIT_ASSERT(false); + } + } + + // Check encode with unusual text encodings: + + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x045F, 0 }; + aText1 = rtl::OUString(aText1U); + aText2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%20!%A1%FF")); + CPPUNIT_ASSERT_MESSAGE( + "failure 20", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_ISO_8859_5) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 20a", + (rtl::Uri::decode( + aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5) + == aText1)); + } + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; + aText1 = rtl::OUString(aText1U); + sal_Unicode const aText2U[] = { + '%', '2', '0', '!', '%', 'A', '1', 0x0700, '%', 'F', 'F', 0 }; + aText2 = rtl::OUString(aText2U); + CPPUNIT_ASSERT_MESSAGE( + "failure 21", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_ISO_8859_5) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 21a", + (rtl::Uri::decode( + aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5) + == aText1)); + } + { + sal_Unicode const aText1U[] = { ' ', '!', 0x028A, 0xD849, 0xDD13, 0 }; + aText1 = rtl::OUString(aText1U); + aText2 = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("%20!%81%30%B1%33%95%39%C5%37")); + CPPUNIT_ASSERT_MESSAGE( + "failure 22", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_GB_18030) + == aText2)); + CPPUNIT_ASSERT_MESSAGE( + "failure 22a", + (rtl::Uri::decode( + aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030) + == aText1)); + } + + // Check strict mode: + + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; + aText1 = rtl::OUString(aText1U); + aText2 = rtl::OUString(); + CPPUNIT_ASSERT_MESSAGE( + "failure 23", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict, + RTL_TEXTENCODING_ISO_8859_5) + == aText2)); + } + { + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%20%C4%80%FF")); + aText2 = rtl::OUString(); + CPPUNIT_ASSERT_MESSAGE( + "failure 24", + (rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8) + == aText2)); + } + { + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81 ")); + aText2 = rtl::OUString(); + CPPUNIT_ASSERT_MESSAGE( + "failure 25", + (rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) + == aText2)); + } + { + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81%20")); + aText2 = rtl::OUString(); + CPPUNIT_ASSERT_MESSAGE( + "failure 26", + (rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) + == aText2)); + } + { + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81%30%B1%33")); + sal_Unicode const aText2U[] = { 0x028A, 0 }; + aText2 = rtl::OUString(aText2U); + CPPUNIT_ASSERT_MESSAGE( + "failure 27", + (rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) + == aText2)); + } + { + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%810%B13")); + sal_Unicode const aText2U[] = { 0x028A, 0 }; + aText2 = rtl::OUString(aText2U); + CPPUNIT_ASSERT_MESSAGE( + "failure 28", + (rtl::Uri::decode( + aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) + == aText2)); + } + + // Check rtl_UriEncodeStrictKeepEscapes mode: + + { + aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%%ea%c3%aa")); + aText2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%25%EA%C3%AA")); + CPPUNIT_ASSERT_MESSAGE( + "failure 29", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + } + { + sal_Unicode const aText1U[] = { 0x00EA, 0 }; + aText1 = rtl::OUString(aText1U); + aText2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%C3%AA")); + CPPUNIT_ASSERT_MESSAGE( + "failure 30", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, + RTL_TEXTENCODING_UTF8) + == aText2)); + } + { + sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; + aText1 = rtl::OUString(aText1U); + aText2 = rtl::OUString(); + CPPUNIT_ASSERT_MESSAGE( + "failure 23", + (rtl::Uri::encode( + aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, + RTL_TEXTENCODING_ISO_8859_5) + == aText2)); + } +} + +} + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "rtl_testuri"); +NOADDITIONAL; diff --git a/sal/qa/rtl/uuid/makefile.mk b/sal/qa/rtl/uuid/makefile.mk new file mode 100644 index 000000000000..554c2034d0cd --- /dev/null +++ b/sal/qa/rtl/uuid/makefile.mk @@ -0,0 +1,70 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=rtl_uuid + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_Uuid.obj + +SHL1TARGET= rtl_Uuid +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# END ------------------------------------------------------------------ +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/rtl/uuid/rtl_Uuid.cxx b/sal/qa/rtl/uuid/rtl_Uuid.cxx new file mode 100644 index 000000000000..a77c4e8d90de --- /dev/null +++ b/sal/qa/rtl/uuid/rtl_Uuid.cxx @@ -0,0 +1,231 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_Uuid.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#include <math.h> +#include <stdio.h> + +#include <testshl/simpleheader.hxx> +#include <rtl/uuid.h> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> + +#ifdef UNX +#include <unistd.h> +#include <time.h> +#endif + +using namespace rtl; + +/** print a UNI_CODE String. And also print some comments of the string. +*/ +inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) +{ + t_print("#%s #printUString_u# ", msg ); + rtl::OString aString; + aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); + t_print("%s\n", (char *)aString.getStr( ) ); +} + +/************************************************************************ + * For diagnostics( from sal/test/testuuid.cxx ) + ************************************************************************/ + +void printUuid( sal_uInt8 *pNode ) +{ + for( sal_Int32 i1 = 0 ; i1 < 4 ; i1++ ) + { + for( sal_Int32 i2 = 0 ; i2 < 4 ; i2++ ) + { + printf( "%02x" , pNode[i1*4 +i2] ); + } + if( i1 == 3 ) + break; + printf( "-" ); + } + + printf( "\n# " ); +} + +namespace rtl_Uuid +{ +class createUuid : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + +#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], 0, sal_False ); + } + sal_Bool bRes = sal_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 = sal_False; + break; + } + } + if ( bRes == sal_False ) + break; + } + CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True ); + } + /* + 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 + +namespace ThreadHelper +{ + void thread_sleep(sal_Int32 _nSec) + { +#ifdef WNT //Windows + Sleep(_nSec * 10 ); +#endif +#if ( defined UNX ) || ( defined OS2 ) //Unix + sleep( _nSec ); +#endif + } +} + +class createNamedUuid : public CppUnit::TestFixture +{ +public: + // initialise your test code values here. + void setUp() + { + } + + void tearDown() + { + } + + 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 = 0; + 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_NAMED_REGISTRATION(rtl_Uuid::createUuid, "rtl_Uuid"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Uuid::createNamedUuid, "rtl_Uuid"); +} // namespace rtl_Uuid + +// ----------------------------------------------------------------------------- + +// 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. +NOADDITIONAL; + + diff --git a/sal/qa/rtl_strings/export.exp b/sal/qa/rtl_strings/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sal/qa/rtl_strings/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sal/qa/rtl_strings/makefile.mk b/sal/qa/rtl_strings/makefile.mk new file mode 100644 index 000000000000..166ef568debc --- /dev/null +++ b/sal/qa/rtl_strings/makefile.mk @@ -0,0 +1,157 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.11 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=sal +TARGET=qa_rtl_strings +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:FileBase by codegen.pl +SHL1OBJS= \ + $(SLO)$/rtl_String_Utils.obj \ + $(SLO)$/rtl_OString.obj + +SHL1TARGET= rtl_OString +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# auto generated Target:FileBase +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:FileBase by codegen.pl +SHL2OBJS= \ + $(SLO)$/rtl_String_Utils.obj \ + $(SLO)$/rtl_OUString.obj + +SHL2TARGET= rtl_OUString +SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL2IMPLIB= i$(SHL2TARGET) +# SHL2DEF= $(MISC)$/$(SHL2TARGET).def + +DEF2NAME =$(SHL2TARGET) +# DEF2EXPORTFILE= export.exp +SHL2VERSIONMAP = $(PRJ)$/qa$/export.map + +# auto generated Target:FileBase +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:FileBase by codegen.pl +SHL3OBJS= \ + $(SLO)$/rtl_String_Utils.obj \ + $(SLO)$/rtl_OUStringBuffer.obj + +SHL3TARGET= rtl_OUStringBuffer +SHL3STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL3IMPLIB= i$(SHL3TARGET) +# SHL3DEF= $(MISC)$/$(SHL3TARGET).def + +DEF3NAME =$(SHL3TARGET) +# DEF3EXPORTFILE= export.exp +SHL3VERSIONMAP = $(PRJ)$/qa$/export.map + +# auto generated Target:FileBase +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +SHL4OBJS= \ + $(SLO)$/rtl_old_teststrbuf.obj + +SHL4TARGET= rtl_old_teststrbuf +SHL4STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL4IMPLIB= i$(SHL4TARGET) +DEF4NAME =$(SHL4TARGET) +SHL4VERSIONMAP = $(PRJ)$/qa$/export.map + +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +SHL5OBJS= \ + $(SLO)$/rtl_old_testowstring.obj + +SHL5TARGET= rtl_old_testowstring +SHL5STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL5IMPLIB= i$(SHL5TARGET) +DEF5NAME =$(SHL5TARGET) +SHL5VERSIONMAP = $(PRJ)$/qa$/export.map + +# END ------------------------------------------------------------------ + +# BEGIN ---------------------------------------------------------------- +SHL6OBJS= \ + $(SLO)$/rtl_old_testostring.obj + +SHL6TARGET= rtl_old_testostring +SHL6STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL6IMPLIB= i$(SHL6TARGET) +DEF6NAME =$(SHL6TARGET) +SHL6VERSIONMAP = $(PRJ)$/qa$/export.map + +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=\ + $(SHL1OBJS) \ + $(SHL2OBJS) \ + $(SHL3OBJS) \ + $(SHL4OBJS) \ + $(SHL5OBJS) \ + $(SHL6OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + + diff --git a/sal/qa/rtl_strings/readme.txt b/sal/qa/rtl_strings/readme.txt new file mode 100644 index 000000000000..388c98751e8d --- /dev/null +++ b/sal/qa/rtl_strings/readme.txt @@ -0,0 +1,20 @@ +This is the old test implemantation of rtl::XString. +If you want to write new or better tests: +Identify the test function in the source and remark it. + +The best way to remark old tests, go to the end of the source code and remark +only the test_rtl_<X>String_<function>(hRtlTestResult); so the test will not +executed any longer. + +There are already some new tests for rtl::XString, take a look into the +directory sal/qa/rtl/ostring or sal/qa/rtl/oustring, where are some +replacements added. + + +Any other Questions? + +Do not hesitate to contact me at 'lla<at>openoffice.org'. + +best regards, +Lars + diff --git a/sal/qa/rtl_strings/rtl_OString.cxx b/sal/qa/rtl_strings/rtl_OString.cxx new file mode 100644 index 000000000000..d42f7e14dbc1 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_OString.cxx @@ -0,0 +1,3608 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OString.cxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <string.h> + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +// #ifndef _RTL_TRES_H_ +// #include <rtl/tres.h> +// #endif + +#include <testshl/tresstatewrapper.hxx> + +#ifndef _RTL_STRING_HXX_ + #include <rtl/string.hxx> +#endif + +#ifndef _RTL_STRING_CONST_H_ + #include <rtl_String_Const.h> +#endif + +#ifndef _RTL_STRING_UTILS_HXX_ + #include <rtl_String_Utils.hxx> +#endif +#include <rtl/ustring.h> + +using namespace rtl; + +//------------------------------------------------------------------------ +// test classes +//------------------------------------------------------------------------ +const int MAXBUFLENGTH = 255; +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +static void unused() +{ + test_ini_uString(); + (void)inputChar; + (void)input1StrDefault; + (void)input1StrNormal; + (void)input1StrLastDefault; + (void)input1StrLastNormal; + unused(); +} + +//------------------------------------------------------------------------ +// testing constructors +//------------------------------------------------------------------------ +static sal_Bool test_rtl_OString_ctor_001( hTestResult hRtlTestResult ) +{ + ::rtl::OString aStr; + rtl_String* pData = aStr.pData; + + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + pData->length == 0 && + ! *pData->buffer, + "New OString containing no characters", + "ctor_001" + ) + ); +} + +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OString_ctor_002( + hTestResult hRtlTestResult ) +{ + ::rtl::OString aStr(kTestStr1); + rtl_String* pData = aStr.pData; + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + pData->refCount == 1 && + pData->length == kTestStr1Len && + cmpstr( (const sal_Char*)pData->buffer, kTestStr1, kTestStr1Len ), + "New OString from a character buffer array", + "ctor_002" + ) + ); +} +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OString_ctor_003( + hTestResult hRtlTestResult ) +{ + ::rtl::OString aStr(kTestStr2, kTestStr1Len); + rtl_String* pData = aStr.pData; + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + pData->refCount == 1 && + pData->length == kTestStr1Len && + cmpstr( (const sal_Char*)pData->buffer, kTestStr2, kTestStr1Len ), + "New OString from the first n chars of ascii string", + "ctor_003" + ) + ); +} + +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OString_ctor_004( + hTestResult hRtlTestResult) +{ + ::rtl::OString aStr1(kTestStr1); + ::rtl::OString aStr2(aStr1); + rtl_String* pData1 = aStr1.pData; + rtl_String* pData2 = aStr2.pData; + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + pData1->refCount == pData2->refCount && + pData1->length == kTestStr1Len && + pData1->buffer == pData2->buffer, + "New OString from an OString", + "ctor_004" + ) + ); +} +//------------------------------------------------------------------------ + +static sal_Bool test_rtl_OString_ctor_005( hTestResult hRtlTestResult ) +{ + rtl_String *aStr1 = NULL; + + rtl_string_newFromStr( &aStr1, kTestStr1 ); + + if ( aStr1 != NULL ) + { + ::rtl::OString aStr2(aStr1); + rtl_String* pData2 = aStr2.pData; + + sal_Bool bOK = c_rtl_tres_state + ( + hRtlTestResult, + aStr1->refCount == pData2->refCount && + pData2->length == kTestStr1Len && + aStr1->buffer == pData2->buffer, + "new OString from a RTL String", + "ctor_005" + ); + + rtl_string_release( aStr1 ); + aStr1 = NULL; + return ( bOK ); + } + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + sal_False, + "copying an ascii string to a RTL String!", + "ctor_005" + ) + ); +} + +//------------------------------------------------------------------------ + +static sal_Bool test_rtl_OString_ctor_006( hTestResult hRtlTestResult ) +{ + + sal_Unicode aStr1[kTestStr1Len+1]; + + if ( AStringToUStringNCopy( aStr1, kTestStr1, kTestStr1Len ) ) + { + if ( AStringToUStringNCompare( aStr1, kTestStr1, kTestStr1Len ) == 0 ) + { + // const sal_Char *kTCMessage[2] = { "", "array." }; + + ::rtl::OString aStr2 + ( + aStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOUStringToOString + ); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aStr2 == kTestStr1, + "new OString from a unicode character buffer", + "ctor_006" + ) + ); + } /// end if AStringToUStringNCompare + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + sal_False, + "compare ascii string with unicode string!", + "ctor_006" + ) + ); + } /// end if AStringToUStringNCopy + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + sal_False, + "copy ascii string to unicode string!", + "ctor_006" + ) + ); +} +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_ctors( + hTestResult hRtlTestResult ) +{ + + c_rtl_tres_state_start(hRtlTestResult, "ctor"); + sal_Bool bTSState = test_rtl_OString_ctor_001( hRtlTestResult ); + + bTSState &= test_rtl_OString_ctor_002( hRtlTestResult); + bTSState &= test_rtl_OString_ctor_003( hRtlTestResult); + bTSState &= test_rtl_OString_ctor_004( hRtlTestResult); + bTSState &= test_rtl_OString_ctor_005( hRtlTestResult); + bTSState &= test_rtl_OString_ctor_006( hRtlTestResult); + + c_rtl_tres_state_end(hRtlTestResult, "ctor"); + +// return( bTSState ); +} + + + +//------------------------------------------------------------------------ +// testing the method getLength +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_getLength( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "getLength"); + +typedef struct TestCase +{ + sal_Char* comments; + sal_Int32 expVal; + OString* input; + ~TestCase() { delete input;} +} TestCase; + +TestCase arrTestCase[]={ + + {"length of ascii string", kTestStr1Len, new OString(kTestStr1)}, + {"length of ascci string of size 1", 1, new OString("1")}, + {"length of empty string (default constructor)", 0, new OString()}, + {"length of empty string (empty ascii string arg)",0,new OString("")}, + {"length of empty string (string arg = '\\0')",0,new OString("\0")} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 length = arrTestCase[i].input->getLength(); + sal_Bool lastRes = (length == arrTestCase[i].expVal); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "getLength", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end(hRtlTestResult, "getLength"); +// return ( res ); +} + + + +//------------------------------------------------------------------------ +// testing the method equals( const OString & aStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_equals( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "equals"); + + typedef struct TestCase +{ + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} +} TestCase; + +TestCase arrTestCase[]={ + + {"same size", sal_True, new OString(kTestStr1),new OString(kTestStr1)}, + {"different size", sal_False, new OString(kTestStr1), + new OString(kTestStr2)}, + {"same size, no case match", sal_False, new OString(kTestStr1), + new OString(kTestStr3)}, + {"two empty strings(def. constructor)", sal_True, new OString(), + new OString()}, + {"empty(def.constructor) and non empty", sal_False, new OString(), + new OString(kTestStr2)}, + {"non empty and empty(def. constructor)", sal_False, + new OString(kTestStr1),new OString()}, + {"two empty strings(string arg = '\\0')", sal_True, + new OString(""),new OString("")}, + {"empty(string arg = '\\0') and non empty", sal_False, + new OString(""),new OString(kTestStr2)}, + {"non empty and empty(string arg = '\\0')", sal_False, + new OString(kTestStr1),new OString("")} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + ( arrTestCase[i].input1->equals(*(arrTestCase[i].input2)) == + arrTestCase[i].expVal ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equals", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end(hRtlTestResult, "equals"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the method equalsIgnoreAsciiCase( const OString & aStr ) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_equalsIgnoreAsciiCase( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "equalsIgnoreAsciiCase"); + typedef struct TestCase +{ + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} +} TestCase; + +TestCase arrTestCase[]={ + {"same strings but different cases",sal_True,new OString(kTestStr4), + new OString(kTestStr5)}, + {"same strings",sal_True,new OString(kTestStr4), + new OString(kTestStr4)}, + {"with equal beginning",sal_False,new OString(kTestStr2), + new OString(kTestStr4)}, + {"empty(def.constructor) and non empty",sal_False,new OString(), + new OString(kTestStr5)}, + {"non empty and empty(def.constructor)",sal_False, + new OString(kTestStr4), new OString()}, + {"two empty strings(def.constructor)",sal_True,new OString(), + new OString()}, + {"different strings with equal length",sal_False, + new OString(kTestStr10), new OString(kTestStr11)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + (arrTestCase[i].input1->equalsIgnoreAsciiCase(*arrTestCase[i].input2) + == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equalsIgnoreAsciiCase", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end(hRtlTestResult, "equalsIgnoreAsciiCase"); + +// return (res); +} + +static sal_Bool SAL_CALL test_rtl_OString_compareTo_001( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase +{ + sal_Char* comments; + sal_Int32 expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} +} TestCase; + +TestCase arrTestCase[]={ + + {"simple compare, str1 to str5",-1,new OString(kTestStr1), + new OString(kTestStr5)}, + {"simple compare, str2 to str5",-1,new OString(kTestStr2), + new OString(kTestStr5)}, + {"simple compare, str1 to str9",-1,new OString(kTestStr1), + new OString(kTestStr9)}, + {"simple compare, str1 to str2",-1,new OString(kTestStr1), + new OString(kTestStr2)}, + {"simple compare, str4 to str5",-1,new OString(kTestStr4), + new OString(kTestStr5)}, + {"simple compare, str1 to str3",-1,new OString(kTestStr1), + new OString(kTestStr3)}, + {"simple compare, str5 to str1",+1,new OString(kTestStr5), + new OString(kTestStr1)}, + {"simple compare, str2 to str1",+1,new OString(kTestStr2), + new OString(kTestStr1)}, + {"simple compare, str9 to str5",+1,new OString(kTestStr9), + new OString(kTestStr5)}, + {"simple compare, str5 to str4",+1,new OString(kTestStr5), + new OString(kTestStr4)}, + {"simple compare, str1 to str1",0,new OString(kTestStr1), + new OString(kTestStr1)}, + {"simple compare, nullString to nullString",0,new OString(), + new OString()}, + {"simple compare, nullString to str2",-1,new OString(), + new OString(kTestStr2)}, + {"simple compare, str1 to nullString",+1,new OString(kTestStr1), + new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 cmpRes = + arrTestCase[i].input1->compareTo(*arrTestCase[i].input2); + cmpRes = ( cmpRes == 0 ) ? 0 : ( cmpRes > 0 ) ? +1 : -1 ; + sal_Bool lastRes = ( cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "compareTo(const OString&)", i ) + ); + + res &= lastRes; + } + + return (res); +} + + +//------------------------------------------------------------------------ +// testing the method compareTo( const OString & rObj, sal_Int32 length ) +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OString_compareTo_002( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + sal_Int32 maxLength; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + {"compare with maxlength, str1 to str9, 16",-1,16, + new OString(kTestStr1), new OString(kTestStr9)}, + {"compare with maxlength, str2 to str9, 32",-1,32, + new OString(kTestStr2), new OString(kTestStr9)}, + {"compare with maxlength, str9 to str4, 16",+1,16, + new OString(kTestStr9), new OString(kTestStr4)}, + {"compare with maxlength, str9 to str22, 32",+1,32, + new OString(kTestStr9), new OString(kTestStr22)}, + {"compare with maxlength, str9 to str5, 16",0,16, + new OString(kTestStr9), new OString(kTestStr5)}, + {"compare with maxlength, str9 to str9, 32",0,32, + new OString(kTestStr9), new OString(kTestStr9)}, + {"compare with maxlength, str1 to str2, 32",-1,32, + new OString(kTestStr1), new OString(kTestStr2)}, + {"compare with maxlength, str1 to str2, 32",-1,32, + new OString(kTestStr1), new OString(kTestStr2)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 cmpRes = + arrTestCase[i].input1->compareTo(*arrTestCase[i].input2, + arrTestCase[i].maxLength); + cmpRes = (cmpRes == 0) ? 0 : (cmpRes > 0) ? +1 : -1 ; + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "compareTo(const OString&, sal_Int32)", i ) + ); + + res &= lastRes; + } + + return (res); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_compareTo( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "compareTo"); + sal_Bool res = test_rtl_OString_compareTo_001(hRtlTestResult); + res &= test_rtl_OString_compareTo_002(hRtlTestResult); + c_rtl_tres_state_end(hRtlTestResult, "compareTo"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the operator == ( const OString& rStr1, const OString& rStr2 ) +// testing the operator == ( const OString& rStr1, const sal_Char *rStr2 ) +// testing the operator == ( const sal_Char *rStr1, const OString& rStr2 ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_cmp( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "op_cmp"); + const sal_Int16 NCASES = 7; + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + const sal_Char *arrOStr[NCASES][2] = + { + {kTestStr1, kTestStr1}, + {kTestStr1, kTestStr3}, + {kTestStr1, kTestStr2}, + {0, 0}, + {0, kTestStr2}, + {kTestStr1, 0}, + {"", ""} + }; + + sal_Bool arrExpVal[NCASES] = + { + sal_True, + sal_False, + sal_False, + sal_True, + sal_False, + sal_False, + sal_True + }; + + sal_Char *arrComments[NCASES] = + { + "'Sun Microsystems'=='Sun Microsystems'", + "!('Sun Microsystems'=='Sun microsystems')", + "!('Sun Microsystems'=='Sun Microsystems Java Technology')", + "two empty strings(def.constructor)", + "!(empty string=='Sun Microsystems Java Technology')", + "!('Sun Microsystems Java Technology'==empty string)", + "''==''" + }; + + sal_Bool res = sal_True; + sal_Int32 i; + + for(i = 0; i < NCASES; i++) + { + OString *str1, *str2; + str1 = (arrOStr[i][0]) ? new OString(arrOStr[i][0]) : new OString() ; + str2 = (arrOStr[i][1]) ? new OString(arrOStr[i][1]) : new OString() ; + + sal_Bool cmpRes = (*str1 == *str2); + sal_Bool lastRes = (cmpRes == arrExpVal[i]); + res &= lastRes; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrComments[i], + createName( pMeth, "operator ==(OString&, OString&)", i ) + ); + + cmpRes = (*str1 == arrOStr[i][1]); + lastRes = (cmpRes == arrExpVal[i]); + res &= lastRes; + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrComments[i], + createName( pMeth, "operator ==(OString&, sal_Char *)", i ) + ); + + cmpRes = (arrOStr[i][0] == *str2); + lastRes = (cmpRes == arrExpVal[i]); + res &= lastRes; + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrComments[i], + createName( pMeth, "operator ==(sal_Char *, OString&)", i ) + ); + + delete str2; + delete str1; + } + + c_rtl_tres_state_end(hRtlTestResult, "op_cmp"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator != (const OString& rStr1, const OString& rStr2) +// testing the operator != (const OString& rStr1, const sal_Char *rStr2) +// testing the operator != (const sal_Char *rStr1, const OString& rStr2) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_neq( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "op_neq"); + const sal_Int16 NCASES = 6; + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Char *arrOStr[NCASES][2] = + { + {kTestStr1, kTestStr3}, + {kTestStr1, kTestStr2}, + {kTestStr1, kTestStr1}, + {0, kTestStr2}, + {kTestStr1, 0}, + {0, 0} + }; + + sal_Bool arrExpVal[NCASES] = + { + sal_True, + sal_True, + sal_False, + sal_True, + sal_True, + sal_False + }; + + sal_Char *arrComments[NCASES] = + { + "'Sun Microsystems'!='Sun microsystems'", + "'Sun Microsystems'!='Sun Microsystems Java Technology'", + "!('Sun Microsystems'!='Sun Microsystems')", + "empty string!='Sun Microsystems Java Technology'", + "'Sun Microsystems Java Technology'!=empty string", "!(''!='')" + }; + + sal_Bool res = sal_True; + sal_Int32 i; + + for(i = 0; i < NCASES; i++) + { + OString *str1, *str2; + str1 = (arrOStr[i][0]) ? new OString(arrOStr[i][0]) : new OString() ; + str2 = (arrOStr[i][1]) ? new OString(arrOStr[i][1]) : new OString() ; + + sal_Bool cmpRes = (*str1 != *str2); + sal_Bool lastRes = (cmpRes == arrExpVal[i]); + res &= lastRes; + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrComments[i], + createName( pMeth, "operator !=(OString&, OString&)", i ) + ); + + cmpRes = (*str1 != arrOStr[i][1]); + lastRes = (cmpRes == arrExpVal[i]); + res &= lastRes; + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrComments[i], + createName( pMeth, "operator !=(OString&, sal_Char *)", i ) + ); + + cmpRes = (arrOStr[i][0] != *str2); + lastRes = (cmpRes == arrExpVal[i]); + res &= lastRes; + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrComments[i], + createName( pMeth, "operator !=(sal_Char *, OString&)", i ) + ); + + delete str2; + delete str1; + } + + c_rtl_tres_state_end(hRtlTestResult, "op_neq"); +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the operator > (const OString& rStr1, const OString& rStr2) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_g( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_g"); + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + { "'Sun microsystems'>'Sun Microsystems'",sal_True, + new OString(kTestStr3), new OString(kTestStr1)}, + {"!('Sun Microsystems'>'Sun microsystems')",sal_False, + new OString(kTestStr1), new OString(kTestStr3)}, + {"'Sun Microsystems Java Technology'>'Sun Microsystems'",sal_True, + new OString(kTestStr2), new OString(kTestStr1)}, + {"!('Sun Microsystems'>'Sun Microsystems Java Technology')",sal_False, + new OString(kTestStr1), new OString(kTestStr2)}, + {"!('Sun Microsystems'>'Sun Microsystems'",sal_False, + new OString(kTestStr1), new OString(kTestStr1)}, + {"'Sun Microsystems'>''",sal_True,new OString(kTestStr1), + new OString()}, + {"!(''>'Sun Microsystems')",sal_False,new OString(), + new OString(kTestStr1)}, + {"!(''>'')",sal_False,new OString(), new OString()} +}; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool cmpRes = (*arrTestCase[i].input1 > *arrTestCase[i].input2); + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator >", i ) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "op_g"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator < (const OString& rStr1, const OString& rStr2) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_l( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_l"); + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + {"!('Sun microsystems'<'Sun Microsystems')",sal_False, + new OString(kTestStr3), new OString(kTestStr1)}, + {"'Sun Microsystems'<'Sun microsystems'",sal_True, + new OString(kTestStr1), new OString(kTestStr3)}, + {"'Sun Microsystems'<'Sun Microsystems Java Technology'",sal_True, + new OString(kTestStr1), new OString(kTestStr2)}, + {"!('Sun Microsystems Java Technology'<'Sun Microsystems')",sal_False, + new OString(kTestStr2), new OString(kTestStr1)}, + {"!('Sun Microsystems'<'Sun Microsystems'", sal_False, + new OString(kTestStr1), new OString(kTestStr1)}, + {"'Sun Microsystems'<''",sal_False,new OString(kTestStr1), + new OString()}, + {"''<'Sun Microsystems Java Technology'",sal_True,new OString(), + new OString(kTestStr2)}, + {"!(''<'')",sal_False,new OString(), new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool cmpRes = (*arrTestCase[i].input1 < *arrTestCase[i].input2); + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator <", i ) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "op_l"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator >= (const OString& rStr1, const OString& rStr2) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_ge( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_ge"); + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + {"'Sun microsystems'>='Sun Microsystems'",sal_True, + new OString(kTestStr3), new OString(kTestStr1)}, + {"!('Sun Microsystems'>='Sun microsystems')",sal_False, + new OString(kTestStr1), new OString(kTestStr3)}, + {"!('Sun Microsystems'>='Sun Microsystems Java Technology')",sal_False, + new OString(kTestStr1), new OString(kTestStr2)}, + {"'Sun Microsystems Java Technology'>='Sun Microsystems'",sal_True, + new OString(kTestStr2), new OString(kTestStr1)}, + {"'Sun Microsystems'>='Sun Microsystems'", sal_True, + new OString(kTestStr1), new OString(kTestStr1)}, + {"'Sun Microsystems'>=''",sal_True,new OString(kTestStr1), + new OString()}, + { "''>='Sun microsystems'",sal_False,new OString(), + new OString(kTestStr3)}, + {"''>=''",sal_True,new OString(), new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool cmpRes = (*arrTestCase[i].input1 >= *arrTestCase[i].input2); + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator >=", i ) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "op_ge"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator <= (const OString& rStr1, const OString& rStr2) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_le( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_le"); + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + {"!('Sun microsystems'<='Sun Microsystems')",sal_False, + new OString(kTestStr3), new OString(kTestStr1)}, + {"'Sun Microsystems'<='Sun microsystems'",sal_True, + new OString(kTestStr1), new OString(kTestStr3)}, + {"'Sun Microsystems'<='Sun Microsystems Java Technology'",sal_True, + new OString(kTestStr1), + new OString(kTestStr2)}, + {"!('Sun Microsystems Java Technology'<='Sun Microsystems')",sal_False, + new OString(kTestStr2), + new OString(kTestStr1)}, + {"!('Sun Microsystems'<='Sun Microsystems'", sal_True, + new OString(kTestStr1), new OString(kTestStr1)}, + {"'Sun Microsystems'<=''",sal_False,new OString(kTestStr1), + new OString()}, + {"''<='Sun Microsystems Java Technology'",sal_True,new OString(), + new OString(kTestStr2)}, + {"!(''<='')",sal_True,new OString(), new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool cmpRes = (*arrTestCase[i].input1 <= *arrTestCase[i].input2); + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator <=", i ) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "op_le"); +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the operator = +//------------------------------------------------------------------------ +static sal_Bool test_rtl_OString_op_eq_001( hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + {"'' = str1, str1 == str2",sal_True,new OString(kTestStr1), + new OString()}, + {"str1 = str2, str1 == str2",sal_True,new OString(kTestStr1), + new OString(kTestStr6)}, + {"str2 = '', str1 == str2",sal_True,new OString(), + new OString(kTestStr2)}, + {"'' = '', str1 == str2",sal_True,new OString(), + new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + *(arrTestCase[i].input1) = *(arrTestCase[i].input2); + + sal_Bool cmpRes = + (*(arrTestCase[i].input1) == *(arrTestCase[i].input2)); + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator =", i ) + ); + + res &= lastRes; + } + + return ( res ); +} + +static sal_Bool test_rtl_OString_op_eq_002( + hTestResult hRtlTestResult ) +{ + ::rtl::OString aStr; + aStr = OString(kTestStr1); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aStr == kTestStr1, + "str = OString(\"%s\"), str == \"%s\"", + "operator =" + ) + ); +} + +static sal_Bool test_rtl_OString_op_eq_003( + hTestResult hRtlTestResult ) +{ + sal_Bool bTCState = false; + + ::rtl::OString aStr1(kTestStr1); + ::rtl::OString aStr2; + ::rtl::OString aStr3; + + aStr3 = aStr2 = aStr1; + + bTCState = ( aStr1 == aStr2 ) + && ( aStr1 == aStr3 ) + && ( aStr2 == aStr3 ); + + c_rtl_tres_state + ( + hRtlTestResult, + bTCState, + "str3=str2=str1,(str1 == str2)&&(str1 == str3)&&(str2 == str3)", + "operator =" + ); + + return bTCState; +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_eq( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "op_eq"); + sal_Bool res = test_rtl_OString_op_eq_001( hRtlTestResult ); + res &= test_rtl_OString_op_eq_002( hRtlTestResult ); + res &= test_rtl_OString_op_eq_003( hRtlTestResult ); + c_rtl_tres_state_end(hRtlTestResult, "op_eq"); + +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator + +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_plus( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_plus"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"str1 = str7 + str8",new OString(kTestStr1), + new OString(kTestStr7), new OString(kTestStr8)}, + {"str1 = str1 + '' ",new OString(kTestStr1), + new OString(kTestStr1), new OString("")}, + {"str1 = '' + str1", new OString(kTestStr1), + new OString(""), new OString(kTestStr1)}, + {" '' = '' + '' ", new OString(""),new OString(""), + new OString("")}, + {"str1 = str1 + def.constr", new OString(kTestStr1), + new OString(kTestStr1), new OString()}, + {" str1 = def.constr + str1 ",new OString(kTestStr1), + new OString(), new OString(kTestStr1)}, + {" def.constr= def.constr + def.constr", new OString(), + new OString(), new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OString str = (*arrTestCase[i].input1) + (*arrTestCase[i].input2); + sal_Bool lastRes = (str == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator +", i ) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "op_plus"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator += +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_peq( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_peq"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"str1 == (str7 += str8)",new OString(kTestStr1), + new OString(kTestStr7), new OString(kTestStr8)}, + {"str1 == (str1 += '')",new OString(kTestStr1), + new OString(kTestStr1), new OString("")}, + {"str1 == ('' += str1)", new OString(kTestStr1), + new OString(""), new OString(kTestStr1)}, + {" '' == ('' += '')", new OString(""), + new OString(""), new OString("")}, + {"str1 == (str1 += def.constr)", new OString(kTestStr1), + new OString(kTestStr1), new OString()}, + {" str1 == (def.constr += str1)",new OString(kTestStr1), + new OString(), new OString(kTestStr1)}, + {" def.constr== (def.constr += def.constr)", + new OString(),new OString(), new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { OString str; + str += (*arrTestCase[i].input1); str += (*arrTestCase[i].input2); + sal_Bool lastRes = (str == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "operator +", i ) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "op_peq"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator const sal_Char * (cscs for short) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_op_cscs( + hTestResult hRtlTestResult ) +{ +sal_Char methName[MAXBUFLENGTH]; +sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "op_cscs"); +typedef struct TestCase + { + sal_Char* comments; + const sal_Char* expVal; + sal_Int32 cmpLen; + OString* input1; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[] = + { + {"test normal string",kTestStr1,kTestStr1Len,new OString(kTestStr1)}, + {"test empty string","",1,new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + const sal_Char* pstr = (*arrTestCase[i].input1); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + cmpstr((sal_Char*)pstr,(sal_Char*)arrTestCase[i].expVal, + arrTestCase[i].cmpLen), + arrTestCase[i].comments, + createName( pMeth, "const sal_Char*", i ) + ); + } + c_rtl_tres_state_end(hRtlTestResult, "op_cscs"); +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the method getStr() +//------------------------------------------------------------------------ + + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_getStr( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "getStr"); + typedef struct TestCase + { + sal_Char* comments; + const sal_Char* expVal; + sal_Int32 cmpLen; + OString* input1; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[] = + { + {"test normal string",kTestStr1,kTestStr1Len,new OString(kTestStr1)}, + {"test empty string","",0,new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + const sal_Char* pstr = arrTestCase[i].input1->getStr(); + res &= c_rtl_tres_state + ( + hRtlTestResult, + cmpstr(pstr, arrTestCase[i].expVal, + arrTestCase[i].cmpLen), + arrTestCase[i].comments, + createName( pMeth, "getStr", i ) + ); + } + c_rtl_tres_state_end(hRtlTestResult, "getStr"); +// return ( res ); +} + + + +//------------------------------------------------------------------------ +// testing the method copy( sal_Int32 beginIndex ) +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OString_copy_001( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + const sal_Char* srcStr; + const sal_Char* arrExpStr; + // string for comparing with result + sal_Int32 beginIndex; + // beginIndex for the method copy + sal_Int32 lengthForCmp; + // number of symbols for comparing + // (if value is equal to 0 then pointers to buffers must be equal) + sal_Int32 expLength; + //expected length of the result string + } TestCase; + + TestCase arrTestCase[] = + { + {"beginIndex == 0 ( whole string )", kTestStr2,kTestStr2, + 0, kTestStr2Len, kTestStr2Len}, + {"beginIndex == strlen-2 ( last two char )", kTestStr2,"gy", + kTestStr2Len-2, 2, 2}, + {"beginIndex == strlen-1( last char )", kTestStr2, "y", + kTestStr2Len-1, 1, 1} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i <(sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OString src(arrTestCase[i].srcStr); + OString dst; + // rtl_String* pDataSrc = src.pData; + + dst = src.copy(arrTestCase[i].beginIndex); + + // rtl_String* pDataDst = dst.pData; + + sal_Bool lastRes; + + lastRes= (dst== arrTestCase[i].arrExpStr); + + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, + "copy_001(beginIndex)(check buffer and length)", i ) + ); + + res &= lastRes; + + } + + return (res); +} + + +//------------------------------------------------------------------------ +// testing the method copy( sal_Int32 beginIndex, sal_Int32 count ) +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OString_copy_002( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + const sal_Char* arrExpStr; + sal_Int32 beginIndex; + sal_Int32 count; + sal_Int32 expLen; + + } TestCase; + + TestCase arrTestCase[] ={ + + {"copy substring", kTestStr6, kTestStr11Len, kTestStr2Len - kTestStr11Len,kTestStr6Len}, + /* LLA: it is a bug, beginIndex + count > kTestStr2.getLength() */ + /* {"copy normal substring with incorrect count",kTestStr6, kTestStr11Len, 31, 15}, */ + {"copy whole string", kTestStr2, 0, kTestStr2Len, kTestStr2Len}, + /* {"copy whole string with incorrect count larger than len and index 0", kTestStr2, 0, 40, 32}, */ + /* LLA: bug beginIndex + count > kTestStr2 {"copy last character", "y",kTestStr2Len - 1, 31,1}, */ + {"copy last character", "y",kTestStr2Len - 1, 1,1}, + /* LLA: bug, beginIndex > kTestStr2 {"beginindex larger than len","",60, 0,0}, */ + {"beginindex exact as large as it's length","",kTestStr2Len, 0,0} + /* LLA: bug, negative count is not allowed. {"count is nagative int","",3, -1,0} */ + }; + sal_Bool res = sal_True; + + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) { + OString src(kTestStr2); + OString dst; + dst = src.copy(arrTestCase[i].beginIndex, arrTestCase[i].count); + // rtl_String* pDataSrc = src.pData; + // rtl_String* pDataDst = dst.pData; + + sal_Bool lastRes=sal_True; + // checks buffer and length + //t_print("this is copy__002 #%d\n", i); + //t_print("dst buffer =%s\n", pDataDst->buffer); + //t_print("expStr =%s\n", arrTestCase[i].arrExpStr); + //t_print("dst length =%d\n", pDataDst->length); + //t_print("count =%d\n", arrTestCase[i].count); + //t_print("expLen =%d\n", arrTestCase[i].expLen); + + lastRes = (dst.equals(arrTestCase[i].arrExpStr)) ? sal_True : sal_False; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, + "copy_002(beginIndex,count)(check buffer and length)", i) + ); + res &= lastRes; + + + } + + return (res); +} + + +static sal_Bool SAL_CALL test_rtl_OString_copy_003( + hTestResult hRtlTestResult ) +{ + sal_Bool res = sal_True; + char comment[] = "copy whole short string to long string"; + + OString src(kTestStr1); + // rtl_String* pDataSrc = src.pData; + OString dst(kTestStr2); + + dst = src.copy(0); + // rtl_String* pDataDst = dst.pData; + //check buffer and length + sal_Bool lastRes =(dst==src); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + comment, + "copy_003(beginIndex)(check buffer and length)" + ); + res &= lastRes; + + return (res); +} + + +static sal_Bool SAL_CALL test_rtl_OString_copy_004( + hTestResult hRtlTestResult ) +{ + sal_Bool res = sal_True; + sal_Char comment[] = "copy whole long string to short string"; + + OString src(kTestStr2); + // rtl_String* pDataSrc = src.pData; + OString dst(kTestStr1); + + dst = src.copy(0); + // rtl_String* pDataDst = dst.pData; + //check buffer and length + sal_Bool lastRes =(dst==src); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + comment, + "copy_004(beginIndex)(check buffer and length)" + ); + + res &= lastRes; + return (res); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_copy( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "copy"); + sal_Bool res = test_rtl_OString_copy_001(hRtlTestResult); + res &= test_rtl_OString_copy_002(hRtlTestResult); + res &= test_rtl_OString_copy_003(hRtlTestResult); + res &= test_rtl_OString_copy_004(hRtlTestResult); + c_rtl_tres_state_end(hRtlTestResult, "copy"); + +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method concat( const OString & aStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_concat( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + c_rtl_tres_state_start(hRtlTestResult, "concat"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input1; + OString* input2; + ~TestCase() { delete input1;delete input2; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"concatenates two strings",new OString(kTestStr1), + new OString(kTestStr7), + new OString(kTestStr8)}, + {"concatenates empty string",new OString(kTestStr1), + new OString(kTestStr1), + new OString("")}, + {"concatenates to empty string",new OString(kTestStr1), + new OString(""), + new OString(kTestStr1)}, + {"concatenates two empty strings",new OString(""),new OString(""), + new OString("")}, + {"concatenates string constructed by default constructor", + new OString(kTestStr1), + new OString(kTestStr1), new OString()}, + {"concatenates to string constructed by default constructor", + new OString(kTestStr1), + new OString(), new OString(kTestStr1)}, + {"concatenates two strings constructed by default constructor", + new OString(), + new OString(), new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OString str = + arrTestCase[i].input1->concat(*arrTestCase[i].input2); + sal_Bool lastRes = (str == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "concat", i) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "concat"); +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the method toAsciiLowerCase() +//----------------------------------------------------------------------- +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toAsciiLowerCase( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + c_rtl_tres_state_start(hRtlTestResult, "toAsciiLowerCase"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input1; + ~TestCase() { delete input1; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + + {"only uppercase",new OString(kTestStr5),new OString(kTestStr4)}, + {"different cases",new OString(kTestStr5),new OString(kTestStr1)}, + {"different cases",new OString(kTestStr5),new OString(kTestStr3)}, + {"only lowercase",new OString(kTestStr5),new OString(kTestStr5)}, + {"empty string",new OString(""),new OString("")}, + {"string constructed by default constructor", + new OString(),new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OString str = arrTestCase[i].input1->toAsciiLowerCase(); + sal_Bool lastRes = (str ==* arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "toAsciiLowerCase", i) + ); + + res &= lastRes; + } + + c_rtl_tres_state_end(hRtlTestResult, "toAsciiLowerCase"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method toAsciiUpperCase() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toAsciiUpperCase( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + c_rtl_tres_state_start(hRtlTestResult, "toAsciiUpperCase"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input1; + ~TestCase() { delete input1; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"only lowercase",new OString(kTestStr4),new OString(kTestStr5)}, + {"mixed cases",new OString(kTestStr4),new OString(kTestStr3)}, + {"miced cases",new OString(kTestStr4),new OString(kTestStr1)}, + {"only uppercase",new OString(kTestStr4),new OString(kTestStr4)}, + {"empty string",new OString(""),new OString("")}, + {"string constructed by default constructor", + new OString(),new OString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OString str = arrTestCase[i].input1->toAsciiUpperCase(); + sal_Bool lastRes = (str == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "toAsciiLowerCase", i) + ); + + res &= lastRes; + } + c_rtl_tres_state_end(hRtlTestResult, "toAsciiUpperCase"); + +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the method trim() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_trim( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + c_rtl_tres_state_start(hRtlTestResult, "trim"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input1; + ~TestCase() { delete input1; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"removes space from the front",new OString(kTestStr1), + new OString(kTestStr10)}, + {"removes space from the end",new OString(kTestStr1), + new OString(kTestStr11)}, + {"removes space from the front and end",new OString(kTestStr1), + new OString(kTestStr12)}, + {"removes several spaces from the end",new OString(kTestStr1), + new OString(kTestStr13)}, + {"removes several spaces from the front",new OString(kTestStr1), + new OString(kTestStr14)}, + {"removes several spaces from the front and one from the end", + new OString(kTestStr1), + new OString(kTestStr15)}, + {"removes one space from the front and several from the end", + new OString(kTestStr1), + new OString(kTestStr16)}, + {"removes several spaces from the front and end", + new OString(kTestStr1), + new OString(kTestStr17)}, + {"removes characters that have codes <= 32",new OString(kTestStr20), + new OString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\33\40")}, + {"no spaces",new OString(kTestStr8),new OString(kTestStr8)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OString strRes = arrTestCase[i].input1->trim(); + sal_Bool lastRes = (strRes == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "trim", i) + ); + + res &= lastRes; + + } + + c_rtl_tres_state_end(hRtlTestResult, "trim"); +// return ( res ); +} + + + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Bool b ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_sal_Bool( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool input1; + OString* expVal; + ~TestCase() {delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"true",sal_True,new OString("true")}, + {"false",sal_False, new OString("false")} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + ::rtl::OString aStr1; + aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); + sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "valueof_bool", i) + ); + + res &= lastRes; + + } + + return ( res ); +} + +sal_Bool SAL_CALL test_rtl_OString_valueOf_sal_Char( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Char input1; + OString* expVal; + ~TestCase() {delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"A",'A',new OString("A")}, + {"a",'a', new OString("a")}, + {"0",'0', new OString("0")}, + {"-",'-', new OString("-")}, + {"_",'_', new OString("_")}, + {"|",'|', new OString("|")}, + {"?",'?', new OString("?")}, + {"?",'?', new OString("?")}, + {"\n",'\n', new OString("\n")}, + {"\'",'\'', new OString("\'")}, + {"\"",'\"', new OString("\"")} + + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + ::rtl::OString aStr1; + aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); + sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "valueof_char", i) + ); + + res &= lastRes; + + } + + return ( res ); +} + +/** + * Calls the method valueOf(T, radix) and compares + * returned strings with strings that passed in the array resArray. + * + * @param T, type of argument, passed to valueOf + * @param resArray, array of result strings to compare to + * @param n the number of elements in the array resArray (testcases) + * @param pTestResult the instance of the class TestResult + * @param inArray [optional], array of value that is passed as first argument + * to valueOf + * + * @return true, if all returned strings are equal to corresponding string in + * resArray else, false. + */ +template <class T> +sal_Bool test_valueOf( const char** resArray, int n, sal_Int16 radix, + hTestResult hRtlTestResult, const T *inArray ) +{ + sal_Bool bRes = sal_True; + + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + sal_Int32 i; + + for (i = 0; i < n; i++) + { + ::rtl::OString aStr1; + ::rtl::OString aStr2( resArray[i] ); + + if (inArray == 0) + aStr1 = ::rtl::OString::valueOf((T)i, radix); + else + { + if ( inArray[i] < 0 ) + { + aStr2 = "-"; + aStr2 += resArray[i]; + } + aStr1 = ::rtl::OString::valueOf((T)inArray[i], radix); + } + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + aStr2.compareTo(aStr1) == 0, + (sal_Char*)resArray[i], + createName( pMeth, "valueOf", i ) + ); + } + + return (bRes); +} + + +#define test_valueOf_Int32 test_valueOf<sal_Int32> +#define test_valueOf_Int64 test_valueOf<sal_Int64> +// LLA: #define test_valueOf_float test_valueOf<float> +// LLA: #define test_valueOf_double test_valueOf<double> + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBinaryNumsStr, + kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0 ), + "kRadixBinary", + "valueOf(sal_Int32, radix 2)" + ); + + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kOctolNumsStr, + kOctolNumsCount, kRadixOctol, hRtlTestResult, 0), + "kRadixOctol", + "valueOf(sal_Int32, radix 8)" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kDecimalNumsStr, + kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0), + "kRadixDecimal", + "valueOf(sal_Int32, radix 10)" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kHexDecimalNumsStr, + kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0), + "kRadixHexdecimal", + "valueOf(sal_Int32, radix 16)" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBase36NumsStr, + kBase36NumsCount, kRadixBase36, hRtlTestResult, 0), + "kRadixBase36", + "valueOf(sal_Int32, radix 36)" + ); + + + return ( bRes ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=2 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=8 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=10 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=16 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=36 ) +// where l = large constants +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_Bounderies( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBinaryMaxNumsStr, + kInt32MaxNumsCount, kRadixBinary, hRtlTestResult, + kInt32MaxNums), + "kRadixBinary", + "valueOf(salInt32, radix 2) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kOctolMaxNumsStr, + kInt32MaxNumsCount, kRadixOctol, hRtlTestResult, + kInt32MaxNums), + "kRadixOctol", + "valueOf(salInt32, radix 8) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kDecimalMaxNumsStr, + kInt32MaxNumsCount, kRadixDecimal, + hRtlTestResult, kInt32MaxNums), + "kRadixDecimal", + "valueOf(salInt32, radix 10) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kHexDecimalMaxNumsStr, + kInt32MaxNumsCount, kRadixHexdecimal, + hRtlTestResult, kInt32MaxNums), + "kRadixHexdecimal", + "valueOf(salInt32, radix 16) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBase36MaxNumsStr, + kInt32MaxNumsCount, kRadixBase36, + hRtlTestResult, kInt32MaxNums), + "kRadixBase36", + "valueOf(salInt32, radix 36) Bounderies" + ); + + return ( bRes ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 ) +// for negative value +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_Negative( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + sal_Int32 inArr[kBase36NumsCount]; + sal_Int32 i; + + for (i = 0; i < kBase36NumsCount; i++ ) + inArr[i] = -i; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kBinaryNumsStr, kBinaryNumsCount, + kRadixBinary, hRtlTestResult, inArr ), + "negative Int32, kRadixBinary", + "valueOf( negative Int32, radix 2 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kOctolNumsStr, kOctolNumsCount, + kRadixOctol, hRtlTestResult, inArr ), + "negative Int32, kRadixOctol", + "valueOf( negative Int32, radix 8 )" + ); + + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kDecimalNumsStr, kDecimalNumsCount, + kRadixDecimal, hRtlTestResult, inArr ), + "negative Int32, kRadixDecimal", + "valueOf( negative Int32, radix 10 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kHexDecimalNumsStr, kHexDecimalNumsCount, + kRadixHexdecimal, hRtlTestResult, inArr ), + "negative Int32, kRadixHexdecimal", + "valueOf( negative Int32, radix 16 )" + ); + + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kBase36NumsStr, kBase36NumsCount, + kRadixBase36, hRtlTestResult, inArr ), + "negative Int32, kRadixBase36", + "valueOf( negative Int32, radix 36 )" + ); + + return ( bRes ); +} +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 l, sal_Int32 radix ) where radix = -5 +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_WrongRadix( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + sal_Int32 intVal = 11; + + ::rtl::OString aStr1; + ::rtl::OString aStr2("11"); + + aStr1 = aStr1.valueOf( intVal, -5 ); + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + aStr2.compareTo( aStr1 ) == 0, + "if radix not valid then radix must be 10", + "valueOf(sal_Int32, sal_Int32 radix): radix = -5" + ); + + return (bRes); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 l, sal_Int32 radix ) +// where l = -2147483648 (smallest negative value) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int32_SmallestNegativeValue( + hTestResult hRtlTestResult) +{ + // Standard-conforming way to assign -2147483648 to n: + sal_Int32 n = -1; + for (int i = 1; i < 32; ++i) + n *= 2; + return c_rtl_tres_state + ( + hRtlTestResult, + ::rtl::OString::valueOf(n) == "-2147483648", + "-2147483648", + "valueOf(sal_Int32 -2147483648)" + ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBinaryNumsStr, + kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0), + "kRadixBinary", + "valueOf(sal_Int64, radix 2)_" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kOctolNumsStr, + kOctolNumsCount, kRadixOctol, hRtlTestResult, 0), + "kRadixOctol", + "valueOf(sal_Int64, radix 8)_" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kDecimalNumsStr, + kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0), + "kRadixDecimal", + "valueOf(sal_Int64, radix 10)_" + ); + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kHexDecimalNumsStr, + kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0), + "kRadixHexdecimal", + "valueOf(sal_Int64, radix 16)_" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBase36NumsStr, + kBase36NumsCount, kRadixBase36, hRtlTestResult, 0), + "kRadixBase36", + "valueOf(sal_Int64, radix 36)_" + ); + + return (bRes); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=2 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=8 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=10 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=16 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=36 ) +// where l = large constants +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_Bounderies( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBinaryMaxNumsStr, + kInt64MaxNumsCount, kRadixBinary, + hRtlTestResult, kInt64MaxNums), + "kRadixBinary", + "valueOf(salInt64, radix 2) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kOctolMaxNumsStr, + kInt64MaxNumsCount, kRadixOctol, + hRtlTestResult, kInt64MaxNums), + "kRadixOctol", + "valueOf(salInt64, radix 8) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kDecimalMaxNumsStr, + kInt64MaxNumsCount, kRadixDecimal, + hRtlTestResult, kInt64MaxNums), + "kRadixDecimal", + "valueOf(salInt64, radix 10) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kHexDecimalMaxNumsStr, + kInt64MaxNumsCount, kRadixHexdecimal, + hRtlTestResult, kInt64MaxNums), + "kRadixHexdecimal", + "valueOf(salInt64, radix 16) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBase36MaxNumsStr, + kInt64MaxNumsCount, kRadixBase36, + hRtlTestResult, kInt64MaxNums), + "kRadixBase36", + "valueOf(salInt64, radix 36) Bounderies" + ); + + return ( bRes ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 ) +// for negative value +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_Negative( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + sal_Int64 inArr[36]; + sal_Int32 i; + + for (i = 0; i < 36; i++) { + inArr[i] = -i; + } + + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kBinaryNumsStr, kBinaryNumsCount, + kRadixBinary, hRtlTestResult, inArr ), + "negative Int64, kRadixBinary", + "valueOf( negative Int64, radix 2 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kOctolNumsStr, kOctolNumsCount, + kRadixOctol, hRtlTestResult, inArr ), + "negative Int64, kRadixOctol", + "valueOf( negative Int64, radix 8 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kDecimalNumsStr, kDecimalNumsCount, + kRadixDecimal, hRtlTestResult, inArr ), + "negative Int64, kRadixDecimal", + "valueOf( negative Int64, radix 10 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kHexDecimalNumsStr, kHexDecimalNumsCount, + kRadixHexdecimal, hRtlTestResult, inArr ), + "negative Int64, kRadixHexDecimal", + "valueOf( negative Int64, radix 16 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kBase36NumsStr, kBase36NumsCount, + kRadixBase36, hRtlTestResult, inArr), + "negative Int64, kRadixBase36", + "valueOf( negative Int64, radix 36 )" + ); + + return (bRes); +} +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int32 radix ) +// where radix = -5 +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_WrongRadix( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + sal_Int64 intVal = 11; + + ::rtl::OString aStr1; + ::rtl::OString aStr2("11"); + + aStr1 = aStr1.valueOf( intVal, -5 ); + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + aStr2.compareTo(aStr1) == 0, + "if radix not valid then radix must be 10", + "valueOf(sal_Int64, sal_Int32 radix): radix = -5" + ); + + return (bRes); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int32 radix ) +// where l = -9223372036854775808 (smallest negative value) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OString_valueOf_Int64_SmallestNegativeValue( + hTestResult hRtlTestResult) +{ + // Standard-conforming way to assign -9223372036854775808 to n: + sal_Int64 n = -1; + for (int i = 1; i < 64; ++i) + n *= 2; + return c_rtl_tres_state + ( + hRtlTestResult, + ::rtl::OString::valueOf(n) == "-9223372036854775808", + "-9223372036854775808", + "valueOf(sal_Int64 -9223372036854775808)" + ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( float f ) +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_float( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: float input1; +// LLA: OString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: { "3.0", 3.0, new OString("3.0") }, +// LLA: { "3.5", 3.5f, new OString("3.5")}, +// LLA: { "3.0625", 3.0625f, new OString("3.0625")}, +// LLA: { "3.502525", 3.502525f, new OString("3.502525") }, +// LLA: { "3.141592", 3.141592f, new OString("3.141592") }, +// LLA: { "3.5025255", 3.5025255f, new OString("3.5025255") }, +// LLA: { "3.0039062", 3.00390625f, new OString("3.0039062") } +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_float", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + + + + +//------------------------------------------------------------------------ +// testing the method valueOf( float f ) for negative value +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Float_Negative( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: float input1; +// LLA: OString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: { "-3.0", -3.0, new OString("-3.0") }, +// LLA: { "-3.5", -3.5f, new OString("-3.5")}, +// LLA: { "-3.0625", -3.0625f, new OString("-3.0625")}, +// LLA: { "-3.502525", -3.502525f, new OString("-3.502525") }, +// LLA: { "-3.141592", -3.141592f, new OString("-3.141592") }, +// LLA: { "-3.5025255", -3.5025255f, new OString("-3.5025255") }, +// LLA: { "-3.0039062", -3.00390625f, new OString("-3.0039062") } +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_negative float", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method valueOf( double f ) +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_double( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: double input1; +// LLA: OString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: {"3.0", 3.0, new OString("3.0")}, +// LLA: {"3.5", 3.5, new OString("3.5")}, +// LLA: {"3.0625", 3.0625, new OString("3.0625")}, +// LLA: {"3.1415926535", 3.1415926535, new OString("3.1415926535")}, +// LLA: {"3.1415926535897931", 3.141592653589793, +// LLA: new OString("3.1415926535897931")}, +// LLA: {"3.1415926535897931", 3.1415926535897932, +// LLA: new OString("3.1415926535897931")}, +// LLA: {"3.1415926535897931", 3.14159265358979323, +// LLA: new OString("3.1415926535897931")}, +// LLA: {"3.1415926535897931", 3.141592653589793238462643, +// LLA: new OString("3.1415926535897931")} +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_double", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + + +//------------------------------------------------------------------------ +// testing the method valueOf( double f ) for negative value +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OString_valueOf_Double_Negative( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: double input1; +// LLA: OString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: {"-3.0", -3.0, new OString("-3.0")}, +// LLA: {"-3.5", -3.5, new OString("-3.5")}, +// LLA: {"-3.0625", -3.0625, new OString("-3.0625")}, +// LLA: {"-3.1415926535", -3.1415926535, new OString("-3.1415926535")}, +// LLA: {"-3.1415926535897931", -3.141592653589793, +// LLA: new OString("-3.1415926535897931")}, +// LLA: {"-3.1415926535897931", -3.1415926535897932, +// LLA: new OString("-3.1415926535897931")}, +// LLA: {"-3.1415926535897931", -3.14159265358979323, +// LLA: new OString("-3.1415926535897931")}, +// LLA: {"-3.1415926535897931", -3.141592653589793238462643, +// LLA: new OString("-3.1415926535897931")} +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_nagative double", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method valueOf() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_valueOf( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start(hRtlTestResult, "valueOf"); + sal_Bool bTState = test_rtl_OString_valueOf_sal_Bool( hRtlTestResult ); + + bTState &= test_rtl_OString_valueOf_sal_Char( hRtlTestResult ); + + bTState &= test_rtl_OString_valueOf_Int32( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int32_Bounderies( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int32_Negative( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int32_WrongRadix( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int32_SmallestNegativeValue( + hRtlTestResult ); + + bTState &= test_rtl_OString_valueOf_Int64( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int64_Bounderies( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int64_Negative( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int64_WrongRadix( hRtlTestResult ); + bTState &= test_rtl_OString_valueOf_Int64_SmallestNegativeValue( + hRtlTestResult ); + + // LLA: the tests for valueOf(float) and valueOf(double) are moved to file + // sal/qa/rtl/ostring/rtl_OString2.cxx + + // LLA: bTState &= test_rtl_OString_valueOf_float( hRtlTestResult ); + // LLA: bTState &= test_rtl_OString_valueOf_Float_Negative( hRtlTestResult ); + + // LLA: bTState &= test_rtl_OString_valueOf_double( hRtlTestResult ); + // LLA: bTState &= test_rtl_OString_valueOf_Double_Negative( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "valueOf"); +// return ( bTState ); +} + + +//------------------------------------------------------------------------ +// testing the method toChar() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toChar( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "toChar"); + typedef struct TestCase + { + sal_Char* comments; + sal_Char expVal; + OString* input1; + ~TestCase() {delete input1;} + } TestCase; + + + TestCase arrTestCase[] = + { + {"A", 'A', new OString("A")}, + {"a", 'a', new OString("a")}, + {"0", '0',new OString("0")}, + {"-", '-',new OString("-")}, + {"_", '_',new OString("_")}, + +// TODO: may be UTF-8 values +// {"06", '06',new OString("06")}, +// { "07", '07',new OString("07")}, +// {"00", '00',new OString("00")}, +// {"06", '06',new OString("06")}, + {"\n", '\n',new OString("\n")}, + {"\'", '\'',new OString("\'")}, + {"\"", '\"',new OString("\"")}, + {"\0", '\0',new OString("\0")}, + {"", '\0',new OString("")}, + {"Sun Microsystems", 'S', new OString(kTestStr1)} + }; + + + // sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ ) + { + sal_Char strRes = arrTestCase[i].input1->toChar(); + sal_Bool lastRes = ( strRes == arrTestCase[i].expVal ); + + char com[MAXBUFLENGTH]; + com[0] = '\''; + cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH); + int length = AStringLen( (*arrTestCase[i].input1) ); + com[length + 1] = '\''; + com[length + 2] = 0; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + com, + createName( pMeth, "toChar", i ) + ); + + } + + c_rtl_tres_state_end(hRtlTestResult, "toChar"); +// return (res); +} + + +//------------------------------------------------------------------------ +// testing the method toFloat() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toFloat( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "toFloat"); + typedef struct TestCase + { + float expVal; + OString* input1; + float m_nPrecision; + ~TestCase() {delete input1;} + } TestCase; + + + TestCase arrTestCase[] = + { + {3.0f, new OString("3"), 3e-7f}, + {3.1f, new OString("3.1"), 3e-7f}, + {3.1415f, new OString("3.1415"), 3e-7f}, + {3.14159f, new OString("3.14159"), 3e-7f}, + {3.141592f, new OString("3.141592"), 3e-7f}, + {3.1415926f, new OString("3.1415926"), 3e-7f}, + {3.14159265f, new OString("3.14159265"), 3e-7f}, + {3.141592653589793238462643f, + new OString("3.141592653589793238462643"), 3e-7f}, + {6.5822e-16f, new OString("6.5822e-16"), 6e-16f * 1e-7f}, + {9.1096e-31f, new OString("9.1096e-31"), 9e-31f * 1e-7f}, + {2.997925e8f, new OString("2.997925e8"), 3e8f * 1e-7f}, + {6.241e18f, new OString("6.241e18"), 6e18f * 1e-7f}, + {3.1f, new OString("03.1"), 3e-7f}, + {3.1f, new OString(" 3.1"), 3e-7f}, + {-3.1f, new OString("-3.1"), 3e-7f}, + {3.1f, new OString("+3.1"), 3e-7f}, + {0.0f, new OString("-0.0"), 1e-7f} + }; + + + // sal_Bool res = sal_True; + sal_uInt32 i; + + t_print("sizeof(float)=%d, sizeof(double)=%d\n", sizeof(float), sizeof(double)); + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ ) + { + float fA = arrTestCase[i].input1->toFloat(); + float fB = arrTestCase[i].expVal; + float fPrec = arrTestCase[i].m_nPrecision; + float fResult = (float) fabs(fA - fB); + // t_print("float result: A:(%.9f) B:(%.9f) fabs(A-B):%E\n", fA, fB, fResult); + t_print("float result: A:(%E) B:(%E) fabs(A-B):%E\n", fA, fB, (float) fResult); + sal_Bool lastRes = ( fResult <= fPrec ); + + char com[MAXBUFLENGTH]; + com[0] = '\''; + cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH); + int length = AStringLen( (*arrTestCase[i].input1) ); + com[length + 1] = '\''; + com[length + 2] = 0; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + com, + createName( pMeth, "toFloat", i ) + ); + + } + + c_rtl_tres_state_end(hRtlTestResult, "toFloat"); +// return (res); +} + + +//------------------------------------------------------------------------ +// testing the method toDouble() +//------------------------------------------------------------------------ +// LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toDouble( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth = methName; +// LLA: +// LLA: c_rtl_tres_state_start(hRtlTestResult, "toDouble"); +// LLA: typedef struct TestCase +// LLA: { +// LLA: double expVal; +// LLA: double expDiff; +// LLA: OString* input1; +// LLA: ~TestCase() {delete input1;} +// LLA: } TestCase; +// LLA: +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: {3.0, 1e-35, new OString("3")}, +// LLA: {3.1, 1e-2, new OString("3.1")}, +// LLA: {3.1415, 1e-5, new OString("3.1415")}, +// LLA: {3.1415926535, 1e-11, new OString("3.1415926535")}, +// LLA: {3.141592653589793, 1e-15, +// LLA: new OString("3.141592653589793")}, +// LLA: {3.1415926535897932, 1e-16, +// LLA: new OString("3.1415926535897932")}, +// LLA: {3.14159265358979323, 1e-15, +// LLA: new OString("3.14159265358979323")}, +// LLA: {3.141592653589793238462643, 1e-15, +// LLA: new OString("3.141592653589793238462643")}, +// LLA: {6.5822e-16, 1e-20, new OString("6.5822e-16")}, +// LLA: {9.1096e-31, 1e-35, new OString("9.1096e-31")}, +// LLA: {2.997925e8, 10, new OString("2.997925e8")}, +// LLA: {6.241e18, 100, new OString("6.241e18")}, +// LLA: {1.7e-308, 1e-35, new OString("1.7e-308")}, +// LLA: {1.7e+308, 100, new OString("1.7e+308")}, +// LLA: {3.1, 1e-2, new OString("03.1")}, +// LLA: {3.1, 1e-2, new OString(" 3.1")}, +// LLA: {-3.1, 1e-2, new OString("-3.1")}, +// LLA: {3.1, 1e-2, new OString("+3.1")}, +// LLA: {0.0, 1e-2, new OString("-0.0")} +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++ ) +// LLA: { +// LLA: double dRes = arrTestCase[i].input1->toDouble(); +// LLA: double dErg = dRes - arrTestCase[i].expVal ; +// LLA: double dComp = fabs( dErg ); +// LLA: sal_Bool lastRes = ( dComp <= arrTestCase[i].expDiff ); +// LLA: +// LLA: char com[MAXBUFLENGTH]; +// LLA: com[0] = '\''; +// LLA: cpynstr(com + 1, (*arrTestCase[i].input1), MAXBUFLENGTH); +// LLA: int length = AStringLen( (*arrTestCase[i].input1) ); +// LLA: com[length + 1] = '\''; +// LLA: com[length + 2] = 0; +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: com, +// LLA: createName( pMeth, "toDouble", i ) +// LLA: ); +// LLA: +// LLA: } +// LLA: +// LLA: c_rtl_tres_state_end(hRtlTestResult, "toDouble"); +// LLA: // return (res); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method toBoolean() +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toBoolean( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "toBoolean"); + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OString* input; + + } TestCase; + + TestCase arrTestCase[]={ + + {"expected true", sal_True, new OString("True")}, + {"expected false", sal_False, new OString("False")}, + {"expected true", sal_True, new OString("1")} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool bRes = arrTestCase[i].input->toBoolean(); + sal_Bool lastRes = (bRes == arrTestCase[i].expVal); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "toBoolean", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end(hRtlTestResult, "toBoolean"); +// return ( res ); +} + + + +//------------------------------------------------------------------------ +// testing the method toInt32( sal_Int16 radix = 2,8,10,16,36 ) +//------------------------------------------------------------------------ +sal_Bool test_toInt32( int num, const sal_Char** in, +const sal_Int32 *expVal,sal_Int16 radix, hTestResult hRtlTestResult ) +{ + sal_Bool res = sal_True; + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + sal_Int32 i; + + for( i = 0; i < num; i++ ) + { + OString str(in[i]); + sal_Int32 intRes = str.toInt32(radix); + sal_Bool lastRes = (intRes == expVal[i]); + + char buf[MAXBUFLENGTH]; + buf[0] = '\''; + cpynstr( buf + 1, in[i], MAXBUFLENGTH ); + int length = AStringLen( in[i] ); + buf[length + 1] = '\''; + buf[length + 2] = 0; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + buf, + createName( pMeth,"toInt32", i ) + ); + + res &= lastRes; + } + + return( res ); +} + +sal_Bool SAL_CALL test_rtl_OString_toInt32_wrongRadix( + hTestResult hRtlTestResult ) +{ + ::rtl::OString str("0"); + + sal_Int32 iRes = str.toInt32(-1); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + iRes == 0, + "wrong radix -1", + "toInt32( 0, wrong radix -1 )" + ) + ); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toInt32( + hTestResult hRtlTestResult ) +{ + sal_Int32 expValues[kBase36NumsCount]; + sal_Int32 i; + + c_rtl_tres_state_start(hRtlTestResult, "toInt32"); + for ( i = 0; i < kBase36NumsCount; i++ ) + expValues[i] = i; + + sal_Bool res = c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kBinaryNumsCount, kBinaryNumsStr, + expValues, kRadixBinary, hRtlTestResult ), + "kBinaryNumsStr", + "toInt32( radix 2 )" + ); + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kInt32MaxNumsCount, kBinaryMaxNumsStr, + kInt32MaxNums, kRadixBinary, hRtlTestResult ), + "kBinaryMaxNumsStr", + "toInt32_Boundaries( radix 2 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kOctolNumsCount, kOctolNumsStr, + expValues, kRadixOctol, hRtlTestResult ), + "kOctolNumsStr", + "toInt32( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kInt32MaxNumsCount, kOctolMaxNumsStr, + (sal_Int32*)kInt32MaxNums, kRadixOctol, hRtlTestResult ), + "kOctolMaxNumsStr", + "toInt32_Boundaries( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kDecimalNumsCount, kDecimalNumsStr, expValues, + kRadixDecimal, hRtlTestResult ), + "kDecimalNumsStr", + "toInt32( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kInt32MaxNumsCount, kDecimalMaxNumsStr, + (sal_Int32*)kInt32MaxNums, kRadixDecimal, hRtlTestResult ), + "kDecimalMaxNumsStr", + "toInt32_Boundaries( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kHexDecimalNumsCount, kHexDecimalNumsStr, expValues, + kRadixHexdecimal, hRtlTestResult ), + "kHexDecimalNumsStr", + "toInt32( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kInt32MaxNumsCount, kHexDecimalMaxNumsStr, + (sal_Int32*)kInt32MaxNums, kRadixHexdecimal, hRtlTestResult ), + "kHexDecimalMaxNumsStr", + "toInt32_Boundaries( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kBase36NumsCount, kBase36NumsStr, expValues, + kRadixBase36, hRtlTestResult ), + "kBase36NumsStr", + "toInt32( radix 36 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( kInt32MaxNumsCount, kBase36MaxNumsStr, + (sal_Int32*)kInt32MaxNums, kRadixBase36, hRtlTestResult ), + "kBase36MaxNumsStr", + "toInt32_Boundaries( radix 36 )" + ); + + const sal_Int16 nSpecCases = 5; + static const sal_Char *spString[nSpecCases] = + { + "-1", + "+1", + " 1", + " -1", + "001" + }; + + sal_Int32 expSpecVal[nSpecCases] = + { + -1, + 1, + 1, + -1, + 1 + }; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt32( nSpecCases, spString, expSpecVal, + kRadixDecimal, hRtlTestResult ), + "special cases", + "toInt32( specialcases )" + ); + + res &= test_rtl_OString_toInt32_wrongRadix( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "toInt32"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method toInt64( sal_Int16 radix = 2,8,10,16,36 ) +//------------------------------------------------------------------------ +sal_Bool test_toInt64( int num, const sal_Char** in, +const sal_Int64 *expVal,sal_Int16 radix, hTestResult hRtlTestResult ) +{ + sal_Bool res = sal_True; + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + sal_Int32 i; + + for( i = 0; i < num; i++ ) + { + OString str( in[i] ); + sal_Int64 intRes = str.toInt64( radix ); + sal_Bool lastRes = ( intRes == expVal[i] ); + + char buf[MAXBUFLENGTH]; + buf[0] = '\''; + cpynstr( buf + 1, in[i], MAXBUFLENGTH ); + int length = AStringLen(in[i]); + buf[length + 1] = '\''; + buf[length + 2] = 0; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + buf, + createName( pMeth, "toInt64", i ) + ); + + res &= lastRes; + } + return (res); +} + +sal_Bool SAL_CALL test_rtl_OString_toInt64_wrongRadix( + hTestResult hRtlTestResult ) +{ + ::rtl::OString str("0"); + + sal_Int64 iRes = str.toInt64(-1); + + return ( + + c_rtl_tres_state + ( hRtlTestResult, + iRes == 0, + "wrong radix -1", + "toInt64( wrong radix -1)" + ) + ); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_toInt64( + hTestResult hRtlTestResult ) +{ + sal_Int64 expValues[kBase36NumsCount]; + sal_Int32 i; + + c_rtl_tres_state_start(hRtlTestResult, "toInt64"); + for (i = 0; i < kBase36NumsCount; expValues[i] = i, i++); + + sal_Bool res = c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kBinaryNumsCount, kBinaryNumsStr, expValues, + kRadixBinary, hRtlTestResult ), + "kBinaryNumsStr", + "toInt64( radix 2 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kInt32MaxNumsCount, kBinaryMaxNumsStr, + (sal_Int64*)kInt64MaxNums, kRadixBinary, hRtlTestResult ), + "kBinaryMaxNumsStr", + "toInt64_Boundaries( radix 2 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kOctolNumsCount, kOctolNumsStr, expValues, + kRadixOctol, hRtlTestResult ), + "kOctolNumsStr", + "toInt64( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kInt32MaxNumsCount, kOctolMaxNumsStr, + (sal_Int64*)kInt64MaxNums, kRadixOctol, hRtlTestResult ), + "kOctolMaxNumsStr", + "toInt64_Boundaries( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kDecimalNumsCount, kDecimalNumsStr, expValues, + kRadixDecimal, hRtlTestResult ), + "kDecimalNumsStr", + "toInt64( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kInt32MaxNumsCount, kDecimalMaxNumsStr, + (sal_Int64*)kInt64MaxNums, kRadixDecimal, hRtlTestResult ), + "kDecimalMaxNumsStr", + "toInt64_Boundaries( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kHexDecimalNumsCount, kHexDecimalNumsStr, expValues, + kRadixHexdecimal, hRtlTestResult ), + "kHexDecimalNumsStr", + "toInt64( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kInt32MaxNumsCount, kHexDecimalMaxNumsStr, + (sal_Int64*)kInt64MaxNums, kRadixHexdecimal, hRtlTestResult ), + "kHexDecimalMaxNumsStr", + "toInt64_Boundaries( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kBase36NumsCount, kBase36NumsStr, expValues, + kRadixBase36, hRtlTestResult ), + "kBase36NumsStr", + "toInt64( radix 36 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( kInt32MaxNumsCount, kBase36MaxNumsStr, + (sal_Int64*)kInt64MaxNums, kRadixBase36, hRtlTestResult ), + "kBase36MaxNumsStr", + "toInt64_Boundaries( radix 36 )" + ); + + + + const sal_Int16 nSpecCases = 5; + static const sal_Char *spString[nSpecCases] = + { + "-1", + "+1", + " 1", + " -1", + "001" + }; + + sal_Int64 expSpecVal[nSpecCases] = + { + -1, + 1, + 1, + -1, + 1 + }; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toInt64( nSpecCases, spString, expSpecVal, + kRadixDecimal, hRtlTestResult ), + "special cases", + "toInt64( specialcases )" + ); + + res &= test_rtl_OString_toInt64_wrongRadix( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "toInt64"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the method replace( sal_Char oldChar, sal_Char newChar ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_replace( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "replace"); +typedef struct TestCase +{ + sal_Char* comments; + OString* expVal; + OString* input; + sal_Char oldChar; + sal_Char newChar; + + ~TestCase() { delete input; delete expVal;} +} TestCase; + +TestCase arrTestCase[]={ + + {"string differs", new OString(kTestStr18), + new OString(kTestStr4),'S','s'}, + {"string differs", new OString(kTestStr19), + new OString(kTestStr17),(sal_Char)' ',(sal_Char)'-'}, + {"same string, no replace ", new OString(kTestStr22), + new OString(kTestStr22),'*','8'} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + ::rtl::OString aStr1; + aStr1= arrTestCase[i].input->replace(arrTestCase[i].oldChar, + arrTestCase[i].newChar); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + (arrTestCase[i].expVal->compareTo(aStr1) == 0), + arrTestCase[i].comments, + createName( pMeth, "replace", i ) + + ); + } + c_rtl_tres_state_end(hRtlTestResult, "replace"); +// return ( res ); +} + + + +//------------------------------------------------------------------------ +// testing the method replaceAt( sal_Int32 index, sal_Int32 count, +// const OString& newStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_replaceAt( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + c_rtl_tres_state_start(hRtlTestResult, "replaceAt"); + typedef struct TestCase + { + sal_Char* comments; + OString* expVal; + OString* input; + OString* newStr; + sal_Int32 index; + sal_Int32 count; + + ~TestCase() { delete input; delete expVal; delete newStr;} + } TestCase; + + TestCase arrTestCase[]= + { + + { "string differs", new OString(kTestStr2), new OString(kTestStr22), + new OString(kTestStr2), 0, kTestStr22Len }, + + { "larger index", new OString(kTestStr1), new OString(kTestStr7), + new OString(kTestStr8), 64, kTestStr8Len }, + + { "larger count", new OString(kTestStr2), new OString(kTestStr22), + new OString(kTestStr2),0, 64 }, + + { "navigate index", new OString(kTestStr2), new OString(kTestStr22), + new OString(kTestStr2), -64, 64 }, + + { "null string", new OString(""), + new OString(kTestStr14),new OString(""), 0, kTestStr14Len } + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + ::rtl::OString aStr1; + aStr1= arrTestCase[i].input->replaceAt( arrTestCase[i].index, + arrTestCase[i].count, *arrTestCase[i].newStr ); + + sal_Bool lastRes = ( arrTestCase[i].expVal->compareTo(aStr1) == 0 ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "replaceAt", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end(hRtlTestResult, "replaceAt"); +// return ( res ); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString( hTestResult hRtlTestResult ) +{ + + c_rtl_tres_state_start(hRtlTestResult, "rtl_OString" ); + + test_rtl_OString_ctors( hRtlTestResult ); + test_rtl_OString_getLength( hRtlTestResult ); + test_rtl_OString_equals( hRtlTestResult ); + test_rtl_OString_equalsIgnoreAsciiCase( hRtlTestResult ); + test_rtl_OString_compareTo( hRtlTestResult ); + test_rtl_OString_op_cmp( hRtlTestResult ); + test_rtl_OString_op_neq( hRtlTestResult ); + test_rtl_OString_op_g( hRtlTestResult ); + test_rtl_OString_op_l( hRtlTestResult ); + test_rtl_OString_op_ge( hRtlTestResult ); + test_rtl_OString_op_le( hRtlTestResult ); + test_rtl_OString_op_eq( hRtlTestResult ); + test_rtl_OString_op_plus( hRtlTestResult ); + test_rtl_OString_op_peq( hRtlTestResult ); + test_rtl_OString_op_cscs( hRtlTestResult ); + test_rtl_OString_getStr( hRtlTestResult ); + test_rtl_OString_copy( hRtlTestResult ); + test_rtl_OString_concat( hRtlTestResult ); + test_rtl_OString_toAsciiLowerCase( hRtlTestResult ); + test_rtl_OString_toAsciiUpperCase( hRtlTestResult ); + test_rtl_OString_trim( hRtlTestResult ); + test_rtl_OString_valueOf( hRtlTestResult ); + test_rtl_OString_toChar( hRtlTestResult ); + test_rtl_OString_toFloat( hRtlTestResult ); + // LLA: test_rtl_OString_toDouble( hRtlTestResult ); + test_rtl_OString_toBoolean( hRtlTestResult ); + test_rtl_OString_toInt32( hRtlTestResult ); + test_rtl_OString_toInt64( hRtlTestResult ); + test_rtl_OString_replace( hRtlTestResult ); + test_rtl_OString_replaceAt( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "rtl_OString"); +} + + +// ----------------------------------------------------------------------------- +void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) +{ + if (_pFunc) + { + (_pFunc)(&test_rtl_OString, ""); + + //# (_pFunc)(&test_rtl_OString_ctors, ""); + //# (_pFunc)(&test_rtl_OString_getLength, ""); + //# (_pFunc)(&test_rtl_OString_equals, ""); + //# (_pFunc)(&test_rtl_OString_equalsIgnoreAsciiCase, ""); + //# (_pFunc)(&test_rtl_OString_compareTo, ""); + //# (_pFunc)(&test_rtl_OString_op_cmp, ""); + //# (_pFunc)(&test_rtl_OString_op_neq, ""); + //# (_pFunc)(&test_rtl_OString_op_g, ""); + //# (_pFunc)(&test_rtl_OString_op_l, ""); + //# (_pFunc)(&test_rtl_OString_op_ge, ""); + //# (_pFunc)(&test_rtl_OString_op_le, ""); + //# (_pFunc)(&test_rtl_OString_op_eq, ""); + //# (_pFunc)(&test_rtl_OString_op_plus, ""); + //# (_pFunc)(&test_rtl_OString_op_peq, ""); + //# (_pFunc)(&test_rtl_OString_op_cscs, ""); + //# (_pFunc)(&test_rtl_OString_getStr, ""); + //# (_pFunc)(&test_rtl_OString_copy, ""); + //# (_pFunc)(&test_rtl_OString_concat, ""); + //# (_pFunc)(&test_rtl_OString_toAsciiLowerCase, ""); + //# (_pFunc)(&test_rtl_OString_toAsciiUpperCase, ""); + //# (_pFunc)(&test_rtl_OString_trim, ""); + //# (_pFunc)(&test_rtl_OString_valueOf, ""); + //# (_pFunc)(&test_rtl_OString_toChar, ""); + //# (_pFunc)(&test_rtl_OString_toFloat, ""); + //# (_pFunc)(&test_rtl_OString_toDouble, ""); + //# (_pFunc)(&test_rtl_OString_toBoolean, ""); + //# (_pFunc)(&test_rtl_OString_toInt32, ""); + //# (_pFunc)(&test_rtl_OString_toInt64, ""); + //# (_pFunc)(&test_rtl_OString_replace, ""); + //# (_pFunc)(&test_rtl_OString_replaceAt, ""); + } +} + +/* +D:\local\644\SRX644\sal\qa\rtl_OString.cxx(3559) : error C2664: +'unsigned char (void (__cdecl *)(void *),const char *)' + : cannot convert parameter 1 from +'unsigned char (__cdecl *)(void *)' to 'void (__cdecl *)(void *)' + + This conversion requires a reinterpret_cast, a C-style cast or function- +style cast +*/ diff --git a/sal/qa/rtl_strings/rtl_OUString.cxx b/sal/qa/rtl_strings/rtl_OUString.cxx new file mode 100644 index 000000000000..e1e2a38e01dc --- /dev/null +++ b/sal/qa/rtl_strings/rtl_OUString.cxx @@ -0,0 +1,3861 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OUString.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <sal/types.h> + +//# #ifndef _RTL_TRES_H_ +//# #include <rtl/tres.h> +//# #endif +#include <testshl/tresstatewrapper.hxx> +#include "stringhelper.hxx" +#include <rtl/string.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#include <osl/thread.h> +#include <rtl_String_Const.h> +#include <rtl_String_Utils.hxx> + + + + using namespace rtl; + +//------------------------------------------------------------------------ +// test classes +//------------------------------------------------------------------------ +const int MAXBUFLENGTH = 255; +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ +static void unused() +{ + // NEVER CALL SUCH FUNCTION!!! + (void)input1StrLastDefault; + (void)input1StrLastNormal; + unused(); +} + +//------------------------------------------------------------------------ +// testing constructors +//------------------------------------------------------------------------ +static sal_Bool test_rtl_OUString_ctor_001( hTestResult hRtlTestResult ) +{ + + ::rtl::OUString aUStr; + rtl_uString * pData = aUStr.pData; + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + pData->length == 0 && + ! *pData->buffer, + "New OUString containing no characters", + "ctor_001" + ) + ); +} + +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OUString_ctor_002( + hTestResult hRtlTestResult ) +{ + ::rtl::OUString aUStr( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStr == aUStr1, + "OUString from an ascii string", + "ctor_002" + ) + ); +} +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OUString_ctor_003( + hTestResult hRtlTestResult ) +{ + rtl_uString *rtlUStr =NULL ; + rtl_uString_newFromAscii( &rtlUStr, kTestStr1 ); + ::rtl::OUString aUStr( rtlUStr ); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStr == aUStr1, + "New OUString from a rtl_uString", + "ctor_003" + ) + ); +} + +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OUString_ctor_004( + hTestResult hRtlTestResult) +{ + ::rtl::OUString aUStr( aUStr1 ); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStr == aUStr1, + "New OUString from unicode string", + "ctor_004" + ) + ); +} +//------------------------------------------------------------------------ + +static sal_Bool test_rtl_OUString_ctor_005( hTestResult hRtlTestResult ) +{ + ::rtl::OUString aUStr( aUStr2, kTestStr1Len ); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStr == aUStr1, + "New OUString from the first n characters of unicode string", + "ctor_004" + ) + ); + +} + + +//------------------------------------------------------------------------ + +static sal_Bool test_rtl_OUString_ctor_006( hTestResult hRtlTestResult ) +{ + ::rtl::OUString aUStrtmp( aUStr1 ); + ::rtl::OUString aUStr( aUStrtmp ); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStr==aUStrtmp, + "New OUString from another OUString", + "ctor_006" + ) + ); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_ctors( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "ctors"); + sal_Bool DCState = test_ini_uString(); + (void)DCState; + sal_Bool bTSState = test_rtl_OUString_ctor_001( hRtlTestResult ); + bTSState &= test_rtl_OUString_ctor_002( hRtlTestResult); + bTSState &= test_rtl_OUString_ctor_003( hRtlTestResult); + bTSState &= test_rtl_OUString_ctor_004( hRtlTestResult); + bTSState &= test_rtl_OUString_ctor_005( hRtlTestResult); + bTSState &= test_rtl_OUString_ctor_006( hRtlTestResult); + c_rtl_tres_state_end( hRtlTestResult, "ctors"); +// return( bTSState ); +} + + + +//------------------------------------------------------------------------ +// testing the method getLength +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_getLength( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "getLength"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUString* input; + ~TestCase() { delete input;} + } TestCase; + + TestCase arrTestCase[]={ + + {"length of ascii string", kTestStr1Len, + new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"length of ascci string of size 1", 1, + new OUString( "1", + 1, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"length of empty string (default constructor)", 0, new OUString()}, + {"length of empty string (empty ascii string arg)",0, + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"length of empty string (string arg = '\\0')", 0, + new OUString( "\0", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 length = arrTestCase[i].input->getLength(); + sal_Bool lastRes = (length == arrTestCase[i].expVal); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "getLength", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "getLength"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method equals( const OString & aStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equals( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "equals"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + + {"same size", sal_True, new OUString(aUStr1), new OUString(aUStr1)}, + {"different size", sal_False, new OUString(aUStr1), + new OUString(aUStr2) + }, + {"same size, no case match", sal_False, new OUString(aUStr1), + new OUString(aUStr3) + }, + {"two empty strings(def. constructor)", sal_True, new OUString(), + new OUString() + }, + {"empty(def.constructor) and non empty", sal_False, new OUString(), + new OUString(aUStr2) + }, + {"non empty and empty(def. constructor)", sal_False, + new OUString(aUStr1), + new OUString() + }, + {"two empty strings(string arg = '\\0')", sal_True, + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"empty(string arg = '\\0') and non empty", sal_False, + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + new OUString(aUStr2) + }, + {"non empty and empty(string arg = '\\0')", sal_False, + new OUString(aUStr1), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + } + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + ( arrTestCase[i].input1->equals(*(arrTestCase[i].input2)) == + arrTestCase[i].expVal ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equals", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "equals"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the method equalsIgnoreAsciiCase( const OString & aStr ) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equalsIgnoreAsciiCase( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "equalsIgnoreAsciiCase"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + {"same strings but different cases",sal_True,new OUString(aUStr4), + new OUString(aUStr5) + }, + {"same strings",sal_True,new OUString(aUStr4), + new OUString(aUStr4)}, + {"with equal beginning",sal_False,new OUString(aUStr2), + new OUString(aUStr4) + }, + {"empty(def.constructor) and non empty",sal_False,new OUString(), + new OUString(aUStr5) + }, + {"non empty and empty(def.constructor)",sal_False, + new OUString(aUStr4), + new OUString() + }, + {"two empty strings(def.constructor)",sal_True,new OUString(), + new OUString() + }, + {"different strings with equal length",sal_False, + new OUString(aUStr10), + new OUString(aUStr11) + } + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + (arrTestCase[i].input1->equalsIgnoreAsciiCase(*arrTestCase[i].input2) == + arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equalsIgnoreAsciiCase", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "equalsIgnoreAsciiCase"); +// return (res); +} + + +static sal_Bool SAL_CALL test_rtl_OUString_compareTo_001( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + + {"simple compare, str1 to str5",-1,new OUString(aUStr1), + new OUString(aUStr5) + }, + {"simple compare, str2 to str5",-1,new OUString(aUStr2), + new OUString(aUStr5) + }, + {"simple compare, str1 to str9",-1,new OUString(aUStr1), + new OUString(aUStr9) + }, + {"simple compare, str1 to str2",-1,new OUString(aUStr1), + new OUString(aUStr2) + }, + {"simple compare, str4 to str5",-1,new OUString(aUStr4), + new OUString(aUStr5) + }, + {"simple compare, str1 to str3",-1,new OUString(aUStr1), + new OUString(aUStr3) + }, + {"simple compare, str5 to str1",+1,new OUString(aUStr5), + new OUString(aUStr1) + }, + {"simple compare, str2 to str1",+1,new OUString(aUStr2), + new OUString(aUStr1) + }, + {"simple compare, str9 to str5",+1,new OUString(aUStr9), + new OUString(aUStr5) + }, + {"simple compare, str5 to str4",+1,new OUString(aUStr5), + new OUString(aUStr4) + }, + {"simple compare, str1 to str1",0,new OUString(aUStr1), + new OUString(aUStr1) + }, + {"simple compare, nullString to nullString",0,new OUString(), + new OUString() + }, + {"simple compare, nullString to str2",-1,new OUString(), + new OUString(aUStr2) + }, + {"simple compare, str1 to nullString",+1,new OUString(aUStr1), + new OUString() + } + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 cmpRes = arrTestCase[i].input1->compareTo + (*arrTestCase[i].input2); + cmpRes = ( cmpRes == 0 ) ? 0 : ( cmpRes > 0 ) ? +1 : -1 ; + sal_Bool lastRes = ( cmpRes == arrTestCase[i].expVal); + + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "compareTo_001(const OString&)", i ) + ); + + res &= lastRes; + } + + return (res); +} + + +//------------------------------------------------------------------------ +// testing the method compareTo( const OString & rObj, sal_Int32 length ) +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OUString_compareTo_002( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + sal_Int32 maxLength; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[] = + { + {"compare with maxlength, str1 to str9, 16",-1,16, + new OUString(aUStr1), new OUString(aUStr9)}, + {"compare with maxlength, str2 to str9, 32",-1,32, + new OUString(aUStr2), new OUString(aUStr9)}, + {"compare with maxlength, str9 to str4, 16",+1,16, + new OUString(aUStr9), new OUString(aUStr4)}, + {"compare with maxlength, str9 to str22, 32",+1,32, + new OUString(aUStr9), new OUString(aUStr22)}, + {"compare with maxlength, str9 to str5, 16",0,16, + new OUString(aUStr9), new OUString(aUStr5)}, + {"compare with maxlength, str9 to str9, 32",0,32, + new OUString(aUStr9), new OUString(aUStr9)}, + {"compare with maxlength, str1 to str2, 32",-1,32, + new OUString(aUStr1), new OUString(aUStr2)}, + {"compare with maxlength, str1 to str2, 32",-1,32, + new OUString(aUStr1), new OUString(aUStr2)}, + {"compare with maxlength, str1 to str2", 0,-1, + new OUString(aUStr1), new OUString(aUStr2)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 cmpRes = arrTestCase[i].input1->compareTo + (*arrTestCase[i].input2, arrTestCase[i].maxLength); + cmpRes = (cmpRes == 0) ? 0 : (cmpRes > 0) ? +1 : -1 ; + sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "compareTo_002(const OString&, sal_Int32)", i ) + ); + + res &= lastRes; + } + + return (res); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_compareTo( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "compareTo"); + sal_Bool res = test_rtl_OUString_compareTo_001(hRtlTestResult); + res &= test_rtl_OUString_compareTo_002(hRtlTestResult); + c_rtl_tres_state_end( hRtlTestResult, "compareTo"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the method match( const OUString & str, sal_Int32 fromIndex = 0 ) +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OUString_match_001( + hTestResult hRtlTestResult) + +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + + {"aUStr2 and aUStr1", sal_True, new OUString(aUStr2), + new OUString(aUStr1)}, + {"aUStr1 and aUStr2", sal_False, new OUString(aUStr1), + new OUString(aUStr2)}, + {"aUStr5 and aUStr6", sal_False, new OUString(aUStr5), + new OUString(aUStr6)}, + {"null and aUStr1", sal_False, new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + new OUString(aUStr1)} + + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = ( arrTestCase[i].input1->match( + *(arrTestCase[i].input2)) == arrTestCase[i].expVal ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "match(const OUString & str)", i ) + ); + + res &= lastRes; + } + return (res); +} + +static sal_Bool SAL_CALL test_rtl_OUString_match_002( + hTestResult hRtlTestResult ) + +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + sal_Int32 fromIndex; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + + {"aUStr2 from 17 and aUStr6", sal_True, 17, + new OUString(aUStr2),new OUString(aUStr6)}, + {"aUStr2 from 5 and aUStr6", sal_False, 5, + new OUString(aUStr2),new OUString(aUStr6)}, + {"aUStr2 from 0 and aUStr1", sal_True, 0, + new OUString(aUStr2),new OUString(aUStr1)}, + {"aUStr1 from 16 and null", sal_True, 16, + new OUString(aUStr1), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ) + }, + {"aUStr1 from 5 and null", sal_True, 5, + new OUString(aUStr1), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ) + }, + {"aUStr2 from -1 and aUStr1", sal_False, -1, + new OUString(aUStr2),new OUString(aUStr1)}, + {"aUStr5 from 2 and aUStr4", sal_False, 2, + new OUString(aUStr5),new OUString(aUStr4)}, + {"aUStr2 from 18 and aUStr1", sal_False, 18, + new OUString(aUStr2),new OUString(aUStr1)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = ( arrTestCase[i].input1->match + (*(arrTestCase[i].input2),arrTestCase[i].fromIndex) == + arrTestCase[i].expVal ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, + "match(const OUString & str,sal_Int32 fromIndex = 0)", i ) + + ); + + res &= lastRes; + } + return (res); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_match( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "match"); + sal_Bool res = test_rtl_OUString_match_001(hRtlTestResult); + res &= test_rtl_OUString_match_002(hRtlTestResult); + c_rtl_tres_state_end( hRtlTestResult, "match"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the operator += +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_op_eq( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "eq"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1; delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + {"null and Ustr1", new OUString, new OUString(aUStr1)}, + {"Ustr2 and Ustr1", new OUString(aUStr2), + new OUString(aUStr1)}, + {""" and Ustr1 from bit charactor buffer", + new OUString(aUStr1), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + )}, + {"Ustr1 and Ustr2 from value and length", + new OUString( aUStr2, kTestStr2Len ), + new OUString(aUStr1)} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + *(arrTestCase[i].input1) = *(arrTestCase[i].input2); + sal_Bool lastRes = (*(arrTestCase[i].input1) == + *(arrTestCase[i].input2)); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "op_eq", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "eq"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator += +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_op_peq( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "peq"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1; delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + {" ' '= ''+='' ", new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), + new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + )}, + {"Ustr1= null += Ustr1", new OUString(aUStr1), + new OUString(), new OUString(aUStr1)}, + {"Ustr1= '' += Ustr1", new OUString(aUStr1), + /*new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + )*/ + new OUString(), + new OUString(aUStr1)}, + {"Ustr1PlusUStr6 = Ustr1 += Ustr6", + new OUString(aUStr1PlusUStr6), new OUString(aUStr1), + new OUString(aUStr6)}, + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + *(arrTestCase[i].input1) += *(arrTestCase[i].input2); + sal_Bool lastRes = (*(arrTestCase[i].expVal) == + *(arrTestCase[i].input1)); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "op_peq", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "peq"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the operator const sal_Unicode * (csuc for short) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_csuc( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "csuc"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Unicode tmpUC=0x0; + rtl_uString* tmpUstring = NULL; + const sal_Char *tmpStr=kTestStr1; + sal_Int32 tmpLen=(sal_Int32) kTestStr1Len; + // sal_Int32 cmpLen = 0; + + rtl_string2UString( &tmpUstring, tmpStr, tmpLen, + osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + OSL_ASSERT(tmpUstring != NULL); + + + typedef struct TestCase + { + sal_Char* comments; + const sal_Unicode* expVal; + sal_Int32 cmpLen; + OUString* input1; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[] = + { + {"test normal ustring",(*tmpUstring).buffer,kTestStr1Len, + new OUString(aUStr1)}, + {"test empty ustring",&tmpUC, 1, new OUString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + const sal_Unicode* pstr = *arrTestCase[i].input1; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + cmpstr((sal_Char*)pstr, + (sal_Char*)arrTestCase[i].expVal, + arrTestCase[i].cmpLen), + arrTestCase[i].comments, + createName( pMeth, "const sal_Unicode*", i ) + ); + } + c_rtl_tres_state_end( hRtlTestResult, "csuc"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method const sal_Unicode * getStr() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_getStr( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "getStr"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Unicode tmpUC=0x0; + rtl_uString* tmpUstring = NULL; + const sal_Char *tmpStr=kTestStr1; + sal_Int32 tmpLen=(sal_Int32) kTestStr1Len; + // sal_Int32 cmpLen = 0; + + rtl_string2UString( &tmpUstring, tmpStr, tmpLen, + osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + OSL_ASSERT(tmpUstring != NULL); + + + typedef struct TestCase + { + sal_Char* comments; + const sal_Unicode* expVal; + sal_Int32 cmpLen; + OUString* input1; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[] = + { + {"test normal ustring",(*tmpUstring).buffer,kTestStr1Len, + new OUString(aUStr1)}, + {"test empty ustring",&tmpUC, 1, new OUString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + const sal_Unicode* pstr = arrTestCase[i].input1->getStr(); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + cmpstr((sal_Char*)pstr, + (sal_Char*)arrTestCase[i].expVal, + arrTestCase[i].cmpLen), + arrTestCase[i].comments, + createName( pMeth, "getStr", i ) + ); + } + c_rtl_tres_state_end( hRtlTestResult, "getStr"); +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the method sal_Int32 reverseCompareTo( const OUString & str ) +//------------------------------------------------------------------------- +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_reverseCompareTo( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "reverseCompareTo"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2;} + } TestCase; + + TestCase arrTestCase[]={ + + {"simple compare, str1 to str5",-1,new OUString(aUStr1), + new OUString(aUStr5) + }, + {"simple compare, str2 to str5",1,new OUString(aUStr2), + new OUString(aUStr5) + }, + {"simple compare, str1 to str9",-1,new OUString(aUStr1), + new OUString(aUStr9) + }, + {"simple compare, str4 to str5",-1,new OUString(aUStr4), + new OUString(aUStr5) + }, + {"simple compare, str5 to str1",+1,new OUString(aUStr5), + new OUString(aUStr1) + }, + {"simple compare, str2 to str1",+1,new OUString(aUStr2), + new OUString(aUStr1) + }, + {"simple compare, str1 to str1",0,new OUString(aUStr1), + new OUString(aUStr1) + }, + {"simple compare, nullString to nullString",0,new OUString(), + new OUString() + }, + {"simple compare, nullString to str2",-1,new OUString(), + new OUString(aUStr2) + }, + {"simple compare, str1 to nullString",+1,new OUString(aUStr1), + new OUString() + } + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 cmpRes = arrTestCase[i].input1->reverseCompareTo + (*arrTestCase[i].input2); + cmpRes = ( cmpRes == 0 ) ? 0 : ( cmpRes > 0 ) ? +1 : -1 ; + sal_Bool lastRes = ( cmpRes == arrTestCase[i].expVal); + + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "compareTo(const OString&)", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "reverseCompareTo"); +// return (res); +} + +//------------------------------------------------------------------------ +// testing the method sal_Bool equalsAscii( const sal_Char* asciiStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equalsAscii( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "equalsAscii"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Char *tmpAstr1="Sun Microsystems\0"; + const sal_Char *tmpAstr2="\0"; + + + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OUString* input1; + const sal_Char* input2; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[]={ + {"str1 with str1 ", sal_True, new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr1}, + {"str2 with str1 ", sal_False,new OUString( kTestStr2, + kTestStr2Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr1}, + {"null with str1 ", sal_False, new OUString(), tmpAstr1}, + {"null with '' ", sal_True, new OUString(), tmpAstr2}, + {"'' with ''", sal_True, new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), + tmpAstr2} + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + + sal_Bool lastRes = (arrTestCase[i].expVal == + arrTestCase[i].input1->equalsAscii(arrTestCase[i].input2)); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equalsAscii", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "equalsAscii"); +// return ( res ); +} + + + +//------------------------------------------------------------------------ +// testing the method sal_Bool equalsAsciiL( +// const sal_Char* asciiStr, sal_Int32 asciiStrLength ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equalsAsciiL( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "equalsAsciiL"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Char *tmpAstr1="Sun Microsystems\0"; + const sal_Char *tmpAstr2="\0"; + const sal_Char *tmpAstr3="Sun Microsystems Java Technology\0"; + + + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OUString* input1; + const sal_Char* input2; + sal_Int32 cmpLen; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[]={ + {"str1 with str1,str1Len ", sal_True, new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr1, kTestStr1Len}, + {"str2 with str1,str1Len", sal_False,new OUString( kTestStr2, + kTestStr2Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr1, kTestStr1Len}, + {"str1 with str2,str1Len", sal_True,new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr3, kTestStr1Len}, + {"null with str1,1 ", sal_False, new OUString(), tmpAstr1, 1}, + {"null with '',1 ", sal_False, new OUString(), tmpAstr2, 1}, + {"'' with '', 1", sal_False, new OUString( "", + 0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), + tmpAstr2, 1} + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + + sal_Bool lastRes = (arrTestCase[i].expVal == + arrTestCase[i].input1->equalsAsciiL(arrTestCase[i].input2, + arrTestCase[i].cmpLen) + ); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equalsAsciiL", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "equalsAsciiL"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method sal_Int32 compareToAscii( const sal_Char* asciiStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_compareToAscii( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "compareToAscii"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Char *tmpAstr1="Sun Microsystems\0"; + const sal_Char *tmpAstr2="\0"; + const sal_Char *tmpAstr3="sun microsystems java technology\0"; + const sal_Char *tmpAstr4="Sun Microsystems Java Technology\0"; + + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUString* input1; + const sal_Char* input2; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[]={ + {"str1 with str1 ", 0, new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr1}, + {"str1 with '' ", 83, new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), tmpAstr2}, + {"null with str1 ", -83 , new OUString(), tmpAstr1}, + {"null with '' ", 0, new OUString(), tmpAstr2}, + {"str1 with str9", -32, new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), + tmpAstr3}, + {"str1 with str2", -32, new OUString( kTestStr1, + kTestStr1Len, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString + ), + tmpAstr4} + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = (arrTestCase[i].expVal == + arrTestCase[i].input1->compareToAscii(arrTestCase[i].input2)); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "equalsAscii", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "compareToAscii"); +// return ( res ); +} + + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Bool b ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf_sal_Bool( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "Bool"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + sal_Bool input1; + + ~TestCase() {delete expVal;} + }TestCase; + + TestCase arrTestCase[]= + { + {"input Bool 'true' and return OUString 'true'", + new OUString("true",4,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + sal_True + }, + {"input Bool 'false' and return OUString 'false'", + new OUString("false",5,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + sal_False + } + }; + + sal_Bool res; + sal_uInt32 i; + + for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) + { + sal_Bool lastRes=(*arrTestCase[i].expVal== + OUString::valueOf(arrTestCase[i].input1) + + ); + + c_rtl_tres_state(hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "valueOf( sal_Bool b )", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "Bool"); +// return(res); +} + +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf_sal_Unicode( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "Unicode"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + sal_Unicode tmpchar1=97; + sal_Unicode tmpchar2=53; + sal_Unicode tmpchar3=0; + sal_Unicode tmpchar4=32; + sal_Unicode tmpchar5=47; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + sal_Unicode input1; + + ~TestCase() {delete expVal;} + }TestCase; + + TestCase arrTestCase[]= + { + {"input Unicode 'a' and return OUString 'a'", + new OUString(&tmpchar1,1),tmpchar1 + }, + {"input Unicode '5' and return OUString '5'", + new OUString(&tmpchar2,1), tmpchar2 + }, + {"input Unicode 0 and return OUString 0", + new OUString(&tmpchar3,1),tmpchar3 + }, + {"input Unicode ' ' and return OUString ' '", + new OUString(&tmpchar4,1),tmpchar4 + }, + {"input Unicode '/' and return OUString ' '", + new OUString(&tmpchar5,1),tmpchar5 + } + }; + + sal_Bool res=sal_True; + sal_uInt32 i; + + for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) + { + sal_Bool lastRes=(*(arrTestCase[i].expVal)== + OUString::valueOf(arrTestCase[i].input1)); + + c_rtl_tres_state(hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "valueOf( sal_Unicode c )", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "Unicode"); +// return(res); +} + + +/** + * Calls the method valueOf(T, radix) and compares + * returned ustrings with ustrings that passed in the array resArray. + * + * @param T, type of argument, passed to valueOf + * @param resArray, array of result ustrings to compare to + * @param n the number of elements in the array resArray (testcases) + * @param pTestResult the instance of the class TestResult + * @param inArray [optional], array of value that is passed as first argument + * to valueOf + * + * @return true, if all returned ustrings are equal to corresponding ustring in + * resArray else, false. + */ +template <class T> +sal_Bool test_valueOf( const char** resArray, int n, sal_Int16 radix, + hTestResult hRtlTestResult, const T *inArray ) +{ + sal_Bool bRes = sal_True; + + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + sal_Int32 i; +// static sal_Unicode aUchar[50]={0x12}; + + for (i = 0; i < n; i++) + { + ::rtl::OUString aStr1; + + OSL_ENSURE( i < 50, "ERROR: leave aUchar bound"); + +// AStringToUStringCopy(aUchar,resArray[i]); +// ::rtl::OUString aStr2(aUchar); + rtl::OUString aStr2; + aStr2 = OUString::createFromAscii(resArray[i]); + + ::rtl::OUString aStr3( "-",1,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString); + + if (inArray == 0) + { + aStr1 = ::rtl::OUString::valueOf((T)i, radix); + } + else + { + if ( inArray[i] < 0 ) + { + sal_Unicode aStr4[100]; + OSL_ASSERT(strlen(resArray[i]) < 100); + + if(AStringToUStringCopy(aStr4,resArray[i])) + { + aStr2 = aStr3; + aStr2 += aStr4; + } + + } + aStr1 = ::rtl::OUString::valueOf((T)inArray[i], radix); + } + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + aStr2.compareTo(aStr1) == 0, + (sal_Char*)resArray[i], + createName( pMeth, "valueOf", i ) + ); + } + + return (bRes); +} + + +#define test_valueOf_Int32 test_valueOf<sal_Int32> +#define test_valueOf_Int64 test_valueOf<sal_Int64> +// LLA: #define test_valueOf_float test_valueOf<float> +// LLA: #define test_valueOf_double test_valueOf<double> + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 ) +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBinaryNumsStr, + kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0 ), + "kRadixBinary", + "valueOf(sal_Int32, radix 2)" + ); + + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kOctolNumsStr, + kOctolNumsCount, kRadixOctol, hRtlTestResult, 0), + "kRadixOctol", + "valueOf(sal_Int32, radix 8)" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kDecimalNumsStr, + kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0), + "kRadixDecimal", + "valueOf(sal_Int32, radix 10)" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kHexDecimalNumsStr, + kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0), + "kRadixHexdecimal", + "valueOf(sal_Int32, radix 16)" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBase36NumsStr, + kBase36NumsCount, kRadixBase36, hRtlTestResult, 0), + "kRadixBase36", + "valueOf(sal_Int32, radix 36)" + ); + + + return ( bRes ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=2 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=8 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=10 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=16 ) +// where l = large constants +// testing the method valueOf( sal_Int32 l, sal_Int32 radix=36 ) +// where l = large constants +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_Bounderies( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBinaryMaxNumsStr, + kInt32MaxNumsCount, kRadixBinary, + hRtlTestResult, kInt32MaxNums), + "kRadixBinary", + "valueOf(salInt32, radix 2) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kOctolMaxNumsStr, + kInt32MaxNumsCount, kRadixOctol, + hRtlTestResult, kInt32MaxNums), + "kRadixOctol", + "valueOf(salInt32, radix 8) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kDecimalMaxNumsStr, + kInt32MaxNumsCount, kRadixDecimal, + hRtlTestResult, kInt32MaxNums), + "kRadixDecimal", + "valueOf(salInt32, radix 10) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kHexDecimalMaxNumsStr, + kInt32MaxNumsCount, kRadixHexdecimal, + hRtlTestResult, kInt32MaxNums), + "kRadixHexdecimal", + "valueOf(salInt32, radix 16) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32((const char**)kBase36MaxNumsStr, + kInt32MaxNumsCount, kRadixBase36, + hRtlTestResult, kInt32MaxNums), + "kRadixBase36", + "valueOf(salInt32, radix 36) Bounderies" + ); + + return ( bRes ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 ) +// for negative value +// testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 ) +// for negative value +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_Negative( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + sal_Int32 inArr[kBase36NumsCount]; + sal_Int32 i; + + for (i = 0; i < kBase36NumsCount; i++ ) + inArr[i] = -i; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kBinaryNumsStr, kBinaryNumsCount, + kRadixBinary, hRtlTestResult, inArr ), + "negative Int32, kRadixBinary", + "valueOf( negative Int32, radix 2 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kOctolNumsStr, kOctolNumsCount, + kRadixOctol, hRtlTestResult, inArr ), + "negative Int32, kRadixOctol", + "valueOf( negative Int32, radix 8 )" + ); + + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kDecimalNumsStr, kDecimalNumsCount, + kRadixDecimal, hRtlTestResult, inArr ), + "negative Int32, kRadixDecimal", + "valueOf( negative Int32, radix 10 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kHexDecimalNumsStr, kHexDecimalNumsCount, + kRadixHexdecimal, hRtlTestResult, inArr ), + "negative Int32, kRadixHexdecimal", + "valueOf( negative Int32, radix 16 )" + ); + + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int32( kBase36NumsStr, kBase36NumsCount, + kRadixBase36, hRtlTestResult, inArr ), + "negative Int32, kRadixBase36", + "valueOf( negative Int32, radix 36 )" + ); + + return ( bRes ); +} +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int32 l, sal_Int32 radix ) where radix = -5 +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_WrongRadix( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + sal_Int32 intVal = 11; + + ::rtl::OUString aStr1; + ::rtl::OUString aStr2("11",2,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString); + + aStr1 = aStr1.valueOf( intVal, -5 ); + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + aStr2.compareTo( aStr1 ) == 0, + "if radix not valid then radix must be 10", + "valueOf(sal_Int32, sal_Int32 radix): radix = -5" + ); + + return (bRes); +} + + +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_defaultParam( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + sal_Char* newUChar1="15"; + sal_Char* newUChar2="0"; + sal_Char* newUChar3="-15"; + sal_Char* newUChar4="2147483647"; + sal_Char* newUChar5="-2147483648"; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 input1; + OUString* expVal; + ~TestCase() {delete expVal;} + }TestCase; + + TestCase arrTestCase[]= + { + {"input Int32 15 and return OUString 15",15, + new OUString(newUChar1,2,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int32 0 and return OUString 0",0, + new OUString(newUChar2,1,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int32 -15 and return OUString -15",-15, + new OUString(newUChar3,3,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int32 2147483647 and return OUString 2147483647", SAL_MAX_INT32 /* 2147483647 */, + new OUString(newUChar4,10,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int32 -2147483648 and return OUString -2147483648", + SAL_MIN_INT32 /* 2-2147483648 */, + new OUString(newUChar5,11,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + } + }; + + sal_Bool res=sal_True; + sal_uInt32 i; + + for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) + { + sal_Bool lastRes=(*(arrTestCase[i].expVal)== + OUString::valueOf(arrTestCase[i].input1)); + + c_rtl_tres_state(hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, + "valueOf( sal_Int32 i, sal_Int16 radix = 10 )", i ) + ); + + res &= lastRes; + } + + return(res); + +} +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 ) +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBinaryNumsStr, + kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0), + "kRadixBinary", + "valueOf(sal_Int64, radix 2)_" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kOctolNumsStr, + kOctolNumsCount, kRadixOctol, hRtlTestResult, 0), + "kRadixOctol", + "valueOf(sal_Int64, radix 8)_" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kDecimalNumsStr, + kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0), + "kRadixDecimal", + "valueOf(sal_Int64, radix 10)_" + ); + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kHexDecimalNumsStr, + kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0), + "kRadixHexdecimal", + "valueOf(sal_Int64, radix 16)_" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBase36NumsStr, + kBase36NumsCount, kRadixBase36, hRtlTestResult, 0), + "kRadixBase36", + "valueOf(sal_Int64, radix 36)_" + ); + + return (bRes); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=2 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=8 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=10 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=16 ) +// where l = large constants +// testing the method valueOf( sal_Int64 l, sal_Int32 radix=36 ) +// where l = large constants +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_Bounderies( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBinaryMaxNumsStr, + kInt64MaxNumsCount, kRadixBinary, + hRtlTestResult, kInt64MaxNums), + "kRadixBinary", + "valueOf(salInt64, radix 2) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kOctolMaxNumsStr, + kInt64MaxNumsCount, kRadixOctol, + hRtlTestResult, kInt64MaxNums), + "kRadixOctol", + "valueOf(salInt64, radix 8) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kDecimalMaxNumsStr, + kInt64MaxNumsCount, kRadixDecimal, + hRtlTestResult, kInt64MaxNums), + "kRadixDecimal", + "valueOf(salInt64, radix 10) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kHexDecimalMaxNumsStr, + kInt64MaxNumsCount, kRadixHexdecimal, + hRtlTestResult, kInt64MaxNums), + "kRadixHexdecimal", + "valueOf(salInt64, radix 16) Bounderies" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64((const char**)kBase36MaxNumsStr, + kInt64MaxNumsCount, kRadixBase36, + hRtlTestResult, kInt64MaxNums), + "kRadixBase36", + "valueOf(salInt64, radix 36) Bounderies" + ); + + return ( bRes ); +} + +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 ) +// for negative value +// testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 ) +// for negative value +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_Negative( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + sal_Int64 inArr[36]; + sal_Int32 i; + + for (i = 0; i < 36; i++) { + inArr[i] = -i; + } + + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kBinaryNumsStr, kBinaryNumsCount, + kRadixBinary, hRtlTestResult, inArr ), + "negative Int64, kRadixBinary", + "valueOf( negative Int64, radix 2 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kOctolNumsStr, kOctolNumsCount, + kRadixOctol, hRtlTestResult, inArr ), + "negative Int64, kRadixOctol", + "valueOf( negative Int64, radix 8 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kDecimalNumsStr, kDecimalNumsCount, + kRadixDecimal, hRtlTestResult, inArr ), + "negative Int64, kRadixDecimal", + "valueOf( negative Int64, radix 10 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kHexDecimalNumsStr, kHexDecimalNumsCount, + kRadixHexdecimal, hRtlTestResult, inArr ), + "negative Int64, kRadixHexDecimal", + "valueOf( negative Int64, radix 16 )" + ); + + bRes &= c_rtl_tres_state + ( + hRtlTestResult, + test_valueOf_Int64( kBase36NumsStr, kBase36NumsCount, + kRadixBase36, hRtlTestResult, inArr), + "negative Int64, kRadixBase36", + "valueOf( negative Int64, radix 36 )" + ); + + return (bRes); +} +//------------------------------------------------------------------------ +// testing the method valueOf( sal_Int64 l, sal_Int32 radix ) +// where radix = -5 +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_WrongRadix( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes = sal_False; + + sal_Int64 intVal = 11; + + ::rtl::OUString aStr1; + ::rtl::OUString aStr2("11",2,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString); + + aStr1 = aStr1.valueOf( intVal, -5 ); + + bRes = c_rtl_tres_state + ( + hRtlTestResult, + aStr2.compareTo(aStr1) == 0, + "if radix not valid then radix must be 10", + "valueOf(sal_Int64, sal_Int32 radix): radix = -5" + ); + + return (bRes); +} + +//------------------------------------------------------------------------ +static sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_defaultParam( + hTestResult hRtlTestResult ) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + sal_Char* newUChar1="15"; + sal_Char* newUChar2="0"; + sal_Char* newUChar3="-15"; + sal_Char* newUChar4= "9223372036854775807"; + sal_Char* newUChar5="-9223372036854775808"; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int64 input1; + OUString* expVal; + ~TestCase() {delete expVal;} + }TestCase; + + TestCase arrTestCase[]= + { + {"input Int64 15 and return OUString 15",15, + new OUString(newUChar1,2,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int64 0 and return OUString 0",0, + new OUString(newUChar2,1,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int64 -15 and return OUString -15",-15, + new OUString(newUChar3,3,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int64 9223372036854775807 and return 9223372036854775807", + SAL_MAX_INT64 /* 9223372036854775807*/, + new OUString(newUChar4,19,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + {"input Int64 -9223372036854775808 and return -9223372036854775808", + SAL_MIN_INT64 /* 9223372036854775808*/, + new OUString(newUChar5,20,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + } + }; + + sal_Bool res=sal_True; + sal_uInt32 i; + + for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) + { + sal_Bool lastRes=(*(arrTestCase[i].expVal)== + OUString::valueOf(arrTestCase[i].input1)); + + c_rtl_tres_state(hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, + "valueOf( sal_Int64 i, sal_Int16 radix = 10 )", i ) + ); + + res &= lastRes; + } + + return(res); + +} +//------------------------------------------------------------------------ +// testing the method valueOf( float f ) +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_float( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: float input1; +// LLA: OUString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: { "3.0", 3.0, new OUString("3.0",3,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString) }, +// LLA: { "3.5", 3.5f, new OUString("3.5",3,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: { "3.0625", 3.0625f, new OUString("3.0625",6,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: { "3.502525", 3.502525f, new OUString("3.502525",8, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, +// LLA: { "3.141592", 3.141592f, new OUString("3.141592",8, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, +// LLA: { "3.5025255", 3.5025255f, new OUString("3.5025255",9, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, +// LLA: { "3.0039062", 3.00390625f, new OUString("3.0039062",9, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) } +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OUString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_float", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method valueOf( float f ) for negative value +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_Float_Negative( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: float input1; +// LLA: OUString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: { "-3.0", -3.0, new OUString("-3.0",4,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString) }, +// LLA: { "-3.5", -3.5f, new OUString("-3.5",4,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: { "-3.0625", -3.0625f, new OUString("-3.0625",7, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, +// LLA: { "-3.502525", -3.502525f, new OUString("-3.502525",9, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, +// LLA: { "-3.141592", -3.141592f, new OUString("-3.141592",9, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, +// LLA: { "-3.5025255", -3.5025255f, new OUString("-3.5025255",10, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, +// LLA: { "-3.0039062", -3.00390625f, new OUString("-3.0039062",10, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) } +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OUString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_negative float", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method valueOf( double f ) +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_double( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: double input1; +// LLA: OUString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: {"3.0", 3.0, new OUString("3.0",3,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"3.5", 3.5, new OUString("3.5",3,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"3.0625", 3.0625, new OUString("3.0625",6,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"3.1415926535", 3.1415926535, new OUString("3.1415926535",12, +// LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, +// LLA: {"3.1415926535897931", 3.141592653589793, +// LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"3.1415926535897931", 3.1415926535897932, +// LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"3.1415926535897931", 3.14159265358979323, +// LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"3.1415926535897931", 3.141592653589793238462643, +// LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)} +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OUString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_double", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + + +//------------------------------------------------------------------------ +// testing the method valueOf( double f ) for negative value +//------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_Double_Negative( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Char methName[MAXBUFLENGTH]; +// LLA: sal_Char* pMeth =methName; +// LLA: +// LLA: typedef struct TestCase +// LLA: { +// LLA: sal_Char* comments; +// LLA: double input1; +// LLA: OUString* expVal; +// LLA: +// LLA: ~TestCase() {delete expVal;} +// LLA: } TestCase; +// LLA: +// LLA: TestCase arrTestCase[] = +// LLA: { +// LLA: {"-3.0", -3.0, new OUString("-3.0",4,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.5", -3.5, new OUString("-3.5",4,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.0625", -3.0625, new OUString("-3.0625",7,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.1415926535", -3.1415926535, +// LLA: new OUString("-3.1415926535",13,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.1415926535897931", -3.141592653589793, +// LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.1415926535897931", -3.1415926535897932, +// LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.1415926535897931", -3.14159265358979323, +// LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)}, +// LLA: {"-3.1415926535897931", -3.141592653589793238462643, +// LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, +// LLA: kConvertFlagsOStringToOUString)} +// LLA: }; +// LLA: +// LLA: sal_Bool res = sal_True; +// LLA: sal_Int32 i; +// LLA: +// LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) +// LLA: { +// LLA: ::rtl::OUString aStr1; +// LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); +// LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); +// LLA: +// LLA: c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: lastRes, +// LLA: arrTestCase[i].comments, +// LLA: createName( pMeth, "valueof_nagative double", i) +// LLA: ); +// LLA: +// LLA: res &= lastRes; +// LLA: +// LLA: } +// LLA: +// LLA: return ( res ); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method valueOf() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "valueOf"); + sal_Bool bTState = test_rtl_OUString_valueOf_Int32( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int32_Bounderies( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int32_Negative( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int32_WrongRadix( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int32_defaultParam( + hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int64( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int64_Bounderies( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int64_Negative( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int64_WrongRadix( hRtlTestResult ); + bTState &= test_rtl_OUString_valueOf_Int64_defaultParam( + hRtlTestResult ); + // LLA: bTState &= test_rtl_OUString_valueOf_float( hRtlTestResult ); + // LLA: bTState &= test_rtl_OUString_valueOf_Float_Negative( hRtlTestResult ); + + // LLA: bTState &= test_rtl_OUString_valueOf_double( hRtlTestResult ); + // LLA: bTState &= test_rtl_OUString_valueOf_Double_Negative( hRtlTestResult ); + c_rtl_tres_state_end( hRtlTestResult, "valueOf"); +// return ( bTState ); +} +//------------------------------------------------------------------------ +// this is my testing code +// testing the method createFromAscii( const sal_Char * value ) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_createFromAscii( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "createFromAscii"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + + typedef struct TestCase + { + sal_Char* comments; + const sal_Char* input1; + OUString* expVal; + ~TestCase() {delete expVal;} + + }TestCase; + + TestCase arrTestCase[]= + { + + { "create OUString from sal_Char" ,kTestStr1, + new OUString(kTestStr1,kTestStr1Len,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }, + { + "create OUString from empty", "", + new OUString() + }, + { + "create OUString from empty(string arg = '\\0')","", + new OUString("",0,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + } + + }; + + sal_Bool res; + sal_uInt32 i; + + for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) + { + sal_Bool lastRes=(*(arrTestCase[i].expVal)== + OUString::createFromAscii(arrTestCase[i].input1)); + + + { + c_rtl_tres_state(hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "createFromAscii", i ) + ); + } + + res&=lastRes; + + } + + c_rtl_tres_state_end( hRtlTestResult, "createFromAscii"); +// return(res); +} +//------------------------------------------------------------------------ +// testing the method index( ) +//------------------------------------------------------------------------ +template <class T> +sal_Bool test_index( const T* input1, int num,const sal_Int32* input2, + const sal_Int32* expVal,int base,rtlTestResult hRtlTestResult) +{ + sal_Bool res=sal_True; + sal_Char methName[MAXBUFLENGTH]; + sal_Char *meth = '\0'; + sal_Char* pMeth=methName; + sal_Int32 i; + sal_Bool lastRes=sal_False; + + for(i=0;i<num;i++) + { + OUString str(aUStr2); + + if(base==0) + { + lastRes=(str.indexOf(input1[i])==expVal[i]); + meth="indexOf_001"; + } + if(base==1) + { + lastRes=(str.indexOf(input1[i],input2[i])==expVal[i]); + meth="indexOf_002"; + } +// LLA: if(base==2) +// LLA: { +// LLA: lastRes=(str.lastIndexOf(input1[i])==expVal[i]); +// LLA: meth="lastIndexOf_001(sal_Unicode)"; +// LLA: } +// LLA: if(base==3) +// LLA: { +// LLA: /* +// LLA: OUString s4(&input1[i]); +// LLA: rtl::OString sStr; +// LLA: sStr <<= str; +// LLA: t_print("str = %s\n", sStr.getStr()); +// LLA: rtl::OString sInput1; +// LLA: sInput1 <<= s4; // rtl::OUString((sal_Unicode*)input1[i]); +// LLA: t_print("%d = lastIndexOf(\"%s\", %d) =? %d\n", str.lastIndexOf(input1[i], input2[i]), sInput1.getStr(), input2[i], expVal[i]); +// LLA: */ +// LLA: lastRes=(str.lastIndexOf(input1[i],input2[i])==expVal[i]); +// LLA: meth="lastIndexOf_002(sal_Unicode , sal_Int32 )"; +// LLA: } + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + "index", + createName( pMeth,meth, i ) + ); + + res &= lastRes; + } + + return( res ); +} +template <class T> +sal_Bool test_indexStr( const T** input1, int num,const sal_Int32* input2, + const sal_Int32* expVal,int base,rtlTestResult hRtlTestResult) +{ + sal_Bool res=sal_True; + sal_Char methName[MAXBUFLENGTH]; + sal_Char *meth = '\0'; + sal_Char* pMeth=methName; + sal_Int32 i; + sal_Bool lastRes=sal_False; + + for(i=0;i<num;i++) + { + OUString str(aUStr2); + + + if(base==0) + { + OUString s1(input1[i]); + lastRes=(str.indexOf(s1)==expVal[i]); + meth="indexOf_003"; + } + if(base==1) + { + OUString s2(input1[i]); + lastRes=(str.indexOf(s2,input2[i])==expVal[i]); + meth="indexOf_004"; + } +// LLA: if(base==2) +// LLA: { +// LLA: OUString s3(input1[i]); +// LLA: lastRes=(str.lastIndexOf(s3)==expVal[i]); +// LLA: meth="lastIndexOf_003(const OUString)"; +// LLA: } +// LLA: if(base==3) +// LLA: { +// LLA: OUString s4(input1[i]); +// LLA: +// LLA: rtl::OString sStr; +// LLA: sStr <<= str; +// LLA: t_print("str = \"%s\"\n", sStr.getStr()); +// LLA: rtl::OString sInput1; +// LLA: sInput1 <<= s4; // rtl::OUString((sal_Unicode*)input1[i]); +// LLA: t_print("%d = lastIndexOf(\"%s\", %d) =? %d\n", str.lastIndexOf(input1[i], input2[i]), sInput1.getStr(), input2[i], expVal[i]); +// LLA: +// LLA: lastRes=(str.lastIndexOf(s4,input2[i])==expVal[i]); +// LLA: meth="lastIndexOf_004(const OUString,sal_Int32)"; +// LLA: } + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + "index", + createName( pMeth,meth, i ) + ); + + res &= lastRes; + } + + return( res ); +} +//------------------------------------------------------------------------ +// testing the method indexOf( ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_indexOf_001( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes=sal_False; + + bRes=c_rtl_tres_state + ( + hRtlTestResult, + test_index<sal_Unicode>((const sal_Unicode*)input1Default, + nDefaultCount,input2Default, + expValDefault,0,hRtlTestResult), + "index", + "indexDefault(sal_Unicode ch, sal_Int32 fromIndex = 0)" + ); + + return ( bRes ); +} +//------------------------------------------------------------------------ +// testing the method indexOf( ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_indexOf_002( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes=sal_False; + + bRes=c_rtl_tres_state + ( + hRtlTestResult, + test_index<sal_Unicode>((const sal_Unicode*)input1Normal, + nNormalCount,input2Normal, + expValNormal,1,hRtlTestResult), + "index", + "indexNormal(sal_Unicode ch, sal_Int32 fromIndex)" + ); + + return ( bRes ); +} +//------------------------------------------------------------------------ +// testing the method indexOf( OUString ch, sal_Int32 fromIndex = 0 ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_indexOf_003( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes=sal_False; + + bRes=c_rtl_tres_state + ( + hRtlTestResult, + test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrDefault, + nStrDefaultCount,input2StrDefault, + expValStrDefault,0,hRtlTestResult), + "index", + "indexDefault(OUString ch, sal_Int32 fromIndex = 0)" + ); + + return ( bRes ); +} +//------------------------------------------------------------------------ +// testing the method indexOf( OUString ch, sal_Int32 fromIndex ) +//------------------------------------------------------------------------ +sal_Bool SAL_CALL test_rtl_OUString_indexOf_004( + hTestResult hRtlTestResult ) +{ + sal_Bool bRes=sal_False; + + bRes=c_rtl_tres_state + ( + hRtlTestResult, + test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrNormal, + nStrNormalCount,input2StrNormal, + expValStrNormal,1,hRtlTestResult), + "indexOf", + "indexOf(OUString ch, sal_Int32 fromIndex)" + ); + + return ( bRes ); +} +// LLA: //------------------------------------------------------------------------ +// LLA: // testing the method lastIndexOf( sal_Unicode ch ) +// LLA: //------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_001( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Bool bRes=sal_False; +// LLA: +// LLA: bRes=c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: test_index<sal_Unicode>((const sal_Unicode*)input1lastDefault, +// LLA: nlastDefaultCount,input2lastDefault, +// LLA: expVallastDefault,2,hRtlTestResult), +// LLA: "lastIndex", +// LLA: "lastIndexDefault(sal_Unicode ch)" +// LLA: ); +// LLA: +// LLA: return ( bRes ); +// LLA: } +// LLA: //------------------------------------------------------------------------ +// LLA: // testing the method lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) +// LLA: //------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_002( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Bool bRes=sal_False; +// LLA: +// LLA: bRes=c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: test_index<sal_Unicode>((const sal_Unicode*)input1lastNormal, +// LLA: nlastNormalCount,input2lastNormal, +// LLA: expVallastNormal,3,hRtlTestResult), +// LLA: "lastIndex", +// LLA: "lastIndexNormal(sal_Unicode ch, sal_Int32 fromIndex)" +// LLA: ); +// LLA: +// LLA: return ( bRes ); +// LLA: } +// LLA: //------------------------------------------------------------------------ +// LLA: // testing the method lastIndexOf( OUString ch ) +// LLA: //------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_003( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Bool bRes=sal_False; +// LLA: +// LLA: bRes=c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrLastDefault, +// LLA: nStrLastDefaultCount,input2StrLastDefault, +// LLA: expValStrLastDefault,2,hRtlTestResult), +// LLA: "lastIndexOf", +// LLA: "lastIndexOf(OUString ch)" +// LLA: ); +// LLA: +// LLA: return ( bRes ); +// LLA: } +// LLA: //------------------------------------------------------------------------ +// LLA: // testing the method lastIndexOf( OUString ch, sal_Int32 fromIndex ) +// LLA: //------------------------------------------------------------------------ +// LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_004( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: sal_Bool bRes=sal_False; +// LLA: +// LLA: for (int i=0;i<nStrLastNormalCount;i++) +// LLA: { +// LLA: rtl::OUString aStr = rtl::OUString(input1StrLastNormal[i]); +// LLA: volatile int dummy = 0; +// LLA: } +// LLA: +// LLA: bRes=c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrLastNormal, +// LLA: nStrLastNormalCount,input2StrLastNormal, +// LLA: expValStrLastNormal,3,hRtlTestResult), +// LLA: "lastIndexOf", +// LLA: "lastIndexOf(OUString ch, sal_Int32 fromIndex)" +// LLA: ); +// LLA: +// LLA: return ( bRes ); +// LLA: } +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_indexOf( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "indexOf"); + sal_Bool res = test_rtl_OUString_indexOf_001(hRtlTestResult); + res &= test_rtl_OUString_indexOf_002(hRtlTestResult); + res &= test_rtl_OUString_indexOf_003(hRtlTestResult); + res &= test_rtl_OUString_indexOf_004(hRtlTestResult); + c_rtl_tres_state_end( hRtlTestResult, "indexOf"); +// return ( res ); +} +//------------------------------------------------------------------------ +// LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_lastIndexOf( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: c_rtl_tres_state_start( hRtlTestResult, "lastIndexOf"); +// LLA: sal_Bool res = test_rtl_OUString_lastIndexOf_001(hRtlTestResult); +// LLA: res &= test_rtl_OUString_lastIndexOf_002(hRtlTestResult); +// LLA: res &= test_rtl_OUString_lastIndexOf_003(hRtlTestResult); +// LLA: res &= test_rtl_OUString_lastIndexOf_004(hRtlTestResult); +// LLA: c_rtl_tres_state_end( hRtlTestResult, "lastIndexOf"); +// LLA: // return ( res ); +// LLA: } +//------------------------------------------------------------------------ +// testing the method concat( const OString & aStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_concat( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "concat"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input1; + OUString* input2; + ~TestCase() { delete input1;delete input2; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"concatenates two ustrings",new OUString(aUStr1), + new OUString(aUStr7), new OUString(aUStr8)}, + {"concatenates empty ustring",new OUString(aUStr1), + new OUString(aUStr1), new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, + {"concatenates to empty ustring",new OUString(aUStr1),new OUString("", + 0,kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString(aUStr1)}, + {"concatenates two empty ustrings",new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, + {"concatenates ustring constructed by default constructor", + new OUString(aUStr1),new OUString(aUStr1), new OUString()}, + {"concatenates to ustring constructed by default constructor", + new OUString(aUStr1),new OUString(), new OUString(aUStr1)}, + {"concatenates two ustrings constructed by default constructor", + new OUString(),new OUString(), new OUString()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OUString str = arrTestCase[i].input1->concat(*arrTestCase[i].input2); + sal_Bool lastRes = (str == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "concat", i) + ); + + res &= lastRes; + + } + c_rtl_tres_state_end( hRtlTestResult, "concat"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method replaceAt( sal_Int32 index, sal_Int32 count, +// const OUString& newStr ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_replaceAt( + rtlTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "replaceAt"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input; + OUString* newStr; + sal_Int32 index; + sal_Int32 count; + + ~TestCase() { delete input; delete expVal; delete newStr;} + } TestCase; + + TestCase arrTestCase[]= + { + + { "string differs", new OUString(aUStr2), new OUString(aUStr22), + new OUString(aUStr2), 0, kTestStr22Len }, + + { "larger index", new OUString(aUStr1), new OUString(aUStr7), + new OUString(aUStr8), 64, kTestStr8Len }, + + { "larger count", new OUString(aUStr2), new OUString(aUStr22), + new OUString(aUStr2),0, 64 }, + + { "navigate index", new OUString(aUStr2), new OUString(aUStr22), + new OUString(aUStr2), -64, 64 }, + + { "null ustring", + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString(aUStr14), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + 0, kTestStr14Len } + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + ::rtl::OUString aStr1; + aStr1 = arrTestCase[i].input->replaceAt( arrTestCase[i].index, + arrTestCase[i].count, *arrTestCase[i].newStr ); + + sal_Bool lastRes = ( arrTestCase[i].expVal->compareTo(aStr1) == 0 ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "replaceAt", i ) + + ); + res &= lastRes; + } + + c_rtl_tres_state_end( hRtlTestResult, "replaceAt"); +// return ( res ); +} +//------------------------------------------------------------------------ +// this is my testing code +// testing the method replace( sal_Unicode oldChar, sal_Unicode newChar ) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_replace( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "replace"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input; + sal_Unicode oldChar; + sal_Unicode newChar; + + ~TestCase() { delete input; delete expVal;} + } TestCase; + + TestCase arrTestCase[]= + { + {"ustring differs", new OUString(aUStr18), new OUString(aUStr4),83,115}, + {"ustring differs", new OUString(aUStr19), new OUString(aUStr17),32,45}, + {"ustring must be empty", new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString),83,23}, + {"ustring must be empty", new OUString(), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString),83,23}, + {"same ustring, no replace ", new OUString(aUStr22), + new OUString(aUStr22),42,56} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + ::rtl::OUString aStr1; + aStr1= arrTestCase[i].input->replace(arrTestCase[i].oldChar,arrTestCase[i].newChar); + res &= c_rtl_tres_state + ( + hRtlTestResult, + (arrTestCase[i].expVal->compareTo(aStr1) == 0), + arrTestCase[i].comments, + createName( pMeth, "replace", i ) + + ); + } + c_rtl_tres_state_end( hRtlTestResult, "replace"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method toAsciiLowerCase() +//----------------------------------------------------------------------- +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toAsciiLowerCase( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "toAsciiLowerCase"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input1; + ~TestCase() { delete input1; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + + {"only uppercase",new OUString(aUStr5),new OUString(aUStr4)}, + {"different cases",new OUString(aUStr5),new OUString(aUStr1)}, + {"different cases",new OUString(aUStr5),new OUString(aUStr3)}, + {"only lowercase",new OUString(aUStr5),new OUString(aUStr5)}, + {"empty ustring",new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, + {"ustring constructed by default constructor",new OUString(), + new OUString()}, + {"have special Unicode",new OUString("\23\12\34sun\13\45",6, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("\23\12\34sun\13\45",6, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + sal_Bool lastRes=sal_False; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OUString str = arrTestCase[i].input1->toAsciiLowerCase(); + if(i<=5) + { + lastRes = (str ==* arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "toAsciiLowerCase", i) + ); + } + else + { + c_rtl_tres_state + ( + hRtlTestResult, + sal_True, + arrTestCase[i].comments, + createName( pMeth, "toAsciiLowerCase", i) + ); + } + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "toAsciiLowerCase"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method toAsciiUpperCase() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toAsciiUpperCase( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "toAsciiUpperCase"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input1; + ~TestCase() { delete input1; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"only lowercase",new OUString(aUStr4),new OUString(aUStr5)}, + {"mixed cases",new OUString(aUStr4),new OUString(aUStr3)}, + {"mixed cases",new OUString(aUStr4),new OUString(aUStr1)}, + {"only uppercase",new OUString(aUStr4),new OUString(aUStr4)}, + {"empty ustring",new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("",0, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, + {"ustring constructed by default constructor",new OUString(), + new OUString()}, + {"have special Unicode",new OUString("\23\12\34SUN\13\45",6, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), + new OUString("\23\12\34sun\13\45",6, + kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + sal_Bool lastRes=sal_False; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OUString str = arrTestCase[i].input1->toAsciiUpperCase(); + if(i<=5) + { + lastRes = (str == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "toAsciiUpperCase", i) + ); + } + else + { + c_rtl_tres_state + ( + hRtlTestResult, + sal_True, + arrTestCase[i].comments, + createName( pMeth, "toAsciiUpperCase", i) + ); + } + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "toAsciiUpperCase"); +// return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method trim() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_trim( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "trim"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth =methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUString* input1; + ~TestCase() { delete input1; delete expVal;} + } TestCase; + + TestCase arrTestCase[] = + { + {"removes space from the front",new OUString(aUStr1), + new OUString(aUStr10)}, + {"removes space from the end",new OUString(aUStr1), + new OUString(aUStr11)}, + {"removes space from the front and end",new OUString(aUStr1), + new OUString(aUStr12)}, + {"removes several spaces from the end",new OUString(aUStr1), + new OUString(aUStr13)}, + {"removes several spaces from the front",new OUString(aUStr1), + new OUString(aUStr14)}, + {"removes several spaces from the front and one from the end", + new OUString(aUStr1), + new OUString(aUStr15)}, + {"removes one space from the front and several from the end", + new OUString(aUStr1), + new OUString(aUStr16)}, + {"removes several spaces from the front and end", + new OUString(aUStr1), + new OUString(aUStr17)}, + {"removes characters that have codes <= 32",new OUString(aUStr30), + new OUString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50", + 18,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"removes characters that have codes <= 32",new OUString(aUStr28), + new OUString("\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\1", + 18,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"removes characters that have codes <= 32",new OUString(aUStr29), + new OUString("\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50", + 18,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"removes characters that have codes <= 32",new OUString(aUStr20), + new OUString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\23\20", + 18,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"no spaces",new OUString(aUStr8), + new OUString(aUStr8)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + OUString strRes = arrTestCase[i].input1->trim(); + sal_Bool lastRes = (strRes == *arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "trim", i) + ); + + res &= lastRes; + + } + c_rtl_tres_state_end( hRtlTestResult, "trim"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method toData() +//------------------------------------------------------------------------ + +template <class T> +sal_Bool test_toData( const char** input, int num, sal_Int16 radix, + const T* expVal,int base, + const T* _fPrecision, + rtlTestResult hRtlTestResult) +{ + (void)_fPrecision; + sal_Bool res=sal_True; + sal_Char methName[MAXBUFLENGTH]; + sal_Char *meth = '\0'; + sal_Char* pMeth=methName; + sal_Int32 i; +// static sal_Unicode aUchar[60]={0x00}; + T intRes; + sal_Bool lastRes=sal_False; + + for(i=0;i<num;i++) + { + OSL_ENSURE( i < 60, "ERROR: leave aUchar bound"); + +// LLA: stored for the posterity +// AStringToUStringCopy(aUchar,input[i]); +// OUString str(aUchar); + + OUString str; + str = OUString::createFromAscii(input[i]); + + + if(base==0) + { + intRes=static_cast<T>(str.toInt32()); + lastRes=(intRes==expVal[i]); + meth="toInt32default"; + } + if(base==1) + { + intRes=static_cast<T>(str.toInt32(radix)); + lastRes=(intRes==expVal[i]); + meth="toInt32normal"; + } + if(base==2) + { + intRes=static_cast<T>(str.toInt64()); + lastRes=(intRes==expVal[i]); + meth="toInt64default"; + } + if(base==3) + { + intRes=static_cast<T>(str.toInt64(radix)); + lastRes=(intRes==expVal[i]); + meth="toInt64normal"; + } +// LLA: does no longer exist, moved to rtl/oustring +// LLA: if(base==4) +// LLA: { +// LLA: intRes=str.toDouble(); +// LLA: lastRes=(fabs(intRes-expVal[i])<=1e-35); +// LLA: meth="toDouble"; +// LLA: } + +// LLA: dt:20040802 create compile problems within wntmsci10 +// if(base==5) +// { +// intRes=str.toFloat(); +// T nPrec = _fPrecision[i]; +// lastRes=(fabs((T)(intRes-expVal[i])) <= nPrec /* 1e-35 */ ); +// meth="toFloat"; +// } + if(base==6) + { + intRes=str.toChar(); + lastRes=(intRes==expVal[i]); + meth="toChar"; + } + + char buf[MAXBUFLENGTH]; + buf[0] = '\''; + cpynstr( buf + 1, input[i], MAXBUFLENGTH ); + int length = AStringLen( input[i] ); + buf[length + 1] = '\''; + buf[length + 2] = 0; + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + buf, + createName( pMeth,meth, i ) + ); + + res &= lastRes; + } + + return( res ); +} +//------------------------------------------------------------------------ +// testing the method toDouble() +//------------------------------------------------------------------------ + +// LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toDouble( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: c_rtl_tres_state_start( hRtlTestResult, "toDouble"); +// LLA: sal_Bool bRes=sal_False; +// LLA: +// LLA: bRes=c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: test_toData<double>((const char**)inputDouble,nDoubleCount,10, +// LLA: expValDouble,4,hRtlTestResult), +// LLA: "toDouble", +// LLA: "toDouble()" +// LLA: ); +// LLA: c_rtl_tres_state_end( hRtlTestResult, "toDouble"); +// LLA: // return ( bRes ); +// LLA: } + +//------------------------------------------------------------------------ +// testing the method toFloat() +//------------------------------------------------------------------------ +// LLA: dt:20040802 the test_toData() has compile problems. +// LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toFloat( +// LLA: hTestResult hRtlTestResult ) +// LLA: { +// LLA: c_rtl_tres_state_start( hRtlTestResult, "toFloat"); +// LLA: sal_Bool bRes=sal_False; +// LLA: +// LLA: bRes=c_rtl_tres_state +// LLA: ( +// LLA: hRtlTestResult, +// LLA: test_toData<float>((const char**)inputFloat, +// LLA: nFloatCount, +// LLA: 10, /* radix */ +// LLA: expValFloat, +// LLA: 5, /* float */ +// LLA: fPrecision, +// LLA: hRtlTestResult), +// LLA: "toFloat", +// LLA: "toFloat()" +// LLA: ); +// LLA: +// LLA: c_rtl_tres_state_end( hRtlTestResult, "toFloat"); +// LLA: // return ( bRes ); +// LLA: +// LLA: } +//------------------------------------------------------------------------ +// testing the method toChar() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toChar( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "toChar"); + sal_Bool bRes=sal_False; + + bRes=c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Unicode>((const char**)inputChar,nCharCount, + 10,expValChar,6,NULL,hRtlTestResult), + "toChar", + "toChar()" + ); + + c_rtl_tres_state_end( hRtlTestResult, "toChar"); +// return ( bRes ); + +} +//------------------------------------------------------------------------ +// testing the method toBoolean() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toBoolean( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "toBoolean"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Bool expVal; + OUString* input; + + ~TestCase() {delete input;} + }TestCase; + + TestCase arrTestCase[]={ + + {"expected true", sal_True, new OUString("True",4,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"expected false", sal_False, new OUString("False",5, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)}, + {"expected true", sal_True, new OUString("1",1,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString)} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool bRes = arrTestCase[i].input->toBoolean(); + sal_Bool lastRes = (bRes == arrTestCase[i].expVal); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "toBoolean", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "toBoolean"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method toInt32() +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUString_toInt32_normal( + hTestResult hRtlTestResult ) +{ + sal_Int32 expValues[kBase36NumsCount]; + sal_Int32 i; + + for ( i = 0; i < kBase36NumsCount; i++ ) + expValues[i] = i; + + sal_Bool res = c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kBinaryNumsStr,kBinaryNumsCount, + kRadixBinary,expValues,1,NULL,hRtlTestResult ), + "kBinaryNumsStr", + "toInt32( radix 2 )" + ); + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kBinaryMaxNumsStr,kInt32MaxNumsCount, + kRadixBinary,kInt32MaxNums,1,NULL,hRtlTestResult ), + "kBinaryMaxNumsStr", + "toInt32_Boundaries( radix 2 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kOctolNumsStr,kOctolNumsCount, + kRadixOctol,expValues,1,NULL,hRtlTestResult ), + "kOctolNumsStr", + "toInt32( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kOctolMaxNumsStr,kInt32MaxNumsCount, + kRadixOctol,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), + "kOctolMaxNumsStr", + "toInt32_Boundaries( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kDecimalNumsStr,kDecimalNumsCount, + kRadixDecimal,expValues,1,NULL,hRtlTestResult ), + "kDecimalNumsStr", + "toInt32( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kDecimalMaxNumsStr,kInt32MaxNumsCount, + kRadixDecimal,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), + "kDecimalMaxNumsStr", + "toInt32_Boundaries( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kHexDecimalNumsStr,kHexDecimalNumsCount, + kRadixHexdecimal,expValues,1,NULL,hRtlTestResult ), + "kHexDecimalNumsStr", + "toInt32( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kHexDecimalMaxNumsStr,kInt32MaxNumsCount, + kRadixHexdecimal,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), + "kHexDecimalMaxNumsStr", + "toInt32_Boundaries( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kBase36NumsStr,kBase36NumsCount, + kRadixBase36, expValues,1,NULL,hRtlTestResult ), + "kBase36NumsStr", + "toInt32( radix 36 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kBase36MaxNumsStr,kInt32MaxNumsCount, + kRadixBase36,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), + "kBase36MaxNumsStr", + "toInt32_Boundaries( radix 36 )" + ); + + const sal_Int16 nSpecCases = 5; + static const sal_Char *spString[nSpecCases] = + { + "-1", + "+1", + " 1", + " -1", + "001" + }; + + sal_Int32 expSpecVal[nSpecCases] = + { + -1, + 1, + 1, + -1, + 1 + }; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( spString,nSpecCases, + kRadixDecimal,expSpecVal,1,NULL,hRtlTestResult ), + "special cases", + "toInt32( specialcases )" + ); + + return ( res ); +} +sal_Bool SAL_CALL test_rtl_OUString_toInt32_wrongRadix( + hTestResult hRtlTestResult ) +{ + ::rtl::OUString str("0",1,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString); + + sal_Int32 iRes =str.toInt32(-1); + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + iRes == 0, + "wrong radix -1", + "toInt32( 0, wrong radix -1 )" + ) + ); +} +sal_Bool SAL_CALL test_rtl_OUString_toInt32_defaultParam( + hTestResult hRtlTestResult ) +{ + sal_Int32 expValues[kBase36NumsCount]; + sal_Int32 i; + + for ( i = 0; i < kBase36NumsCount; i++ ) + expValues[i] = i; + + sal_Bool res = c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kDecimalNumsStr,kDecimalNumsCount, + kRadixDecimal,expValues,0,NULL,hRtlTestResult ), + "kBinaryNumsStr", + "toInt32( radix 2 )" + ); + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( kDecimalMaxNumsStr,kInt32MaxNumsCount, + kRadixDecimal,(sal_Int32*)kInt32MaxNums,0,NULL,hRtlTestResult ), + "kDecimalMaxNumsStr", + "toInt32_Boundaries( radix 10 )" + ); + const sal_Int16 nSpecCases = 5; + static const sal_Char *spString[nSpecCases] = + { + "-1", + "+1", + " 1", + " -1", + "001" + }; + + sal_Int32 expSpecVal[nSpecCases] = + { + -1, + 1, + 1, + -1, + 1 + }; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int32>( spString,nSpecCases, + kRadixDecimal,expSpecVal,0,NULL,hRtlTestResult ), + "special cases", + "toInt32( specialcases )" + ); + + return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method toInt32() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toInt32( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "toInt32"); + sal_Bool bTState = test_rtl_OUString_toInt32_normal( hRtlTestResult ); + bTState &= test_rtl_OUString_toInt32_defaultParam( hRtlTestResult ); + bTState &= test_rtl_OUString_toInt32_wrongRadix( hRtlTestResult ); + c_rtl_tres_state_end( hRtlTestResult, "toInt32"); +// return ( bTState ); +} +//------------------------------------------------------------------------ +// testing the method toInt64( sal_Int16 radix = 2,8,10,16,36 ) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUString_toInt64_normal( + hTestResult hRtlTestResult ) +{ + sal_Int64 expValues[kBase36NumsCount]; + sal_Int32 i; + + for (i = 0; i < kBase36NumsCount; expValues[i] = i, i++); + + sal_Bool res = c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kBinaryNumsStr,kBinaryNumsCount, + kRadixBinary,expValues,3,NULL,hRtlTestResult ), + "kBinaryNumsStr", + "toInt64( radix 2 )" + ); + +/* LLA: does not work within wntmsci8.pro + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kBinaryMaxNumsStr,kInt64MaxNumsCount, + kRadixBinary,kInt64MaxNums,3,hRtlTestResult ), + "kBinaryMaxNumsStr", + "toInt64_Boundaries( radix 2 )" + ); +*/ + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kOctolNumsStr,kOctolNumsCount, + kRadixOctol,expValues,3,NULL,hRtlTestResult ), + "kOctolNumsStr", + "toInt64( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kOctolMaxNumsStr,kInt64MaxNumsCount, + kRadixOctol,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), + "kOctolMaxNumsStr", + "toInt64_Boundaries( radix 8 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kDecimalNumsStr,kDecimalNumsCount, + kRadixDecimal,expValues,3,NULL,hRtlTestResult ), + "kDecimalNumsStr", + "toInt64( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kDecimalMaxNumsStr,kInt64MaxNumsCount, + kRadixDecimal,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), + "kDecimalMaxNumsStr", + "toInt64_Boundaries( radix 10 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kHexDecimalNumsStr,kHexDecimalNumsCount, + kRadixHexdecimal,expValues,3,NULL,hRtlTestResult ), + "kHexDecimalNumsStr", + "toInt64( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kHexDecimalMaxNumsStr,kInt64MaxNumsCount, + kRadixHexdecimal,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), + "kHexDecimalMaxNumsStr", + "toInt64_Boundaries( radix 16 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kBase36NumsStr,kBase36NumsCount, + kRadixBase36, expValues,3,NULL,hRtlTestResult ), + "kBase36NumsStr", + "toInt64( radix 36 )" + ); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kBase36MaxNumsStr,kInt64MaxNumsCount, + kRadixBase36,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), + "kBase36MaxNumsStr", + "toInt64_Boundaries( radix 36 )" + ); + + + + const sal_Int16 nSpecCases = 5; + static const sal_Char *spString[nSpecCases] = + { + "-1", + "+1", + " 1", + " -1", + "001" + }; + + sal_Int64 expSpecVal[nSpecCases] = + { + -1, + 1, + 1, + -1, + 1 + }; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( spString,nSpecCases, + kRadixDecimal,expSpecVal,3,NULL,hRtlTestResult ), + "special cases", + "toInt64( specialcases )" + ); + + return (res); +} + +sal_Bool SAL_CALL test_rtl_OUString_toInt64_wrongRadix( + hTestResult hRtlTestResult ) +{ + ::rtl::OUString str("0",1,kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString); + + sal_Int64 iRes = str.toInt64(-1); + + return ( + c_rtl_tres_state + ( + hRtlTestResult, + iRes == 0, + "wrong radix -1", + "toInt64( wrong radix -1)" + ) + ); +} +sal_Bool SAL_CALL test_rtl_OUString_toInt64_defaultParam( + hTestResult hRtlTestResult ) +{ + sal_Int64 expValues[kBase36NumsCount]; + sal_Int32 i; + + for ( i = 0; i < kBase36NumsCount; i++ ) + expValues[i] = i; + + sal_Bool res = c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kDecimalNumsStr,kDecimalNumsCount, + kRadixDecimal,expValues,2,NULL,hRtlTestResult ), + "kBinaryNumsStr", + "toInt64( radix 10 )" + ); + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( kDecimalMaxNumsStr,kInt64MaxNumsCount, + kRadixDecimal,(sal_Int64*)kInt64MaxNums,2,NULL,hRtlTestResult ), + "kDecimalMaxNumsStr", + "toInt64_Boundaries( radix 10 )" + ); + const sal_Int16 nSpecCases = 5; + static const sal_Char *spString[nSpecCases] = + { + "-1", + "+1", + " 1", + " -1", + "001" + }; + + sal_Int64 expSpecVal[nSpecCases] = + { + -1, + 1, + 1, + -1, + 1 + }; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + test_toData<sal_Int64>( spString,nSpecCases, + kRadixDecimal,expSpecVal,2,NULL,hRtlTestResult ), + "special cases", + "toInt64( specialcases )" + ); + + return ( res ); +} + +//------------------------------------------------------------------------ +// testing the method toInt64() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toInt64( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "toInt64"); + sal_Bool bTState = test_rtl_OUString_toInt64_normal( hRtlTestResult ); + bTState &= test_rtl_OUString_toInt64_defaultParam (hRtlTestResult ); + bTState &= test_rtl_OUString_toInt64_wrongRadix( hRtlTestResult ); + c_rtl_tres_state_end( hRtlTestResult, "toInt64"); +// return ( bTState ); +} +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString( hTestResult hRtlTestResult ) +{ + + c_rtl_tres_state_start(hRtlTestResult, "rtl_OUString" ); + + test_rtl_OUString_ctors( hRtlTestResult ); + test_rtl_OUString_getLength( hRtlTestResult ); + test_rtl_OUString_equals( hRtlTestResult ); + test_rtl_OUString_equalsIgnoreAsciiCase( hRtlTestResult ); + test_rtl_OUString_compareTo( hRtlTestResult ); + test_rtl_OUString_match( hRtlTestResult ); + test_rtl_OUString_op_eq( hRtlTestResult ); + test_rtl_OUString_op_peq( hRtlTestResult ); + test_rtl_OUString_csuc( hRtlTestResult ); + test_rtl_OUString_getStr( hRtlTestResult ); + test_rtl_OUString_reverseCompareTo( hRtlTestResult ); + test_rtl_OUString_equalsAscii( hRtlTestResult ); + test_rtl_OUString_equalsAsciiL( hRtlTestResult ); + test_rtl_OUString_compareToAscii( hRtlTestResult ); + test_rtl_OUString_valueOf_sal_Bool( hRtlTestResult ); + test_rtl_OUString_valueOf_sal_Unicode( hRtlTestResult ); + test_rtl_OUString_valueOf( hRtlTestResult ); + test_rtl_OUString_createFromAscii( hRtlTestResult ); + test_rtl_OUString_indexOf( hRtlTestResult ); +// LLA: removed, it is in a new test in rtl/oustring. test_rtl_OUString_lastIndexOf( hRtlTestResult ); + test_rtl_OUString_concat( hRtlTestResult ); + test_rtl_OUString_replaceAt( hRtlTestResult ); + test_rtl_OUString_replace( hRtlTestResult ); + test_rtl_OUString_toAsciiLowerCase( hRtlTestResult ); + test_rtl_OUString_toAsciiUpperCase( hRtlTestResult ); + test_rtl_OUString_trim( hRtlTestResult ); +// LLA: removed, it is in a new test in rtl/oustring. test_rtl_OUString_toDouble( hRtlTestResult ); +// LLA: removed, has compile problems. test_rtl_OUString_toFloat( hRtlTestResult ); + test_rtl_OUString_toChar( hRtlTestResult ); + test_rtl_OUString_toBoolean( hRtlTestResult ); + test_rtl_OUString_toInt32( hRtlTestResult ); + test_rtl_OUString_toInt64( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "rtl_OUString"); +} +// ----------------------------------------------------------------------------- +void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) +{ + if (_pFunc) + { + (_pFunc)(&test_rtl_OUString, ""); + } +} diff --git a/sal/qa/rtl_strings/rtl_OUStringBuffer.cxx b/sal/qa/rtl_strings/rtl_OUStringBuffer.cxx new file mode 100644 index 000000000000..be37c67570d8 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_OUStringBuffer.cxx @@ -0,0 +1,1826 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_OUStringBuffer.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +// #ifndef _RTL_TRES_H_ +// #include <rtl/tres.h> +// #endif +#include <testshl/tresstatewrapper.hxx> + +#ifndef _RTL_STRING_HXX_ + #include <rtl/string.hxx> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +#ifndef _RTL_USTRING_HXX_ + #include <rtl/ustring.hxx> +#endif + +#ifndef _RTL_USTRBUF_H_ + #include <rtl/ustrbuf.h> +#endif + +#ifndef _RTL_USTRBUF_HXX + #include <rtl/ustrbuf.hxx> +#endif +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#ifndef _OSL_THREAD_H_ + #include <osl/thread.h> +#endif + +#ifndef _RTL_STRING_CONST_H_ + #include <rtl_String_Const.h> +#endif + +#ifndef _RTL_STRING_UTILS_HXX_ + #include <rtl_String_Utils.hxx> +#endif + +#include "stdio.h" +using namespace rtl; + +//------------------------------------------------------------------------ +// test classes +//------------------------------------------------------------------------ +const int MAXBUFLENGTH = 255; +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ +static void unused() +{ + (void)kBinaryNumsStr; + (void)kOctolNumsStr; + (void)kDecimalNumsStr; + (void)kHexDecimalNumsStr; + (void)kBase36NumsStr; + (void)inputChar; + (void)input1StrDefault; + (void)input1StrNormal; + (void)input1StrLastDefault; + (void)input1StrLastNormal; + unused(); +} + +//------------------------------------------------------------------------ +// testing constructors +//------------------------------------------------------------------------ +static sal_Bool test_rtl_OUStringBuffer_ctor_001( hTestResult hRtlTestResult ) +{ + + ::rtl::OUStringBuffer aUStrBuf; + + bool b1 = + aUStrBuf.getLength() == 0 && + ! *(aUStrBuf.getStr()) && aUStrBuf.getCapacity() == 16; + + ::rtl::OUStringBuffer aUStrBuf2(0); + + bool b2 = + aUStrBuf2.getLength() == 0 && + ! *(aUStrBuf2.getStr()) && aUStrBuf2.getCapacity() == /* LLA: !!! */ 0; + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + b1 && b2, + "New OUStringBuffer containing no characters", + "ctor_001" + ) + ); +} + +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OUStringBuffer_ctor_002( + hTestResult hRtlTestResult ) +{ + ::rtl::OUStringBuffer aUStrBuftmp( aUStr1 ); + ::rtl::OUStringBuffer aUStrBuf( aUStrBuftmp ); + sal_Bool res = cmpustr(aUStrBuftmp.getStr(),aUStrBuf.getStr()); + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStrBuf.getLength()==aUStrBuftmp.getLength() && + aUStrBuf.getCapacity() == aUStrBuftmp.getCapacity() && res , + "New OUStringBuffer from another OUStringBuffer", + "ctor_002" + ) + ); +} +//------------------------------------------------------------------------ + +/* static */ +sal_Bool SAL_CALL test_rtl_OUStringBuffer_ctor_003( + hTestResult hRtlTestResult ) +{ + ::rtl::OUStringBuffer aUStrBuf1(kTestStr2Len); +#ifdef WITH_CORE + ::rtl::OUStringBuffer aUStrBuf2(kSInt32Max); //will core dump +#else + ::rtl::OUStringBuffer aUStrBuf2(0); +#endif + ::rtl::OUStringBuffer aUStrBuf3(kNonSInt32Max); + + + bool b1 = + aUStrBuf1.getLength() == 0 && + ! *(aUStrBuf1.getStr()) && aUStrBuf1.getCapacity() == kTestStr2Len ; + + bool b2 = +#ifdef WITH_CORE + aUStrBuf2.getLength() == 0 && + ! *(aUStrBuf2.getStr()) && aUStrBuf2.getCapacity() == kSInt32Max ; +#else + aUStrBuf2.getLength() == 0 && + ! *(aUStrBuf2.getStr()) && aUStrBuf2.getCapacity() == /* LLA: ??? 16 */ 0; +#endif + bool b3 = + aUStrBuf3.getLength() == 0 && + ! *(aUStrBuf3.getStr()) && aUStrBuf3.getCapacity() == kNonSInt32Max; + + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + b1 && b2 && b3, + "New OUStringBuffer containing no characters and contain assigned capacity", + "ctor_003( will core dump,because the kSInt32Max )" + ) + ); + +} + +//------------------------------------------------------------------------ + +static sal_Bool SAL_CALL test_rtl_OUStringBuffer_ctor_004( + hTestResult hRtlTestResult) +{ + ::rtl::OUString aUStrtmp( aUStr1 ); + ::rtl::OUStringBuffer aUStrBuf( aUStrtmp ); + sal_Int32 leg = aUStrBuf.getLength(); + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStrBuf.getStr() == aUStrtmp && + leg == aUStrtmp.pData->length && + aUStrBuf.getCapacity() == leg+16 , + "New OUStringBuffer from OUstring", + "ctor_004" + ) + ); +} + +static sal_Bool SAL_CALL test_rtl_OUStringBuffer_ctor_005( + hTestResult hRtlTestResult) +{ + ::rtl::OUStringBuffer aUStrBuftmp( aUStr1 ); + ::rtl::OUString aUStrtmp = aUStrBuftmp.makeStringAndClear(); + ::rtl::OUStringBuffer aUStrBuf( aUStrBuftmp ); + sal_Bool res = cmpustr(aUStrBuftmp.getStr(),aUStrBuf.getStr()); + sal_Int32 leg = aUStrBuf.getLength(); + return + ( + c_rtl_tres_state + ( + hRtlTestResult, + aUStrBuf.getLength()==aUStrBuftmp.getLength() && + aUStrBuf.getCapacity() == aUStrBuftmp.getCapacity() && + res && leg == 0, + "New OUStringBuffer from another OUStringBuffer after makeClearFromString", + "ctor_005" + ) + ); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_ctors( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "ctors"); + sal_Bool DCState = test_ini_uString(); + (void)DCState; + sal_Bool bTSState = test_rtl_OUStringBuffer_ctor_001( hRtlTestResult ); + bTSState &= test_rtl_OUStringBuffer_ctor_002( hRtlTestResult); + bTSState &= test_rtl_OUStringBuffer_ctor_003( hRtlTestResult); + bTSState &= test_rtl_OUStringBuffer_ctor_004( hRtlTestResult); + bTSState &= test_rtl_OUStringBuffer_ctor_005( hRtlTestResult); + + c_rtl_tres_state_end( hRtlTestResult, "ctors"); +// return( bTSState ); +} + +//------------------------------------------------------------------------ +// testing the method makeStringAndClear() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_makeStringAndClear( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "makeStringAndClear"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + + ~TestCase() { delete input1;} + } TestCase; + + OUString arrOUS[6]={ + OUString( aUStr1 ), + OUString( aUStr14 ), + OUString( aUStr25 ), + OUString( aUStr27 ), + OUString( aUStr29 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString) + }; + + TestCase arrTestCase[]={ + + {"two empty strings(def. constructor)", new OUString(), + new OUStringBuffer()}, + {"two empty strings(with a argu)", new OUString(), + new OUStringBuffer(26)}, + {"normal string", new OUString(arrOUS[0]), + new OUStringBuffer(arrOUS[0])}, + {"string with space ", new OUString(arrOUS[1]), + new OUStringBuffer(arrOUS[1])}, + {"empty string", new OUString(arrOUS[2]), + new OUStringBuffer(arrOUS[2])}, + {"string with a character", new OUString(arrOUS[3]), + new OUStringBuffer(arrOUS[3])}, + {"string with special characters", new OUString(arrOUS[4]), + new OUStringBuffer(arrOUS[4])}, + {"string only with (\0)", new OUString(arrOUS[5]), + new OUStringBuffer(arrOUS[5])} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + ( arrTestCase[i].input1->makeStringAndClear() == + *( arrTestCase[i].expVal )); + lastRes = lastRes && ( arrTestCase[i].input1->getCapacity() == 0 ); + lastRes = lastRes && ( *(arrTestCase[i].input1->getStr()) == '\0' ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "makeStringAndClear", i ) + ); + + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "makeStringAndClear"); +// return (res); +} +//------------------------------------------------------------------------ +// testing the method getLength +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_getLength( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "getLength"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[6]={OUString( aUStr1 ), + OUString( "1",1, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString(), + OUString( "",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr2 )}; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUStringBuffer* input; + ~TestCase() { delete input;} + } TestCase; + + TestCase arrTestCase[]={ + + {"length of ascii string", kTestStr1Len, + new OUStringBuffer(arrOUS[0]) }, + {"length of ascci string of size 1", 1, + new OUStringBuffer(arrOUS[1])}, + {"length of empty string", 0, + new OUStringBuffer(arrOUS[2])}, + {"length of empty string (empty ascii string arg)",0, + new OUStringBuffer(arrOUS[3])}, + {"length of empty string (string arg = '\\0')", 0, + new OUStringBuffer(arrOUS[4])}, + {"length(>16) of ascii string", kTestStr2Len, + new OUStringBuffer(arrOUS[5]) }, + {"length of empty string (default constructor)", 0, + new OUStringBuffer()}, + {"length of empty string (with capacity)", 0, + new OUStringBuffer(26)} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 length = arrTestCase[i].input->getLength(); + sal_Bool lastRes = (length == arrTestCase[i].expVal); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "getLength", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "getLength"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method getCapacity() +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_getCapacity( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "getCapacity"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[6]={OUString( aUStr1 ), + OUString( "1",1, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString(), + OUString( "",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr2 )}; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUStringBuffer* input; + ~TestCase() { delete input;} + } TestCase; + + TestCase arrTestCase[]={ + + {"capacity of ascii string", kTestStr1Len+16, + new OUStringBuffer(arrOUS[0]) }, + {"capacity of ascci string of size 1", 1+16, + new OUStringBuffer(arrOUS[1]) }, + {"capacity of empty string", 0+16, + new OUStringBuffer(arrOUS[2]) }, + {"capacity of empty string (empty ascii string arg)",0+16, + new OUStringBuffer(arrOUS[3]) }, + {"capacity of empty string (string arg = '\\0')", 0+16, + new OUStringBuffer(arrOUS[4]) }, + {"capacity(>16) of ascii string", kTestStr2Len+16, + new OUStringBuffer(arrOUS[5]) }, + {"capacity of empty string (default constructor)", 16, + new OUStringBuffer() }, +#ifdef WITH_CORE + {"capacity of empty string (with capacity 2147483647)(code will core dump)", kSInt32Max, + new OUStringBuffer(kSInt32Max) },// will core dump +#endif + {"capacity of empty string (with capacity -2147483648)", kNonSInt32Max, + new OUStringBuffer(kNonSInt32Max) }, + {"capacity of empty string (with capacity 16)", 16, + new OUStringBuffer(16) }, + {"capacity of empty string (with capacity 6)", 6, + new OUStringBuffer(6) }, + {"capacity of empty string (with capacity 0)", 0, + new OUStringBuffer(0) }, + {"capacity of empty string (with capacity -2)", -2, + new OUStringBuffer(-2) } + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Int32 length = arrTestCase[i].input->getCapacity(); + sal_Bool lastRes = (length == arrTestCase[i].expVal); + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "getCapacity", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "getCapacity"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method ensureCapacity(sal_Int32 minimumCapacity) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_ensureCapacity( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "ensureCapacity"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal; + OUStringBuffer* input1; + sal_Int32 input2; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[]={ + + {"capacity equal to 16, minimum is 5 ", 16, + new OUStringBuffer(), 5 }, + {"capacity equal to 16, minimum is -5", 16, + new OUStringBuffer(), -5}, + {"capacity equal to 16, minimum is 0", 16, + new OUStringBuffer(), 0}, + {"capacity equal to 16, minimum is 20", 20, //the testcase is based on comments + new OUStringBuffer(), 20}, + {"capacity equal to 16, minimum is 50", 50, + new OUStringBuffer(), 50}, + {"capacity equal to 6, minimum is 20", 20, + new OUStringBuffer(6), 20 }, + {"capacity equal to 6, minimum is 2", 6, + new OUStringBuffer(6), 2}, + {"capacity equal to 6, minimum is -6", 6, + new OUStringBuffer(6), -6}, + {"capacity equal to 6, minimum is -6", 10, //the testcase is based on comments + new OUStringBuffer(6), 10}, + {"capacity equal to 0, minimum is 6", 6, + new OUStringBuffer(0), 6}, + {"capacity equal to 0, minimum is 1", 2, //the testcase is based on comments + new OUStringBuffer(0), 1}, + /* + {"capacity equal to 0, minimum is -1", 0, + new OUStringBuffer(0), -1}, + */ +#ifdef WITH_CORE + {"capacity equal to 2147483647, minimum is 65535", kSInt32Max,//will core dump + new OUStringBuffer(kSInt32Max), 65535}, + {"capacity equal to 2147483647, minimum is 2147483647", kSInt32Max,//will core dump + new OUStringBuffer(kSInt32Max), kSInt32Max}, + {"capacity equal to 2147483647, minimum is -1", kSInt32Max,//will core dump + new OUStringBuffer(kSInt32Max), -1}, + {"capacity equal to 2147483647, minimum is 0", kSInt32Max,//will core dump + new OUStringBuffer(kSInt32Max), 0}, + {"capacity equal to 2147483647, minimum is -2147483648", kSInt32Max,//will core dump + new OUStringBuffer(kSInt32Max), kNonSInt32Max}, +#endif + {"capacity equal to -2147483648, minimum is 65535", 65535, + new OUStringBuffer(kNonSInt32Max), 65535}, +#ifdef WITH_CORE + {"capacity equal to -2147483648, minimum is 2147483647", 2147483647,//will core dump + new OUStringBuffer(kNonSInt32Max), 2147483647}, +#endif + {"capacity equal to -2147483648, minimum is -1", 2, + new OUStringBuffer(kNonSInt32Max), -1}, + {"capacity equal to -2147483648, minimum is 0", 2, + new OUStringBuffer(kNonSInt32Max), 0}, + {"capacity equal to -2147483648, minimum is -2147483648", kNonSInt32Max, + new OUStringBuffer(kNonSInt32Max), kNonSInt32Max} + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->ensureCapacity(arrTestCase[i].input2); + sal_Int32 length = arrTestCase[i].input1->getCapacity(); + sal_Bool lastRes = (length == arrTestCase[i].expVal); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "ensureCapacity", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "ensureCapacity"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method setLength(sal_Int32 newLength) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_setLength( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "setLength"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[6]={OUString( aUStr1 ), + OUString( aUStr27), + OUString(), + OUString( "",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr2 )}; + + typedef struct TestCase + { + sal_Char* comments; + sal_Int32 expVal1; + OUString* expVal2; + sal_Int32 expVal3; + OUStringBuffer* input1; + sal_Int32 input2; + ~TestCase() { delete input1; delete expVal2;} + } TestCase; + + TestCase arrTestCase[]={ + + {"newLength more than the capacity of OUStringBuffer(aUStr1)", + 50, new OUString(aUStr1), 50, + new OUStringBuffer(arrOUS[0]), 50 }, + {"newLength more than the length of OUStringBuffer(aUStr1)", + kTestStr13Len, new OUString(aUStr1), 32, + new OUStringBuffer(arrOUS[0]), kTestStr13Len }, + {"newLength equal to the length of OUStringBuffer(aUStr1)", + kTestStr1Len, new OUString(aUStr1), 32, + new OUStringBuffer(arrOUS[0]), kTestStr1Len }, + {"newLength less than the length of OUStringBuffer(aUStr1)", + kTestStr7Len, new OUString(aUStr7), 32, + new OUStringBuffer(arrOUS[0]), kTestStr7Len}, + {"newLength equal to 0", + 0, new OUString(), 32, + new OUStringBuffer(arrOUS[0]), 0}, + {"newLength more than the capacity of OUStringBuffer(1)", + 25, new OUString(arrOUS[1]), 25, + new OUStringBuffer(arrOUS[1]), 25}, + {"newLength more than the length of OUStringBuffer(1)", + 5, new OUString(arrOUS[1]), 17, + new OUStringBuffer(arrOUS[1]), 5}, + {"newLength equal to the length of OUStringBuffer(1)", + kTestStr27Len, new OUString(arrOUS[1]), 17, + new OUStringBuffer(arrOUS[1]), kTestStr27Len}, + {"newLength less than the length of OUStringBuffer(1)", + 0, new OUString(), 17, + new OUStringBuffer(arrOUS[1]), 0}, + {"newLength more than the capacity of OUStringBuffer()", + 20, new OUString(), 20, + new OUStringBuffer(arrOUS[2]), 20}, + {"newLength more than the length of OUStringBuffer()", + 3, new OUString(), 16, + new OUStringBuffer(arrOUS[2]), 3}, + {"newLength less than the length of OUStringBuffer()", + 0, new OUString(), 16, + new OUStringBuffer(arrOUS[2]), 0}, + {"newLength more than the capacity of OUStringBuffer("")", + 20, new OUString(), 20, + new OUStringBuffer(arrOUS[3]), 20}, + {"newLength more than the length of OUStringBuffer("")", + 5, new OUString(), 16, + new OUStringBuffer(arrOUS[3]), 5}, + {"newLength less than the length of OUStringBuffer("")", + 0, new OUString(), 16, + new OUStringBuffer(arrOUS[3]), 0}, + {"newLength more than the length of OUStringBuffer(\0)", + 20, new OUString(), 20, + new OUStringBuffer(arrOUS[4]), 20}, + {"newLength more than the length of OUStringBuffer(\0)", + 5, new OUString(), 16, + new OUStringBuffer(arrOUS[4]), 5}, + {"newLength less than the length of OUStringBuffer(\0)", + 0, new OUString(), 16, + new OUStringBuffer(arrOUS[4]), 0}, + {"newLength more than the capacity of OUStringBuffer(aUStr2)", + 50, new OUString(aUStr2), 66, + new OUStringBuffer(arrOUS[5]), 50,}, + {"newLength more than the length of OUStringBuffer(aUStr2)", + 40, new OUString(aUStr2), 48, + new OUStringBuffer(arrOUS[5]), 40,}, + {"newLength equal to the length of OUStringBuffer(aUStr2)", + kTestStr2Len, new OUString(aUStr2), 48, + new OUStringBuffer(arrOUS[5]), kTestStr2Len,}, + {"newLength less than the length of OUStringBuffer(aUStr2)", + kTestStr7Len, new OUString(aUStr7), 48, + new OUStringBuffer(arrOUS[5]), kTestStr7Len}, + {"newLength equal to 0", + 0, new OUString(), 48, + new OUStringBuffer(arrOUS[5]), 0} + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->setLength(arrTestCase[i].input2); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr() == *(arrTestCase[i].expVal2) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal1 && + arrTestCase[i].input1->getCapacity() == arrTestCase[i].expVal3 ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "setLength", i ) + + ); + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "setLength"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method charAt( sal_Int32 index ) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_charAt( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "charAt"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[4]={OUString( aUStr1 ), // "Sun Microsystems"; + OUString( aUStr27), // "s"; + OUString( aUStr28), // "\50\3\5\7\11\13\15\17sun"; + OUString( )}; + + typedef struct TestCase + { + sal_Char* comments; + sal_Unicode expVal; + OUStringBuffer* input1; + sal_Int32 input2; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[]={ + + {"return the first character of OUStringBuffer(aUStr1)", + 83, new OUStringBuffer(arrOUS[0]), 0 }, + {"return the middle character of OUStringBuffer(aUStr1)", + 32, new OUStringBuffer(arrOUS[0]), 3 }, + {"return the last character of OUStringBuffer(aUStr1)", + 115, new OUStringBuffer(arrOUS[0]), 15 }, + {"return the only character of OUStringBuffer(aUStr27)", + 115, new OUStringBuffer(arrOUS[1]), 0}, + {"return the first of OUStringBuffer(aUStr28) with special character", + 40, new OUStringBuffer(arrOUS[2]), 0}, + /* +{"return the mid of OUStringBuffer(aUStr28) with special character", + 11, new OUStringBuffer(arrOUS[2]), 5}, +*/ +/* + {"invalid character of OUStringBuffer()", + 0, new OUStringBuffer(arrOUS[3]), 0}, +*/ +/* + {"invalid character of OUStringBuffer()", + 0, new OUStringBuffer(arrOUS[3]), -2} +*/ + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + ( arrTestCase[i].input1->charAt(arrTestCase[i].input2) == + arrTestCase[i].expVal ); + // LLA: last case removed, due to the fact of complexity of the test code :-( + // LLA: if(i<=7) + // LLA: { + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "charAt", i ) + + ); + // LLA: } + // LLA: else + // LLA: { + // LLA: c_rtl_tres_state + // LLA: ( + // LLA: hRtlTestResult, + // LLA: sal_True, + // LLA: arrTestCase[i].comments, + // LLA: createName( pMeth, "charAt", i ) + // LLA: + // LLA: ); + // LLA: } + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "charAt"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the operator const sal_Unicode * (csuc for short) +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_csuc( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "csuc"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Unicode tmpUC=0x0; + rtl_uString* tmpUstring = NULL; + const sal_Char *tmpStr=kTestStr1; + sal_Int32 tmpLen=(sal_Int32) kTestStr1Len; + //sal_Int32 cmpLen = 0; + OUString tempString(aUStr1); + + rtl_string2UString( &tmpUstring, tmpStr, tmpLen, + osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + OSL_ASSERT(tmpUstring != NULL); + + + typedef struct TestCase + { + sal_Char* comments; + const sal_Unicode* expVal; + sal_Int32 cmpLen; + OUStringBuffer* input1; + ~TestCase() { delete input1; } + } TestCase; + + TestCase arrTestCase[] = + { + {"test normal ustring",(*tmpUstring).buffer,kTestStr1Len, + new OUStringBuffer(tempString)}, + {"test empty ustring",&tmpUC, 1, new OUStringBuffer()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + const sal_Unicode* pstr = *arrTestCase[i].input1; + + res &= c_rtl_tres_state + ( + hRtlTestResult, + cmpustr( pstr, arrTestCase[i].expVal, arrTestCase[i].cmpLen ), + arrTestCase[i].comments, + createName( pMeth, "const sal_Unicode*", i ) + ); + } + c_rtl_tres_state_end( hRtlTestResult, "csuc"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method const sal_Unicode * getStr() +//------------------------------------------------------------------------ +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_getStr( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "getStr"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + const sal_Unicode tmpUC=0x0; + rtl_uString* tmpUstring = NULL; + const sal_Char *tmpStr=kTestStr1; + sal_Int32 tmpLen=(sal_Int32) kTestStr1Len; + //sal_Int32 cmpLen = 0; + OUString tempString(aUStr1); + + rtl_string2UString( &tmpUstring, tmpStr, tmpLen, + osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + OSL_ASSERT(tmpUstring != NULL); + + + typedef struct TestCase + { + sal_Char* comments; + const sal_Unicode* expVal; + sal_Int32 cmpLen; + OUStringBuffer* input1; + ~TestCase() { delete input1;} + } TestCase; + + TestCase arrTestCase[] = + { + {"test normal ustring",(*tmpUstring).buffer,kTestStr1Len, + new OUStringBuffer(tempString)}, + {"test empty ustring",&tmpUC, 1, new OUStringBuffer()} + }; + + sal_Bool res = sal_True; + sal_uInt32 i; + for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + const sal_Unicode* pstr = arrTestCase[i].input1->getStr(); + + res &= c_rtl_tres_state + ( + hRtlTestResult, + cmpustr( pstr, arrTestCase[i].expVal, arrTestCase[i].cmpLen ), + arrTestCase[i].comments, + createName( pMeth, "getStr", i ) + ); + } + c_rtl_tres_state_end( hRtlTestResult, "getStr"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method setCharAt(sal_Int32 index, sal_Unicode ch) +//------------------------------------------------------------------------ + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_setCharAt( + hTestResult hRtlTestResult) +{ + c_rtl_tres_state_start( hRtlTestResult, "setCharAt"); + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[4]={OUString( aUStr1 ), + OUString( aUStr27), + OUString( aUStr28), + OUString( )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + sal_Int32 input2; + sal_Unicode input3; + ~TestCase() { delete input1; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"set the first character of OUStringBuffer(aUStr1) with s", + new OUString(aUStr31), + new OUStringBuffer(arrOUS[0]), 0, 115 }, + {"set the middle character of OUStringBuffer(aUStr1) with m", + new OUString(aUStr3), + new OUStringBuffer(arrOUS[0]), 4, 109 }, + {"set the last character of OUStringBuffer(aUStr1) with ' '", + new OUString(aUStr32), + new OUStringBuffer(arrOUS[0]), 15, 32 }, + {"set the only character of OUStringBuffer(aUStr27) with ' '", + new OUString(aUStr33), + new OUStringBuffer(arrOUS[1]), 0, 32}, + {"set the only of OUStringBuffer(aUStr28) with special character", + new OUString(aUStr34), + new OUStringBuffer(arrOUS[2]), 1, 5}, +/* + {"set the only of OUStringBuffer(aUStr28) with special character", + new OUString(aUStr35), + new OUStringBuffer(arrOUS[2]), 1, -5} +*/ +#ifdef WITH_CORE + ,{"invalid character of OUStringBuffer()", + 0, + new OUStringBuffer(arrOUS[3]), 0, 5}, + {"invalid character of OUStringBuffer()", + 0, + new OUStringBuffer(arrOUS[3]), -2, 5}, + {"invalid character of OUStringBuffer()", + 0, + new OUStringBuffer(arrOUS[3]), 3, 5} +#endif + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + sal_Bool lastRes = + ( (arrTestCase[i].input1->setCharAt(arrTestCase[i].input2, + arrTestCase[i].input3)).getStr() == *(arrTestCase[i].expVal) ); + if(i<=4) + { + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "setCharAt", i ) + + ); + } + else + { + c_rtl_tres_state + ( + hRtlTestResult, + sal_True, + arrTestCase[i].comments, + createName( pMeth, "setCharAt", i ) + + ); + } + res &= lastRes; + } + c_rtl_tres_state_end( hRtlTestResult, "setCharAt"); +// return ( res ); +} +//------------------------------------------------------------------------ +// testing the method append(const OUString &str) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUStringBuffer_append_001( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[5]={OUString( aUStr7 ), + OUString(), + OUString( aUStr25 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr28 )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + OUString* input2; + + ~TestCase() { delete input1; delete input2; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"Appends the string(length less than 16) to the string buffer arrOUS[0]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[0]), new OUString(aUStr8) }, + {"Appends the string(length more than 16) to the string buffer arrOUS[0]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[0]), new OUString(aUStr36) }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[0]", + new OUString(aUStr37), + new OUStringBuffer(arrOUS[0]), new OUString(aUStr23) }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[0]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[0]), new OUString()}, + {"Appends the string(length less than 16) to the string buffer arrOUS[1]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[1]), new OUString(aUStr7)}, + {"Appends the string(length more than 16) to the string buffer arrOUS[1]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[1]), new OUString(aUStr2)}, + {"Appends the string(length equal to 16) to the string buffer arrOUS[1]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[1]), new OUString(aUStr1) }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), new OUString()}, + {"Appends the string(length less than 16) to the string buffer arrOUS[2]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[2]), new OUString(aUStr7)}, + {"Appends the string(length more than 16) to the string buffer arrOUS[2]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[2]), new OUString(aUStr2)}, + {"Appends the string(length equal to 16) to the string buffer arrOUS[2]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[2]), new OUString(aUStr1) }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), new OUString()}, + {"Appends the string(length less than 16) to the string buffer arrOUS[3]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[3]), new OUString(aUStr7)}, + {"Appends the string(length more than 16) to the string buffer arrOUS[3]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[3]), new OUString(aUStr2)}, + {"Appends the string(length equal to 16) to the string buffer arrOUS[3]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[3]), new OUString(aUStr1) }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), new OUString()}, + {"Appends the string(length less than 16) to the string buffer arrOUS[4]", + new OUString(aUStr29), + new OUStringBuffer(arrOUS[4]), new OUString(aUStr38)}, + {"Appends the string(length more than 16) to the string buffer arrOUS[4]", + new OUString(aUStr39), + new OUStringBuffer(arrOUS[4]), new OUString(aUStr17)}, + {"Appends the string(length equal to 16) to the string buffer arrOUS[4]", + new OUString(aUStr40), + new OUStringBuffer(arrOUS[4]), new OUString(aUStr31) }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[4]", + new OUString(aUStr28), + new OUStringBuffer(arrOUS[4]), new OUString()} +#ifdef WITH_CORE + ,{"Appends the string(length equal to 0) to the string buffer(with INT_MAX) ", + new OUString(), + new OUStringBuffer(kSInt32Max), new OUString()} +#endif + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->append( *(arrTestCase[i].input2) ); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr()== *(arrTestCase[i].expVal) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal->getLength() ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "append(const OUString &str)_001", i ) + + ); + + res &= lastRes; + } + + return ( res ); +} +//------------------------------------------------------------------------ +// testing the method append( const sal_Unicode * str ) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUStringBuffer_append_002( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[5]={OUString( aUStr7 ), + OUString(), + OUString( aUStr25 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr28 )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + sal_Unicode* input2; + + ~TestCase() { delete input1; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"Appends the string(length less than 16) to the string buffer arrOUS[0]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[0]), aUStr8 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[0]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[0]), aUStr36 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[0]", + new OUString(aUStr37), + new OUStringBuffer(arrOUS[0]), aUStr23 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[0]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[0]), aUStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[1]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[1]), aUStr7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[1]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[1]), aUStr2 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[1]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[1]), aUStr1 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), aUStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[2]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[2]), aUStr7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[2]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[2]), aUStr2 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[2]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[2]), aUStr1 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), aUStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[3]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[3]), aUStr7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[3]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[3]), aUStr2 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[3]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[3]), aUStr1 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), aUStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[4]", + new OUString(aUStr29), + new OUStringBuffer(arrOUS[4]), aUStr38 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[4]", + new OUString(aUStr39), + new OUStringBuffer(arrOUS[4]), aUStr17 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[4]", + new OUString(aUStr40), + new OUStringBuffer(arrOUS[4]), aUStr31 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[4]", + new OUString(aUStr28), + new OUStringBuffer(arrOUS[4]), aUStr25 } +#ifdef WITH_CORE + ,{"Appends the string(length equal to 0) to the string buffer(with INT_MAX) ", + new OUString(), + new OUStringBuffer(kSInt32Max), aUStr25 } +#endif + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->append( arrTestCase[i].input2 ); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr()== *(arrTestCase[i].expVal) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal->getLength() ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "append( const sal_Unicode * str )_002", i ) + + ); + + res &= lastRes; + } + + return ( res ); +} +//------------------------------------------------------------------------ +// testing the method append( const sal_Unicode * str, sal_Int32 len) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUStringBuffer_append_003( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[5]={OUString( aUStr7 ), + OUString(), + OUString( aUStr25 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr28 )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + sal_Unicode* input2; + sal_Int32 input3; + + ~TestCase() { delete input1; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"Appends the string(length less than 16) to the string buffer arrOUS[0]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[0]), aUStr36, 12 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[0]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[0]), aUStr36, 28 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[0]", + new OUString(aUStr37), + new OUStringBuffer(arrOUS[0]), aUStr23, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[0]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[0]), aUStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[0]", + new OUString(aUStr41), + new OUStringBuffer(arrOUS[0]), aUStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[1]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[1]), aUStr2, 4 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[1]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[1]), aUStr2, 32 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[1]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[1]), aUStr2, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), aUStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), aUStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[2]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[2]), aUStr2, 4 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[2]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[2]), aUStr2, 32 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[2]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[2]), aUStr2, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), aUStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), aUStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[3]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[3]), aUStr2, 4 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[3]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[3]), aUStr2, 32 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[3]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[3]), aUStr2, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), aUStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), aUStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[4]", + new OUString(aUStr29), + new OUStringBuffer(arrOUS[4]), aUStr38, 7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[4]", + new OUString(aUStr39), + new OUStringBuffer(arrOUS[4]), aUStr17, 22 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[4]", + new OUString(aUStr40), + new OUStringBuffer(arrOUS[4]), aUStr31, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[4]", + new OUString(aUStr28), + new OUStringBuffer(arrOUS[4]), aUStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[4]", + new OUString(aUStr42), + new OUStringBuffer(arrOUS[4]), aUStr2, -1 } + */ +#ifdef WITH_CORE + ,{"Appends the string(length equal to 0) to the string buffer(with INT_MAX) ", + new OUString(), + new OUStringBuffer(kSInt32Max), aUStr25 } +#endif + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->append( + arrTestCase[i].input2, arrTestCase[i].input3); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr()== *(arrTestCase[i].expVal) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal->getLength() ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "append( const sal_Unicode * str, sal_Int32 len)_003", i ) + + ); + + res &= lastRes; + } + + return ( res ); +} +//------------------------------------------------------------------------ +// testing the method append(sal_Bool b) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUStringBuffer_append_004( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[5]={OUString( aUStr7 ), + OUString(), + OUString( aUStr25 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr28 )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + sal_Bool input2; + + ~TestCase() { delete input1; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"Appends the sal_Bool(sal_True) to the string buffer arrOUS[0]", + new OUString(aUStr45), + new OUStringBuffer(arrOUS[0]), sal_True }, + {"Appends the sal_Bool(sal_False) to the string buffer arrOUS[0]", + new OUString(aUStr46), + new OUStringBuffer(arrOUS[0]), sal_False }, + {"Appends the sal_Bool(sal_True) to the string buffer arrOUS[1]", + new OUString(aUStr47), + new OUStringBuffer(arrOUS[1]), sal_True }, + {"Appends the sal_Bool(sal_False) to the string buffer arrOUS[1]", + new OUString(aUStr48), + new OUStringBuffer(arrOUS[1]), sal_False }, + {"Appends the sal_Bool(sal_True) to the string buffer arrOUS[2]", + new OUString(aUStr47), + new OUStringBuffer(arrOUS[2]), sal_True }, + {"Appends the sal_Bool(sal_False) to the string buffer arrOUS[2]", + new OUString(aUStr48), + new OUStringBuffer(arrOUS[2]), sal_False }, + {"Appends the sal_Bool(sal_True) to the string buffer arrOUS[3]", + new OUString(aUStr47), + new OUStringBuffer(arrOUS[3]), sal_True }, + {"Appends the sal_Bool(sal_False) to the string buffer arrOUS[3]", + new OUString(aUStr48), + new OUStringBuffer(arrOUS[3]), sal_False }, + {"Appends the sal_Bool(sal_True) to the string buffer arrOUS[4]", + new OUString(aUStr49), + new OUStringBuffer(arrOUS[4]), sal_True }, + {"Appends the sal_Bool(sal_False) to the string buffer arrOUS[4]", + new OUString(aUStr50), + new OUStringBuffer(arrOUS[4]), sal_False } +#ifdef WITH_CORE + ,{"Appends the sal_Bool(sal_True) to the string buffer(with INT_MAX) ", + new OUString(aUStr47), + new OUStringBuffer(kSInt32Max), sal_True }, + {"Appends the sal_Bool(sal_False) to the string buffer(with INT_MAX) ", + new OUString(aUStr48), + new OUStringBuffer(kSInt32Max), sal_False } +#endif + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->append( + arrTestCase[i].input2 ); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr()== *(arrTestCase[i].expVal) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal->getLength() ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "append( sal_Bool b)_004", i ) + + ); + + res &= lastRes; + } + + return ( res ); +} + +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_appends( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "appends"); + sal_Bool bTSState = test_rtl_OUStringBuffer_append_001( hRtlTestResult ); + bTSState &= test_rtl_OUStringBuffer_append_002( hRtlTestResult); + bTSState &= test_rtl_OUStringBuffer_append_003( hRtlTestResult); + bTSState &= test_rtl_OUStringBuffer_append_004( hRtlTestResult); + + c_rtl_tres_state_end( hRtlTestResult, "appends"); +// return( bTSState ); +} +//------------------------------------------------------------------------ +// testing the method appendAscii( const sal_Char * str ) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUStringBuffer_appendAscii_001( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[5]={OUString( aUStr7 ), + OUString(), + OUString( aUStr25 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr28 )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + const sal_Char* input2; + + ~TestCase() { delete input1; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"Appends the string(length less than 16) to the string buffer arrOUS[0]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[0]), kTestStr8 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[0]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[0]), kTestStr36 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[0]", + new OUString(aUStr37), + new OUStringBuffer(arrOUS[0]), kTestStr23 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[0]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[0]), kTestStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[1]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[1]), kTestStr7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[1]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[1]), kTestStr2 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[1]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[1]), kTestStr1 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), kTestStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[2]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[2]), kTestStr7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[2]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[2]), kTestStr2 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[2]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[2]), kTestStr1 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), kTestStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[3]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[3]), kTestStr7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[3]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[3]), kTestStr2 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[3]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[3]), kTestStr1 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), kTestStr25 }, + {"Appends the string(length less than 16) to the string buffer arrOUS[4]", + new OUString(aUStr29), + new OUStringBuffer(arrOUS[4]), kTestStr38 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[4]", + new OUString(aUStr39), + new OUStringBuffer(arrOUS[4]), kTestStr17 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[4]", + new OUString(aUStr40), + new OUStringBuffer(arrOUS[4]), kTestStr31 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[4]", + new OUString(aUStr28), + new OUStringBuffer(arrOUS[4]), kTestStr25 } + /*{"Appends the string(with special characters) to the string buffer arrOUS[4]", + new OUString(aUStr43), + new OUStringBuffer(arrOUS[4]), kTestStr44 }*/ +#ifdef WITH_CORE + ,{"Appends the string(length equal to 0) to the string buffer(with INT_MAX) ", + new OUString(), + new OUStringBuffer(kSInt32Max), kTestStr25 } +#endif + + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->appendAscii( arrTestCase[i].input2 ); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr()== *(arrTestCase[i].expVal) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal->getLength() ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "appendAscii_001", i ) + ); + + res &= lastRes; + } + return ( res ); +} +//------------------------------------------------------------------------ +// testing the method appendAscii( const sal_Char * str, sal_Int32 len) +//------------------------------------------------------------------------ + +sal_Bool SAL_CALL test_rtl_OUStringBuffer_appendAscii_002( + hTestResult hRtlTestResult) +{ + sal_Char methName[MAXBUFLENGTH]; + sal_Char* pMeth = methName; + + OUString arrOUS[5]={OUString( aUStr7 ), + OUString(), + OUString( aUStr25 ), + OUString( "\0",0, + kEncodingRTLTextUSASCII, + kConvertFlagsOStringToOUString), + OUString( aUStr28 )}; + + typedef struct TestCase + { + sal_Char* comments; + OUString* expVal; + OUStringBuffer* input1; + const sal_Char* input2; + sal_Int32 input3; + + ~TestCase() { delete input1; delete expVal; } + } TestCase; + + TestCase arrTestCase[]={ + + {"Appends the string(length less than 16) to the string buffer arrOUS[0]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[0]), kTestStr36, 12 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[0]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[0]), kTestStr36, 28 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[0]", + new OUString(aUStr37), + new OUStringBuffer(arrOUS[0]), kTestStr23, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[0]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[0]), kTestStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[0]", + new OUString(aUStr41), + new OUStringBuffer(arrOUS[0]), kTestStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[1]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[1]), kTestStr2, 4 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[1]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[1]), kTestStr2, 32 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[1]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[1]), kTestStr2, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), kTestStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[1]", + new OUString(), + new OUStringBuffer(arrOUS[1]), kTestStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[2]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[2]), kTestStr2, 4 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[2]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[2]), kTestStr2, 32 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[2]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[2]), kTestStr2, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), kTestStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[2]", + new OUString(), + new OUStringBuffer(arrOUS[2]), kTestStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[3]", + new OUString(aUStr7), + new OUStringBuffer(arrOUS[3]), kTestStr2, 4 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[3]", + new OUString(aUStr2), + new OUStringBuffer(arrOUS[3]), kTestStr2, 32 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[3]", + new OUString(aUStr1), + new OUStringBuffer(arrOUS[3]), kTestStr2, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), kTestStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[3]", + new OUString(), + new OUStringBuffer(arrOUS[3]), kTestStr2, -1 }, + */ + {"Appends the string(length less than 16) to the string buffer arrOUS[4]", + new OUString(aUStr29), + new OUStringBuffer(arrOUS[4]), kTestStr38, 7 }, + {"Appends the string(length more than 16) to the string buffer arrOUS[4]", + new OUString(aUStr39), + new OUStringBuffer(arrOUS[4]), kTestStr17, 22 }, + {"Appends the string(length equal to 16) to the string buffer arrOUS[4]", + new OUString(aUStr40), + new OUStringBuffer(arrOUS[4]), kTestStr31, 16 }, + {"Appends the string(length equal to 0) to the string buffer arrOUS[4]", + new OUString(aUStr28), + new OUStringBuffer(arrOUS[4]), kTestStr2, 0 }, + /* LLA: input3 must null < 0 + {"Appends the string(length less than 0) to the string buffer arrOUS[4]", + new OUString(aUStr42), + new OUStringBuffer(arrOUS[4]), kTestStr2, -1 } + */ +#ifdef WITH_CORE + ,{"Appends the string(length equal to 0) to the string buffer(with INT_MAX) ", + new OUString(), + new OUStringBuffer(kSInt32Max), kTestStr25 } +#endif + }; + + + sal_Bool res = sal_True; + sal_uInt32 i; + + for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) + { + arrTestCase[i].input1->appendAscii( + arrTestCase[i].input2, arrTestCase[i].input3); + sal_Bool lastRes = + ( arrTestCase[i].input1->getStr()== *(arrTestCase[i].expVal) && + arrTestCase[i].input1->getLength() == arrTestCase[i].expVal->getLength() ); + + c_rtl_tres_state + ( + hRtlTestResult, + lastRes, + arrTestCase[i].comments, + createName( pMeth, "appendAscii_002", i ) + + ); + + res &= lastRes; + } + return ( res ); +} +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer_appendAsciis( + hTestResult hRtlTestResult ) +{ + c_rtl_tres_state_start( hRtlTestResult, "appendAsciis"); + sal_Bool bTSState = test_rtl_OUStringBuffer_appendAscii_001( hRtlTestResult ); + bTSState &= test_rtl_OUStringBuffer_appendAscii_002( hRtlTestResult); + + c_rtl_tres_state_end( hRtlTestResult, "appendAsciis"); +// return( bTSState ); +} +// ----------------------------------------------------------------------------- +extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUStringBuffer( hTestResult hRtlTestResult ) +{ + + c_rtl_tres_state_start(hRtlTestResult, "rtl_OUStringBuffer" ); + + test_rtl_OUStringBuffer_ctors( hRtlTestResult ); + test_rtl_OUStringBuffer_makeStringAndClear( hRtlTestResult ); + test_rtl_OUStringBuffer_getLength( hRtlTestResult ); + test_rtl_OUStringBuffer_getCapacity( hRtlTestResult ); + test_rtl_OUStringBuffer_ensureCapacity( hRtlTestResult ); + test_rtl_OUStringBuffer_setLength( hRtlTestResult ); + test_rtl_OUStringBuffer_charAt( hRtlTestResult ); + test_rtl_OUStringBuffer_csuc( hRtlTestResult ); + test_rtl_OUStringBuffer_getStr( hRtlTestResult ); + test_rtl_OUStringBuffer_setCharAt( hRtlTestResult ); + test_rtl_OUStringBuffer_appends( hRtlTestResult ); + test_rtl_OUStringBuffer_appendAsciis( hRtlTestResult ); + + c_rtl_tres_state_end(hRtlTestResult, "rtl_OUStringBuffer"); +} + +// ----------------------------------------------------------------------------- +void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) +{ + if (_pFunc) + { + (_pFunc)(&test_rtl_OUStringBuffer, ""); + } +} diff --git a/sal/qa/rtl_strings/rtl_String_Const.h b/sal/qa/rtl_strings/rtl_String_Const.h new file mode 100644 index 000000000000..686b152396bb --- /dev/null +++ b/sal/qa/rtl_strings/rtl_String_Const.h @@ -0,0 +1,888 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Const.h,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_CONST_H_ +#define _RTL_STRING_CONST_H_ + +#ifndef _RTL_STRING_UTILS_HXX_ + #include <rtl_String_Utils.hxx> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <limits.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +#ifndef _RTL_TEXTENC_H + #include <rtl/textenc.h> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#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 sal_Char *kTestStr1 = "Sun Microsystems"; +static const sal_Char *kTestStr2 = "Sun Microsystems Java Technology"; +static const sal_Char *kTestStr3 = "Sun microsystems"; +static const sal_Char *kTestStr4 = "SUN MICROSYSTEMS"; +static const sal_Char *kTestStr5 = "sun microsystems"; +static const sal_Char *kTestStr6 = "Java Technology"; +static const sal_Char *kTestStr7 = "Sun "; +static const sal_Char *kTestStr8 = "Microsystems"; +static const sal_Char *kTestStr9 = "sun microsystems java technology"; +static const sal_Char *kTestStr10 = " Sun Microsystems"; +static const sal_Char *kTestStr11 = "Sun Microsystems "; +static const sal_Char *kTestStr12 = " Sun Microsystems "; +static const sal_Char *kTestStr13 = "Sun Microsystems "; +static const sal_Char *kTestStr14 = " Sun Microsystems"; +static const sal_Char *kTestStr15 = " Sun Microsystems "; +static const sal_Char *kTestStr16 = " Sun Microsystems "; +static const sal_Char *kTestStr17 = " Sun Microsystems "; +static const sal_Char *kTestStr18 = "sUN MICROsYsTEMs"; +static const sal_Char *kTestStr19 = "---Sun-Microsystems---"; +static const sal_Char *kTestStr20 = "sun"; +static const sal_Char *kTestStr21 = "SUN"; +static const sal_Char *kTestStr22 = "SUN MICROSYSTEMS JAVA TECHNOLOGY"; +static const sal_Char *kTestStr23 = " Java Technology"; +static const sal_Char *kTestStr24 = "Sun Microsystems Java Technolog"; +static const sal_Char *kTestStr25 = ""; +static const sal_Char *kTestStr26 = " Mic"; +static const sal_Char *kTestStr27 = "s"; +static const sal_Char *kTestStr28 = "\50\3\5\7\11\13\15\17sun"; +static const sal_Char *kTestStr29 = "\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50"; +static const sal_Char *kTestStr30 = "sun\21\23\25\27\31\33\50"; +static const sal_Char *kTestStr31 = "sun Microsystems"; +static const sal_Char *kTestStr32 = "Sun Microsystem "; +static const sal_Char *kTestStr33 = " "; +static const sal_Char *kTestStr34 = "\50\5\5\7\11\13\15\17sun"; +static const sal_Char *kTestStr35 = "\50\373\5\7\11\13\15\17sun"; +static const sal_Char *kTestStr36 = "Microsystems Java Technology"; +static const sal_Char *kTestStr37 = "Sun Java Technology"; +static const sal_Char *kTestStr38 = "\21\23\25\27\31\33\50"; +static const sal_Char *kTestStr39 = "\50\3\5\7\11\13\15\17sun Sun Microsystems "; +static const sal_Char *kTestStr40 = "\50\3\5\7\11\13\15\17sunsun Microsystems"; +static const sal_Char *kTestStr41 = "Sun"; +static const sal_Char *kTestStr42 = "\50\3\5\7\11\13\15\17su"; +static const sal_Char *kTestStr43 = "\50\3\5\7\11\13\15\17sun\256\345"; +static const sal_Char *kTestStr44 = "\256\345"; +static const sal_Char *kTestStr45 = "Sun true"; +static const sal_Char *kTestStr46 = "Sun false"; +static const sal_Char *kTestStr47 = "true"; +static const sal_Char *kTestStr48 = "false"; +static const sal_Char *kTestStr49 = "\50\3\5\7\11\13\15\17suntrue"; +static const sal_Char *kTestStr50 = "\50\3\5\7\11\13\15\17sunfalse"; +static const sal_Char *kTestStr51 = "Sun M"; +//static const sal_Char *kTestStr52 = "Sun \077777"; +//static const sal_Char *kTestStr53 = "Sun \100000"; +//static const sal_Char *kTestStr54 = "\77777"; +//static const sal_Char *kTestStr55 = "\100000"; +static const sal_Char *kTestStr56 = "\50\3\5\7\11\13\15\17suns"; +//static const sal_Char *kTestStr57 = "\50\3\5\7\11\13\15\17sun\77777"; +//static const sal_Char *kTestStr58 = "\50\3\5\7\11\13\15\17sun\10000"; +static const sal_Char *kTestStr1PlusStr6 = "Sun Microsystems" "Java Technology"; +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +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 kTestStr1PlusStr6Len = kTestStr1Len + kTestStr6Len; + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + static sal_Unicode aUStr1[kTestStr1Len+1]; + static sal_Unicode aUStr2[kTestStr2Len+1]; + static sal_Unicode aUStr3[kTestStr3Len+1]; + static sal_Unicode aUStr4[kTestStr4Len+1]; + static sal_Unicode aUStr5[kTestStr5Len+1]; + static sal_Unicode aUStr6[kTestStr6Len+1]; + static sal_Unicode aUStr7[kTestStr7Len+1]; + static sal_Unicode aUStr8[kTestStr8Len+1]; + static sal_Unicode aUStr9[kTestStr9Len+1]; + static sal_Unicode aUStr10[kTestStr10Len+1]; + static sal_Unicode aUStr11[kTestStr11Len+1]; + static sal_Unicode aUStr12[kTestStr12Len+1]; + static sal_Unicode aUStr13[kTestStr13Len+1]; + static sal_Unicode aUStr14[kTestStr14Len+1]; + static sal_Unicode aUStr15[kTestStr15Len+1]; + static sal_Unicode aUStr16[kTestStr16Len+1]; + static sal_Unicode aUStr17[kTestStr17Len+1]; + static sal_Unicode aUStr18[kTestStr18Len+1]; + static sal_Unicode aUStr19[kTestStr19Len+1]; + static sal_Unicode aUStr20[kTestStr20Len+1]; + static sal_Unicode aUStr21[kTestStr21Len+1]; + static sal_Unicode aUStr22[kTestStr22Len+1]; + static sal_Unicode aUStr23[kTestStr23Len+1]; + static sal_Unicode aUStr24[kTestStr24Len+1]; + static sal_Unicode aUStr25[kTestStr25Len+1]; + static sal_Unicode aUStr26[kTestStr26Len+1]; + static sal_Unicode aUStr27[kTestStr27Len+1]; + static sal_Unicode aUStr28[kTestStr28Len+1]; + static sal_Unicode aUStr29[kTestStr29Len+1]; + static sal_Unicode aUStr30[kTestStr30Len+1]; + static sal_Unicode aUStr31[kTestStr31Len+1]; + static sal_Unicode aUStr32[kTestStr32Len+1]; + static sal_Unicode aUStr33[kTestStr33Len+1]; + static sal_Unicode aUStr34[kTestStr34Len+1]; + static sal_Unicode aUStr35[kTestStr35Len+1]; + static sal_Unicode aUStr36[kTestStr36Len+1]; + static sal_Unicode aUStr37[kTestStr37Len+1]; + static sal_Unicode aUStr38[kTestStr38Len+1]; + static sal_Unicode aUStr39[kTestStr39Len+1]; + static sal_Unicode aUStr40[kTestStr40Len+1]; + static sal_Unicode aUStr41[kTestStr41Len+1]; + static sal_Unicode aUStr42[kTestStr42Len+1]; + static sal_Unicode aUStr43[kTestStr43Len+1]; + static sal_Unicode aUStr44[kTestStr44Len+1]; + static sal_Unicode aUStr45[kTestStr45Len+1]; + static sal_Unicode aUStr46[kTestStr46Len+1]; + static sal_Unicode aUStr47[kTestStr47Len+1]; + static sal_Unicode aUStr48[kTestStr48Len+1]; + static sal_Unicode aUStr49[kTestStr49Len+1]; + static sal_Unicode aUStr50[kTestStr50Len+1]; + static sal_Unicode aUStr51[kTestStr51Len+1]; +// static sal_Unicode aUStr52[kTestStr52Len+1]={83,117,110,32,32767}; +// static sal_Unicode aUStr53[kTestStr53Len+1]={83,117,110,32,SAL_MIN_INT16 /*-32768*/}; +// static sal_Unicode aUStr54[kTestStr54Len+1]={32767}; +// static sal_Unicode aUStr55[kTestStr55Len+1]={SAL_MIN_INT16 /*-32768*/}; + static sal_Unicode aUStr56[kTestStr56Len+1]; +// static sal_Unicode aUStr57[kTestStr57Len+1]={40,3,5,7,9,11,13,15,115,117,110,32767}; +// static sal_Unicode aUStr58[kTestStr58Len+1]={40,3,5,7,9,11,13,15,115,117,110,SAL_MIN_INT16 /*-32768*/}; + static sal_Unicode aUStr1PlusUStr6[kTestStr1Len + kTestStr6Len + 1]; + +// we are already in "C" + +static sal_Bool SAL_CALL test_ini_uString() +{ + + sal_Bool iniResult= sal_True; + + iniResult &=AStringToUStringNCopy( aUStr1, kTestStr1, kTestStr1Len ); + + iniResult &=AStringToUStringNCopy( aUStr2, kTestStr2, kTestStr2Len ); + + iniResult &=AStringToUStringNCopy( aUStr3, kTestStr3, kTestStr3Len ); + + iniResult &=AStringToUStringNCopy( aUStr4, kTestStr4, kTestStr4Len ); + + iniResult &=AStringToUStringNCopy( aUStr5, kTestStr5, kTestStr5Len ); + + iniResult &=AStringToUStringNCopy( aUStr6, kTestStr6, kTestStr6Len ); + + iniResult &=AStringToUStringNCopy( aUStr7, kTestStr7, kTestStr7Len ); + + iniResult &=AStringToUStringNCopy( aUStr8, kTestStr8, kTestStr8Len ); + + iniResult &=AStringToUStringNCopy( aUStr9, kTestStr9, kTestStr9Len ); + + iniResult &=AStringToUStringNCopy( aUStr10, kTestStr10, kTestStr10Len ); + + iniResult &=AStringToUStringNCopy( aUStr11, kTestStr11, kTestStr11Len ); + + iniResult &=AStringToUStringNCopy( aUStr12, kTestStr12, kTestStr12Len ); + + iniResult &=AStringToUStringNCopy( aUStr13, kTestStr13, kTestStr13Len ); + + iniResult &=AStringToUStringNCopy( aUStr14, kTestStr14, kTestStr14Len ); + + iniResult &=AStringToUStringNCopy( aUStr15, kTestStr15, kTestStr15Len ); + + iniResult &=AStringToUStringNCopy( aUStr16, kTestStr16, kTestStr16Len ); + + iniResult &=AStringToUStringNCopy( aUStr17, kTestStr17, kTestStr17Len ); + + iniResult &=AStringToUStringNCopy( aUStr18, kTestStr18, kTestStr18Len ); + + iniResult &=AStringToUStringNCopy( aUStr19, kTestStr19, kTestStr19Len ); + + iniResult &=AStringToUStringNCopy( aUStr20, kTestStr20, kTestStr20Len ); + + iniResult &=AStringToUStringNCopy( aUStr21, kTestStr21, kTestStr21Len ); + + iniResult &=AStringToUStringNCopy( aUStr22, kTestStr22, kTestStr22Len ); + + iniResult &=AStringToUStringNCopy( aUStr23, kTestStr23, kTestStr23Len ); + + iniResult &=AStringToUStringNCopy( aUStr1PlusUStr6, kTestStr1PlusStr6, kTestStr1PlusStr6Len ); + + iniResult &=AStringToUStringNCopy( aUStr24, kTestStr24, kTestStr24Len ); + + iniResult &=AStringToUStringNCopy( aUStr25, kTestStr25, kTestStr25Len ); + + iniResult &=AStringToUStringNCopy( aUStr26, kTestStr26, kTestStr26Len ); + + iniResult &=AStringToUStringNCopy( aUStr27, kTestStr27, kTestStr27Len ); + + iniResult &=AStringToUStringNCopy( aUStr28, kTestStr28, kTestStr28Len ); + + iniResult &=AStringToUStringNCopy( aUStr29, kTestStr29, kTestStr29Len ); + + iniResult &=AStringToUStringNCopy( aUStr30, kTestStr30, kTestStr30Len ); + + iniResult &=AStringToUStringNCopy( aUStr31, kTestStr31, kTestStr31Len ); + + iniResult &=AStringToUStringNCopy( aUStr32, kTestStr32, kTestStr32Len ); + + iniResult &=AStringToUStringNCopy( aUStr33, kTestStr33, kTestStr33Len ); + + iniResult &=AStringToUStringNCopy( aUStr34, kTestStr34, kTestStr34Len ); + + iniResult &=AStringToUStringNCopy( aUStr35, kTestStr35, kTestStr35Len ); + + iniResult &=AStringToUStringNCopy( aUStr36, kTestStr36, kTestStr36Len ); + + iniResult &=AStringToUStringNCopy( aUStr37, kTestStr37, kTestStr37Len ); + + iniResult &=AStringToUStringNCopy( aUStr38, kTestStr38, kTestStr38Len ); + + iniResult &=AStringToUStringNCopy( aUStr39, kTestStr39, kTestStr39Len ); + + iniResult &=AStringToUStringNCopy( aUStr40, kTestStr40, kTestStr40Len ); + + iniResult &=AStringToUStringNCopy( aUStr41, kTestStr41, kTestStr41Len ); + + iniResult &=AStringToUStringNCopy( aUStr42, kTestStr42, kTestStr42Len ); + + iniResult &=AStringToUStringNCopy( aUStr43, kTestStr43, kTestStr43Len ); + + iniResult &=AStringToUStringNCopy( aUStr44, kTestStr44, kTestStr44Len ); + + iniResult &=AStringToUStringNCopy( aUStr45, kTestStr45, kTestStr45Len ); + + iniResult &=AStringToUStringNCopy( aUStr46, kTestStr46, kTestStr46Len ); + + iniResult &=AStringToUStringNCopy( aUStr47, kTestStr47, kTestStr47Len ); + + iniResult &=AStringToUStringNCopy( aUStr48, kTestStr48, kTestStr48Len ); + + iniResult &=AStringToUStringNCopy( aUStr49, kTestStr49, kTestStr49Len ); + + iniResult &=AStringToUStringNCopy( aUStr50, kTestStr50, kTestStr50Len ); + + iniResult &=AStringToUStringNCopy( aUStr51, kTestStr51, kTestStr51Len ); + + //iniResult &=AStringToUStringNCopy( aUStr52, kTestStr52, kTestStr52Len ); + + // iniResult &=AStringToUStringNCopy( aUStr53, kTestStr53, kTestStr53Len ); + + //iniResult &=AStringToUStringNCopy( aUStr54, kTestStr54, kTestStr54Len ); + + //iniResult &=AStringToUStringNCopy( aUStr55, kTestStr55, kTestStr55Len ); + + iniResult &=AStringToUStringNCopy( aUStr56, kTestStr56, kTestStr56Len ); + + // iniResult &=AStringToUStringNCopy( aUStr57, kTestStr57, kTestStr57Len ); + + //iniResult &=AStringToUStringNCopy( aUStr58, kTestStr58, kTestStr58Len ); + return iniResult; + +} + + + + +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; +#if (defined UNX) || (defined OS2) +static const sal_Int64 kSInt64Max = 9223372036854775807LL; +#else +static const sal_Int64 kSInt64Max = 9223372036854775807; +#endif +//------------------------------------------------------------------------ + +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_Char *kSInt8MaxBinaryStr = "1111111"; +static const sal_Char *kUInt8MaxBinaryStr = "11111111"; +static const sal_Char *kSInt16MaxBinaryStr = "111111111111111"; +static const sal_Char *kUInt16MaxBinaryStr = "1111111111111111"; +static const sal_Char *kSInt32MaxBinaryStr = + "1111111111111111111111111111111"; +static const sal_Char *kUInt32MaxBinaryStr = + "11111111111111111111111111111111"; +static const sal_Char *kSInt64MaxBinaryStr = + "111111111111111111111111111111111111111111111111111111111111111"; + +//------------------------------------------------------------------------ + +static const sal_Char *kSInt8MaxOctolStr = "177"; +static const sal_Char *kUInt8MaxOctolStr = "377"; +static const sal_Char *kSInt16MaxOctolStr = "77777"; +static const sal_Char *kUInt16MaxOctolStr = "177777"; +static const sal_Char *kSInt32MaxOctolStr = "17777777777"; +static const sal_Char *kUInt32MaxOctolStr = "37777777777"; +static const sal_Char *kSInt64MaxOctolStr = "777777777777777777777"; + +//------------------------------------------------------------------------ + +static const sal_Char *kSInt8MaxDecimalStr = "127"; +static const sal_Char *kUInt8MaxDecimalStr = "255"; +static const sal_Char *kSInt16MaxDecimalStr = "32767"; +static const sal_Char *kUInt16MaxDecimalStr = "65535"; +static const sal_Char *kSInt32MaxDecimalStr = "2147483647"; +static const sal_Char *kUInt32MaxDecimalStr = "4294967295"; +static const sal_Char *kSInt64MaxDecimalStr = "9223372036854775807"; + +//------------------------------------------------------------------------ + +static const sal_Char *kSInt8MaxHexDecimalStr = "7f"; +static const sal_Char *kUInt8MaxHexDecimalStr = "ff"; +static const sal_Char *kSInt16MaxHexDecimalStr = "7fff"; +static const sal_Char *kUInt16MaxHexDecimalStr = "ffff"; +static const sal_Char *kSInt32MaxHexDecimalStr = "7fffffff"; +static const sal_Char *kUInt32MaxHexDecimalStr = "ffffffff"; +static const sal_Char *kSInt64MaxHexDecimalStr = "7fffffffffffffff"; + +//------------------------------------------------------------------------ + +static const sal_Char *kSInt8MaxBase36Str = "3j"; +static const sal_Char *kUInt8MaxBase36Str = "73"; +static const sal_Char *kSInt16MaxBase36Str = "pa7"; +static const sal_Char *kUInt16MaxBase36Str = "1ekf"; +static const sal_Char *kSInt32MaxBase36Str = "zik0zj"; +static const sal_Char *kUInt32MaxBase36Str = "1z141z3"; +static const sal_Char *kSInt64MaxBase36Str = "1y2p0ij32e8e7"; + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +static const sal_Int32 kBinaryNumsCount = 16; + +static const sal_Char *kBinaryNumsStr[kBinaryNumsCount] = + { + "0", "1", "10", "11", + "100", "101", "110", "111", + "1000", "1001", "1010", "1011", + "1100", "1101", "1110", "1111" + }; + +static const sal_Int32 kBinaryMaxNumsCount = 7; + +static const sal_Char *kBinaryMaxNumsStr[kBinaryMaxNumsCount] = + { + kSInt8MaxBinaryStr, + kUInt8MaxBinaryStr, + kSInt16MaxBinaryStr, + kUInt16MaxBinaryStr, + kSInt32MaxBinaryStr, + kUInt32MaxBinaryStr, + kSInt64MaxBinaryStr + }; + +//------------------------------------------------------------------------ + +static const sal_Int32 kOctolNumsCount = 16; + +static const sal_Char *kOctolNumsStr[kOctolNumsCount] = + { + "0", "1", "2", "3", + "4", "5", "6", "7", + "10", "11", "12", "13", + "14", "15", "16", "17" + }; + +static const sal_Int32 kOctolMaxNumsCount = 7; + +static const sal_Char *kOctolMaxNumsStr[kOctolMaxNumsCount] = + { + kSInt8MaxOctolStr, + kUInt8MaxOctolStr, + kSInt16MaxOctolStr, + kUInt16MaxOctolStr, + kSInt32MaxOctolStr, + kUInt32MaxOctolStr, + kSInt64MaxOctolStr + }; + +//------------------------------------------------------------------------ + +static const sal_Int32 kDecimalNumsCount = 16; + +static const sal_Char *kDecimalNumsStr[kDecimalNumsCount] = + { + "0", "1", "2", "3", + "4", "5", "6", "7", + "8", "9", "10", "11", + "12", "13", "14", "15" + }; + +static const sal_Int32 kDecimalMaxNumsCount = 7; + +static const sal_Char *kDecimalMaxNumsStr[kDecimalMaxNumsCount] = + { + kSInt8MaxDecimalStr, + kUInt8MaxDecimalStr, + kSInt16MaxDecimalStr, + kUInt16MaxDecimalStr, + kSInt32MaxDecimalStr, + kUInt32MaxDecimalStr, + kSInt64MaxDecimalStr + }; + +//------------------------------------------------------------------------ + +static const sal_Int32 kHexDecimalNumsCount = 16; + +static const sal_Char *kHexDecimalNumsStr[kHexDecimalNumsCount] = + { + "0", "1", "2", "3", + "4", "5", "6", "7", + "8", "9", "a", "b", + "c", "d", "e", "f" + }; + +static const sal_Int32 kHexDecimalMaxNumsCount = 7; + +static const sal_Char *kHexDecimalMaxNumsStr[kHexDecimalMaxNumsCount] = + { + kSInt8MaxHexDecimalStr, + kUInt8MaxHexDecimalStr, + kSInt16MaxHexDecimalStr, + kUInt16MaxHexDecimalStr, + kSInt32MaxHexDecimalStr, + kUInt32MaxHexDecimalStr, + kSInt64MaxHexDecimalStr + }; + +//------------------------------------------------------------------------ + +static const sal_Int32 kBase36NumsCount = 36; + +static const sal_Char *kBase36NumsStr[kBase36NumsCount] = + { + "0", "1", "2", "3", + "4", "5", "6", "7", + "8", "9", "a", "b", + "c", "d", "e", "f", + "g", "h", "i", "j", + "k", "l", "m", "n", + "o", "p", "q", "r", + "s", "t", "u", "v", + "w", "x", "y", "z" + }; + +static const sal_Int32 kBase36MaxNumsCount = 7; + +static const sal_Char *kBase36MaxNumsStr[kBase36MaxNumsCount] = + { + kSInt8MaxBase36Str, + kUInt8MaxBase36Str, + kSInt16MaxBase36Str, + kUInt16MaxBase36Str, + kSInt32MaxBase36Str, + kUInt32MaxBase36Str, + kSInt64MaxBase36Str + }; + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +static const sal_Int32 nDoubleCount=24; +// static const sal_Char *inputDouble[nDoubleCount] = +// { +// "3","3.1","3.1415","3.1415926535","3.141592653589793", +// "3.1415926535897932","3.14159265358979323","+3.1", +// "3.141592653589793238462643","9.1096e-31","2.997925e8","6.241e18","5.381e+18", +// "1.7e-309","6.5822e-16","1.7e+307","2.2e30","03.1"," 3.1","-3.1", +// "-0.0","0.0","","1.00e308" +// }; +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 sal_Char *inputFloat[nFloatCount] = +// { +// "3", +// "3.1", +// "3.1415", +// "3.14159", +// "3.141592", +// "3.1415926", +// "3.14159265", +// "3.141592653589793238462643", +// "6.5822e-16", +// "9.1096e-31", +// "2.997925e8", +// "6.241e18", +// "1.00e38", +// "6.241e-37", +// "6.241e37", +// "03.1", +// " 3.1", +// "-3.1", +// "+3.1", +// "-0.0", +// "0.0", +// "" +// }; +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 float fPrecision[nFloatCount] = + { + 3e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 6e-16f * 1e-7f, + 9e-31f * 1e-7f, + 3e8f * 1e-7f, + 6e18f * 1e-7f, + 1e38f * 1e-7f, + 6e-37f * 1e-7f, + 6e37f * 1e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 3e-7f, + 1e-7f, + 1e-7f, + 1e-7f + }; +//------------------------------------------------------------------------ +static const sal_Int32 nCharCount=15; +static const sal_Char *inputChar[nCharCount] = + { + "A","a","0","-","_", + "\25","\33","\35", + "@","\n","\'","\"", + "\0","","Sun Microsystems" + }; +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_Unicode *input1StrDefault[nStrDefaultCount] = + { + aUStr7,aUStr8,aUStr21, + aUStr30,aUStr25,aUStr26 + }; +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_Unicode *input1StrNormal[nStrNormalCount] = + { + aUStr7,aUStr7,aUStr8,aUStr8,aUStr21,aUStr30,aUStr25,aUStr25,aUStr26 + }; +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_Unicode *input1StrLastDefault[nStrLastDefaultCount] = + { + aUStr7,aUStr8,aUStr21,aUStr30,aUStr25,aUStr26 + }; +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_Unicode *input1StrLastNormal[nStrLastNormalCount] = + { + aUStr7,aUStr7,aUStr7,aUStr8,aUStr8,aUStr21,aUStr30, + aUStr25,aUStr25,aUStr26,aUStr27,aUStr27 + }; +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 /* _RTL_STRING_CONST_H_ */ + diff --git a/sal/qa/rtl_strings/rtl_String_Utils.cxx b/sal/qa/rtl_strings/rtl_String_Utils.cxx new file mode 100644 index 000000000000..1800ee37ef89 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_String_Utils.cxx @@ -0,0 +1,596 @@ +/************************************************************************* +# + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Utils.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * +#*************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <math.h> +#include <stdlib.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +#ifndef _RTL_STRING_HXX_ + #include <rtl/string.hxx> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_UTILS_CONST_H_ + #include <rtl_String_Utils_Const.h> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +using namespace rtl; + +sal_uInt32 AStringLen( const sal_Char *pAStr ) +{ + sal_uInt32 nStrLen = 0; + + if ( pAStr != NULL ) + { + const sal_Char *pTempStr = pAStr; + + while( *pTempStr ) + { + pTempStr++; + } // while + + nStrLen = (sal_uInt32)( pTempStr - pAStr ); + } // if + + return nStrLen; +} // AStringLen +sal_Char* cpystr( sal_Char* dst, const sal_Char* src ) +{ + const sal_Char* psrc = src; + sal_Char* pdst = dst; + + while( *pdst++ = *psrc++ ); + return ( dst ); +} + +sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt ) +{ + + const sal_Char* psrc = src; + sal_Char* pdst = dst; + sal_uInt32 len = cnt; + sal_uInt32 i; + + if ( len >= AStringLen(src) ) + { + return( cpystr( dst, src ) ); + } + + // copy string by char + for( i = 0; i < len; i++ ) + *pdst++ = *psrc++; + *pdst = '\0'; + + return ( dst ); +} + +//------------------------------------------------------------------------ +sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len ) +{ + const sal_Char* pBuf1 = str1; + const sal_Char* pBuf2 = str2; + sal_uInt32 i = 0; + + while ( (*pBuf1 == *pBuf2) && i < len ) + { + (pBuf1)++; + (pBuf2)++; + i++; + } + return( i == len ); +} +//------------------------------------------------------------------------ +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len ) +{ + const sal_Unicode* pBuf1 = str1; + const sal_Unicode* pBuf2 = str2; + sal_uInt32 i = 0; + + while ( (*pBuf1 == *pBuf2) && i < len ) + { + (pBuf1)++; + (pBuf2)++; + i++; + } + return( i == len ); +} + +//----------------------------------------------------------------------- +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 ) +{ + const sal_Unicode* pBuf1 = str1; + const sal_Unicode* pBuf2 = str2; + sal_Bool res = sal_True; + + while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0') + { + (pBuf1)++; + (pBuf2)++; + } + if (*pBuf1 == '\0' && *pBuf2 == '\0') + res = sal_True; + else + res = sal_False; + return (res); +} + +sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt ) +{ + sal_Char* pdst = dst; + sal_Char nstr[16]; + sal_Char* pstr = nstr; + rtl_str_valueOfInt32( pstr, cnt, 10 ); + + cpystr( pdst, meth ); + cpystr( pdst+ AStringLen(meth), "_" ); + + if ( cnt < 100 ) + { + cpystr(pdst + AStringLen(pdst), "0" ); + } + if ( cnt < 10 ) + { + cpystr(pdst + AStringLen(pdst), "0" ); + } + + cpystr( pdst + AStringLen(pdst), nstr ); + return( pdst ); +} + +//------------------------------------------------------------------------ +// testing the method compareTo( const OString & aStr ) +//------------------------------------------------------------------------ +void makeComment( char *com, const char *str1, const char *str2, + sal_Int32 sgn ) +{ + cpystr(com, str1); + int str1Length = AStringLen( str1 ); + const char *sign = (sgn == 0) ? " == " : (sgn > 0) ? " > " : " < " ; + cpystr(com + str1Length, sign); + int signLength = AStringLen(sign); + cpystr(com + str1Length + signLength, str2); + com[str1Length + signLength + AStringLen(str2)] = 0; +} + + +//------------------------------------------------------------------------ + +sal_Bool AStringToFloatCompare ( const sal_Char *pStr, + const float nX, + const float nEPS + ) +{ + sal_Bool cmp = sal_False; + + if ( pStr != NULL ) + { + ::rtl::OString aStr(pStr); + + float actNum = 0; + float expNum = nX; + float eps = nEPS; + + actNum = aStr.toFloat(); + + if ( abs( (int)(actNum - expNum) ) <= eps ) + { + cmp = sal_True; + } // if + } // if + + return cmp; +} // AStringToFloatCompare + +//------------------------------------------------------------------------ + +sal_Bool AStringToDoubleCompare ( const sal_Char *pStr, + const double nX, + const double nEPS + ) +{ + sal_Bool cmp = sal_False; + + if ( pStr != NULL ) + { + ::rtl::OString aStr(pStr); + + double actNum = 0; + double expNum = nX; + double eps = nEPS; + + actNum = aStr.toDouble(); + + if ( abs( (int)(actNum - expNum) ) <= eps ) + { + cmp = sal_True; + } // if + } // if + + return cmp; +} // AStringToDoubleCompare + +//------------------------------------------------------------------------ + + +//------------------------------------------------------------------------ + +sal_uInt32 UStringLen( const sal_Unicode *pUStr ) +{ + sal_uInt32 nUStrLen = 0; + + if ( pUStr != NULL ) + { + const sal_Unicode *pTempUStr = pUStr; + + while( *pTempUStr ) + { + pTempUStr++; + } // while + + nUStrLen = (sal_uInt32)( pTempUStr - pUStr ); + } // if + + return nUStrLen; +} // UStringLen + +//------------------------------------------------------------------------ + +sal_Bool AStringIsValid( const sal_Char *pAStr ) +{ + if ( pAStr != NULL ) + { + sal_uInt32 nLen = AStringLen( pAStr ); + sal_uChar uChar = 0; + + while ( ( nLen >= 0 ) && ( *pAStr ) ) + { + uChar = (unsigned char)*pAStr; + + if ( uChar > 127 ) + { + return sal_False; + } // if + + pAStr++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nLen > 0 ) + { + nLen--; + } // if + else + { + break; + } // else + } // while + } // if + + return sal_True; +} // AStringIsValid + +//------------------------------------------------------------------------ + +sal_Bool AStringNIsValid( const sal_Char *pAStr, + const sal_uInt32 nStrLen + ) +{ + sal_uInt32 nLen = nStrLen; + sal_uChar uChar = 0; + + while ( ( nLen >= 0 ) && ( *pAStr ) ) + { + uChar = (unsigned char)*pAStr; + + if ( uChar > 127 ) + { + return sal_False; + } // if + + pAStr++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nLen > 0 ) + { + nLen--; + } // if + else + { + break; + } // else + } // while + + return sal_True; +} // AStringNIsValid + +//------------------------------------------------------------------------ + +static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr + ) +{ + sal_Int32 nCmp = 0; + sal_Int32 nUChar = (sal_Int32)*pUStr; + sal_Int32 nChar = (sal_Int32)((unsigned char)*pAStr); + + nCmp = nUChar - nChar; + + return nCmp; +} // ACharToUCharCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToUStringCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr + ) +{ + sal_Int32 nCmp = kErrCompareAStringToUString; + + if ( ( pUStr != NULL ) && ( pAStr != NULL ) ) + { + nCmp = ACharToUCharCompare( pUStr, pAStr ); + + while ( ( nCmp == 0 ) && ( *pAStr ) ) + { + pUStr++; + pAStr++; + + nCmp = ACharToUCharCompare( pUStr, pAStr ); + } // while + } // if + + return nCmp; +} // AStringToUStringCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToUStringNCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ) +{ + sal_Int32 nCmp = kErrCompareNAStringToUString; + + if ( ( pUStr != NULL ) && ( pAStr != NULL ) ) + { + sal_uInt32 nCount = nAStrCount; + + nCmp = ACharToUCharCompare( pUStr, pAStr ); + + while ( ( nCmp == 0 ) && ( *pAStr ) && ( nCount ) ) + { + pUStr++; + pAStr++; + + nCmp = ACharToUCharCompare( pUStr, pAStr ); + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nCount > 0 ) + { + nCount--; + } // if + else + { + break; + } // else + } // while + } // if + + return nCmp; +} // AStringToUStringNCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToRTLUStringCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr + ) +{ + sal_Int32 nCmp = kErrCompareAStringToRTLUString; + + if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) ) + { + rtl_uString *pRTLUStrCopy = NULL; + + rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr ); + + if ( pRTLUStrCopy != NULL ) + { + const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy ); + + if ( pUStr != NULL ) + { + nCmp = AStringToUStringCompare( pUStr, pAStr ); + } // if + + rtl_uString_release( pRTLUStrCopy ); + + pRTLUStrCopy = NULL; + } // if + } // if + + return nCmp; +} // AStringToRTLUStringCompare + +//------------------------------------------------------------------------ + +sal_Int32 AStringToRTLUStringNCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ) +{ + sal_Int32 nCmp = kErrCompareNAStringToRTLUString; + + if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) ) + { + rtl_uString *pRTLUStrCopy = NULL; + + rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr ); + + if ( pRTLUStrCopy != NULL ) + { + const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy ); + + if ( pUStr != NULL ) + { + nCmp = AStringToUStringNCompare( pUStr, pAStr, nAStrCount ); + } // if + + rtl_uString_release( pRTLUStrCopy ); + + pRTLUStrCopy = NULL; + } // if + } // if + + return nCmp; +} // AStringToRTLUStringNCompare + +//------------------------------------------------------------------------ + +sal_Bool AStringToUStringCopy( sal_Unicode *pDest, + const sal_Char *pSrc + ) +{ + sal_Bool bCopied = sal_False; + sal_uInt32 nCount = AStringLen( pSrc ); + sal_uInt32 nLen = nCount; + + if ( ( pDest != NULL ) + && ( pSrc != NULL ) + && ( AStringNIsValid( pSrc, nLen ) ) + ) + { + while ( nCount >= 0 ) + { + *pDest = (unsigned char)*pSrc; + + pDest++; + pSrc++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nCount > 0 ) + { + nCount--; + } // if + else + { + break; + } // else + } // while + + if ( nCount == 0 ) + { + bCopied = sal_True; + } // if + } // if + + return bCopied; +} // AStringToUStringCopy + +//------------------------------------------------------------------------ + +sal_Bool AStringToUStringNCopy( sal_Unicode *pDest, + const sal_Char *pSrc, + const sal_uInt32 nSrcLen + ) +{ + sal_Bool bCopied = sal_False; + sal_uInt32 nCount = nSrcLen; + sal_uInt32 nLen = nSrcLen; + + if ( ( pDest != NULL ) + && ( pSrc != NULL ) + && ( AStringNIsValid( pSrc, nLen ) ) + ) + { + while ( nCount >= 0 ) + { + *pDest = (unsigned char)*pSrc; + + pDest++; + pSrc++; + + // Since we are dealing with unsigned integers + // we want to make sure that the last number is + // indeed zero. + + if ( nCount > 0 ) + { + nCount--; + } // if + else + { + break; + } // else + } // while + + if ( nCount == 0 ) + { + bCopied = sal_True; + } // if + } // if + + return bCopied; +} // AStringToUStringNCopy + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + diff --git a/sal/qa/rtl_strings/rtl_String_Utils.hxx b/sal/qa/rtl_strings/rtl_String_Utils.hxx new file mode 100644 index 000000000000..23e253be3d21 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_String_Utils.hxx @@ -0,0 +1,140 @@ +/************************************************************************* +# + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Utils.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * +#*************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_UTILS_HXX_ +#define _RTL_STRING_UTILS_HXX_ + +#ifdef __cplusplus + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#include <math.h> +#include <stdlib.h> + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +#ifndef _RTL_USTRING_H_ + #include <rtl/ustring.h> +#endif + +#ifndef _RTL_STRING_HXX_ + #include <rtl/string.hxx> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +sal_Char* cpystr( sal_Char* dst, const sal_Char* src ); +sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt ); + +sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len ); +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len ); +sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 ); + +sal_Char* createName( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt ); +void makeComment(char *com, const char *str1, const char *str2, sal_Int32 sgn); + + +sal_uInt32 AStringLen( const sal_Char *pAStr ); + +sal_uInt32 UStringLen( const sal_Unicode *pUStr ); + +//------------------------------------------------------------------------ + +sal_Bool AStringToFloatCompare ( const sal_Char *pStr, + const float nX, + const float nEPS + ); + +sal_Bool AStringToDoubleCompare ( const sal_Char *pStr, + const double nX, + const double nEPS + ); + +//------------------------------------------------------------------------ + +sal_Bool AStringIsValid( const sal_Char *pAStr ); + +sal_Bool AStringNIsValid( const sal_Char *pAStr, + const sal_uInt32 nStrLen + ); + +//------------------------------------------------------------------------ + +sal_Int32 AStringToUStringCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr + ); + +sal_Int32 AStringToUStringNCompare( const sal_Unicode *pUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ); + +sal_Int32 AStringToRTLUStringCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr + ); + +sal_Int32 AStringToRTLUStringNCompare( const rtl_uString *pRTLUStr, + const sal_Char *pAStr, + const sal_uInt32 nAStrCount + ); + +//------------------------------------------------------------------------ + +sal_Bool AStringToUStringCopy( sal_Unicode *pDest, + const sal_Char *pSrc + ); + +sal_Bool AStringToUStringNCopy( sal_Unicode *pDest, + const sal_Char *pSrc, + const sal_uInt32 nSrcLen + ); + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#endif /* __cplusplus */ + +#endif /* _RTL_STRING_UTILS_HXX */ + + + + + + + diff --git a/sal/qa/rtl_strings/rtl_String_Utils_Const.h b/sal/qa/rtl_strings/rtl_String_Utils_Const.h new file mode 100644 index 000000000000..0ef1ea058930 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_String_Utils_Const.h @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_String_Utils_Const.h,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _RTL_STRING_UTILS_CONST_H_ +#define _RTL_STRING_UTILS_CONST_H_ + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#ifndef _SAL_TYPES_H_ + #include <sal/types.h> +#endif + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ + +#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 /* _RTL_STRING_UTILS_CONST_H_ */ + + + diff --git a/sal/qa/rtl_strings/rtl_old_testostring.cxx b/sal/qa/rtl_strings/rtl_old_testostring.cxx new file mode 100644 index 000000000000..329eb71c7dc5 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_old_testostring.cxx @@ -0,0 +1,269 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_old_testostring.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + + +// ----------------------------------------------------------------------------- +#include <string.h> +#include <stdio.h> + +// #ifndef _OSL_DIAGNOSE_H_ +// #include <osl/diagnose.h> +// #endif + +#ifndef _RTL_STRING_HXX +#include <rtl/string.hxx> +#endif + +#include <testshl/simpleheader.hxx> + +#define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c)) + +// #if OSL_DEBUG_LEVEL > 0 +// #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m) +// #else +// #define TEST_ENSHURE(c, m) OSL_VERIFY(c) +// #endif + +using namespace rtl; + +// ----------------------------------------------------------------------------- +namespace rtl_OString +{ + class oldtests : public CppUnit::TestFixture + { + public: + void test_OString(); + + CPPUNIT_TEST_SUITE( oldtests ); + CPPUNIT_TEST( test_OString ); + CPPUNIT_TEST_SUITE_END( ); + }; + + +#ifdef WNT +#pragma warning( disable : 4723 ) +#endif + +void oldtests::test_OString() +{ + TEST_ENSURE( sal_True, "_USENAMEPSACE defined"); + + // "Mein erster RTL OString\n" + // | | | | | + // Index 0 5 10 15 20 + OString s1("Mein erster RTL OString\n"); + TEST_ENSURE( s1 == "Mein erster RTL OString\n", "test_OString error 1"); + TEST_ENSURE( s1.getLength() == 24, "test_OString error 2"); + + OString s2 = s1; + TEST_ENSURE( s2[16] == 'O', "test_OString error 3"); + TEST_ENSURE( s2.equals(s1), "test_OString error 4"); + TEST_ENSURE( s2.indexOf('O') == 16, "test_OString error 5"); + TEST_ENSURE( s2.indexOf('O', 5) == 16, "test_OString error 5a"); + TEST_ENSURE( s2.lastIndexOf('r') == 19, "test_OString error 6"); + TEST_ENSURE( s2[19] == 'r', "test_OString error 7"); + TEST_ENSURE( s2[23] == '\n', "test_OString error 8"); + TEST_ENSURE( s2.lastIndexOf('\n') == 23, "test_OString error 9"); + TEST_ENSURE( s2.lastIndexOf('M') == 0, "test_OString error 10"); + TEST_ENSURE( s2.lastIndexOf('t', s2.getLength() - 8) == 8, "test_OString error 9"); + + + // "Mein erster RTL OString ist ein String aus der RTL Library\n" + // | | | | | | | | | | | | + // Index 0 5 10 15 20 25 30 35 40 45 50 55 + OString s3 = s2.copy(0, s2.getLength() - 1); + OString s4 = s3.concat(" ist ein String aus der RTL Library\n"); + TEST_ENSURE( s4.getLength() == 59, "test_OString error 11"); + + s1 = s4.copy(0, 38); + OString s5; + s5 = s1 + " aus der RTL Library\n"; + TEST_ENSURE( s5.compareTo(s4) == 0 , "test_OString error 12"); + TEST_ENSURE( s5.indexOf("RTL") == 12, "test_OString error 13"); + TEST_ENSURE( s5.lastIndexOf("RTL") == 47, "test_OString error 13"); + + sal_Bool b = sal_False; + OString s6 = s5.valueOf(b); + TEST_ENSURE( s6.compareTo("false") == 0, "test_OString error 14"); + s6 = s5.valueOf('H'); + TEST_ENSURE( s6.compareTo("H") == 0, "test_OString error 15"); + sal_Int32 n = 123456789L; + s6 = s5.valueOf(n); + TEST_ENSURE( s6.compareTo("123456789") == 0, "test_OString error 16"); + +#ifndef SAL_OS2 +#ifdef SAL_UNX + sal_Int64 m = -3223372036854775807LL; +#elif defined(SAL_OS2) + sal_Int64 m; + sal_setInt64(&m, 3965190145L, -750499787L); +#else + sal_Int64 m = -3223372036854775807; +#endif + s6 = s5.valueOf(m); + TEST_ENSURE( s6.compareTo("-3223372036854775807") == 0, "test_OString error 17"); +#endif + + OString s7("HaLLo"); + s7 = s7.toAsciiLowerCase(); + TEST_ENSURE( s7 == "hallo", "test_OString error 19"); + s7 = s7.toAsciiUpperCase(); + TEST_ENSURE( s7 == "HALLO", "test_OString error 20"); + + OString s8("HaLLo ICH BIn eIn StRiNg"); + s7 = s8.toAsciiLowerCase(); + + TEST_ENSURE( s8.equalsIgnoreAsciiCase(s7), "test_OString error 21"); + + s8 = s7.toAsciiUpperCase(); + TEST_ENSURE( s8 == "HALLO ICH BIN EIN STRING", "test_OString error 22"); + + s7 = " "; + s8 = s7 + s8 + " "; + TEST_ENSURE( s8 == " HALLO ICH BIN EIN STRING ", + "test_OString error 23"); + + s7 = s8.trim(); + TEST_ENSURE( s7 == "HALLO ICH BIN EIN STRING", "test_OString error 24"); + TEST_ENSURE( strcmp(s7.getStr(), "HALLO ICH BIN EIN STRING") == 0, + "test_OString error 25"); + + s7 = "Hallo"; + s8 = "aber Hallo"; + + TEST_ENSURE( s7 < s8, "test_OString error 26"); + TEST_ENSURE( s8 > s7, "test_OString error 27"); + TEST_ENSURE( s7 != s8, "test_OString error 28"); + TEST_ENSURE( s7 != "blabla", "test_OString error 29"); + TEST_ENSURE( "blabla" != s7, "test_OString error 30"); + + s8 = "Hallo"; + TEST_ENSURE( s7 <= s8, "test_OString error 31"); + TEST_ENSURE( s7 >= s8, "test_OString error 32"); + + s8 = s8.replace('l', 'r'); + TEST_ENSURE( s8 == "Harro", "test_OString error 33"); + + sal_Int32 nIndex = 0; + s8 = "|hallo1|hallo2|hallo3|hallo4|hallo5|hallo6|hallo7|hallo8|"; + TEST_ENSURE( s8.getToken(3,'|', nIndex) == "hallo3", "test_OString error 40"); + + char* Tokens[10] = { "", "hallo1", "hallo2", "hallo3", "hallo4", + "hallo5", "hallo6", "hallo7", "hallo8", "" }; + + nIndex = 0; + sal_Int32 i = 0; + do + { + TEST_ENSURE( s8.getToken(0,'|',nIndex) == Tokens[i], "test_OString error 40e"); + i++; + } + while ( nIndex >= 0 ); + + s7 = ""; + s7 += s8; + TEST_ENSURE( s7 == s8, "test_OString error 41"); + + s7 = s8.replaceAt(8, 6, "mmmmmmmmmm"); + TEST_ENSURE( s7.getLength() == 61, "test_OString error 42"); + + s8 = s7.replaceAt(8, 11, ""); + TEST_ENSURE( s8.getLength() == 50, "test_OString error 43"); + + s7 = s8.replaceAt(8, 0, "hallo2|"); + TEST_ENSURE( s7.getLength() == 57, "test_OString error 44"); + + sal_Int32 pos = 0; + while ((pos = s7.indexOf("|")) >= 0) + { + s8 = s7.replaceAt(pos, 1, "**"); + s7 = s8; + } + TEST_ENSURE( s7.getLength() == 66, "test_OString error 45"); + + TEST_ENSURE( OString( "aaa" ).compareTo( OString( "bbb" ) ) < 0, "test_OString error 46" ); + TEST_ENSURE( OString( "aaa" ).compareTo( OString( "aaa" ) ) == 0, "test_OString error 47" ); + TEST_ENSURE( OString( "bbb" ).compareTo( OString( "aaa" ) ) > 0, "test_OString error 48" ); + TEST_ENSURE( OString( "aaaa" ).compareTo( OString( "bbb" ) ) < 0, "test_OString error 49" ); + TEST_ENSURE( OString( "aaa" ).compareTo( OString( "bbbb" ) ) < 0, "test_OString error 50" ); + TEST_ENSURE( OString( "aaa" ).compareTo( OString( "aaaa" ) ) < 0, "test_OString error 51" ); + TEST_ENSURE( OString( "aaaa" ).compareTo( OString( "aaa" ) ) > 0, "test_OString error 52" ); + TEST_ENSURE( OString( "bbbb" ).compareTo( OString( "bbb" ) ) > 0, "test_OString error 53" ); + TEST_ENSURE( OString( "bbb" ) == OString( "bbb" ), "test_OString error 54" ); + TEST_ENSURE( OString( "bbb" ) == "bbb", "test_OString error 55" ); + +/* + * As clarified in #104229#, calling copy with invalid arguments causes + * undefined behaviour, so the following test does no longer work: + + s7 = "Hallo jetzt komm ich"; + s8 = s7.copy(0, s7.indexOf(':')); + TEST_ENSURE( s8.getLength() == 0, "test_OString error 56"); + TEST_ENSURE( s8.compareTo("") == 0, "test_OString error 57"); +*/ + + double f = OString("1.7e-10").toDouble(); + TEST_ENSURE(f > 1E-10 && f < 2E-10, "1.7e-10 problem"); + f = OString("1.7e+10").toDouble(); + TEST_ENSURE(f > 1E10 && f < 2E10, "1.7e+10 problem"); + f = OString("1.7e10").toDouble(); + TEST_ENSURE(f > 1E10 && f < 2E10, "1.7e308 problem"); + + { + float f0 = 0; + float f1 = 1; + float fInf = f1 / f0; + OString aStr1(OString::valueOf(fInf)); + OString aStr2("1.#INF"); + bool bSuccess = aStr1 == aStr2; + if (!bSuccess) + printf("ERROR: OString::valueOf(1f/0f): %s\n", aStr1.getStr()); + TEST_ENSURE(bSuccess, "OString::valueOf(1f/0f)"); + } + + printf("test_OString OK !!!\n"); + return; +} + +} // namespace rtl_OString + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OString::oldtests, "rtl_OString" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; + diff --git a/sal/qa/rtl_strings/rtl_old_testowstring.cxx b/sal/qa/rtl_strings/rtl_old_testowstring.cxx new file mode 100644 index 000000000000..938ec01f5fff --- /dev/null +++ b/sal/qa/rtl_strings/rtl_old_testowstring.cxx @@ -0,0 +1,424 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_old_testowstring.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + + +// ----------------------------------------------------------------------------- +#include <string.h> +#include <stdio.h> + +#ifdef UNX +#include <wchar.h> +#endif +#ifdef OS2__00 +#include <wcstr.h> +#endif + +// #ifndef _OSL_DIAGNOSE_H_ +// #include <osl/diagnose.h> +// #endif + +#ifndef _RTL_USTRING_HXX +#include <rtl/ustring.hxx> +#endif + +#ifndef _RTL_STRING_HXX +#include <rtl/string.hxx> +#endif + +#include <rtl/locale.hxx> + +#include <testshl/simpleheader.hxx> + +#define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c)) +// #if OSL_DEBUG_LEVEL > 0 +// #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m) +// #else +// #define TEST_ENSHURE(c, m) OSL_VERIFY(c) +// #endif + +using namespace rtl; + +// ----------------------------------------------------------------------------- +namespace rtl_OUString +{ + class oldtests : public CppUnit::TestFixture + { + public: + void test_OUString(); + void test_OString2OUStringAndViceVersa(); + + CPPUNIT_TEST_SUITE( oldtests ); + CPPUNIT_TEST( test_OUString ); + CPPUNIT_TEST( test_OString2OUStringAndViceVersa ); + CPPUNIT_TEST_SUITE_END( ); + }; + + +void oldtests::test_OUString() +{ + // "Mein erster RTL OUString\n" + // | | | | | + // Index 0 5 10 15 20 + OUString s1(OUString::createFromAscii("Mein erster RTL OUString\n")); + TEST_ENSURE( s1 == OUString::createFromAscii("Mein erster RTL OUString\n"), "test_OWString error 1"); + TEST_ENSURE( s1.getLength() == 25, "test_OWString error 2"); + + OUString s2 = s1; + TEST_ENSURE( s2[16] == (sal_Unicode)'O', "test_OWString error 3"); + TEST_ENSURE( s2.equals(s1), "test_OWString error 4"); + TEST_ENSURE( OUString( OUString::createFromAscii("hallo")) == OUString::createFromAscii( "hallo"), "test_OWString error 4"); + TEST_ENSURE( s2.indexOf((sal_Unicode)'O') == 16, "test_OWString error 5"); + TEST_ENSURE( s2.indexOf((sal_Unicode)'O', 5) == 16, "test_OWString error 5a"); + TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'r') == 20, "test_OWString error 6"); + TEST_ENSURE( s2[20] == (sal_Unicode)'r', "test_OWString error 7"); + TEST_ENSURE( s2[24] == (sal_Unicode)'\n', "test_OWString error 8"); + TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'\n') == 24, "test_OWString error 9"); + TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'M') == 0, "test_OWString error 10"); + TEST_ENSURE( s2.lastIndexOf((sal_Unicode)'t', s2.getLength() - 8) == 8, "test_OWString error 9"); + + + // "Mein erster RTL OUString ist ein String aus der RTL Library\n" + // | | | | | | | | | | | | + // Index 0 5 10 15 20 25 30 35 40 45 50 55 + OUString s3 = s2.copy(0, s2.getLength() - 1); + OUString s4 = s3.concat( OUString::createFromAscii(" ist ein String aus der RTL Library\n") ); + TEST_ENSURE( s4.getLength() == 60, "test_OWString error 11"); + + s1 = s4.copy(0, 39); + OUString s5; + s5 = s1 + OUString::createFromAscii( " aus der RTL Library\n" ); + TEST_ENSURE( s5.compareTo(s4) == 0 , "test_OWString error 12"); + TEST_ENSURE( s5.indexOf(OUString::createFromAscii("RTL")) == 12, "test_OWString error 13"); + TEST_ENSURE( s5.lastIndexOf(OUString::createFromAscii("RTL")) == 48, "test_OWString error 13"); + + sal_Bool b = sal_False; + OUString s6 = s5.valueOf(b); +// TEST_ENSURE( s6.compareTo(OUString::createFromAscii("False")) == 0, "test_OWString error 14"); + s6 = s5.valueOf((sal_Unicode)'H'); + TEST_ENSURE( s6.compareTo(OUString::createFromAscii("H")) == 0, "test_OWString error 15"); + sal_Int32 n = 123456789L; + s6 = s5.valueOf(n); + TEST_ENSURE( s6.compareTo(OUString::createFromAscii("123456789")) == 0, "test_OWString error 16"); + +#ifndef SAL_OS2 +#ifdef SAL_UNX + sal_Int64 m = -3223372036854775807LL; +#elif defined(SAL_OS2) + sal_Int64 m; + sal_setInt64(&m, 3965190145L, -750499787L); +#else + sal_Int64 m = -3223372036854775807; +#endif + s6 = s5.valueOf(m); + TEST_ENSURE( s6.compareTo( OUString::createFromAscii( "-3223372036854775807" ) ) == 0, "test_OWString error 17"); +#endif + +// LLA: locale tests removed ::rtl::OLocale locale = ::rtl::OLocale::getDefault(); +// LLA: locale tests removed +// LLA: locale tests removed OUString s61(OUString::createFromAscii("HaLLo")); +// LLA: locale tests removed s61 = s61.toLowerCase(locale); +// LLA: locale tests removed TEST_ENSURE( s61 == OUString::createFromAscii("hallo"), "test_OWString error 17a"); +// LLA: locale tests removed s61 = s61.toUpperCase(); +// LLA: locale tests removed TEST_ENSURE( s61 == OUString::createFromAscii("HALLO"), "test_OWString error 17b"); +// LLA: locale tests removed s61 = s61.toLowerCase(); +// LLA: locale tests removed TEST_ENSURE( s61 == OUString::createFromAscii("hallo"), "test_OWString error 17c"); +// LLA: locale tests removed +// LLA: locale tests removed ::rtl::OLocale::setDefault( OUString::createFromAscii( "de" ), OUString::createFromAscii( "DE" ), OUString() ); +// LLA: locale tests removed locale = OLocale::getDefault(); +// LLA: locale tests removed +// LLA: locale tests removed // AB, 24.3.2000, removed NAMESPACE_RTL(OLocale)::getENGLISH() and error 18 +// LLA: locale tests removed +// LLA: locale tests removed OUString s7(OUString::createFromAscii("HaLLo")); +// LLA: locale tests removed s7 = s7.toLowerCase(locale); +// LLA: locale tests removed TEST_ENSURE( s7 == OUString::createFromAscii("hallo"), "test_OWString error 19"); +// LLA: locale tests removed s7 = s7.toUpperCase(locale); +// LLA: locale tests removed TEST_ENSURE( s7 == OUString::createFromAscii("HALLO"), "test_OWString error 20"); +// LLA: locale tests removed +// LLA: locale tests removed OUString s8(OUString::createFromAscii("HaLLo ICH BIn eIn ")); +// LLA: locale tests removed s8 += OUString::valueOf( (sal_Unicode)0xDF ); +// LLA: locale tests removed locale = OLocale::registerLocale( OUString::createFromAscii("tr"), OUString::createFromAscii("TR"), OUString()); +// LLA: locale tests removed s8 = s8.toLowerCase(locale); +// LLA: locale tests removed s8 = s8.toUpperCase(locale); +// LLA: locale tests removed TEST_ENSURE( s8 == OUString::createFromAscii("HALLO ICH BIN EIN SS"), "test_OWString error 21"); +// LLA: locale tests removed +// LLA: locale tests removed s7 = OUString::createFromAscii("Hallo ich bIn ein I"); +// LLA: locale tests removed s7 = s8.toUpperCase(locale); +// LLA: locale tests removed TEST_ENSURE( s7 != OUString::createFromAscii("HALLO ICH BIN EIN I"), "test_OWString error 21.b"); + + OUString s7; + OUString s8(OUString::createFromAscii("HALLO ICH BIN EIN SS")); + s7 = OUString::createFromAscii(" "); + s8 = s7 + s8 + OUString::createFromAscii(" " ); + TEST_ENSURE( s8 == OUString::createFromAscii(" HALLO ICH BIN EIN SS "), + "test_OWString error 22"); + + s7 = s8.trim(); + TEST_ENSURE( s7 == OUString::createFromAscii("HALLO ICH BIN EIN SS"), "test_OWString error 23"); +// TEST_ENSURE( wcscmp(s7.getStr(), L"HALLO ICH BIN EIN SS") == 0, "test_OWString error 24"); + + s7 = OUString::createFromAscii("Hallo"); + s8 = OUString::createFromAscii("aber Hallo"); + + TEST_ENSURE( s7 < s8, "test_OWString error 25"); + TEST_ENSURE( s8 > s7, "test_OWString error 26"); + TEST_ENSURE( s7 != s8, "test_OWString error 27"); + TEST_ENSURE( s7 != OUString::createFromAscii("blabla"), "test_OWString error 28"); + TEST_ENSURE( OUString::createFromAscii("blabla") != s7, "test_OWString error 29"); + + s8 = OUString::createFromAscii("Hallo"); + TEST_ENSURE( s7 <= s8, "test_OWString error 30"); + TEST_ENSURE( s7 >= s8, "test_OwString error 31"); + + s8 = s8.replace((sal_Unicode)'l', (sal_Unicode)'r'); + TEST_ENSURE( s8 == OUString::createFromAscii("Harro"), "test_OWString error 32"); +// LLA: len() unknown TEST_ENSURE( s8.len() == 5, "test_OWString error 33"); + + // "Ich bin ein String mit einem A und C und vielen m, m, m, m" + // | | | | | | | | | | | | + //index 0 5 10 15 20 25 30 35 40 45 50 55 + s8 = OUString::createFromAscii("Ich bin ein String mit einem A und C und vielen m, m, m, m"); +// LLA: no matching TEST_ENSURE( s8.search((sal_Unicode)'I') == 0, "test_OWString error 34"); +// LLA: no matching TEST_ENSURE( s8.search((sal_Unicode)'A') == 29, "test_OWString error 35"); +// LLA: no matching s7 = OUString::createFromAscii("A und C"); +// LLA: no matching TEST_ENSURE( s8.search(s7) == 29, "test_OWString error 36"); +// LLA: no matching TEST_ENSURE( s8.search(OUString::createFromAscii("mit einem A")) == 19, "test_OWString error 37"); +// LLA: no matching +// LLA: no matching s8 = OUString::createFromAscii("||token1|token2|token3||token4|token5||" ); +// LLA: no matching TEST_ENSURE( s8.getTokenCount('|') == 10, "test_OWString error 38a"); +// LLA: no matching TEST_ENSURE( s8.getToken(10,'|') == OUString(), "test_OWString error 39a"); +// LLA: no matching +// LLA: no matching s8 = OUString::createFromAscii("token1"); +// LLA: no matching TEST_ENSURE( s8.getTokenCount('|') == 1, "test_OWString error 38b"); +// LLA: no matching TEST_ENSURE( s8.getToken(0,'|') == OUString::createFromAscii("token1"), "test_OWString error 39b"); +// LLA: no matching TEST_ENSURE( s8.getToken(-1,'|') == OUString(), "test_OWString error 39c"); +// LLA: no matching TEST_ENSURE( s8.getToken(1,'|') == OUString(), "test_OWString error 39d"); +// LLA: no matching +// LLA: no matching s8 = OUString::createFromAscii("|hallo1|hallo2|hallo3|hallo4|hallo5|hallo6|hallo7|hallo8|"); +// LLA: no matching TEST_ENSURE( s8.getTokenCount((sal_Unicode)'|') == 10, "test_OWString error 38"); +// LLA: no matching TEST_ENSURE( s8.getToken(3, (sal_Unicode)'|') == OUString::createFromAscii("hallo3"), "test_OWString error 39"); + +// LLA: removed due to the fact, this is not a clean test! + +// LLA: s7 = OUString(); +// LLA: s7 += s8; +// LLA: TEST_ENSURE( s7 == s8, "test_OWString error 40"); +// LLA: +// LLA: s7 = s8.replaceAt(8, 6, OUString::createFromAscii("mmmmmmmmmm")); +// LLA: TEST_ENSURE( s7.getLength() == 61, "test_OWString error 41"); +// LLA: +// LLA: s8 = s7.replaceAt(8, 11, OUString()); +// LLA: TEST_ENSURE( s8.getLength() == 50, "test_OWString error 42"); +// LLA: +// LLA: s7 = s8.replaceAt(8, 0, OUString::createFromAscii("hallo2|")); +// LLA: TEST_ENSURE( s7.getLength() == 57, "test_OWString error 43"); +// LLA: +// LLA: sal_Int32 pos = 0; +// LLA: while ((pos = s7.indexOf(OUString::createFromAscii("|"))) >= 0) +// LLA: { +// LLA: s8 = s7.replaceAt(pos, 1, OUString::createFromAscii("**")); +// LLA: s7 = s8; +// LLA: } +// LLA: TEST_ENSURE( s7.getLength() == 66, "test_OWString error 44"); + + TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("bbb" ) ) < 0, "test_OWString error 46" ); + TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("aaa" ) ) == 0, "test_OWString error 46" ); + TEST_ENSURE( OUString::createFromAscii("bbb" ).compareTo( OUString::createFromAscii("aaa" ) ) > 0, "test_OWString error 47" ); + TEST_ENSURE( OUString::createFromAscii("aaaa" ).compareTo( OUString::createFromAscii("bbb" ) ) < 0, "test_OWString error 48" ); + TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("bbbb" ) ) < 0, "test_OWString error 49" ); + TEST_ENSURE( OUString::createFromAscii("aaa" ).compareTo( OUString::createFromAscii("aaaa" ) ) < 0, "test_OWString error 50" ); + TEST_ENSURE( OUString::createFromAscii("aaaa" ).compareTo( OUString::createFromAscii("aaa" ) ) > 0, "test_OWString error 51" ); + TEST_ENSURE( OUString::createFromAscii("bbbb" ).compareTo( OUString::createFromAscii("bbb" ) ) > 0, "test_OWString error 52" ); + TEST_ENSURE( OUString::createFromAscii("bbb" ) == OUString::createFromAscii("bbb" ), "test_OWString error 53" ); + TEST_ENSURE( OUString::createFromAscii("bbb" ) == OUString::createFromAscii("bbb" ), "test_OWString error 54" ); + + { + OUString uStr = OUString::createFromAscii( "Hallo" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Hallo"), 5 ) == 0, "test_OWString error 54.2.1" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Halloa"), 6 ) < 0 , "test_OWString error 54.2.2" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("1Hallo"), 6 ) > 0, "test_OWString error 54.2.3" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Aallo"), 5 ) > 0, "test_OWString error 54.2.4" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Halla"), 5 ) > 0, "test_OWString error 54.2.5" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Mallo"), 5 ) < 0, "test_OWString error 54.2.6" ); + TEST_ENSURE( uStr.compareTo( OUString::createFromAscii("Hallp"), 5 ) < 0, "test_OWString error 54.2.7" ); + } + +#if OSL_DEBUG_LEVEL == 0 +//YD will fail copy assert on indexes, because ':' returns -1 + s7 = OUString::createFromAscii("Hallo jetzt komm ich"); + s8 = s7.copy(0, s7.indexOf((sal_Unicode)':')); + TEST_ENSURE( s8.getLength() == 0, "test_OWString error 55"); + TEST_ENSURE( s8.compareTo(OUString()) == 0, "test_OWString error 56"); +#endif + + // ASCII-Schnittstellen, AB 15.10.1999 + + // "Ich bin ein reiner ASCII-String mit ein paar Zahlen 0123456789 und Zeichen" + // | | | | | | | | | | | | | | | + //index 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 + // + // "Ich bin ein weiterer ASCII-String" + // | | | | | | | + //index 0 5 10 15 20 25 30 + sal_Char ascii_str1[] = "Ich bin ein reiner ASCII-String mit ein paar Zahlen 0123456789 und Zeichen"; + sal_Char ascii_str2[] = "Ich bin ein weiterer ASCII-String"; + OUString OWAsciiStr1 = OUString::createFromAscii( ascii_str1 ); + sal_Int32 nLen1 = OWAsciiStr1.getLength(); + TEST_ENSURE( nLen1 == 74, "test_OWString error 57" ); + OUString OWAsciiStr2 = OUString::createFromAscii( ascii_str2 ); + sal_Int32 nLen2 = OWAsciiStr2.getLength(); + TEST_ENSURE( nLen2 == 33, "test_OWString error 58" ); + + sal_Int32 nCompareResult11 = OWAsciiStr1.compareToAscii( ascii_str1 ); + TEST_ENSURE( nCompareResult11 == 0, "test_OWString error 59" ); + sal_Int32 nCompareResult12 = OWAsciiStr1.compareToAscii( ascii_str2 ); + TEST_ENSURE( nCompareResult12 < 0, "test_OWString error 60" ); + + sal_Int32 nCompareResult21 = OWAsciiStr2.compareToAscii( ascii_str1 ); + TEST_ENSURE( nCompareResult21 > 0, "test_OWString error 61" ); + sal_Int32 nCompareResult22 = OWAsciiStr2.compareToAscii( ascii_str2 ); + TEST_ENSURE( nCompareResult22 == 0, "test_OWString error 62" ); + + sal_Int32 nCompareResult12_Len12 = OWAsciiStr1.compareToAscii( ascii_str2, 12 ); + TEST_ENSURE( nCompareResult12_Len12 == 0, "test_OWString error 63" ); + sal_Int32 nCompareResult12_Len13 = OWAsciiStr1.compareToAscii( ascii_str2, 13 ); + TEST_ENSURE( nCompareResult12_Len13 < 0, "test_OWString error 64" ); + + sal_Int32 nCompareResult21_Len12 = OWAsciiStr2.compareToAscii( ascii_str1, 12 ); + TEST_ENSURE( nCompareResult21_Len12 == 0, "test_OWString error 65" ); + sal_Int32 nCompareResult21_Len13 = OWAsciiStr2.compareToAscii( ascii_str1, 13 ); + TEST_ENSURE( nCompareResult21_Len13 > 0, "test_OWString error 66" ); + + { + OUString uStr = OUString::createFromAscii( "Hallo" ); + TEST_ENSURE( uStr.equalsAsciiL( "Hallo", 5 ), "test_OWString error 66.1.1" ); + TEST_ENSURE( !uStr.equalsAsciiL( "Hallo1", 6 ), "test_OWString error 66.1.2" ); + TEST_ENSURE( !uStr.equalsAsciiL( "1Hallo", 6 ), "test_OWString error 66.1.3" ); + TEST_ENSURE( !uStr.equalsAsciiL( "aallo", 5 ), "test_OWString error 66.1.2" ); + TEST_ENSURE( !uStr.equalsAsciiL( "Halla", 5 ), "test_OWString error 66.1.3" ); + + TEST_ENSURE( uStr.reverseCompareToAsciiL( "Hallo", 5 ) == 0, "test_OWString error 66.2.1" ); + TEST_ENSURE( uStr.reverseCompareToAsciiL( "Halloa", 6 ) > 0 , "test_OWString error 66.2.2" ); + TEST_ENSURE( uStr.reverseCompareToAsciiL( "1Hallo", 6 ) < 0, "test_OWString error 66.2.3" ); + TEST_ENSURE( uStr.reverseCompareToAsciiL( "Aallo", 5 ) > 0, "test_OWString error 66.2.4" ); + TEST_ENSURE( uStr.reverseCompareToAsciiL( "Halla", 5 ) > 0, "test_OWString error 66.2.5" ); + TEST_ENSURE( uStr.reverseCompareToAsciiL( "Mallo", 5 ) < 0, "test_OWString error 66.2.6" ); + TEST_ENSURE( uStr.reverseCompareToAsciiL( "Hallp", 5 ) < 0, "test_OWString error 66.2.7" ); + } + + // toInt64 + OUString s9( OUString::createFromAscii(" -3223372036854775807") ); + sal_Int64 ln1 = s9.toInt64(); +#if (defined UNX) || (defined OS2) + TEST_ENSURE( ln1 == -3223372036854775807LL, "test_OWString error 67" ); +#else + TEST_ENSURE( ln1 == -3223372036854775807, "test_OWString error 67" ); +#endif + OUString s10( OUString::createFromAscii("13243A65f1H45") ); + sal_Int64 ln2 = s10.toInt64(); + TEST_ENSURE( ln2 == 13243, "test_OWString error 68" ); + + sal_Int64 ln3 = s10.toInt64( 16 ); +#if (defined UNX) || (defined OS2) + TEST_ENSURE( ln3 == 0x13243A65F1LL, "test_OWString error 69" ); +#else + TEST_ENSURE( ln3 == 0x13243A65F1, "test_OWString error 69" ); +#endif + // Exotic base + OUString s11( OUString::createFromAscii("H4A") ); + sal_Int64 ln4 = s11.toInt64( 23 ); + TEST_ENSURE( ln4 == 23*23*17 + 4 * 23 + 10, "test_OWString error 70" ); + + // toInt32 + OUString s12( OUString::createFromAscii(" -220368507") ); + sal_Int32 n1 = s12.toInt32(); + TEST_ENSURE( n1 == -220368507, "test_OWString error 71" ); + + OUString s13( OUString::createFromAscii("4423A61H45") ); + sal_Int64 n2 = s13.toInt32(); + TEST_ENSURE( n2 == 4423, "test_OWString error 72" ); + + sal_Int64 n3 = s13.toInt64( 16 ); + TEST_ENSURE( n3 == 0x4423A61, "test_OWString error 73" ); + +// LLA: Value tests fails most the time, this is not a good test +// LLA: double d = 1.23456781; +// LLA: OUString sDouble = OUString::valueOf( d ); +// LLA: char str[] = "1.2345678099999999"; +// LLA: sal_Int32 nLength = sDouble.getLength(); +// LLA: TEST_ENSURE( nLength == strlen( str ), "test_OWString error 74" ); +// LLA: sal_Int32 nCompare = sDouble.compareToAscii( str ); +// LLA: TEST_ENSURE( nCompare == 0, "test_OWString error 75" ); + + printf("test_OWString OK !!!\n"); + return; +} + +// ----------------------------------------------------------------------------- + +void oldtests::test_OString2OUStringAndViceVersa() +{ + OString s1("Hallo jetzt komm ich"); + OUString u1 = OStringToOUString(s1, RTL_TEXTENCODING_MS_1252); + TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 1" ); + u1 = OStringToOUString(s1, RTL_TEXTENCODING_IBM_850); + TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 2" ); + u1 = OStringToOUString(s1, RTL_TEXTENCODING_ISO_8859_15); + TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 3" ); + u1 = OStringToOUString(s1, RTL_TEXTENCODING_ASCII_US); + TEST_ENSURE( u1.equals(OUString::createFromAscii("Hallo jetzt komm ich")), "test_OString2OWStringAndViceVersa error 4" ); + + OString s2 = OUStringToOString(u1, RTL_TEXTENCODING_MS_1252); + TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 5" ); + s2 = OUStringToOString(u1, RTL_TEXTENCODING_IBM_850); + TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 6" ); + s2 = OUStringToOString(u1, RTL_TEXTENCODING_ISO_8859_15); + TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 7" ); + s2 = OUStringToOString(u1, RTL_TEXTENCODING_ASCII_US); + TEST_ENSURE( s2.equals("Hallo jetzt komm ich"), "test_OString2OWStringAndViceVersa error 8" ); + + printf("test_OString2OWStringAndViceVersa OK !!!\n"); +} + +} // namespace rtl_OUString + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUString::oldtests, "rtl_OUString" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; + + diff --git a/sal/qa/rtl_strings/rtl_old_teststrbuf.cxx b/sal/qa/rtl_strings/rtl_old_teststrbuf.cxx new file mode 100644 index 000000000000..c277517d57b2 --- /dev/null +++ b/sal/qa/rtl_strings/rtl_old_teststrbuf.cxx @@ -0,0 +1,272 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rtl_old_teststrbuf.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" + +// LLA: +// this file is converted to use with testshl2 +// original was placed in sal/test/textenc.cxx + + +// ----------------------------------------------------------------------------- + +#include <string.h> +#include <stdio.h> + +// #ifndef _OSL_DIAGNOSE_H_ +// #include <osl/diagnose.h> +// #endif + +#ifndef _RTL_STRBUF_HXX +#include <rtl/strbuf.hxx> +#endif + +#ifndef _RTL_WSTRBUF_HXX +#include <rtl/ustrbuf.hxx> +#endif + +#include <testshl/simpleheader.hxx> + +using namespace rtl; + +#define TEST_ENSURE(c, m) CPPUNIT_ASSERT_MESSAGE((m), (c)) + +// #if OSL_DEBUG_LEVEL > 0 +// #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m) +// #else +// #define TEST_ENSHURE(c, m) OSL_VERIFY(c) +// #endif + +// ----------------------------------------------------------------------------- +namespace rtl_OStringBuffer +{ + class oldtests : public CppUnit::TestFixture + { + public: + void test_OStringBuffer(); + + CPPUNIT_TEST_SUITE( oldtests ); + CPPUNIT_TEST( test_OStringBuffer ); + CPPUNIT_TEST_SUITE_END( ); + }; + + +void oldtests::test_OStringBuffer() +{ + // "Mein erster RTL OString\n" + // | | | | | + // Index 0 5 10 15 20 + OString s1("Mein erster RTL OString\n"); + + OStringBuffer b1(s1); + + TEST_ENSURE( b1.getCapacity() == 16 + s1.getLength(), "test_OStringBuffer error 1"); + + b1.insert(b1.getLength() - 1, "Buffer"); + s1 = "Mein erster RTL OStringBuffer\n"; + TEST_ENSURE( s1 == b1.getStr(), "test_OStringBuffer error 2"); + + b1.insert(b1.getLength() - 1, " ist viel zu gross fuer den alten Buffer"); + TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OStringBuffer error 3"); + + OStringBuffer b2(30); + + s1 = "false"; + sal_Bool b = sal_False; + b2.append(b); + TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 4"); + + sal_Int32 n = 123456789L; + s1 += " 123456789"; + b2.append(" "); + b2.append(n); + TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 5"); + +#ifndef SAL_OS2 +#ifdef SAL_UNX + sal_Int64 m = -3223372036854775807LL; +#elif defined(SAL_OS2) + sal_Int64 m; + sal_setInt64(&m, 3965190145L, -750499787L); +#else + sal_Int64 m = -3223372036854775807; +#endif + s1 += " -3223372036854775807"; + b2.append(" "); + b2.append(m); + TEST_ENSURE( s1 == b2.getStr(), "test_OStringBuffer error 6"); +#endif + + OString s2(b2.makeStringAndClear()); + TEST_ENSURE( s1 == s2, "test_OStringBuffer error 7"); + + b2.ensureCapacity(50); + TEST_ENSURE( b2.getCapacity() == 50, "test_OStringBuffer error 8"); + + b2.append("Hier fuege ich jetzt ein > <\n"); + b2.insert(26, " Hallo"); + s2 = "Hier fuege ich jetzt ein > Hallo <\n"; + TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 9"); + + b2.insert(26, b); + b2.insert(26, " "); + s2 = "Hier fuege ich jetzt ein > false Hallo <\n"; + TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 10"); + + b2.insert(26, n); + b2.insert(26, " "); + s2 = "Hier fuege ich jetzt ein > 123456789 false Hallo <\n"; + TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 11"); + +#ifndef SAL_OS2 + b2.insert(26, m); + b2.insert(26, " "); + s2 = "Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n"; + TEST_ENSURE( s2 == b2.getStr(), "test_OStringBuffer error 12"); +#endif + + printf("test_OStringBuffer OK !!!\n"); + return; +} +} // namespace rtl_OStringBuffer + +// ----------------------------------------------------------------------------- + +namespace rtl_OUStringBuffer +{ + class oldtests : public CppUnit::TestFixture + { + public: + void test_OUStringBuffer(); + + CPPUNIT_TEST_SUITE( oldtests ); + CPPUNIT_TEST( test_OUStringBuffer ); + CPPUNIT_TEST_SUITE_END( ); + }; + + +void oldtests::test_OUStringBuffer() +{ + // "Mein erster RTL OUString\n" + // | | | | | + // Index 0 5 10 15 20 + OUString s1(OUString::createFromAscii("Mein erster RTL OUString\n")); + + OUStringBuffer b1(s1); + + TEST_ENSURE( b1.getCapacity() == 16 + s1.getLength(), "test_OWStringBuffer error 1"); + + b1.insert(b1.getLength() - 1, OUString::createFromAscii("Buffer")); + s1 = OUString::createFromAscii("Mein erster RTL OUStringBuffer\n"); + TEST_ENSURE( s1 == b1.getStr(), "test_OWStringBuffer error 2"); + + b1.insert(b1.getLength() - 1, OUString::createFromAscii(" ist viel zu gross fuer den alten Buffer")); + //TEST_ENSURE( b1.getCapacity() == b1.getLength(), "test_OWStringBuffer error 3"); + + OUStringBuffer b2(30); + + s1 = OUString::createFromAscii("false"); + sal_Bool b = sal_False; + b2.append(b); + TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 4"); + + sal_Int32 n = 123456789L; + s1 += OUString::createFromAscii(" 123456789"); + b2.append(OUString::createFromAscii(" ")); + b2.append(n); + TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 5"); + +#ifndef SAL_OS2 +#ifdef SAL_UNX + sal_Int64 m = -3223372036854775807LL; +#elif defined(SAL_OS2) + sal_Int64 m; + sal_setInt64(&m, 3965190145L, -750499787L); +#else + sal_Int64 m = -3223372036854775807; +#endif + s1 += OUString::createFromAscii(" -3223372036854775807"); + b2.append(OUString::createFromAscii(" ")); + b2.append(m); + TEST_ENSURE( s1 == b2.getStr(), "test_OWStringBuffer error 6"); +#endif + + OUString s2(b2.makeStringAndClear()); + TEST_ENSURE( s1 == s2, "test_OWStringBuffer error 7"); + + b2.ensureCapacity(50); + TEST_ENSURE( b2.getCapacity() == 50, "test_OWStringBuffer error 8"); + + b2.append(OUString::createFromAscii("Hier fuege ich jetzt ein > <\n")); + b2.insert(26, OUString::createFromAscii(" Hallo")); + s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > Hallo <\n"); + TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 9"); + + b2.insert(26, b); + b2.insert(26, OUString::createFromAscii(" ")); + s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > false Hallo <\n"); + TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 10"); + + b2.insert(26, n); + b2.insert(26, OUString::createFromAscii(" ")); + s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > 123456789 false Hallo <\n"); + TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 11"); + +#ifndef SAL_OS2 + b2.insert(26, m); + b2.insert(26, OUString::createFromAscii(" ")); + s2 = OUString::createFromAscii("Hier fuege ich jetzt ein > -3223372036854775807 123456789 false Hallo <\n"); + TEST_ENSURE( s2 == b2.getStr(), "test_OWStringBuffer error 12"); +#endif + + // ASCII-Schnittstelle, AB 15.10.1999 + OUString s3(OUString::createFromAscii("Noch'n RTL OUString")); + OUStringBuffer b3(s3); + sal_Char aAsciiStr[] = " mit appendetem ASCII\n"; + b3.appendAscii( aAsciiStr ); + s3 = OUString::createFromAscii("Noch'n RTL OUString mit appendetem ASCII\n"); + TEST_ENSURE( b3.getStr() == s3 , "test_OWStringBuffer error 13"); + + + + printf("test_OWStringBuffer OK !!!\n"); + return; +} + +} // namespace rtl_OUStringBuffer + + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OUStringBuffer::oldtests, "rtl_OUStringBuffer" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_OStringBuffer::oldtests, "rtl_OStringBuffer" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; diff --git a/sal/qa/sal/makefile.mk b/sal/qa/sal/makefile.mk new file mode 100644 index 000000000000..61f279e226eb --- /dev/null +++ b/sal/qa/sal/makefile.mk @@ -0,0 +1,54 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := sal +TARGET := qa_sal + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk + +SHL1TARGET = $(TARGET)_types +SHL1OBJS = $(SLO)$/test_types.obj +SHL1STDLIBS = $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +SHL1VERSIONMAP = version.map +SHL1IMPLIB = i$(SHL1TARGET) +DEF1NAME = $(SHL1TARGET) + +SLOFILES = $(SHL1OBJS) + +.INCLUDE: target.mk + +ALLTAR: test + +test .PHONY: $(SHL1TARGETN) + testshl2 $(SHL1TARGETN) diff --git a/sal/qa/sal/test_types.cxx b/sal/qa/sal/test_types.cxx new file mode 100644 index 000000000000..5d72175bb8db --- /dev/null +++ b/sal/qa/sal/test_types.cxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_types.cxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_sal.hxx" +#include "sal/config.h" + +#include <cstddef> +#include <stdio.h> // C99 snprintf not necessarily in <cstdio> +#include <string.h> // wntmsci10 does not know <cstring> std::strcmp + +#include "testshl/simpleheader.hxx" +#include "sal/types.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(strcmp(buf, result) == 0); +} + +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_NAMED_REGISTRATION(Test, "alltests"); + +} + +NOADDITIONAL; diff --git a/sal/qa/sal/version.map b/sal/qa/sal/version.map new file mode 100644 index 000000000000..4833b67470ca --- /dev/null +++ b/sal/qa/sal/version.map @@ -0,0 +1,38 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: version.map,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3_0_0 { + global: + registerAllTestFunction; + + local: + *; +}; diff --git a/sal/qa/systools/makefile.mk b/sal/qa/systools/makefile.mk new file mode 100644 index 000000000000..035bef25c34a --- /dev/null +++ b/sal/qa/systools/makefile.mk @@ -0,0 +1,74 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +INCPRE+= $(PRJ)$/qa$/inc + +PRJNAME=sal +TARGET=test_comtools + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +CFLAGS+=/Ob0 + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:joblist by codegen.pl +SHL1OBJS= \ + $(SLO)$/test_comtools.obj + +SHL1TARGET= test_comtools +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) uuid.lib + +SHL1IMPLIB= i$(SHL1TARGET) +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP= $(PRJ)$/qa$/export.map +# auto generated Target:joblist +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + diff --git a/sal/qa/systools/test_comtools.cxx b/sal/qa/systools/test_comtools.cxx new file mode 100644 index 000000000000..c61ff435d235 --- /dev/null +++ b/sal/qa/systools/test_comtools.cxx @@ -0,0 +1,253 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_comtools.cxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// autogenerated file with codegen.pl + +#include <testshl/simpleheader.hxx> +#include <systools/win32/comtools.hxx> + +class COMObject : public IUnknown +{ +public: + COMObject() : ref_count_(0) + { + } + + ~COMObject() + { + } + + ULONG __stdcall AddRef() + { + ref_count_++; + return ref_count_; + } + + ULONG __stdcall Release() + { + ULONG cnt = --ref_count_; + if (cnt == 0) + delete this; + return cnt; + } + + HRESULT __stdcall QueryInterface(REFIID riid, LPVOID* ppv) + { + if (riid == IID_IUnknown) + { + AddRef(); + *ppv = this; + return S_OK; + } + return E_NOINTERFACE; + } + + ULONG GetRefCount() const + { + return ref_count_; + } + +private: + ULONG ref_count_; +}; + +sal::systools::COMReference<IUnknown> comObjectSource() +{ + return sal::systools::COMReference<IUnknown>(new COMObject); +} + +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); +} + +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_MESSAGE("COMReference should be empty", r.get() == NULL); + } + + void test_ctor_manual_AddRef() + { + COMObject* p = new COMObject; + p->AddRef(); + sal::systools::COMReference<IUnknown> r(p, false); + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + } + + void test_copy_ctor() + { + sal::systools::COMReference<IUnknown> r(comObjectSource()); + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + } + + void test_copy_assignment() + { + sal::systools::COMReference<IUnknown> r; + CPPUNIT_ASSERT_MESSAGE("COMReference should be empty", r.get() == NULL); + + r = comObjectSource(); + CPPUNIT_ASSERT_MESSAGE("COMReference should be empty", r.get() != NULL); + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + } + + void test_ref_to_ref_assignment() + { + sal::systools::COMReference<IUnknown> r1 = comObjectSource(); + sal::systools::COMReference<IUnknown> r2 = r1; + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 2 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2); + } + + void test_pointer_to_ref_assignment() + { + sal::systools::COMReference<IUnknown> r; + r = new COMObject; + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + } + + void test_pointer_to_ref_assignment2() + { + sal::systools::COMReference<IUnknown> r = comObjectSource(); + r = new COMObject; + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + } + + 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_MESSAGE("Wrong reference count, 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + } + + void test_address_operator2() + { + sal::systools::COMReference<IUnknown> r1 = comObjectSource(); + sal::systools::COMReference<IUnknown> r2 = r1; + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 2 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2); + comObjectSource2(reinterpret_cast<LPVOID*>(&r1)); + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r1.get())->GetRefCount() == 1); + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 1); + } + + void test_clear() + { + sal::systools::COMReference<IUnknown> r = comObjectSource(); + CPPUNIT_ASSERT_MESSAGE("Wrong reference count 1 is expected", reinterpret_cast<COMObject*>(r.get())->GetRefCount() == 1); + 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_MESSAGE("Wrong reference count, 2 is expected", reinterpret_cast<COMObject*>(r2.get())->GetRefCount() == 2); + } + catch(sal::systools::ComError& ex) + { + 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(sal::systools::ComError& ex) + { + 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_NAMED_REGISTRATION(test_comtools::test_COMReference, "test_comtools"); + +} // namespace rtl_OUString + + +// 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. +NOADDITIONAL; + diff --git a/sal/qa/testHelperFunctions/makefile.mk b/sal/qa/testHelperFunctions/makefile.mk new file mode 100644 index 000000000000..33c43f259081 --- /dev/null +++ b/sal/qa/testHelperFunctions/makefile.mk @@ -0,0 +1,67 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.6 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=sal +TARGET=qa_testHelperFunctions + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGS+= $(LFS_CFLAGS) +CXXFLAGS+= $(LFS_CFLAGS) + +# --- BEGIN -------------------------------------------------------- +SHL1OBJS= \ + $(SLO)$/testHelperFunctions.obj \ + $(SLO)$/testHelperFunctions2.obj + +SHL1TARGET= testHelperFunctions +SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = $(PRJ)$/qa$/export.map + +# END -------------------------------------------------------------- + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sal/qa/testHelperFunctions/testHelperFunctions.cxx b/sal/qa/testHelperFunctions/testHelperFunctions.cxx new file mode 100644 index 000000000000..9d96d91939ec --- /dev/null +++ b/sal/qa/testHelperFunctions/testHelperFunctions.cxx @@ -0,0 +1,457 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: testHelperFunctions.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +// This is a test of helperfunctions + +#include <osl/time.h> +#include <osl/thread.hxx> + +#include "stringhelper.hxx" + +#include <testshl/simpleheader.hxx> + +// void isJaBloed() +// { +// t_print("Ist ja echt bloed.\n"); +// } + +inline sal_Int64 t_abs64(sal_Int64 _nValue) +{ + // std::abs() seems to have some ambiguity problems (so-texas) + // return abs(_nValue); + t_print("t_abs64(%ld)\n", _nValue); + // CPPUNIT_ASSERT(_nValue < 2147483647); + + if (_nValue < 0) + { + _nValue = -_nValue; + } + return _nValue; +} + +void t_print64(sal_Int64 n) +{ + if (n < 0) + { + // negativ + printf("-"); + n = -n; + } + if (n > 2147483647) + { + sal_Int64 n64 = n >> 32; + sal_uInt32 n32 = n64 & 0xffffffff; + printf("0x%.8x ", n32); + n32 = n & 0xffffffff; + printf("%.8x (64bit)", n32); + } + else + { + sal_uInt32 n32 = n & 0xffffffff; + printf("0x%.8x (32bit) ", n32); + } + printf("\n"); +} + +// ----------------------------------------------------------------------------- +namespace testOfHelperFunctions +{ + class test_t_abs64 : public CppUnit::TestFixture + { + public: + void test0(); + void test1_0(); + void test1(); + void test1_1(); + void test2(); + void test3(); + void test4(); + + CPPUNIT_TEST_SUITE( test_t_abs64 ); + CPPUNIT_TEST( test0 ); + CPPUNIT_TEST( test1_0 ); + CPPUNIT_TEST( test1 ); + CPPUNIT_TEST( test1_1 ); + CPPUNIT_TEST( test2 ); + CPPUNIT_TEST( test3 ); + CPPUNIT_TEST( test4 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + void test_t_abs64::test0() + { + // this values has an overrun! + sal_Int32 n32 = 2147483648; + t_print("n32 should be -2^31 is: %d\n", n32); + CPPUNIT_ASSERT_MESSAGE("n32!=2147483648", n32 == -2147483648 ); + } + + + void test_t_abs64::test1_0() + { + sal_Int64 n; + n = 1073741824; + n <<= 9; + t_print("Value of n is "); + t_print64(n); + CPPUNIT_ASSERT_MESSAGE("n=2^30 << 9", t_abs64(n) > 0 ); + } + + void test_t_abs64::test1() + { + sal_Int64 n; + n = 2147483648 << 8; + t_print("Value of n is "); + t_print64(n); + CPPUNIT_ASSERT_MESSAGE("n=2^31 << 8", t_abs64(n) > 0 ); + } + void test_t_abs64::test1_1() + { + sal_Int64 n; + n = sal_Int64(2147483648) << 8; + t_print("Value of n is "); + t_print64(n); + CPPUNIT_ASSERT_MESSAGE("n=2^31 << 8", t_abs64(n) > 0 ); + } + + void test_t_abs64::test2() + { + sal_Int64 n; + n = 2147483648 << 1; + t_print("Value of n is "); + t_print64(n); + + CPPUNIT_ASSERT_MESSAGE("(2147483648 << 1) is != 0", n != 0 ); + + sal_Int64 n2 = 2147483648 * 2; + CPPUNIT_ASSERT_MESSAGE("2147483648 * 2 is != 0", n2 != 0 ); + + sal_Int64 n3 = 4294967296LL; + CPPUNIT_ASSERT_MESSAGE("4294967296 is != 0", n3 != 0 ); + + CPPUNIT_ASSERT_MESSAGE("n=2^31 << 1, n2 = 2^31 * 2, n3 = 2^32, all should equal!", n == n2 && n == n3 ); + } + + + void test_t_abs64::test3() + { + sal_Int64 n = 0; + CPPUNIT_ASSERT_MESSAGE("n=0", t_abs64(n) == 0 ); + + n = 1; + CPPUNIT_ASSERT_MESSAGE("n=1", t_abs64(n) > 0 ); + + n = 2147483647; + CPPUNIT_ASSERT_MESSAGE("n=2^31 - 1", t_abs64(n) > 0 ); + + n = 2147483648; + CPPUNIT_ASSERT_MESSAGE("n=2^31", t_abs64(n) > 0 ); + } + + void test_t_abs64::test4() + { + sal_Int64 n = 0; + n = -1; + t_print("Value of n is -1 : "); + t_print64(n); + CPPUNIT_ASSERT_MESSAGE("n=-1", t_abs64(n) > 0 ); + + n = -2147483648; + t_print("Value of n is -2^31 : "); + t_print64(n); + CPPUNIT_ASSERT_MESSAGE("n=-2^31", t_abs64(n) > 0 ); + + n = -8589934592LL; + t_print("Value of n is -2^33 : "); + t_print64(n); + CPPUNIT_ASSERT_MESSAGE("n=-2^33", t_abs64(n) > 0 ); + } + + +// ----------------------------------------------------------------------------- + class test_t_print : public CppUnit::TestFixture + { + public: + void t_print_001(); + + CPPUNIT_TEST_SUITE( test_t_print ); + CPPUNIT_TEST( t_print_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + void test_t_print::t_print_001( ) + { + t_print("This is only a test of some helper functions\n"); + sal_Int32 nValue = 12345; + t_print("a value %d (should be 12345)\n", nValue); + + rtl::OString sValue("foo bar"); + t_print("a String '%s' (should be 'foo bar')\n", sValue.getStr()); + + rtl::OUString suValue(rtl::OUString::createFromAscii("a unicode string")); + sValue <<= suValue; + t_print("a String '%s'\n", sValue.getStr()); + } + + + class StopWatch + { + TimeValue m_aStartTime; + TimeValue m_aEndTime; + bool m_bStarted; + public: + StopWatch() + :m_bStarted(false) + { + } + + void start() + { + m_bStarted = true; + osl_getSystemTime(&m_aStartTime); + } + void stop() + { + osl_getSystemTime(&m_aEndTime); + OSL_ENSURE(m_bStarted, "Not Started."); + m_bStarted = false; + } + rtl::OString makeTwoDigits(rtl::OString const& _sStr) + { + rtl::OString sBack; + if (_sStr.getLength() == 0) + { + sBack = "00"; + } + else + { + if (_sStr.getLength() == 1) + { + sBack = "0" + _sStr; + } + else + { + sBack = _sStr; + } + } + return sBack; + } + rtl::OString makeThreeDigits(rtl::OString const& _sStr) + { + rtl::OString sBack; + if (_sStr.getLength() == 0) + { + sBack = "000"; + } + else + { + if (_sStr.getLength() == 1) + { + sBack = "00" + _sStr; + } + else + { + if (_sStr.getLength() == 2) + { + sBack = "0" + _sStr; + } + else + { + sBack = _sStr; + } + } + } + return sBack; + } + + void showTime(const rtl::OString & aWhatStr) + { + OSL_ENSURE(!m_bStarted, "Not Stopped."); + + sal_Int32 nSeconds = m_aEndTime.Seconds - m_aStartTime.Seconds; + sal_Int32 nNanoSec = sal_Int32(m_aEndTime.Nanosec) - sal_Int32(m_aStartTime.Nanosec); + // printf("Seconds: %d Nanosec: %d ", nSeconds, nNanoSec); + if (nNanoSec < 0) + { + nNanoSec = 1000000000 + nNanoSec; + nSeconds--; + // printf(" NEW Seconds: %d Nanosec: %d\n", nSeconds, nNanoSec); + } + + rtl::OString aStr = "Time for "; + aStr += aWhatStr; + aStr += " "; + aStr += makeTwoDigits(rtl::OString::valueOf(nSeconds / 3600)); + aStr += ":"; + aStr += makeTwoDigits(rtl::OString::valueOf((nSeconds % 3600) / 60)); + aStr += ":"; + aStr += makeTwoDigits(rtl::OString::valueOf((nSeconds % 60))); + aStr += ":"; + aStr += makeThreeDigits(rtl::OString::valueOf((nNanoSec % 1000000000) / 1000000)); + aStr += ":"; + aStr += makeThreeDigits(rtl::OString::valueOf((nNanoSec % 1000000) / 1000)); + aStr += ":"; + aStr += makeThreeDigits(rtl::OString::valueOf((nNanoSec % 1000))); + + printf("%s\n", aStr.getStr()); + // cout << aStr.getStr() << endl; + } + + }; + +static sal_Bool isEqualTimeValue ( const TimeValue* time1, const TimeValue* time2) +{ + if( time1->Seconds == time2->Seconds && + time1->Nanosec == time2->Nanosec) + return sal_True; + else + return sal_False; +} + +static sal_Bool isGreaterTimeValue( const TimeValue* time1, const TimeValue* time2) +{ + sal_Bool retval= sal_False; + if ( time1->Seconds > time2->Seconds) + retval= sal_True; + else if ( time1->Seconds == time2->Seconds) + { + if( time1->Nanosec > time2->Nanosec) + retval= sal_True; + } + return retval; +} + +static sal_Bool isGreaterEqualTimeValue( const TimeValue* time1, const TimeValue* time2) +{ + if( isEqualTimeValue( time1, time2) ) + return sal_True; + else if( isGreaterTimeValue( time1, time2)) + return sal_True; + else + return sal_False; +} + +bool isBTimeGreaterATime(TimeValue const& A, TimeValue const& B) +{ + if (B.Seconds > A.Seconds) return true; + if (B.Nanosec > A.Nanosec) return true; + + // lower or equal + return false; +} + // ----------------------------------------------------------------------------- + + + class test_TimeValues : public CppUnit::TestFixture + { + public: + + void t_time1(); + void t_time2(); + void t_time3(); + + CPPUNIT_TEST_SUITE( test_TimeValues ); + CPPUNIT_TEST( t_time1 ); + CPPUNIT_TEST( t_time2 ); + CPPUNIT_TEST( t_time3 ); + CPPUNIT_TEST_SUITE_END( ); + }; + +void test_TimeValues::t_time1() +{ + StopWatch aWatch; + aWatch.start(); + TimeValue aTimeValue={3,0}; + osl::Thread::wait(aTimeValue); + aWatch.stop(); + aWatch.showTime("Wait for 3 seconds"); +} + +void test_TimeValues::t_time2() +{ + t_print("Wait repeats 20 times.\n"); + int i=0; + while(i++<20) + { + StopWatch aWatch; + aWatch.start(); + TimeValue aTimeValue={0,1000 * 1000 * 500}; + osl::Thread::wait(aTimeValue); + aWatch.stop(); + aWatch.showTime("wait for 500msec"); + } +} + +void test_TimeValues::t_time3() +{ + t_print("Wait repeats 100 times.\n"); + int i=0; + while(i++<20) + { + StopWatch aWatch; + aWatch.start(); + TimeValue aTimeValue={0,1000*1000*100}; + osl::Thread::wait(aTimeValue); + aWatch.stop(); + aWatch.showTime("wait for 100msec"); + } +} + + // void demoTimeValue() + // { + // TimeValue aStartTime, aEndTime; + // osl_getSystemTime(&aStartTime); + // // testSession(xORB, false); + // osl_getSystemTime(&aEndTime); + // + // sal_Int32 nSeconds = aEndTime.Seconds - aStartTime.Seconds; + // sal_Int32 nNanoSec = aEndTime.Nanosec - aStartTime.Nanosec; + // if (nNanoSec < 0) + // { + // nNanoSec = 1000000000 - nNanoSec; + // nSeconds++; + // } + // + // // cout << "Time: " << nSeconds << ". " << nNanoSec << endl; + // } + + +} // namespace testOfHelperFunctions + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_t_print, "helperFunctions" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_t_abs64, "helperFunctions" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_TimeValues, "helperFunctions" ); + +// ----------------------------------------------------------------------------- +NOADDITIONAL; diff --git a/sal/qa/testHelperFunctions/testHelperFunctions2.cxx b/sal/qa/testHelperFunctions/testHelperFunctions2.cxx new file mode 100644 index 000000000000..1adae36ade2a --- /dev/null +++ b/sal/qa/testHelperFunctions/testHelperFunctions2.cxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: testHelperFunctions2.cxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sal.hxx" +#include <testshl/simpleheader.hxx> +#include "stringhelper.hxx" + +namespace testOfHelperFunctions +{ + class test_valueequal : public CppUnit::TestFixture + { + public: + void valueequal_001(); + + CPPUNIT_TEST_SUITE( test_valueequal ); + CPPUNIT_TEST( valueequal_001 ); + CPPUNIT_TEST_SUITE_END( ); + }; + + void test_valueequal::valueequal_001( ) + { + rtl::OString sValue; + rtl::OUString suValue(rtl::OUString::createFromAscii("This is only a test of some helper functions")); + sValue <<= suValue; + t_print("'%s'\n", sValue.getStr()); + } + +} // namespace testOfHelperFunctions + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_valueequal, "helperFunctions" ); + +// ----------------------------------------------------------------------------- +// This is only allowed to be in one file! +// NOADDITIONAL; |