LCOV - code coverage report
Current view: top level - sal/qa/ByteSequence - ByteSequence.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 127 127 100.0 %
Date: 2014-11-03 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             : 
      27             : namespace {
      28             : 
      29          84 : class Test: public CppUnit::TestFixture {
      30             : public:
      31           2 :     void test_default() {
      32           2 :         rtl::ByteSequence s;
      33           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
      34           2 :     }
      35             : 
      36           2 :     void test_size0() {
      37           2 :         rtl::ByteSequence s(sal_Int32(0));
      38           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
      39           2 :     }
      40             : 
      41           2 :     void test_size5() {
      42           2 :         rtl::ByteSequence s(5);
      43           2 :         sal_Int8 const * p = s.getConstArray();
      44           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
      45           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]);
      46           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[1]);
      47           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[2]);
      48           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[3]);
      49           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[4]);
      50           2 :     }
      51             : 
      52           2 :     void test_noinit0() {
      53           2 :         rtl::ByteSequence s(0, rtl::BYTESEQ_NODEFAULT);
      54           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
      55           2 :     }
      56             : 
      57           2 :     void test_noinit5() {
      58           2 :         rtl::ByteSequence s(5, rtl::BYTESEQ_NODEFAULT);
      59           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
      60           2 :     }
      61             : 
      62           2 :     void test_elem0() {
      63           2 :         rtl::ByteSequence s(0, 0);
      64           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), s.getLength());
      65           2 :     }
      66             : 
      67           2 :     void test_elem5() {
      68           2 :         sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
      69           2 :         rtl::ByteSequence s(a, 5);
      70           2 :         sal_Int8 const * p = s.getConstArray();
      71           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
      72           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(0), p[0]);
      73           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(1), p[1]);
      74           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(2), p[2]);
      75           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(3), p[3]);
      76           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(4), p[4]);
      77           2 :     }
      78             : 
      79           2 :     void test_copy() {
      80           2 :         rtl::ByteSequence s1(5);
      81             :         {
      82           2 :             rtl::ByteSequence s2(s1);
      83           2 :             CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s2.getLength());
      84           2 :             CPPUNIT_ASSERT_EQUAL(s1.getConstArray(), s2.getConstArray());
      85           2 :             CPPUNIT_ASSERT_EQUAL(s1.getHandle(), s2.getHandle());
      86           2 :             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), s1.getHandle()->nRefCount);
      87             :         }
      88           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount);
      89           2 :     }
      90             : 
      91           2 :     void test_fromC() {
      92           2 :         sal_Sequence c = { 1, 1, { 0 } };
      93             :         {
      94           2 :             rtl::ByteSequence s(&c);
      95           2 :             CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength());
      96           4 :             CPPUNIT_ASSERT_EQUAL(
      97             :                 static_cast< void const * >(c.elements),
      98           2 :                 static_cast< void const * >(s.getConstArray()));
      99           2 :             CPPUNIT_ASSERT_EQUAL(&c, s.getHandle());
     100           2 :             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount);
     101             :         }
     102           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount);
     103           2 :     }
     104             : 
     105           2 :     void test_noacquire() {
     106           2 :         sal_Sequence c = { 2, 1, { 0 } };
     107             :         {
     108           2 :             rtl::ByteSequence s(&c, rtl::BYTESEQ_NOACQUIRE);
     109           2 :             CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s.getLength());
     110           4 :             CPPUNIT_ASSERT_EQUAL(
     111             :                 static_cast< void const * >(c.elements),
     112           2 :                 static_cast< void const * >(s.getConstArray()));
     113           2 :             CPPUNIT_ASSERT_EQUAL(&c, s.getHandle());
     114           2 :             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), c.nRefCount);
     115             :         }
     116           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(1), c.nRefCount);
     117           2 :     }
     118             : 
     119           2 :     void test_getArray() {
     120           2 :         sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
     121           2 :         rtl::ByteSequence s1(a, 5);
     122           4 :         rtl::ByteSequence s2(s1);
     123           2 :         sal_Int8 * p = s2.getArray();
     124           2 :         p[2] = 10;
     125           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s1.getHandle()->nRefCount);
     126           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(1), s2.getHandle()->nRefCount);
     127           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(2), s1.getConstArray()[2]);
     128           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int8(10), s2.getConstArray()[2]);
     129           2 :     }
     130             : 
     131           2 :     void test_same0() {
     132           2 :         rtl::ByteSequence s1;
     133           4 :         rtl::ByteSequence s2;
     134           2 :         CPPUNIT_ASSERT_EQUAL(true, s1 == s2);
     135           2 :         CPPUNIT_ASSERT_EQUAL(true, s2 == s1);
     136           2 :         CPPUNIT_ASSERT_EQUAL(false, s1 != s2);
     137           4 :         CPPUNIT_ASSERT_EQUAL(false, s2 != s1);
     138           2 :     }
     139             : 
     140           2 :     void test_diffLen() {
     141           2 :         sal_Int8 const a[5] = { 0, 1, 2, 3, 4 };
     142           2 :         rtl::ByteSequence s1(a, 5);
     143           4 :         rtl::ByteSequence s2(a, 4);
     144           2 :         CPPUNIT_ASSERT_EQUAL(false, s1 == s2);
     145           2 :         CPPUNIT_ASSERT_EQUAL(false, s2 == s1);
     146           2 :         CPPUNIT_ASSERT_EQUAL(true, s1 != s2);
     147           4 :         CPPUNIT_ASSERT_EQUAL(true, s2 != s1);
     148           2 :     }
     149             : 
     150           2 :     void test_diffElem() {
     151           2 :         sal_Int8 const a1[5] = { 0, 1, 2, 3, 4 };
     152           2 :         rtl::ByteSequence s1(a1, 5);
     153           2 :         sal_Int8 const a2[5] = { 0, 1, 10, 3, 4 };
     154           4 :         rtl::ByteSequence s2(a2, 5);
     155           2 :         CPPUNIT_ASSERT_EQUAL(false, s1 == s2);
     156           2 :         CPPUNIT_ASSERT_EQUAL(false, s2 == s1);
     157           2 :         CPPUNIT_ASSERT_EQUAL(true, s1 != s2);
     158           4 :         CPPUNIT_ASSERT_EQUAL(true, s2 != s1);
     159           2 :     }
     160             : 
     161           4 :     CPPUNIT_TEST_SUITE(Test);
     162           2 :     CPPUNIT_TEST(test_default);
     163           2 :     CPPUNIT_TEST(test_size0);
     164           2 :     CPPUNIT_TEST(test_size5);
     165           2 :     CPPUNIT_TEST(test_noinit0);
     166           2 :     CPPUNIT_TEST(test_noinit5);
     167           2 :     CPPUNIT_TEST(test_elem0);
     168           2 :     CPPUNIT_TEST(test_elem5);
     169           2 :     CPPUNIT_TEST(test_copy);
     170           2 :     CPPUNIT_TEST(test_fromC);
     171           2 :     CPPUNIT_TEST(test_noacquire);
     172           2 :     CPPUNIT_TEST(test_getArray);
     173           2 :     CPPUNIT_TEST(test_same0);
     174           2 :     CPPUNIT_TEST(test_diffLen);
     175           2 :     CPPUNIT_TEST(test_diffElem);
     176           4 :     CPPUNIT_TEST_SUITE_END();
     177             : };
     178             : 
     179           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     180             : 
     181             : }
     182             : 
     183           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10