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