Skip to content

Commit

Permalink
add before/after-hook-func in test
Browse files Browse the repository at this point in the history
  • Loading branch information
knorth55 committed Oct 20, 2022
1 parent 9a75aac commit 750c936
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
7 changes: 6 additions & 1 deletion roseus_smach/test/test-roseus-smach-utils.l
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@
(assert (eq (send *sm* :active-state) (send *sm* :node :end))))

(deftest test-exec-state-machine
(exec-state-machine *sm* '((count . 0)) :spin t :hz 0.5 :root-name "SM_ROOT"))
(exec-state-machine *sm* '((count . 0)) :spin t :hz 0.5 :root-name "SM_ROOT"
:before-hook-func
#'(lambda (userdata) (ros::ros-warn (format nil "userdata (before): ~A" userdata)))
:after-hook-func
#'(lambda (userdata) (ros::ros-warn (format nil "userdata (after): ~A" userdata)))
))

(run-all-tests)
(exit)
43 changes: 31 additions & 12 deletions roseus_smach/test/test-samples.l
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,39 @@
(defun exec-smach-simple2 () (setq count 0) (exec-state-machine (smach-simple2)))
(defun exec-smach-simple3 () (setq count 0) (exec-state-machine (smach-simple3)))
(defun exec-smach-simple-nested () (setq count 0) (exec-state-machine (smach-simple-nested)))
(run-test-smach exec-smach-simple :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO) (BAR) (FOO)))
(run-test-smach exec-smach-simple2 :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO) (BAR) (FOO)))
(run-test-smach exec-smach-simple3 :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO) (BAR) (FOO)))
; (run-test-smach exec-smach-simple :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO) (BAR) (FOO)))
; (run-test-smach exec-smach-simple2 :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO) (BAR) (FOO)))
; (run-test-smach exec-smach-simple3 :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO) (BAR) (FOO)))
;
; (run-test-smach exec-smach-nested :outcome5 '(nil (FOO) (BAR) (FOO) (BAR) (FOO) (BAR) nil (BAS) nil))
; (run-test-smach exec-smach-simple-nested :outcome5 '(nil (FOO) (BAR) (FOO) (BAR) (FOO) (BAR) nil (BAS) nil))
;
; (run-test-smach exec-smach-userdata :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO)))
; (run-test-smach exec-smach-userdata-hook :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO)))
;
; (deftest test-smach-sample-userdata ()
; ; (assert (eq (send (exec-smach-userdata) :name) :outcome4)
; ; "sample of smach with userdata")
; (assert (eq (send (exec-state-machine (smach-userdata)) :name) :outcome4)
; "exec (smach-userdata) without initial userdata"))

(run-test-smach exec-smach-nested :outcome5 '(nil (FOO) (BAR) (FOO) (BAR) (FOO) (BAR) nil (BAS) nil))
(run-test-smach exec-smach-simple-nested :outcome5 '(nil (FOO) (BAR) (FOO) (BAR) (FOO) (BAR) nil (BAS) nil))
(deftest test-smach-sample-userdata-no-hook ()
(let ((mydata '((count . 1) (test-count . 0))))
(exec-state-machine (smach-userdata) mydata)
(assert (eq (cdr (assoc 'test-count mydata)) 0)
"exec (smach-userdata) without hook failed")))

(run-test-smach exec-smach-userdata :outcome4 '((FOO) (BAR) (FOO) (BAR) (FOO)))

(deftest test-smach-sample-userdata ()
; (assert (eq (send (exec-smach-userdata) :name) :outcome4)
; "sample of smach with userdata")
(assert (eq (send (exec-state-machine (smach-userdata)) :name) :outcome4)
"exec (smach-userdata) without initial userdata"))
(deftest test-smach-sample-userdata-hook ()
(let ((mydata '((count . 1) (test-count . 0))))
(exec-state-machine
(smach-userdata) mydata
:before-hook-func
#'(lambda (userdata) (incf (cdr (assoc 'test-count userdata))))
:after-hook-func
#'(lambda (userdata) (incf (cdr (assoc 'test-count userdata))))
)
(assert (eq (cdr (assoc 'test-count mydata)) 10)
"exec (smach-userdata) with hook failed")))

(run-test-smach exec-sample-parallel-state-machine :success '((PRESS-BUTTON) (CLOSE-DOOR) (PUT-SOAP PUT-CLOTH) (OPEN-DOOR)))

Expand Down

0 comments on commit 750c936

Please sign in to comment.