diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2019-12-17 10:45:52 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2019-12-17 10:52:13 +0100 |
commit | d83c018f9825d4244cc4254ff729e64172afbc2e (patch) | |
tree | 0a703c45db5dcf18f7edaebf71c8db61cd004c8b | |
parent | 9991f2906fcaeb7c86740f3d0d19c82dc0ac86f9 (diff) |
core,tests: new test to make sure all error codes are supported
Defining the new error codes in the headers is not enough, we also
need to add support in the error helpers in order to create proper
GErrors with the expected error codes.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/tests/Makefile.am | 1 | ||||
-rw-r--r-- | src/tests/test-error-helpers.c | 86 |
3 files changed, 88 insertions, 0 deletions
@@ -59,6 +59,7 @@ Makefile.in /src/tests/test-sms-part-3gpp /src/tests/test-sms-part-cdma /src/tests/test-udev-rules +/src/tests/test-error-helpers /cli/mmcli diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index ea69da2e..2631f9ba 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -55,6 +55,7 @@ noinst_PROGRAMS = \ test-sms-part-3gpp \ test-sms-part-cdma \ test-udev-rules \ + test-error-helpers \ $(NULL) if WITH_QMI diff --git a/src/tests/test-error-helpers.c b/src/tests/test-error-helpers.c new file mode 100644 index 00000000..88af6283 --- /dev/null +++ b/src/tests/test-error-helpers.c @@ -0,0 +1,86 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2019 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include <glib.h> +#include <glib-object.h> +#include <string.h> +#include <stdlib.h> +#include <locale.h> + +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> +#include "mm-error-helpers.h" +#include "mm-log.h" + +#define TEST_ERROR_HELPER(ERROR_CAPS,ERROR_SMALL,ERROR_CAMEL) \ + static void \ + test_error_helpers_## ERROR_SMALL (void) \ + { \ + GError *error; \ + guint i; \ + GEnumClass *enum_class; \ + \ + enum_class = g_type_class_ref (MM_TYPE_ ## ERROR_CAPS); \ + for (i = enum_class->minimum; i <= enum_class->maximum; i++) { \ + GEnumValue *enum_value; \ + \ + enum_value = g_enum_get_value (enum_class, i); \ + if (enum_value) { \ + error = mm_## ERROR_SMALL ## _for_code ((MM##ERROR_CAMEL)i); \ + g_assert_error (error, MM_ ## ERROR_CAPS, i); \ + g_error_free (error); \ + } \ + } \ + g_type_class_unref (enum_class); \ + } + +TEST_ERROR_HELPER (CONNECTION_ERROR, connection_error, ConnectionError) +TEST_ERROR_HELPER (MOBILE_EQUIPMENT_ERROR, mobile_equipment_error, MobileEquipmentError) +TEST_ERROR_HELPER (MESSAGE_ERROR, message_error, MessageError) + +/*****************************************************************************/ + +void +_mm_log (const char *loc, + const char *func, + guint32 level, + const char *fmt, + ...) +{ + va_list args; + gchar *msg; + + if (!g_test_verbose ()) + return; + + va_start (args, fmt); + msg = g_strdup_vprintf (fmt, args); + va_end (args); + g_print ("%s\n", msg); + g_free (msg); +} + +int main (int argc, char **argv) +{ + setlocale (LC_ALL, ""); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/MM/error-helpers/connection-error", test_error_helpers_connection_error); + g_test_add_func ("/MM/error-helpers/mobile-equipment-error", test_error_helpers_mobile_equipment_error); + g_test_add_func ("/MM/error-helpers/message-error", test_error_helpers_message_error); + + return g_test_run (); +} |