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