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 Vladimir N. Molotkov 20 */ 21 22package org.apache.harmony.security.tests.java.security.spec; 23 24import java.math.BigInteger; 25import java.security.spec.ECFieldF2m; 26import java.security.spec.ECFieldFp; 27import java.security.spec.EllipticCurve; 28 29import junit.framework.TestCase; 30 31/** 32 * Tests for <code>EllipticCurve</code> class fields and methods. 33 */ 34public class EllipticCurve_ImplTest extends TestCase { 35 36 /** 37 * Test #2 for <code>equals(Object other)</code> method<br> 38 * Assertion: return false if this and other objects are not equal<br> 39 * Test preconditions: see test comments<br> 40 * Expected: all objects in this test must be NOT equal 41 */ 42 public final void testEqualsObject02() { 43 // test case 1: must not be equal to null 44 EllipticCurve c2 = null, c1 = 45 new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 46 BigInteger.ONE, 47 BigInteger.valueOf(19L)); 48 assertFalse(c1.equals(c2)); 49 50 // test case 2: not equal objects - field 51 c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 52 BigInteger.ONE, 53 BigInteger.valueOf(19L)); 54 c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(31L)), 55 BigInteger.valueOf(1L), 56 BigInteger.valueOf(19L)); 57 assertFalse(c1.equals(c2) || c2.equals(c1)); 58 59 // test case 3: not equal objects - a 60 c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 61 BigInteger.ONE, 62 BigInteger.valueOf(19L)); 63 c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 64 BigInteger.ZERO, 65 BigInteger.valueOf(19L)); 66 assertFalse(c1.equals(c2) || c2.equals(c1)); 67 68 // test case 4: not equal objects - b 69 c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 70 BigInteger.ONE, 71 BigInteger.valueOf(19L)); 72 c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 73 BigInteger.ONE, 74 BigInteger.valueOf(17L)); 75 assertFalse(c1.equals(c2) || c2.equals(c1)); 76 77 // test case 5: not equal objects - both seed not null 78 c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 79 BigInteger.ONE, 80 BigInteger.valueOf(19L), 81 new byte[24]); 82 c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 83 BigInteger.valueOf(1L), 84 BigInteger.valueOf(19L), 85 new byte[25]); 86 assertFalse(c1.equals(c2) || c2.equals(c1)); 87 88 // test case 6: not equal objects - one seed is null 89 c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 90 BigInteger.ONE, 91 BigInteger.valueOf(19L), 92 null); 93 c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 94 BigInteger.valueOf(1L), 95 BigInteger.valueOf(19L), 96 new byte[24]); 97 assertFalse(c1.equals(c2) || c2.equals(c1)); 98 99 // test case 7: not equal objects - field class 100 c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), 101 BigInteger.ONE, 102 BigInteger.valueOf(19L), 103 new byte[24]); 104 c2 = new EllipticCurve(new ECFieldF2m(5), 105 BigInteger.ONE, 106 BigInteger.valueOf(19L), 107 new byte[24]); 108 assertFalse(c1.equals(c2) || c2.equals(c1)); 109 } 110} 111