LCOV - code coverage report
Current view: top level - sal/qa/rtl/cipher - rtl_cipher.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 359 359 100.0 %
Date: 2014-11-03 Functions: 110 111 99.1 %
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 <cstring>
      21             : 
      22             : #include <sal/types.h>
      23             : #include <cppunit/TestFixture.h>
      24             : #include <cppunit/extensions/HelperMacros.h>
      25             : #include <cppunit/plugin/TestPlugIn.h>
      26             : 
      27             : #include <rtl/strbuf.hxx>
      28             : #include <rtl/cipher.h>
      29             : 
      30             : namespace rtl_cipher
      31             : {
      32             : 
      33          48 : class create : public CppUnit::TestFixture
      34             : {
      35             : public:
      36             :     // initialise your test code values here.
      37          16 :     void setUp() SAL_OVERRIDE
      38             :     {
      39          16 :     }
      40             : 
      41          16 :     void tearDown() SAL_OVERRIDE
      42             :     {
      43          16 :     }
      44             : 
      45           2 :     void create_001()
      46             :         {
      47           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
      48           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
      49           2 :             rtl_cipher_destroy(aCipher);
      50           2 :         }
      51           2 :     void create_002()
      52             :         {
      53           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB);
      54           2 :             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
      55           2 :         }
      56           2 :     void create_003()
      57             :         {
      58           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
      59           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
      60           2 :             rtl_cipher_destroy(aCipher);
      61           2 :         }
      62           2 :     void create_004()
      63             :         {
      64           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC);
      65           2 :             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
      66           2 :         }
      67           2 :     void create_005()
      68             :         {
      69           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
      70           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
      71           2 :             rtl_cipher_destroy(aCipher);
      72           2 :         }
      73           2 :     void create_006()
      74             :         {
      75           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream);
      76           2 :             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
      77           2 :         }
      78           2 :     void create_007()
      79             :         {
      80           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid);
      81           2 :             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
      82           2 :         }
      83           2 :     void create_008()
      84             :         {
      85           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid);
      86           2 :             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
      87           2 :         }
      88             : 
      89             :     // Change the following lines only, if you add, remove or rename
      90             :     // member functions of the current class,
      91             :     // because these macros are need by auto register mechanism.
      92             : 
      93           4 :     CPPUNIT_TEST_SUITE(create);
      94           2 :     CPPUNIT_TEST(create_001);
      95           2 :     CPPUNIT_TEST(create_002);
      96           2 :     CPPUNIT_TEST(create_003);
      97           2 :     CPPUNIT_TEST(create_004);
      98           2 :     CPPUNIT_TEST(create_005);
      99           2 :     CPPUNIT_TEST(create_006);
     100           2 :     CPPUNIT_TEST(create_007);
     101           2 :     CPPUNIT_TEST(create_008);
     102           4 :     CPPUNIT_TEST_SUITE_END();
     103             : }; // class create
     104             : 
     105          24 : class createBF : public CppUnit::TestFixture
     106             : {
     107             : public:
     108             :     // initialise your test code values here.
     109           8 :     void setUp() SAL_OVERRIDE
     110             :     {
     111           8 :     }
     112             : 
     113           8 :     void tearDown() SAL_OVERRIDE
     114             :     {
     115           8 :     }
     116             : 
     117           2 :     void createBF_001()
     118             :         {
     119           2 :             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
     120           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     121           2 :             rtl_cipher_destroy(aCipher);
     122           2 :         }
     123           2 :     void createBF_002()
     124             :         {
     125           2 :             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC);
     126           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     127           2 :             rtl_cipher_destroy(aCipher);
     128           2 :         }
     129           2 :     void createBF_003()
     130             :         {
     131           2 :             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream);
     132           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     133           2 :             rtl_cipher_destroy(aCipher);
     134           2 :         }
     135           2 :     void createBF_004()
     136             :         {
     137           2 :             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid);
     138           2 :             CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
     139             :             // rtl_cipher_destroy(aCipher);
     140           2 :         }
     141             :     // Change the following lines only, if you add, remove or rename
     142             :     // member functions of the current class,
     143             :     // because these macros are need by auto register mechanism.
     144             : 
     145           4 :     CPPUNIT_TEST_SUITE(createBF);
     146           2 :     CPPUNIT_TEST(createBF_001);
     147           2 :     CPPUNIT_TEST(createBF_002);
     148           2 :     CPPUNIT_TEST(createBF_003);
     149           2 :     CPPUNIT_TEST(createBF_004);
     150           4 :     CPPUNIT_TEST_SUITE_END();
     151             : }; // class createBF
     152             : 
     153          12 : class decode : public CppUnit::TestFixture
     154             : {
     155             : public:
     156             :     // initialise your test code values here.
     157           4 :     void setUp() SAL_OVERRIDE
     158             :     {
     159           4 :     }
     160             : 
     161           4 :     void tearDown() SAL_OVERRIDE
     162             :     {
     163           4 :     }
     164             : 
     165           8 :     void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
     166             :         {
     167           8 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     168           8 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     169             : 
     170           8 :             sal_uInt32     nKeyLen = 16;
     171           8 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     172           8 :             memset(pKeyBuffer, 0, nKeyLen);
     173           8 :             pKeyBuffer[0] = _nKeyValue;
     174             : 
     175           8 :             sal_uInt32     nArgLen = 16;
     176           8 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     177           8 :             memset(pArgBuffer, 0, nArgLen);
     178           8 :             pArgBuffer[0] = _nArgValue;
     179             : 
     180           8 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     181           8 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     182             : 
     183           8 :             sal_uInt32     nPlainTextLen = 16;
     184           8 :             sal_uInt8     *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
     185           8 :             memset(pPlainTextBuffer, 0, nPlainTextLen);
     186           8 :             strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
     187             : 
     188           8 :             sal_uInt32     nCipherLen = 16;
     189           8 :             sal_uInt8     *pCipherBuffer = new sal_uInt8[ nCipherLen ];
     190           8 :             memset(pCipherBuffer, 0, nCipherLen);
     191             : 
     192           8 :             /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
     193           8 :             CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
     194             : 
     195           8 :             sal_uInt32     nPlainText2Len = 16;
     196           8 :             sal_uInt8     *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
     197           8 :             memset(pPlainText2Buffer, 0, nPlainText2Len);
     198             : 
     199           8 :             /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
     200           8 :             CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None);
     201             : 
     202           8 :             delete [] pPlainText2Buffer;
     203             : 
     204           8 :             delete [] pCipherBuffer;
     205           8 :             delete [] pPlainTextBuffer;
     206             : 
     207           8 :             delete [] pArgBuffer;
     208           8 :             delete [] pKeyBuffer;
     209             : 
     210           8 :             rtl_cipher_destroy(aCipher);
     211           8 :         }
     212             : 
     213           8 :     void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
     214             :         {
     215           8 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     216           8 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     217             : 
     218           8 :             sal_uInt32     nKeyLen = 16;
     219           8 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     220           8 :             memset(pKeyBuffer, 0, nKeyLen);
     221           8 :             pKeyBuffer[0] = _nKeyValue;
     222             : 
     223           8 :             sal_uInt32     nArgLen = 16;
     224           8 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     225           8 :             memset(pArgBuffer, 0, nArgLen);
     226           8 :             pArgBuffer[0] = _nArgValue;
     227             : 
     228           8 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     229           8 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     230             : 
     231           8 :             sal_uInt32     nPlainTextLen = 16;
     232           8 :             sal_uInt8     *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
     233           8 :             memset(pPlainTextBuffer, 0, nPlainTextLen);
     234           8 :             strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
     235             : 
     236           8 :             sal_uInt32     nCipherLen = 16;
     237           8 :             sal_uInt8     *pCipherBuffer = new sal_uInt8[ nCipherLen ];
     238           8 :             memset(pCipherBuffer, 0, nCipherLen);
     239             : 
     240           8 :             /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
     241           8 :             CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
     242             : 
     243           8 :             sal_uInt32     nPlainText2Len = 16;
     244           8 :             sal_uInt8     *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
     245           8 :             memset(pPlainText2Buffer, 0, nPlainText2Len);
     246             : 
     247           8 :             /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
     248           8 :             CPPUNIT_ASSERT_MESSAGE("wrong decode", aError == rtl_Cipher_E_None);
     249             : 
     250           8 :             sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
     251             : 
     252           8 :             CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
     253             : 
     254           8 :             delete [] pPlainText2Buffer;
     255             : 
     256           8 :             delete [] pCipherBuffer;
     257           8 :             delete [] pPlainTextBuffer;
     258             : 
     259           8 :             delete [] pArgBuffer;
     260           8 :             delete [] pKeyBuffer;
     261             : 
     262           8 :             rtl_cipher_destroy(aCipher);
     263           8 :         }
     264             : 
     265           2 :     void decode_001()
     266             :         {
     267           2 :             test_encode_and_decode(0,0,"");
     268           2 :             test_encode_and_decode(0,0,"hallo");
     269           2 :             test_encode_and_decode(1,0,"B2Aahg5B");
     270           2 :             test_encode_and_decode(1,2,"Longer text string");
     271           2 :         }
     272             : 
     273           2 :     void decode_002()
     274             :         {
     275           2 :             test_encode(0,0,"");
     276           2 :             test_encode(0,0,"hallo");
     277           2 :             test_encode(1,0,"B2Aahg5B");
     278           2 :             test_encode(1,2,"Longer text string");
     279           2 :         }
     280             :     // Change the following lines only, if you add, remove or rename
     281             :     // member functions of the current class,
     282             :     // because these macros are need by auto register mechanism.
     283             : 
     284           4 :     CPPUNIT_TEST_SUITE(decode);
     285           2 :     CPPUNIT_TEST(decode_001);
     286           2 :     CPPUNIT_TEST(decode_002);
     287           4 :     CPPUNIT_TEST_SUITE_END();
     288             : }; // class decode
     289             : 
     290           6 : class decodeBF : public CppUnit::TestFixture
     291             : {
     292             : public:
     293             :     // initialise your test code values here.
     294           2 :     void setUp() SAL_OVERRIDE
     295             :     {
     296           2 :     }
     297             : 
     298           2 :     void tearDown() SAL_OVERRIDE
     299             :     {
     300           2 :     }
     301             : 
     302           2 :     void decodeBF_001()
     303             :         {
     304           2 :         }
     305             :     // Change the following lines only, if you add, remove or rename
     306             :     // member functions of the current class,
     307             :     // because these macros are need by auto register mechanism.
     308             : 
     309           4 :     CPPUNIT_TEST_SUITE(decodeBF);
     310           2 :     CPPUNIT_TEST(decodeBF_001);
     311           4 :     CPPUNIT_TEST_SUITE_END();
     312             : }; // class decodeBF
     313             : 
     314           6 : class destroy : public CppUnit::TestFixture
     315             : {
     316             : public:
     317             :     // initialise your test code values here.
     318           2 :     void setUp() SAL_OVERRIDE
     319             :     {
     320           2 :     }
     321             : 
     322           2 :     void tearDown() SAL_OVERRIDE
     323             :     {
     324           2 :     }
     325             : 
     326           2 :     void destroy_001()
     327             :         {
     328           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
     329           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     330           2 :             rtl_cipher_destroy(aCipher);
     331           2 :         }
     332             :     // Change the following lines only, if you add, remove or rename
     333             :     // member functions of the current class,
     334             :     // because these macros are need by auto register mechanism.
     335             : 
     336           4 :     CPPUNIT_TEST_SUITE(destroy);
     337           2 :     CPPUNIT_TEST(destroy_001);
     338           4 :     CPPUNIT_TEST_SUITE_END();
     339             : }; // class destroy
     340             : 
     341           6 : class destroyBF : public CppUnit::TestFixture
     342             : {
     343             : public:
     344             :     // initialise your test code values here.
     345           2 :     void setUp() SAL_OVERRIDE
     346             :     {
     347           2 :     }
     348             : 
     349           2 :     void tearDown() SAL_OVERRIDE
     350             :     {
     351           2 :     }
     352             : 
     353           2 :     void destroyBF_001()
     354             :         {
     355           2 :             rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
     356           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     357           2 :             rtl_cipher_destroyBF(aCipher);
     358             :             // more proforma
     359             :             // should not GPF
     360           2 :         }
     361             :     // Change the following lines only, if you add, remove or rename
     362             :     // member functions of the current class,
     363             :     // because these macros are need by auto register mechanism.
     364             : 
     365           4 :     CPPUNIT_TEST_SUITE(destroyBF);
     366           2 :     CPPUNIT_TEST(destroyBF_001);
     367           4 :     CPPUNIT_TEST_SUITE_END();
     368             : }; // class destroyBF
     369             : 
     370           6 : class encode : public CppUnit::TestFixture
     371             : {
     372             : public:
     373             :     // initialise your test code values here.
     374           2 :     void setUp() SAL_OVERRIDE
     375             :     {
     376           2 :     }
     377             : 
     378           2 :     void tearDown() SAL_OVERRIDE
     379             :     {
     380           2 :     }
     381             : 
     382          16 :     void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue)
     383             :         {
     384          16 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     385          16 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     386             : 
     387          16 :             sal_uInt32     nKeyLen = 16;
     388          16 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     389          16 :             memset(pKeyBuffer, 0, nKeyLen);
     390          16 :             pKeyBuffer[0] = _nKeyValue;
     391             : 
     392          16 :             sal_uInt32     nArgLen = 16;
     393          16 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     394          16 :             memset(pArgBuffer, 0, nArgLen);
     395          16 :             pArgBuffer[0] = _nArgValue;
     396             : 
     397          16 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     398          16 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     399             : 
     400          16 :             sal_uInt32     nDataLen = 16;
     401          16 :             sal_uInt8     *pDataBuffer = new sal_uInt8[ nDataLen ];
     402          16 :             memset(pDataBuffer, 0, nDataLen);
     403          16 :             pDataBuffer[0] = _nDataValue;
     404             : 
     405          16 :             sal_uInt32     nLen = 16;
     406          16 :             sal_uInt8     *pBuffer = new sal_uInt8[ nLen ];
     407          16 :             memset(pBuffer, 0, nLen);
     408             : 
     409          16 :             /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen);
     410          16 :             CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
     411             : 
     412          16 :             delete [] pBuffer;
     413          16 :             delete [] pDataBuffer;
     414             : 
     415          16 :             delete [] pArgBuffer;
     416          16 :             delete [] pKeyBuffer;
     417             : 
     418          16 :             rtl_cipher_destroy(aCipher);
     419          16 :         }
     420             : 
     421           2 :     void encode_001()
     422             :         {
     423           2 :             test_encode(0,0,0);
     424           2 :             test_encode(1,0,0);
     425           2 :             test_encode(0,1,0);
     426           2 :             test_encode(1,1,0);
     427             : 
     428           2 :             test_encode(0,0,1);
     429           2 :             test_encode(1,0,1);
     430           2 :             test_encode(0,1,1);
     431           2 :             test_encode(1,1,1);
     432           2 :         }
     433             : 
     434             :     // Change the following lines only, if you add, remove or rename
     435             :     // member functions of the current class,
     436             :     // because these macros are need by auto register mechanism.
     437             : 
     438           4 :     CPPUNIT_TEST_SUITE(encode);
     439           2 :     CPPUNIT_TEST(encode_001);
     440           4 :     CPPUNIT_TEST_SUITE_END();
     441             : }; // class encode
     442             : 
     443           6 : class encodeBF : public CppUnit::TestFixture
     444             : {
     445             : public:
     446             :     // initialise your test code values here.
     447           2 :     void setUp() SAL_OVERRIDE
     448             :     {
     449           2 :     }
     450             : 
     451           2 :     void tearDown() SAL_OVERRIDE
     452             :     {
     453           2 :     }
     454             : 
     455           2 :     void encodeBF_001()
     456             :         {
     457           2 :         }
     458             :     // Change the following lines only, if you add, remove or rename
     459             :     // member functions of the current class,
     460             :     // because these macros are need by auto register mechanism.
     461             : 
     462           4 :     CPPUNIT_TEST_SUITE(encodeBF);
     463           2 :     CPPUNIT_TEST(encodeBF_001);
     464           4 :     CPPUNIT_TEST_SUITE_END();
     465             : }; // class encodeBF
     466             : 
     467          24 : class init : public CppUnit::TestFixture
     468             : {
     469             : public:
     470             :     // initialise your test code values here.
     471           8 :     void setUp() SAL_OVERRIDE
     472             :     {
     473           8 :     }
     474             : 
     475           8 :     void tearDown() SAL_OVERRIDE
     476             :     {
     477           8 :     }
     478             : 
     479           2 :     void init_001()
     480             :         {
     481           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     482           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     483             : 
     484           2 :             sal_uInt32     nKeyLen = 16;
     485           2 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     486           2 :             memset(pKeyBuffer, 0, nKeyLen);
     487             : 
     488           2 :             sal_uInt32     nArgLen = 16;
     489           2 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     490           2 :             memset(pArgBuffer, 0, nArgLen);
     491             : 
     492           2 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     493           2 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     494             : 
     495           2 :             delete [] pArgBuffer;
     496           2 :             delete [] pKeyBuffer;
     497             : 
     498           2 :             rtl_cipher_destroy(aCipher);
     499           2 :         }
     500             : 
     501           2 :     void init_002()
     502             :         {
     503           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     504           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     505             : 
     506           2 :             sal_uInt32     nKeyLen = 16;
     507           2 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     508           2 :             memset(pKeyBuffer, 0, nKeyLen);
     509           2 :             pKeyBuffer[0] = 1;
     510             : 
     511           2 :             sal_uInt32     nArgLen = 16;
     512           2 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     513           2 :             memset(pArgBuffer, 0, nArgLen);
     514             : 
     515           2 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     516           2 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     517             : 
     518           2 :             delete [] pArgBuffer;
     519           2 :             delete [] pKeyBuffer;
     520             : 
     521           2 :             rtl_cipher_destroy(aCipher);
     522           2 :         }
     523           2 :     void init_003()
     524             :         {
     525           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     526           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     527             : 
     528           2 :             sal_uInt32     nKeyLen = 16;
     529           2 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     530           2 :             memset(pKeyBuffer, 0, nKeyLen);
     531             : 
     532           2 :             sal_uInt32     nArgLen = 16;
     533           2 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     534           2 :             memset(pArgBuffer, 0, nArgLen);
     535           2 :             pArgBuffer[0] = 1;
     536             : 
     537           2 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     538           2 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     539             : 
     540           2 :             delete [] pArgBuffer;
     541           2 :             delete [] pKeyBuffer;
     542             : 
     543           2 :             rtl_cipher_destroy(aCipher);
     544           2 :         }
     545           2 :     void init_004()
     546             :         {
     547           2 :             rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
     548           2 :             CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
     549             : 
     550           2 :             sal_uInt32     nKeyLen = 16;
     551           2 :             sal_uInt8     *pKeyBuffer = new sal_uInt8[ nKeyLen ];
     552           2 :             memset(pKeyBuffer, 0, nKeyLen);
     553           2 :             pKeyBuffer[0] = 1;
     554             : 
     555           2 :             sal_uInt32     nArgLen = 16;
     556           2 :             sal_uInt8     *pArgBuffer = new sal_uInt8[ nArgLen ];
     557           2 :             memset(pArgBuffer, 0, nArgLen);
     558           2 :             pArgBuffer[0] = 1;
     559             : 
     560           2 :             rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
     561           2 :             CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
     562             : 
     563           2 :             delete [] pArgBuffer;
     564           2 :             delete [] pKeyBuffer;
     565             : 
     566           2 :             rtl_cipher_destroy(aCipher);
     567           2 :         }
     568             :     // Change the following lines only, if you add, remove or rename
     569             :     // member functions of the current class,
     570             :     // because these macros are need by auto register mechanism.
     571             : 
     572           4 :     CPPUNIT_TEST_SUITE(init);
     573           2 :     CPPUNIT_TEST(init_001);
     574           2 :     CPPUNIT_TEST(init_002);
     575           2 :     CPPUNIT_TEST(init_003);
     576           2 :     CPPUNIT_TEST(init_004);
     577           4 :     CPPUNIT_TEST_SUITE_END();
     578             : }; // class init
     579             : 
     580           6 : class initBF : public CppUnit::TestFixture
     581             : {
     582             : public:
     583             :     // initialise your test code values here.
     584           2 :     void setUp() SAL_OVERRIDE
     585             :     {
     586           2 :     }
     587             : 
     588           2 :     void tearDown() SAL_OVERRIDE
     589             :     {
     590           2 :     }
     591             : 
     592           2 :     void initBF_001()
     593             :         {
     594             :             // seems to be the same as init, so empty
     595           2 :         }
     596             : 
     597             :     // Change the following lines only, if you add, remove or rename
     598             :     // member functions of the current class,
     599             :     // because these macros are need by auto register mechanism.
     600             : 
     601           4 :     CPPUNIT_TEST_SUITE(initBF);
     602           2 :     CPPUNIT_TEST(initBF_001);
     603           4 :     CPPUNIT_TEST_SUITE_END();
     604             : }; // class initBF
     605             : 
     606           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::create);
     607           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::createBF);
     608           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::decode);
     609           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::decodeBF);
     610           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::destroy);
     611           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::destroyBF);
     612           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::encode);
     613           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::encodeBF);
     614           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::init);
     615           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::initBF);
     616             : 
     617             : } // namespace rtl_cipher
     618             : 
     619             : // this macro creates an empty function, which will called by the RegisterAllFunctions()
     620             : // to let the user the possibility to also register some functions by hand.
     621           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     622             : 
     623             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10