summaryrefslogtreecommitdiff
path: root/src/test-totem.c
blob: de4520a2262f3e9cdbdf1ef4130027a1bb155754 (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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "config.h"

#include <locale.h>
#define GST_USE_UNSTABLE_API 1
#include <gst/tag/tag.h>

#include "gst/totem-time-helpers.h"
#include "backend/bacon-video-widget.h"
#include "backend/bacon-time-label.h"
#include "totem-menu.h"

static BvwLangInfo *
bvw_lang_info_new (const char *title,
		   const char *language,
		   const char *codec)
{
	BvwLangInfo *info;

	info = g_new0 (BvwLangInfo, 1);
	info->title = g_strdup (title);
	info->language = g_strdup (language);
	info->codec = g_strdup (codec);
	return info;
}

static const char *
nth_label (GList *list, guint index)
{
	MenuItem *item = g_list_nth_data (list, index);
	if (!item)
		return NULL;
	return item->label;
}

static void
test_menus_lang_info (void)
{
	GList *l, *ret;

	/* No language, no codec */
	l = NULL;
	l = g_list_append (l, bvw_lang_info_new (NULL, "und", NULL));
	l = g_list_append (l, bvw_lang_info_new (NULL, "und", NULL));

	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);

	g_assert_cmpstr (nth_label (ret, 0), ==, "Audio Track #1");
	g_assert_cmpstr (nth_label (ret, 1), ==, "Audio Track #2");
	g_list_free_full (ret, g_free);

	/* Same language, same codecs */
	l = NULL;
	l = g_list_append (l, bvw_lang_info_new (NULL, "eng", "Dolby Pro Racing"));
	l = g_list_append (l, bvw_lang_info_new (NULL, "eng", "Dolby Pro Racing"));
	l = g_list_append (l, bvw_lang_info_new (NULL, "fre", "Dolby Amateur 5.1"));

	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);

	g_assert_cmpstr (nth_label (ret, 0), ==, "English #1");
	g_assert_cmpstr (nth_label (ret, 1), ==, "English #2");
	g_assert_cmpstr (nth_label (ret, 2), ==, "French");
	g_list_free_full (ret, g_free);

	/* Same language, different codecs */
	l = NULL;
	l = g_list_append (l, bvw_lang_info_new (NULL, "eng", "Dolby Pro Racing"));
	l = g_list_append (l, bvw_lang_info_new (NULL, "eng", "Dolby Amateur 5.1"));
	l = g_list_append (l, bvw_lang_info_new (NULL, "fre", "Dolby Amateur 5.1"));

	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);

	g_assert_cmpstr (nth_label (ret, 0), ==, "English — Dolby Pro Racing");
	g_assert_cmpstr (nth_label (ret, 1), ==, "English — Dolby Amateur 5.1");
	g_assert_cmpstr (nth_label (ret, 2), ==, "French");
	g_list_free_full (ret, g_free);

	/* Different languages */
	l = NULL;
	l = g_list_append (l, bvw_lang_info_new (NULL, "eng", "Dolby Amateur 5.1"));
	l = g_list_append (l, bvw_lang_info_new (NULL, "spa", "Dolby Amateur 5.1"));
	l = g_list_append (l, bvw_lang_info_new (NULL, "fre", "Dolby Amateur 5.1"));

	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);

	g_assert_cmpstr (nth_label (ret, 0), ==, "English");
	g_assert_cmpstr (nth_label (ret, 1), ==, "Spanish; Castilian");
	g_assert_cmpstr (nth_label (ret, 2), ==, "French");
	g_list_free_full (ret, g_free);
}

static void
set_labels (GtkWidget  *label,
	    GtkWidget  *label_remaining,
	    gint64      _time,
	    gint64      length,
	    const char *expected,
	    const char *expected_remaining)
{
	const char *str;

	bacon_time_label_set_time (BACON_TIME_LABEL (label), _time, length);
	bacon_time_label_set_time (BACON_TIME_LABEL (label_remaining), _time, length);

	str = gtk_label_get_text (GTK_LABEL (label));
	g_assert_cmpstr (str, ==, expected);

	str = gtk_label_get_text (GTK_LABEL (label_remaining));
	g_assert_cmpstr (str, ==, expected_remaining);
}

static void
test_time_label (void)
{
	GtkWidget *label, *label_remaining;
	char *str;

	label = bacon_time_label_new ();
	label_remaining = bacon_time_label_new ();
	bacon_time_label_set_remaining (BACON_TIME_LABEL (label_remaining), TRUE);

	set_labels (label, label_remaining,
		    0, 1000,
		    "0:00", "-0:01");

	set_labels (label, label_remaining,
		    500, 1000,
		    "0:00", "-0:01");

	set_labels (label, label_remaining,
		    700, 1400,
		    "0:00", "-0:01");

	set_labels (label, label_remaining,
		    1000, 1400,
		    "0:01", "-0:01");

	set_labels (label, label_remaining,
		    0, 45 * 60 * 1000,
		    "0:00", "-45:00");

	set_labels (label, label_remaining,
		    50 * 60 * 1000, 45 * 60 * 1000,
		    "50:00", "--:--");

	str = totem_time_to_string (0, FALSE, FALSE);
	g_assert_cmpstr (str, ==, "0:00");
	g_free (str);

	str = totem_time_to_string (500, FALSE, FALSE);
	g_assert_cmpstr (str, ==, "0:01");
	g_free (str);

	str = totem_time_to_string (500, TRUE, FALSE);
	g_assert_cmpstr (str, ==, "-0:01");
	g_free (str);

	str = totem_time_to_string (1250, FALSE, FALSE);
	g_assert_cmpstr (str, ==, "0:01");
	g_free (str);

	str = totem_time_to_string (1250, TRUE, FALSE);
	g_assert_cmpstr (str, ==, "-0:02");
	g_free (str);
}

int main (int argc, char **argv)
{
	setlocale (LC_ALL, "en_GB.UTF-8");

	g_test_init (&argc, &argv, NULL);
	gtk_init (&argc, &argv);
	g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");

	g_test_add_func ("/menus/lang_info", test_menus_lang_info);
	g_test_add_func ("/osd/time_label", test_time_label);

	return g_test_run ();
}