diff options
Diffstat (limited to 'tests/gsup')
-rw-r--r-- | tests/gsup/Makefile.am | 36 | ||||
-rw-r--r-- | tests/gsup/gsup_test.c | 113 | ||||
-rw-r--r-- | tests/gsup/gsup_test.err | 0 | ||||
-rw-r--r-- | tests/gsup/gsup_test.ok | 32 |
4 files changed, 181 insertions, 0 deletions
diff --git a/tests/gsup/Makefile.am b/tests/gsup/Makefile.am new file mode 100644 index 0000000..5dbb180 --- /dev/null +++ b/tests/gsup/Makefile.am @@ -0,0 +1,36 @@ +AM_CPPFLAGS = \ + $(all_includes) \ + $(NULL) + +AM_CFLAGS = \ + -I$(top_srcdir)/include \ + $(LIBOSMOCORE_CFLAGS) \ + $(LIBOSMOGSM_CFLAGS) \ + $(NULL) + +AM_LDFLAGS = \ + -no-install \ + $(NULL) + +EXTRA_DIST = \ + gsup_test.ok \ + gsup_test.err \ + $(NULL) + +noinst_PROGRAMS = \ + gsup_test \ + $(NULL) + +gsup_test_SOURCES = \ + gsup_test.c \ + $(NULL) + +gsup_test_LDADD = \ + $(top_builddir)/src/gsupclient/libosmo-gsup-client.la \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOGSM_LIBS) \ + $(NULL) + +.PHONY: update_exp +update_exp: + $(builddir)/gsup_test >"$(srcdir)/gsup_test.ok" 2>"$(srcdir)/gsup_test.err" diff --git a/tests/gsup/gsup_test.c b/tests/gsup/gsup_test.c new file mode 100644 index 0000000..1a7bb76 --- /dev/null +++ b/tests/gsup/gsup_test.c @@ -0,0 +1,113 @@ +/* (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <string.h> + +#include <osmocom/core/logging.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/application.h> +#include <osmocom/gsupclient/gsup_req.h> + +void *ctx = NULL; + +static void test_gsup_make_response(void) +{ + char *source_name = "incoming-source-name"; + char *destination_name = "preset-destination-name"; + uint8_t sm_rp_mr = 23; + uint8_t other_sm_rp_mr = 17; + struct osmo_gsup_message rx = { + .message_type = OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST, + .imsi = "1234567", + .message_class = OSMO_GSUP_MESSAGE_CLASS_SUBSCRIBER_MANAGEMENT, + .source_name = (uint8_t*)source_name, + .source_name_len = strlen(source_name) + 1, + .sm_rp_mr = &sm_rp_mr, + .session_id = 42, + .session_state = OSMO_GSUP_SESSION_STATE_BEGIN, + }; + struct osmo_gsup_message nonempty = { + .message_type = OSMO_GSUP_MSGT_ROUTING_ERROR, + .imsi = "987654321", + .message_class = OSMO_GSUP_MESSAGE_CLASS_INTER_MSC, + .destination_name = (uint8_t*)destination_name, + .destination_name_len = strlen(destination_name) + 1, + .sm_rp_mr = &other_sm_rp_mr, + .session_id = 11, + .session_state = OSMO_GSUP_SESSION_STATE_END, + }; + void *name_ctx = talloc_named_const(ctx, 0, __func__); + int error; + int final; + char *nonempty_str; + int rc; + + printf("\n%s()\n", __func__); + printf("rx = %s\n", osmo_gsup_message_to_str_c(name_ctx, &rx)); + + printf("\nwriting to an empty struct osmo_gsup_message should populate values as needed:\n"); + for (error = 0; error <= 1; error++) { + for (final = 0; final <= 1; final++) { + struct osmo_gsup_message target = {}; + printf("- args (error=%d, final=%d)\n", error, final); + rc = osmo_gsup_make_response(&target, &rx, error, final); + printf(" %s\n", osmo_gsup_message_to_str_c(name_ctx, &target)); + printf(" rc = %d\n", rc); + } + } + + printf("\nwriting to an already populated struct osmo_gsup_message, should have no effect:\n"); + nonempty_str = osmo_gsup_message_to_str_c(name_ctx, &nonempty); + for (error = 0; error <= 1; error++) { + for (final = 0; final <= 1; final++) { + struct osmo_gsup_message target = nonempty; + char *result; + printf("- args (error=%d, final=%d)\n", error, final); + rc = osmo_gsup_make_response(&target, &rx, error, final); + result = osmo_gsup_message_to_str_c(name_ctx, &target); + printf(" %s\n", result); + if (strcmp(result, nonempty_str)) + printf(" ERROR: expected: %s\n", nonempty_str); + printf(" rc = %d\n", rc); + } + } +} + +const struct log_info_cat default_categories[] = { +}; + +static struct log_info info = { + .cat = default_categories, + .num_cat = ARRAY_SIZE(default_categories), +}; + +int main(int argc, char **argv) +{ + ctx = talloc_named_const(NULL, 0, "gsup_test"); + osmo_init_logging2(ctx, &info); + log_set_print_filename(osmo_stderr_target, 0); + log_set_print_timestamp(osmo_stderr_target, 0); + log_set_use_color(osmo_stderr_target, 0); + log_set_print_category(osmo_stderr_target, 1); + + test_gsup_make_response(); + + printf("Done.\n"); + return EXIT_SUCCESS; +} diff --git a/tests/gsup/gsup_test.err b/tests/gsup/gsup_test.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/gsup/gsup_test.err diff --git a/tests/gsup/gsup_test.ok b/tests/gsup/gsup_test.ok new file mode 100644 index 0000000..0899633 --- /dev/null +++ b/tests/gsup/gsup_test.ok @@ -0,0 +1,32 @@ + +test_gsup_make_response() +rx = Subscriber-Management OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST: imsi="1234567" source_name="incoming-source-name\0" session_id=42 session_state=BEGIN sm_rp_mr=23 + +writing to an empty struct osmo_gsup_message should populate values as needed: +- args (error=0, final=0) + Subscriber-Management OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT: imsi="1234567" destination_name="incoming-source-name\0" session_id=42 session_state=CONTINUE sm_rp_mr=23 + rc = 0 +- args (error=0, final=1) + Subscriber-Management OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT: imsi="1234567" destination_name="incoming-source-name\0" session_id=42 session_state=END sm_rp_mr=23 + rc = 0 +- args (error=1, final=0) + Subscriber-Management OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR: imsi="1234567" destination_name="incoming-source-name\0" session_id=42 session_state=CONTINUE sm_rp_mr=23 + rc = 0 +- args (error=1, final=1) + Subscriber-Management OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR: imsi="1234567" destination_name="incoming-source-name\0" session_id=42 session_state=END sm_rp_mr=23 + rc = 0 + +writing to an already populated struct osmo_gsup_message, should have no effect: +- args (error=0, final=0) + Inter-MSC OSMO_GSUP_MSGT_ROUTING_ERROR: imsi="987654321" destination_name="preset-destination-name\0" session_id=11 session_state=END sm_rp_mr=17 + rc = 15 +- args (error=0, final=1) + Inter-MSC OSMO_GSUP_MSGT_ROUTING_ERROR: imsi="987654321" destination_name="preset-destination-name\0" session_id=11 session_state=END sm_rp_mr=17 + rc = 15 +- args (error=1, final=0) + Inter-MSC OSMO_GSUP_MSGT_ROUTING_ERROR: imsi="987654321" destination_name="preset-destination-name\0" session_id=11 session_state=END sm_rp_mr=17 + rc = 15 +- args (error=1, final=1) + Inter-MSC OSMO_GSUP_MSGT_ROUTING_ERROR: imsi="987654321" destination_name="preset-destination-name\0" session_id=11 session_state=END sm_rp_mr=17 + rc = 15 +Done. |