00001
00012 package dndtester;
00013 import java.net.*;
00014 import java.io.*;
00015 import java.util.*;
00016 import java.text.*;
00017 import javax.swing.*;
00018 import java.awt.*;
00019
00025 public class DaqTests{
00027 protected static int DATAPORT = 55056;
00028
00030 protected static int COMMANDPORT = 55055;
00031
00033 private InetAddress remoteAddr;
00034
00036 private Socket dataSocket = null;
00037
00039 private Socket commandSock = null;
00040
00042 protected BufferedReader commReader = null;
00043
00045 protected BufferedReader dataReader = null;
00046
00048 protected PrintStream commPStream = null;
00049
00052 private boolean dialog = false;
00053
00055 private boolean connection = false;
00056
00058 protected boolean validConnect = false;
00059
00061 protected Hashtable channelTable;
00062
00065 public static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss.SSS");
00066
00068 private JProgressBar progressBar = null;
00069
00071 private int increment = 0;
00072
00080 public DaqTests(String hostname){
00081 channelTable = new Hashtable();
00082 try{
00083
00084 remoteAddr = InetAddress.getByName(hostname);
00085 }catch(UnknownHostException e1){
00086 JOptionPane.showMessageDialog(null, "Unknown Host",
00087 "Error", JOptionPane.ERROR_MESSAGE);
00088 return;
00089 }
00090
00091 DialogThread dialogThread = new DialogThread();
00092 ConnectingThread connectThread = new ConnectingThread(dialogThread);
00093 dialogThread.setToKill(connectThread);
00094
00095 connectThread.start();
00096
00097 dialogThread.start();
00098 }
00099
00104 class ConnectingThread extends Thread{
00107 boolean killed = false;
00108
00110 boolean failed = false;
00111
00113 Thread toKill;
00114
00120 public ConnectingThread(Thread tokill){
00121 toKill = tokill;
00122 }
00128 public void destroy(){
00129 killed = true;
00130 }
00131
00138 public void run(){
00139 connection = true;
00140 try{
00141 InetSocketAddress inetCommandAddress =
00142 new InetSocketAddress(remoteAddr, COMMANDPORT);
00143 Socket temp = new Socket();
00144
00145 try{
00146
00147
00148 Thread.sleep(100);
00149 }catch(InterruptedException e2){}
00150
00151
00152 temp.connect(inetCommandAddress, 20000);
00153
00154 commandSock = temp;
00155 InetSocketAddress inetDataAddress =
00156 new InetSocketAddress(remoteAddr, DATAPORT);
00157 temp = new Socket();
00158 try{
00159
00160
00161 Thread.sleep(1000);
00162 }catch(InterruptedException e2){}
00163
00164 temp.connect(inetDataAddress, 20000);
00165
00166 dataSocket = temp;
00167
00168
00169
00170 commReader = new BufferedReader (new InputStreamReader
00171 (commandSock.getInputStream()));
00172 dataReader = new BufferedReader (new InputStreamReader
00173 (dataSocket.getInputStream()));
00174 commPStream = new PrintStream (commandSock.getOutputStream());
00175 validConnect = true;
00176 }
00177 catch(IOException e2){
00178 failed = true;
00179
00180 if(!killed){
00181
00182 while(!dialog){
00183 try{
00184 sleep(10);
00185 }catch(InterruptedException e1){}
00186 }
00187
00188
00189
00190 yield();
00191
00192 toKill.interrupt();
00193 ((DialogThread)toKill).interrupted = true;
00194 JOptionPane.showMessageDialog(null, "Connection Failed\n make sure DAQ is running",
00195 "Error", JOptionPane.ERROR_MESSAGE);
00196 }
00197
00198 killed = true;
00199 return;
00200 }
00201 finally{
00202 if(killed){
00203 validConnect = false;
00204 DaqPanel.curDaqPanel.updateConnectionStatus();
00205 return;
00206 }
00207 }
00208
00209 while(!dialog){
00210 try{
00211
00212 sleep(50);
00213 }catch(InterruptedException e1){
00214 DaqPanel.curDaqPanel.updateConnectionStatus();
00215 return;}
00216 }
00217
00218
00219
00220 yield();
00221 toKill.interrupt();
00222
00223 ((DialogThread)toKill).interrupted = true;
00224 validConnect = true;
00225 DaqPanel.curDaqPanel.updateConnectionStatus();
00226 }
00227 }
00233 class DialogThread extends Thread{
00234
00236 Thread toKill;
00237
00239 boolean interrupted = false;
00240
00245 protected void setToKill(Thread tokill){
00246 toKill = tokill;
00247 }
00248
00254 public void run(){
00255 dialog = true;
00256 JOptionPane.showOptionDialog(null, "Connecting ...", "Trying to Connect",
00257 JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
00258 null, new Object[] {"stop Connection"}, "stop Connection");
00259
00260
00261 if(!interrupted){
00262 toKill.interrupt();
00263 toKill.destroy();
00264 }
00265 }
00266 }
00267
00274 public String testCommand(String command) throws TestSuiteException{
00275 return testingCommand(commPStream,
00276 commReader, command);
00277 }
00278
00286 public TestResult testCommand(String command, String result)
00287 throws TestSuiteException{
00288 return testingCommand(commPStream,
00289 commReader, command, result);
00290 }
00291
00304 public TestResult testingCommand (PrintStream pstream, BufferedReader buf,
00305 final String command, final String responce) throws TestSuiteException{
00306 pstream.print(command);
00307 TestResult result = new TestResult();
00308
00309
00310 if(((StopThread)Thread.currentThread()).isStopped()){
00311 return new TestResult();
00312
00313
00314 }
00315
00316 try{
00317 String str = buf.readLine();
00318 if(str == null){
00319
00320
00321 throw new TestSuiteException(){
00322 public void run(){
00323 JOptionPane.showMessageDialog(null, "Connection was lost",
00324 "Error", JOptionPane.ERROR_MESSAGE);
00325 disconnect();
00326 }
00327 };
00328 }
00329 if(str.equalsIgnoreCase(responce)){
00330 result.pass = true;
00331 }
00332 else{
00333 result.pass = false;
00334 result.different = str;
00335 }
00336 }
00337 catch(IOException e3){
00338 throw new TestSuiteException(){
00339 public void run(){
00340 System.out.println("Here the error is");
00341 JOptionPane.showMessageDialog(null, "Error while reading from command Socket",
00342 "Error", JOptionPane.ERROR_MESSAGE);
00343 }
00344 };
00345 }
00346 return result;
00347 }
00348
00354 public String readingData() throws TestSuiteException{
00355 String str = null;
00356 try{
00357 str = dataReader.readLine();
00358 if(str == null){
00359 throw new TestSuiteException(){
00360 public void run(){
00361 JOptionPane.showMessageDialog(null, "Connection was lost",
00362 "Error", JOptionPane.ERROR_MESSAGE);
00363 disconnect();
00364 }
00365 };
00366 }
00367 }
00368 catch(IOException e3){
00369 throw new TestSuiteException(){
00370 public void run(){
00371 System.out.println("reading data");
00372 JOptionPane.showMessageDialog(null, "Error while reading from data Socket",
00373 "Error", JOptionPane.ERROR_MESSAGE);
00374 }
00375 };
00376 }
00377 return str;
00378 }
00379
00388 public String testingCommand(PrintStream pstream, BufferedReader buf, String command)
00389 throws TestSuiteException{
00390 pstream.print(command);
00391 String str = null;
00392 try{
00393 str = buf.readLine();
00394 if(str == null){
00395
00396
00397 throw new TestSuiteException(){
00398 public void run(){
00399 JOptionPane.showMessageDialog(null, "Connection was lost",
00400 "Error", JOptionPane.ERROR_MESSAGE);
00401 disconnect();
00402 }
00403 };
00404 }
00405 }
00406 catch(IOException e3){
00407 throw new TestSuiteException(){
00408 public void run(){
00409 System.out.println("third");
00410 JOptionPane.showMessageDialog(null, "Error while reading from command Socket",
00411 "Error", JOptionPane.ERROR_MESSAGE);
00412 }
00413 };
00414 }
00415 return str;
00416 }
00417
00422 public void disconnect(){
00423 try{
00424 if(dataSocket != null){
00425 dataSocket.close();
00426 }
00427 if(commandSock != null){
00428 commandSock.close();
00429 }
00430 }catch(IOException exception){
00431 System.out.println("Error in disconnect()");
00432 }
00433 validConnect = false;
00434 }
00435
00447 public boolean openCloseBadPort(String command, DaqPanel repaintPanel, SSPanel sspanel)
00448 throws TestSuiteException{
00449 TestResult responce;
00450 int index = sspanel.logString("Testing " + command + "-port on a bad channel");
00451
00452 repaintPanel.repaint();
00453
00454 responce = testCommand(command + "-port 9,,0\n",
00455 "Invalid port '[bad port]'");
00456
00457
00458 if(DaqDriverTest.debug){
00459 sspanel.logDebugString("Send command: " + command + "-port 9,,0");
00460 if(responce.pass){
00461 sspanel.logDebugString("Expected response: Invalid port '9,,0'");
00462 sspanel.logDebugString("Actual response matches");
00463 }
00464 else{
00465 sspanel.logDebugString("Expected response: Invalid port '9,,0'");
00466 sspanel.logDebugString("Actual response: " + responce.different);
00467 }
00468 }
00469
00470
00471 if(responce.pass){
00472 sspanel.replaceLog("Testing " + command + "-port on a bad channel PASS",
00473 index);
00474 }
00475 else{
00476 sspanel.replaceLog("Testing " + command + "-port on a bad channel FAIL",
00477 index);
00478 }
00479 repaintPanel.repaint();
00480 return responce.pass;
00481 }
00482
00483
00484
00498 public boolean openClosePort(String command, String answer, DaqPanel repaintPanel, SSPanel sspanel)
00499 throws TestSuiteException{
00500
00501 String str, str2;
00502 boolean pass = true;
00503 TestResult responce;
00504
00505
00506 Enumeration iter = channelTable.elements();
00507
00508
00509 int counter = 0;
00510
00511
00512
00513 int index = sspanel.logString("Testing " + command + "-port on all channels");
00514
00515 repaintPanel.repaint();
00516
00517
00518
00519
00520 if(!iter.hasMoreElements()){
00521 throw new TestSuiteException(){
00522 public void run(){
00523 JOptionPane.showMessageDialog(null, "No Channels available",
00524 "Error", JOptionPane.ERROR_MESSAGE);
00525 }
00526 };
00527 }
00528 str = (String)iter.nextElement();
00529
00530
00531 responce = testCommand(command + "-port " + str + "\n",
00532 answer + str);
00533
00534 if(progressBar != null){
00535 progressBar.setValue(progressBar.getValue() + increment);
00536 }
00537
00538
00539 if(((StopThread)Thread.currentThread()).isStopped()){
00540 return false;
00541 }
00542
00543 pass = pass && responce.pass;
00544 counter++;
00545
00546
00547 if(DaqDriverTest.debug){
00548 sspanel.logDebugString("Send command: " + command + "-port");
00549 if(responce.pass){
00550 sspanel.logDebugString("Expected response: " + answer + str);
00551 sspanel.logDebugString("Actual response matches");
00552 }
00553 else{
00554 sspanel.logDebugString("Expected response: " + answer + str);
00555 sspanel.logDebugString("Actual response: " + responce.different);
00556 }
00557 }
00558
00559 str2 = str;
00560 responce = testCommand(command + "-port " + str + "\n",
00561 answer + str);
00562 pass = pass && responce.pass;
00563
00564
00565
00566 if(DaqDriverTest.debug){
00567 sspanel.logDebugString("Send command: " + command + "-port");
00568 if(responce.pass){
00569 sspanel.logDebugString("Expected response: " + answer + str);
00570 sspanel.logDebugString("Actual response matches");
00571 }
00572 else{
00573 sspanel.logDebugString("Expected response: " + answer + str);
00574 sspanel.logDebugString("Actual response: " + responce.different);
00575 }
00576 }
00577
00578
00579
00580
00581
00582
00583 while(iter.hasMoreElements()){
00584 repaintPanel.repaint();
00585 str = (String)iter.nextElement();
00586 responce = testCommand(command + "-port " + str + "\n",
00587 answer + str);
00588
00589
00590 if(progressBar != null){
00591 progressBar.setValue(progressBar.getValue() + increment);
00592 }
00593
00594
00595 if(((StopThread)Thread.currentThread()).isStopped()){
00596 return false;
00597 }
00598
00599 pass = pass && responce.pass;
00600 if(DaqDriverTest.debug){
00601 sspanel.logDebugString("Send command: " + command + "-port");
00602 if(responce.pass){
00603 sspanel.logDebugString("Expected response: " + answer + str);
00604 sspanel.logDebugString("Actual response matches");
00605 }
00606 else{
00607 sspanel.logDebugString("Expected response: " + answer + str);
00608 sspanel.logDebugString("Actual response: " + responce.different);
00609 }
00610 }
00611
00612
00613 if(counter % 5 == 0){
00614 responce = testCommand(command + "-port " + str2 + "\n",
00615 answer + str2);
00616 pass = pass && responce.pass;
00617 if(DaqDriverTest.debug){
00618 sspanel.logDebugString("Send command: " + command + "-port");
00619 if(responce.pass){
00620 sspanel.logDebugString("Expected response: " + answer + str2);
00621 sspanel.logDebugString("Actual response matches");
00622 }
00623 else{
00624 sspanel.logDebugString("Expected response: " + answer);
00625 sspanel.logDebugString("Actual response: " + responce.different);
00626 }
00627 }
00628 }
00629 counter++;
00630 }
00631
00632
00633 if(pass){
00634 sspanel.replaceLog("Testing " + command + "-port on all channels PASS",
00635 index);
00636 }
00637 else{
00638 sspanel.replaceLog("Testing " + command + "-port on all channels FAIL",
00639 index);
00640 }
00641 repaintPanel.repaint();
00642 return pass;
00643 }
00644
00650 public static void setPorts(int commandPort){
00651 COMMANDPORT = commandPort;
00652 DATAPORT = COMMANDPORT + 1;
00653 }
00654
00663 public boolean testStatus(String answer, DaqPanel repaintPanel, SSPanel sspanel)
00664 throws TestSuiteException{
00665 boolean pass = true;
00666 TestResult responce;
00667 int index = sspanel.logString("Testing daq-status");
00668 repaintPanel.repaint();
00669 responce = testCommand("daq-status\n", answer);
00670 pass = pass && responce.pass;
00671
00672 if(DaqDriverTest.debug){
00673 sspanel.logDebugString("Send command: daq-status");
00674 if(responce.pass){
00675 sspanel.logDebugString("Expected response: " + answer);
00676 sspanel.logDebugString("Actual response matches");
00677 }
00678 else{
00679 sspanel.logDebugString("Expected response: " + answer);
00680 sspanel.logDebugString("Actual response: " + responce.different);
00681 }
00682 }
00683
00684 if(pass){
00685 sspanel.replaceLog("Testing daq-status PASS", index);
00686 }
00687 else{
00688 sspanel.replaceLog("Testing daq-status FAIL", index);
00689 }
00690 return pass;
00691 }
00692
00702 public boolean testingUnknownCommands(DaqPanel repaintPanel, SSPanel sspanel)
00703 throws TestSuiteException{
00704 boolean pass = true;
00705 TestResult responce[];
00706 int index = sspanel.logString("Testing Unknown Commands");
00707 repaintPanel.repaint();
00708 responce = new TestResult[2];
00709 String send[] = {"987978", "daq,status10"};
00710 for(int i = 0; i < responce.length; i++){
00711 responce[i] = testCommand(send[i] + "\n", "Unknown Command '" + send[i] + "'");
00712
00713 if(DaqDriverTest.debug){
00714 sspanel.logDebugString("Send command: " + send[i]);
00715 if(responce[i].pass){
00716 sspanel.logDebugString("Expected response: " + "Unknown Command '" + send[i] +
00717 "'" + " Actual response: " + "Unknown Command '" + send[i] +"'");
00718 }
00719 else{
00720 sspanel.logDebugString("Expected response: " + "Unknown Command '" + send[i] +
00721 "'" + " Actual response: " + responce[i].different);
00722 }
00723 }
00724 pass = pass && responce[i].pass;
00725 }
00726 if(pass){
00727 sspanel.replaceLog("Testing Unknown Commands PASS", index);
00728 }
00729 else{
00730 sspanel.replaceLog("Testing Unknown Commands FAIL", index);
00731 }
00732 repaintPanel.repaint();
00733 return pass;
00734 }
00735
00742 public void flushBuffers(DaqPanel repaintPanel, SSPanel sspanel, boolean block) throws TestSuiteException{
00743
00744 Enumeration iter = channelTable.elements();
00745 String str = "";
00746 if(block){
00747 while(iter.hasMoreElements()){
00748 repaintPanel.repaint();
00749 str = (String)iter.nextElement();
00750 testCommand("close-port " + str + "\n", "Stopping data on data channel from port "+ str);
00751 }
00752 }
00753 try{
00754 if(block){
00755 Thread.sleep(500);
00756 }
00757 while(commReader.ready()){
00758 commReader.read();
00759 }
00760
00761 while(dataReader.ready()){
00762 dataReader.read();
00763 }
00764
00765 if(block){
00766 Thread.sleep(500);
00767 while(commReader.ready()){
00768 commReader.read();
00769 }
00770
00771 while(dataReader.ready()){
00772 dataReader.read();
00773 }
00774 }
00775
00776
00777 }
00778 catch(IOException e5){
00779 if(DaqDriverTest.debug){
00780 sspanel.logDebugString("Error While flushing");
00781 repaintPanel.repaint();
00782 }
00783 }
00784 catch(InterruptedException e1){
00785 System.out.println("I WAS INTERRUPTED");
00786 }
00787 channelTable = new Hashtable();
00788 }
00789
00806 public boolean testSuite(DaqPanel repaintPanel, SSPanel sspanel, JProgressBar bar, int runs) throws TestSuiteException{
00807 String str = "", str2 = "";
00808 Graphics graphics;
00809 int i;
00810 TestResult responce = null;
00811 boolean pass = true;
00812 int testNumber = 0, testFail = 0;
00813 progressBar = bar;
00814
00815
00816
00817 flushBuffers(repaintPanel, sspanel, false);
00818 channelTable = new Hashtable();
00819
00820
00821 testNumber++;
00822 if(!testStatus("Running", repaintPanel, sspanel)){
00823 testFail++;
00824 progressBar.setForeground(Color.red);
00825 }
00826
00827 if(((StopThread)Thread.currentThread()).isStopped()){
00828 return false;
00829 }
00830
00831
00832 testNumber++;
00833 if(!testingUnknownCommands(repaintPanel, sspanel)){
00834 testFail++;
00835 progressBar.setForeground(Color.red);
00836 }
00837
00838
00839 if(((StopThread)Thread.currentThread()).isStopped()){
00840 return false;
00841 }
00842
00843
00844 int index = sspanel.logString("Testing list-channels");
00845 testNumber++;
00846 repaintPanel.repaint();
00847 String channels = testCommand("list-channels\n");
00848
00849
00850 if(((StopThread)Thread.currentThread()).isStopped()){
00851 return false;
00852 }
00853
00854 StringTokenizer tokens = new StringTokenizer(channels, ",", true);
00855 str = ",";
00856 while(true){
00857
00858
00859 if(((StopThread)Thread.currentThread()).isStopped()){
00860 return false;
00861 }
00862
00863 if(tokens.hasMoreTokens()){
00864 if(str.equals(",")){
00865 str = tokens.nextToken();
00866 if(str.equals(",") ||
00867 (str.equals(",") && !tokens.hasMoreTokens())){
00868 pass = false;
00869 break;
00870 }
00871 else{
00872
00873 if(channelTable.contains(str)){
00874 pass = false;
00875 if(DaqDriverTest.debug){
00876 sspanel.logDebugString("the channel " + str+" is already in channelTable");
00877 }
00878 break;
00879 }
00880 channelTable.put(str, str);
00881 }
00882 }
00883 else{
00884 str = tokens.nextToken();
00885
00886 if(channelTable.contains(str)){
00887 if(DaqDriverTest.debug){
00888 sspanel.logDebugString("the channel" + str+" is already in channelTable");
00889 }
00890 pass = false;
00891 break;
00892 }
00893 if(!str.equals(",")){
00894 channelTable.put(str, str);
00895 }
00896 }
00897 }
00898 else{
00899 break;
00900 }
00901 }
00902
00903 if(DaqDriverTest.debug){
00904 sspanel.logDebugString("Send command: list-channels");
00905 sspanel.logDebugString(" Actual response: " + channels);
00906 }
00907
00908 if(pass){
00909 sspanel.replaceLog("Testing list-channels PASS", index);
00910 }
00911 else{
00912 sspanel.replaceLog("Testing list-channels FAIL", index);
00913 testFail++;
00914 pass = true;
00915 progressBar.setForeground(Color.red);
00916 }
00917
00918
00919 if(progressBar != null){
00920 if(progressBar.getForeground() != Color.red){
00921 progressBar.setForeground(Color.green);
00922 }
00923 progressBar.setMaximum((10 + 5 *channelTable.size() + (int)(channelTable.size() * 1.05)) * runs);
00924 increment = 1;
00925 progressBar.setValue(progressBar.getValue() + 3 + channelTable.size());
00926 }
00927
00928
00929 testNumber++;
00930
00931 if (!openClosePort("open", "Streaming data on data channel from port ", repaintPanel, sspanel)){
00932 testFail++;
00933 progressBar.setForeground(Color.red);
00934 }
00935
00936
00937 if(((StopThread)Thread.currentThread()).isStopped()){
00938 return false;
00939 }
00940
00941
00942 testNumber++;
00943
00944 if(!testStatus("Running", repaintPanel, sspanel)){
00945 testFail++;
00946 progressBar.setForeground(Color.red);
00947 }
00948
00949
00950 if(((StopThread)Thread.currentThread()).isStopped()){
00951 return false;
00952 }
00953
00954
00955 index = sspanel.logString("Testing daq-status\ndaq-status");
00956 testNumber++;
00957 repaintPanel.repaint();
00958 responce = testCommand("daq-status\ndaq-status\n", "Running");
00959 pass = pass && responce.pass;
00960
00961
00962 if(((StopThread)Thread.currentThread()).isStopped()){
00963 return false;
00964 }
00965
00966 if(pass){
00967 sspanel.replaceLog("Testing daq-status\\ndaq-status PASS", index);
00968 }
00969 else{
00970 sspanel.replaceLog("Testing daq-status\\ndaq-status FAIL", index);
00971 testFail++;
00972 progressBar.setForeground(Color.red);
00973 }
00974
00975 responce = testCommand("", "Running");
00976
00977
00978 if(((StopThread)Thread.currentThread()).isStopped()){
00979 return false;
00980 }
00981
00982 pass = pass && responce.pass;
00983 if(pass){
00984 sspanel.replaceLog("Testing daq-status\\ndaq-status PASS", index);
00985 }
00986 else{
00987 sspanel.replaceLog("Testing daq-status\\ndaq-status FAIL", index);
00988 testFail++;
00989 pass = true;
00990 progressBar.setForeground(Color.red);
00991 }
00992
00993
00994 testNumber++;
00995
00996 if (!openClosePort("close", "Stopping data on data channel from port ", repaintPanel, sspanel)){
00997 testFail++;
00998 progressBar.setForeground(Color.red);
00999 }
01000
01001
01002 if(((StopThread)Thread.currentThread()).isStopped()){
01003 return false;
01004 }
01005
01006
01007 testNumber++;
01008
01009 if(!testStatus("Running", repaintPanel, sspanel)){
01010 testFail++;
01011 progressBar.setForeground(Color.red);
01012 }
01013
01014 testNumber++;
01015
01016 if (!openClosePort("open", "Streaming data on data channel from port ", repaintPanel, sspanel)){
01017 testFail++;
01018 progressBar.setForeground(Color.red);
01019 }
01020
01021
01022 index = sspanel.logString("Testing data format");
01023 repaintPanel.repaint();
01024 testNumber++;
01025
01026
01027 String prueva = "";
01028
01029 String number = "";
01030 StringTokenizer dataTokens = null;
01031
01032 Hashtable allChannelsUsed = new Hashtable();
01033 try{
01034 prueva = dataReader.readLine();
01035 if(prueva == null){
01036
01037
01038 throw new TestSuiteException(){
01039 public void run(){
01040 JOptionPane.showMessageDialog(null, "Connection was lost",
01041 "Error", JOptionPane.ERROR_MESSAGE);
01042 disconnect();
01043 }
01044 };
01045 }
01046 dataTokens = new StringTokenizer(prueva, "\t");
01047 }
01048 catch(IOException e1){
01049 sspanel.logString("Problems reading from Data Socket");
01050 pass = false;}
01051 Date prev = null, current = null;
01052
01053 try{
01054
01055 if(((StopThread)Thread.currentThread()).isStopped()){
01056 return false;
01057 }
01058 prev = current = dateFormat.parse(((String)dataTokens.nextElement()).substring(0,22));
01059 }
01060 catch(ParseException e2){
01061 sspanel.logString("Data format is incorrect");
01062 if(DaqDriverTest.debug){
01063 sspanel.logDebugString("Data is:" + prueva);
01064 }
01065 pass = false;
01066 }
01067
01068
01069 while(dataTokens.hasMoreElements()){
01070
01071 if(((StopThread)Thread.currentThread()).isStopped()){
01072 return false;
01073 }
01074
01075 str = (String)dataTokens.nextElement();
01076
01077 if(channelTable.containsKey(str)){
01078 allChannelsUsed.put(str,str);
01079 }
01080 else{
01081 sspanel.logString("Channel " + str +
01082 " does not match any channel from \"list-channels\"");
01083 if(DaqDriverTest.debug){
01084 sspanel.logDebugString("Data is:" + prueva);
01085 }
01086 pass = false;
01087 }
01088
01089
01090 try{
01091 number = (String)dataTokens.nextElement();
01092 Double.parseDouble(number);
01093 }
01094
01095 catch(NumberFormatException e3){
01096 if(DaqDriverTest.debug){
01097 sspanel.logString("Bad string for int format: " + number);
01098 }
01099 }
01100
01101 catch(NoSuchElementException e4){
01102 sspanel.logString("Incorrect Data Format does not match "+
01103 "\"Date\\tchannel\\tvalue\"");
01104 if(DaqDriverTest.debug){
01105 sspanel.logDebugString("Data is:" + prueva);
01106 }
01107 }
01108 }
01109
01110
01111 for(i = 0; i < channelTable.size() + channelTable.size() * 0.05; i++){
01112
01113 if(((StopThread)Thread.currentThread()).isStopped()){
01114 return false;
01115 }
01116 try{
01117 prueva = dataReader.readLine();
01118
01119
01120 if(progressBar != null){
01121 progressBar.setValue(progressBar.getValue() + increment);
01122 }
01123 if(prueva == null){
01124
01125
01126 throw new TestSuiteException(){
01127 public void run(){
01128 JOptionPane.showMessageDialog(null, "Connection was lost",
01129 "Error", JOptionPane.ERROR_MESSAGE);
01130 disconnect();
01131 }
01132 };
01133 }
01134
01135
01136 dataTokens = new StringTokenizer(prueva, "\t");
01137 }
01138 catch(IOException e1){
01139
01140 if(((StopThread)Thread.currentThread()).isStopped()){
01141 return false;
01142 }
01143 sspanel.logString("Problems reading from Data Socket");
01144 pass = false;}
01145 try{
01146
01147 if(((StopThread)Thread.currentThread()).isStopped()){
01148 return false;
01149 }
01150 current = dateFormat.parse(((String)dataTokens.nextElement()).substring(0,22));
01151 }
01152 catch(ParseException e2){
01153 sspanel.logString("Data format is incorrect");
01154
01155 if(DaqDriverTest.debug){
01156 sspanel.logDebugString("Data is:" + prueva);
01157 }
01158 pass = false;
01159 }
01160 catch(StringIndexOutOfBoundsException e5){
01161
01162 sspanel.logString("Data format is incorrect");
01163 if(DaqDriverTest.debug){
01164 sspanel.logDebugString("Data is:" + prueva);
01165 }
01166 pass = false;
01167 }
01168 if(pass && prev.compareTo(current) > 0){
01169 pass = false;
01170 sspanel.logString("Time Stamps are not chronologycal");
01171 if(DaqDriverTest.debug){
01172 sspanel.logDebugString("previous: " + prev + " and current: " + current);
01173 }
01174 }
01175
01176
01177 while(dataTokens.hasMoreElements()){
01178 str = (String)dataTokens.nextElement();
01179
01180 if(((StopThread)Thread.currentThread()).isStopped()){
01181 return false;
01182 }
01183
01184 if(channelTable.containsKey(str)){
01185 allChannelsUsed.put(str,str);
01186 }
01187 else{
01188 sspanel.logString("Channel " + str +
01189 " does not match any channel from \"list-channels\"");
01190 if(DaqDriverTest.debug){
01191 sspanel.logDebugString("Data is:" + prueva);
01192 }
01193 pass = false;
01194
01195 }
01196
01197 try{
01198 str2 = (String)dataTokens.nextElement();
01199 Double.parseDouble(str2);
01200 }
01201
01202
01203 catch(NumberFormatException e3){
01204 sspanel.logString("Incorrect Data Format does not match "+
01205 "\"Date\\tchannel\\tvalue\"NumberFormat");
01206 sspanel.logString(prueva);
01207 if(DaqDriverTest.debug){
01208 sspanel.logDebugString("Data is:" + prueva);
01209 sspanel.logDebugString("Bad number is : " + str2);
01210 }
01211 }
01212
01213 catch(NoSuchElementException e4){
01214 sspanel.logString("Incorrect Data Format does not match "+
01215 "\"Date\\tchannel\\tvalue\"NoSuchElement");
01216 if(DaqDriverTest.debug){
01217 sspanel.logDebugString("Data is:" + prueva);
01218 }
01219 }
01220 }
01221
01222
01223 prev = current;
01224
01225 }
01226
01227 str2 = "";
01228 Enumeration iter = channelTable.elements();
01229
01230
01231 while(iter.hasMoreElements()){
01232 str = (String)iter.nextElement();
01233 if(!allChannelsUsed.containsKey(str)){
01234 str2 += str + ",";
01235 }
01236 }
01237
01238
01239
01240 if(str2 != ""){
01241 str2 = str2.substring(0, str2.length() - 2);
01242 sspanel.logString("The following Channels where not used: ");
01243 int sub = 0;
01244 while(true){
01245 if(sub + 60 >= str2.length() - 1){
01246 sspanel.logString(str2.substring(sub));
01247 break;
01248 }
01249 else{
01250 sspanel.logString(str2.substring(sub, sub + 60));
01251 sub += 60;
01252 }
01253 }
01254 }
01255
01256 if(pass){
01257 sspanel.replaceLog("Testing data format PASS", index);
01258 }
01259 else{
01260 sspanel.replaceLog("Testing data format FAIL", index);
01261 testFail++;
01262 progressBar.setForeground(Color.red);
01263 pass = true;
01264 }
01265
01266
01267
01268
01269 testNumber++;
01270
01271 if (!openClosePort("close", "Stopping data on data channel from port ", repaintPanel, sspanel)){
01272 testFail++;
01273 progressBar.setForeground(Color.red);
01274 }
01275
01276
01277 if(((StopThread)Thread.currentThread()).isStopped()){
01278 return false;
01279 }
01280
01281
01282 testNumber++;
01283 if(!testStatus("Running", repaintPanel, sspanel)){
01284 testFail++;
01285 progressBar.setForeground(Color.red);
01286 }
01287
01288
01289 if(((StopThread)Thread.currentThread()).isStopped()){
01290 return false;
01291 }
01292
01293 if(progressBar != null){
01294 progressBar.setValue(progressBar.getValue() + increment);
01295 }
01296
01297 testNumber++;
01298 if(!openCloseBadPort("open", repaintPanel, sspanel)){
01299 testFail++;
01300 progressBar.setForeground(Color.red);
01301 }
01302
01303
01304 if(((StopThread)Thread.currentThread()).isStopped()){
01305 return false;
01306 }
01307
01308 if(progressBar != null){
01309 progressBar.setValue(progressBar.getValue() + increment);
01310 }
01311
01312 testNumber++;
01313 if(!openCloseBadPort("close", repaintPanel, sspanel)){
01314 testFail++;
01315 progressBar.setForeground(Color.red);
01316 }
01317
01318
01319 if(((StopThread)Thread.currentThread()).isStopped()){
01320 return false;
01321 }
01322
01323
01324 if(progressBar != null){
01325 progressBar.setValue(progressBar.getValue() + increment);
01326 }
01327
01328
01329 if(testFail == 0){
01330 sspanel.logString("Test Results " + testNumber + "/" + testNumber + " tests PASS");
01331 }
01332 else{
01333 sspanel.logString(testFail + " tests FAIL");
01334 sspanel.logString("Test Results " + (testNumber - testFail)
01335 + "/" + testNumber + " tests PASS");
01336 }
01337
01338 flushBuffers(repaintPanel, sspanel, false);
01339 channelTable = new Hashtable();
01340 return testFail == 0;
01341 }
01342
01343 }
01344
01351 class TestResult{
01353 public boolean pass = false;
01354
01356 public String different;
01357 }
01358
01364 class TestSuiteException extends Exception{
01370 public void run(){}
01371 }