00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package gov.lanl.isr.sensix.test;
00036
00037 import junit.framework.*;
00038 import org.omg.CORBA.*;
00039 import org.omg.PortableServer.*;
00040 import gov.lanl.isr.sensix.*;
00041 import gov.lanl.isr.sensix.discovery.*;
00042 import gov.lanl.isr.sensix.sensing.*;
00043
00044
00045 public class ParserTest extends TestCase
00046 {
00047 protected ORB orb;
00048 protected POA poa;
00049
00050 protected void setUp() {
00051 String[] args = null;
00052 java.util.Properties props = null;
00053 try {
00054 orb = ORB.init(args, props);
00055 poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
00056 poa.the_POAManager().activate();
00057 } catch (UserException e) {
00058 fail("CORBA exception on test startup");
00059 }
00060 }
00061
00062 protected void tearDown() {
00063 orb.shutdown(false);
00064 }
00065
00066
00067 public void testInvalidCommand() {
00068 String s = "gobbledygook(foo[bar;baz)";
00069 Sensory sens = null;
00070 try {
00071 sens = SenseParser.senseParser(poa, s);
00072 fail("Should raise an exception on invalid input");
00073 } catch (ParseException e) {
00074 } catch (UserException e) {
00075 } catch (TokenMgrError e) {
00076 } catch (java.io.IOException e) {
00077 } catch (NumberFormatException e) {
00078 }
00079 }
00080
00081 public void testFunctorString() {
00082 String s_orig = "peakSENSE(sEnsOr=temperature,HIGH threshold=5.8)";
00083 PeakSenseImpl psi = new PeakSenseImpl(SenseCorba.TEMP, 5.8, true);
00084 String s_constr = psi.asString();
00085 assertTrue("\nOriginal: " + s_orig + "\nConstructed: " + s_constr,
00086 s_constr.equalsIgnoreCase(s_orig));
00087 }
00088
00089 public void testCompoundFunctorString() {
00090 String s_orig = "recite(spatialseries(" +
00091 "sense(sensor=light,rate=5.0))&&" +
00092 "spatialseries(" +
00093 "peaksense(sensor=accelerometer,rate=5.0,high threshold=3.0)))";
00094 try {
00095 Sensory si = SensoryHelper.narrow(poa.servant_to_reference(
00096 new SenseImpl(SenseCorba.LIGHT, 5.0)));
00097 Sensory psi = SensoryHelper.narrow(poa.servant_to_reference(
00098 new PeakSenseImpl(SenseCorba.ACCEL, 5.0, 3.0, true)));
00099 Collection sl = CollectionHelper.narrow(poa.servant_to_reference(
00100 new SpatialSeriesImpl(si)));
00101 Collection sa = CollectionHelper.narrow(poa.servant_to_reference(
00102 new SpatialSeriesImpl(psi)));
00103 Collection[] c = {sl, sa};
00104 Recite r = ReciteHelper.narrow(poa.servant_to_reference(
00105 new ReciteImpl(c)));
00106 String s_constr = r.asString();
00107 assertTrue("\nOriginal: " + s_orig +
00108 "\nConstructed: " + s_constr,
00109 s_constr.equalsIgnoreCase(s_orig));
00110 } catch (UserException e) {
00111 fail("CORBA exception: Servant not active");
00112 }
00113 }
00114
00115 public void testShortCommand() {
00116 String s_orig = "mean(spatialseries(sense(sensor=temperature)))";
00117 String s_constr = null;
00118 Sensory sens;
00119 try {
00120 sens = SenseParser.senseParser(poa, s_orig);
00121 s_constr = sens.asString();
00122 assertTrue(s_orig.equalsIgnoreCase(s_constr));
00123 } catch (Error e) {
00124 e.printStackTrace(System.err);
00125 fail("\nError on valid command: " + s_orig +
00126 "\nConstructed: " + s_constr);
00127 } catch (Exception e) {
00128 e.printStackTrace(System.err);
00129 fail("\nException on valid command: " + s_orig +
00130 "\nConstructed: " + s_constr);
00131 }
00132 }
00133
00134 public void testMedCommand() {
00135 String s_orig = "sum(spatialseries(sense(level=1,sensor=light)))";
00136 String s_constr = null;
00137 Sensory sens;
00138 try {
00139 sens = SenseParser.senseParser(poa, s_orig);
00140 s_constr = sens.asString();
00141 assertTrue(s_orig.equalsIgnoreCase(s_constr));
00142 } catch (Error e) {
00143 e.printStackTrace(System.err);
00144 fail("\nError on valid command: " + s_orig +
00145 "\nConstructed: " + s_constr);
00146 } catch (Exception e) {
00147 e.printStackTrace(System.err);
00148 fail("\nException on valid command: " + s_orig +
00149 "\nConstructed: " + s_constr);
00150 }
00151 }
00152
00153 public void testCompoundCommand() {
00154 String s_orig = "recite(" +
00155 "timeseries(duration=10," +
00156 "peaksense(sensor=light,rate=5.0,low threshold=2.0))" +
00157 "&&" +
00158 "timeseries(duration=10," +
00159 "peaksense(sensor=accelerometer,rate=5.0,high threshold=3.0))" +
00160 ")";
00161 String s_orig2 = "recite(" +
00162 "timeseries(duration=10," +
00163 "peaksense(sensor=accelerometer,rate=5.0,high threshold=3.0))" +
00164 "&&" +
00165 "timeseries(duration=10," +
00166 "peaksense(sensor=light,rate=5.0,low threshold=2.0))" +
00167 ")";
00168 String s_constr = null;
00169 Sensory sens;
00170 try {
00171 sens = SenseParser.senseParser(poa, s_orig);
00172 s_constr = sens.asString();
00173 assertTrue(s_orig.equalsIgnoreCase(s_constr) ||
00174 s_orig2.equalsIgnoreCase(s_constr));
00175 } catch (Error e) {
00176 e.printStackTrace(System.err);
00177 fail("\nError on valid command: " + s_orig +
00178 "\nConstructed: " + s_constr);
00179 } catch (Exception e) {
00180 e.printStackTrace(System.err);
00181 fail("\nException on valid command: " + s_orig +
00182 "\nConstructed: " + s_constr);
00183 }
00184 }
00185
00186 public void testLongCommand() {
00187 String s_orig = "sum(level=4,spatialseries(level=4," +
00188 "mean(level=3,spatialseries(level=3," +
00189 "delta(level=2,spatialseries(level=2," +
00190 "sigma(level=1,timeseries(level=1,duration=10," +
00191 "sense(level=1,sensor=magnetometer,rate=2.0)))))))))";
00192 String s_constr = null;
00193 Sensory sens;
00194 try {
00195 sens = SenseParser.senseParser(poa, s_orig);
00196 s_constr = sens.asString();
00197 assertTrue(s_orig.equalsIgnoreCase(s_constr));
00198 } catch (Error e) {
00199 e.printStackTrace(System.err);
00200 fail("\nError on valid command: " + s_orig +
00201 "\nConstructed: " + s_constr);
00202 } catch (Exception e) {
00203 e.printStackTrace(System.err);
00204 fail("\nException on valid command: " + s_orig +
00205 "\nConstructed: " + s_constr);
00206 }
00207 }
00208 }