aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/test_sms.c
blob: 07680469d075b317158cc3e9f4765702069da3f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include "../common/sample.h"
#include "../common/debug.h"
#include "../common/timer.h"
#include "../nmt/nmt.h"

static const uint8_t test_mo_sms_data[] = {
	0x00, 0x00, 0x00, 0xa1, 0x41, 0x0f, 0x11,
	0x00, 0x04, 0xa1, 0x8a, 0x51,
	0x00, 0x00, 0xff, 0x05, 0xc8, 0x20, 0x93,
	0xf9, 0x7c,
};

static const char *test_mo_sms_text = "HALLO";

static const char *test_mt_sms_text = "Moin Moin";
static const char *test_mt_sms_tel = "4948416068";
static time_t test_mt_sms_time = 851430904;

static const uint8_t test_mt_sms_data[] = {
	0x01, 0x18, 0x53, 0x4d, 0x53, 0x48, 0x18, 0x41, 0x42, 0x43, 0x02,
	0x01,
	0x01,
	0x41,
	0x1a,
	0x04,
	0x0a, 0x91, 0x94, 0x84, 0x14, 0xa6, 0x86,
	0x00,
	0x00,
	0x69, 0x21, 0x42, 0x31, 0x53, 0x4a, 0x48,
	0x09, 0xcd, 0x77, 0xda, 0x0d, 0x6a, 0xbe, 0xd3, 0x6e,
};

static void assert(int condition, char *why)
{
	printf("%s = %s\n", why, (condition) ? "TRUE" : "FALSE");

	if (!condition) {
		printf("\n******************** FAILED ********************\n\n");
		exit(-1);
	}
}

void ok(void)
{
	printf("\n OK ;->\n\n");
	sleep(1);
}

static uint8_t dms_buffer[256];
static int dms_buffer_count;
void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits)
{
//	int i;

	/* skip deliver report */
	if (length == 13)
		return;

	dms_buffer_count = length;
	memcpy(dms_buffer, data, length);

	assert(length == sizeof(test_mt_sms_data), "Expecting SMS binary data length to match");
	assert(!memcmp(data, test_mt_sms_data, length), "Expecting SMS binary data to match");
//	for (i = 0; i < length; i++) {
//		printf("(0x%02x)\n", data[i]);
//	}
}

void sms_release(nmt_t *nmt)
{
	printf("(got release from SMS layer)\n");
}

int sms_submit(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_type, uint8_t orig_plan, int msg_ref, const char *dest_address, uint8_t dest_type, uint8_t dest_plan, const char *message)
{
	strcpy((char *)dms_buffer, message);
	dms_buffer_count = strlen(message);

	return 0;
}

void sms_deliver_report(nmt_t *nmt, uint8_t ref, int error, uint8_t cause)
{
	printf("(got deliver report from SMS layer)\n");
}


int main(void)
{
	nmt_t *nmt;
	int i;
	int rc;

	debuglevel = DEBUG_DEBUG;

	nmt = calloc(sizeof(*nmt), 1);
	sms_init_sender(nmt);
	sms_reset(nmt);

	/* deliver */
	printf("(delivering SMS)\n");
	rc = sms_deliver(nmt, 1, test_mt_sms_tel, SMS_TYPE_INTERNATIONAL, SMS_PLAN_ISDN_TEL, test_mt_sms_time, test_mt_sms_text);
	assert(rc == 0, "Expecting sms_deliver() to return 0");

	sms_cleanup_sender(nmt);
	free(nmt);

	ok();

	nmt = calloc(sizeof(*nmt), 1);
	sms_init_sender(nmt);
	sms_reset(nmt);

	printf("(submitting SMS)\n");
	dms_buffer_count = 0;
	for (i = 0; i < sizeof(test_mo_sms_data); i++)
		dms_receive(nmt, test_mo_sms_data + i, 1, 1);

	assert(dms_buffer_count == strlen(test_mo_sms_text), "Expecting SMS text length to match");
	assert(!memcmp(dms_buffer, test_mo_sms_text, dms_buffer_count), "Expecting SMS text to match");

	sms_cleanup_sender(nmt);
	free(nmt);

	ok();

	return 0;
}