1 /* 2 * Copyright (C) 2007 The Android Open Source Project 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 17 package tests.security.spec; 18 19 import junit.framework.TestCase; 20 21 import java.math.BigInteger; 22 import java.security.spec.ECFieldF2m; 23 import java.security.spec.ECParameterSpec; 24 import java.security.spec.ECPoint; 25 import java.security.spec.ECPublicKeySpec; 26 import java.security.spec.EllipticCurve; 27 28 public class ECPublicKeySpecTest extends TestCase { 29 ECPoint w; 30 31 ECParameterSpec params; 32 33 ECPublicKeySpec ecpks; 34 35 protected void setUp() throws Exception { 36 super.setUp(); 37 ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger 38 .valueOf(1)); 39 EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger 40 .valueOf(1), BigInteger.valueOf(1)); 41 42 w = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1)); 43 params = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1); 44 ecpks = new ECPublicKeySpec(w, params); 45 } 46 47 protected void tearDown() throws Exception { 48 w = null; 49 params = null; 50 ecpks = null; 51 super.tearDown(); 52 } 53 54 /** 55 * test for constructor ECPublicKeySpec(ECPoint, ECParameterSpec) 56 * test covers following usecases: 57 * case 1: creating object with valid parameters 58 * case 2: catch NullPointerException - if w is null. 59 * case 3: catch NullPointerException - if params is null. 60 */ 61 public final void test_constructorLjava_security_spec_ECPointLjava_security_spec_ECParameterSpec() { 62 63 // case 1: creating object with valid parameters 64 assertEquals("wrong params value", params, ecpks.getParams()); 65 assertEquals("wrong w value", w, ecpks.getW()); 66 67 // case 2: catch NullPointerException - if w is null. 68 try { 69 new ECPublicKeySpec(null, params); 70 fail("NullPointerException has not been thrown"); 71 } catch (NullPointerException e) { 72 // expected 73 } 74 75 // case 3: catch NullPointerException - if params is null. 76 try { 77 new ECPublicKeySpec(w, null); 78 fail("NullPointerException has not been thrown"); 79 } catch (NullPointerException e) { 80 // expected 81 } 82 } 83 84 /** 85 * test for getW() method 86 */ 87 public final void testGetW() { 88 assertEquals("wrong w value", w, ecpks.getW()); 89 } 90 91 /** 92 * test for getParams() meyhod 93 */ 94 public final void testGetParams() { 95 assertEquals("wrong params value", params, ecpks.getParams()); 96 } 97 } 98