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 /** 19 * @author Alexander Y. Kleymenov 20 * @version $Revision$ 21 */ 22 23 package org.apache.harmony.crypto.tests.javax.crypto.spec; 24 25 import dalvik.annotation.TestTargetClass; 26 import dalvik.annotation.TestTargets; 27 import dalvik.annotation.TestLevel; 28 import dalvik.annotation.TestTargetNew; 29 30 import java.lang.Integer; 31 import java.math.BigInteger; 32 33 import javax.crypto.spec.DHParameterSpec; 34 35 import junit.framework.Test; 36 import junit.framework.TestCase; 37 import junit.framework.TestSuite; 38 39 @TestTargetClass(DHParameterSpec.class) 40 /** 41 */ 42 43 public class DHParameterSpecTest extends TestCase { 44 45 /** 46 * DHParameterSpec class testing. Tests the equivalence of parameters 47 * specified in the constructor with the values returned by getters. 48 * The tested object is created by different constructors. 49 */ 50 @TestTargets({ 51 @TestTargetNew( 52 level = TestLevel.COMPLETE, 53 notes = "All functionality tested in one method. Probably it should be divided into several tests.", 54 method = "DHParameterSpec", 55 args = {java.math.BigInteger.class, java.math.BigInteger.class} 56 ), 57 @TestTargetNew( 58 level = TestLevel.COMPLETE, 59 notes = "All functionality tested in one method. Probably it should be divided into several tests.", 60 method = "DHParameterSpec", 61 args = {java.math.BigInteger.class, java.math.BigInteger.class, int.class} 62 ), 63 @TestTargetNew( 64 level = TestLevel.COMPLETE, 65 notes = "All functionality tested in one method. Probably it should be divided into several tests.", 66 method = "getG", 67 args = {} 68 ), 69 @TestTargetNew( 70 level = TestLevel.COMPLETE, 71 notes = "All functionality tested in one method. Probably it should be divided into several tests.", 72 method = "getL", 73 args = {} 74 ), 75 @TestTargetNew( 76 level = TestLevel.COMPLETE, 77 notes = "All functionality tested in one method. Probably it should be divided into several tests.", 78 method = "getP", 79 args = {} 80 ) 81 }) 82 public void testDHParameterSpec() { 83 BigInteger[] ps = {new BigInteger("-1000000000000"), BigInteger.ZERO, 84 BigInteger.ONE, new BigInteger("1000000000000")}; 85 BigInteger[] gs = {new BigInteger("-1000000000000"), BigInteger.ZERO, 86 BigInteger.ONE, new BigInteger("1000000000000")}; 87 int[] ls = {Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE}; 88 for (int i=0; i<ps.length; i++) { 89 DHParameterSpec dhps = new DHParameterSpec(ps[i], gs[i]); 90 assertEquals("The value returned by getP() must be " 91 + "equal to the value specified in the constructor", 92 dhps.getP(), ps[i]); 93 assertEquals("The value returned by getG() must be " 94 + "equal to the value specified in the constructor", 95 dhps.getG(), gs[i]); 96 } 97 for (int i=0; i<ps.length; i++) { 98 DHParameterSpec dhps = new DHParameterSpec(ps[i], gs[i], ls[i]); 99 assertEquals("The value returned by getP() must be " 100 + "equal to the value specified in the constructor", 101 dhps.getP(), ps[i]); 102 assertEquals("The value returned by getG() must be " 103 + "equal to the value specified in the constructor", 104 dhps.getG(), gs[i]); 105 assertEquals("The value returned by getL() must be " 106 + "equal to the value specified in the constructor", 107 dhps.getL(), ls[i]); 108 } 109 } 110 111 public static Test suite() { 112 return new TestSuite(DHParameterSpecTest.class); 113 } 114 115 public static void main(String[] args) { 116 junit.textui.TestRunner.run(suite()); 117 } 118 } 119 120