Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/sal/qa/rtl/strings/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 4 kB image not shown  

Quelle  test_strings_valuex.cxx   Sprache: C

 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


#include <sal/types.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <rtl/ustring.hxx>

namespace test::strings {

class valueX : public CppUnit::TestFixture {
public:
    void testOBoolean();
    void testOUBoolean();
    void testOUInt();
    void testOInt();
    void testOUFloat();
    void testOFloat();

    CPPUNIT_TEST_SUITE(valueX);
    CPPUNIT_TEST(testOBoolean);
    CPPUNIT_TEST(testOUBoolean);
    CPPUNIT_TEST(testOUInt);
    CPPUNIT_TEST(testOInt);
    CPPUNIT_TEST(testOUFloat);
    CPPUNIT_TEST(testOFloat);
    CPPUNIT_TEST_SUITE_END();
};

}

CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX);

namespace {

templatetypename T >
void testBoolean() {
    CPPUNIT_ASSERT_EQUAL( T( "false" ), T(T::boolean( false )) );
    CPPUNIT_ASSERT_EQUAL( T( "true" ), T(T::boolean( true )) );
}

}

void test::strings::valueX::testOBoolean() {
    testBoolean<OString>();
}

void test::strings::valueX::testOUBoolean() {
    testBoolean<OUString>();
}

templatetypename T >
static void testInt() {
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( 30039062 )));

    // test the overloading resolution

    CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_castsigned char >( 30 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_castunsigned char >( 30 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_castshort >( 30039 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_castunsigned short >( 30039 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_castint >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_castunsigned int >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_castlong >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_castunsigned long >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_castlong long >( 30039062 ))));
    // The highest bit set in unsigned long long may not actually work.
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_castunsigned long long >( 30039062 ))));

    CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< sal_Int8 >( 30 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30" ), T( T::number( static_cast< sal_uInt8 >( 30 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< sal_Int16 >( 30039 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039" ), T( T::number( static_cast< sal_uInt16 >( 30039 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_Int32 >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_uInt32 >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_Int64 >( 30039062 ))));
    CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T( T::number( static_cast< sal_uInt64 >( 30039062 ))));

    // The implementation internally uses sal_Int64 etc. types, so check ranges.
    assert( sizeofint ) <= sizeof( sal_Int32 ));
    assert( sizeoflong ) <= sizeof( sal_Int64 ));
    assert( sizeoflong long ) <= sizeof( sal_Int64 ));
    assert( sizeofunsigned int ) < sizeof( sal_Int64 ));
}

void test::strings::valueX::testOUInt() {
    testInt<OUString>();
}

void test::strings::valueX::testOInt() {
    testInt<OString>();
}

templatetypename T >
static void testFloat() {
    CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T( T::number( 39062.2f )));
    CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T( T::number( 30039062.2 )));
    // long double not supported
}

void test::strings::valueX::testOUFloat() {
    testFloat<OUString>();
}

void test::strings::valueX::testOFloat() {
    testFloat<OString>();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Messung V0.5
C=94 H=96 G=94

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.