DSAPublicKeySpecTest.java revision cec4dd4b1d33f78997603d0f89c0d0e56e64dbcd
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* @version $Revision$
21*/
22
23package tests.security.spec;
24
25import dalvik.annotation.TestTargets;
26import dalvik.annotation.TestLevel;
27import dalvik.annotation.TestTargetNew;
28import dalvik.annotation.TestTargetClass;
29
30import junit.framework.TestCase;
31
32import java.math.BigInteger;
33import java.security.spec.DSAPublicKeySpec;
34import java.security.spec.KeySpec;
35
36/**
37 * Tests for <code>DSAPublicKeySpec</code>
38 *
39 */
40@TestTargetClass(DSAPublicKeySpec.class)
41public class DSAPublicKeySpecTest extends TestCase {
42
43    /**
44     * Test for <code>DSAPublicKeySpec</code> ctor
45     */
46    @TestTargetNew(
47        level = TestLevel.COMPLETE,
48        notes = "",
49        method = "DSAPublicKeySpec",
50        args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class}
51    )
52    public final void testDSAPublicKeySpec() {
53        KeySpec ks = new DSAPublicKeySpec(
54                new BigInteger("1"), // y
55                new BigInteger("2"), // p
56                new BigInteger("3"), // q
57                new BigInteger("4"));// g
58
59        assertTrue(ks instanceof DSAPublicKeySpec);
60    }
61
62    /**
63     * Test for <code>getG</code> method
64     */
65    @TestTargetNew(
66        level = TestLevel.COMPLETE,
67        notes = "",
68        method = "getG",
69        args = {}
70    )
71    public final void testGetG() {
72        DSAPublicKeySpec dpks = new DSAPublicKeySpec(
73                new BigInteger("1"), // y
74                new BigInteger("2"), // p
75                new BigInteger("3"), // q
76                new BigInteger("4"));// g
77
78        assertEquals(4, dpks.getG().intValue());
79    }
80
81    /**
82     * Test for <code>getP</code> method
83     */
84    @TestTargetNew(
85        level = TestLevel.COMPLETE,
86        notes = "",
87        method = "getP",
88        args = {}
89    )
90    public final void testGetP() {
91        DSAPublicKeySpec dpks = new DSAPublicKeySpec(
92                new BigInteger("1"), // y
93                new BigInteger("2"), // p
94                new BigInteger("3"), // q
95                new BigInteger("4"));// g
96
97        assertEquals(2, dpks.getP().intValue());
98    }
99
100    /**
101     * Test for <code>getQ</code> method
102     */
103    @TestTargetNew(
104        level = TestLevel.COMPLETE,
105        notes = "",
106        method = "getQ",
107        args = {}
108    )
109    public final void testGetQ() {
110        DSAPublicKeySpec dpks = new DSAPublicKeySpec(
111                new BigInteger("1"), // y
112                new BigInteger("2"), // p
113                new BigInteger("3"), // q
114                new BigInteger("4"));// g
115
116        assertEquals(3, dpks.getQ().intValue());
117    }
118
119    /**
120     * Test for <code>getY</code> method
121     */
122    @TestTargetNew(
123        level = TestLevel.COMPLETE,
124        notes = "",
125        method = "getY",
126        args = {}
127    )
128    public final void testGetY() {
129        DSAPublicKeySpec dpks = new DSAPublicKeySpec(
130                new BigInteger("1"), // y
131                new BigInteger("2"), // p
132                new BigInteger("3"), // q
133                new BigInteger("4"));// g
134
135        assertEquals(1, dpks.getY().intValue());
136    }
137}
138