diff options
Diffstat (limited to 'tests/gsm0808')
-rw-r--r-- | tests/gsm0808/gsm0808_test.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c index 5fe9c876..af457b4d 100644 --- a/tests/gsm0808/gsm0808_test.c +++ b/tests/gsm0808/gsm0808_test.c @@ -610,6 +610,88 @@ static void test_gsm0808_enc_dec_encrypt_info() msgb_free(msg); } +static void test_gsm0808_enc_dec_cell_id_list_lac() +{ + struct gsm0808_cell_id_list enc_cil; + struct gsm0808_cell_id_list dec_cil; + struct msgb *msg; + uint8_t rc_enc; + int rc_dec; + + memset(&enc_cil, 0, sizeof(enc_cil)); + enc_cil.id_discr = CELL_IDENT_LAC; + enc_cil.id_list_lac[0] = 0x0124; + enc_cil.id_list_lac[1] = 0xABCD; + enc_cil.id_list_lac[2] = 0x5678; + enc_cil.id_list_len = 3; + + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_cell_id_list(msg, &enc_cil); + OSMO_ASSERT(rc_enc == 9); + + rc_dec = gsm0808_dec_cell_id_list(&dec_cil, msg->data + 2, + msg->len - 2); + OSMO_ASSERT(rc_dec == 7); + + OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); + + msgb_free(msg); +} + +static void test_gsm0808_enc_dec_cell_id_list_single_lac() +{ + struct gsm0808_cell_id_list enc_cil; + struct gsm0808_cell_id_list dec_cil; + struct msgb *msg; + uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03, + 0x05, 0x23, 0x42 + }; + uint8_t rc_enc; + int rc_dec; + + memset(&enc_cil, 0, sizeof(enc_cil)); + enc_cil.id_discr = CELL_IDENT_LAC; + enc_cil.id_list_lac[0] = 0x2342; + enc_cil.id_list_len = 1; + + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_cell_id_list(msg, &enc_cil); + OSMO_ASSERT(rc_enc == 5); + OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0); + + rc_dec = gsm0808_dec_cell_id_list(&dec_cil, msg->data + 2, + msg->len - 2); + OSMO_ASSERT(rc_dec == 3); + + OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); + + msgb_free(msg); +} + +static void test_gsm0808_enc_dec_cell_id_list_bss() +{ + struct gsm0808_cell_id_list enc_cil; + struct gsm0808_cell_id_list dec_cil; + struct msgb *msg; + uint8_t rc_enc; + int rc_dec; + + memset(&enc_cil, 0, sizeof(enc_cil)); + enc_cil.id_discr = CELL_IDENT_LAC; + + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_cell_id_list(msg, &enc_cil); + OSMO_ASSERT(rc_enc == 3); + + rc_dec = gsm0808_dec_cell_id_list(&dec_cil, msg->data + 2, + msg->len - 2); + OSMO_ASSERT(rc_dec == 1); + + OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0); + + msgb_free(msg); +} + int main(int argc, char **argv) { printf("Testing generation of GSM0808 messages\n"); @@ -637,6 +719,9 @@ int main(int argc, char **argv) test_gsm0808_enc_dec_speech_codec_list(); test_gsm0808_enc_dec_channel_type(); test_gsm0808_enc_dec_encrypt_info(); + test_gsm0808_enc_dec_cell_id_list_lac(); + test_gsm0808_enc_dec_cell_id_list_single_lac(); + test_gsm0808_enc_dec_cell_id_list_bss(); printf("Done\n"); return EXIT_SUCCESS; |