summaryrefslogtreecommitdiff
path: root/src/tests/test-sms-part-3gpp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test-sms-part-3gpp.c')
-rw-r--r--src/tests/test-sms-part-3gpp.c167
1 files changed, 100 insertions, 67 deletions
diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c
index 21822f09..4da299e7 100644
--- a/src/tests/test-sms-part-3gpp.c
+++ b/src/tests/test-sms-part-3gpp.c
@@ -24,24 +24,7 @@
#include <libmm-glib.h>
#include "mm-sms-part-3gpp.h"
-#include "mm-log.h"
-
-/* If defined will print debugging traces */
-#ifdef TEST_SMS_PART_ENABLE_TRACE
-#define trace_pdu(pdu, pdu_len) do { \
- guint i; \
- \
- g_print ("\n "); \
- for (i = 0; i < len; i++) { \
- g_print (" 0x%02X", pdu[i]); \
- if (((i + 1) % 12) == 0) \
- g_print ("\n "); \
- } \
- g_print ("\n"); \
- } while (0)
-#else
-#define trace_pdu(...)
-#endif
+#include "mm-log-test.h"
/********************* PDU PARSER TESTS *********************/
@@ -58,7 +41,7 @@ common_test_part_from_hexpdu (const gchar *hexpdu,
MMSmsPart *part;
GError *error = NULL;
- part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, &error);
+ part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, NULL, &error);
g_assert_no_error (error);
g_assert (part != NULL);
@@ -136,7 +119,7 @@ test_pdu1 (void)
pdu, sizeof (pdu),
"+12404492164", /* smsc */
"+16175927198", /* number */
- "110228115050-05", /* timestamp */
+ "2011-02-28T11:50:50-05", /* timestamp */
FALSE,
"Here's a longer message [{with some extended characters}] "
"thrown in, such as £ and ΩΠΨ and §¿ as well.", /* text */
@@ -157,7 +140,7 @@ test_pdu2 (void)
pdu, sizeof (pdu),
"+79037011111", /* smsc */
"InternetSMS", /* number */
- "110329192004+04", /* timestamp */
+ "2011-03-29T19:20:04+04", /* timestamp */
FALSE,
"тест", /* text */
NULL, 0);
@@ -177,7 +160,7 @@ test_pdu3 (void)
pdu, sizeof (pdu),
"+12345678901", /* smsc */
"+18005551212", /* number */
- "110101123456+00", /* timestamp */
+ "2011-01-01T12:34:56Z", /* timestamp */
FALSE,
"hellohello", /* text */
NULL, 0);
@@ -198,7 +181,7 @@ test_pdu3_nzpid (void)
pdu, sizeof (pdu),
"+12345678901", /* smsc */
"+18005551212", /* number */
- "110101123456+00", /* timestamp */
+ "2011-01-01T12:34:56Z", /* timestamp */
FALSE,
"hellohello", /* text */
NULL, 0);
@@ -219,7 +202,7 @@ test_pdu3_mms (void)
pdu, sizeof (pdu),
"+12345678901", /* smsc */
"+18005551212", /* number */
- "110101123456+00", /* timestamp */
+ "2011-01-01T12:34:56Z", /* timestamp */
FALSE,
"hellohello", /* text */
NULL, 0);
@@ -240,7 +223,7 @@ test_pdu3_natl (void)
pdu, sizeof (pdu),
"+12345678901", /* smsc */
"18005551212", /* number, no plus */
- "110101123456+00", /* timestamp */
+ "2011-01-01T12:34:56Z", /* timestamp */
FALSE,
"hellohello", /* text */
NULL, 0);
@@ -262,7 +245,7 @@ test_pdu3_8bit (void)
pdu, sizeof (pdu),
"+12345678901", /* smsc */
"+18005551212", /* number */
- "110101123456+00", /* timestamp */
+ "2011-01-01T12:34:56Z", /* timestamp */
FALSE,
NULL, /* text */
expected_data, /* data */
@@ -310,7 +293,7 @@ test_pdu_dcsf1 (void)
pdu, sizeof (pdu),
"+33609001390", /* smsc */
"1800", /* number */
- "110624130815+02", /* timestamp */
+ "2011-06-24T13:08:15+02", /* timestamp */
FALSE,
"Info SFR - Confidentiel, à ne jamais transmettre -\r\n"
"Voici votre nouveau mot de passe : sw2ced pour gérer "
@@ -334,7 +317,7 @@ test_pdu_dcsf_8bit (void)
pdu, sizeof (pdu),
"+12345678901", /* smsc */
"+18005551212", /* number */
- "110101123456+00", /* timestamp */
+ "2011-01-01T12:34:56Z", /* timestamp */
FALSE,
NULL, /* text */
expected_data, /* data */
@@ -356,7 +339,7 @@ test_pdu_insufficient_data (void)
};
hexpdu = mm_utils_bin2hexstr (pdu, sizeof (pdu));
- part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, &error);
+ part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, NULL, &error);
g_assert (part == NULL);
/* We don't care for the specific error type */
g_assert (error != NULL);
@@ -380,7 +363,7 @@ test_pdu_udhi (void)
hexpdu,
"+31653131316", /* smsc */
"1002", /* number */
- "110629233219+02", /* timestamp */
+ "2011-06-29T23:32:19+02", /* timestamp */
TRUE,
"Welkom, bel om uw Voicemail te beluisteren naar +31612001233"
" (PrePay: *100*1233#). Voicemail ontvangen is altijd gratis."
@@ -405,7 +388,7 @@ test_pdu_multipart (void)
hexpdu1,
"+12063130025", /* smsc */
"+16175046925", /* number */
- "120425195650-04", /* timestamp */
+ "2012-04-25T19:56:50-04", /* timestamp */
TRUE, /* multipart! */
"This is a very long test designed to exercise multi part capability. It should "
"show up as one message, not as two, as the underlying encoding represents ", /* text */
@@ -415,7 +398,7 @@ test_pdu_multipart (void)
hexpdu2,
"+12063130026", /* smsc */
"+16175046925", /* number */
- "120425195651-04", /* timestamp */
+ "2012-04-25T19:56:51-04", /* timestamp */
TRUE, /* multipart! */
"that the parts are related to one another. ", /* text */
NULL, 0);
@@ -448,7 +431,7 @@ test_pdu_not_stored (void)
hexpdu1,
"+34656000311", /* smsc */
"639337937", /* number */
- "120911074036+02", /* timestamp */
+ "2012-09-11T07:40:36+02", /* timestamp */
FALSE, /* multipart! */
NULL, /* text */
NULL, 0);
@@ -509,6 +492,21 @@ test_address_encode_unknown (void)
/********************* PDU CREATOR TESTS *********************/
static void
+trace_pdu (const guint8 *pdu,
+ guint len)
+{
+ guint i;
+
+ g_print ("n ");
+ for (i = 0; i < len; i++) {
+ g_print (" 0x%02X", pdu[i]);
+ if (((i + 1) % 12) == 0)
+ g_print ("n ");
+ }
+ g_print ("n");
+}
+
+static void
common_test_create_pdu (const gchar *smsc,
const gchar *number,
const gchar *text,
@@ -533,7 +531,7 @@ common_test_create_pdu (const gchar *smsc,
MMSmsEncoding encoding = MM_SMS_ENCODING_UNKNOWN;
/* Detect best encoding */
- out = mm_sms_part_3gpp_util_split_text (text, &encoding);
+ out = mm_sms_part_3gpp_util_split_text (text, &encoding, NULL);
g_strfreev (out);
mm_sms_part_set_text (part, text);
mm_sms_part_set_encoding (part, encoding);
@@ -546,15 +544,16 @@ common_test_create_pdu (const gchar *smsc,
pdu = mm_sms_part_3gpp_get_submit_pdu (part,
&len,
&msgstart,
+ NULL,
&error);
mm_sms_part_free (part);
- trace_pdu (pdu, len);
+ if (g_test_verbose ())
+ trace_pdu (pdu, len);
g_assert_no_error (error);
g_assert (pdu != NULL);
- g_assert_cmpuint (len, ==, expected_size);
- g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpmem (pdu, len, expected, expected_size);
g_assert_cmpint (msgstart, ==, expected_msgstart);
g_free (pdu);
@@ -720,7 +719,7 @@ common_test_text_split (const gchar *text,
MMSmsEncoding out_encoding = MM_SMS_ENCODING_UNKNOWN;
guint i;
- out = mm_sms_part_3gpp_util_split_text (text, &out_encoding);
+ out = mm_sms_part_3gpp_util_split_text (text, &out_encoding, NULL);
g_assert (out != NULL);
g_assert (out_encoding != MM_SMS_ENCODING_UNKNOWN);
@@ -735,7 +734,7 @@ common_test_text_split (const gchar *text,
}
static void
-test_text_split_short (void)
+test_text_split_short_gsm7 (void)
{
const gchar *text = "Hello";
const gchar *expected [] = {
@@ -749,7 +748,7 @@ test_text_split_short (void)
static void
test_text_split_short_ucs2 (void)
{
- const gchar *text = "你好";
+ const gchar *text = "你好"; /* (UTF-8) e4 bd a0 e5 a5 bd */
const gchar *expected [] = {
"你好",
NULL
@@ -759,7 +758,19 @@ test_text_split_short_ucs2 (void)
}
static void
-test_text_split_max_single_pdu (void)
+test_text_split_short_utf16 (void)
+{
+ const gchar *text = "😉"; /* U+1F609, winking face */
+ const gchar *expected [] = {
+ "😉",
+ NULL
+ };
+
+ common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2);
+}
+
+static void
+test_text_split_max_single_pdu_gsm7 (void)
{
const gchar *text =
"0123456789012345678901234567890123456789"
@@ -798,7 +809,23 @@ test_text_split_max_single_pdu_ucs2 (void)
}
static void
-test_text_split_two_pdu (void)
+test_text_split_max_single_pdu_utf16 (void)
+{
+ /* NOTE: this string contains 35 Bhaiksuki characters, each of
+ * them requiring 4 bytes both in UTF-8 and in UTF-16 (140 bytes
+ * in total). */
+ const gchar *text =
+ "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡𑰢𑰣";
+ const gchar *expected [] = {
+ "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡𑰢𑰣",
+ NULL
+ };
+
+ common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2);
+}
+
+static void
+test_text_split_two_pdu_gsm7 (void)
{
const gchar *text =
"0123456789012345678901234567890123456789"
@@ -839,33 +866,36 @@ test_text_split_two_pdu_ucs2 (void)
common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2);
}
-/************************************************************/
-
-void
-_mm_log (const char *loc,
- const char *func,
- guint32 level,
- const char *fmt,
- ...)
+static void
+test_text_split_two_pdu_utf16 (void)
{
-#if defined ENABLE_TEST_MESSAGE_TRACES
- /* Dummy log function */
- va_list args;
- gchar *msg;
+ /* NOTE: this string contains 35 Bhaiksuki characters, each of
+ * them requiring 4 bytes both in UTF-8 and in UTF-16 (140 bytes
+ * in total) plus one ASCII char (encoded with 1 byte in UTF-8 and
+ * 2 bytes in UTF-16), making it a total of 142 bytes when in
+ * UTF-16 (so not fitting in one single PDU)
+ *
+ * When split in chunks, the last chunk will hold 2 Bhaiksuki
+ * characters plus the last ASCII one (9 bytes in UTF-16) so that
+ * the first chunk contains the leading 33 Bhaiksuki characters
+ * (132 characters, less than 134) */
+ const gchar *text =
+ "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡𑰢𑰣a";
+ const gchar *expected [] = {
+ "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡",
+ "𑰢𑰣a",
+ NULL
+ };
- va_start (args, fmt);
- msg = g_strdup_vprintf (fmt, args);
- va_end (args);
- g_print ("%s\n", msg);
- g_free (msg);
-#endif
+ common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2);
}
+/************************************************************/
+
int main (int argc, char **argv)
{
setlocale (LC_ALL, "");
- g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/SMS/3GPP/PDU-Parser/pdu1", test_pdu1);
@@ -895,12 +925,15 @@ int main (int argc, char **argv)
g_test_add_func ("/MM/SMS/3GPP/PDU-Creator/GSM-3", test_create_pdu_gsm_3);
g_test_add_func ("/MM/SMS/3GPP/PDU-Creator/GSM-no-validity", test_create_pdu_gsm_no_validity);
- g_test_add_func ("/MM/SMS/3GPP/Text-Split/short", test_text_split_short);
- g_test_add_func ("/MM/SMS/3GPP/Text-Split/short-UCS2", test_text_split_short_ucs2);
- g_test_add_func ("/MM/SMS/3GPP/Text-Split/max-single-pdu", test_text_split_max_single_pdu);
- g_test_add_func ("/MM/SMS/3GPP/Text-Split/max-single-pdu-UCS2", test_text_split_max_single_pdu_ucs2);
- g_test_add_func ("/MM/SMS/3GPP/Text-Split/two-pdu", test_text_split_two_pdu);
- g_test_add_func ("/MM/SMS/3GPP/Text-Split/two-pdu-UCS2", test_text_split_two_pdu_ucs2);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/gsm7/short", test_text_split_short_gsm7);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/ucs2/short", test_text_split_short_ucs2);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/utf16/short", test_text_split_short_utf16);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/gsm7/max-single-pdu", test_text_split_max_single_pdu_gsm7);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/ucs2/max-single-pdu", test_text_split_max_single_pdu_ucs2);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/utf16/max-single-pdu", test_text_split_max_single_pdu_utf16);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/gsm7/two-pdu", test_text_split_two_pdu_gsm7);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/ucs2/two-pdu", test_text_split_two_pdu_ucs2);
+ g_test_add_func ("/MM/SMS/3GPP/Text-Split/utf16/two-pdu", test_text_split_two_pdu_utf16);
return g_test_run ();
}