From 364d9362165f9f0d468eadc269c6421f4bf929e3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Mar 2010 20:40:32 +0000 Subject: new pulse manager test beginnings --- tests/test-pulse-manager.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test-pulse-manager.c (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c new file mode 100644 index 0000000..6a9c55b --- /dev/null +++ b/tests/test-pulse-manager.c @@ -0,0 +1,29 @@ +#include "defintions.h" +// I know this is not nice but I would rather not make everything public ? +#include "pulse-manager.c" + +pa_context* context; + +static void pa_context_exit() +{ + pa_context_set_state_callback(context, context_state_callback, NULL); + // => call context_state_callback(context, NULL); + // pa_context_get_state needs to be mocked to return the right FAIL flag. + // 1. test to make sure relevant variables are tidied up + // 2. then using the same pa_context_get_state we could ensure the manager is attempting to reconnect tp PA. +} + +static void test_sink_insert() +{ + sink_info *value; + value = g_new0(sink_info, 1); + value->index = 8; + value->name = "mock_sink";" + value->description = "mock description" + value->mute = FALSE + value->volume = 30000; // almost full + // update_sink_info is a static method in pulse-manager.c ? + pa_context_get_sink_info_by_index(context, value->index, update_sink_info); + // 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. +} + -- cgit v1.2.3 From 56f9654524bbf61a625905fe9e9dcaa63eaf71b5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Mar 2010 20:49:02 +0000 Subject: update --- tests/test-pulse-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index 6a9c55b..f05bccb 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -4,7 +4,7 @@ pa_context* context; -static void pa_context_exit() +static void test_pa_context_exit() { pa_context_set_state_callback(context, context_state_callback, NULL); // => call context_state_callback(context, NULL); -- cgit v1.2.3 From 2e85d8a7db825a7aef087710abe8159a716df6c7 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 9 Mar 2010 09:24:36 +1100 Subject: snapshot closer-to-building. --- tests/test-pulse-manager.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index f05bccb..2bc1c51 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -1,6 +1,25 @@ -#include "defintions.h" -// I know this is not nice but I would rather not make everything public ? -#include "pulse-manager.c" +/* +Copyright 2010 Canonical Ltd. + +Authors: + Robert Collins + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +/* we test static functions */ +#include "../src/pulse-manager.c" pa_context* context; -- cgit v1.2.3 From a89c6663a0cf1deec82d8492fb897fd8541c1194 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 9 Mar 2010 09:33:12 +1100 Subject: More snapshot, just need to deal with other sound-service components now. --- tests/test-pulse-manager.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index 2bc1c51..f5dfb80 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -37,12 +37,25 @@ static void test_sink_insert() sink_info *value; value = g_new0(sink_info, 1); value->index = 8; - value->name = "mock_sink";" - value->description = "mock description" - value->mute = FALSE - value->volume = 30000; // almost full + value->name = "mock_sink"; + value->description = "mock description"; + value->mute = FALSE; + pa_cvolume volume; // nearly full volume: + pa_cvolume_set(&volume, 1, 30000); + value->volume = volume; // update_sink_info is a static method in pulse-manager.c ? - pa_context_get_sink_info_by_index(context, value->index, update_sink_info); + pa_context_get_sink_info_by_index(context, value->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. } + +gint main (gint argc, gchar * argv[]) +{ + g_type_init(); + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/indicator-sound/pulse-manager/sink-insert", test_sink_insert); + g_test_add_func("/indicator-sound/pulse-manager/pa-context-exit", test_pa_context_exit); + + return g_test_run (); +} -- cgit v1.2.3 From 6c2b978f17d48fe212cccb15c23bb1e278ba600f Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 9 Mar 2010 13:43:16 +1100 Subject: flesh out test_pa_context_exit --- tests/test-pulse-manager.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index f5dfb80..f4f7ffc 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -20,21 +20,28 @@ with this program. If not, see . /* we test static functions */ #include "../src/pulse-manager.c" +#include "mockpulse.h" -pa_context* context; static void test_pa_context_exit() { + pa_context* context = pa_context_new(NULL, "foo"); pa_context_set_state_callback(context, context_state_callback, NULL); // => call context_state_callback(context, NULL); - // pa_context_get_state needs to be mocked to return the right FAIL flag. + // pa_context_get_state is mocked to return the right FAIL flag. + set_pa_context_get_state_result(context, PA_CONTEXT_FAILED); + context_state_callback(context, NULL); // 1. test to make sure relevant variables are tidied up - // 2. then using the same pa_context_get_state we could ensure the manager is attempting to reconnect tp PA. + // XXX: Conor to do. + // 2. then using the same pa_context_get_state we could ensure the manager + // is attempting to reconnect to PA. + pa_context_unref(context); } static void test_sink_insert() { sink_info *value; + pa_context* context = pa_context_new(NULL, "foo"); value = g_new0(sink_info, 1); value->index = 8; value->name = "mock_sink"; @@ -46,6 +53,7 @@ static void test_sink_insert() // update_sink_info is a static method in pulse-manager.c ? pa_context_get_sink_info_by_index(context, value->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); } -- cgit v1.2.3 From 69049dd2d6011e9ab96f4f439d00e1de98178449 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 9 Mar 2010 14:37:03 +1100 Subject: Fleshed out mocking needs missing symbols from the service linked in to work now. --- tests/test-pulse-manager.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index f4f7ffc..169acbd 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -40,20 +40,31 @@ static void test_pa_context_exit() static void test_sink_insert() { - sink_info *value; + sink_info *sink_details; pa_context* context = pa_context_new(NULL, "foo"); - value = g_new0(sink_info, 1); - value->index = 8; - value->name = "mock_sink"; - value->description = "mock description"; - value->mute = FALSE; + sink_details = g_new0(sink_info, 1); + sink_details->index = 8; + sink_details->name = "mock_sink"; + sink_details->description = "mock description"; + sink_details->mute = FALSE; pa_cvolume volume; // nearly full volume: pa_cvolume_set(&volume, 1, 30000); - value->volume = volume; + sink_details->volume = volume; + 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, value->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_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); } -- cgit v1.2.3 From f02377f77f88106ba1c26cb184a14f33cd1a89fe Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 22 Mar 2010 17:32:57 +0000 Subject: first pulse manager test wrote ... finally --- tests/test-pulse-manager.c | 118 +++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 35 deletions(-) (limited to 'tests/test-pulse-manager.c') diff --git a/tests/test-pulse-manager.c b/tests/test-pulse-manager.c index 169acbd..5fff7b9 100644 --- a/tests/test-pulse-manager.c +++ b/tests/test-pulse-manager.c @@ -18,53 +18,101 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* we test static functions */ +#include + +/* we intend to test static functions which are not to be exported */ #include "../src/pulse-manager.c" #include "mockpulse.h" +static pa_sink_info* mock_sink_info(); -static void test_pa_context_exit() -{ - pa_context* context = pa_context_new(NULL, "foo"); - pa_context_set_state_callback(context, context_state_callback, NULL); - // => call context_state_callback(context, NULL); - // pa_context_get_state is mocked to return the right FAIL flag. - set_pa_context_get_state_result(context, PA_CONTEXT_FAILED); - context_state_callback(context, NULL); - // 1. test to make sure relevant variables are tidied up - // XXX: Conor to do. - // 2. then using the same pa_context_get_state we could ensure the manager - // is attempting to reconnect to PA. - pa_context_unref(context); -} -static void test_sink_insert() + +/*static void test_pa_context_exit()*/ +/*{*/ +/* pa_context* context = pa_context_new(NULL, "foo");*/ + +/* pa_context_set_state_callback(context, context_state_callback, NULL);*/ +/* // => call context_state_callback(context, NULL);*/ +/* // pa_context_get_state is mocked to return the right FAIL flag.*/ +/* set_pa_context_get_state_result(context, PA_CONTEXT_FAILED);*/ +/* context_state_callback(context, NULL);*/ +/* // Test to ensure context is tidied after failure.*/ +/* g_assert(context == NULL);*/ +/* // 2. then using the same pa_context_get_state we could ensure the manager*/ +/* // is attempting to reconnect to PA. */ +/* //g_assert(PA_CONTEXT_CONNECTING == pa_context_get_state(get_context()));*/ +/* //pa_context_unref(context);*/ +/*}*/ + +static void test_sink_update { - sink_info *sink_details; - pa_context* context = pa_context_new(NULL, "foo"); - sink_details = g_new0(sink_info, 1); - sink_details->index = 8; - sink_details->name = "mock_sink"; - sink_details->description = "mock description"; - sink_details->mute = FALSE; - pa_cvolume volume; // nearly full volume: - pa_cvolume_set(&volume, 1, 30000); - sink_details->volume = volume; - pa_sink_info *expected = g_new0(pa_sink_info, 1); - expected->name = g_strdup("foo"); - expected->index = 8; - expected->description = g_strdup("more details"); +/* 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); + // 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); +/* 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);*/ + + +} + +static void test_sink_cache_population() +{ + 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); + + 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(g_ascii_strncasecmp(mock_sink->name, stored_sink_info->name, strlen(mock_sink->name)) == 0); + g_assert(g_ascii_strncasecmp(mock_sink->description, stored_sink_info->description, strlen(mock_sink->description)) == 0); + g_assert(!!mock_sink->mute == stored_sink_info->mute); + g_assert(mock_sink->index == stored_sink_info->index); + 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); - g_free(expected); +} + +/** +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; } @@ -73,8 +121,8 @@ gint main (gint argc, gchar * argv[]) g_type_init(); g_test_init(&argc, &argv, NULL); - g_test_add_func("/indicator-sound/pulse-manager/sink-insert", test_sink_insert); - g_test_add_func("/indicator-sound/pulse-manager/pa-context-exit", test_pa_context_exit); + g_test_add_func("/indicator-sound/pulse-manager/sink-cache-population", test_sink_cache_population); + //g_test_add_func("/indicator-sound/pulse-manager/pa-context-exit", test_pa_context_exit); return g_test_run (); } -- cgit v1.2.3 From e29d2d4c451d7954aba3aea32432eb7e3b889226 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 22 Mar 2010 18:46:57 +0000 Subject: test for update of sink data --- tests/test-pulse-manager.c | 95 ++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 41 deletions(-) (limited to 'tests/test-pulse-manager.c') 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 . #include -/* 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 (); -- cgit v1.2.3