From bff6eb2046e5fb2c227d08c998d97cfe24a77ee3 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Tue, 13 Sep 2022 16:11:06 +0900 Subject: [PATCH] add test to check float/double serialization/deserialization see https://github.com/jsk-ros-pkg/jsk_roseus/pull/721 --- roseus/CMakeLists.txt | 2 ++ roseus/test/pub-double.l | 20 ++++++++++++++ roseus/test/pub-float.l | 20 ++++++++++++++ roseus/test/test-pub-sub-double.test | 4 +++ roseus/test/test-pub-sub-float.test | 4 +++ roseus/test/test-sub-double.l | 41 ++++++++++++++++++++++++++++ roseus/test/test-sub-float.l | 41 ++++++++++++++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 roseus/test/pub-double.l create mode 100644 roseus/test/pub-float.l create mode 100644 roseus/test/test-pub-sub-double.test create mode 100644 roseus/test/test-pub-sub-float.test create mode 100755 roseus/test/test-sub-double.l create mode 100755 roseus/test/test-sub-float.l diff --git a/roseus/CMakeLists.txt b/roseus/CMakeLists.txt index e732689e3..ae4663050 100644 --- a/roseus/CMakeLists.txt +++ b/roseus/CMakeLists.txt @@ -177,6 +177,8 @@ if(CATKIN_ENABLE_TESTING) set_target_properties(simple_execute_ref_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/test) add_rostest(test/test-talker-listener.test) add_rostest(test/test-talker-listener-private-topic.test) + add_rostest(test/test-pub-sub-float.test) + add_rostest(test/test-pub-sub-double.test) add_rostest(test/test-add-two-ints.test) add_rostest(test/test-add-two-ints-server.test) add_rostest(test/test-add-two-ints-server-groupname.test) diff --git a/roseus/test/pub-double.l b/roseus/test/pub-double.l new file mode 100644 index 000000000..1ab60303c --- /dev/null +++ b/roseus/test/pub-double.l @@ -0,0 +1,20 @@ +#!/usr/bin/env roseus +;;; +;;; +(ros::load-ros-manifest "roseus") + +(ros::roseus "pub_double") +(ros::advertise "double" std_msgs::float64 1) +(ros::rate 10) +(setq f 123456.654321) +(while (ros::ok) + (setq msg (instance std_msgs::float64 :init)) + (send msg :data f) + (warning-message 3 "publish msg [~8,8f]~%" (send msg :data)) + (ros::publish "double" msg) + (ros::sleep) + (setq f (* f 2)) + ) +(ros::roseus "shutdown") +(exit) + diff --git a/roseus/test/pub-float.l b/roseus/test/pub-float.l new file mode 100644 index 000000000..4ef133b53 --- /dev/null +++ b/roseus/test/pub-float.l @@ -0,0 +1,20 @@ +#!/usr/bin/env roseus +;;; +;;; +(ros::load-ros-manifest "roseus") + +(ros::roseus "pub_float") +(ros::advertise "float" std_msgs::float32 1) +(ros::rate 10) +(setq f 123.321) +(while (ros::ok) + (setq msg (instance std_msgs::float32 :init)) + (send msg :data f) + (warning-message 3 "publish msg [~8,8f]~%" (send msg :data)) + (ros::publish "float" msg) + (ros::sleep) + (setq f (* f 2)) + ) +(ros::roseus "shutdown") +(exit) + diff --git a/roseus/test/test-pub-sub-double.test b/roseus/test/test-pub-sub-double.test new file mode 100644 index 000000000..40451a094 --- /dev/null +++ b/roseus/test/test-pub-sub-double.test @@ -0,0 +1,4 @@ + + + + diff --git a/roseus/test/test-pub-sub-float.test b/roseus/test/test-pub-sub-float.test new file mode 100644 index 000000000..5014114f9 --- /dev/null +++ b/roseus/test/test-pub-sub-float.test @@ -0,0 +1,4 @@ + + + + diff --git a/roseus/test/test-sub-double.l b/roseus/test/test-sub-double.l new file mode 100755 index 000000000..32f16930d --- /dev/null +++ b/roseus/test/test-sub-double.l @@ -0,0 +1,41 @@ +#!/usr/bin/env roseus +;;; +;;; +(ros::load-ros-manifest "roseus") +(require :unittest "lib/llib/unittest.l") + +(init-unit-test) + + +(ros::roseus "sub_double") +;; method call +(defclass double-cb-class + :super propertied-object + :slots (count prev-msg)) +(defmethod double-cb-class + (:init + () + (setq count 0) + (setq prev-msg nil) + (ros::subscribe "double" std_msgs::float64 #'send self :double-cb)) + (:double-cb + (msg) + (warning-message 2 "subscribe msg [~8,8f], ~A times bigger than previous data~%" (send msg :data) (if prev-msg (/ (send msg :data) (send prev-msg :data)))) + (when prev-msg + (assert (eps= (/ (send msg :data) (send prev-msg :data)) 2.0)) + ) + (incf count) + (setq prev-msg msg) + ) + (:count () count) + ) + +(deftest test-sub-double () + (setq m (instance double-cb-class :init)) + + (while (< (send m :count) 10) + (ros::spin-once) + )) + +(run-all-tests) +(exit) diff --git a/roseus/test/test-sub-float.l b/roseus/test/test-sub-float.l new file mode 100755 index 000000000..b930ac01a --- /dev/null +++ b/roseus/test/test-sub-float.l @@ -0,0 +1,41 @@ +#!/usr/bin/env roseus +;;; +;;; +(ros::load-ros-manifest "roseus") +(require :unittest "lib/llib/unittest.l") + +(init-unit-test) + + +(ros::roseus "sub_float") +;; method call +(defclass float-cb-class + :super propertied-object + :slots (count prev-msg)) +(defmethod float-cb-class + (:init + () + (setq count 0) + (setq prev-msg nil) + (ros::subscribe "float" std_msgs::float32 #'send self :float-cb)) + (:float-cb + (msg) + (warning-message 2 "subscribe msg [~8,8f], ~A times bigger than previous data~%" (send msg :data) (if prev-msg (/ (send msg :data) (send prev-msg :data)))) + (when prev-msg + (assert (eps= (/ (send msg :data) (send prev-msg :data)) 2.0)) + ) + (incf count) + (setq prev-msg msg) + ) + (:count () count) + ) + +(deftest test-sub-float () + (setq m (instance float-cb-class :init)) + + (while (< (send m :count) 10) + (ros::spin-once) + )) + +(run-all-tests) +(exit)