telit: add load_supported_bands interface
This commit is contained in:
committed by
Aleksander Morgado
parent
81019ca5b5
commit
70b8ec1a88
@@ -22,7 +22,6 @@
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-log.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-helpers-telit.h"
|
||||
|
||||
@@ -63,7 +62,7 @@ static CSIMResponseTest invalid_csim_response_test_list [] = {
|
||||
};
|
||||
|
||||
static void
|
||||
test_parse_csim_response (void)
|
||||
test_mm_telit_parse_csim_response (void)
|
||||
{
|
||||
const gint step = 1;
|
||||
guint i;
|
||||
@@ -92,6 +91,148 @@ test_parse_csim_response (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_mm_bands_contains (void) {
|
||||
GArray* mm_bands;
|
||||
guint i = 1;
|
||||
|
||||
mm_bands = g_array_sized_new (FALSE, TRUE, sizeof (MMModemBand), 3);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
g_array_append_val (mm_bands, i);
|
||||
|
||||
g_assert_true (mm_telit_bands_contains (mm_bands, 2));
|
||||
g_assert_true (mm_telit_bands_contains (mm_bands, 2));
|
||||
g_assert_false (mm_telit_bands_contains (mm_bands, 3));
|
||||
|
||||
g_array_free (mm_bands, TRUE);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
gchar* band_flag_str;
|
||||
guint band_flags_len;
|
||||
guint band_flags [MAX_BANDS_LIST_LEN];
|
||||
} BNDFlagsTest;
|
||||
|
||||
static BNDFlagsTest band_flag_test[] = {
|
||||
{"0-3", 4, {0, 1, 2, 3} },
|
||||
{"0,3", 2, {0, 3} },
|
||||
{"0,2-3,5-7,9", 2, {0, 2, 3, 5, 6, 7, 9} },
|
||||
{ NULL, 0, {}},
|
||||
};
|
||||
|
||||
static void
|
||||
test_parse_band_flag_str (void) {
|
||||
GError *error = NULL;
|
||||
gboolean res = FALSE;
|
||||
GArray *band_flags = NULL;
|
||||
guint i, j;
|
||||
|
||||
for (i = 0; band_flag_test[i].band_flag_str != NULL; i++) {
|
||||
band_flags = g_array_new (FALSE, FALSE, sizeof (guint));
|
||||
res = mm_telit_get_band_flags_from_string (band_flag_test[i].band_flag_str,
|
||||
&band_flags,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_true (res);
|
||||
|
||||
for (j = 0; j < band_flag_test[i].band_flags_len; j++) {
|
||||
guint ref = band_flag_test[i].band_flags[j];
|
||||
guint cur = g_array_index (band_flags, guint, j);
|
||||
|
||||
g_assert_true (ref == cur);
|
||||
}
|
||||
|
||||
g_array_free (band_flags, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
gchar* response;
|
||||
gboolean modem_is_2g;
|
||||
gboolean modem_is_3g;
|
||||
gboolean modem_is_4g;
|
||||
guint mm_bands_len;
|
||||
MMModemBand mm_bands [MAX_BANDS_LIST_LEN];
|
||||
} BNDResponseTest;
|
||||
|
||||
static BNDResponseTest supported_band_mapping_tests [] = {
|
||||
{ "#BND: (0-3),(0,2,5,6)", TRUE, TRUE, FALSE, 7, { MM_MODEM_BAND_EGSM,
|
||||
MM_MODEM_BAND_DCS,
|
||||
MM_MODEM_BAND_PCS,
|
||||
MM_MODEM_BAND_G850,
|
||||
MM_MODEM_BAND_U2100,
|
||||
MM_MODEM_BAND_U850,
|
||||
MM_MODEM_BAND_U900} },
|
||||
{ "#BND: (0,3),(0,2,5,6)", TRUE, TRUE, FALSE, 7, { MM_MODEM_BAND_EGSM,
|
||||
MM_MODEM_BAND_DCS,
|
||||
MM_MODEM_BAND_PCS,
|
||||
MM_MODEM_BAND_G850,
|
||||
MM_MODEM_BAND_U2100,
|
||||
MM_MODEM_BAND_U850,
|
||||
MM_MODEM_BAND_U900} },
|
||||
{ "#BND: (0,2),(0,2,5,6)", TRUE, TRUE, FALSE, 6, { MM_MODEM_BAND_EGSM,
|
||||
MM_MODEM_BAND_DCS,
|
||||
MM_MODEM_BAND_G850,
|
||||
MM_MODEM_BAND_U2100,
|
||||
MM_MODEM_BAND_U850,
|
||||
MM_MODEM_BAND_U900} },
|
||||
{ "#BND: (0,2),(0-4,5,6)", TRUE, TRUE, FALSE, 7, { MM_MODEM_BAND_EGSM,
|
||||
MM_MODEM_BAND_DCS,
|
||||
MM_MODEM_BAND_G850,
|
||||
MM_MODEM_BAND_U2100,
|
||||
MM_MODEM_BAND_U1900,
|
||||
MM_MODEM_BAND_U850,
|
||||
MM_MODEM_BAND_U900} },
|
||||
{ "#BND: (0-3),(0,2,5,6),(1-1)", TRUE, TRUE, TRUE, 8, { MM_MODEM_BAND_EGSM,
|
||||
MM_MODEM_BAND_DCS,
|
||||
MM_MODEM_BAND_PCS,
|
||||
MM_MODEM_BAND_G850,
|
||||
MM_MODEM_BAND_U2100,
|
||||
MM_MODEM_BAND_U850,
|
||||
MM_MODEM_BAND_U900,
|
||||
MM_MODEM_BAND_EUTRAN_I} },
|
||||
{ "#BND: (0),(0),(1-3)", TRUE, TRUE, TRUE, 5, { MM_MODEM_BAND_EGSM,
|
||||
MM_MODEM_BAND_DCS,
|
||||
MM_MODEM_BAND_U2100,
|
||||
MM_MODEM_BAND_EUTRAN_I,
|
||||
MM_MODEM_BAND_EUTRAN_II} },
|
||||
{ "#BND: (0),(0),(1-3)", FALSE, FALSE, TRUE, 2, { MM_MODEM_BAND_EUTRAN_I,
|
||||
MM_MODEM_BAND_EUTRAN_II} },
|
||||
{ NULL, FALSE, FALSE, FALSE, 0, {}},
|
||||
};
|
||||
|
||||
static void
|
||||
test_parse_supported_bands_response (void) {
|
||||
GError* error = NULL;
|
||||
gboolean res = FALSE;
|
||||
guint i, j;
|
||||
GArray* bands = NULL;
|
||||
|
||||
for (i = 0; supported_band_mapping_tests[i].response != NULL; i++) {
|
||||
res = mm_telit_parse_supported_bands_response (supported_band_mapping_tests[i].response,
|
||||
supported_band_mapping_tests[i].modem_is_2g,
|
||||
supported_band_mapping_tests[i].modem_is_3g,
|
||||
supported_band_mapping_tests[i].modem_is_4g,
|
||||
&bands,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_true (res);
|
||||
|
||||
|
||||
for (j = 0; j < supported_band_mapping_tests[i].mm_bands_len; j++) {
|
||||
MMModemBand ref = supported_band_mapping_tests[i].mm_bands[j];
|
||||
MMModemBand cur = g_array_index (bands, MMModemBand, j);
|
||||
g_assert_cmpint (cur, ==, ref);
|
||||
}
|
||||
|
||||
g_assert_cmpint(bands->len, ==, supported_band_mapping_tests[i].mm_bands_len);
|
||||
|
||||
g_array_free (bands, FALSE);
|
||||
bands = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
@@ -99,6 +240,9 @@ int main (int argc, char **argv)
|
||||
g_type_init ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/MM/telit/csim", test_parse_csim_response);
|
||||
g_test_add_func ("/MM/telit/csim", test_mm_telit_parse_csim_response);
|
||||
g_test_add_func ("/MM/telit/bands/supported/bands_contains", test_mm_bands_contains);
|
||||
g_test_add_func ("/MM/telit/bands/supported/parse_band_flag", test_parse_band_flag_str);
|
||||
g_test_add_func ("/MM/telit/bands/supported/parse_bands_response", test_parse_supported_bands_response);
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user