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

Generated by: LCOV version 1.11