187d2adbcSAndrew Rist /**************************************************************
287d2adbcSAndrew Rist  *
387d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
487d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
587d2adbcSAndrew Rist  * distributed with this work for additional information
687d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
787d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
887d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
987d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1087d2adbcSAndrew Rist  *
1187d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1287d2adbcSAndrew Rist  *
1387d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1487d2adbcSAndrew Rist  * software distributed under the License is distributed on an
1587d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1687d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
1787d2adbcSAndrew Rist  * specific language governing permissions and limitations
1887d2adbcSAndrew Rist  * under the License.
1987d2adbcSAndrew Rist  *
2087d2adbcSAndrew Rist  *************************************************************/
2187d2adbcSAndrew Rist 
2287d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sal.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27*0ffb4d95SDamjan Jovanovic #include "gtest/gtest.h"
28cdf0e10cSrcweir #include "rtl/byteseq.hxx"
29cdf0e10cSrcweir #include "sal/types.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace {
32cdf0e10cSrcweir 
33*0ffb4d95SDamjan Jovanovic class Test: public ::testing::Test {
34cdf0e10cSrcweir public:
35*0ffb4d95SDamjan Jovanovic };
36cdf0e10cSrcweir 
37*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_default) {
38*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s;
39*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
40*0ffb4d95SDamjan Jovanovic }
41cdf0e10cSrcweir 
42*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_size0) {
43*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(sal_Int32(0));
44*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
45*0ffb4d95SDamjan Jovanovic }
46cdf0e10cSrcweir 
47*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_size5) {
48*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(5);
49*0ffb4d95SDamjan Jovanovic     sal_Int8 const * p = s.getConstArray();
50*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(5), s.getLength());
51*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[0]);
52*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[1]);
53*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[2]);
54*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[3]);
55*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[4]);
56*0ffb4d95SDamjan Jovanovic }
57cdf0e10cSrcweir 
58*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_noinit0) {
59*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT);
60*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
61*0ffb4d95SDamjan Jovanovic }
62cdf0e10cSrcweir 
63*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_noinit5) {
64*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT);
65*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(5), s.getLength());
66*0ffb4d95SDamjan Jovanovic }
67cdf0e10cSrcweir 
68*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_elem0) {
69*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(0, 0);
70*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
71*0ffb4d95SDamjan Jovanovic }
72cdf0e10cSrcweir 
73*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_elem5) {
74*0ffb4d95SDamjan Jovanovic     sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
75*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(a, 5);
76*0ffb4d95SDamjan Jovanovic     sal_Int8 const * p = s.getConstArray();
77*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(5), s.getLength());
78*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[0]);
79*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(1), p[1]);
80*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(2), p[2]);
81*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(3), p[3]);
82*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(4), p[4]);
83*0ffb4d95SDamjan Jovanovic }
84cdf0e10cSrcweir 
85*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_copy) {
86*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(5);
87*0ffb4d95SDamjan Jovanovic     {
88*0ffb4d95SDamjan Jovanovic         rtl::ByteSequence s2(s1);
89*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(5), s2.getLength());
90*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(s1.getConstArray(), s2.getConstArray());
91*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(s1.getHandle(), s2.getHandle());
92*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(2), s1.getHandle()->nRefCount);
93cdf0e10cSrcweir     }
94*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), s1.getHandle()->nRefCount);
95*0ffb4d95SDamjan Jovanovic }
96cdf0e10cSrcweir 
97*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_fromC) {
98*0ffb4d95SDamjan Jovanovic     sal_Sequence c = { 1, 1, { 0 } };
99*0ffb4d95SDamjan Jovanovic     {
100*0ffb4d95SDamjan Jovanovic         rtl::ByteSequence s(&c);
101*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(1), s.getLength());
102*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(
103*0ffb4d95SDamjan Jovanovic             static_cast< void const * >(c.elements),
104*0ffb4d95SDamjan Jovanovic             static_cast< void const * >(s.getConstArray()));
105*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(&c, s.getHandle());
106*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(2), c.nRefCount);
107cdf0e10cSrcweir     }
108*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), c.nRefCount);
109*0ffb4d95SDamjan Jovanovic }
110cdf0e10cSrcweir 
111*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_noacquire) {
112*0ffb4d95SDamjan Jovanovic     sal_Sequence c = { 2, 1, { 0 } };
113*0ffb4d95SDamjan Jovanovic     {
114*0ffb4d95SDamjan Jovanovic         rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE);
115*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(1), s.getLength());
116*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(
117*0ffb4d95SDamjan Jovanovic             static_cast< void const * >(c.elements),
118*0ffb4d95SDamjan Jovanovic             static_cast< void const * >(s.getConstArray()));
119*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(&c, s.getHandle());
120*0ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(2), c.nRefCount);
121cdf0e10cSrcweir     }
122*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), c.nRefCount);
123*0ffb4d95SDamjan Jovanovic }
124cdf0e10cSrcweir 
125*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_getArray) {
126*0ffb4d95SDamjan Jovanovic     sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
127*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(a, 5);
128*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2(s1);
129*0ffb4d95SDamjan Jovanovic     sal_Int8 * p = s2.getArray();
130*0ffb4d95SDamjan Jovanovic     p[2] = 10;
131*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), s1.getHandle()->nRefCount);
132*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), s2.getHandle()->nRefCount);
133*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(2), s1.getConstArray()[2]);
134*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(10), s2.getConstArray()[2]);
135*0ffb4d95SDamjan Jovanovic }
136cdf0e10cSrcweir 
137*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_same0) {
138*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1;
139*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2;
140*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s1 == s2);
141*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s2 == s1);
142*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s1 != s2);
143*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s2 != s1);
144*0ffb4d95SDamjan Jovanovic }
145cdf0e10cSrcweir 
146*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_diffLen) {
147*0ffb4d95SDamjan Jovanovic     sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
148*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(a, 5);
149*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2(a, 4);
150*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s1 == s2);
151*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s2 == s1);
152*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s1 != s2);
153*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s2 != s1);
154*0ffb4d95SDamjan Jovanovic }
155cdf0e10cSrcweir 
156*0ffb4d95SDamjan Jovanovic TEST_F(Test, test_diffElem) {
157*0ffb4d95SDamjan Jovanovic     sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 };
158*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(a1, 5);
159*0ffb4d95SDamjan Jovanovic     sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 };
160*0ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2(a2, 5);
161*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s1 == s2);
162*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s2 == s1);
163*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s1 != s2);
164*0ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s2 != s1);
165*0ffb4d95SDamjan Jovanovic }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170