1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "sal/config.h"
25 
26 #include "com/sun/star/io/IOException.hpp"
27 #include "com/sun/star/uno/Sequence.hxx"
28 #include "cppu/unotype.hxx"
29 #include "cppunit/TestAssert.h"
30 #include "cppunit/TestFixture.h"
31 #include "cppunit/extensions/HelperMacros.h"
32 #include "cppunit/plugin/TestPlugIn.h"
33 #include "rtl/ref.hxx"
34 #include "rtl/string.h"
35 #include "sal/types.h"
36 #include "typelib/typedescription.hxx"
37 
38 #include "../source/bridge.hxx"
39 #include "../source/cache.hxx"
40 #include "../source/readerstate.hxx"
41 #include "../source/unmarshal.hxx"
42 
43 namespace {
44 
45 namespace css = com::sun::star;
46 
47 class Test: public CppUnit::TestFixture {
48 private:
49     CPPUNIT_TEST_SUITE(Test);
50     CPPUNIT_TEST(testTypeOfBooleanSequence);
51     CPPUNIT_TEST(testTypeOfVoidSequence);
52     CPPUNIT_TEST_SUITE_END();
53 
54     void testTypeOfBooleanSequence();
55 
56     void testTypeOfVoidSequence();
57 };
58 
testTypeOfBooleanSequence()59 void Test::testTypeOfBooleanSequence() {
60     binaryurp::ReaderState state;
61     css::uno::Sequence< sal_Int8 > buf(13);
62     buf[0] = static_cast< sal_Int8 >(20 | 0x80); // sequence type | cache flag
63     buf[1] = static_cast< sal_Int8 >(binaryurp::cache::ignore >> 8);
64     buf[2] = static_cast< sal_Int8 >(binaryurp::cache::ignore & 0xFF);
65     buf[3] = RTL_CONSTASCII_LENGTH("[]boolean");
66     buf[4] = '[';
67     buf[5] = ']';
68     buf[6] = 'b';
69     buf[7] = 'o';
70     buf[8] = 'o';
71     buf[9] = 'l';
72     buf[10] = 'e';
73     buf[11] = 'a';
74     buf[12] = 'n';
75     binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
76     css::uno::TypeDescription t(m.readType());
77     CPPUNIT_ASSERT(
78         t.equals(
79             css::uno::TypeDescription(
80                 cppu::UnoType< css::uno::Sequence< bool > >::get())));
81     m.done();
82 }
83 
testTypeOfVoidSequence()84 void Test::testTypeOfVoidSequence() {
85     binaryurp::ReaderState state;
86     css::uno::Sequence< sal_Int8 > buf(10);
87     buf[0] = static_cast< sal_Int8 >(20 | 0x80); // sequence type | cache flag
88     buf[1] = static_cast< sal_Int8 >(binaryurp::cache::ignore >> 8);
89     buf[2] = static_cast< sal_Int8 >(binaryurp::cache::ignore & 0xFF);
90     buf[3] = RTL_CONSTASCII_LENGTH("[]void");
91     buf[4] = '[';
92     buf[5] = ']';
93     buf[6] = 'v';
94     buf[7] = 'o';
95     buf[8] = 'i';
96     buf[9] = 'd';
97     binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
98     try {
99         m.readType();
100         CPPUNIT_FAIL("exception expected");
101     } catch (css::io::IOException &) {}
102 }
103 
104 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
105 
106 }
107 
108 CPPUNIT_PLUGIN_IMPLEMENT();
109