Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sal/types.h>
30 : : #include "cppunit/TestAssert.h"
31 : : #include "cppunit/TestFixture.h"
32 : : #include "cppunit/extensions/HelperMacros.h"
33 : : #include "cppunit/plugin/TestPlugIn.h"
34 : : #include "rtl/byteseq.hxx"
35 : : #include "sal/types.h"
36 : :
37 : : namespace {
38 : :
39 [ - + ]: 210 : class Test: public CppUnit::TestFixture {
40 : : public:
41 : 5 : void test_default() {
42 : 5 : rtl::ByteSequence s;
43 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
[ + - ][ + - ]
[ + - ]
44 : 5 : }
45 : :
46 : 5 : void test_size0() {
47 [ + - ]: 5 : rtl::ByteSequence s(sal_Int32(0));
48 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
[ + - ][ + - ]
[ + - ]
49 : 5 : }
50 : :
51 : 5 : void test_size5() {
52 [ + - ]: 5 : rtl::ByteSequence s(5);
53 : 5 : sal_Int8 const * p = s.getConstArray();
54 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
[ + - ][ + - ]
[ + - ]
55 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]);
[ + - ][ + - ]
[ + - ]
56 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[1]);
[ + - ][ + - ]
[ + - ]
57 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[2]);
[ + - ][ + - ]
[ + - ]
58 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[3]);
[ + - ][ + - ]
[ + - ]
59 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[4]);
[ + - ][ + - ]
[ + - ]
60 : 5 : }
61 : :
62 : 5 : void test_noinit0() {
63 [ + - ]: 5 : rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT);
64 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
[ + - ][ + - ]
[ + - ]
65 : 5 : }
66 : :
67 : 5 : void test_noinit5() {
68 [ + - ]: 5 : rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT);
69 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
[ + - ][ + - ]
[ + - ]
70 : 5 : }
71 : :
72 : 5 : void test_elem0() {
73 [ + - ]: 5 : rtl::ByteSequence s(0, 0);
74 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
[ + - ][ + - ]
[ + - ]
75 : 5 : }
76 : :
77 : 5 : void test_elem5() {
78 : 5 : sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
79 [ + - ]: 5 : rtl::ByteSequence s(a, 5);
80 : 5 : sal_Int8 const * p = s.getConstArray();
81 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
[ + - ][ + - ]
[ + - ]
82 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]);
[ + - ][ + - ]
[ + - ]
83 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(1), p[1]);
[ + - ][ + - ]
[ + - ]
84 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(2), p[2]);
[ + - ][ + - ]
[ + - ]
85 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(3), p[3]);
[ + - ][ + - ]
[ + - ]
86 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(4), p[4]);
[ + - ][ + - ]
[ + - ]
87 : 5 : }
88 : :
89 : 5 : void test_copy() {
90 [ + - ]: 5 : rtl::ByteSequence s1(5);
91 : : {
92 : 5 : rtl::ByteSequence s2(s1);
93 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s2.getLength());
[ + - ][ + - ]
[ + - ]
94 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(s1.getConstArray(), s2.getConstArray());
[ + - ][ + - ]
[ + - ]
95 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(s1.getHandle(), s2.getHandle());
[ + - ][ + - ]
[ + - ]
96 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s1.getHandle()->nRefCount);
[ + - ][ + - ]
[ + - ]
97 : : }
98 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount);
[ + - ][ + - ]
[ + - ]
99 : 5 : }
100 : :
101 : 5 : void test_fromC() {
102 : 5 : sal_Sequence c = { 1, 1, { 0 } };
103 : : {
104 : 5 : rtl::ByteSequence s(&c);
105 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength());
[ + - ][ + - ]
[ + - ]
106 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL(
[ + - ][ + - ]
107 : : static_cast< void const * >(c.elements),
108 [ + - ]: 5 : static_cast< void const * >(s.getConstArray()));
109 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(&c, s.getHandle());
[ + - ][ + - ]
[ + - ]
110 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount);
[ + - ][ + - ]
[ + - ]
111 : : }
112 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount);
[ + - ][ + - ]
[ + - ]
113 : 5 : }
114 : :
115 : 5 : void test_noacquire() {
116 : 5 : sal_Sequence c = { 2, 1, { 0 } };
117 : : {
118 : 5 : rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE);
119 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength());
[ + - ][ + - ]
[ + - ]
120 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL(
[ + - ][ + - ]
121 : : static_cast< void const * >(c.elements),
122 [ + - ]: 5 : static_cast< void const * >(s.getConstArray()));
123 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(&c, s.getHandle());
[ + - ][ + - ]
[ + - ]
124 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount);
[ + - ][ + - ]
[ + - ]
125 : : }
126 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount);
[ + - ][ + - ]
[ + - ]
127 : 5 : }
128 : :
129 : 5 : void test_getArray() {
130 : 5 : sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
131 [ + - ]: 5 : rtl::ByteSequence s1(a, 5);
132 : 5 : rtl::ByteSequence s2(s1);
133 [ + - ]: 5 : sal_Int8 * p = s2.getArray();
134 : 5 : p[2] = 10;
135 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount);
[ + - ][ + - ]
[ + - ]
136 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s2.getHandle()->nRefCount);
[ + - ][ + - ]
[ + - ]
137 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(2), s1.getConstArray()[2]);
[ + - ][ + - ]
[ + - ]
138 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_Int8(10), s2.getConstArray()[2]);
[ + - ][ + - ]
[ + - ]
139 : 5 : }
140 : :
141 : 5 : void test_same0() {
142 : 5 : rtl::ByteSequence s1;
143 : 5 : rtl::ByteSequence s2;
144 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_True, s1 == s2);
[ + - ][ + - ]
[ + - ]
145 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_True, s2 == s1);
[ + - ][ + - ]
[ + - ]
146 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_False, s1 != s2);
[ + - ][ + - ]
[ + - ]
147 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_False, s2 != s1);
[ + - ][ + - ]
[ + - ]
148 : 5 : }
149 : :
150 : 5 : void test_diffLen() {
151 : 5 : sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
152 [ + - ]: 5 : rtl::ByteSequence s1(a, 5);
153 [ + - ]: 5 : rtl::ByteSequence s2(a, 4);
154 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_False, s1 == s2);
[ + - ][ + - ]
[ + - ]
155 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_False, s2 == s1);
[ + - ][ + - ]
[ + - ]
156 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_True, s1 != s2);
[ + - ][ + - ]
[ + - ]
157 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_True, s2 != s1);
[ + - ][ + - ]
[ + - ]
158 : 5 : }
159 : :
160 : 5 : void test_diffElem() {
161 : 5 : sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 };
162 [ + - ]: 5 : rtl::ByteSequence s1(a1, 5);
163 : 5 : sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 };
164 [ + - ]: 5 : rtl::ByteSequence s2(a2, 5);
165 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_False, s1 == s2);
[ + - ][ + - ]
[ + - ]
166 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_False, s2 == s1);
[ + - ][ + - ]
[ + - ]
167 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_True, s1 != s2);
[ + - ][ + - ]
[ + - ]
168 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL(sal_True, s2 != s1);
[ + - ][ + - ]
[ + - ]
169 : 5 : }
170 : :
171 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(Test);
[ + - ][ + - ]
[ # # ]
172 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_default);
[ + - ][ + - ]
[ + - ][ + - ]
173 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_size0);
[ + - ][ + - ]
[ + - ][ + - ]
174 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_size5);
[ + - ][ + - ]
[ + - ][ + - ]
175 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_noinit0);
[ + - ][ + - ]
[ + - ][ + - ]
176 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_noinit5);
[ + - ][ + - ]
[ + - ][ + - ]
177 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_elem0);
[ + - ][ + - ]
[ + - ][ + - ]
178 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_elem5);
[ + - ][ + - ]
[ + - ][ + - ]
179 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_copy);
[ + - ][ + - ]
[ + - ][ + - ]
180 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_fromC);
[ + - ][ + - ]
[ + - ][ + - ]
181 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_noacquire);
[ + - ][ + - ]
[ + - ][ + - ]
182 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_getArray);
[ + - ][ + - ]
[ + - ][ + - ]
183 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_same0);
[ + - ][ + - ]
[ + - ][ + - ]
184 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_diffLen);
[ + - ][ + - ]
[ + - ][ + - ]
185 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test_diffElem);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
186 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
187 : : };
188 : :
189 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
190 : :
191 : : }
192 : :
193 [ + - ][ + - ]: 20 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
194 : :
195 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|