summaryrefslogtreecommitdiff
path: root/cesar/cp2/sta/mgr/test/src/station_test.c
blob: e5235ef21da6cf93dac68f6f255f19eb0525e8d5 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/station_test.c
 * \brief   Test the station.
 * \ingroup cp2_sta_mgr
 *
 */

#include "common/std.h"
#include "string.h"

#include "lib/test.h"
#include "lib/bitstream.h"
#include "lib/slab.h"

#include "cp2/sta/mgr/sta.h"

#include "cp2/sta/mgr/inc/sta.h"

/**
 * Initialise a station.
 *
 */
void
test_case_station_init (test_t test)
{
    cp_sta_t *sta;
    cp_sta_private_t station;

    memset (&station, 0, sizeof (cp_sta_private_t));
    sta = cp_sta_init ();

    test_case_begin (test, "Station init");
    test_begin (test, "verify data")
    {
       test_fail_if (memcmp(sta, &station,
                                      sizeof(cp_sta_private_t)) != 0,
                    "Wrong sta is not initialised");
    }
    test_end;
    slab_release (sta);
}

/**
 * Get the TEI of the station.
 *
 * \param test  the test object.
 */
void
test_case_get_tei (test_t test)
{
    cp_sta_private_t station;

    memset (&station, '\0', sizeof (cp_sta_private_t));

    test_case_begin (test, "get station TEI");

    station.tei = 0xA;

    test_begin (test, "Getting TEI")
    {
        test_fail_if (cp_sta_get_tei ((cp_sta_t *) &station) != 0xA,
                      "Wrong TEI");
    }
    test_end;
}

/**
 * Get the Mac address of the station.
 *
 * \param test  the test object.
 */
void
test_case_get_mac_addr (test_t test)
{
    cp_sta_private_t station;

    memset (&station, '\0', sizeof (cp_sta_private_t));

    test_case_begin (test, "get station Mac address");

    station.mac_address = 0x123456789abcull;

    test_begin (test, "Getting Mac address")
    {
        test_fail_if (cp_sta_get_mac_address ((cp_sta_t *) &station)
                      != 0x123456789abcull,
                      "Wrong Mac address");
    }
    test_end;
}

/**
 * Get the peer structure of the station.
 *
 * \param test  the test object.
 */
void
test_case_get_peer (test_t test)
{
    cp_sta_private_t station;

    memset (&station, '\0', sizeof (cp_sta_private_t));

    test_case_begin (test, "get station peer");

    station.tei = 0xA;
    station.mac_address = 0x123456789abcull;

    test_begin (test, "Getting peer")
    {
        cp_mme_peer_t peer;
        cp_sta_get_peer ((cp_sta_t *) &station, &peer);
        test_fail_if (!cp_mme_peer_cmp (
                &peer, &CP_MME_PEER (0x123456789abcull, 0xA)),
            "Wrong peer");
    }
    test_end;
}

/**
 * Get the CCo status of the station.
 *
 * \param test  the test object.
 */
void
test_case_get_cco_status (test_t test)
{
    cp_sta_private_t station;

    memset (&station, '\0', sizeof (cp_sta_private_t));

    test_case_begin (test, "get station CCo status");

    test_begin (test, "Getting CCo status")
    {
        test_fail_if (cp_sta_get_cco_status ((cp_sta_t *) &station)
                      != false,
                      "Wrong CCo status");
    }
    test_end;

    station.is_cco = true;

    test_begin (test, "Getting CCo status true")
    {
        test_fail_if (cp_sta_get_cco_status ((cp_sta_t *) &station)
                      != true,
                      "Wrong CCo status");
    }
    test_end;
}

/**
 * Get the PCo status of the station.
 *
 * \param test  the test object.
 */
void
test_case_get_pco_status (test_t test)
{
    cp_sta_private_t station;

    memset (&station, '\0', sizeof (cp_sta_private_t));

    test_case_begin (test, "get station PCo status");

    test_begin (test, "Getting PCo status")
    {
        test_fail_if (cp_sta_get_pco_status ((cp_sta_t *) &station)
                      != false,
                      "Wrong PCo status");
    }
    test_end;

    station.pco_glid = 0x80;

    test_begin (test, "Getting PCo status true")
    {
        test_fail_if (cp_sta_get_pco_status ((cp_sta_t *) &station)
                      != true,
                      "Wrong PCo status");
    }
    test_end;
}

int
main (void)
{
    test_t test;

    test_init (test, 0, NULL);

    test_case_station_init (test);
    test_case_get_tei (test);
    test_case_get_mac_addr (test);
    test_case_get_peer (test);
    test_case_get_cco_status (test);
    test_case_get_pco_status (test);

    test_result (test);
    return test_nb_failed (test) == 0 ? 0 : 1;
}