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