1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2018 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <glib.h>
21 #include <glib-object.h>
22 
23 #include <CUnit/CUnit.h>
24 #include <CUnit/Basic.h>
25 
26 #include <ags/libags.h>
27 #include <ags/libags-audio.h>
28 
29 int ags_track_test_init_suite();
30 int ags_track_test_clean_suite();
31 
32 void ags_track_test_duplicate();
33 
34 #define AGS_TRACK_TEST_DUPLICATE_X_0 (17)
35 #define AGS_TRACK_TEST_DUPLICATE_X_1 (3 * AGS_MIDI_DEFAULT_OFFSET + 17)
36 
37 /* The suite initialization function.
38  * Opens the temporary file used by the tests.
39  * Returns zero on success, non-zero otherwise.
40  */
41 int
ags_track_test_init_suite()42 ags_track_test_init_suite()
43 {
44   return(0);
45 }
46 
47 /* The suite cleanup function.
48  * Closes the temporary file used by the tests.
49  * Returns zero on success, non-zero otherwise.
50  */
51 int
ags_track_test_clean_suite()52 ags_track_test_clean_suite()
53 {
54   return(0);
55 }
56 
57 void
ags_track_test_duplicate()58 ags_track_test_duplicate()
59 {
60   AgsTrack *track, *copy_track;
61 
62   /* create track - #0 */
63   track = g_object_new(AGS_TYPE_TRACK,
64 			"x", (guint64) AGS_TRACK_TEST_DUPLICATE_X_0,
65 			NULL);
66 
67   /* assert duplicate - #0 */
68   copy_track = ags_track_duplicate(track);
69 
70   CU_ASSERT(AGS_IS_TRACK(copy_track) &&
71 	    copy_track->x == track->x);
72 
73   /* create track - #1 */
74   track = g_object_new(AGS_TYPE_TRACK,
75 			"x", (guint64) AGS_TRACK_TEST_DUPLICATE_X_1,
76 			NULL);
77 
78   /* assert duplicate - #1 */
79   copy_track = ags_track_duplicate(track);
80 
81   CU_ASSERT(AGS_IS_TRACK(copy_track) &&
82 	    copy_track->x == track->x);
83 }
84 
85 int
main(int argc,char ** argv)86 main(int argc, char **argv)
87 {
88   CU_pSuite pSuite = NULL;
89 
90   /* initialize the CUnit test registry */
91   if(CUE_SUCCESS != CU_initialize_registry()){
92     return CU_get_error();
93   }
94 
95   /* add a suite to the registry */
96   pSuite = CU_add_suite("AgsTrackTest", ags_track_test_init_suite, ags_track_test_clean_suite);
97 
98   if(pSuite == NULL){
99     CU_cleanup_registry();
100 
101     return CU_get_error();
102   }
103 
104   /* add the tests to the suite */
105   if((CU_add_test(pSuite, "test of AgsTrack duplicate", ags_track_test_duplicate) == NULL)){
106     CU_cleanup_registry();
107 
108     return CU_get_error();
109   }
110 
111   /* Run all tests using the CUnit Basic interface */
112   CU_basic_set_mode(CU_BRM_VERBOSE);
113   CU_basic_run_tests();
114 
115   CU_cleanup_registry();
116 
117   return(CU_get_error());
118 }
119