source: tests/check_arc.c @ d07c3a8

Last change on this file since d07c3a8 was 2799ff9, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-02-16T12:20:03Z

Fixed broken check in check_arc.c

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include <stdlib.h>
2#include <glib.h>
3#include <gmodule.h>
4#include <check.h>
5#include <string.h>
6#include <stdio.h>
7#include "arc.h"
8
9char *password = "TotT";
10
11char *clear_tests[] =
12{
13        "Wie dit leest is gek :-)",
14        "ItllBeBitlBee",
15        "One more boring password",
16        NULL
17};
18
19static void check_codec(int l)
20{
21        int i;
22       
23        for( i = 0; clear_tests[i]; i++ )
24        {
25                tcase_fn_start (clear_tests[i], __FILE__, __LINE__);
26                unsigned char *crypted;
27                char *decrypted;
28                int len;
29               
30                len = arc_encode( clear_tests[i], 0, &crypted, password );
31                len = arc_decode( crypted, len, &decrypted, password );
32               
33                fail_if( strcmp( clear_tests[i], decrypted ) != 0,
34                         "%s didn't decrypt back properly", clear_tests[i] );
35               
36                g_free( crypted );
37                g_free( decrypted );
38        }
39}
40
41struct
42{
43        unsigned char crypted[24];
44        int len;
45        char *decrypted;
46} decrypt_tests[] = {
47        {
48                {
49                        0xc3, 0x0d, 0x43, 0xc3, 0xee, 0x80, 0xe2, 0x8c, 0x0b, 0x29, 0x32, 0x7e,
50                        0x38, 0x05, 0x82, 0x10, 0x21, 0x1c, 0x4a, 0x00, 0x2c
51                }, 21, "Debugging sucks"
52        },
53        {
54                {
55                        0xb0, 0x00, 0x57, 0x0d, 0x0d, 0x0d, 0x70, 0xe1, 0xc0, 0x00, 0xa4, 0x25,
56                        0x7d, 0xbe, 0x03, 0xcc, 0x24, 0xd1, 0x0c
57                }, 19, "Testing rocks"
58        },
59        {
60                {
61                        0xb6, 0x92, 0x59, 0xe4, 0xf9, 0xc1, 0x7a, 0xf6, 0xf3, 0x18, 0xea, 0x28,
62                        0x73, 0x6d, 0xb3, 0x0a, 0x6f, 0x0a, 0x2b, 0x43, 0x57, 0xe9, 0x3e, 0x63
63                }, 24, "OSCAR is creepy..."
64        },
65        { "", 0, NULL }
66};
67
68static void check_decod(int l)
69{
70        int i;
71       
72        for( i = 0; decrypt_tests[i].len; i++ )
73        {
74                tcase_fn_start (decrypt_tests[i].decrypted, __FILE__, __LINE__);
75                char *decrypted;
76                int len;
77               
78                len = arc_decode( decrypt_tests[i].crypted, decrypt_tests[i].len,
79                                  &decrypted, password );
80               
81                fail_if( strcmp( decrypt_tests[i].decrypted, decrypted ) != 0,
82                         "%s didn't decrypt properly", clear_tests[i] );
83               
84                g_free( decrypted );
85        }
86}
87
88Suite *arc_suite (void)
89{
90        Suite *s = suite_create("ArcFour");
91        TCase *tc_core = tcase_create("Core");
92        suite_add_tcase (s, tc_core);
93        tcase_add_test (tc_core, check_codec);
94        tcase_add_test (tc_core, check_decod);
95        return s;
96}
Note: See TracBrowser for help on using the repository browser.