bump product version to 4.1.6.2
[LibreOffice.git] / bridges / test / java_remote / PolyStructTest.java
blob146d14fea644dfaf8fccc6ec46e9d538eb86dbc3
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package test.java_remote;
21 import com.sun.star.bridge.XInstanceProvider;
22 import com.sun.star.uno.Any;
23 import com.sun.star.uno.Type;
24 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.uno.XComponentContext;
26 import complexlib.ComplexTestCase;
27 import test.lib.TestBed;
29 public final class PolyStructTest extends ComplexTestCase {
30 public String[] getTestMethodNames() {
31 return new String[] { "test" };
34 public void test() throws Exception {
35 assure(
36 "test",
37 new TestBed().execute(new Provider(), false, Client.class, 0));
40 public static final class Client extends TestBed.Client {
41 public static void main(String[] args) {
42 new Client().execute();
45 protected boolean run(XComponentContext context) throws Throwable {
46 TestTransport t = UnoRuntime.queryInterface(
47 TestTransport.class, getBridge(context).getInstance(""));
49 assertEquals(
50 Boolean.FALSE, t.transportBoolean(new TestPolyStruct()).member);
51 assertEquals(
52 Boolean.FALSE,
53 t.transportBoolean(new TestPolyStruct(Boolean.FALSE)).member);
54 assertEquals(
55 Boolean.TRUE,
56 t.transportBoolean(new TestPolyStruct(Boolean.TRUE)).member);
58 assertEquals(
59 new Byte((byte) 0),
60 t.transportByte(new TestPolyStruct()).member);
61 assertEquals(
62 new Byte(Byte.MIN_VALUE),
63 t.transportByte(
64 new TestPolyStruct(new Byte(Byte.MIN_VALUE))).member);
65 assertEquals(
66 new Byte(Byte.MAX_VALUE),
67 t.transportByte(
68 new TestPolyStruct(new Byte(Byte.MAX_VALUE))).member);
70 assertEquals(
71 new Short((short) 0),
72 t.transportShort(new TestPolyStruct()).member);
73 assertEquals(
74 new Short(Short.MIN_VALUE),
75 t.transportShort(
76 new TestPolyStruct(new Short(Short.MIN_VALUE))).member);
77 assertEquals(
78 new Short(Short.MAX_VALUE),
79 t.transportShort(
80 new TestPolyStruct(new Short(Short.MAX_VALUE))).member);
82 assertEquals(
83 new Integer(0), t.transportLong(new TestPolyStruct()).member);
84 assertEquals(
85 new Integer(Integer.MIN_VALUE),
86 t.transportLong(
87 new TestPolyStruct(new Integer(Integer.MIN_VALUE))).member);
88 assertEquals(
89 new Integer(Integer.MAX_VALUE),
90 t.transportLong(
91 new TestPolyStruct(new Integer(Integer.MAX_VALUE))).member);
93 assertEquals(
94 new Long(0L), t.transportHyper(new TestPolyStruct()).member);
95 assertEquals(
96 new Long(Long.MIN_VALUE),
97 t.transportHyper(
98 new TestPolyStruct(new Long(Long.MIN_VALUE))).member);
99 assertEquals(
100 new Long(Long.MAX_VALUE),
101 t.transportHyper(
102 new TestPolyStruct(new Long(Long.MAX_VALUE))).member);
104 assertEquals(
105 new Float(0.0f), t.transportFloat(new TestPolyStruct()).member);
106 assertEquals(
107 new Float(Float.MIN_VALUE),
108 t.transportFloat(
109 new TestPolyStruct(new Float(Float.MIN_VALUE))).member);
110 assertEquals(
111 new Float(Float.MAX_VALUE),
112 t.transportFloat(
113 new TestPolyStruct(new Float(Float.MAX_VALUE))).member);
115 assertEquals(
116 new Double(0.0),
117 t.transportDouble(new TestPolyStruct()).member);
118 assertEquals(
119 new Double(Double.MIN_VALUE),
120 t.transportDouble(
121 new TestPolyStruct(new Double(Double.MIN_VALUE))).member);
122 assertEquals(
123 new Double(Double.MAX_VALUE),
124 t.transportDouble(
125 new TestPolyStruct(new Double(Double.MAX_VALUE))).member);
127 assertEquals(
128 new Character(Character.MIN_VALUE),
129 t.transportChar(new TestPolyStruct()).member);
130 assertEquals(
131 new Character(Character.MIN_VALUE),
132 t.transportChar(
133 new TestPolyStruct(
134 new Character(Character.MIN_VALUE))).member);
135 assertEquals(
136 new Character(Character.MAX_VALUE),
137 t.transportChar(
138 new TestPolyStruct(
139 new Character(Character.MAX_VALUE))).member);
141 assertEquals("", t.transportString(new TestPolyStruct()).member);
142 assertEquals(
143 "ABC", t.transportString(new TestPolyStruct("ABC")).member);
145 assertEquals(
146 Type.VOID, t.transportType(new TestPolyStruct()).member);
147 assertEquals(
148 new Type(
149 "[]com.sun.star.lib.uno.bridges.javaremote.TestPolyStruct"
150 + "<long>"),
151 t.transportType(
152 new TestPolyStruct(
153 new Type(
154 "[]com.sun.star.lib.uno.bridges.javaremote."
155 + "TestPolyStruct<long>"))).member);
157 assertEquals(null, t.transportAny(new TestPolyStruct()).member);
158 assertEquals(
159 Any.VOID, t.transportAny(new TestPolyStruct(Any.VOID)).member);
160 assertEquals(null, t.transportAny(new TestPolyStruct(null)).member);
161 assertEquals(
162 new Any(Type.UNSIGNED_LONG, new Integer(5)),
163 t.transportAny(
164 new TestPolyStruct(
165 new Any(Type.UNSIGNED_LONG, new Integer(5)))).member);
167 assertEquals(
168 TestEnum.VALUE1, t.transportEnum(new TestPolyStruct()).member);
169 assertEquals(
170 TestEnum.VALUE1,
171 t.transportEnum(new TestPolyStruct(TestEnum.VALUE1)).member);
172 assertEquals(
173 TestEnum.VALUE2,
174 t.transportEnum(new TestPolyStruct(TestEnum.VALUE2)).member);
176 return success;
179 private void assertEquals(Object expected, Object actual) {
180 if (!(expected == null ? actual == null : expected.equals(actual)))
182 new RuntimeException(
183 "failed; expected " + expected + ", got " + actual).
184 printStackTrace();
185 success = false;
189 private boolean success = true;
192 private static final class Provider implements XInstanceProvider {
193 public Object getInstance(String instanceName) {
194 return new TestTransport() {
195 public TestPolyStruct transportBoolean(TestPolyStruct s) {
196 return s;
199 public TestPolyStruct transportByte(TestPolyStruct s) {
200 return s;
203 public TestPolyStruct transportShort(TestPolyStruct s) {
204 return s;
207 public TestPolyStruct transportLong(TestPolyStruct s) {
208 return s;
211 public TestPolyStruct transportHyper(TestPolyStruct s) {
212 return s;
215 public TestPolyStruct transportFloat(TestPolyStruct s) {
216 return s;
219 public TestPolyStruct transportDouble(TestPolyStruct s) {
220 return s;
223 public TestPolyStruct transportChar(TestPolyStruct s) {
224 return s;
227 public TestPolyStruct transportString(TestPolyStruct s) {
228 return s;
231 public TestPolyStruct transportType(TestPolyStruct s) {
232 return s;
235 public TestPolyStruct transportAny(TestPolyStruct s) {
236 return s;
239 public TestPolyStruct transportEnum(TestPolyStruct s) {
240 return s;