source: proiecte/PPPP/gdm/tests/s-common-utils.c @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

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