1 #include <stdarg.h>
2 #include <stddef.h>
3 #include <setjmp.h>
4 #include <cmocka.h>
5 #include <stdlib.h>
6
7 #include "plugins/disco.h"
8
9 void
returns_empty_list_when_none(void ** state)10 returns_empty_list_when_none(void** state)
11 {
12 disco_close();
13 GList* features = disco_get_features();
14
15 assert_int_equal(g_list_length(features), 0);
16
17 g_list_free(features);
18 disco_close();
19 }
20
21 void
returns_added_feature(void ** state)22 returns_added_feature(void** state)
23 {
24 disco_close();
25 disco_add_feature("my_plugin", "some:feature:example");
26
27 GList* features = disco_get_features();
28 assert_int_equal(g_list_length(features), 1);
29 char* feature = features->data;
30 assert_string_equal(feature, "some:feature:example");
31
32 g_list_free(features);
33 disco_close();
34 }
35
36 void
resets_features_on_close(void ** state)37 resets_features_on_close(void** state)
38 {
39 disco_close();
40 disco_add_feature("my_plugin", "some:feature:example");
41
42 GList* features = disco_get_features();
43 assert_int_equal(g_list_length(features), 1);
44 g_list_free(features);
45
46 disco_close();
47 features = disco_get_features();
48 assert_int_equal(g_list_length(features), 0);
49
50 g_list_free(features);
51 disco_close();
52 }
53
54 void
returns_all_added_features(void ** state)55 returns_all_added_features(void** state)
56 {
57 disco_close();
58 disco_add_feature("first_plugin", "first:feature");
59 disco_add_feature("first_plugin", "second:feature");
60 disco_add_feature("second_plugin", "third:feature");
61 disco_add_feature("third_plugin", "fourth:feature");
62 disco_add_feature("third_plugin", "fifth:feature");
63
64 GList* features = disco_get_features();
65
66 assert_int_equal(g_list_length(features), 5);
67 assert_true(g_list_find_custom(features, "first:feature", (GCompareFunc)g_strcmp0));
68 assert_true(g_list_find_custom(features, "second:feature", (GCompareFunc)g_strcmp0));
69 assert_true(g_list_find_custom(features, "third:feature", (GCompareFunc)g_strcmp0));
70 assert_true(g_list_find_custom(features, "fourth:feature", (GCompareFunc)g_strcmp0));
71 assert_true(g_list_find_custom(features, "fifth:feature", (GCompareFunc)g_strcmp0));
72
73 g_list_free(features);
74 disco_close();
75 }
76
77 void
does_not_add_duplicate_feature(void ** state)78 does_not_add_duplicate_feature(void** state)
79 {
80 disco_close();
81 disco_add_feature("my_plugin", "my:feature");
82 disco_add_feature("some_other_plugin", "my:feature");
83
84 GList* features = disco_get_features();
85 assert_int_equal(g_list_length(features), 1);
86
87 g_list_free(features);
88 disco_close();
89 }
90
91 void
removes_plugin_features(void ** state)92 removes_plugin_features(void** state)
93 {
94 disco_close();
95 disco_add_feature("plugin1", "plugin1:feature1");
96 disco_add_feature("plugin1", "plugin1:feature2");
97 disco_add_feature("plugin2", "plugin2:feature1");
98
99 GList* features = disco_get_features();
100 assert_int_equal(g_list_length(features), 3);
101 g_list_free(features);
102
103 disco_remove_features("plugin1");
104
105 features = disco_get_features();
106 assert_int_equal(g_list_length(features), 1);
107
108 g_list_free(features);
109 disco_close();
110 }
111
112 void
does_not_remove_feature_when_more_than_one_reference(void ** state)113 does_not_remove_feature_when_more_than_one_reference(void** state)
114 {
115 disco_close();
116 disco_add_feature("plugin1", "feature1");
117 disco_add_feature("plugin1", "feature2");
118 disco_add_feature("plugin2", "feature1");
119
120 GList* features = disco_get_features();
121 assert_int_equal(g_list_length(features), 2);
122 g_list_free(features);
123
124 disco_remove_features("plugin1");
125
126 features = disco_get_features();
127 assert_int_equal(g_list_length(features), 1);
128
129 g_list_free(features);
130 disco_close();
131 }
132