xref: /trunk/main/binaryurp/qa/test-unmarshal.cxx (revision cdf0e10c)
1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2011 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #include "sal/config.h"
29 
30 #include "com/sun/star/io/IOException.hpp"
31 #include "com/sun/star/uno/Sequence.hxx"
32 #include "cppu/unotype.hxx"
33 #include "cppunit/TestAssert.h"
34 #include "cppunit/TestFixture.h"
35 #include "cppunit/extensions/HelperMacros.h"
36 #include "cppunit/plugin/TestPlugIn.h"
37 #include "rtl/ref.hxx"
38 #include "rtl/string.h"
39 #include "sal/types.h"
40 #include "typelib/typedescription.hxx"
41 
42 #include "../source/bridge.hxx"
43 #include "../source/cache.hxx"
44 #include "../source/readerstate.hxx"
45 #include "../source/unmarshal.hxx"
46 
47 namespace {
48 
49 namespace css = com::sun::star;
50 
51 class Test: public CppUnit::TestFixture {
52 private:
53     CPPUNIT_TEST_SUITE(Test);
54     CPPUNIT_TEST(testTypeOfBooleanSequence);
55     CPPUNIT_TEST(testTypeOfVoidSequence);
56     CPPUNIT_TEST_SUITE_END();
57 
58     void testTypeOfBooleanSequence();
59 
60     void testTypeOfVoidSequence();
61 };
62 
63 void Test::testTypeOfBooleanSequence() {
64     binaryurp::ReaderState state;
65     css::uno::Sequence< sal_Int8 > buf(13);
66     buf[0] = static_cast< sal_Int8 >(20 | 0x80); // sequence type | cache flag
67     buf[1] = static_cast< sal_Int8 >(binaryurp::cache::ignore >> 8);
68     buf[2] = static_cast< sal_Int8 >(binaryurp::cache::ignore & 0xFF);
69     buf[3] = RTL_CONSTASCII_LENGTH("[]boolean");
70     buf[4] = '[';
71     buf[5] = ']';
72     buf[6] = 'b';
73     buf[7] = 'o';
74     buf[8] = 'o';
75     buf[9] = 'l';
76     buf[10] = 'e';
77     buf[11] = 'a';
78     buf[12] = 'n';
79     binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
80     css::uno::TypeDescription t(m.readType());
81     CPPUNIT_ASSERT(
82         t.equals(
83             css::uno::TypeDescription(
84                 cppu::UnoType< css::uno::Sequence< bool > >::get())));
85     m.done();
86 }
87 
88 void Test::testTypeOfVoidSequence() {
89     binaryurp::ReaderState state;
90     css::uno::Sequence< sal_Int8 > buf(10);
91     buf[0] = static_cast< sal_Int8 >(20 | 0x80); // sequence type | cache flag
92     buf[1] = static_cast< sal_Int8 >(binaryurp::cache::ignore >> 8);
93     buf[2] = static_cast< sal_Int8 >(binaryurp::cache::ignore & 0xFF);
94     buf[3] = RTL_CONSTASCII_LENGTH("[]void");
95     buf[4] = '[';
96     buf[5] = ']';
97     buf[6] = 'v';
98     buf[7] = 'o';
99     buf[8] = 'i';
100     buf[9] = 'd';
101     binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
102     try {
103         m.readType();
104         CPPUNIT_FAIL("exception expected");
105     } catch (css::io::IOException &) {}
106 }
107 
108 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
109 
110 }
111 
112 CPPUNIT_PLUGIN_IMPLEMENT();
113