aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-03-22 17:32:57 +0000
committerConor Curran <conor.curran@canonical.com>2010-03-22 17:32:57 +0000
commitf02377f77f88106ba1c26cb184a14f33cd1a89fe (patch)
tree2b5edc1549208898d2d843c53f0899fac03af3d8 /tests
parentb26c97936312634da3fb30e818a76ce2a5a03992 (diff)
downloadayatana-indicator-sound-f02377f77f88106ba1c26cb184a14f33cd1a89fe.tar.gz
ayatana-indicator-sound-f02377f77f88106ba1c26cb184a14f33cd1a89fe.tar.bz2
ayatana-indicator-sound-f02377f77f88106ba1c26cb184a14f33cd1a89fe.zip
first pulse manager test wrote ... finally
Diffstat (limited to 'tests')
-rw-r--r--tests/mockpulse.c6
-rw-r--r--tests/test-pulse-manager.c118
2 files changed, 89 insertions, 35 deletions
diff --git a/tests/mockpulse.c b/tests/mockpulse.c
index a41de30..b868e07 100644
--- a/tests/mockpulse.c
+++ b/tests/mockpulse.c
@@ -73,6 +73,12 @@ struct pa_operation {
int refcount;
};
+
+/*void pa_context_connect(pa_context* c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api)*/
+/*{*/
+/* set_pa_context_get_state_result(c, PA_CONTEXT_CONNECTING);*/
+/*}*/
+
/* Can be made into a list if we need multiple callbacks */
static pa_sink_info *next_sink_info;
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 <http://www.gnu.org/licenses/>.
*/
-/* we test static functions */
+#include <string.h>
+
+/* 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 ();
}