hythmbox-2.98/tests/test-rb-lib.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  This program is free software; you can redistribute it and/or modify
  4  *  it under the terms of the GNU General Public License as published by
  5  *  the Free Software Foundation; either version 2 of the License, or
  6  *  (at your option) any later version.
  7  *
  8  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
  9  *  GStreamer plugins to be used and distributed together with GStreamer
 10  *  and Rhythmbox. This permission is above and beyond the permissions granted
 11  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 12  *  you may extend this exception to your version of the code, but you are not
 13  *  obligated to do so. If you do not wish to do so, delete this exception
 14  *  statement from your version.
 15  *
 16  *  This program is distributed in the hope that it will be useful,
 17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19  *  GNU General Public License for more details.
 20  *
 21  *  You should have received a copy of the GNU General Public License
 22  *  along with this program; if not, write to the Free Software
 23  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 24  *
 25  */
 26 
 27 
 28 #include "config.h"
 29 
 30 #include <string.h>
 31 #include <glib-object.h>
 32 
 33 #include <check.h>
 34 #include "test-utils.h"
 35 #include "rb-util.h"
 36 #include "rb-string-value-map.h"
 37 #include "rb-debug.h"
 38 
 39 START_TEST (test_rb_string_value_map)
 40 {
 41 	RBStringValueMap *map;
 42 	GValue val = {0,};
 43 
 44 	map = rb_string_value_map_new ();
 45 	fail_unless (rb_string_value_map_size (map) == 0, "new map should have 0 entries");
 46 
 47 	g_value_init (&val, G_TYPE_INT);
 48 	g_value_set_int (&val, 42);
 49 	rb_string_value_map_set (map, "foo", &val);
 50 	g_value_unset (&val);
 51 	fail_unless (rb_string_value_map_size (map) == 1, "map with 1 entry added should have 1 entry");
 52 
 53 	fail_unless (rb_string_value_map_get (map, "foo", &val), "couldn't retrieve just-added entry");
 54 	fail_unless (g_value_get_int (&val) == 42, "entry returned wrong value");
 55 	g_value_unset (&val);
 56 
 57 	g_value_init (&val, G_TYPE_STRING);
 58 	g_value_set_string (&val, "BAZ");
 59 	rb_string_value_map_set (map, "bar", &val);
 60 	g_value_unset (&val);
 61 	fail_unless (rb_string_value_map_size (map) == 2, "map with 2 entries added should have 2 entries");
 62 
 63 	fail_unless (rb_string_value_map_get (map, "foo", &val), "couldn't retrieve entry");
 64 	fail_unless (g_value_get_int (&val) == 42, "entry returned wrong value");
 65 	g_value_unset (&val);
 66 
 67 	fail_unless (strcmp (g_value_get_string (rb_string_value_map_peek (map, "bar")), "BAZ") == 0,
 68 		     "wrong string returned");
 69 
 70 	fail_unless (rb_string_value_map_get (map, "wombat", &val) == FALSE, "could retrieve non-existant entry");
 71 
 72 	rb_string_value_map_remove (map, "foo");
 73 	fail_unless (rb_string_value_map_size (map) == 1, "map with second entry removed should have 1 entry");
 74 
 75 	fail_unless (strcmp (g_value_get_string (rb_string_value_map_peek (map, "bar")), "BAZ") == 0,
 76 		     "wrong string returned");
 77 
 78 	rb_string_value_map_remove (map, "bar");
 79 	fail_unless (rb_string_value_map_size (map) == 0, "map with both entries removed should have 0 entries");
 80 
 81 	fail_unless (rb_string_value_map_peek (map, "bar") == NULL, "removed entry should return NULL");
 82 }
 83 END_TEST
 84 
 85 static Suite *
 86 rb_file_helpers_suite ()
 87 {
 88 	Suite *s = suite_create ("rb-utils");
 89 	TCase *tc_chain = tcase_create ("rb-utils-core");
 90 
 91 	suite_add_tcase (s, tc_chain);
 92 
 93 	tcase_add_test (tc_chain, test_rb_string_value_map);
 94 
 95 	return s;
 96 }
 97 
 98 int
 99 main (int argc, char **argv)
100 {
101 	int ret;
102 	SRunner *sr;
103 	Suite *s;
104 
105 	rb_profile_start ("rb-utils test suite");
106 	rb_threads_init ();
107 	g_type_init ();
108 	rb_debug_init (TRUE);
109 
110 	GDK_THREADS_ENTER ();
111 
112 	/* setup tests */
113 	s = rb_file_helpers_suite ();
114 	sr = srunner_create (s);
115 	srunner_run_all (sr, CK_NORMAL);
116 	ret = srunner_ntests_failed (sr);
117 	srunner_free (sr);
118 
119 	rb_profile_end ("rb-file-helpers test suite");
120 	return ret;
121 }