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 Boris V. Kuznetsov 20 */ 21 22package java.security; 23 24import org.apache.harmony.security.tests.support.MySignature1; 25 26import junit.framework.TestCase; 27 28/** 29 * Tests for <code>Signature</code> constructor and methods 30 */ 31public class Signature_Impl1Test extends TestCase { 32 33 /* 34 * Class under test for int sign(byte[], int, int) 35 */ 36 public void testSignbyteArrayintint() throws Exception { 37 MySignature1 s = new MySignature1("ABC"); 38 byte[] b = new byte[8]; 39 try { 40 s.sign(b, 0, 5); 41 fail("No expected SignatureException 1"); 42 } catch (SignatureException e) { 43 } 44 45 s.initVerify(new MyPublicKey()); 46 47 try { 48 s.sign(b, 0, 5); 49 fail("No expected SignatureException 1"); 50 } catch (SignatureException e) { 51 } 52 53 s.initSign(new MyPrivateKey()); 54 s.sign(b, 0, 5); 55 assertEquals("state", Signature.SIGN, s.getState()); 56 assertTrue("sign() failed", s.runEngineSign); 57 } 58 59 /* 60 * Class under test for String toString() 61 */ 62 public void testToString() { 63 MySignature1 s = new MySignature1("ABC"); 64 assertEquals("toString() failed", "SIGNATURE ABC state: UNINITIALIZED", 65 s.toString()); 66 } 67 68 private class MyKey implements Key { 69 public String getFormat() { 70 return "123"; 71 } 72 73 public byte[] getEncoded() { 74 return null; 75 } 76 77 public String getAlgorithm() { 78 return "aaa"; 79 } 80 } 81 82 private class MyPublicKey extends MyKey implements PublicKey { 83 } 84 85 private class MyPrivateKey extends MyKey implements PrivateKey { 86 } 87 88} 89