Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
c9244f09
Commit
c9244f09
authored
Jan 04, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(UNetUDP): написал базовый тест для проверки UNetReceiver
parent
c83719b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
2 deletions
+76
-2
test_unetudp.cc
extensions/UNetUDP/tests/test_unetudp.cc
+69
-0
unetudp-test-configure.xml
extensions/UNetUDP/tests/unetudp-test-configure.xml
+7
-2
No files found.
extensions/UNetUDP/tests/test_unetudp.cc
View file @
c9244f09
...
...
@@ -13,6 +13,12 @@ static ost::IPV4Host host("127.255.255.255");
static
UInterface
*
ui
=
nullptr
;
static
ObjectId
aid
=
2
;
static
ost
::
UDPDuplex
*
udp_r
=
nullptr
;
static
ost
::
UDPBroadcast
*
udp_s
=
nullptr
;
static
int
s_port
=
3003
;
// Node2
static
int
s_nodeID
=
3003
;
static
int
s_procID
=
123
;
static
int
s_numpack
=
1
;
static
ObjectId
node2_respond_s
=
12
;
// -----------------------------------------------------------------------------
void
InitTest
()
{
...
...
@@ -30,6 +36,9 @@ void InitTest()
if
(
udp_r
==
nullptr
)
udp_r
=
new
ost
::
UDPDuplex
(
host
,
port
);
if
(
udp_s
==
nullptr
)
udp_s
=
new
ost
::
UDPBroadcast
(
host
,
s_port
);
}
// -----------------------------------------------------------------------------
// pnum - минималный номер ожидаемого пакета ( 0 - любой пришедщий )
...
...
@@ -56,6 +65,20 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
return
std
::
move
(
pack
);
}
// -----------------------------------------------------------------------------
void
send
(
UniSetUDP
::
UDPMessage
&
pack
,
int
tout
=
2000
)
{
CHECK
(
udp_s
->
isPending
(
ost
::
Socket
::
pendingOutput
,
tout
)
);
pack
.
nodeID
=
s_nodeID
;
pack
.
procID
=
s_procID
;
pack
.
num
=
s_numpack
++
;
UniSetUDP
::
UDPPacket
s_buf
;
pack
.
transport_msg
(
s_buf
);
size_t
ret
=
udp_s
->
send
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
REQUIRE
(
ret
==
s_buf
.
len
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[UNetUDP]: UDPMessage"
,
"[unetudp][udpmessage]"
)
{
SECTION
(
"UDPMessage::isFull()"
)
...
...
@@ -182,3 +205,49 @@ TEST_CASE("[UNetUDP]: check sender","[unetudp][sender]")
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[UNetUDP]: check receiver"
,
"[unetudp][receiver]"
)
{
InitTest
();
SECTION
(
"Test: send data pack..."
)
{
REQUIRE
(
ui
->
getValue
(
node2_respond_s
)
==
0
);
UniSetUDP
::
UDPMessage
pack
;
pack
.
addAData
(
8
,
100
);
pack
.
addAData
(
9
,
-
100
);
pack
.
addDData
(
10
,
true
);
pack
.
addDData
(
11
,
false
);
REQUIRE
(
ui
->
getValue
(
8
)
==
0
);
REQUIRE
(
ui
->
getValue
(
9
)
==
0
);
REQUIRE
(
ui
->
getValue
(
10
)
==
0
);
REQUIRE
(
ui
->
getValue
(
11
)
==
0
);
send
(
pack
);
msleep
(
120
);
REQUIRE
(
ui
->
getValue
(
8
)
==
100
);
REQUIRE
(
ui
->
getValue
(
9
)
==
-
100
);
REQUIRE
(
ui
->
getValue
(
10
)
==
1
);
REQUIRE
(
ui
->
getValue
(
11
)
==
0
);
REQUIRE
(
ui
->
getValue
(
node2_respond_s
)
==
1
);
}
SECTION
(
"Test: send data pack2.."
)
{
UniSetUDP
::
UDPMessage
pack
;
pack
.
addAData
(
8
,
10
);
pack
.
addAData
(
9
,
-
10
);
pack
.
addDData
(
10
,
false
);
pack
.
addDData
(
11
,
true
);
send
(
pack
);
msleep
(
120
);
REQUIRE
(
ui
->
getValue
(
8
)
==
10
);
REQUIRE
(
ui
->
getValue
(
9
)
==
-
10
);
REQUIRE
(
ui
->
getValue
(
10
)
==
0
);
REQUIRE
(
ui
->
getValue
(
11
)
==
1
);
REQUIRE
(
ui
->
getValue
(
node2_respond_s
)
==
1
);
msleep
(
3000
);
// в запускающем файле стоит --unet-recv-timeout 2000
REQUIRE
(
ui
->
getValue
(
node2_respond_s
)
==
0
);
}
}
// -----------------------------------------------------------------------------
extensions/UNetUDP/tests/unetudp-test-configure.xml
View file @
c9244f09
...
...
@@ -35,8 +35,8 @@
<nodes
port=
"2809"
unet_broadcast_ip=
"127.255.255.255"
>
<item
id=
"3000"
ip=
"127.0.0.1"
name=
"localhost"
textname=
"Локальный узел"
unet_ignore=
"0"
unet_port=
"3000"
/>
<item
id=
"3001"
ip=
"127.0.0.1"
name=
"localhost1"
textname=
"Локальный узел"
unet_ignore=
"1"
unet_port=
"3001"
/>
<item
id=
"3002"
ip=
"192.168.56.10"
name=
"Node1"
textname=
"Node1"
unet_ignore=
"0"
unet_ip=
"192.168.56.255"
unet_
port=
"3001"
unet_
respond_id=
"Node1_Respond_S"
unet_respond_invert=
"1"
/>
<item
id=
"3003"
ip=
"192.168.56.11"
name=
"Node2"
textname=
"Node2"
unet_ignore=
"0"
unet_ip=
"192.168.56.255"
unet_
port=
"3002
"
/>
<item
id=
"3002"
ip=
"192.168.56.10"
name=
"Node1"
textname=
"Node1"
unet_ignore=
"0"
unet_ip=
"192.168.56.255"
unet_respond_id=
"Node1_Respond_S"
unet_respond_invert=
"1"
/>
<item
id=
"3003"
ip=
"192.168.56.11"
name=
"Node2"
textname=
"Node2"
unet_ignore=
"0"
unet_ip=
"192.168.56.255"
unet_
respond_id=
"Node2_Respond_S
"
/>
</nodes>
<!-- ************************ Датчики ********************** -->
<sensors
name=
"Sensors"
>
...
...
@@ -49,6 +49,11 @@
<item
id=
"5"
iotype=
"AI"
name=
"AI4_S"
textname=
"AI sensor 4"
unet=
"1"
default=
"4"
/>
<item
id=
"6"
iotype=
"DI"
name=
"DI1_S"
textname=
"DI sensor 1"
unet=
"1"
default=
"1"
/>
<item
id=
"7"
iotype=
"DI"
name=
"DI2_S"
textname=
"DI sensor 2"
unet=
"1"
/>
<item
id=
"8"
iotype=
"AI"
name=
"AI3_S"
textname=
"AI sensor 3"
/>
<item
id=
"9"
iotype=
"AI"
name=
"AI4_S"
textname=
"AI sensor 4"
/>
<item
id=
"10"
iotype=
"DI"
name=
"DI3_S"
textname=
"DI sensor 3"
/>
<item
id=
"11"
iotype=
"DI"
name=
"DI4_S"
textname=
"DI sensor 4"
/>
<item
id=
"12"
iotype=
"DI"
name=
"Node2_Respond_S"
textname=
"Node2 respond"
/>
</sensors>
<thresholds
name=
"thresholds"
/>
<controllers
name=
"Controllers"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment