KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > bugs > bug401 > TestCase


1 package org.jacorb.test.bugs.bug401;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import junit.framework.*;
24
25 import java.io.*;
26 import org.omg.CORBA.*;
27 import org.omg.CORBA.portable.*;
28 import org.jacorb.test.common.*;
29
30 /**
31  * Test for bug 401, TypeCode problem when putting values into Anys.
32  *
33  * @author <a HREF="mailto:spiegel@gnu.org">Andre Spiegel</a>
34  * @version $Id: TestCase.java,v 1.1 2003/10/29 11:47:22 andre.spiegel Exp $
35  */

36 public class TestCase extends ClientServerTestCase
37 {
38     private AnyServer server = null;
39     
40     public TestCase (String JavaDoc name, ClientServerSetup setup)
41     {
42         super (name, setup);
43     }
44     
45     public void setUp()
46     {
47         server = (AnyServer)AnyServerHelper.narrow(setup.getServerObject());
48         org.omg.CORBA_2_3.ORB JavaDoc orb = (org.omg.CORBA_2_3.ORB JavaDoc)setup.getClientOrb();
49         orb.register_value_factory(AHelper.id(), new AFactory());
50         orb.register_value_factory(BHelper.id(), new BFactory());
51     }
52     
53     public static Test suite()
54     {
55         TestSuite suite = new TestSuite("bug 401 values in anys");
56         ClientServerSetup setup =
57             new ClientServerSetup(suite,
58                                   "org.jacorb.test.bugs.bug401.AnyServant");
59
60         suite.addTest(new TestCase("test_getA", setup));
61         suite.addTest(new TestCase("test_getB", setup));
62         suite.addTest(new TestCase("test_getAB", setup));
63         
64         return setup;
65     }
66     
67     public void test_getA()
68     {
69         Any aa = server.getAnyA();
70         assertTrue ("expected TypeCode of A, got: " + aa.type().toString(),
71                     aa.type().equivalent(AHelper.type()));
72         A a = AHelper.extract(aa);
73         assertEquals (0xAA, a.aa);
74     }
75
76     public void test_getB()
77     {
78         Any bb = server.getAnyB();
79         assertTrue ("expected TypeCode of B, got: " + bb.type().toString(),
80                     bb.type().equivalent(BHelper.type()));
81         B b = BHelper.extract(bb);
82         assertEquals (0xAA, b.aa);
83         assertEquals (0xBB, b.bb);
84     }
85
86     public void test_getAB()
87     {
88         Any[] ab = server.getAnyAB();
89         assertTrue ("expected TypeCode of A, got: " + ab[0].type().toString(),
90                     ab[0].type().equivalent(AHelper.type()));
91         assertTrue ("expected TypeCode of B, got: " + ab[1].type().toString(),
92                     ab[1].type().equivalent(BHelper.type()));
93         A a = AHelper.extract(ab[0]);
94         B b = BHelper.extract(ab[1]);
95         assertEquals (0xAA, a.aa);
96         assertEquals (0xAA, b.aa);
97         assertEquals (0xBB, b.bb);
98     }
99
100     public static class AFactory implements ValueFactory
101     {
102         public Serializable read_value
103                                  (org.omg.CORBA_2_3.portable.InputStream JavaDoc is)
104         {
105             A a = new A(){};
106             return is.read_value(a);
107         }
108     }
109
110     public static class BFactory implements ValueFactory
111     {
112         public Serializable read_value
113                                  (org.omg.CORBA_2_3.portable.InputStream JavaDoc is)
114         {
115             B b = new B(){};
116             return is.read_value(b);
117         }
118     }
119
120 }
121
Popular Tags