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 
270ffb4d95SDamjan Jovanovic #include "gtest/gtest.h"
28cdf0e10cSrcweir #include "rtl/byteseq.hxx"
29cdf0e10cSrcweir #include "sal/types.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace {
32cdf0e10cSrcweir 
330ffb4d95SDamjan Jovanovic class Test: public ::testing::Test {
34cdf0e10cSrcweir public:
350ffb4d95SDamjan Jovanovic };
36cdf0e10cSrcweir 
TEST_F(Test,test_default)370ffb4d95SDamjan Jovanovic TEST_F(Test, test_default) {
380ffb4d95SDamjan Jovanovic     rtl::ByteSequence s;
390ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
400ffb4d95SDamjan Jovanovic }
41cdf0e10cSrcweir 
TEST_F(Test,test_size0)420ffb4d95SDamjan Jovanovic TEST_F(Test, test_size0) {
430ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(sal_Int32(0));
440ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
450ffb4d95SDamjan Jovanovic }
46cdf0e10cSrcweir 
TEST_F(Test,test_size5)470ffb4d95SDamjan Jovanovic TEST_F(Test, test_size5) {
480ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(5);
490ffb4d95SDamjan Jovanovic     sal_Int8 const * p = s.getConstArray();
500ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(5), s.getLength());
510ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[0]);
520ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[1]);
530ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[2]);
540ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[3]);
550ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[4]);
560ffb4d95SDamjan Jovanovic }
57cdf0e10cSrcweir 
TEST_F(Test,test_noinit0)580ffb4d95SDamjan Jovanovic TEST_F(Test, test_noinit0) {
590ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT);
600ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
610ffb4d95SDamjan Jovanovic }
62cdf0e10cSrcweir 
TEST_F(Test,test_noinit5)630ffb4d95SDamjan Jovanovic TEST_F(Test, test_noinit5) {
640ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT);
650ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(5), s.getLength());
660ffb4d95SDamjan Jovanovic }
67cdf0e10cSrcweir 
TEST_F(Test,test_elem0)680ffb4d95SDamjan Jovanovic TEST_F(Test, test_elem0) {
690ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(0, 0);
700ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(0), s.getLength());
710ffb4d95SDamjan Jovanovic }
72cdf0e10cSrcweir 
TEST_F(Test,test_elem5)730ffb4d95SDamjan Jovanovic TEST_F(Test, test_elem5) {
740ffb4d95SDamjan Jovanovic     sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
750ffb4d95SDamjan Jovanovic     rtl::ByteSequence s(a, 5);
760ffb4d95SDamjan Jovanovic     sal_Int8 const * p = s.getConstArray();
770ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(5), s.getLength());
780ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(0), p[0]);
790ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(1), p[1]);
800ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(2), p[2]);
810ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(3), p[3]);
820ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(4), p[4]);
830ffb4d95SDamjan Jovanovic }
84cdf0e10cSrcweir 
TEST_F(Test,test_copy)850ffb4d95SDamjan Jovanovic TEST_F(Test, test_copy) {
860ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(5);
870ffb4d95SDamjan Jovanovic     {
880ffb4d95SDamjan Jovanovic         rtl::ByteSequence s2(s1);
890ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(5), s2.getLength());
900ffb4d95SDamjan Jovanovic         ASSERT_EQ(s1.getConstArray(), s2.getConstArray());
910ffb4d95SDamjan Jovanovic         ASSERT_EQ(s1.getHandle(), s2.getHandle());
920ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(2), s1.getHandle()->nRefCount);
93cdf0e10cSrcweir     }
940ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), s1.getHandle()->nRefCount);
950ffb4d95SDamjan Jovanovic }
96cdf0e10cSrcweir 
TEST_F(Test,test_fromC)970ffb4d95SDamjan Jovanovic TEST_F(Test, test_fromC) {
980ffb4d95SDamjan Jovanovic     sal_Sequence c = { 1, 1, { 0 } };
990ffb4d95SDamjan Jovanovic     {
1000ffb4d95SDamjan Jovanovic         rtl::ByteSequence s(&c);
1010ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(1), s.getLength());
1020ffb4d95SDamjan Jovanovic         ASSERT_EQ(
1030ffb4d95SDamjan Jovanovic             static_cast< void const * >(c.elements),
1040ffb4d95SDamjan Jovanovic             static_cast< void const * >(s.getConstArray()));
1050ffb4d95SDamjan Jovanovic         ASSERT_EQ(&c, s.getHandle());
1060ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(2), c.nRefCount);
107cdf0e10cSrcweir     }
1080ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), c.nRefCount);
1090ffb4d95SDamjan Jovanovic }
110cdf0e10cSrcweir 
TEST_F(Test,test_noacquire)1110ffb4d95SDamjan Jovanovic TEST_F(Test, test_noacquire) {
1120ffb4d95SDamjan Jovanovic     sal_Sequence c = { 2, 1, { 0 } };
1130ffb4d95SDamjan Jovanovic     {
1140ffb4d95SDamjan Jovanovic         rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE);
1150ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(1), s.getLength());
1160ffb4d95SDamjan Jovanovic         ASSERT_EQ(
1170ffb4d95SDamjan Jovanovic             static_cast< void const * >(c.elements),
1180ffb4d95SDamjan Jovanovic             static_cast< void const * >(s.getConstArray()));
1190ffb4d95SDamjan Jovanovic         ASSERT_EQ(&c, s.getHandle());
1200ffb4d95SDamjan Jovanovic         ASSERT_EQ(sal_Int32(2), c.nRefCount);
121cdf0e10cSrcweir     }
1220ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), c.nRefCount);
1230ffb4d95SDamjan Jovanovic }
124cdf0e10cSrcweir 
TEST_F(Test,test_getArray)1250ffb4d95SDamjan Jovanovic TEST_F(Test, test_getArray) {
1260ffb4d95SDamjan Jovanovic     sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
1270ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(a, 5);
1280ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2(s1);
1290ffb4d95SDamjan Jovanovic     sal_Int8 * p = s2.getArray();
1300ffb4d95SDamjan Jovanovic     p[2] = 10;
1310ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), s1.getHandle()->nRefCount);
1320ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int32(1), s2.getHandle()->nRefCount);
1330ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(2), s1.getConstArray()[2]);
1340ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_Int8(10), s2.getConstArray()[2]);
1350ffb4d95SDamjan Jovanovic }
136cdf0e10cSrcweir 
TEST_F(Test,test_same0)1370ffb4d95SDamjan Jovanovic TEST_F(Test, test_same0) {
1380ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1;
1390ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2;
1400ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s1 == s2);
1410ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s2 == s1);
1420ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s1 != s2);
1430ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s2 != s1);
1440ffb4d95SDamjan Jovanovic }
145cdf0e10cSrcweir 
TEST_F(Test,test_diffLen)1460ffb4d95SDamjan Jovanovic TEST_F(Test, test_diffLen) {
1470ffb4d95SDamjan Jovanovic     sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
1480ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(a, 5);
1490ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2(a, 4);
1500ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s1 == s2);
1510ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s2 == s1);
1520ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s1 != s2);
1530ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s2 != s1);
1540ffb4d95SDamjan Jovanovic }
155cdf0e10cSrcweir 
TEST_F(Test,test_diffElem)1560ffb4d95SDamjan Jovanovic TEST_F(Test, test_diffElem) {
1570ffb4d95SDamjan Jovanovic     sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 };
1580ffb4d95SDamjan Jovanovic     rtl::ByteSequence s1(a1, 5);
1590ffb4d95SDamjan Jovanovic     sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 };
1600ffb4d95SDamjan Jovanovic     rtl::ByteSequence s2(a2, 5);
1610ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s1 == s2);
1620ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_False, s2 == s1);
1630ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s1 != s2);
1640ffb4d95SDamjan Jovanovic     ASSERT_EQ(sal_True, s2 != s1);
1650ffb4d95SDamjan Jovanovic }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
main(int argc,char ** argv)170*cb98cea0SDamjan Jovanovic int main(int argc, char **argv)
171*cb98cea0SDamjan Jovanovic {
172*cb98cea0SDamjan Jovanovic     ::testing::InitGoogleTest(&argc, argv);
173*cb98cea0SDamjan Jovanovic     return RUN_ALL_TESTS();
174*cb98cea0SDamjan Jovanovic }
175*cb98cea0SDamjan Jovanovic 
176