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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
/* Buzztrax
* Copyright (C) 2006 Buzztrax team <buzztrax-devel@buzztrax.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "m-bt-edit.h"
//-- globals
static BtEditApplication *app;
static BtMainWindow *main_window;
//-- fixtures
static void
case_setup (void)
{
BT_CASE_START;
}
static void
test_setup (void)
{
BtSettings *settings;
bt_edit_setup ();
app = bt_edit_application_new ();
g_object_get (app, "main-window", &main_window, NULL);
// no beeps please
settings = bt_settings_make ();
g_object_set (settings, "audiosink", "fakesink", NULL);
g_object_unref (settings);
flush_main_loop ();
}
static void
test_teardown (void)
{
gtk_widget_destroy (GTK_WIDGET (main_window));
flush_main_loop ();
ck_g_object_final_unref (app);
bt_edit_teardown ();
}
static void
case_teardown (void)
{
}
//-- helper
//-- tests
// create app and then unconditionally destroy window
static void
test_bt_edit_application_create (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
GST_INFO ("-- act --");
GST_INFO ("-- assert --");
fail_unless (app != NULL, NULL);
check_make_widget_screenshot (GTK_WIDGET (main_window), NULL);
{
BtCheckWidgetScreenshotRegions regions[] = {
{BT_CHECK_WIDGET_SCREENSHOT_REGION_MATCH_TYPE, NULL, NULL,
BT_TYPE_MAIN_MENU, GTK_POS_LEFT},
{BT_CHECK_WIDGET_SCREENSHOT_REGION_MATCH_TYPE, NULL, NULL,
BT_TYPE_MAIN_TOOLBAR, GTK_POS_LEFT},
{BT_CHECK_WIDGET_SCREENSHOT_REGION_MATCH_TYPE, NULL, NULL,
BT_TYPE_MAIN_STATUSBAR, GTK_POS_LEFT},
{BT_CHECK_WIDGET_SCREENSHOT_REGION_MATCH_LABEL, NULL, "Grid",
G_TYPE_INVALID, GTK_POS_RIGHT},
{BT_CHECK_WIDGET_SCREENSHOT_REGION_MATCH_NONE, NULL, NULL, G_TYPE_INVALID,
0}
};
check_make_widget_screenshot_with_highlight (GTK_WIDGET (main_window),
"highlight", regions);
}
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
static gboolean
finish_main_loops (gpointer user_data)
{
// this does not work for dialogs (gtk_dialog_run)!
gtk_main_quit ();
return FALSE;
}
// create app and then unconditionally destroy window
static void
test_bt_edit_application_run (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
BtSettings *settings = bt_settings_make ();
// avoid the about dialog
g_object_set (settings, "news-seen", PACKAGE_VERSION_NUMBER, NULL);
g_object_unref (settings);
GST_INFO ("-- act --");
g_idle_add (finish_main_loops, NULL);
bt_edit_application_run (app);
GST_INFO ("-- assert --");
mark_point ();
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
// create a new song
static void
test_bt_edit_application_new_song (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
GST_INFO ("-- act --");
bt_edit_application_new_song (app);
GST_INFO ("-- assert --");
ck_assert_gobject_object_ne (app, "song", NULL);
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
static void
test_bt_edit_application_new_song_is_saved (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
GST_INFO ("-- act --");
bt_edit_application_new_song (app);
GST_INFO ("-- assert --");
ck_assert_gobject_boolean_eq (app, "unsaved", FALSE);
check_make_widget_screenshot (GTK_WIDGET (main_window), "song");
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
// load a song
static void
test_bt_edit_application_load_song (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
GST_INFO ("-- act --");
bt_edit_application_load_song (app, check_get_test_song_path ("melo3.xml"),
NULL);
GST_INFO ("-- assert --");
ck_assert_gobject_object_ne (app, "song", NULL);
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
static void
test_bt_edit_application_load_song_is_saved (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
GST_INFO ("-- act --");
bt_edit_application_load_song (app, check_get_test_song_path ("melo3.xml"),
NULL);
GST_INFO ("-- assert --");
ck_assert_gobject_boolean_eq (app, "unsaved", FALSE);
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
// load a song, free it, load another
static void
test_bt_edit_application_load_songs (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
BtSong *song1, *song2;
bt_edit_application_load_song (app, check_get_test_song_path ("melo1.xml"),
NULL);
g_object_get (app, "song", &song1, NULL);
g_object_unref (song1);
GST_INFO ("-- act --");
bt_edit_application_load_song (app, check_get_test_song_path ("melo3.xml"),
NULL);
GST_INFO ("-- assert --");
g_object_get (app, "song", &song2, NULL);
fail_unless (song2 != NULL, NULL);
fail_unless (song2 != song1, NULL);
GST_INFO ("-- cleanup --");
g_object_unref (song2);
BT_TEST_END;
}
// load a song, free it, load again
static void
test_bt_edit_application_num_children (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
guint num;
GstElement *bin;
g_object_get (app, "bin", &bin, NULL);
GST_INFO ("song.elements=%d", GST_BIN_NUMCHILDREN (bin));
GST_INFO ("-- act --");
// load for first time
bt_edit_application_load_song (app, check_get_test_song_path ("melo3.xml"),
NULL);
num = GST_BIN_NUMCHILDREN (bin);
GST_INFO ("song.elements=%d", num);
// load song for second time
bt_edit_application_load_song (app, check_get_test_song_path ("melo3.xml"),
NULL);
GST_INFO ("song.elements=%d", GST_BIN_NUMCHILDREN (bin));
GST_INFO ("-- assert --");
fail_unless (num == GST_BIN_NUMCHILDREN (bin), NULL);
GST_INFO ("-- cleanup --");
gst_object_unref (bin);
BT_TEST_END;
}
// load a song with a view disabled
static void
test_bt_edit_application_load_song_with_view_disabled (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
BtMainPages *pages;
g_object_get (G_OBJECT (main_window), "pages", &pages, NULL);
gtk_notebook_remove_page (GTK_NOTEBOOK (pages), _i);
g_object_unref (pages);
GST_INFO ("removed page number %d", _i);
GST_INFO ("-- act --");
bt_edit_application_load_song (app, check_get_test_song_path ("melo3.xml"),
NULL);
GST_INFO ("-- assert --");
mark_point ();
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
// load a song and play it
static void
test_bt_edit_application_load_and_play (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
BtSong *song;
bt_edit_application_load_song (app, check_get_test_song_path ("melo1.xml"),
NULL);
g_object_get (app, "song", &song, NULL);
GST_INFO ("-- act --");
gboolean playing = bt_song_play (song);
GST_INFO ("-- assert --");
fail_unless (playing == TRUE, NULL);
GST_INFO ("-- cleanup --");
flush_main_loop ();
bt_song_stop (song);
g_object_unref (song);
BT_TEST_END;
}
// load a song, play it and load another song while the former is playing
static void
test_bt_edit_application_load_while_playing (BT_TEST_ARGS)
{
BT_TEST_START;
GST_INFO ("-- arrange --");
BtSong *song;
bt_edit_application_load_song (app, check_get_test_song_path ("melo1.xml"),
NULL);
g_object_get (app, "song", &song, NULL);
bt_song_play (song);
g_object_unref (song);
GST_INFO ("-- act --");
bt_edit_application_load_song (app, check_get_test_song_path ("melo2.xml"),
NULL);
GST_INFO ("-- assert --");
mark_point ();
GST_INFO ("-- cleanup --");
BT_TEST_END;
}
TCase *
bt_edit_application_example_case (void)
{
TCase *tc = tcase_create ("BtEditApplicationExamples");
tcase_add_test (tc, test_bt_edit_application_create);
tcase_add_test (tc, test_bt_edit_application_run);
tcase_add_test (tc, test_bt_edit_application_new_song);
tcase_add_test (tc, test_bt_edit_application_new_song_is_saved);
tcase_add_test (tc, test_bt_edit_application_load_song);
tcase_add_test (tc, test_bt_edit_application_load_song_is_saved);
tcase_add_test (tc, test_bt_edit_application_load_songs);
tcase_add_test (tc, test_bt_edit_application_num_children);
tcase_add_loop_test (tc,
test_bt_edit_application_load_song_with_view_disabled,
BT_MAIN_PAGES_MACHINES_PAGE, BT_MAIN_PAGES_COUNT);
tcase_add_test (tc, test_bt_edit_application_load_and_play);
tcase_add_test (tc, test_bt_edit_application_load_while_playing);
tcase_add_checked_fixture (tc, test_setup, test_teardown);
tcase_add_unchecked_fixture (tc, case_setup, case_teardown);
return (tc);
}
|