blob: 9b94c63f47adf4180dfbe5b9c7ec1ec7ea532167 [file] [log] [blame]
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +02001/*
2 * (C) 2013 by Holger Hans Peter Freyther
Harald Weltee6f11602022-05-17 18:25:14 +02003 * (C) 2022 by Harald Welte <laforge@osmocom.org>
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +02004 * 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#include <stdlib.h>
22#include <stdio.h>
23
Neels Hofmeyr90843962017-09-04 15:04:35 +020024#include <osmocom/msc/debug.h>
Max5346f692022-07-28 14:19:22 +070025#include <osmocom/smpp/smpp_smsc.h>
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +020026#include <osmocom/core/application.h>
27#include <osmocom/core/backtrace.h>
28
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +020029struct coding_test {
30 uint8_t dcs;
31 uint8_t coding;
32 int mode;
33 int res;
34};
35
36static struct coding_test codecs[] = {
37 { .dcs = 0xf6 , .coding = 0x02, .mode = MODE_8BIT, .res = 0 },
38 { .dcs = 0xf2 , .coding = 0x01, .mode = MODE_7BIT, .res = 0 },
39 { .dcs = 0x02 , .coding = 0x01, .mode = MODE_7BIT, .res = 0 },
40 { .dcs = 0x06 , .coding = 0x02, .mode = MODE_8BIT, .res = 0 },
41 { .dcs = 0x0A , .coding = 0x08, .mode = MODE_8BIT, .res = 0 },
42 { .dcs = 0x0E , .coding = 0xFF, .mode = 0xFF, .res = -1 },
43 { .dcs = 0xE0 , .coding = 0xFF, .mode = 0xFF, .res = -1 },
44};
45
46static void test_coding_scheme(void)
47{
48 int i;
49 printf("Testing coding scheme support\n");
50
51 for (i = 0; i < ARRAY_SIZE(codecs); ++i) {
52 uint8_t coding;
53 int mode, res;
54
55 res = smpp_determine_scheme(codecs[i].dcs, &coding, &mode);
56 OSMO_ASSERT(res == codecs[i].res);
57 if (res != -1) {
58 OSMO_ASSERT(mode == codecs[i].mode);
59 OSMO_ASSERT(coding == codecs[i].coding);
60 }
61 }
62}
63
Harald Weltee6f11602022-05-17 18:25:14 +020064static const char *smpp_time_tests[] = {
65 "\0",
66 "220517175524000+",
67 "220517175524000-",
68 "220517175524004+", /* 1 hour advanced compared to GMT */
69 "220517175524004-", /* 1 hour retarded compared to GMT */
70 "000000010000000R", /* 1 hour */
71 "000001000000000R", /* 1 day */
72};
73
74static void test_smpp_parse_time_format(void)
75{
76 time_t t_now = 1652745600; /* 2022-05-17 00:00:00 UTC */
77 char *orig_tz;
78
79 printf("Testing SMPP time format parser\n");
80
81 /* relative time format conversion depends on the local time */
82 orig_tz = getenv("TZ");
83 setenv("TZ", "UTC", 1);
84
85 for (unsigned int i = 0; i < ARRAY_SIZE(smpp_time_tests); i++) {
86 time_t t = smpp_parse_time_format(smpp_time_tests[i], &t_now);
87 char buf[32];
88 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", gmtime(&t));
89 printf("'%s': %ld == %s\n", smpp_time_tests[i], t, buf);
90 }
91
92 if (orig_tz)
93 setenv("TZ", orig_tz, 1);
94 else
95 unsetenv("TZ");
96
97}
98
Neels Hofmeyr6a8b9c72018-03-22 15:51:22 +010099static const struct log_info_cat smpp_mirror_default_categories[] = {
100 [DSMPP] = {
101 .name = "DSMPP",
102 .description = "SMPP interface for external SMS apps",
103 .enabled = 1, .loglevel = LOGL_DEBUG,
104 },
105};
106
107const struct log_info log_info = {
108 .cat = smpp_mirror_default_categories,
109 .num_cat = ARRAY_SIZE(smpp_mirror_default_categories),
110};
111
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +0200112int main(int argc, char **argv)
113{
Neels Hofmeyr08b38282018-03-30 23:04:04 +0200114 void *ctx = talloc_named_const(NULL, 0, "smpp_test");
115 osmo_init_logging2(ctx, &log_info);
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +0200116 log_set_use_color(osmo_stderr_target, 0);
Pau Espin Pedrolcad22fd2021-02-19 13:37:00 +0100117 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
Pau Espin Pedrol8d02d992021-02-19 13:36:47 +0100118 log_set_print_category(osmo_stderr_target, 0);
119 log_set_print_category_hex(osmo_stderr_target, 0);
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +0200120
121 test_coding_scheme();
Harald Weltee6f11602022-05-17 18:25:14 +0200122 test_smpp_parse_time_format();
123
Holger Hans Peter Freythera7328a52013-07-13 17:09:56 +0200124 return EXIT_SUCCESS;
125}