1/*
2 * Copyright (C) 2009 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 */
16package tests.targets.security;
17
18import dalvik.annotation.TestLevel;
19import dalvik.annotation.TestTargetNew;
20import dalvik.annotation.TestTargets;
21
22import junit.framework.TestCase;
23
24import java.security.AlgorithmParameters;
25import java.security.NoSuchAlgorithmException;
26import java.security.spec.AlgorithmParameterSpec;
27import java.security.spec.InvalidParameterSpecException;
28
29public class AlgorithmParametersTest extends TestCase {
30
31    private final String algorithmName;
32    private final TestHelper<AlgorithmParameters> helper;
33    private final AlgorithmParameterSpec parameterData;
34
35    public AlgorithmParametersTest(String algorithmName,
36            TestHelper<AlgorithmParameters> helper, AlgorithmParameterSpec parameterData) {
37        this.algorithmName = algorithmName;
38        this.helper = helper;
39        this.parameterData = parameterData;
40    }
41
42    protected void setUp() throws Exception {
43        super.setUp();
44    }
45
46    @TestTargets({
47        @TestTargetNew(
48                level=TestLevel.ADDITIONAL,
49                method="getInstance",
50                args={String.class}
51        ),
52        @TestTargetNew(
53                level=TestLevel.ADDITIONAL,
54                method="init",
55                args={byte[].class}
56        ),
57        @TestTargetNew(
58                level=TestLevel.COMPLETE,
59                method="method",
60                args={}
61        )
62    })
63    public void testAlgorithmParameters() {
64        AlgorithmParameters algorithmParameters = null;
65        try {
66            algorithmParameters = AlgorithmParameters
67                    .getInstance(algorithmName);
68        } catch (NoSuchAlgorithmException e) {
69            fail(e.getMessage());
70        }
71
72        try {
73            algorithmParameters.init(parameterData);
74        } catch (InvalidParameterSpecException e) {
75            fail(e.getMessage());
76        }
77
78        helper.test(algorithmParameters);
79    }
80}
81