01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.harmony.jndi.provider.ldap.asn1;
19:
20: import java.io.IOException;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1ChoiceWrap.ChosenValue;
25: import org.apache.harmony.security.asn1.ASN1Boolean;
26: import org.apache.harmony.security.asn1.ASN1Integer;
27: import org.apache.harmony.security.asn1.ASN1OctetString;
28: import org.apache.harmony.security.asn1.ASN1Type;
29:
30: public class ASN1ChoiceWrapTest extends TestCase {
31: private static ASN1ChoiceWrap choice = new ASN1ChoiceWrap(
32: new ASN1Type[] { ASN1OctetString.getInstance(),
33: ASN1Integer.getInstance(),
34: ASN1Boolean.getInstance() });
35:
36: public void test_getIndex_LObject() {
37: Object[] values = new Object[] { Integer.valueOf(1),
38: Integer.valueOf(100) };
39: assertEquals(1, choice.getIndex(values));
40:
41: ChosenValue chosen = new ChosenValue(2, Boolean.valueOf(true));
42: assertEquals(2, choice.getIndex(chosen));
43: }
44:
45: public void test_getObjectToEncode_LObject() {
46: Object[] values = new Object[] { Integer.valueOf(1),
47: Integer.valueOf(100) };
48: assertEquals(values[1], choice.getObjectToEncode(values));
49:
50: ChosenValue chosen = new ChosenValue(0, "hello");
51: assertEquals(chosen.getValue(), choice
52: .getObjectToEncode(chosen));
53: }
54:
55: public void test_decode_LBerInputStream() throws IOException {
56: int index = 2;
57: Boolean value = Boolean.FALSE;
58: Object[] values = new Object[] { Integer.valueOf(index), value };
59: byte[] encoded = choice.encode(values);
60: Object decoded = choice.decode(encoded);
61:
62: assertTrue(decoded instanceof ChosenValue);
63: ChosenValue chosen = (ChosenValue) decoded;
64:
65: assertEquals(index, chosen.getIndex());
66: assertEquals(value, chosen.getValue());
67: }
68: }
|