/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/services/case.hpp" #include //TODO: #include "test/codemaker/cppumaker/services/char.hpp" #include //TODO: #include "test/codemaker/cppumaker/services/const.hpp" #include //TODO: #include "test/codemaker/cppumaker/services/default.hpp" #include #include //TODO: #include "test/codemaker/cppumaker/services/double.hpp" #include //TODO: #include "test/codemaker/cppumaker/services/enum.hpp" #include #include #include #include //TODO: #include "test/codemaker/cppumaker/services/float.hpp" #include #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/services/long.hpp" #include #include #include #include #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/services/short.hpp" #include #include #include //TODO: #include "test/codemaker/cppumaker/services/struct.hpp" //TODO: #include "test/codemaker/cppumaker/services/switch.hpp" #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/services/typedef.hpp" #include #include //TODO: #include "test/codemaker/cppumaker/services/union.hpp" //TODO: #include "test/codemaker/cppumaker/services/unsigned.hpp" #include #include //TODO: #include "test/codemaker/cppumaker/services/void.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/singletons/case.hpp" #include //TODO: #include "test/codemaker/cppumaker/singletons/char.hpp" #include //TODO: #include "test/codemaker/cppumaker/singletons/const.hpp" #include //TODO: #include "test/codemaker/cppumaker/singletons/default.hpp" #include #include //TODO: #include "test/codemaker/cppumaker/singletons/double.hpp" #include //TODO: #include "test/codemaker/cppumaker/singletons/enum.hpp" #include #include #include #include //TODO: #include "test/codemaker/cppumaker/singletons/float.hpp" #include #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/singletons/long.hpp" #include #include #include #include #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/singletons/short.hpp" #include #include #include //TODO: #include "test/codemaker/cppumaker/singletons/struct.hpp" //TODO: #include "test/codemaker/cppumaker/singletons/switch.hpp" #include #include #include #include #include //TODO: #include "test/codemaker/cppumaker/singletons/typedef.hpp" #include #include //TODO: #include "test/codemaker/cppumaker/singletons/union.hpp" //TODO: #include "test/codemaker/cppumaker/singletons/unsigned.hpp" #include #include //TODO: #include "test/codemaker/cppumaker/singletons/void.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace test::codemaker::cppumaker { static bool operator ==( test::codemaker::cppumaker::TestException1 const & e1, test::codemaker::cppumaker::TestException1 const & e2) { return e1.Message == e2.Message && e1.Context == e2.Context && e1.m1 == e2.m1 && e1.m2 == e2.m2 && e1.m3 == e2.m3 && e1.m4.member1 == e2.m4.member1 && e1.m4.member2 == e2.m4.member2; } } namespace { class Test: public CppUnit::TestFixture { public: void testBigStruct(); void testPolyStruct(); void testExceptions(); void testConstants(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testBigStruct); CPPUNIT_TEST(testPolyStruct); CPPUNIT_TEST(testExceptions); CPPUNIT_TEST(testConstants); CPPUNIT_TEST_SUITE_END(); }; struct Guard { explicit Guard(void * buffer): p(new(buffer) test::codemaker::cppumaker::BigStruct) {} ~Guard() { p->test::codemaker::cppumaker::BigStruct::~BigStruct(); } test::codemaker::cppumaker::BigStruct * const p; }; void Test::testBigStruct() { // Default-initialize a BigStruct instance on top of a memory buffer filled // with random data, and make sure that all members are default-initialized: std::unique_ptr< char []> buffer( new char[sizeof (test::codemaker::cppumaker::BigStruct)]); for (std::size_t i = 0; i < sizeof (test::codemaker::cppumaker::BigStruct); ++i) { buffer[i] = '\x56'; } Guard guard(buffer.get()); CPPUNIT_ASSERT_EQUAL(sal_False, guard.p->m1); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int8 >(0), guard.p->m2); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int16 >(0), guard.p->m3); CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt16 >(0), guard.p->m4); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), guard.p->m5); CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(0), guard.p->m6); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int64 >(0), guard.p->m7); CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt64 >(0), guard.p->m8); CPPUNIT_ASSERT_EQUAL(0.0f, guard.p->m9); CPPUNIT_ASSERT_EQUAL(0.0, guard.p->m10); CPPUNIT_ASSERT_EQUAL( u'\0', guard.p->m11); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), guard.p->m12.getLength()); CPPUNIT_ASSERT_EQUAL(sal_Int32(css::uno::TypeClass_VOID), static_cast(guard.p->m13.getTypeClass())); CPPUNIT_ASSERT_EQUAL(false, guard.p->m14.hasValue()); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), guard.p->m15.getLength()); CPPUNIT_ASSERT_EQUAL(int(test::codemaker::cppumaker::HelperEnum_ZERO), static_cast(guard.p->m16)); CPPUNIT_ASSERT_EQUAL(sal_False, guard.p->m17.m1); CPPUNIT_ASSERT_EQUAL(false, guard.p->m17.m2.is()); CPPUNIT_ASSERT_EQUAL(false, guard.p->m18.is()); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int8 >(0), guard.p->m19); CPPUNIT_ASSERT_EQUAL(sal_Int32(test::codemaker::cppumaker::HelperEnum_ZERO), static_cast(guard.p->m20)); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), guard.p->m21.getLength()); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), guard.p->m22.getLength()); CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), guard.p->m23.getLength()); //This is a very platform specific test. #if defined __GNUC__ // see CPPU_GCC3_ALIGN #if defined(LINUX) && (defined (X86_64) || defined(X86) || defined(PPC)) static_assert( sizeof (test::codemaker::cppumaker::AlignmentDerivedStruct) == #if defined X86_64 || defined PPC 24 #else 16 #endif ); #endif #endif css::uno::Type t( cppu::UnoType< test::codemaker::cppumaker::BigStruct >::get()); typelib_TypeDescription * td = nullptr; t.getDescription(&td); typelib_typedescription_complete(&td); fprintf(stdout, "#### 1\n"); CPPUNIT_ASSERT(td != nullptr); CPPUNIT_ASSERT_EQUAL(+typelib_TypeClass_STRUCT, +td->eTypeClass); typelib_StructTypeDescription * std = reinterpret_cast< typelib_StructTypeDescription * >(td); CPPUNIT_ASSERT_EQUAL(+typelib_TypeClass_UNSIGNED_SHORT, +std->aBase.ppTypeRefs[3]->eTypeClass); // unsigned short m4; CPPUNIT_ASSERT_EQUAL(+typelib_TypeClass_CHAR, +std->aBase.ppTypeRefs[10]->eTypeClass); // char m11; } void Test::testPolyStruct() { CPPUNIT_ASSERT_EQUAL( u"test.codemaker.cppumaker.Struct"_ustr, (css::uno::Any( test::codemaker::cppumaker::Struct< sal_Unicode, sal_Int16 >()). getValueType().getTypeName())); css::uno::Sequence< css::uno::Sequence< css::uno::Any > > aEmptySequence; CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt32 >(5), (test::codemaker::cppumaker::make_Struct< sal_uInt32, sal_Bool >(5, aEmptySequence).member1)); } void Test::testExceptions() { css::uno::Sequence< css::uno::Sequence< css::uno::Any > > aEmptySequence; test::codemaker::cppumaker::TestException1 e11( u"abc"_ustr, nullptr, 1, css::uno::Any(123.0), test::codemaker::cppumaker::HelperEnum_ONE, test::codemaker::cppumaker::Struct(5, aEmptySequence), 2); test::codemaker::cppumaker::TestException1 e12(e11); CPPUNIT_ASSERT_EQUAL(e11, e12); test::codemaker::cppumaker::TestException1 e13; e13 = e11; CPPUNIT_ASSERT_EQUAL(e11, e13); test::codemaker::cppumaker::TestException2 e21( u"abc"_ustr, nullptr, 1, css::uno::Any(123.0), test::codemaker::cppumaker::HelperEnum_ONE, test::codemaker::cppumaker::Struct(5, aEmptySequence), 2); test::codemaker::cppumaker::TestException2 e22(e21); CPPUNIT_ASSERT_EQUAL(e21, e22); test::codemaker::cppumaker::TestException2 e23; e23 = e21; CPPUNIT_ASSERT_EQUAL(e21, e23); } void Test::testConstants() { CPPUNIT_ASSERT_EQUAL( SAL_MIN_INT8, test::codemaker::cppumaker::Constants::byteMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_INT8, test::codemaker::cppumaker::Constants::byteMax); CPPUNIT_ASSERT_EQUAL( SAL_MIN_INT16, test::codemaker::cppumaker::Constants::shortMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_INT16, test::codemaker::cppumaker::Constants::shortMax); CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt16 >(0), test::codemaker::cppumaker::Constants::unsignedShortMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_UINT16, test::codemaker::cppumaker::Constants::unsignedShortMax); CPPUNIT_ASSERT_EQUAL( SAL_MIN_INT32, test::codemaker::cppumaker::Constants::longMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_INT32, test::codemaker::cppumaker::Constants::longMax); CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt32 >(0), test::codemaker::cppumaker::Constants::unsignedLongMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_UINT32, test::codemaker::cppumaker::Constants::unsignedLongMax); CPPUNIT_ASSERT_EQUAL( SAL_MIN_INT64, test::codemaker::cppumaker::Constants::hyperMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_INT64, test::codemaker::cppumaker::Constants::hyperMax); CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt64 >(0), test::codemaker::cppumaker::Constants::unsignedHyperMin); CPPUNIT_ASSERT_EQUAL( SAL_MAX_UINT64, test::codemaker::cppumaker::Constants::unsignedHyperMax); } CPPUNIT_TEST_SUITE_REGISTRATION(Test); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */