Skip to content

Commit 0598a30

Browse files
committed
Improve testing coverage
1 parent 91ca164 commit 0598a30

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed

test/pubsub.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#typegeneration.jl must be run first
44

55
using geometry_msgs.msg
6-
init_node("jltest", anonymous=true)
7-
const t0 = to_nsec(get_rostime())
86

97
const Nmsgs = 10
108
const rate = 20. #Hz
119
const msgs = PoseStamped[]
1210
const refs = Array(Vector3, Nmsgs)
11+
const t0 = to_nsec(get_rostime())
1312

1413
for i=1:Nmsgs
1514
refs[i] = Vector3(rand(3)...)

test/rospy.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Test basic rospy interactions
2+
init_node("jltest", anonymous=true)
3+
4+
#Parameters
5+
@test length(RobotOS.get_param_names()) > 0
6+
@test has_param("rosdistro")
7+
@test chomp(get_param("rosdistro")) in ["hydro", "indigo", "jade"]
8+
@test ! has_param("some_param")
9+
@test_throws KeyError get_param("some_param")
10+
@test_throws KeyError delete_param("some_param")
11+
@test get_param("some_param", 1.1) == 1.1
12+
@test get_param("some_param", "some_val") == "some_val"
13+
set_param("some_param", "val")
14+
@test get_param("some_param", 1.1) == "val"
15+
delete_param("some_param")
16+
@test ! has_param("some_param")
17+
18+
#Really just running this stuff for coverage
19+
20+
#Logging
21+
logdebug("%s", "debug")
22+
loginfo("%s", "info")
23+
logwarn("%s", "warn")
24+
logerr("%s", "err")
25+
logfatal("%s", "fatal")
26+
@test ! is_shutdown()
27+
28+
#Generic stuff
29+
@test startswith(RobotOS.get_name()[2:end], "jltest")
30+
@test RobotOS.get_namespace() == "/"
31+
RobotOS.get_node_uri()
32+
RobotOS.get_caller_id()
33+
RobotOS.get_published_topics()
34+
RobotOS.get_ros_root()

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using Base.Test
22
using RobotOS
3+
using Compat
34
RobotOS.debug(true)
45

6+
#Generally, later tests rely on things defined in previous tests, so the order
7+
#is important
8+
include("rospy.jl")
59
include("time.jl")
610
include("typegeneration.jl")
711
include("pubsub.jl")

test/services.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#typegeneration.jl and pubsub.jl must be run first
1+
#pubsub.jl must be run first
22

33
using std_srvs.srv
44
using nav_msgs.srv
@@ -24,8 +24,8 @@ function srv_cb(req::GetPlanRequest)
2424
return resp
2525
end
2626

27-
const srvcall = ServiceProxy{Empty}("callme")
28-
const srvlisten = Service{GetPlan}("getplan", srv_cb)
27+
const srvcall = ServiceProxy("callme", Empty)
28+
const srvlisten = Service("getplan", GetPlan, srv_cb)
2929

3030
#Call echo's Empty service
3131
println("Waiting for 'callme' service...")
@@ -49,3 +49,7 @@ if flag[1]
4949
@test_approx_eq(msgs[i].pose.position.z, i)
5050
end
5151
end
52+
53+
#Test error handling
54+
@test_throws ErrorException wait_for_service("fake_srv", timeout=1.0)
55+
@test_throws ArgumentError call(srvcall, EmptyResponse())

test/time.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,64 @@ d3 = Duration(0, 1)
88
@test t1 == Time(1,0)
99
@test t1 != t2
1010
@test t1 > t2
11+
@test t1 >= t2
12+
@test t2 < t1
13+
@test t2 <= t1
1114

1215
@test d1 == Duration(0, 999_999_999)
1316
@test d1 != d2
1417
@test d1 < d2
18+
@test d1 <= d2
19+
@test d2 > d1
20+
@test d2 >= d1
1521

1622
@test t1 + d2 == t3
1723
@test t2 + d3 == t1
1824
@test t1 - t2 == d3
1925
@test t1 - d3 == t2
2026
@test d1 + d2 + d3 == Duration(t3.secs, t3.nsecs)
2127
@test d2 - d1 - d3 == Duration(0, 500_000_000)
28+
29+
tt = Time()
30+
tt.secs = 2
31+
@test tt == Time(2.0)
32+
@test convert(Float64,tt) == 2.0
33+
@test to_sec(tt) == 2.0
34+
@test to_nsec(tt) == 2_000_000_000
35+
36+
dt = Duration()
37+
dt.secs = 3
38+
@test dt == Duration(3.0)
39+
@test convert(Float64,dt) == 3.0
40+
@test to_sec(dt) == 3.0
41+
@test to_nsec(dt) == 3_000_000_000
42+
43+
@test tt + dt == Time(5.0)
44+
@test dt + dt == Duration(6.0)
45+
46+
t1 = get_rostime()
47+
rossleep(0.5)
48+
t2 = get_rostime()
49+
@test t2 - t1 >= Duration(0.4)
50+
51+
rte = Rate(Duration(0.5))
52+
rossleep(rte)
53+
t1 = RobotOS.now()
54+
rossleep(rte)
55+
t2 = RobotOS.now()
56+
rossleep(rte)
57+
t3 = RobotOS.now()
58+
@test t2 - t1 >= Duration(0.4)
59+
@test t3 - t2 >= Duration(0.4)
60+
@test t3 - t1 >= Duration(0.8)
61+
62+
t1 = get_rostime()
63+
RobotOS.sleep(0.5)
64+
t2 = get_rostime()
65+
@test t2 - t1 >= Duration(0.4)
66+
67+
RobotOS.sleep(rte)
68+
t1 = get_rostime()
69+
RobotOS.sleep(rte)
70+
t2 = get_rostime()
71+
@test t2 - t1 >= Duration(0.4)

0 commit comments

Comments
 (0)