All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcin Kraglak <marcin.kraglak@tieto.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 4/9] unit/test_hfp_at: Add test cases for processing basic commands
Date: Tue, 25 Feb 2014 10:23:42 +0100	[thread overview]
Message-ID: <1393320227-10931-5-git-send-email-marcin.kraglak@tieto.com> (raw)
In-Reply-To: <1393320227-10931-1-git-send-email-marcin.kraglak@tieto.com>

It will test processing basic commands including S-parameter commands,
D-commands.
---
 unit/test-hfp-at.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 252 insertions(+)

diff --git a/unit/test-hfp-at.c b/unit/test-hfp-at.c
index 4374a70..9cb716d 100644
--- a/unit/test-hfp-at.c
+++ b/unit/test-hfp-at.c
@@ -33,6 +33,9 @@
 
 struct test_data {
 	const struct hfp_at_handler *handlers;
+	const char *process_data;
+	bool process_return_val;
+	enum hfp_cmd_type returned_type;
 };
 
 static void test_init(gconstpointer data)
@@ -46,9 +49,27 @@ static void test_init(gconstpointer data)
 	hfp_at_free(hfp_at);
 }
 
+static void test_process_data(gconstpointer data)
+{
+	struct hfp_at *hfp_at;
+	const struct test_data *test_data = data;
+	bool ret;
+
+	hfp_at = hfp_at_new(test_data->handlers);
+	g_assert(hfp_at != NULL);
+
+	ret = hfp_at_process_data(hfp_at, test_data->process_data,
+							(void *)test_data);
+	g_assert(ret == test_data->process_return_val);
+
+	hfp_at_free(hfp_at);
+}
+
 static void process_generic(struct hfp_at *hfp_at, enum hfp_cmd_type type,
 						const char *at, void *user_data)
 {
+	struct test_data *test_data = user_data;
+	g_assert(type == test_data->returned_type);
 }
 
 const struct hfp_at_handler handlers_1[] = {};
@@ -62,8 +83,63 @@ const struct hfp_at_handler handlers_2[] = {
 
 const struct hfp_at_handler handlers_3[] = {
 	{
+		.prefix = NULL,
+		.cb = process_generic
+	},
+	{
 		.prefix = "+BRSF",
 		.cb = process_generic
+	}
+};
+
+const struct hfp_at_handler handlers_4[] = {
+	{
+		.prefix = "S12",
+		.cb = process_generic
+	},
+	{
+		.prefix = NULL,
+		.cb = process_generic
+	}
+};
+
+const struct hfp_at_handler handlers_5[] = {
+	{
+		.prefix = "S12",
+		.cb = process_generic
+	},
+	{
+		.prefix = NULL,
+		.cb = process_generic
+	}
+};
+
+const struct hfp_at_handler handlers_6[] = {
+	{
+		.prefix = "D",
+		.cb = process_generic
+	},
+	{
+		.prefix = NULL,
+		.cb = process_generic
+	}
+};
+
+const struct hfp_at_handler handlers_7[] = {
+	{
+		.prefix = "&A",
+		.cb = process_generic
+	},
+	{
+		.prefix = NULL,
+		.cb = process_generic
+	}
+};
+
+const struct hfp_at_handler handlers_8[] = {
+	{
+		.prefix = "A",
+		.cb = process_generic
 	},
 	{
 		.prefix = NULL,
@@ -83,6 +159,136 @@ const struct test_data data_3 = {
 	.handlers = handlers_3,
 };
 
+const struct test_data prefix_S_1_data = {
+	.handlers = handlers_4,
+	.process_data = "ATS12=12,6",
+	.process_return_val = true,
+	.returned_type = HFP_AT_SET
+};
+
+const struct test_data prefix_S_2_data = {
+	.handlers = handlers_4,
+	.process_data = "ATS12=?12,6",
+	.process_return_val = true,
+	.returned_type = HFP_AT_TEST
+};
+
+const struct test_data prefix_S_3_data = {
+	.handlers = handlers_4,
+	.process_data = "ATS12?",
+	.process_return_val = true,
+	.returned_type = HFP_AT_READ
+};
+
+const struct test_data prefix_S_4_data = {
+	.handlers = handlers_4,
+	.process_data = "ATS12",
+	.process_return_val = true,
+	.returned_type = HFP_AT_COMMAND
+};
+
+const struct test_data prefix_S_5_data = {
+	.handlers = handlers_5,
+	.process_data = "ATS1",
+	.process_return_val = true,
+	.returned_type = HFP_AT_UNKNOWN
+};
+
+const struct test_data prefix_D_1_data = {
+	.handlers = handlers_5,
+	.process_data = "ATD0046131415",
+	.process_return_val = true,
+	.returned_type = HFP_AT_UNKNOWN
+};
+
+const struct test_data prefix_D_2_data = {
+	.handlers = handlers_6,
+	.process_data = "ATD0046131415",
+	.process_return_val = true,
+	.returned_type = HFP_AT_SET
+};
+
+const struct test_data prefix_D_3_data = {
+	.handlers = handlers_2,
+	.process_data = "ATD0046131415",
+	.process_return_val = true,
+	.returned_type = HFP_AT_UNKNOWN
+};
+
+const struct test_data prefix_anda_1_data = {
+	.handlers = handlers_7,
+	.process_data = "AT&A=12",
+	.process_return_val = true,
+	.returned_type = HFP_AT_SET
+};
+
+const struct test_data prefix_anda_2_data = {
+	.handlers = handlers_7,
+	.process_data = "AT&A=?12",
+	.process_return_val = true,
+	.returned_type = HFP_AT_TEST
+};
+
+const struct test_data prefix_anda_3_data = {
+	.handlers = handlers_7,
+	.process_data = "AT&A?12",
+	.process_return_val = true,
+	.returned_type = HFP_AT_READ
+};
+
+const struct test_data prefix_anda_4_data = {
+	.handlers = handlers_7,
+	.process_data = "AT&A",
+	.process_return_val = true,
+	.returned_type = HFP_AT_COMMAND
+};
+
+const struct test_data prefix_a_1_data = {
+	.handlers = handlers_8,
+	.process_data = "ATA",
+	.process_return_val = true,
+	.returned_type = HFP_AT_COMMAND
+};
+
+const struct test_data prefix_a_2_data = {
+	.handlers = handlers_8,
+	.process_data = "ATA=12",
+	.process_return_val = true,
+	.returned_type = HFP_AT_SET
+};
+
+const struct test_data prefix_a_3_data = {
+	.handlers = handlers_8,
+	.process_data = "ATA=?12",
+	.process_return_val = true,
+	.returned_type = HFP_AT_TEST
+};
+
+const struct test_data prefix_a_4_data = {
+	.handlers = handlers_8,
+	.process_data = "ATA?",
+	.process_return_val = true,
+	.returned_type = HFP_AT_READ
+};
+
+const struct test_data invalid_command_1_data = {
+	.handlers = handlers_2,
+	.process_data = "AYA?",
+	.process_return_val = false,
+};
+
+const struct test_data invalid_command_2_data = {
+	.handlers = handlers_2,
+	.process_data = "AT?",
+	.process_return_val = false,
+};
+
+const struct test_data invalid_command_3_data = {
+	.handlers = handlers_2,
+	.process_data = "AT",
+	.process_return_val = false,
+};
+
 int main(int argc, char *argv[])
 {
 	g_test_init(&argc, &argv, NULL);
@@ -90,6 +296,52 @@ int main(int argc, char *argv[])
 	g_test_add_data_func("/hfp_at/init_1", &data_1, test_init);
 	g_test_add_data_func("/hfp_at/init_2", &data_2, test_init);
 	g_test_add_data_func("/hfp_at/init_3", &data_3, test_init);
+	/* Basic commands tests */
+	g_test_add_data_func("/hfp_at/prefix_S_1", &prefix_S_1_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_S_2", &prefix_S_2_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_S_3", &prefix_S_3_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_S_4", &prefix_S_4_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_S_5", &prefix_S_5_data,
+							test_process_data);
+
+	g_test_add_data_func("/hfp_at/prefix_D_1", &prefix_D_1_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_D_2", &prefix_D_2_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_D_3", &prefix_D_3_data,
+							test_process_data);
+
+	g_test_add_data_func("/hfp_at/prefix_&A_1", &prefix_anda_1_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_&A_2", &prefix_anda_2_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_&A_3", &prefix_anda_3_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_&A_4", &prefix_anda_4_data,
+							test_process_data);
+
+	g_test_add_data_func("/hfp_at/prefix_A_1", &prefix_a_1_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_A_1", &prefix_a_2_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_A_1", &prefix_a_3_data,
+							test_process_data);
+	g_test_add_data_func("/hfp_at/prefix_A_1", &prefix_a_4_data,
+							test_process_data);
+
+	g_test_add_data_func("/hfp_at/invalid_command_1",
+					&invalid_command_1_data,
+					test_process_data);
+	g_test_add_data_func("/hfp_at/invalid_command_2",
+					&invalid_command_2_data,
+					test_process_data);
+	g_test_add_data_func("/hfp_at/invalid_command_3",
+					&invalid_command_3_data,
+					test_process_data);
 
 	return g_test_run();
 }
-- 
1.8.5.3


  parent reply	other threads:[~2014-02-25  9:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-25  9:23 [PATCH 0/9] HFP AT parser skeleton Marcin Kraglak
2014-02-25  9:23 ` [PATCH 1/9] shared: Add skeleton of hfp_at parser Marcin Kraglak
2014-02-25 18:46   ` Marcel Holtmann
2014-02-25  9:23 ` [PATCH 2/9] unit: Add hfp_at tester Marcin Kraglak
2014-02-25  9:23 ` [PATCH 3/9] shared/hfp_at: Add skeleton of hfp_at_process_data Marcin Kraglak
2014-02-25 18:56   ` Marcel Holtmann
2014-02-25  9:23 ` Marcin Kraglak [this message]
2014-02-25  9:23 ` [PATCH 5/9] shared/hfp_at: Add function for getting number Marcin Kraglak
2014-02-25  9:23 ` [PATCH 6/9] shared/hfp_at: Add function to open container Marcin Kraglak
2014-02-25  9:23 ` [PATCH 7/9] shared/hfp_at: Add function to close container Marcin Kraglak
2014-02-25  9:23 ` [PATCH 8/9] shared/hfp_at: Add function to get string Marcin Kraglak
2014-02-25  9:23 ` [PATCH 9/9] shared/hfp_at: Add function to get unquoted string Marcin Kraglak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393320227-10931-5-git-send-email-marcin.kraglak@tieto.com \
    --to=marcin.kraglak@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.