summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2011-07-26 10:05:41 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2011-07-27 13:38:26 +0100
commit1051de8fc4fdb26ed08f7029a1ff9a571775708c (patch)
tree14057a8a6d0f9c651cc531d39cc0c3082c9f756e
parent502a365c34c9b684bb586e0761c0ce762fcd5d2b (diff)
Add an incomplete write mode to the test-stream
To stress the various bit of code a bit more, make writes by default never succeed completely. Only write half the buffer that is given to us as this causes some more code-paths to be tested. Unfortunately some tests seem to be too sensitive to this. So switch them back to the old write mode.
-rw-r--r--tests/wocky-porter-test.c10
-rw-r--r--tests/wocky-test-stream.c18
-rw-r--r--tests/wocky-test-stream.h10
3 files changed, 34 insertions, 4 deletions
diff --git a/tests/wocky-porter-test.c b/tests/wocky-porter-test.c
index 9c6111a..ca64f0f 100644
--- a/tests/wocky-porter-test.c
+++ b/tests/wocky-porter-test.c
@@ -648,8 +648,10 @@ test_close_cancel (void)
{
test_data_t *test = setup_test ();
- test_open_both_connections (test);
+ wocky_test_stream_set_write_mode (test->stream->stream0_output,
+ WOCKY_TEST_STREAM_WRITE_COMPLETE);
+ test_open_both_connections (test);
wocky_porter_start (test->sched_out);
wocky_xmpp_connection_recv_stanza_async (test->in, NULL,
@@ -2352,6 +2354,9 @@ test_close_error (void)
{
test_data_t *test = setup_test ();
+ wocky_test_stream_set_write_mode (test->stream->stream0_output,
+ WOCKY_TEST_STREAM_WRITE_COMPLETE);
+
test_open_both_connections (test);
wocky_porter_start (test->sched_in);
@@ -2552,6 +2557,9 @@ test_close_force (void)
test_data_t *test = setup_test ();
WockyStanza *s;
+ wocky_test_stream_set_write_mode (test->stream->stream0_output,
+ WOCKY_TEST_STREAM_WRITE_COMPLETE);
+
test_open_both_connections (test);
wocky_porter_start (test->sched_in);
diff --git a/tests/wocky-test-stream.c b/tests/wocky-test-stream.c
index 1f955a1..007fb8a 100644
--- a/tests/wocky-test-stream.c
+++ b/tests/wocky-test-stream.c
@@ -52,6 +52,7 @@ typedef struct {
typedef struct {
GOutputStream parent;
GAsyncQueue *queue;
+ WockyTestStreamWriteMode mode;
GError *write_error /* no, this is not a coding style violation */;
gboolean dispose_has_run;
} WockyTestOutputStream;
@@ -473,6 +474,10 @@ wocky_test_output_stream_write (GOutputStream *stream, const void *buffer,
{
WockyTestOutputStream *self = WOCKY_TEST_OUTPUT_STREAM (stream);
GArray *data;
+ gsize written = count;
+
+ if (self->mode == WOCKY_TEST_STREAM_WRITE_INCOMPLETE)
+ written = MAX (count/2, 1);
if (self->write_error != NULL)
{
@@ -481,14 +486,14 @@ wocky_test_output_stream_write (GOutputStream *stream, const void *buffer,
return -1;
}
- data = g_array_sized_new (FALSE, FALSE, sizeof (guint8), count);
+ data = g_array_sized_new (FALSE, FALSE, sizeof (guint8), written);
- g_array_insert_vals (data, 0, buffer, count);
+ g_array_insert_vals (data, 0, buffer, written);
g_async_queue_push (self->queue, data);
g_signal_emit (self, output_signals[OUTPUT_DATA_WRITTEN], 0);
- return count;
+ return written;
}
static void
@@ -639,3 +644,10 @@ wocky_test_stream_cork (GInputStream *stream,
wocky_test_input_stream_try_read (tstream);
}
+
+void
+wocky_test_stream_set_write_mode (GOutputStream *stream,
+ WockyTestStreamWriteMode mode)
+{
+ WOCKY_TEST_OUTPUT_STREAM (stream)->mode = mode;
+}
diff --git a/tests/wocky-test-stream.h b/tests/wocky-test-stream.h
index e084cde..b37a678 100644
--- a/tests/wocky-test-stream.h
+++ b/tests/wocky-test-stream.h
@@ -80,9 +80,19 @@ typedef enum {
WOCK_TEST_STREAM_READ_EXACT,
} WockyTestSTreamReadMode;
+typedef enum {
+ /* all writes are only half-done, default */
+ WOCKY_TEST_STREAM_WRITE_INCOMPLETE = 0,
+ /* Always succeed in writing everything */
+ WOCKY_TEST_STREAM_WRITE_COMPLETE = 1,
+} WockyTestStreamWriteMode;
+
void wocky_test_stream_set_mode (GInputStream *stream,
WockyTestSTreamReadMode mode);
+void wocky_test_stream_set_write_mode (GOutputStream *stream,
+ WockyTestStreamWriteMode mode);
+
G_END_DECLS
#endif /* #ifndef __WOCKY_TEST_STREAM_H__*/