1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 Andrew Ziem <ahz001@gmail.com>
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "s-common-utils.h"
#include "gdm-common.h"
START_TEST (test_gdm_string_hex_encode)
{
GString *a;
GString *b;
a = g_string_new ("foo");
b = g_string_sized_new (100);
fail_unless (TRUE == gdm_string_hex_encode (a, 0, b, 0), NULL);
fail_unless (0 == strncmp (b->str, "666f6f", 7), NULL);
#ifndef NO_INVALID_INPUT
/* invalid input */
fail_unless (FALSE == gdm_string_hex_encode (a, -1, b, -1), NULL);
fail_unless (FALSE == gdm_string_hex_encode (NULL, 0, NULL, 0), NULL);
fail_unless (FALSE == gdm_string_hex_encode (a, 0, a, 0), NULL);
#endif
g_string_free (a, TRUE);
g_string_free (b, TRUE);
}
END_TEST
START_TEST (test_gdm_string_hex_decode)
GString *a;
GString *b;
a = g_string_new ("666f6f");
b = g_string_sized_new (100);
fail_unless (TRUE == gdm_string_hex_decode (a, 0, NULL, b, 0), NULL);
fail_unless (0 == strncmp (b->str, "foo", 7), NULL);
#ifndef NO_INVALID_INPUT
/* invalid input */
fail_unless (FALSE == gdm_string_hex_decode (a, -1, NULL, b, -1), NULL);
fail_unless (FALSE == gdm_string_hex_decode (NULL, 0, NULL, NULL, 0), NULL);
fail_unless (FALSE == gdm_string_hex_decode (a, 0, NULL, a, 0), NULL);
#endif
g_string_free (a, TRUE);
g_string_free (b, TRUE);
END_TEST
Suite *
suite_common_utils (void)
{
Suite *s;
TCase *tc_core;
s = suite_create ("gdm-common");
tc_core = tcase_create ("core");
tcase_add_test (tc_core, test_gdm_string_hex_encode);
tcase_add_test (tc_core, test_gdm_string_hex_decode);
suite_add_tcase (s, tc_core);
return s;
}
|