1 #include "config.h"
2 
3 #include <locale.h>
4 #define GST_USE_UNSTABLE_API 1
5 #include <gst/tag/tag.h>
6 
7 #include "gst/totem-time-helpers.h"
8 #include "backend/bacon-video-widget.h"
9 #include "backend/bacon-time-label.h"
10 #include "totem-menu.h"
11 
12 static BvwLangInfo *
bvw_lang_info_new(const char * language,const char * codec)13 bvw_lang_info_new (const char *language,
14 		   const char *codec)
15 {
16 	BvwLangInfo *info;
17 
18 	info = g_new0 (BvwLangInfo, 1);
19 	info->language = g_strdup (language);
20 	info->codec = g_strdup (codec);
21 	return info;
22 }
23 
24 static void
test_menus_lang_info(void)25 test_menus_lang_info (void)
26 {
27 	GList *l, *ret;
28 
29 	/* No language, no codec */
30 	l = NULL;
31 	l = g_list_append (l, bvw_lang_info_new ("und", NULL));
32 	l = g_list_append (l, bvw_lang_info_new ("und", NULL));
33 
34 	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
35 	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
36 
37 	g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "Audio Track #1");
38 	g_assert_cmpstr (g_list_nth_data (ret, 1), ==, "Audio Track #2");
39 	g_list_free_full (ret, g_free);
40 
41 	/* Same language, same codecs */
42 	l = NULL;
43 	l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Pro Racing"));
44 	l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Pro Racing"));
45 	l = g_list_append (l, bvw_lang_info_new ("fre", "Dolby Amateur 5.1"));
46 
47 	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
48 	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
49 
50 	g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "English #1");
51 	g_assert_cmpstr (g_list_nth_data (ret, 1), ==, "English #2");
52 	g_assert_cmpstr (g_list_nth_data (ret, 2), ==, "French");
53 	g_list_free_full (ret, g_free);
54 
55 	/* Same language, different codecs */
56 	l = NULL;
57 	l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Pro Racing"));
58 	l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Amateur 5.1"));
59 	l = g_list_append (l, bvw_lang_info_new ("fre", "Dolby Amateur 5.1"));
60 
61 	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
62 	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
63 
64 	g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "English — Dolby Pro Racing");
65 	g_assert_cmpstr (g_list_nth_data (ret, 1), ==, "English — Dolby Amateur 5.1");
66 	g_assert_cmpstr (g_list_nth_data (ret, 2), ==, "French");
67 	g_list_free_full (ret, g_free);
68 
69 	/* Different languages */
70 	l = NULL;
71 	l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Amateur 5.1"));
72 	l = g_list_append (l, bvw_lang_info_new ("spa", "Dolby Amateur 5.1"));
73 	l = g_list_append (l, bvw_lang_info_new ("fre", "Dolby Amateur 5.1"));
74 
75 	ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
76 	g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
77 
78 	g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "English");
79 	g_assert_cmpstr (g_list_nth_data (ret, 1), ==, "Spanish; Castilian");
80 	g_assert_cmpstr (g_list_nth_data (ret, 2), ==, "French");
81 	g_list_free_full (ret, g_free);
82 }
83 
84 static void
set_labels(GtkWidget * label,GtkWidget * label_remaining,gint64 _time,gint64 length,const char * expected,const char * expected_remaining)85 set_labels (GtkWidget  *label,
86 	    GtkWidget  *label_remaining,
87 	    gint64      _time,
88 	    gint64      length,
89 	    const char *expected,
90 	    const char *expected_remaining)
91 {
92 	const char *str;
93 
94 	bacon_time_label_set_time (BACON_TIME_LABEL (label), _time, length);
95 	bacon_time_label_set_time (BACON_TIME_LABEL (label_remaining), _time, length);
96 
97 	str = gtk_label_get_text (GTK_LABEL (label));
98 	g_assert_cmpstr (str, ==, expected);
99 
100 	str = gtk_label_get_text (GTK_LABEL (label_remaining));
101 	g_assert_cmpstr (str, ==, expected_remaining);
102 }
103 
104 static void
test_time_label(void)105 test_time_label (void)
106 {
107 	GtkWidget *label, *label_remaining;
108 	char *str;
109 
110 	label = bacon_time_label_new ();
111 	label_remaining = bacon_time_label_new ();
112 	bacon_time_label_set_remaining (BACON_TIME_LABEL (label_remaining), TRUE);
113 
114 	set_labels (label, label_remaining,
115 		    0, 1000,
116 		    "0:00", "-0:01");
117 
118 	set_labels (label, label_remaining,
119 		    500, 1000,
120 		    "0:00", "-0:01");
121 
122 	set_labels (label, label_remaining,
123 		    700, 1400,
124 		    "0:00", "-0:01");
125 
126 	set_labels (label, label_remaining,
127 		    1000, 1400,
128 		    "0:01", "-0:01");
129 
130 	set_labels (label, label_remaining,
131 		    0, 45 * 60 * 1000,
132 		    "0:00", "-45:00");
133 
134 	set_labels (label, label_remaining,
135 		    50 * 60 * 1000, 45 * 60 * 1000,
136 		    "50:00", "--:--");
137 
138 	str = totem_time_to_string (0, FALSE, FALSE);
139 	g_assert_cmpstr (str, ==, "0:00");
140 	g_free (str);
141 
142 	str = totem_time_to_string (500, FALSE, FALSE);
143 	g_assert_cmpstr (str, ==, "0:01");
144 	g_free (str);
145 
146 	str = totem_time_to_string (500, TRUE, FALSE);
147 	g_assert_cmpstr (str, ==, "-0:01");
148 	g_free (str);
149 
150 	str = totem_time_to_string (1250, FALSE, FALSE);
151 	g_assert_cmpstr (str, ==, "0:01");
152 	g_free (str);
153 
154 	str = totem_time_to_string (1250, TRUE, FALSE);
155 	g_assert_cmpstr (str, ==, "-0:02");
156 	g_free (str);
157 }
158 
main(int argc,char ** argv)159 int main (int argc, char **argv)
160 {
161 	setlocale (LC_ALL, "en_GB.UTF-8");
162 
163 	g_test_init (&argc, &argv, NULL);
164 	gtk_init (&argc, &argv);
165 	g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");
166 
167 	g_test_add_func ("/menus/lang_info", test_menus_lang_info);
168 	g_test_add_func ("/osd/time_label", test_time_label);
169 
170 	return g_test_run ();
171 }
172