aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2015-01-26 15:26:28 -0600
committerTed Gould <ted@gould.cx>2015-01-26 15:26:28 -0600
commitb7b3a850299741e61c88e0471fdb797ae77c70cc (patch)
tree3bfec28510d5d9d9b04ceac56fc273583fbd86a2 /tests
parenta35e1d48e54ac59aecbf61aaba5e9dfb0cf151e0 (diff)
downloadayatana-indicator-sound-b7b3a850299741e61c88e0471fdb797ae77c70cc.tar.gz
ayatana-indicator-sound-b7b3a850299741e61c88e0471fdb797ae77c70cc.tar.bz2
ayatana-indicator-sound-b7b3a850299741e61c88e0471fdb797ae77c70cc.zip
Checkpoint, need some refactoring
Diffstat (limited to 'tests')
-rw-r--r--tests/pa-mock.c253
1 files changed, 235 insertions, 18 deletions
diff --git a/tests/pa-mock.c b/tests/pa-mock.c
index 6f4e6ad..906e3de 100644
--- a/tests/pa-mock.c
+++ b/tests/pa-mock.c
@@ -7,15 +7,18 @@
#define G_LOG_DOMAIN "PA-Mock"
G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb);
-typedef struct {
- pa_context_notify_cb_t cb;
- gpointer user_data;
-} state_cb_t;
+G_DEFINE_QUARK("pa-mock-subscribe-callback", subscribe_cb);
+G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask);
/* *******************************
* context.h
* *******************************/
+typedef struct {
+ pa_context_notify_cb_t cb;
+ gpointer user_data;
+} state_cb_t;
+
static void
context_weak_cb (gpointer user_data, GObject * oldobj)
{
@@ -223,22 +226,128 @@ pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userda
return pa_context_get_sink_info_by_name(c, "default-sink", cb, userdata);
}
+typedef struct {
+ pa_sink_info_cb_t cb;
+ gpointer userdata;
+ pa_context * context;
+} get_sink_input_info_t;
+
+static void
+get_sink_info_free (gpointer data)
+{
+ get_sink_input_info_t * info = (get_sink_info_t *)data;
+ pa_context_unref(info->context);
+ g_free(info);
+}
+
+static gboolean
+get_sink_info_cb (gpointer data)
+{
+ pa_sink_input_info sink = {
+ .name = "default-sink"
+ };
+ get_sink_input_info_t * info = (get_sink_input_info_t *)data;
+
+ info->cb(info->context, &sink, info->userdata);
+
+ return G_SOURCE_REMOVE;
+}
+
+pa_operation *
+pa_context_get_sink_input_info (pa_context *c, pa_sink_input_info_cb_t cb, void * userdata)
+{
+ g_return_val_if_fail(G_IS_OBJECT(c), NULL);
+ g_return_val_if_fail(cb != NULL, NULL);
+
+ get_sink_input_info_t * info = g_new(get_sink_input_info_t, 1);
+ info->cb = cb;
+ info->userdata = userdata;
+ info->context = g_objet_ref(c);
+
+ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+ get_sink_input_info_cb,
+ info,
+ get_sink_input_info_free);
+
+ GObject * goper = g_object_new(G_TYPE_OBJECT);
+ pa_operation * oper = (pa_operation *)goper;
+ return oper;
+}
-pa_context_get_sink_input_info
+#if 0
pa_context_get_source_info_by_name
pa_context_get_source_output_info
-pa_context_get_state
pa_context_set_sink_mute_by_index
pa_context_set_sink_volume_by_index
pa_context_set_source_volume_by_name
-pa_context_set_subscribe_callback
-pa_context_subscribe
+#endif
+
+/* *******************************
+ * subscribe.h
+ * *******************************/
+
+typedef struct {
+ pa_context_subscribe_cb_t cb;
+ gointer userdata;
+ GObject * context;
+ pa_subscription_mask_t mask;
+} subscribe_mask_t;
+
+static void
+subscribe_mask_free (gpointer data)
+{
+ subscribe_mask_t * mask_data = (subscribe_mask_t *)data;
+ g_object_unref(mask_data->context);
+ g_free(mask_data);
+}
+
+static gboolean
+subscribe_mask_cb (gpointer data)
+{
+ subscribe_mask_t * mask_data = (subscribe_mask_t *)data;
+ g_object_set_qdata(mask_data->context, subscribe_mask_quark, GINT_TO_POINTER(mask_data->mask));
+ mask_data->cb(mask_data->context, 1, mask_data->userdata);
+ return G_SOURCE_REMOVE;
+}
+
+pa_operation *
+pa_context_subscribe (pa_context * c, pa_subscription_mask_t mask, pa_context_success_cb_t callback, void * userdata)
+{
+ g_return_if_fail(G_IS_OBJECT(c));
+
+ subscribe_mask_t * data = g_new0(subscribe_mask_t, 1);
+ data->cb = callback;
+ data->userdata = userdata;
+ data->context = g_object_ref(G_OBJECT(c));
+ data->mask = mask;
-pa_cvolume_init
-pa_cvolume_max
-pa_cvolume_scale
-pa_cvolume_set
+ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+ subscribe_mask_cb,
+ data,
+ subscribe_mask_free);
+
+ GObject * goper = g_object_new(G_TYPE_OBJECT);
+ pa_operation * oper = (pa_operation *)goper;
+ return oper;
+}
+
+typedef struct {
+ pa_context_subscribe_cb_t cb;
+ gointer userdata;
+} subscribe_cb_t;
+
+void
+pa_context_set_subscribe_callback (pa_context * c, pa_context_subscribe_cb_t callback, void * userdata)
+{
+ g_return_if_fail(G_IS_OBJECT(c));
+
+ subscribe_cb_t * sub = g_new0(subscribe_cb_t, 1);
+ sub->cb = callback;
+ sub->userdata = userdata;
+
+ g_object_set_qdata_full(c, subscribe_cb_quark, sub, g_free);
+}
/* *******************************
* glib-mainloop.h
@@ -288,12 +397,120 @@ pa_operation_unref (pa_operation * operation)
g_object_unref(G_OBJECT(operation));
}
-pa_proplist_free
-pa_proplist_gets
-pa_proplist_new
-pa_proplist_sets
+/* *******************************
+ * proplist.h
+ * *******************************/
+
+pa_proplist *
+pa_proplist_new (void)
+{
+ return (pa_proplist *)g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+}
+
+void
+pa_proplist_free (pa_proplist * p)
+{
+ g_return_if_fail(p != NULL);
+ g_hash_table_destroy((GHashTable *)p);
+}
+
+const char *
+pa_proplist_gets (pa_proplist * p, const char * key)
+{
+ g_return_val_if_fail(p != NULL, NULL);
+ g_return_val_if_fail(key != NULL, NULL);
+ return g_hash_table_lookup((GHashTable *)p, key);
+}
+
+int
+pa_proplist_sets (pa_proplist *p, const char * key, const char * value)
+{
+ g_return_val_if_fail(p != NULL, -1);
+ g_return_val_if_fail(key != NULL, -1);
+ g_return_val_if_fail(value != NULL, -1);
-pa_strerror
+ g_hash_table_insert((GHashTable *)p, g_strdup(key), g_strdup(value));
+ return 0;
+}
-pa_sw_volume_from_dB
+/* *******************************
+ * error.h
+ * *******************************/
+
+const char *
+pa_strerror (int error)
+{
+ return "This is error text";
+}
+
+/* *******************************
+ * volume.h
+ * *******************************/
+
+pa_volume_t
+pa_sw_volume_from_dB (double f)
+{
+ double linear = pow(10.0, f / 20.0);
+ return (pa_volume_t) PA_CLAMP_VOLUME((uint64_t) lround(cbrt(linear) * PA_VOLUME_NORM));
+}
+
+pa_cvolume *
+pa_cvolume_init (pa_cvolume * cvol)
+{
+ g_return_val_if_fail(cvol != NULL, NULL);
+
+ cvol->channels = 0;
+
+ unsigned int i;
+ for (i = 0; i < PA_CHANNELS_MAX; i++)
+ cvol->values[i] = PA_VOLUME_INVALID;
+
+ return cvol;
+}
+
+pa_cvolume *
+pa_cvolume_set (pa_cvolume * cvol, unsigned channels, pa_volume_t volume)
+{
+ g_return_val_if_fail(cvol != NULL, NULL);
+ g_return_val_if_fail(channels > 0, NULL);
+ g_return_val_if_fail(channels <= PA_CHANNELS_MAX, NULL);
+
+ cvol->channels = channels;
+
+ unsigned int i;
+ for (i = 0; i < channels; i++)
+ cvol->values[i] = PA_CLAMP_VOLUME(volume);
+
+ return cvol;
+}
+
+pa_volume_t
+pa_cvolume_max (const pa_cvolume * cvol)
+{
+ g_return_val_if_fail(cvol != NULL, NULL);
+ pa_volume_t max = PA_VOLUME_MUTED;
+
+ unsigned int i;
+ for (i = 0; i < cvol->channels; i++)
+ max = MAX(max, cvol->values[i]);
+
+ return max;
+}
+
+pa_cvolume *
+pa_cvolume_scale (pa_cvolume * cvol, pa_volume_t max)
+{
+ g_return_val_if_fail(cvol != NULL, NULL);
+
+ pa_volume_t originalmax = pa_cvolume_max(cvol);
+
+ if (originalmax <= PA_VOLUME_MUTED)
+ return pa_cvolume_set(cvol, cvol->channels, max);
+
+ unsigned int i;
+ for (i = 0; i < channels; i++)
+ cvol->values[i] = PA_CLAMP_VOLUME( (cvol->values[i] * max) / originalmax );
+
+ return cvol;
+}