From 74779c68f79765db7d66f95b456202d2b8dd51ae Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 28 Oct 2010 15:27:00 +0200 Subject: nat: Add test case for matching phone numbers Add the test case for matching '*' and for not matching at all --- openbsc/tests/bsc-nat/bsc_nat_test.c | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c index 7a2557fe6..aac28704e 100644 --- a/openbsc/tests/bsc-nat/bsc_nat_test.c +++ b/openbsc/tests/bsc-nat/bsc_nat_test.c @@ -878,6 +878,68 @@ static void test_setup_rewrite() } msgb_free(out); + + /* Make sure that a wildcard is matching */ + entry.mnc = "*"; + msg = msgb_alloc(4096, "test_dt_filter"); + copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); + parsed = bsc_nat_parse(msg); + if (!parsed) { + fprintf(stderr, "FAIL: Could not parse ID resp\n"); + abort(); + } + + out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); + if (!out) { + fprintf(stderr, "FAIL: A new message should be created.\n"); + abort(); + } + + if (msg == out) { + fprintf(stderr, "FAIL: The message should have changed\n"); + abort(); + } + + if (out->len != ARRAY_SIZE(cc_setup_national_patched)) { + fprintf(stderr, "FAIL: Length is wrong.\n"); + abort(); + } + + if (memcmp(cc_setup_national_patched, out->data, out->len) != 0) { + fprintf(stderr, "FAIL: Data is wrong.\n"); + fprintf(stderr, "Data was: %s\n", hexdump(out->data, out->len)); + abort(); + } + + msgb_free(out); + + /* Make sure that a wildcard is matching */ + entry.mnc = "09"; + msg = msgb_alloc(4096, "test_dt_filter"); + copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); + parsed = bsc_nat_parse(msg); + if (!parsed) { + fprintf(stderr, "FAIL: Could not parse ID resp\n"); + abort(); + } + + out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); + if (out != msg) { + fprintf(stderr, "FAIL: The message should be unchanged.\n"); + abort(); + } + + if (out->len != ARRAY_SIZE(cc_setup_national)) { + fprintf(stderr, "FAIL: Foo\n"); + abort(); + } + + if (memcmp(out->data, cc_setup_national, ARRAY_SIZE(cc_setup_national)) != 0) { + fprintf(stderr, "FAIL: The message should really be unchanged.\n"); + abort(); + } + + msgb_free(out); } int main(int argc, char **argv) -- cgit v1.2.3