LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/rtl/crc32 - rtl_crc32.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 69 100.0 %
Date: 2012-12-27 Functions: 17 18 94.4 %
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/TestFixture.h>
      22             : #include <cppunit/extensions/HelperMacros.h>
      23             : #include <cppunit/plugin/TestPlugIn.h>
      24             : 
      25             : #include <rtl/crc.h>
      26             : 
      27             : namespace rtl_CRC32
      28             : {
      29             : 
      30          18 : class test : public CppUnit::TestFixture
      31             : {
      32             : public:
      33             :     // initialise your test code values here.
      34           6 :     void setUp()
      35             :     {
      36           6 :     }
      37             : 
      38           6 :     void tearDown()
      39             :     {
      40           6 :     }
      41             : 
      42             : 
      43             :     // insert your test code here.
      44           1 :     void rtl_crc32_001()
      45             :     {
      46             :         // this is demonstration code
      47             :         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
      48             : 
      49           1 :         sal_uInt32 nCRC = 0;
      50             : 
      51           1 :         char buf[] = {0};
      52           1 :         int num = 0;
      53             : 
      54           1 :         nCRC = rtl_crc32(nCRC, buf, num);
      55             : 
      56           1 :         CPPUNIT_ASSERT_MESSAGE("empty crc buffer", nCRC == 0);
      57           1 :     }
      58             : 
      59           1 :     void rtl_crc32_002()
      60             :     {
      61           1 :         sal_uInt32 nCRC = 0;
      62             : 
      63           1 :         char buf[] = {0,0};
      64           1 :         int num = sizeof(buf);
      65             : 
      66           1 :         nCRC = rtl_crc32(nCRC, buf, num);
      67             : 
      68           1 :         CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0);
      69           1 :     }
      70             : 
      71           1 :     void rtl_crc32_002_1()
      72             :     {
      73           1 :         sal_uInt32 nCRC = 0;
      74             : 
      75           1 :         char buf[] = {0,0,0};
      76           1 :         int num = sizeof(buf);
      77             : 
      78           1 :         nCRC = rtl_crc32(nCRC, buf, num);
      79             : 
      80           1 :         CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0);
      81           1 :     }
      82             : 
      83             :     /**
      84             :      * crc32 check:
      85             :      * Build checksum on two buffers with same size but different content,
      86             :      * the result (crc32 checksum) must differ
      87             :      */
      88             : 
      89           1 :     void rtl_crc32_003()
      90             :     {
      91           1 :         sal_uInt32 nCRC1 = 0;
      92           1 :         char buf1[] = {2};
      93           1 :         int num1 = sizeof(buf1);
      94             : 
      95           1 :         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
      96             : 
      97           1 :         sal_uInt32 nCRC2 = 0;
      98           1 :         char buf2[] = {3};
      99           1 :         int num2 = sizeof(buf2);
     100             : 
     101           1 :         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
     102             : 
     103           1 :         CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2);
     104           1 :     }
     105             : 
     106             :     /** check if the crc32 only use as much values, as given
     107             :      *
     108             :      */
     109           1 :     void rtl_crc32_003_1()
     110             :     {
     111           1 :         sal_uInt32 nCRC1 = 0;
     112           1 :         char buf1[] = {2,1};
     113           1 :         int num1 = sizeof(buf1) - 1;
     114             : 
     115           1 :         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
     116             : 
     117           1 :         sal_uInt32 nCRC2 = 0;
     118           1 :         char buf2[] = {2,2};
     119           1 :         int num2 = sizeof(buf2) - 1;
     120             : 
     121           1 :         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
     122             : 
     123           1 :         CPPUNIT_ASSERT_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2);
     124           1 :     }
     125             : 
     126             :     /** check if the crc32 differ at same content in reverse order
     127             :      *
     128             :      */
     129           1 :     void rtl_crc32_003_2()
     130             :     {
     131           1 :         sal_uInt32 nCRC1 = 0;
     132           1 :         char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
     133           1 :         int num1 = sizeof(buf1);
     134             : 
     135           1 :         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
     136             : 
     137           1 :         sal_uInt32 nCRC2 = 0;
     138           1 :         char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
     139           1 :         int num2 = sizeof(buf2);
     140             : 
     141           1 :         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
     142             : 
     143           1 :         CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2);
     144           1 :     }
     145             : 
     146             : 
     147             : 
     148             :     // Change the following lines only, if you add, remove or rename
     149             :     // member functions of the current class,
     150             :     // because these macros are need by auto register mechanism.
     151             : 
     152           2 :     CPPUNIT_TEST_SUITE(test);
     153           1 :     CPPUNIT_TEST(rtl_crc32_001);
     154           1 :     CPPUNIT_TEST(rtl_crc32_002);
     155           1 :     CPPUNIT_TEST(rtl_crc32_002_1);
     156           1 :     CPPUNIT_TEST(rtl_crc32_003);
     157           1 :     CPPUNIT_TEST(rtl_crc32_003_1);
     158           1 :     CPPUNIT_TEST(rtl_crc32_003_2);
     159           2 :     CPPUNIT_TEST_SUITE_END();
     160             : }; // class test
     161             : 
     162             : // -----------------------------------------------------------------------------
     163           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_CRC32::test);
     164             : } // namespace rtl_CRC32
     165             : 
     166             : 
     167             : // -----------------------------------------------------------------------------
     168             : 
     169             : // this macro creates an empty function, which will called by the RegisterAllFunctions()
     170             : // to let the user the possibility to also register some functions by hand.
     171           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10