OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / libcore / javax / net / ssl / SSLParametersTest.java
1 /*
2  * Copyright (C) 2010 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  */
16
17 package libcore.javax.net.ssl;
18
19 import java.util.Arrays;
20 import javax.net.ssl.SSLParameters;
21 import junit.framework.TestCase;
22
23 public class SSLParametersTest extends TestCase {
24
25     public void test_SSLParameters_emptyConstructor() {
26         SSLParameters p = new SSLParameters();
27         assertNull(p.getCipherSuites());
28         assertNull(p.getProtocols());
29         assertFalse(p.getWantClientAuth());
30         assertFalse(p.getNeedClientAuth());
31     }
32
33     public void test_SSLParameters_cipherSuitesConstructor() {
34         String[] cipherSuites = new String[] { "foo", null, "bar" };
35         SSLParameters p = new SSLParameters(cipherSuites);
36         assertNotNull(p.getCipherSuites());
37         assertNotSame(cipherSuites, p.getCipherSuites());
38         assertEquals(Arrays.asList(cipherSuites), Arrays.asList(p.getCipherSuites()));
39         assertNull(p.getProtocols());
40         assertFalse(p.getWantClientAuth());
41         assertFalse(p.getNeedClientAuth());
42     }
43
44     public void test_SSLParameters_cpherSuitesProtocolsConstructor() {
45         String[] cipherSuites = new String[] { "foo", null, "bar" };
46         String[] protocols = new String[] { "baz", null, "qux" };
47         SSLParameters p = new SSLParameters(cipherSuites, protocols);
48         assertNotNull(p.getCipherSuites());
49         assertNotNull(p.getProtocols());
50         assertNotSame(cipherSuites, p.getCipherSuites());
51         assertNotSame(protocols, p.getProtocols());
52         assertEquals(Arrays.asList(cipherSuites), Arrays.asList(p.getCipherSuites()));
53         assertEquals(Arrays.asList(protocols), Arrays.asList(p.getProtocols()));
54         assertFalse(p.getWantClientAuth());
55         assertFalse(p.getNeedClientAuth());
56     }
57
58     public void test_SSLParameters_CipherSuites() {
59         SSLParameters p = new SSLParameters();
60         assertNull(p.getCipherSuites());
61
62         // confirm clone on input
63         String[] cipherSuites = new String[] { "fnord" };
64         String[] copy = cipherSuites.clone();
65         p.setCipherSuites(copy);
66         copy[0] = null;
67         assertEquals(Arrays.asList(cipherSuites), Arrays.asList(p.getCipherSuites()));
68
69         // confirm clone on output
70         assertNotSame(p.getCipherSuites(), p.getCipherSuites());
71     }
72
73     public void test_SSLParameters_Protocols() {
74         SSLParameters p = new SSLParameters();
75         assertNull(p.getProtocols());
76
77         // confirm clone on input
78         String[] protocols = new String[] { "fnord" };
79         String[] copy = protocols.clone();
80         p.setProtocols(copy);
81         copy[0] = null;
82         assertEquals(Arrays.asList(protocols), Arrays.asList(p.getProtocols()));
83
84         // confirm clone on output
85         assertNotSame(p.getProtocols(), p.getProtocols());
86     }
87
88     public void test_SSLParameters_ClientAuth() {
89         SSLParameters p = new SSLParameters();
90         assertFalse(p.getWantClientAuth());
91         assertFalse(p.getNeedClientAuth());
92
93         // confirm turning one on by itself
94         p.setWantClientAuth(true);
95         assertTrue(p.getWantClientAuth());
96         assertFalse(p.getNeedClientAuth());
97
98         // confirm turning setting on toggles the other
99         p.setNeedClientAuth(true);
100         assertFalse(p.getWantClientAuth());
101         assertTrue(p.getNeedClientAuth());
102
103         // confirm toggling back
104         p.setWantClientAuth(true);
105         assertTrue(p.getWantClientAuth());
106         assertFalse(p.getNeedClientAuth());
107     }
108 }