~ubuntu-branches/ubuntu/feisty/libuser/feisty

« back to all changes in this revision

Viewing changes to tests/config_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Ghe Rivero
  • Date: 2005-09-30 16:22:04 UTC
  • Revision ID: james.westby@ubuntu.com-20050930162204-qubxaa7e2lbovdgh
Tags: upstream-0.54.dfsg.1
ImportĀ upstreamĀ versionĀ 0.54.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2002, 2005 Red Hat, Inc.
 
2
 *
 
3
 * This is free software; you can redistribute it and/or modify it under
 
4
 * the terms of the GNU Library General Public License as published by
 
5
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Library General Public
 
14
 * License along with this program; if not, write to the Free Software
 
15
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
16
 */
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
#include "config.h"
 
20
#endif
 
21
#include <glib.h>
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
#include "../lib/user.h"
 
26
#undef NDEBUG
 
27
#include <assert.h>
 
28
 
 
29
int
 
30
main(void)
 
31
{
 
32
        struct lu_context *ctx;
 
33
        struct lu_error *error;
 
34
        GList *list;
 
35
        
 
36
        error = NULL;
 
37
        ctx = lu_start(NULL, 0, NULL, NULL, lu_prompt_console_quiet, NULL,
 
38
                       &error);
 
39
        if (ctx == NULL) {
 
40
                fprintf(stderr, "Error initializing %s: %s.\n", PACKAGE,
 
41
                        lu_strerror(error));
 
42
                return 1;
 
43
        }
 
44
 
 
45
 
 
46
        list = lu_cfg_read(ctx, "test/name", NULL);
 
47
        assert(g_list_length(list) == 2);
 
48
        assert(strcmp(list->data, "value1") == 0);
 
49
        assert(strcmp(list->next->data, "value2") == 0);
 
50
 
 
51
        list = lu_cfg_read(ctx, "test/nonexistent", "default");
 
52
        assert(g_list_length(list) == 1);
 
53
        assert(strcmp(list->data, "default") == 0);
 
54
 
 
55
        list = lu_cfg_read(ctx, "test/nonexistent", NULL);
 
56
        assert(g_list_length(list) == 0);
 
57
        
 
58
        assert(strcmp(lu_cfg_read_single(ctx, "test/name", NULL), "value1")
 
59
               == 0);
 
60
        assert(strcmp(lu_cfg_read_single(ctx, "test/nonexistent", "default"),
 
61
                      "default") == 0);
 
62
        assert(lu_cfg_read_single(ctx, "test/nonexistent", NULL) == NULL);
 
63
        
 
64
        list = lu_cfg_read_keys(ctx, "test");
 
65
        assert(g_list_length(list) == 2);
 
66
        assert(strcmp(list->data, "name") == 0);
 
67
        assert(strcmp(list->next->data, "name2") == 0);
 
68
 
 
69
        list = lu_cfg_read_keys(ctx, "invalid");
 
70
        assert(g_list_length(list) == 0);
 
71
        
 
72
        lu_end(ctx);
 
73
 
 
74
        return 0;
 
75
}