blob: 22af271b981de966145395b4be770d5234622ca3 [file] [log] [blame]
The Android Open Source Projecta0881d02009-01-09 17:50:54 -08001/*
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 */
17package tests.api.javax.net.ssl;
18
19import dalvik.annotation.TestTargetClass;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22
23import javax.net.ssl.SSLEngineResult;
24
25import junit.framework.TestCase;
26
27/**
28 * Tests for SSLEngineResult.Status class
29 *
30 */
31@TestTargetClass(SSLEngineResult.HandshakeStatus.class)
32public class SSLEngineResultHandshakeStatusTest extends TestCase {
33
34 /**
35 * Test for <code> SSLEngineResult.HandshakeStatus.values() </code>
36 */
37 @TestTargetNew(
38 level = TestLevel.COMPLETE,
39 notes = "",
40 method = "values",
41 args = {}
42 )
43 public void test_SSLEngineResultHandshakeStatus_values() {
44 String[] str = {"NOT_HANDSHAKING", "FINISHED", "NEED_TASK", "NEED_WRAP", "NEED_UNWRAP"};
45 SSLEngineResult.HandshakeStatus[] enS = SSLEngineResult.HandshakeStatus.values();
46 if (enS.length == str.length) {
47 for (int i = 0; i < enS.length; i++) {
48 //System.out.println("enS[" + i + "] = " + enS[i]);
49 assertEquals("Incorrect Status", enS[i].toString(), str[i]);
50 }
51 } else {
52 fail("Incorrect number of enum constant was returned");
53 }
54 }
55
56 /**
57 * Test for <code> SSLEngineResult.HandshakeStatus.valueOf(String name) </code>
58 */
59 @TestTargetNew(
60 level = TestLevel.COMPLETE,
61 notes = "",
62 method = "valueOf",
63 args = {String.class}
64 )
65 public void test_SSLEngineResultStatus_valueOf() {
66 String[] str = {"FINISHED", "NEED_TASK", "NEED_UNWRAP", "NEED_WRAP", "NOT_HANDSHAKING"};
67 String[] str_invalid = {"", "FINISHED1", "NEED_task", "NEED_UN",
68 "NEED_WRAP_WRAP", "not_HANDSHAKING", "Bad string for verification valueOf method"};
69 SSLEngineResult.HandshakeStatus enS;
70
71 //Correct parameter
72 for (int i = 0; i < str.length; i++) {
73 try {
74 enS = SSLEngineResult.HandshakeStatus.valueOf(str[i]);
75 assertEquals("Incorrect Status", enS.toString(), str[i]);
76 } catch (Exception e) {
77 fail("Unexpected exception " + e + " was thrown for " + str[i]);
78 }
79 }
80
81 //Incorrect parameter
82 for (int i = 0; i < str_invalid.length; i++) {
83 try {
84 enS = SSLEngineResult.HandshakeStatus.valueOf(str_invalid[i]);
85 fail("IllegalArgumentException should be thrown for " + str_invalid[i]);
86 } catch (IllegalArgumentException iae) {
87 //expected
88 }
89 }
90
91 //Null parameter
92 try {
93 enS = SSLEngineResult.HandshakeStatus.valueOf(null);
94 fail("NullPointerException/IllegalArgumentException should be thrown for NULL parameter");
95 } catch (NullPointerException npe) {
96 //expected
97 } catch (IllegalArgumentException iae) {
98 }
99 }
100}