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 6 : class Test: public CppUnit::TestFixture {
40 : private:
41 2 : CPPUNIT_TEST_SUITE(Test);
42 1 : CPPUNIT_TEST(testTypeOfBooleanSequence);
43 1 : CPPUNIT_TEST(testTypeOfVoidSequence);
44 2 : CPPUNIT_TEST_SUITE_END();
45 :
46 : void testTypeOfBooleanSequence();
47 :
48 : void testTypeOfVoidSequence();
49 : };
50 :
51 1 : void Test::testTypeOfBooleanSequence() {
52 1 : binaryurp::ReaderState state;
53 1 : css::uno::Sequence< sal_Int8 > buf(13);
54 1 : buf[0] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(20 | 0x80)); // sequence type | cache flag
55 1 : buf[1] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore >> 8));
56 1 : buf[2] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore & 0xFF));
57 1 : buf[3] = RTL_CONSTASCII_LENGTH("[]boolean");
58 1 : buf[4] = '[';
59 1 : buf[5] = ']';
60 1 : buf[6] = 'b';
61 1 : buf[7] = 'o';
62 1 : buf[8] = 'o';
63 1 : buf[9] = 'l';
64 1 : buf[10] = 'e';
65 1 : buf[11] = 'a';
66 1 : buf[12] = 'n';
67 1 : binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
68 1 : css::uno::TypeDescription t(m.readType());
69 2 : CPPUNIT_ASSERT(
70 : t.equals(
71 : css::uno::TypeDescription(
72 1 : cppu::UnoType< css::uno::Sequence< bool > >::get())));
73 1 : m.done();
74 1 : }
75 :
76 1 : void Test::testTypeOfVoidSequence() {
77 1 : binaryurp::ReaderState state;
78 1 : css::uno::Sequence< sal_Int8 > buf(10);
79 1 : buf[0] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(20 | 0x80)); // sequence type | cache flag
80 1 : buf[1] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore >> 8));
81 1 : buf[2] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore & 0xFF));
82 1 : buf[3] = RTL_CONSTASCII_LENGTH("[]void");
83 1 : buf[4] = '[';
84 1 : buf[5] = ']';
85 1 : buf[6] = 'v';
86 1 : buf[7] = 'o';
87 1 : buf[8] = 'i';
88 1 : buf[9] = 'd';
89 1 : binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
90 : try {
91 1 : m.readType();
92 0 : CPPUNIT_FAIL("exception expected");
93 2 : } catch (const css::io::IOException &) {}
94 1 : }
95 :
96 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
97 :
98 : }
99 :
100 4 : CPPUNIT_PLUGIN_IMPLEMENT();
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|