Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "com/sun/star/io/IOException.hpp"
21 : #include "com/sun/star/uno/Sequence.hxx"
22 : #include "cppu/unotype.hxx"
23 : #include "cppunit/TestAssert.h"
24 : #include "cppunit/TestFixture.h"
25 : #include "cppunit/extensions/HelperMacros.h"
26 : #include "cppunit/plugin/TestPlugIn.h"
27 : #include "rtl/ref.hxx"
28 : #include "rtl/string.h"
29 : #include "sal/types.h"
30 : #include "typelib/typedescription.hxx"
31 :
32 : #include "../source/bridge.hxx"
33 : #include "../source/cache.hxx"
34 : #include "../source/readerstate.hxx"
35 : #include "../source/unmarshal.hxx"
36 :
37 : namespace {
38 :
39 12 : class Test: public CppUnit::TestFixture {
40 : private:
41 4 : CPPUNIT_TEST_SUITE(Test);
42 2 : CPPUNIT_TEST(testTypeOfBooleanSequence);
43 2 : CPPUNIT_TEST(testTypeOfVoidSequence);
44 4 : CPPUNIT_TEST_SUITE_END();
45 :
46 : void testTypeOfBooleanSequence();
47 :
48 : void testTypeOfVoidSequence();
49 : };
50 :
51 2 : void Test::testTypeOfBooleanSequence() {
52 2 : binaryurp::ReaderState state;
53 4 : css::uno::Sequence< sal_Int8 > buf(13);
54 2 : buf[0] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(20 | 0x80)); // sequence type | cache flag
55 2 : buf[1] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore >> 8));
56 2 : buf[2] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore & 0xFF));
57 2 : buf[3] = RTL_CONSTASCII_LENGTH("[]boolean");
58 2 : buf[4] = '[';
59 2 : buf[5] = ']';
60 2 : buf[6] = 'b';
61 2 : buf[7] = 'o';
62 2 : buf[8] = 'o';
63 2 : buf[9] = 'l';
64 2 : buf[10] = 'e';
65 2 : buf[11] = 'a';
66 2 : buf[12] = 'n';
67 4 : binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
68 4 : css::uno::TypeDescription t(m.readType());
69 4 : CPPUNIT_ASSERT(
70 : t.equals(
71 : css::uno::TypeDescription(
72 2 : cppu::UnoType< css::uno::Sequence< bool > >::get())));
73 4 : m.done();
74 2 : }
75 :
76 2 : void Test::testTypeOfVoidSequence() {
77 2 : binaryurp::ReaderState state;
78 4 : css::uno::Sequence< sal_Int8 > buf(10);
79 2 : buf[0] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(20 | 0x80)); // sequence type | cache flag
80 2 : buf[1] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore >> 8));
81 2 : buf[2] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore & 0xFF));
82 2 : buf[3] = RTL_CONSTASCII_LENGTH("[]void");
83 2 : buf[4] = '[';
84 2 : buf[5] = ']';
85 2 : buf[6] = 'v';
86 2 : buf[7] = 'o';
87 2 : buf[8] = 'i';
88 2 : buf[9] = 'd';
89 4 : binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
90 : try {
91 2 : m.readType();
92 0 : CPPUNIT_FAIL("exception expected");
93 4 : } catch (const css::io::IOException &) {}
94 2 : }
95 :
96 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
97 :
98 : }
99 :
100 8 : CPPUNIT_PLUGIN_IMPLEMENT();
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|