OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / sql / tests / java / sql / ParameterMetaDataTest.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.apache.harmony.sql.tests.java.sql;
19
20 import dalvik.annotation.TestTargetClass;
21 import dalvik.annotation.TestTargets;
22 import dalvik.annotation.TestLevel;
23 import dalvik.annotation.TestTargetNew;
24
25 import java.lang.reflect.Field;
26 import java.lang.reflect.Modifier;
27 import java.util.HashMap;
28
29 import junit.framework.TestCase;
30
31 @TestTargetClass(java.sql.ParameterMetaData.class)
32 public class ParameterMetaDataTest extends TestCase {
33
34     /*
35      * Public statics test
36      */
37     @TestTargetNew(
38         level = TestLevel.COMPLETE,
39         notes = "Field testing",
40         method = "!Constants",
41         args = {}
42     )
43     public void testPublicStatics() {
44
45         HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
46         thePublicStatics.put("parameterModeOut", new Integer(4));
47         thePublicStatics.put("parameterModeInOut", new Integer(2));
48         thePublicStatics.put("parameterModeIn", new Integer(1));
49         thePublicStatics.put("parameterModeUnknown", new Integer(0));
50         thePublicStatics.put("parameterNullableUnknown", new Integer(2));
51         thePublicStatics.put("parameterNullable", new Integer(1));
52         thePublicStatics.put("parameterNoNulls", new Integer(0));
53
54         /*
55          * System.out.println( "parameterModeOut: " +
56          * ParameterMetaData.parameterModeOut ); System.out.println(
57          * "parameterModeInOut: " + ParameterMetaData.parameterModeInOut );
58          * System.out.println( "parameterModeIn: " +
59          * ParameterMetaData.parameterModeIn ); System.out.println(
60          * "parameterModeUnknown: " + ParameterMetaData.parameterModeUnknown );
61          * System.out.println( "parameterNullableUnknown: " +
62          * ParameterMetaData.parameterNullableUnknown ); System.out.println(
63          * "parameterNullable: " + ParameterMetaData.parameterNullable );
64          * System.out.println( "parameterNoNulls: " +
65          * ParameterMetaData.parameterNoNulls );
66          */
67
68         Class<?> parameterMetaDataClass;
69         try {
70             parameterMetaDataClass = Class
71                     .forName("java.sql.ParameterMetaData");
72         } catch (ClassNotFoundException e) {
73             fail("java.sql.ParameterMetaData class not found!");
74             return;
75         } // end try
76
77         Field[] theFields = parameterMetaDataClass.getDeclaredFields();
78         int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
79                 + Modifier.FINAL;
80
81         int countPublicStatics = 0;
82         for (Field element : theFields) {
83             String fieldName = element.getName();
84             int theMods = element.getModifiers();
85             if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
86                 try {
87                     Object fieldValue = element.get(null);
88                     Object expectedValue = thePublicStatics.get(fieldName);
89                     if (expectedValue == null) {
90                         fail("Field " + fieldName + " missing!");
91                     } // end
92                     assertEquals("Field " + fieldName + " value mismatch: ",
93                             expectedValue, fieldValue);
94                     assertEquals("Field " + fieldName + " modifier mismatch: ",
95                             requiredModifier, theMods);
96                     countPublicStatics++;
97                 } catch (IllegalAccessException e) {
98                     fail("Illegal access to Field " + fieldName);
99                 } // end try
100             } // end if
101         } // end for
102
103     } // end method testPublicStatics
104
105 } // end class ParameterMetaDataTest
106