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 import org.junit.Test; 26 import static org.junit.Assert.*; 27 28 29 public class ClimakerTestCase 30 { 31 @Test checkGeneratedCLITypes()32 public void checkGeneratedCLITypes() throws Exception 33 { 34 String testProgram = System.getProperty("cli_ure_test"); 35 if (testProgram == null || testProgram.length() == 0) 36 fail("Check the make file. Java must be called with -Dcli_ure_test=pathtoexe"); 37 Process proc = null; 38 proc = Runtime.getRuntime().exec(testProgram); 39 Reader outReader = new Reader(proc.getInputStream()); 40 Reader errReader = new Reader(proc.getErrorStream()); 41 proc.waitFor(); 42 int retVal = proc.exitValue(); 43 assertTrue("Tests for generated CLI code failed.", retVal == 0); 44 } 45 } 46 47 48 /* This reads reads from an InputStream and discards the data. 49 */ 50 class Reader extends Thread 51 { 52 java.io.InputStream is; Reader(java.io.InputStream stream)53 public Reader(java.io.InputStream stream) 54 { 55 is = stream; 56 start(); 57 } 58 run()59 public void run() 60 { 61 try 62 { 63 byte[] buf = new byte[1024]; 64 while (-1 != is.read(buf)); 65 } 66 catch (java.io.IOException exc) 67 { 68 } 69 } 70 } 71