1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/types.h>
21 #include "cppunit/TestAssert.h"
22 #include "cppunit/TestFixture.h"
23 #include "cppunit/extensions/HelperMacros.h"
24 #include "cppunit/plugin/TestPlugIn.h"
25 #include "rtl/byteseq.hxx"
26 #include "sal/types.h"
30 class Test
: public CppUnit::TestFixture
{
34 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s
.getLength());
38 rtl::ByteSequence
s(sal_Int32(0));
39 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s
.getLength());
43 rtl::ByteSequence
s(5);
44 sal_Int8
const * p
= s
.getConstArray();
45 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s
.getLength());
46 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p
[0]);
47 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p
[1]);
48 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p
[2]);
49 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p
[3]);
50 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p
[4]);
54 rtl::ByteSequence
s(0, rtl::BYTESEQ_NODEFAULT
);
55 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s
.getLength());
59 rtl::ByteSequence
s(5, rtl::BYTESEQ_NODEFAULT
);
60 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s
.getLength());
64 rtl::ByteSequence
s(0, 0);
65 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s
.getLength());
69 sal_Int8
const a
[5] = { 0, 1, 2, 3, 4 };
70 rtl::ByteSequence
s(a
, 5);
71 sal_Int8
const * p
= s
.getConstArray();
72 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s
.getLength());
73 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p
[0]);
74 CPPUNIT_ASSERT_EQUAL(sal_Int8(1), p
[1]);
75 CPPUNIT_ASSERT_EQUAL(sal_Int8(2), p
[2]);
76 CPPUNIT_ASSERT_EQUAL(sal_Int8(3), p
[3]);
77 CPPUNIT_ASSERT_EQUAL(sal_Int8(4), p
[4]);
81 rtl::ByteSequence
s1(5);
83 rtl::ByteSequence
s2(s1
);
84 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s2
.getLength());
85 CPPUNIT_ASSERT_EQUAL(s1
.getConstArray(), s2
.getConstArray());
86 CPPUNIT_ASSERT_EQUAL(s1
.getHandle(), s2
.getHandle());
87 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s1
.getHandle()->nRefCount
);
89 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1
.getHandle()->nRefCount
);
93 sal_Sequence c
= { 1, 1, { 0 } };
95 rtl::ByteSequence
s(&c
);
96 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s
.getLength());
98 static_cast< void const * >(c
.elements
),
99 static_cast< void const * >(s
.getConstArray()));
100 CPPUNIT_ASSERT_EQUAL(&c
, s
.getHandle());
101 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c
.nRefCount
);
103 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c
.nRefCount
);
106 void test_noacquire() {
107 sal_Sequence c
= { 2, 1, { 0 } };
109 rtl::ByteSequence
s(&c
, rtl::BYTESEQ_NOACQUIRE
);
110 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s
.getLength());
111 CPPUNIT_ASSERT_EQUAL(
112 static_cast< void const * >(c
.elements
),
113 static_cast< void const * >(s
.getConstArray()));
114 CPPUNIT_ASSERT_EQUAL(&c
, s
.getHandle());
115 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c
.nRefCount
);
117 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c
.nRefCount
);
120 void test_getArray() {
121 sal_Int8
const a
[5] = { 0, 1, 2, 3, 4 };
122 rtl::ByteSequence
s1(a
, 5);
123 rtl::ByteSequence
s2(s1
);
124 sal_Int8
* p
= s2
.getArray();
126 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1
.getHandle()->nRefCount
);
127 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s2
.getHandle()->nRefCount
);
128 CPPUNIT_ASSERT_EQUAL(sal_Int8(2), s1
.getConstArray()[2]);
129 CPPUNIT_ASSERT_EQUAL(sal_Int8(10), s2
.getConstArray()[2]);
133 rtl::ByteSequence s1
;
134 rtl::ByteSequence s2
;
135 CPPUNIT_ASSERT_EQUAL(sal_True
, s1
== s2
);
136 CPPUNIT_ASSERT_EQUAL(sal_True
, s2
== s1
);
137 CPPUNIT_ASSERT_EQUAL(sal_False
, s1
!= s2
);
138 CPPUNIT_ASSERT_EQUAL(sal_False
, s2
!= s1
);
141 void test_diffLen() {
142 sal_Int8
const a
[5] = { 0, 1, 2, 3, 4 };
143 rtl::ByteSequence
s1(a
, 5);
144 rtl::ByteSequence
s2(a
, 4);
145 CPPUNIT_ASSERT_EQUAL(sal_False
, s1
== s2
);
146 CPPUNIT_ASSERT_EQUAL(sal_False
, s2
== s1
);
147 CPPUNIT_ASSERT_EQUAL(sal_True
, s1
!= s2
);
148 CPPUNIT_ASSERT_EQUAL(sal_True
, s2
!= s1
);
151 void test_diffElem() {
152 sal_Int8
const a1
[5] = { 0, 1, 2, 3, 4 };
153 rtl::ByteSequence
s1(a1
, 5);
154 sal_Int8
const a2
[5] = { 0, 1, 10, 3, 4 };
155 rtl::ByteSequence
s2(a2
, 5);
156 CPPUNIT_ASSERT_EQUAL(sal_False
, s1
== s2
);
157 CPPUNIT_ASSERT_EQUAL(sal_False
, s2
== s1
);
158 CPPUNIT_ASSERT_EQUAL(sal_True
, s1
!= s2
);
159 CPPUNIT_ASSERT_EQUAL(sal_True
, s2
!= s1
);
162 CPPUNIT_TEST_SUITE(Test
);
163 CPPUNIT_TEST(test_default
);
164 CPPUNIT_TEST(test_size0
);
165 CPPUNIT_TEST(test_size5
);
166 CPPUNIT_TEST(test_noinit0
);
167 CPPUNIT_TEST(test_noinit5
);
168 CPPUNIT_TEST(test_elem0
);
169 CPPUNIT_TEST(test_elem5
);
170 CPPUNIT_TEST(test_copy
);
171 CPPUNIT_TEST(test_fromC
);
172 CPPUNIT_TEST(test_noacquire
);
173 CPPUNIT_TEST(test_getArray
);
174 CPPUNIT_TEST(test_same0
);
175 CPPUNIT_TEST(test_diffLen
);
176 CPPUNIT_TEST(test_diffElem
);
177 CPPUNIT_TEST_SUITE_END();
180 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
184 CPPUNIT_PLUGIN_IMPLEMENT();
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */