Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/test/edu/wpi/hri/gen/comm/GazeKnowledgeTest.javaGo to the documentation of this file.00001 package edu.wpi.hri.gen.comm; 00002 00003 import java.util.ArrayList; 00004 import java.util.List; 00005 00006 import junit.framework.TestCase; 00007 00008 import org.junit.After; 00009 import org.junit.Before; 00010 import org.junit.Test; 00011 00012 import ros.NodeHandle; 00013 import ros.Ros; 00014 import ros.RosException; 00015 import ros.pkg.engagement_msgs.msg.ActorID; 00016 import ros.pkg.engagement_msgs.msg.BCOccurrence; 00017 import ros.pkg.bml_msgs.msg.BehaviorResult; 00018 import ros.pkg.bml_msgs.msg.Entity; 00019 import ros.pkg.bml_msgs.msg.Flag; 00020 import ros.pkg.engagement_msgs.msg.Performance; 00021 import edu.wpi.hri.bml.XMLInterface; 00022 import edu.wpi.hri.comm.MasterSpinner; 00023 import edu.wpi.hri.gen.Generation; 00024 import edu.wpi.hri.gen.ebml.EBMLList; 00025 import edu.wpi.hri.log.Logger; 00026 00027 public class GazeKnowledgeTest extends TestCase { 00028 00029 private NodeHandle handle; 00030 private Logger logger; 00031 private XMLInterface xml; 00032 private MasterSpinner spin; 00033 private BMLRealizer realizer; 00034 private GazeKnowledge gaze; 00035 private boolean listened; 00036 00037 private class TestListener extends GazeListener { 00038 00039 protected TestListener(GazeListener next) { 00040 super(next); 00041 } 00042 00043 @Override 00044 public void gazeChanged(String target, boolean face, boolean lock) { 00045 listened = true; 00046 } 00047 } 00048 00049 @Before 00050 @Override 00051 public void setUp() { 00052 handle = Ros.getInstance().createNodeHandle(); 00053 logger = Logger.createDefault(); 00054 xml = Generation.createXML(logger); 00055 spin = new MasterSpinner(logger, false); 00056 try { 00057 realizer = new BMLRealizer(handle, spin, logger) { 00058 @Override 00059 public Result sendBML(EBMLList list) { 00060 return new Result(Flag.SUCCESS, new ArrayList<BehaviorResult>(), 00061 new ArrayList<BCOccurrence>()); 00062 } 00063 }; 00064 gaze = new GazeKnowledge(handle, logger, xml, realizer); 00065 } catch (RosException e) { 00066 } 00067 gaze.addListener(new TestListener(gaze)); 00068 listened = false; 00069 } 00070 00071 @Test 00072 public void testGetTarget() { 00073 assertTrue(gaze.getTarget() == null || gaze.getTarget().isEmpty()); 00074 String target = "face-test"; 00075 gaze.trySetGaze(target); 00076 assertEquals(target, gaze.getTarget()); 00077 } 00078 00079 @Test 00080 public void testCallPerformance() { 00081 ArrayList<Entity> targets = new ArrayList<Entity>(); 00082 Entity ent = new Entity(); 00083 ent.id = "target-1"; 00084 ent.type = Entity.UNKNOWN; 00085 targets.add(ent); 00086 00087 Performance perf = new Performance(); 00088 perf.actor.id = ActorID.ROBOT; 00089 perf.begin.value = Flag.BEGIN; 00090 perf.objects = targets; 00091 perf.prob = new float[targets.size()]; 00092 for (int c = 0; c < perf.prob.length; c++) 00093 perf.prob[c] = 1.0f; 00094 00095 listened = false; 00096 gaze.call(perf); 00097 assertTrue(listened); 00098 00099 listened = false; 00100 gaze.call(perf); 00101 assertFalse(listened); 00102 00103 perf.objects.get(0).id = "target-2"; 00104 perf.begin.value = Flag.END; 00105 gaze.call(perf); 00106 assertFalse(listened); 00107 00108 perf.begin.value = Flag.BEGIN; 00109 perf.actor.id = "face-test"; 00110 gaze.call(perf); 00111 assertFalse(listened); 00112 } 00113 00114 @After 00115 @Override 00116 public void tearDown() throws Exception { 00117 gaze.shutdown(); 00118 realizer.shutdown(); 00119 spin.stop(); 00120 spin.joinOldMasters(); 00121 handle.shutdown(); 00122 } 00123 } |