Holger Hans Peter Freyther | b79a148 | 2014-01-02 13:55:00 +0100 | [diff] [blame] | 1 | /* tests for utilities of libmsomcore */ |
| 2 | /* |
| 3 | * (C) 2014 Holger Hans Peter Freyther |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
Holger Hans Peter Freyther | f558ed4 | 2015-06-02 15:52:06 +0200 | [diff] [blame] | 23 | #include <osmocom/gsm/ipa.h> |
| 24 | |
| 25 | #include <osmocom/core/logging.h> |
Holger Hans Peter Freyther | b79a148 | 2014-01-02 13:55:00 +0100 | [diff] [blame] | 26 | #include <osmocom/core/utils.h> |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | |
| 30 | static void hexdump_test(void) |
| 31 | { |
| 32 | uint8_t data[4098]; |
| 33 | int i; |
| 34 | |
| 35 | for (i = 0; i < ARRAY_SIZE(data); ++i) |
| 36 | data[i] = i & 0xff; |
| 37 | |
| 38 | printf("Plain dump\n"); |
| 39 | printf("%s\n", osmo_hexdump(data, 4)); |
| 40 | |
| 41 | printf("Corner case\n"); |
| 42 | printf("%s\n", osmo_hexdump(data, ARRAY_SIZE(data))); |
| 43 | printf("%s\n", osmo_hexdump_nospc(data, ARRAY_SIZE(data))); |
| 44 | } |
| 45 | |
Holger Hans Peter Freyther | f558ed4 | 2015-06-02 15:52:06 +0200 | [diff] [blame] | 46 | static void test_idtag_parsing(void) |
| 47 | { |
| 48 | struct tlv_parsed tvp; |
| 49 | int rc; |
| 50 | |
| 51 | static uint8_t data[] = { |
| 52 | 0x01, 0x08, |
| 53 | 0x01, 0x07, |
| 54 | 0x01, 0x02, |
| 55 | 0x01, 0x03, |
| 56 | 0x01, 0x04, |
| 57 | 0x01, 0x05, |
| 58 | 0x01, 0x01, |
| 59 | 0x01, 0x00, |
| 60 | 0x11, 0x23, 0x4e, 0x6a, 0x28, 0xd2, 0xa2, 0x53, 0x3a, 0x2a, 0x82, 0xa7, 0x7a, 0xef, 0x29, 0xd4, 0x44, 0x30, |
| 61 | 0x11, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 62 | }; |
| 63 | |
| 64 | rc = ipa_ccm_idtag_parse_off(&tvp, data, sizeof(data), 1); |
| 65 | OSMO_ASSERT(rc == 0); |
| 66 | |
| 67 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 8)); |
| 68 | OSMO_ASSERT(TLVP_LEN(&tvp, 8) == 0); |
| 69 | |
| 70 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 7)); |
| 71 | OSMO_ASSERT(TLVP_LEN(&tvp, 7) == 0); |
| 72 | |
| 73 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 2)); |
| 74 | OSMO_ASSERT(TLVP_LEN(&tvp, 2) == 0); |
| 75 | |
| 76 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 3)); |
| 77 | OSMO_ASSERT(TLVP_LEN(&tvp, 3) == 0); |
| 78 | |
| 79 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 4)); |
| 80 | OSMO_ASSERT(TLVP_LEN(&tvp, 4) == 0); |
| 81 | |
| 82 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 5)); |
| 83 | OSMO_ASSERT(TLVP_LEN(&tvp, 5) == 0); |
| 84 | |
| 85 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 1)); |
| 86 | OSMO_ASSERT(TLVP_LEN(&tvp, 1) == 0); |
| 87 | |
| 88 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 0)); |
| 89 | OSMO_ASSERT(TLVP_LEN(&tvp, 0) == 0); |
| 90 | |
| 91 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 0x23)); |
| 92 | OSMO_ASSERT(TLVP_LEN(&tvp, 0x23) == 16); |
| 93 | |
| 94 | OSMO_ASSERT(TLVP_PRESENT(&tvp, 0x24)); |
| 95 | OSMO_ASSERT(TLVP_LEN(&tvp, 0x24) == 16); |
| 96 | |
| 97 | OSMO_ASSERT(!TLVP_PRESENT(&tvp, 0x25)); |
| 98 | } |
| 99 | |
Holger Hans Peter Freyther | b79a148 | 2014-01-02 13:55:00 +0100 | [diff] [blame] | 100 | int main(int argc, char **argv) |
| 101 | { |
Holger Hans Peter Freyther | f558ed4 | 2015-06-02 15:52:06 +0200 | [diff] [blame] | 102 | static const struct log_info log_info = {}; |
| 103 | log_init(&log_info, NULL); |
| 104 | |
Holger Hans Peter Freyther | b79a148 | 2014-01-02 13:55:00 +0100 | [diff] [blame] | 105 | hexdump_test(); |
Holger Hans Peter Freyther | f558ed4 | 2015-06-02 15:52:06 +0200 | [diff] [blame] | 106 | test_idtag_parsing(); |
Holger Hans Peter Freyther | b79a148 | 2014-01-02 13:55:00 +0100 | [diff] [blame] | 107 | return 0; |
| 108 | } |