aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2010-03-09 13:43:16 +1100
committerRobert Collins <robertc@robertcollins.net>2010-03-09 13:43:16 +1100
commit6c2b978f17d48fe212cccb15c23bb1e278ba600f (patch)
tree831860bd8bfb6778ac6c72cc1d105c66c0585435
parenta89c6663a0cf1deec82d8492fb897fd8541c1194 (diff)
downloadayatana-indicator-sound-6c2b978f17d48fe212cccb15c23bb1e278ba600f.tar.gz
ayatana-indicator-sound-6c2b978f17d48fe212cccb15c23bb1e278ba600f.tar.bz2
ayatana-indicator-sound-6c2b978f17d48fe212cccb15c23bb1e278ba600f.zip
flesh out test_pa_context_exit
-rw-r--r--tests/mockpulse.c42
-rw-r--r--tests/mockpulse.h1
-rw-r--r--tests/test-pulse-manager.c14
3 files changed, 52 insertions, 5 deletions
diff --git a/tests/mockpulse.c b/tests/mockpulse.c
index a931e1d..eec2c03 100644
--- a/tests/mockpulse.c
+++ b/tests/mockpulse.c
@@ -17,13 +17,51 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include <pulse/glib-mainloop.h>
+#include <pulse/context.h>
+
+struct pa_context {
+ int refcount;
+ pa_context_notify_cb_t cb;
+ void *cbdata;
+ pa_context_state_t state;
+};
-pa_glib_mainloop*
+pa_glib_mainloop *
pa_glib_mainloop_new(GMainContext *c)
{
- printf("This is reached\n", c);
return NULL;
}
+pa_context *
+pa_context_new(pa_mainloop_api *loop, char const *name) {
+ struct pa_context * result = g_new(pa_context, 1);
+ result->refcount = 1;
+ return result;
+}
+void
+pa_context_unref(pa_context * context) {
+ context->refcount--;
+ if (!context->refcount)
+ g_free(context);
+}
+
+void
+pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, void *userdata)
+{
+ c->cb = cb;
+ c->cbdata = userdata;
+}
+
+void set_pa_context_get_state_result(pa_context *c, pa_context_state_t state)
+{
+ c->state = state;
+}
+
+pa_context_state_t
+pa_context_get_state(pa_context *c)
+{
+ return c->state;
+}
diff --git a/tests/mockpulse.h b/tests/mockpulse.h
index 521ba2b..327121a 100644
--- a/tests/mockpulse.h
+++ b/tests/mockpulse.h
@@ -22,3 +22,4 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pulse/glib-mainloop.h>
+void set_pa_context_get_state_result(pa_context *, pa_context_state_t state);
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 <http://www.gnu.org/licenses/>.
/* 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);
}