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