aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmicli/test/test-helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmicli/test/test-helpers.c')
-rw-r--r--src/qmicli/test/test-helpers.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/qmicli/test/test-helpers.c b/src/qmicli/test/test-helpers.c
index 9c2e597..7523c0a 100644
--- a/src/qmicli/test/test-helpers.c
+++ b/src/qmicli/test/test-helpers.c
@@ -13,6 +13,7 @@
* Copyright (C) 2012-2016 Aleksander Morgado <aleksander@aleksander.es>
*/
+#include <string.h>
#include <glib.h>
#include "qmicli-helpers.h"
@@ -117,6 +118,55 @@ test_helpers_raw_printable_4 (void)
/******************************************************************************/
static void
+test_helpers_binary_array_from_string_1 (void)
+{
+ const guint8 expected[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0xAB, 0xCD, 0xEF
+ };
+ const gchar *str = "123456789ABCDEF0abcdef";
+ GArray *out = NULL;
+
+ g_assert (qmicli_read_binary_array_from_string (str, &out));
+ g_assert (out != NULL);
+ g_assert_cmpuint (out->len, ==, strlen (str) / 2);
+ g_assert (memcmp ((guint8 *)(out->data), expected, out->len) == 0);
+
+ g_array_unref (out);
+}
+
+static void
+test_helpers_binary_array_from_string_2 (void)
+{
+ const gchar *str = "";
+ GArray *out = NULL;
+
+ g_assert (qmicli_read_binary_array_from_string (str, &out));
+ g_assert (out != NULL);
+ g_assert_cmpuint (out->len, ==, 0);
+ g_array_unref (out);
+}
+
+static void
+test_helpers_binary_array_from_string_3 (void)
+{
+ const gchar *str = "hello";
+ GArray *out = NULL;
+
+ g_assert (qmicli_read_binary_array_from_string (str, &out) == FALSE);
+}
+
+static void
+test_helpers_binary_array_from_string_4 (void)
+{
+ const gchar *str = "a";
+ GArray *out = NULL;
+
+ g_assert (qmicli_read_binary_array_from_string (str, &out) == FALSE);
+}
+
+/******************************************************************************/
+
+static void
test_helpers_supported_messages_list (void)
{
const guint8 bytearray[] = {
@@ -242,6 +292,11 @@ int main (int argc, char **argv)
g_test_add_func ("/qmicli/helpers/raw-printable/3", test_helpers_raw_printable_3);
g_test_add_func ("/qmicli/helpers/raw-printable/4", test_helpers_raw_printable_4);
+ g_test_add_func ("/qmicli/helpers/binary-array-from-string/1", test_helpers_binary_array_from_string_1);
+ g_test_add_func ("/qmicli/helpers/binary-array-from-string/2", test_helpers_binary_array_from_string_2);
+ g_test_add_func ("/qmicli/helpers/binary-array-from-string/3", test_helpers_binary_array_from_string_3);
+ g_test_add_func ("/qmicli/helpers/binary-array-from-string/4", test_helpers_binary_array_from_string_4);
+
g_test_add_func ("/qmicli/helpers/supported-message-list", test_helpers_supported_messages_list);
g_test_add_func ("/qmicli/helpers/supported-message-list/none", test_helpers_supported_messages_list_none);