Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / binaryurp / qa / test-unmarshal.cxx
blobdf3a96d8f3787daddb8bf45237482dee8685e5de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
32 #include "../source/bridge.hxx"
33 #include "../source/cache.hxx"
34 #include "../source/readerstate.hxx"
35 #include "../source/unmarshal.hxx"
37 namespace {
39 class Test: public CppUnit::TestFixture {
40 private:
41 CPPUNIT_TEST_SUITE(Test);
42 CPPUNIT_TEST(testTypeOfBooleanSequence);
43 CPPUNIT_TEST(testTypeOfVoidSequence);
44 CPPUNIT_TEST_SUITE_END();
46 void testTypeOfBooleanSequence();
48 void testTypeOfVoidSequence();
51 void Test::testTypeOfBooleanSequence() {
52 binaryurp::ReaderState state;
53 css::uno::Sequence<sal_Int8> buf{
54 static_cast<sal_Int8>(static_cast<sal_uInt8>(20 | 0x80)),
55 // sequence type | cache flag
56 static_cast<sal_Int8>(
57 static_cast<sal_uInt8>(binaryurp::cache::ignore >> 8)),
58 static_cast<sal_Int8>(
59 static_cast<sal_uInt8>(binaryurp::cache::ignore & 0xFF)),
60 RTL_CONSTASCII_LENGTH("[]boolean"),
61 '[', ']', 'b', 'o', 'o', 'l', 'e', 'a', 'n' };
62 binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
63 css::uno::TypeDescription t(m.readType());
64 CPPUNIT_ASSERT(
65 t.equals(
66 css::uno::TypeDescription(
67 cppu::UnoType< css::uno::Sequence< bool > >::get())));
68 m.done();
71 void Test::testTypeOfVoidSequence() {
72 binaryurp::ReaderState state;
73 css::uno::Sequence<sal_Int8> buf{
74 static_cast<sal_Int8>(static_cast<sal_uInt8>(20 | 0x80)),
75 // sequence type | cache flag
76 static_cast<sal_Int8>(
77 static_cast<sal_uInt8>(binaryurp::cache::ignore >> 8)),
78 static_cast<sal_Int8>(
79 static_cast<sal_uInt8>(binaryurp::cache::ignore & 0xFF)),
80 RTL_CONSTASCII_LENGTH("[]void"), '[', ']', 'v', 'o', 'i', 'd' };
81 binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
82 try {
83 m.readType();
84 CPPUNIT_FAIL("exception expected");
85 } catch (const css::io::IOException &) {}
88 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
92 CPPUNIT_PLUGIN_IMPLEMENT();
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */