* [PATCH] unit: Update test_invalid() unit test
@ 2012-07-18 15:13 Guillaume Zajac
2012-07-18 15:17 ` Guillaume Zajac
0 siblings, 1 reply; 2+ messages in thread
From: Guillaume Zajac @ 2012-07-18 15:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1541 bytes --]
---
unit/test-util.c | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/unit/test-util.c b/unit/test-util.c
index 079d775..f65f3ee 100644
--- a/unit/test-util.c
+++ b/unit/test-util.c
@@ -345,7 +345,9 @@ static void test_invalid(void)
{
long nwritten;
long nread;
- char *res;
+ short unsigned int exp_code;
+ long exp_res_length;
+ char *res, *temp, *exp_res = NULL;
unsigned char *gsm;
res = convert_gsm_to_utf8(invalid_gsm_extended, 0, &nread, &nwritten,
@@ -356,15 +358,34 @@ static void test_invalid(void)
g_assert(res[0] == '\0');
g_free(res);
+ /*
+ * In case of invalid GSM extended code, we should display
+ * the character of the main default alphabet table.
+ */
res = convert_gsm_to_utf8(invalid_gsm_extended,
sizeof(invalid_gsm_extended),
&nread, &nwritten, 0);
- g_assert(res == NULL);
- g_assert(nread == 1);
+
+ exp_code = gsm_to_unicode_map[invalid_gsm_extended[1]*2 + 1];
+
+ exp_res_length = UTF8_LENGTH(exp_code);
+ exp_res = g_try_malloc(exp_res_length + 1);
+
+ g_assert(exp_res != NULL);
+
+ temp = exp_res;
+ temp += g_unichar_to_utf8(exp_code, temp);
+ *temp = '\0';
+
+ g_assert(g_strcmp0(res, exp_res) == 0);
+ g_assert(nread == exp_res_length);
+ g_free(exp_res);
+ g_free(res);
res = convert_gsm_to_utf8(invalid_gsm_extended_len,
sizeof(invalid_gsm_extended_len),
&nread, &nwritten, 0);
+
g_assert(res == NULL);
g_assert(nread == 3);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] unit: Update test_invalid() unit test
2012-07-18 15:13 [PATCH] unit: Update test_invalid() unit test Guillaume Zajac
@ 2012-07-18 15:17 ` Guillaume Zajac
0 siblings, 0 replies; 2+ messages in thread
From: Guillaume Zajac @ 2012-07-18 15:17 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1824 bytes --]
Hi,
On 18/07/2012 17:13, Guillaume Zajac wrote:
> ---
> unit/test-util.c | 27 ++++++++++++++++++++++++---
> 1 files changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/unit/test-util.c b/unit/test-util.c
> index 079d775..f65f3ee 100644
> --- a/unit/test-util.c
> +++ b/unit/test-util.c
> @@ -345,7 +345,9 @@ static void test_invalid(void)
> {
> long nwritten;
> long nread;
> - char *res;
> + short unsigned int exp_code;
> + long exp_res_length;
> + char *res, *temp, *exp_res = NULL;
> unsigned char *gsm;
>
> res = convert_gsm_to_utf8(invalid_gsm_extended, 0, &nread, &nwritten,
> @@ -356,15 +358,34 @@ static void test_invalid(void)
> g_assert(res[0] == '\0');
> g_free(res);
>
> + /*
> + * In case of invalid GSM extended code, we should display
> + * the character of the main default alphabet table.
> + */
> res = convert_gsm_to_utf8(invalid_gsm_extended,
> sizeof(invalid_gsm_extended),
> &nread, &nwritten, 0);
> - g_assert(res == NULL);
> - g_assert(nread == 1);
> +
> + exp_code = gsm_to_unicode_map[invalid_gsm_extended[1]*2 + 1];
> +
> + exp_res_length = UTF8_LENGTH(exp_code);
> + exp_res = g_try_malloc(exp_res_length + 1);
> +
> + g_assert(exp_res != NULL);
> +
> + temp = exp_res;
> + temp += g_unichar_to_utf8(exp_code, temp);
> + *temp = '\0';
> +
> + g_assert(g_strcmp0(res, exp_res) == 0);
> + g_assert(nread == exp_res_length);
> + g_free(exp_res);
> + g_free(res);
>
> res = convert_gsm_to_utf8(invalid_gsm_extended_len,
> sizeof(invalid_gsm_extended_len),
> &nread, &nwritten, 0);
> +
I added blank line although I shouldn't have done it.
I will send a new version.
> g_assert(res == NULL);
> g_assert(nread == 3);
>
Kind regards,
Guillaume
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-07-18 15:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18 15:13 [PATCH] unit: Update test_invalid() unit test Guillaume Zajac
2012-07-18 15:17 ` Guillaume Zajac
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.