LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/ByteSequence - ByteSequence.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 127 127 100.0 %
Date: 2012-12-27 Functions: 23 24 95.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10