aboutsummaryrefslogtreecommitdiff
path: root/libplanfahr/tests/lpf-manager.c
blob: 502a3a5e2992ebeaf43b3234107db0f5de3c2885 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * db.c: Deutsche Bahn provider for libplanfahr
 *
 * Copyright (C) 2014 Guido Günther
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "../libplanfahr.h"

#define LPF_TEST_PROVIDER "test-test"

LpfManager *manager;
LpfProvider *provider;

static void
test_lpf_manager(void)
{
    manager = lpf_manager_new();
    g_assert_nonnull (manager);
}


static void
test_lpf_manager_activate_provider(void)
{
    GError *err;

    g_assert_nonnull (manager);
    provider = lpf_manager_activate_provider(manager, LPF_TEST_PROVIDER, &err);
    g_assert_nonnull (provider);
    g_assert_no_error (err);
    g_assert_cmpstr ("test_test", ==, lpf_provider_get_name(provider));
}


static void
test_lpf_manager_activate_nonexistent_provider(void)
{
    GError *err;
    LpfProvider *nonexistent;

    g_assert_nonnull (manager);
    nonexistent = lpf_manager_activate_provider(manager, "doesnot-exist", &err);
    g_assert_error (err, LPF_MANAGER_ERROR,  LPF_MANAGER_ERROR_ACTIVATION_FAILED);
    g_assert_null (nonexistent);
}


static void
test_lpf_manager_deactivate_provider(void)
{
    g_assert_nonnull (manager);
    lpf_manager_deactivate_provider(manager, provider);
}


static void
test_lpf_manager_get_available_providers(void)
{
    GStrv providers;
    gint i;

    g_assert_nonnull (manager);
    providers = lpf_manager_get_available_providers();
    g_assert_nonnull(providers);
    for (i = 0; i < g_strv_length (providers); i++) {
        if (!g_strcmp0 (LPF_TEST_PROVIDER, providers[i]))
            return;
    }
    g_assert_not_reached(); /* test provider not found */
}


int main(int argc, char **argv)
{
    gboolean ret;

    g_test_init (&argc, &argv, NULL);
    g_setenv(LPF_PROVIDERS_ENV, LPF_TEST_SRCDIR "/../providers/.libs/", TRUE);

    g_test_add_func ("/libplanfahr/lpf-manager/new", test_lpf_manager);
    g_test_add_func ("/libplanfahr/lpf-manager/get_available-providers", test_lpf_manager_get_available_providers);
    g_test_add_func ("/libplanfahr/lpf-manager/activate-provider", test_lpf_manager_activate_provider);
    g_test_add_func ("/libplanfahr/lpf-manager/activate-nonexistent-provider", test_lpf_manager_activate_nonexistent_provider);
    g_test_add_func ("/libplanfahr/lpf-manager/deactivate-provider", test_lpf_manager_deactivate_provider);

    ret = g_test_run ();
    return ret;
}