summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang Gu <yang.gu@intel.com>2010-05-13 18:48:25 +0800
committerDenis Kenzior <denkenz@gmail.com>2010-05-13 13:45:59 -0500
commitd04ebc0fdb132bb8bf2607e22d839b7096b032eb (patch)
treec0613f992058a2cb06fe98fb8d43aca0ed72ef09
parentb99bf23f1914599e2b13eaff63107ffc5bee4cff (diff)
downloadofono-d04ebc0fdb132bb8bf2607e22d839b7096b032eb.tar.bz2
test-stkutil: Refactor test for send sms parser
-rw-r--r--unit/test-stkutil.c132
1 files changed, 84 insertions, 48 deletions
diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c
index 60f1d7a0..d319a357 100644
--- a/unit/test-stkutil.c
+++ b/unit/test-stkutil.c
@@ -71,6 +71,27 @@ static inline void check_common_text(const char *command, const char *test)
g_assert(g_str_equal(command, test));
}
+static inline void check_common_byte_array(
+ const struct stk_common_byte_array *command,
+ const struct stk_common_byte_array *test)
+{
+ if (test->len == 0) {
+ g_assert(command->len == 0);
+ return;
+ }
+
+ g_assert(command->len != 0);
+ g_assert(g_mem_equal(command->array, test->array, test->len));
+}
+
+/* Defined in TS 102.223 Section 8.1 */
+static inline void check_address(const struct stk_address *command,
+ const struct stk_address *test)
+{
+ g_assert(command->ton_npi == test->ton_npi);
+ g_assert(g_str_equal(command->number, test->number));
+}
+
/* Defined in TS 102.223 Section 8.2 */
static inline void check_alpha_id(const char *command, const char *test)
{
@@ -126,6 +147,18 @@ static void check_response_length(const struct stk_response_length *command,
g_assert(command->max == test->max);
}
+/* Defined in TS 102.223 Section 8.13 */
+static void check_gsm_sms_tpdu(const struct sms *command,
+ const struct sms *test)
+{
+ g_assert(command->submit.mr == test->submit.mr);
+ g_assert(command->submit.udl == test->submit.udl);
+ g_assert(g_str_equal(command->submit.daddr.address,
+ test->submit.daddr.address));
+ g_assert(g_mem_equal(command->submit.ud, test->submit.ud,
+ test->submit.udl));
+}
+
/* Defined in TS 102.223 Section 8.15 */
static inline void check_text(const char *command, const char *test)
{
@@ -178,6 +211,14 @@ static inline void check_imm_resp(const unsigned char command,
check_common_byte(command, test);
}
+/* Defined in TS 102.223 Section 8.71 */
+static inline void check_cdma_sms_tpdu(
+ const struct stk_common_byte_array *command,
+ const struct stk_common_byte_array *test)
+{
+ check_common_byte_array(command, test);
+}
+
/* Defined in TS 102.223 Section 8.72 */
static void check_text_attr(const struct stk_text_attribute *command,
const struct stk_text_attribute *test)
@@ -7449,45 +7490,51 @@ struct send_sms_test {
const unsigned char *pdu;
unsigned int pdu_len;
unsigned char qualifier;
- const char *alpha_id;
- unsigned char ton_npi;
- const char *address;
- unsigned char sms_mr;
- const char *sms_address;
- unsigned char sms_udl;
- const char *sms_ud;
+ char *alpha_id;
+ struct stk_address address;
+ struct sms gsm_sms;
+ struct stk_common_byte_array cdma_sms;
+ struct stk_icon_id icon_id;
+ struct stk_text_attribute text_attr;
+ struct stk_frame_id frame_id;
};
/* 3GPP TS 31.124 Section 27.22.4.10.1.4.2 */
-static unsigned char send_sms_11[] = { 0xD0, 0x37, 0x81, 0x03, 0x01, 0x13, 0x00,
- 0x82, 0x02, 0x81, 0x83, 0x85, 0x07,
- 0x53, 0x65, 0x6E, 0x64, 0x20, 0x53,
- 0x4D, 0x86, 0x09, 0x91, 0x11, 0x22,
- 0x33, 0x44, 0x55, 0x66, 0x77, 0xF8,
- 0x8B, 0x18, 0x01, 0x00, 0x09, 0x91,
- 0x10, 0x32, 0x54, 0x76, 0xF8, 0x40,
- 0xF4, 0x0C, 0x54, 0x65, 0x73, 0x74,
- 0x20, 0x4D, 0x65, 0x73, 0x73, 0x61,
- 0x67, 0x65 };
-
-static struct send_sms_test send_sms_data_11 = {
- .pdu = send_sms_11,
- .pdu_len = sizeof(send_sms_11),
+static unsigned char send_sms_111[] = { 0xD0, 0x37, 0x81, 0x03, 0x01, 0x13,
+ 0x00, 0x82, 0x02, 0x81, 0x83, 0x85,
+ 0x07, 0x53, 0x65, 0x6E, 0x64, 0x20,
+ 0x53, 0x4D, 0x86, 0x09, 0x91, 0x11,
+ 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0xF8, 0x8B, 0x18, 0x01, 0x00, 0x09,
+ 0x91, 0x10, 0x32, 0x54, 0x76, 0xF8,
+ 0x40, 0xF4, 0x0C, 0x54, 0x65, 0x73,
+ 0x74, 0x20, 0x4D, 0x65, 0x73, 0x73,
+ 0x61, 0x67, 0x65 };
+
+static struct send_sms_test send_sms_data_111 = {
+ .pdu = send_sms_111,
+ .pdu_len = sizeof(send_sms_111),
.qualifier = 0x00,
.alpha_id = "Send SM",
- .ton_npi = 0x91,
- .address = "112233445566778",
- .sms_mr = 0x00,
- .sms_address = "012345678",
- .sms_udl = 12,
- .sms_ud = "Test Message",
+ .address = {
+ .ton_npi = 0x91,
+ .number = "112233445566778"
+ },
+ .gsm_sms = {
+ {}, SMS_TYPE_SUBMIT,
+ {.submit = {
+ .mr = 0x00,
+ .daddr.address = "012345678",
+ .udl = 12,
+ .ud = "Test Message"
+ } }
+ }
};
static void test_send_sms(gconstpointer data)
{
const struct send_sms_test *test = data;
struct stk_command *command;
- int i;
command = stk_command_new_from_pdu(test->pdu, test->pdu_len);
@@ -7500,24 +7547,13 @@ static void test_send_sms(gconstpointer data)
g_assert(command->src == STK_DEVICE_IDENTITY_TYPE_UICC);
g_assert(command->dst == STK_DEVICE_IDENTITY_TYPE_NETWORK);
- if (test->alpha_id)
- g_assert(g_str_equal(test->alpha_id,
- command->send_sms.alpha_id));
-
- if (test->address) {
- g_assert(test->ton_npi == command->send_sms.address.ton_npi);
- g_assert(g_str_equal(test->address,
- command->send_sms.address.number));
- }
-
- g_assert(test->sms_mr == command->send_sms.gsm_sms.submit.mr);
- g_assert(test->sms_udl == command->send_sms.gsm_sms.submit.udl);
- g_assert(g_str_equal(test->sms_address,
- command->send_sms.gsm_sms.submit.daddr.address));
-
- for (i = 0; i < test->sms_udl; i++)
- g_assert(test->sms_ud[i] ==
- command->send_sms.gsm_sms.submit.ud[i]);
+ check_alpha_id(command->send_sms.alpha_id, test->alpha_id);
+ check_address(&command->send_sms.address, &test->address);
+ check_gsm_sms_tpdu(&command->send_sms.gsm_sms, &test->gsm_sms);
+ check_cdma_sms_tpdu(&command->send_sms.cdma_sms, &test->cdma_sms);
+ check_icon_id(&command->select_item.icon_id, &test->icon_id);
+ check_text_attr(&command->select_item.text_attr, &test->text_attr);
+ check_frame_id(&command->select_item.frame_id, &test->frame_id);
stk_command_free(command);
}
@@ -8054,8 +8090,8 @@ int main(int argc, char **argv)
g_test_add_data_func("/teststk/Select Item 12.3.1",
&select_item_data_1231, test_select_item);
- g_test_add_data_func("/teststk/Send SMS 1.1",
- &send_sms_data_11, test_send_sms);
+ g_test_add_data_func("/teststk/Send SMS 1.1.1",
+ &send_sms_data_111, test_send_sms);
return g_test_run();
}