ByteSequence.cxx (87d2adbc) ByteSequence.cxx (0ffb4d95)
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

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23
24#include "precompiled_sal.hxx"
25#include "sal/config.h"
26
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

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23
24#include "precompiled_sal.hxx"
25#include "sal/config.h"
26
27#include "cppunit/TestAssert.h"
28#include "cppunit/TestFixture.h"
29#include "cppunit/extensions/HelperMacros.h"
30#include "cppunit/plugin/TestPlugIn.h"
27#include "gtest/gtest.h"
31#include "rtl/byteseq.hxx"
32#include "sal/types.h"
33
34namespace {
35
28#include "rtl/byteseq.hxx"
29#include "sal/types.h"
30
31namespace {
32
36class Test: public CppUnit::TestFixture {
33class Test: public ::testing::Test {
37public:
34public:
38 void test_default() {
39 rtl::ByteSequence s;
40 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
41 }
35};
42
36
43 void test_size0() {
44 rtl::ByteSequence s(sal_Int32(0));
45 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
46 }
37TEST_F(Test, test_default) {
38 rtl::ByteSequence s;
39 ASSERT_EQ(sal_Int32(0), s.getLength());
40}
47
41
48 void test_size5() {
49 rtl::ByteSequence s(5);
50 sal_Int8 const * p = s.getConstArray();
51 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
52 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]);
53 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[1]);
54 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[2]);
55 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[3]);
56 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[4]);
57 }
42TEST_F(Test, test_size0) {
43 rtl::ByteSequence s(sal_Int32(0));
44 ASSERT_EQ(sal_Int32(0), s.getLength());
45}
58
46
59 void test_noinit0() {
60 rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT);
61 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
62 }
47TEST_F(Test, test_size5) {
48 rtl::ByteSequence s(5);
49 sal_Int8 const * p = s.getConstArray();
50 ASSERT_EQ(sal_Int32(5), s.getLength());
51 ASSERT_EQ(sal_Int8(0), p[0]);
52 ASSERT_EQ(sal_Int8(0), p[1]);
53 ASSERT_EQ(sal_Int8(0), p[2]);
54 ASSERT_EQ(sal_Int8(0), p[3]);
55 ASSERT_EQ(sal_Int8(0), p[4]);
56}
63
57
64 void test_noinit5() {
65 rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT);
66 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
67 }
58TEST_F(Test, test_noinit0) {
59 rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT);
60 ASSERT_EQ(sal_Int32(0), s.getLength());
61}
68
62
69 void test_elem0() {
70 rtl::ByteSequence s(0, 0);
71 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
72 }
63TEST_F(Test, test_noinit5) {
64 rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT);
65 ASSERT_EQ(sal_Int32(5), s.getLength());
66}
73
67
74 void test_elem5() {
75 sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
76 rtl::ByteSequence s(a, 5);
77 sal_Int8 const * p = s.getConstArray();
78 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
79 CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]);
80 CPPUNIT_ASSERT_EQUAL(sal_Int8(1), p[1]);
81 CPPUNIT_ASSERT_EQUAL(sal_Int8(2), p[2]);
82 CPPUNIT_ASSERT_EQUAL(sal_Int8(3), p[3]);
83 CPPUNIT_ASSERT_EQUAL(sal_Int8(4), p[4]);
84 }
68TEST_F(Test, test_elem0) {
69 rtl::ByteSequence s(0, 0);
70 ASSERT_EQ(sal_Int32(0), s.getLength());
71}
85
72
86 void test_copy() {
87 rtl::ByteSequence s1(5);
88 {
89 rtl::ByteSequence s2(s1);
90 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s2.getLength());
91 CPPUNIT_ASSERT_EQUAL(s1.getConstArray(), s2.getConstArray());
92 CPPUNIT_ASSERT_EQUAL(s1.getHandle(), s2.getHandle());
93 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s1.getHandle()->nRefCount);
94 }
95 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount);
96 }
73TEST_F(Test, test_elem5) {
74 sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
75 rtl::ByteSequence s(a, 5);
76 sal_Int8 const * p = s.getConstArray();
77 ASSERT_EQ(sal_Int32(5), s.getLength());
78 ASSERT_EQ(sal_Int8(0), p[0]);
79 ASSERT_EQ(sal_Int8(1), p[1]);
80 ASSERT_EQ(sal_Int8(2), p[2]);
81 ASSERT_EQ(sal_Int8(3), p[3]);
82 ASSERT_EQ(sal_Int8(4), p[4]);
83}
97
84
98 void test_fromC() {
99 sal_Sequence c = { 1, 1, { 0 } };
100 {
101 rtl::ByteSequence s(&c);
102 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength());
103 CPPUNIT_ASSERT_EQUAL(
104 static_cast< void const * >(c.elements),
105 static_cast< void const * >(s.getConstArray()));
106 CPPUNIT_ASSERT_EQUAL(&c, s.getHandle());
107 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount);
108 }
109 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount);
85TEST_F(Test, test_copy) {
86 rtl::ByteSequence s1(5);
87 {
88 rtl::ByteSequence s2(s1);
89 ASSERT_EQ(sal_Int32(5), s2.getLength());
90 ASSERT_EQ(s1.getConstArray(), s2.getConstArray());
91 ASSERT_EQ(s1.getHandle(), s2.getHandle());
92 ASSERT_EQ(sal_Int32(2), s1.getHandle()->nRefCount);
110 }
93 }
94 ASSERT_EQ(sal_Int32(1), s1.getHandle()->nRefCount);
95}
111
96
112 void test_noacquire() {
113 sal_Sequence c = { 2, 1, { 0 } };
114 {
115 rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE);
116 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength());
117 CPPUNIT_ASSERT_EQUAL(
118 static_cast< void const * >(c.elements),
119 static_cast< void const * >(s.getConstArray()));
120 CPPUNIT_ASSERT_EQUAL(&c, s.getHandle());
121 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount);
122 }
123 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount);
97TEST_F(Test, test_fromC) {
98 sal_Sequence c = { 1, 1, { 0 } };
99 {
100 rtl::ByteSequence s(&c);
101 ASSERT_EQ(sal_Int32(1), s.getLength());
102 ASSERT_EQ(
103 static_cast< void const * >(c.elements),
104 static_cast< void const * >(s.getConstArray()));
105 ASSERT_EQ(&c, s.getHandle());
106 ASSERT_EQ(sal_Int32(2), c.nRefCount);
124 }
107 }
108 ASSERT_EQ(sal_Int32(1), c.nRefCount);
109}
125
110
126 void test_getArray() {
127 sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
128 rtl::ByteSequence s1(a, 5);
129 rtl::ByteSequence s2(s1);
130 sal_Int8 * p = s2.getArray();
131 p[2] = 10;
132 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount);
133 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s2.getHandle()->nRefCount);
134 CPPUNIT_ASSERT_EQUAL(sal_Int8(2), s1.getConstArray()[2]);
135 CPPUNIT_ASSERT_EQUAL(sal_Int8(10), s2.getConstArray()[2]);
111TEST_F(Test, test_noacquire) {
112 sal_Sequence c = { 2, 1, { 0 } };
113 {
114 rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE);
115 ASSERT_EQ(sal_Int32(1), s.getLength());
116 ASSERT_EQ(
117 static_cast< void const * >(c.elements),
118 static_cast< void const * >(s.getConstArray()));
119 ASSERT_EQ(&c, s.getHandle());
120 ASSERT_EQ(sal_Int32(2), c.nRefCount);
136 }
121 }
122 ASSERT_EQ(sal_Int32(1), c.nRefCount);
123}
137
124
138 void test_same0() {
139 rtl::ByteSequence s1;
140 rtl::ByteSequence s2;
141 CPPUNIT_ASSERT_EQUAL(sal_True, s1 == s2);
142 CPPUNIT_ASSERT_EQUAL(sal_True, s2 == s1);
143 CPPUNIT_ASSERT_EQUAL(sal_False, s1 != s2);
144 CPPUNIT_ASSERT_EQUAL(sal_False, s2 != s1);
145 }
125TEST_F(Test, test_getArray) {
126 sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
127 rtl::ByteSequence s1(a, 5);
128 rtl::ByteSequence s2(s1);
129 sal_Int8 * p = s2.getArray();
130 p[2] = 10;
131 ASSERT_EQ(sal_Int32(1), s1.getHandle()->nRefCount);
132 ASSERT_EQ(sal_Int32(1), s2.getHandle()->nRefCount);
133 ASSERT_EQ(sal_Int8(2), s1.getConstArray()[2]);
134 ASSERT_EQ(sal_Int8(10), s2.getConstArray()[2]);
135}
146
136
147 void test_diffLen() {
148 sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
149 rtl::ByteSequence s1(a, 5);
150 rtl::ByteSequence s2(a, 4);
151 CPPUNIT_ASSERT_EQUAL(sal_False, s1 == s2);
152 CPPUNIT_ASSERT_EQUAL(sal_False, s2 == s1);
153 CPPUNIT_ASSERT_EQUAL(sal_True, s1 != s2);
154 CPPUNIT_ASSERT_EQUAL(sal_True, s2 != s1);
155 }
137TEST_F(Test, test_same0) {
138 rtl::ByteSequence s1;
139 rtl::ByteSequence s2;
140 ASSERT_EQ(sal_True, s1 == s2);
141 ASSERT_EQ(sal_True, s2 == s1);
142 ASSERT_EQ(sal_False, s1 != s2);
143 ASSERT_EQ(sal_False, s2 != s1);
144}
156
145
157 void test_diffElem() {
158 sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 };
159 rtl::ByteSequence s1(a1, 5);
160 sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 };
161 rtl::ByteSequence s2(a2, 5);
162 CPPUNIT_ASSERT_EQUAL(sal_False, s1 == s2);
163 CPPUNIT_ASSERT_EQUAL(sal_False, s2 == s1);
164 CPPUNIT_ASSERT_EQUAL(sal_True, s1 != s2);
165 CPPUNIT_ASSERT_EQUAL(sal_True, s2 != s1);
166 }
146TEST_F(Test, test_diffLen) {
147 sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
148 rtl::ByteSequence s1(a, 5);
149 rtl::ByteSequence s2(a, 4);
150 ASSERT_EQ(sal_False, s1 == s2);
151 ASSERT_EQ(sal_False, s2 == s1);
152 ASSERT_EQ(sal_True, s1 != s2);
153 ASSERT_EQ(sal_True, s2 != s1);
154}
167
155
168 CPPUNIT_TEST_SUITE(Test);
169 CPPUNIT_TEST(test_default);
170 CPPUNIT_TEST(test_size0);
171 CPPUNIT_TEST(test_size5);
172 CPPUNIT_TEST(test_noinit0);
173 CPPUNIT_TEST(test_noinit5);
174 CPPUNIT_TEST(test_elem0);
175 CPPUNIT_TEST(test_elem5);
176 CPPUNIT_TEST(test_copy);
177 CPPUNIT_TEST(test_fromC);
178 CPPUNIT_TEST(test_noacquire);
179 CPPUNIT_TEST(test_getArray);
180 CPPUNIT_TEST(test_same0);
181 CPPUNIT_TEST(test_diffLen);
182 CPPUNIT_TEST(test_diffElem);
183 CPPUNIT_TEST_SUITE_END();
184};
156TEST_F(Test, test_diffElem) {
157 sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 };
158 rtl::ByteSequence s1(a1, 5);
159 sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 };
160 rtl::ByteSequence s2(a2, 5);
161 ASSERT_EQ(sal_False, s1 == s2);
162 ASSERT_EQ(sal_False, s2 == s1);
163 ASSERT_EQ(sal_True, s1 != s2);
164 ASSERT_EQ(sal_True, s2 != s1);
165}
185
166
186CPPUNIT_TEST_SUITE_REGISTRATION(Test);
187
188}
189
167
168}
169
190CPPUNIT_PLUGIN_IMPLEMENT();