xref: /trunk/main/binaryurp/qa/test-unmarshal.cxx (revision e5230ffa)
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 "gtest/gtest.h"
30 #include "rtl/ref.hxx"
31 #include "rtl/string.h"
32 #include "sal/types.h"
33 #include "typelib/typedescription.hxx"
34 
35 #include "../source/bridge.hxx"
36 #include "../source/cache.hxx"
37 #include "../source/readerstate.hxx"
38 #include "../source/unmarshal.hxx"
39 
40 namespace {
41 
42 namespace css = com::sun::star;
43 
44 class Test: public ::testing::Test {
45 public:
46 };
47 
TEST_F(Test,testTypeOfBooleanSequence)48 TEST_F(Test, testTypeOfBooleanSequence) {
49     binaryurp::ReaderState state;
50     css::uno::Sequence< sal_Int8 > buf(13);
51     buf[0] = static_cast< sal_Int8 >(20 | 0x80); // sequence type | cache flag
52     buf[1] = static_cast< sal_Int8 >(binaryurp::cache::ignore >> 8);
53     buf[2] = static_cast< sal_Int8 >(binaryurp::cache::ignore & 0xFF);
54     buf[3] = RTL_CONSTASCII_LENGTH("[]boolean");
55     buf[4] = '[';
56     buf[5] = ']';
57     buf[6] = 'b';
58     buf[7] = 'o';
59     buf[8] = 'o';
60     buf[9] = 'l';
61     buf[10] = 'e';
62     buf[11] = 'a';
63     buf[12] = 'n';
64     binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
65     css::uno::TypeDescription t(m.readType());
66     ASSERT_TRUE(
67         t.equals(
68             css::uno::TypeDescription(
69                 cppu::UnoType< css::uno::Sequence< bool > >::get())));
70     m.done();
71 }
72 
TEST_F(Test,testTypeOfVoidSequence)73 TEST_F(Test, testTypeOfVoidSequence) {
74     binaryurp::ReaderState state;
75     css::uno::Sequence< sal_Int8 > buf(10);
76     buf[0] = static_cast< sal_Int8 >(20 | 0x80); // sequence type | cache flag
77     buf[1] = static_cast< sal_Int8 >(binaryurp::cache::ignore >> 8);
78     buf[2] = static_cast< sal_Int8 >(binaryurp::cache::ignore & 0xFF);
79     buf[3] = RTL_CONSTASCII_LENGTH("[]void");
80     buf[4] = '[';
81     buf[5] = ']';
82     buf[6] = 'v';
83     buf[7] = 'o';
84     buf[8] = 'i';
85     buf[9] = 'd';
86     binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
87     try {
88         m.readType();
89         FAIL() << "exception expected";
90     } catch (css::io::IOException &) {}
91 }
92 
93 
94 }
95