1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package climaker; 24 25 26 import complexlib.ComplexTestCase; 27 28 29 public class ClimakerTestCase extends ComplexTestCase 30 { getTestMethodNames()31 public String[] getTestMethodNames() 32 { 33 // TODO think about trigger of sub-tests from outside 34 return new String[] 35 { 36 "checkGeneratedCLITypes" 37 }; 38 } 39 checkGeneratedCLITypes()40 public void checkGeneratedCLITypes() 41 { 42 try 43 { 44 String testProgram = System.getProperty("cli_ure_test"); 45 if (testProgram == null || testProgram.length() == 0) 46 failed("Check the make file. Java must be called with -Dcli_ure_test=pathtoexe"); 47 Process proc = null; 48 try{ 49 50 proc = Runtime.getRuntime().exec(testProgram); 51 Reader outReader = new Reader(proc.getInputStream()); 52 Reader errReader = new Reader(proc.getErrorStream()); 53 54 } catch(Exception e) 55 { 56 System.out.println("\n ###" + e.getMessage() + "\n"); 57 58 } 59 proc.waitFor(); 60 int retVal = proc.exitValue(); 61 if (retVal != 0) 62 failed("Tests for generated CLI code failed."); 63 } catch( java.lang.Exception e) 64 { 65 failed("Unexpected exception."); 66 } 67 68 } 69 } 70 71 72 /* This reads reads from an InputStream and discards the data. 73 */ 74 class Reader extends Thread 75 { 76 java.io.InputStream is; Reader(java.io.InputStream stream)77 public Reader(java.io.InputStream stream) 78 { 79 is = stream; 80 start(); 81 } 82 run()83 public void run() 84 { 85 try 86 { 87 byte[] buf = new byte[1024]; 88 while (-1 != is.read(buf)); 89 } 90 catch (java.io.IOException exc) 91 { 92 } 93 } 94 } 95