~macslow/notify-osd/mouse-movement-monitor

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
158
159
160
161
162
163
164
165
166
167
/*******************************************************************************
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
**      10        20        30        40        50        60        70        80
**
** notify-osd
**
** test-bubble.c - implements unit-tests for rendering/displaying a bubble
**
** Copyright 2009 Canonical Ltd.
**
** Authors:
**    Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
**    David Barth <david.barth@canonical.com>
**
** This program is free software: you can redistribute it and/or modify it
** under the terms of the GNU General Public License version 3, as published
** by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranties of
** MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <unistd.h>
#include <glib.h>
#include <gtk/gtk.h>

#include "bubble.h"
#include "util.h"

static
gboolean
stop_main_loop (GMainLoop *loop)
{
	g_main_loop_quit (loop);

	return FALSE;
}

static
void
test_bubble_new (void)
{
	Bubble* bubble;
	Defaults* defaults;

	defaults = defaults_new ();
	bubble = bubble_new (defaults);

	g_assert (bubble != NULL);

	g_object_unref (bubble);
	g_object_unref (defaults);
}

static
void
test_bubble_del (void)
{
	Bubble* bubble;
	Defaults* defaults;

	defaults = defaults_new ();
	bubble = bubble_new (defaults);

	g_assert (bubble != NULL);

	g_object_unref (bubble);
	g_object_unref (defaults);
}

static
void
test_bubble_set_attributes (void)
{
	Bubble*    bubble;
        GMainLoop* loop;
	Defaults* defaults;

	defaults = defaults_new ();
	bubble = bubble_new (defaults);
	bubble_set_icon (bubble, "/usr/share/icons/Human/scalable/status/notification-message-im.svg");
	bubble_set_title (bubble, "Unit Testing");
	bubble_set_message_body (bubble, "Long text that is hopefully wrapped");
	bubble_determine_layout (bubble);
	bubble_move (bubble, 30, 30);
	bubble_show (bubble);

	/* let the main loop run */
        loop = g_main_loop_new (NULL, FALSE);
        g_timeout_add (2000, (GSourceFunc) stop_main_loop, loop);
        g_main_loop_run (loop);

	g_object_unref (bubble);
	g_object_unref (defaults);
}

static
void
test_bubble_get_attributes (void)
{
	Bubble*    bubble;
	Defaults*  defaults;

	defaults = defaults_new ();
	bubble = bubble_new (defaults);
	bubble_set_title (bubble, "Foo Bar");
	bubble_set_message_body (bubble, "Some message-body text.");
	bubble_set_value (bubble, 42);

	g_assert_cmpstr (bubble_get_title (bubble), ==, "Foo Bar");
	g_assert_cmpstr (bubble_get_message_body (bubble),
			 ==,
			 "Some message-body text.");
	g_assert_cmpint (bubble_get_value (bubble), ==, 42);

	g_object_unref (bubble);
	g_object_unref (defaults);
}

GTestSuite *
test_bubble_create_test_suite (void)
{
	GTestSuite *ts = NULL;
	GTestCase  *tc = NULL;

	ts = g_test_create_suite ("bubble");
	tc = g_test_create_case ("can create a new bubble",
				 0,
				 NULL,
				 NULL,
				 test_bubble_new,
				 NULL);
	g_test_suite_add (ts, tc);

	g_test_suite_add(ts,
			 g_test_create_case ("can delete a bubble",
					     0,
					     NULL,
					     NULL,
					     test_bubble_del,
					     NULL)
		);

	g_test_suite_add (ts,
			  g_test_create_case ("can set bubble attributes",
					      0,
					      NULL,
					      NULL,
					      test_bubble_set_attributes,
					      NULL));

	g_test_suite_add (ts,
			  g_test_create_case ("can get bubble attributes",
					      0,
					      NULL,
					      NULL,
					      test_bubble_get_attributes,
					      NULL));

	return ts;
}