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

Generated by: LCOV version 1.11