File: test-plugins.c

package info (click to toggle)
gnome-calls 49.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,196 kB
  • sloc: ansic: 25,122; xml: 569; python: 139; sh: 106; lisp: 22; makefile: 19
file content (157 lines) | stat: -rw-r--r-- 5,084 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright (C) 2021 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
 */

#include "calls-config.h"

#include "calls-provider.h"
#include "calls-plugin-manager.h"

#include <glib.h>

static void
on_providers_changed (GListModel *model,
                      guint       position,
                      guint       removed,
                      guint       added,
                      gpointer    unused)
{
  g_autoptr (CallsProvider) provider = NULL;
  static guint phase = 0;

  switch (phase) {
  case 0:
  case 1:
  case 2:
  case 3:
    g_assert_cmpint (added, ==, 1);
    provider = g_list_model_get_item (model, position);
    g_assert_true (CALLS_IS_PROVIDER (provider));
    break;

  case 4:
  case 5:
  case 6:
  case 7:
    g_assert_cmpint (removed, ==, 1);
    break;

  default:
    g_assert_not_reached ();
  }

  phase++;
}

static void
test_calls_plugin_loading (void)
{
  CallsPluginManager *manager = calls_plugin_manager_get_default ();
  g_autoptr (GError) error = NULL;

  g_assert_false (calls_plugin_manager_has_any_plugins (manager));

  g_signal_connect (calls_plugin_manager_get_providers (manager),
                    "items-changed",
                    G_CALLBACK (on_providers_changed),
                    NULL);

  g_assert_true (calls_plugin_manager_load_plugin (manager, "dummy", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));
  g_assert_true (calls_plugin_manager_has_plugin (manager, "dummy"));

  g_assert_true (calls_plugin_manager_load_plugin (manager, "mm", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));
  g_assert_true (calls_plugin_manager_has_plugin (manager, "mm"));

  g_assert_true (calls_plugin_manager_load_plugin (manager, "sip", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));
  g_assert_true (calls_plugin_manager_has_plugin (manager, "sip"));

  g_assert_true (calls_plugin_manager_load_plugin (manager, "ofono", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));
  g_assert_true (calls_plugin_manager_has_plugin (manager, "ofono"));

  g_assert_false (calls_plugin_manager_load_plugin (manager, "not-a-plugin", &error));
  g_assert_nonnull (error);
  g_clear_error (&error);


  g_assert_true (calls_plugin_manager_unload_plugin (manager, "dummy", &error));
  g_assert_no_error (error);
  g_assert_false (calls_plugin_manager_has_plugin (manager, "dummy"));
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));

  g_assert_true (calls_plugin_manager_unload_plugin (manager, "mm", &error));
  g_assert_no_error (error);
  g_assert_false (calls_plugin_manager_has_plugin (manager, "mm"));
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));

  g_assert_true (calls_plugin_manager_unload_plugin (manager, "sip", &error));
  g_assert_no_error (error);
  g_assert_false (calls_plugin_manager_has_plugin (manager, "sip"));
  g_assert_true (calls_plugin_manager_has_any_plugins (manager));

  g_assert_true (calls_plugin_manager_unload_plugin (manager, "ofono", &error));
  g_assert_no_error (error);
  g_assert_false (calls_plugin_manager_has_plugin (manager, "ofono"));
  g_assert_false (calls_plugin_manager_has_any_plugins (manager));

  g_assert_cmpint (g_list_model_get_n_items (calls_plugin_manager_get_providers (manager)),
                   ==, 0);

  g_assert_finalize_object (manager);
}


static void
test_calls_plugin_unload_all (void)
{
  CallsPluginManager *manager = calls_plugin_manager_get_default ();
  g_autoptr (GError) error = NULL;

  g_assert_false (calls_plugin_manager_has_any_plugins (manager));

  g_assert_true (calls_plugin_manager_load_plugin (manager, "dummy", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_plugin (manager, "dummy"));

  g_assert_true (calls_plugin_manager_load_plugin (manager, "mm", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_plugin (manager, "mm"));

  g_assert_true (calls_plugin_manager_load_plugin (manager, "sip", &error));
  g_assert_no_error (error);
  g_assert_true (calls_plugin_manager_has_plugin (manager, "sip"));

  g_assert_true (calls_plugin_manager_has_any_plugins (manager));
  g_assert_true (calls_plugin_manager_unload_all_plugins (manager, &error));
  g_assert_no_error (error);
  g_assert_false (calls_plugin_manager_has_plugin (manager, "dummy"));
  g_assert_false (calls_plugin_manager_has_plugin (manager, "mm"));
  g_assert_false (calls_plugin_manager_has_plugin (manager, "sip"));
  g_assert_false (calls_plugin_manager_has_any_plugins (manager));

  g_assert_finalize_object (manager);
}


int
main (int   argc,
      char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/Calls/Plugins/load_plugins", test_calls_plugin_loading);
  g_test_add_func ("/Calls/Plugins/unload_all", test_calls_plugin_unload_all);

  return g_test_run ();
}