1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* unit-test-util.c: Test gck-util.c
4 Copyright (C) 2007 Stefan Walter
6 The Gnome Keyring Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The Gnome Keyring Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 see <http://www.gnu.org/licenses/>.
20 Author: Stef Walter <stef@memberwebs.com>
25 #include "egg/egg-hex.h"
31 static const guchar TEST_DATA[] = { 0x05, 0xD6, 0x95, 0x96, 0x10, 0x12, 0xAE, 0x35 };
32 static const gchar *TEST_HEX = "05D695961012AE35";
33 static const gchar *TEST_HEX_DELIM = "05 D6 95 96 10 12 AE 35";
40 hex = egg_hex_encode (TEST_DATA, sizeof (TEST_DATA));
42 g_assert_cmpstr (hex, ==, TEST_HEX);
48 test_encode_spaces (void)
52 /* Encode without spaces */
53 hex = egg_hex_encode_full (TEST_DATA, sizeof (TEST_DATA), TRUE, 0, 0);
55 g_assert_cmpstr (hex, ==, TEST_HEX);
59 /* Encode with spaces */
60 hex = egg_hex_encode_full (TEST_DATA, sizeof (TEST_DATA), TRUE, " ", 1);
62 g_assert_cmpstr (hex, ==, TEST_HEX_DELIM);
73 data = egg_hex_decode (TEST_HEX, -1, &n_data);
75 g_assert (n_data == sizeof (TEST_DATA));
76 g_assert (memcmp (data, TEST_DATA, n_data) == 0);
79 /* Nothing in, empty out */
80 data = egg_hex_decode ("AB", 0, &n_data);
82 g_assert (n_data == 0);
86 data = egg_hex_decode_full (TEST_HEX_DELIM, -1, " ", 1, &n_data);
88 g_assert (n_data == sizeof (TEST_DATA));
89 g_assert (memcmp (data, TEST_DATA, n_data) == 0);
94 test_decode_fail (void)
99 /* Invalid input, null out */
100 data = egg_hex_decode ("AB", 1, &n_data);
103 /* Bad characters, null out */
104 data = egg_hex_decode ("ABXX", -1, &n_data);
107 /* Not Delimited, null out*/
108 data = egg_hex_decode_full ("ABABAB", -1, ":", 1, &n_data);
113 main (int argc, char **argv)
115 g_test_init (&argc, &argv, NULL);
117 g_test_add_func ("/hex/encode", test_encode);
118 g_test_add_func ("/hex/encode_spaces", test_encode_spaces);
119 g_test_add_func ("/hex/decode", test_decode);
120 g_test_add_func ("/hex/decode_fail", test_decode_fail);
122 return g_test_run ();