From c53bfdaf561dd289b566dd495945fb093919f9f2 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Tue, 13 Jul 2010 05:40:48 -0700 Subject: [PATCH] test-stkutil: add unit test for html text attributes --- unit/test-stkutil.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c index dbd5b5e..2a56259 100644 --- a/unit/test-stkutil.c +++ b/unit/test-stkutil.c @@ -478,6 +478,29 @@ static inline void check_cdma_sms_tpdu( check_common_byte_array(command, test); } +static void check_text_attr_html(const struct stk_text_attribute *test, + char *text, const char *expected_html) +{ + char *html; + unsigned short attrs[256]; + int i; + + if (expected_html == NULL) + return; + + for (i = 0; i < test->len; i += 4) { + attrs[i] = test->attributes[i]; + attrs[i + 1] = test->attributes[i + 1]; + attrs[i + 2] = test->attributes[i + 2]; + attrs[i + 3] = test->attributes[i + 3]; + } + html = stk_text_to_html(text, attrs, test->len / 4); + + g_assert(memcmp(html, expected_html, strlen(expected_html)) == 0); + + g_free(html); +} + /* 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) @@ -22139,6 +22162,70 @@ static const struct envelope_test timer_expiration_data_221a = { }, }; +struct html_attr_test { + char *text; + struct stk_text_attribute text_attr; + char *html; +}; + +static struct html_attr_test html_attr_data_1 = { + .text = "Blue green green green", + .text_attr = { + .len = 8, + .attributes = { 0x00, 0x00, 0x03, 0x94, 0x00, 0x04, 0x03, + 0x96 }, + }, + .html = "" + "Blue green green green", +}; + +static struct html_attr_test html_attr_data_2 = { + .text = "abc", + .text_attr = { + .len = 8, + .attributes = { 0x00, 0x02, 0x03, 0x94, 0x01, 0x02, 0x03, + 0x96 }, + }, + .html = "" + "abc", +}; + +static struct html_attr_test html_attr_data_3 = { + .text = "1 < 2, 2 > 1, 1 & 0 == 0\nSpecial Chars are Fun\r\nTo Write", + .text_attr = { + .len = 4, + .attributes = { 0x00, 0x00, 0x03, 0x00 }, + }, + .html = "1 < 2, 2 > 1, 1 & 0 == 0
Special Chars are Fun" + "
To Write", +}; + +static struct html_attr_test html_attr_data_4 = { + .text = "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€", + .text_attr = { + .len = 4, + .attributes = { 0x00, 0x00, 0x03, 0x94 }, + }, + .html = "" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€" + "€€€€€€€€€€€€€€€", +}; + +static void test_html_attr(gconstpointer data) +{ + const struct html_attr_test *test = data; + check_text_attr_html(&test->text_attr, test->text, test->html); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -24146,5 +24233,14 @@ int main(int argc, char **argv) g_test_add_data_func("/teststk/Timer Expiration 2.2.1A", &timer_expiration_data_221a, test_envelope_encoding); + g_test_add_data_func("/teststk/HTML Attribute Test 1", + &html_attr_data_1, test_html_attr); + g_test_add_data_func("/teststk/HTML Attribute Test 2", + &html_attr_data_2, test_html_attr); + g_test_add_data_func("/teststk/HTML Attribute Test 3", + &html_attr_data_3, test_html_attr); + g_test_add_data_func("/teststk/HTML Attribute Test 4", + &html_attr_data_4, test_html_attr); + return g_test_run(); } -- 2.7.4