Api_test.java
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2012 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package api_test;
17 
18 
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21 import java.lang.reflect.Type;
22 import java.util.Locale;
23 
24 public class Api_test {
25  static
26  {
27  System.loadLibrary ( "zorba_api" );
28  }
29 
30 
31  public static void main ( String... args )
32  {
33  try {
34  Class<?> c = Class.forName("api_test.Tests");
35  Object t = c.newInstance();
36 
37  Method[] allMethods = c.getDeclaredMethods();
38  for (Method m : allMethods) {
39  String mname = m.getName();
40  if (!mname.startsWith("test")
41  || (m.getGenericReturnType() != boolean.class)) {
42  continue;
43  }
44  Type[] pType = m.getGenericParameterTypes();
45  if ((pType.length != 1)
46  || Locale.class.isAssignableFrom(pType[0].getClass())) {
47  //continue;
48  }
49 
50  System.out.format("invoking %s()%n", mname);
51  try {
52  m.setAccessible(true);
53  Object o = m.invoke(t);
54  System.out.format("%s() returned %b%n", mname, (Boolean) o);
55  if ((Boolean) o) {
56  System.out.println("Success");
57  } else {
58  System.out.println("Failed");
59  System.exit (1);
60  }
61 
62  // Handle any exceptions thrown by method to be invoked.
63  } catch (InvocationTargetException x) {
64  Throwable cause = x.getCause();
65  System.err.format("invocation of %s failed: %s%n",
66  mname, cause.getMessage());
67  }
68  }
69 
70  // production code should handle these exceptions more gracefully
71  } catch (Exception e) {
72  System.out.println("Failed");
73  System.out.println("Exception caught. " + e.getLocalizedMessage());
74  e.printStackTrace();
75  }
76  } // main
77 
78 } // class Test_Zorba
blog comments powered by Disqus