[PATCH 04/22] unit: Add test case for cbuffer's manual mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Test cbuffers direct memory access functionality.
---
 unit/test-cbuffer.c |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/unit/test-cbuffer.c b/unit/test-cbuffer.c
index 4af73b8..5a3482d 100644
--- a/unit/test-cbuffer.c
+++ b/unit/test-cbuffer.c
@@ -167,6 +167,39 @@ static void cbt_drain(struct cbt_fixture *fix, gconstpointer test_data)
 	g_assert_cmpint(cbuffer_is_empty(fix->cbuff), >, 0);
 }
 
+/* test cbuffer's manual mode */
+static void cbt_manual(struct cbt_fixture *fix, gconstpointer test_data)
+{
+	char ch = 1;
+	char *inbuffer = NULL;
+
+	inbuffer = cbuffer_get_free_cell(fix->cbuff);
+	g_assert(cbuffer_is_empty(fix->cbuff));
+	g_assert(inbuffer != NULL);
+
+	/* write directly to buffers memory */
+	if (inbuffer)
+		*inbuffer = 'a';
+
+	/* mark cell as written */
+	g_assert_cmpint(cbuffer_consume_next_cell(fix->cbuff),
+			>=, 0);
+	inbuffer = NULL;
+	inbuffer = cbuffer_get_free_cell(fix->cbuff);
+	g_assert(inbuffer != NULL);
+
+	if (inbuffer)
+		*inbuffer = 'b';
+
+	g_assert_cmpint(cbuffer_consume_next_cell(fix->cbuff),
+			>=, 0);
+	cbuffer_read(fix->cbuff, &ch);
+	g_assert_cmpint('a', ==, ch);
+	cbuffer_read(fix->cbuff, &ch);
+	g_assert_cmpint('b', ==, ch);
+	g_assert(cbuffer_is_empty(fix->cbuff));
+}
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
@@ -182,5 +215,7 @@ int main(int argc, char **argv)
 			cbt_overflow, cbt_fix_teardown);
 	g_test_add("/cbuffer/drain", struct cbt_fixture, 0, cbt_fix_setup,
 			cbt_drain, cbt_fix_teardown);
+	g_test_add("/cbuffer/manual", struct cbt_fixture, 0, cbt_fix_setup,
+			cbt_manual, cbt_fix_teardown);
 	return g_test_run();
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux