plugins,tests: setup new helper utilities for tests
For now, including a handy method from the ublox tests that allows comparing arrays of bands that may not be sorted.
This commit is contained in:
+14
-4
@@ -78,6 +78,8 @@ libmm_test_common_la_SOURCES = \
|
||||
tests/test-fixture.c \
|
||||
tests/test-port-context.h \
|
||||
tests/test-port-context.c \
|
||||
tests/test-helpers.h \
|
||||
tests/test-helpers.c \
|
||||
$(NULL)
|
||||
libmm_test_common_la_CPPFLAGS = \
|
||||
-I$(top_builddir)/libmm-glib/generated/tests \
|
||||
@@ -98,11 +100,12 @@ TEST_COMMON_COMPILER_FLAGS = \
|
||||
-I$(top_srcdir)/libmm-glib/generated \
|
||||
-I$(top_builddir)/libmm-glib/generated \
|
||||
-I$(top_builddir)/libmm-glib/generated/tests \
|
||||
-DCOMMON_GSM_PORT_CONF=\""$(abs_top_srcdir)/plugins/tests/gsm-port.conf"\"
|
||||
-DCOMMON_GSM_PORT_CONF=\""$(abs_top_srcdir)/plugins/tests/gsm-port.conf"\" \
|
||||
$(NULL)
|
||||
|
||||
TEST_COMMON_LIBADD_FLAGS = \
|
||||
$(builddir)/libmm-test-common.la \
|
||||
$(top_builddir)/libmm-glib/libmm-glib.la
|
||||
$(NULL)
|
||||
|
||||
################################################################################
|
||||
# common icera support
|
||||
@@ -310,7 +313,10 @@ libmm_plugin_generic_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
|
||||
noinst_PROGRAMS += test-service-generic
|
||||
test_service_generic_SOURCES = generic/tests/test-service-generic.c
|
||||
test_service_generic_CPPFLAGS = $(TEST_COMMON_COMPILER_FLAGS)
|
||||
test_service_generic_LDADD = $(TEST_COMMON_LIBADD_FLAGS)
|
||||
test_service_generic_LDADD = \
|
||||
$(top_builddir)/libmm-glib/libmm-glib.la \
|
||||
$(TEST_COMMON_LIBADD_FLAGS) \
|
||||
$(NULL)
|
||||
|
||||
################################################################################
|
||||
# plugin: motorola
|
||||
@@ -1016,8 +1022,12 @@ noinst_PROGRAMS += test-modem-helpers-ublox
|
||||
test_modem_helpers_ublox_SOURCES = \
|
||||
ublox/tests/test-modem-helpers-ublox.c \
|
||||
$(NULL)
|
||||
test_modem_helpers_ublox_CPPFLAGS = $(PLUGIN_UBLOX_COMPILER_FLAGS)
|
||||
test_modem_helpers_ublox_CPPFLAGS = \
|
||||
$(PLUGIN_UBLOX_COMPILER_FLAGS) \
|
||||
$(TEST_COMMON_COMPILER_FLAGS) \
|
||||
$(NULL)
|
||||
test_modem_helpers_ublox_LDADD = \
|
||||
$(TEST_COMMON_LIBADD_FLAGS) \
|
||||
$(builddir)/libhelpers-ublox.la \
|
||||
$(top_builddir)/src/libhelpers.la \
|
||||
$(top_builddir)/libmm-glib/libmm-glib.la \
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/* -*- 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 <ModemManager.h>
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-log.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
|
||||
#include "test-helpers.h"
|
||||
|
||||
void
|
||||
mm_test_helpers_compare_bands (GArray *bands,
|
||||
const MMModemBand *expected_bands,
|
||||
guint n_expected_bands)
|
||||
{
|
||||
gchar *bands_str;
|
||||
GArray *expected_bands_array;
|
||||
gchar *expected_bands_str;
|
||||
|
||||
if (!expected_bands || !n_expected_bands) {
|
||||
g_assert (!bands);
|
||||
return;
|
||||
}
|
||||
|
||||
g_assert (bands);
|
||||
mm_common_bands_garray_sort (bands);
|
||||
bands_str = mm_common_build_bands_string ((MMModemBand *)(bands->data), bands->len);
|
||||
|
||||
expected_bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), n_expected_bands);
|
||||
g_array_append_vals (expected_bands_array, expected_bands, n_expected_bands);
|
||||
mm_common_bands_garray_sort (expected_bands_array);
|
||||
expected_bands_str = mm_common_build_bands_string ((MMModemBand *)(expected_bands_array->data), expected_bands_array->len);
|
||||
g_array_unref (expected_bands_array);
|
||||
|
||||
g_assert_cmpstr (bands_str, ==, expected_bands_str);
|
||||
g_free (bands_str);
|
||||
g_free (expected_bands_str);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/* -*- 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>
|
||||
*/
|
||||
|
||||
#ifndef TEST_HELPERS_H
|
||||
#define TEST_HELPERS_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <libmm-glib.h>
|
||||
|
||||
void mm_test_helpers_compare_bands (GArray *bands,
|
||||
const MMModemBand *expected_bands,
|
||||
guint n_expected_bands);
|
||||
|
||||
#endif /* TEST_HELPERS_H */
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-helpers-ublox.h"
|
||||
|
||||
#include "test-helpers.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test +UPINCNT responses */
|
||||
|
||||
@@ -487,36 +489,6 @@ test_urat_write_command (void)
|
||||
/*****************************************************************************/
|
||||
/* Test +UBANDSEL? response parser */
|
||||
|
||||
static void
|
||||
common_compare_bands (GArray *bands,
|
||||
const MMModemBand *expected_bands,
|
||||
guint n_expected_bands)
|
||||
{
|
||||
gchar *bands_str;
|
||||
GArray *expected_bands_array;
|
||||
gchar *expected_bands_str;
|
||||
|
||||
if (!expected_bands || !n_expected_bands) {
|
||||
g_assert (!bands);
|
||||
return;
|
||||
}
|
||||
|
||||
g_assert (bands);
|
||||
mm_common_bands_garray_sort (bands);
|
||||
bands_str = mm_common_build_bands_string ((MMModemBand *)(bands->data), bands->len);
|
||||
g_array_unref (bands);
|
||||
|
||||
expected_bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), n_expected_bands);
|
||||
g_array_append_vals (expected_bands_array, expected_bands, n_expected_bands);
|
||||
mm_common_bands_garray_sort (expected_bands_array);
|
||||
expected_bands_str = mm_common_build_bands_string ((MMModemBand *)(expected_bands_array->data), expected_bands_array->len);
|
||||
g_array_unref (expected_bands_array);
|
||||
|
||||
g_assert_cmpstr (bands_str, ==, expected_bands_str);
|
||||
g_free (bands_str);
|
||||
g_free (expected_bands_str);
|
||||
}
|
||||
|
||||
static void
|
||||
common_validate_ubandsel_response (const gchar *str,
|
||||
const MMModemBand *expected_bands,
|
||||
@@ -530,7 +502,8 @@ common_validate_ubandsel_response (const gchar *str,
|
||||
g_assert_no_error (error);
|
||||
g_assert (bands);
|
||||
|
||||
common_compare_bands (bands, expected_bands, n_expected_bands);
|
||||
mm_test_helpers_compare_bands (bands, expected_bands, n_expected_bands);
|
||||
g_array_unref (bands);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -655,7 +628,8 @@ common_validate_uact_response (const gchar *str,
|
||||
if (n_expected_bands > 0) {
|
||||
g_assert (bands);
|
||||
g_assert_no_error (error);
|
||||
common_compare_bands (bands, expected_bands, n_expected_bands);
|
||||
mm_test_helpers_compare_bands (bands, expected_bands, n_expected_bands);
|
||||
g_array_unref (bands);
|
||||
} else {
|
||||
g_assert (!bands);
|
||||
g_assert (error);
|
||||
@@ -731,9 +705,15 @@ common_validate_uact_test (const gchar *str,
|
||||
g_assert_no_error (error);
|
||||
g_assert (result);
|
||||
|
||||
common_compare_bands (bands_2g, expected_bands_2g, n_expected_bands_2g);
|
||||
common_compare_bands (bands_3g, expected_bands_3g, n_expected_bands_3g);
|
||||
common_compare_bands (bands_4g, expected_bands_4g, n_expected_bands_4g);
|
||||
mm_test_helpers_compare_bands (bands_2g, expected_bands_2g, n_expected_bands_2g);
|
||||
if (bands_2g)
|
||||
g_array_unref (bands_2g);
|
||||
mm_test_helpers_compare_bands (bands_3g, expected_bands_3g, n_expected_bands_3g);
|
||||
if (bands_3g)
|
||||
g_array_unref (bands_3g);
|
||||
mm_test_helpers_compare_bands (bands_4g, expected_bands_4g, n_expected_bands_4g);
|
||||
if (bands_4g)
|
||||
g_array_unref (bands_4g);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user