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