File: DiscoveryTest.cc

package info (click to toggle)
alljoyn-thin-client-1604 16.04-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,480 kB
  • sloc: ansic: 59,739; cpp: 2,759; python: 361; sh: 174; makefile: 39
file content (234 lines) | stat: -rw-r--r-- 12,041 bytes parent folder | download | duplicates (4)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/******************************************************************************
 *
 *
 * Copyright AllSeen Alliance. All rights reserved.
 *
 *    Permission to use, copy, modify, and/or distribute this software for any
 *    purpose with or without fee is hereby granted, provided that the above
 *    copyright notice and this permission notice appear in all copies.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************************/

#include <gtest/gtest.h>

extern "C" {
#include <ajtcl/aj_debug.h>
#include <ajtcl/alljoyn.h>
}

class DiscoveryTest : public testing::Test {
  public:

    virtual void SetUp() {
        AJ_Initialize();

    }
    virtual void TearDown() {
    }
};

TEST_F(DiscoveryTest, DiscoverValidBusNodeName)
{
    // Attempt to discover a valid bus node name that is being advertised.
    AJ_Service service;
    AJ_Service newService = { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&newService);
    AJ_Status status = AJ_Discover("org.alljoyn.BusNode", &service, 5000, 5000);
    AJ_InitRoutingNodeResponselist();
    EXPECT_EQ(AJ_OK, status) << "Unable to discover routing node. Got status " << AJ_StatusText(status);

}

TEST_F(DiscoveryTest, DiscoverInValidBusNodeName)
{
    // Attempt to discover an invalid bus node name that is not being advertised.
    AJ_Service service;
    AJ_InitRoutingNodeResponselist();
    AJ_Status status = AJ_Discover("org.alljoyn.BusNodezzzz", &service, 5000, 5000);
    EXPECT_EQ(AJ_ERR_TIMEOUT, status) << "Able to discover invalid routing node. Got status " << AJ_StatusText(status);
}

TEST_F(DiscoveryTest, SelectPriority)
{
    // Select between two routing nodes with different priorities.
    AJ_Service service;
    AJ_Service serviceHighScore = { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowScore =  { 0, 0, 0, 0, 0x0200007f, 5678, 0, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceHighScore);
    AJ_AddRoutingNodeToResponseList(&serviceLowScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHighScore.priority, service.priority) << "Wrong priority selected from the response list";
    EXPECT_EQ(serviceHighScore.ipv4, service.ipv4) << "Wrong ipv4 address selected from the response list";
}

TEST_F(DiscoveryTest, UpdatePriority)
{
    // Select between two routing nodes with different priorities.
    AJ_Service service;
    AJ_Service serviceHighScore = { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowScore =  { 0, 0, 0, 0, 0x0100007f, 5678, 0, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceLowScore);
    AJ_AddRoutingNodeToResponseList(&serviceHighScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHighScore.priority, service.priority) << "Priority not updated in response list";
}

TEST_F(DiscoveryTest, SelectProtocolVersion)
{
    // Select between two routing nodes with different protocol versions.
    AJ_Service service;
    AJ_Service serviceOldProtocol = { 0, 0, 0, 0, 0x0100007f, 0, 11, { 0, 0, 0, 0 } };
    AJ_Service serviceNewProtocol =  { 0, 0, 0, 0, 0x0200007f, 5678, 12, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceOldProtocol);
    AJ_AddRoutingNodeToResponseList(&serviceNewProtocol);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceNewProtocol.priority, service.priority) << "Wrong priority selected from the response list";
    EXPECT_EQ(serviceNewProtocol.ipv4, service.ipv4) << "Wrong priority selected from the response list";
}

TEST_F(DiscoveryTest, UpdateProtocolVersion)
{
    // Select between two routing nodes with different protocol versions.
    AJ_Service service;
    AJ_Service serviceOldProtocol = { 0, 0, 0, 0, 0x0100007f, 1234, 11, { 0, 0, 0, 0 } };
    AJ_Service serviceNewProtocol =  { 0, 0, 0, 0, 0x0100007f, 5678, 12, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceOldProtocol);
    AJ_AddRoutingNodeToResponseList(&serviceNewProtocol);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceNewProtocol.priority, service.priority) << "Priority not updated in the response list";
    EXPECT_EQ(serviceNewProtocol.pv, service.pv) << "Protocol version not updated in the response list";
    EXPECT_EQ(serviceNewProtocol.ipv4, service.ipv4) << "Wrong priority selected from the response list";
}

TEST_F(DiscoveryTest, ExhaustSelection)
{
    // Select from the response list until there are no more responses available.
    AJ_Service service;
    AJ_Service serviceHighScore = { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowScore =  { 0, 0, 0, 0, 0x0200007f, 5678, 0, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceHighScore);
    AJ_AddRoutingNodeToResponseList(&serviceLowScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    status = AJ_SelectRoutingNodeFromResponseList(&service);
    status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_ERR_END_OF_DATA, status) << "Response list was not exhausted after all nodes were selected";
}

TEST_F(DiscoveryTest, SelectPriorityListFullVarious)
{
    // Select correct routing node after adding best priority to a list that is full of various priorities
    AJ_Service service;
    AJ_Service serviceHigherScore =  { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore1 = { 0, 0, 0, 0, 0x0200007f, 2345, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore2 = { 0, 0, 0, 0, 0x0300007f, 3456, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore3 =  { 0, 0, 0, 0, 0x0400007f, 4567, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore4 =  { 0, 0, 0, 0, 0x0500007f, 5678, 0, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore2);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore3);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore4);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore1);
    AJ_AddRoutingNodeToResponseList(&serviceHigherScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHigherScore.ipv4, service.ipv4) << "Wrong ipv4 address selected from the response list";
}

TEST_F(DiscoveryTest, SelectPriorityListFullEqual)
{
    // Select correct routing node after adding best priority to a list that is full of equal priorities
    AJ_Service service;
    AJ_Service serviceHigherScore =  { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore1 = { 0, 0, 0, 0, 0x0200007f, 5678, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore2 = { 0, 0, 0, 0, 0x0300007f, 5678, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore3 =  { 0, 0, 0, 0, 0x0400007f, 5678, 0, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore2);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore3);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore1);
    AJ_AddRoutingNodeToResponseList(&serviceHigherScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHigherScore.ipv4, service.ipv4) << "Wrong ipv4 address selected from the response list";
}

TEST_F(DiscoveryTest, SelectPriorityListFullDoNotEvict)
{
    // Select correct routing node after attempting to add lesser score to a list that is full of various priorities
    AJ_Service service;
    AJ_Service serviceHigherScore =  { 0, 0, 0, 0, 0x0100007f, 1234, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore1 = { 0, 0, 0, 0, 0x0200007f, 2345, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore2 = { 0, 0, 0, 0, 0x0300007f, 3456, 0, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore3 =  { 0, 0, 0, 0, 0x0400007f, 4567, 0, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore2);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore1);
    AJ_AddRoutingNodeToResponseList(&serviceHigherScore);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore3);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHigherScore.ipv4, service.ipv4) << "Wrong ipv4 address selected from the response list";
}

TEST_F(DiscoveryTest, SelectProtocolVersionListFullEqual)
{
    // Select correct routing node after adding better protocol version to a list that is full of equal protocol versi
    AJ_Service service;
    AJ_Service serviceHigherScore =  { 0, 0, 0, 0, 0x0100007f, 6789, 12, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore1 = { 0, 0, 0, 0, 0x0200007f, 5678, 11, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore2 = { 0, 0, 0, 0, 0x0300007f, 5678, 11, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore3 =  { 0, 0, 0, 0, 0x0400007f, 5678, 11, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore2);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore3);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore1);
    AJ_AddRoutingNodeToResponseList(&serviceHigherScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHigherScore.ipv4, service.ipv4) << "Wrong ipv4 address selected from the response list";
}

TEST_F(DiscoveryTest, SelectProtocolVersionPriorityListFullEqual)
{
    // Select correct routing node after adding better protocol version and priority to a list that is full of equal protocol versi
    AJ_Service service;
    AJ_Service serviceHigherScore =  { 0, 0, 0, 0, 0x0100007f, 1234, 12, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore1 = { 0, 0, 0, 0, 0x0200007f, 5678, 11, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore2 = { 0, 0, 0, 0, 0x0300007f, 5678, 11, { 0, 0, 0, 0 } };
    AJ_Service serviceLowerScore3 =  { 0, 0, 0, 0, 0x0400007f, 5678, 11, { 0, 0, 0, 0 } };

    AJ_InitRoutingNodeResponselist();
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore2);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore3);
    AJ_AddRoutingNodeToResponseList(&serviceLowerScore1);
    AJ_AddRoutingNodeToResponseList(&serviceHigherScore);
    AJ_Status status = AJ_SelectRoutingNodeFromResponseList(&service);
    EXPECT_EQ(AJ_OK, status) << "Unable to select any routing node from the response list ";
    EXPECT_EQ(serviceHigherScore.ipv4, service.ipv4) << "Wrong ipv4 address selected from the response list";
}