diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-03-22 18:46:57 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-03-22 18:46:57 +0000 |
commit | e29d2d4c451d7954aba3aea32432eb7e3b889226 (patch) | |
tree | 1f0ed735494b0eaceadb6ff30f9fa273c5009319 /tests/test-pulse-manager.c | |
parent | f02377f77f88106ba1c26cb184a14f33cd1a89fe (diff) | |
download | ayatana-indicator-sound-e29d2d4c451d7954aba3aea32432eb7e3b889226.tar.gz ayatana-indicator-sound-e29d2d4c451d7954aba3aea32432eb7e3b889226.tar.bz2 ayatana-indicator-sound-e29d2d4c451d7954aba3aea32432eb7e3b889226.zip |
test for update of sink data
Diffstat (limited to 'tests/test-pulse-manager.c')
-rw-r--r-- | tests/test-pulse-manager.c | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index 5fff7b9..67fd67d 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -20,11 +20,30 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <string.h> -/* we intend to test static functions which are not to be exported */ +/* we intend to test static functions +which are not to be exported +hence the inclusion of the C file*/ #include "../src/pulse-manager.c" #include "mockpulse.h" -static pa_sink_info* mock_sink_info(); + +/** +Helper Methods +**/ +static pa_sink_info* +mock_sink_info() +{ + pa_sink_info* mock_sink; + mock_sink = g_new0(pa_sink_info, 1); + mock_sink->index = 8; + mock_sink->name = g_strdup("mock_sink"); + mock_sink->description = g_strdup("mock description"); + mock_sink->mute = 0; + pa_cvolume volume; // nearly full volume: + pa_cvolume_set(&volume, 1, 30000); + mock_sink->volume = volume; + return mock_sink; +} @@ -45,35 +64,46 @@ static pa_sink_info* mock_sink_info(); /* //pa_context_unref(context);*/ /*}*/ -static void test_sink_update +static void test_sink_update() { -/* pa_sink_info *expected = g_new0(pa_sink_info, 1);*/ -/* expected->name = g_strdup("foo");*/ -/* expected->index = 8;*/ -/* expected->description = g_strdup("more details");*/ - // fill it out here more. - // hook into our pa_context_get_sink_info_by_index to pass exppected to - // update_sink_info - // set_pa_context_get_sink_info(expected); - // update_sink_info is a static method in pulse-manager.c ? -/* pa_context_get_sink_info_by_index(context, sink_details->index, update_sink_info, NULL);*/ - // the mockinkg lib should then return this mocked up sink_info to the - // method update_sink_info which tests could be wrote against to make sure - // everthing is populated correctly. -/* pa_context_unref(context);*/ -/* g_free(expected);*/ + pa_context* context = pa_context_new(NULL, "foo"); + pa_sink_info* mock_sink = mock_sink_info(); + set_pa_context_get_sink_info(mock_sink); + sink_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_sink_info); + + pa_context_get_sink_info_by_index(context, mock_sink->index, pulse_sink_info_callback, NULL); + + mock_sink->mute = 1; + pa_cvolume volume; // nearly full volume: + pa_cvolume_set(&volume, 1, 10000); + mock_sink->volume = volume; + + set_pa_context_get_sink_info(mock_sink); + + pa_context_get_sink_info_by_index(context, mock_sink->index, update_sink_info, NULL); + GList *keys = g_hash_table_get_keys(sink_hash); + gint position = g_list_index(keys, GINT_TO_POINTER(mock_sink->index)); + + g_assert(position >= 0); + sink_info* stored_sink_info = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(mock_sink->index)); + + g_assert(!!mock_sink->mute == stored_sink_info->mute); + g_assert(pa_cvolume_equal(&mock_sink->volume, &stored_sink_info->volume)); + + + g_free(mock_sink); + g_hash_table_destroy(sink_hash); + pa_context_unref(context); } + static void test_sink_cache_population() { - pa_context* context = pa_context_new(NULL, "foo"); - + pa_context* context = pa_context_new(NULL, "foo"); pa_sink_info* mock_sink = mock_sink_info(); - set_pa_context_get_sink_info(mock_sink); - sink_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_sink_info); pa_context_get_sink_info_by_index(context, mock_sink->index, pulse_sink_info_callback, NULL); @@ -96,25 +126,6 @@ static void test_sink_cache_population() pa_context_unref(context); } -/** -Helper Methods -**/ - -static pa_sink_info* -mock_sink_info() -{ - pa_sink_info* mock_sink; - mock_sink = g_new0(pa_sink_info, 1); - mock_sink->index = 8; - mock_sink->name = g_strdup("mock_sink"); - mock_sink->description = g_strdup("mock description"); - mock_sink->mute = 0; - pa_cvolume volume; // nearly full volume: - pa_cvolume_set(&volume, 1, 30000); - mock_sink->volume = volume; - return mock_sink; -} - gint main (gint argc, gchar * argv[]) { @@ -122,6 +133,8 @@ gint main (gint argc, gchar * argv[]) g_test_init(&argc, &argv, NULL); g_test_add_func("/indicator-sound/pulse-manager/sink-cache-population", test_sink_cache_population); + g_test_add_func("/indicator-sound/pulse-manager/sink-update", test_sink_update); + //g_test_add_func("/indicator-sound/pulse-manager/pa-context-exit", test_pa_context_exit); return g_test_run (); |