/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// 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(number_double_test_001);
CPPUNIT_TEST(number_double_test_002);
CPPUNIT_TEST(number_double_test_003);
CPPUNIT_TEST(number_double_test_004);
CPPUNIT_TEST(number_double_test_005);
CPPUNIT_TEST(number_double_test_006);
CPPUNIT_TEST(number_double_test_007);
CPPUNIT_TEST(number_double_test_008);
CPPUNIT_TEST_SUITE_END();
}; // class number
class toInt: public CppUnit::TestFixture { public: void test() {
CPPUNIT_ASSERT_EQUAL( static_cast< sal_Int32 >(-0x76543210),
(u"-76543210"_ustr.
toInt32(16))); // @return 0 if this string represents no number or one of too large magnitude
CPPUNIT_ASSERT_EQUAL( static_cast< sal_Int32 >(0),
(u"+FEDCBA98"_ustr.
toInt32(16)));
CPPUNIT_ASSERT_EQUAL( static_cast< sal_Int64 >(-SAL_CONST_INT64(0x76543210FEDCBA98)),
(u"-76543210FEDCBA98"_ustr.
toInt64(16))); // @return 0 if this string represents no number or one of too large magnitude
CPPUNIT_ASSERT_EQUAL( static_cast< sal_Int64 >(SAL_CONST_INT64(0)),
(u"+FEDCBA9876543210"_ustr.
toInt64(16)));
}
// 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.
// 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.
void lastIndexOf_test_oustring_offset_001()
{ // search for sun, start at the end, found (pos==0)
OUString aStr(u"sun java system"_ustr);
lastIndexOf_oustring_offset(aStr, u"sun"_ustr, 0, aStr.getLength());
}
void lastIndexOf_test_oustring_offset_002()
{ // search for sun, start at pos = 3, found (pos==0)
lastIndexOf_oustring_offset(u"sun java system"_ustr, u"sun"_ustr, 0, 3);
}
void lastIndexOf_test_oustring_offset_003()
{ // search for sun, start at pos = 2, found (pos==-1)
lastIndexOf_oustring_offset(u"sun java system"_ustr, u"sun"_ustr, -1, 2);
}
void lastIndexOf_test_oustring_offset_004()
{ // search for sun, start at the end, found (pos==0)
lastIndexOf_oustring_offset(u"sun java system"_ustr, u"sun"_ustr, -1, 1);
}
void lastIndexOf_test_oustring_001()
{ // search for sun, found (pos==0)
lastIndexOf_oustring(u"sun java system"_ustr, u"sun"_ustr, 0);
}
void lastIndexOf_test_oustring_002()
{ // search for sun, found (pos==4)
lastIndexOf_oustring(u"the sun java system"_ustr, u"sun"_ustr, 4);
}
void lastIndexOf_test_oustring_003()
{ // search for sun, found (pos==8)
lastIndexOf_oustring(u"the sun sun java system"_ustr, u"sun"_ustr, 8);
}
void lastIndexOf_test_oustring_004()
{ // search for sun, found (pos==8)
lastIndexOf_oustring(u"the sun sun"_ustr, u"sun"_ustr, 8);
}
void lastIndexOf_test_oustring_005()
{ // search for sun, found (pos==4)
lastIndexOf_oustring(u"the sun su"_ustr, u"sun"_ustr, 4);
}
void lastIndexOf_test_oustring_006()
{ // search for sun, found (pos==-1)
lastIndexOf_oustring(u"the su su"_ustr, u"sun"_ustr, -1);
}
void lastIndexOf_test_oustring_007()
{ // search for earth, not found (-1)
lastIndexOf_oustring(u"the su su"_ustr, u"earth"_ustr, -1);
}
void lastIndexOf_test_oustring_008()
{ // search for earth, not found (-1)
lastIndexOf_oustring(u""_ustr, u"earth"_ustr, -1);
}
void lastIndexOf_test_oustring_009()
{ // search for earth, not found (-1)
lastIndexOf_oustring(u""_ustr, u""_ustr, -1);
}
void lastIndexOf_test_salunicode_001()
{ // search for 's', found (19)
sal_Unicode suChar = L's';
lastIndexOf_salunicode(u"the sun sun java system"_ustr, suChar, 19);
}
void lastIndexOf_test_salunicode_002()
{ // search for 'x', not found (-1)
sal_Unicode suChar = L'x';
lastIndexOf_salunicode(u"the sun sun java system"_ustr, suChar, -1);
}
void lastIndexOf_test_salunicode_offset_001()
{ // search for 's', start from pos last char, found (19)
OUString aStr(u"the sun sun java system"_ustr);
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)
sal_Unicode cuChar = L's';
lastIndexOf_salunicode_offset(u"the sun sun java system"_ustr, cuChar, 17, 19);
} void lastIndexOf_test_salunicode_offset_003()
{ // search for 't', start pos is 1, found (0)
sal_Unicode cuChar = L't';
lastIndexOf_salunicode_offset(u"the sun sun java system"_ustr, 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.
OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'a'", u"a"_ustr, suToken);
/* OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be a 'b'", u"b"_ustr, suToken);
CPPUNIT_ASSERT_EQUAL_MESSAGE("index should be negative", static_cast<sal_Int32>(-1), nIndex);
}
OUString suToken = suTokenStr.getToken( 0, '.', nIndex );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be 'longer'", u"longer"_ustr, suToken );
/* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be 'then'", u"then"_ustr, suToken );
/* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Token should be 'ever'", u"ever"_ustr, suToken );
/* OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.isEmpty());
CPPUNIT_ASSERT_EQUAL_MESSAGE("index should be negative", static_cast<sal_Int32>(-1), nIndex);
}
void getToken_005() {
OUString ab(u"ab"_ustr);
sal_Int32 n = 0;
CPPUNIT_ASSERT_EQUAL_MESSAGE( "token should be 'ab'", ab, ab.getToken(0, '-', n));
CPPUNIT_ASSERT_EQUAL_MESSAGE("n should be -1", static_cast<sal_Int32>(-1), n);
CPPUNIT_ASSERT_MESSAGE( "token should be empty", ab.getToken(0, '-', n).isEmpty());
}
void getToken_006()
{
OUString suTokenStr; auto pTokenStr = suTokenStr.getStr();
sal_uInt64 n64 = reinterpret_cast<sal_uInt64>(pTokenStr) / sizeof(sal_Unicode); // Point either to 0x0, or to some random address -4GiB away from this string
sal_Int32 n = n64 > o3tl::make_unsigned(SAL_MAX_INT32) ? -SAL_MAX_INT32
: -static_cast<sal_Int32>(n64);
suTokenStr.getToken(0, ';', n); // should not GPF with negative index
}
OUString aBaa( "this is a very long string with a lot of long things inside it and it goes on and on and on forever etc." );
CPPUNIT_ASSERT_MESSAGE("string length", aBaa.getLength() == 104); // Dig at the internals ... FIXME: should we have the bit-flag defines public ?
CPPUNIT_ASSERT_MESSAGE("string static flags", (aBaa.pData->refCount & 1<<30) != 0); #endif
}
void intern()
{ // The empty string is 'static' a special case ...
OUString().intern();
OUString::intern( "",strlen(""),RTL_TEXTENCODING_ASCII_US );
OUString aFoo( u"foo"_ustr );
OUString aFooIntern = aFoo.intern();
CPPUNIT_ASSERT_EQUAL_MESSAGE( "string contents", u"foo"_ustr, aFooIntern);
CPPUNIT_ASSERT_EQUAL_MESSAGE("string length", static_cast<sal_Int32>(3), aFooIntern.getLength()); // We have to dup due to no atomic 'intern' bit-set operation
CPPUNIT_ASSERT_MESSAGE("intern dups", aFoo.pData != aFooIntern.pData);
// Test interning lots of things int i; staticconstint nSequence = 4096;
std::unique_ptr<OUString[]> pStrs(new OUString[nSequence]); for (i = 0; i < nSequence; i++)
{
pStrs[i] = OUString::number( sqrt( static_cast<double>(i) ) ).intern();
} for (i = 0; i < nSequence; i++)
{
OUString aNew = OUString::number( sqrt( static_cast<double>(i) ) ).intern();
CPPUNIT_ASSERT_EQUAL_MESSAGE("double intern failed",
pStrs[i].pData, aNew.pData);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.