diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gsm0808/gsm0808_test.c | 36 | ||||
-rw-r--r-- | tests/gsm0808/gsm0808_test.ok | 2 |
2 files changed, 31 insertions, 7 deletions
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c index 197ec06d..63b87200 100644 --- a/tests/gsm0808/gsm0808_test.c +++ b/tests/gsm0808/gsm0808_test.c @@ -30,6 +30,13 @@ #include <arpa/inet.h> #include <errno.h> +#define EXPECT_ENCODED(hexstr) do { \ + const char *enc_str = msgb_hexdump(msg); \ + printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \ + OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \ + OSMO_ASSERT(rc_enc == msg->len); \ + } while(0) + #define VERIFY(msg, data, len) \ if (msgb_l3len(msg) != len) { \ printf("%s:%d Length don't match: %d vs. %d. %s\n", \ @@ -65,6 +72,27 @@ static void setup_codec_list(struct gsm0808_speech_codec_list *scl) scl->len = 3; } +void test_gsm0808_enc_cause(void) +{ + /* NOTE: This must be tested early because many of the following tests + * rely on the generation of a proper cause code. */ + + uint8_t rc_enc; + struct msgb *msg; + + /* Test with a single byte cause code */ + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_cause(msg, 0x41); + EXPECT_ENCODED("04 01 41"); + msgb_free(msg); + + /* Test with an extended (two byte) cause code */ + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_cause(msg, 0x8041); + EXPECT_ENCODED("04 02 80 41"); + msgb_free(msg); +} + static void test_create_layer3(void) { static const uint8_t res[] = { @@ -824,13 +852,6 @@ static void test_gsm0808_enc_dec_encrypt_info() msgb_free(msg); } -#define EXPECT_ENCODED(hexstr) do { \ - const char *enc_str = msgb_hexdump(msg); \ - printf("%s: encoded: %s(rc = %u)\n", __func__, enc_str, rc_enc); \ - OSMO_ASSERT(strcmp(enc_str, hexstr " ") == 0); \ - OSMO_ASSERT(rc_enc == msg->len); \ - } while(0) - static void test_gsm0808_enc_dec_cell_id_list_lac() { struct gsm0808_cell_id_list2 enc_cil; @@ -1770,6 +1791,7 @@ void test_gsm48_mr_cfg_from_gsm0808_sc_cfg() int main(int argc, char **argv) { printf("Testing generation of GSM0808 messages\n"); + test_gsm0808_enc_cause(); test_create_layer3(); test_create_layer3_aoip(); test_create_reset(); diff --git a/tests/gsm0808/gsm0808_test.ok b/tests/gsm0808/gsm0808_test.ok index a48cf1d5..e5833d01 100644 --- a/tests/gsm0808/gsm0808_test.ok +++ b/tests/gsm0808/gsm0808_test.ok @@ -1,4 +1,6 @@ Testing generation of GSM0808 messages +test_gsm0808_enc_cause: encoded: 04 01 41 (rc = 3) +test_gsm0808_enc_cause: encoded: 04 02 80 41 (rc = 4) Testing creating Layer3 Testing creating Layer3 (AoIP) Testing creating Reset |