Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame^] | 1 | /* some humble start of unit testing */ |
| 2 | |
| 3 | /* (C) 2015 by Harald Welte <laforge@gnumonks.org> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | |
Harald Welte | 35cbc11 | 2015-09-11 17:36:59 +0200 | [diff] [blame] | 22 | #include "iu_helpers.h" |
| 23 | #include "asn1helpers.h" |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #define ASSERT(x) assert(x) |
| 27 | |
| 28 | #include <osmocom/core/utils.h> |
| 29 | |
| 30 | void *talloc_asn1_ctx; |
| 31 | |
| 32 | /* use odd number of digits */ |
| 33 | const uint8_t imsi_encoded[] = { 0x10, 0x32, 0x54, 0x76, 0xF8 }; |
| 34 | const char imsi_decoded[] = "012345678"; |
| 35 | |
| 36 | int main(int argc, char **argv) |
| 37 | { |
| 38 | char outstr[32]; |
| 39 | uint8_t outbuf[16]; |
| 40 | int rc; |
| 41 | |
| 42 | printf("pre-encoded: %s\n", osmo_hexdump_nospc(imsi_encoded, |
| 43 | sizeof(imsi_encoded))); |
| 44 | rc = decode_iu_bcd(outstr, sizeof(outstr), imsi_encoded, |
| 45 | sizeof(imsi_encoded)); |
| 46 | ASSERT(rc >= 0); |
| 47 | printf("decoded: %s\n", outstr); |
| 48 | ASSERT(!strcmp(outstr, imsi_decoded)); |
| 49 | |
| 50 | rc = encode_iu_imsi(outbuf, sizeof(outbuf), imsi_decoded); |
| 51 | ASSERT(rc >= 0); |
| 52 | printf("re-encoded: %s\n", osmo_hexdump_nospc(outbuf, rc)); |
| 53 | ASSERT(!memcmp(outbuf, imsi_encoded, sizeof(imsi_encoded))); |
| 54 | |
| 55 | return 0; |
| 56 | } |