Diff between a2ced03a85c2d1a5687bd6e87ec3044b37b90c17 and 3f2536cb1da0c96a3f270e616f53130898bd3ead

Changed Files

File Additions Deletions Status
unit/test-gobex-transfer.c +66 -3 modified

Full Patch

diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 117ca5e..b2f6643 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -210,8 +210,6 @@ static gboolean put_rcv_data(const void *buf, gsize len, gpointer user_data)
 					"Unexpected byte count %zu", len);
 	}
 
-	g_main_loop_quit(mainloop);
-
 	return TRUE;
 }
 
@@ -233,6 +231,71 @@ static void handle_put(GObex *obex, GObexPacket *req, gpointer user_data)
 		g_main_loop_quit(mainloop);
 }
 
+static gboolean put_cli(GIOChannel *io, GIOCondition cond, gpointer user_data)
+{
+	struct test_data *d = user_data;
+	GIOStatus status;
+	gsize bytes_written, rbytes, send_buf_len, expect_len;
+	char buf[255];
+	const char *send_buf, *expect;
+
+	d->count++;
+
+	if (d->count > 1) {
+		expect = (const char *) pkt_put_rsp_last;
+		expect_len = sizeof(pkt_put_rsp_last);
+		send_buf = NULL;
+		send_buf_len = 0;
+	} else {
+		expect = (const char *) pkt_put_rsp;
+		expect_len = sizeof(pkt_put_rsp);
+		send_buf = (const char *) pkt_put_last;
+		send_buf_len = sizeof(pkt_put_last);
+	}
+
+	status = g_io_channel_read_chars(io, buf, sizeof(buf), &rbytes, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		g_print("put_cli count %u\n", d->count);
+		g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+				"Reading data failed with status %d", status);
+		goto failed;
+	}
+
+	if (rbytes < expect_len) {
+		g_print("put_cli count %u\n", d->count);
+		dump_bufs(expect, expect_len, buf, rbytes);
+		g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+					"Not enough data from socket");
+		goto failed;
+	}
+
+	if (memcmp(buf, expect, expect_len) != 0) {
+		g_print("put_cli count %u\n", d->count);
+		dump_bufs(expect, expect_len, buf, rbytes);
+		g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+					"Received data is not correct");
+		goto failed;
+	}
+
+	if (send_buf == NULL)
+		return TRUE;
+
+	g_io_channel_write_chars(io, send_buf, send_buf_len, &bytes_written,
+									NULL);
+	if (bytes_written != send_buf_len) {
+		g_print("put_cli count %u\n", d->count);
+		g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+						"Unable to write to socket");
+		goto failed;
+	}
+
+	return TRUE;
+
+failed:
+	g_main_loop_quit(mainloop);
+	return FALSE;
+}
+
 static void test_put_rsp(void)
 {
 	GIOChannel *io;
@@ -244,7 +307,7 @@ static void test_put_rsp(void)
 	create_endpoints(&obex, &io, SOCK_STREAM);
 
 	cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
-	io_id = g_io_add_watch(io, cond, put_srv, &d);
+	io_id = g_io_add_watch(io, cond, put_cli, &d);
 
 	mainloop = g_main_loop_new(NULL, FALSE);