]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/perf/ResourceBundlePerf.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / perf / ResourceBundlePerf.java
1 /*\r
2 **********************************************************************\r
3 * Copyright (c) 2006-2008, International Business Machines\r
4 * Corporation and others.  All Rights Reserved.\r
5 **********************************************************************\r
6 */\r
7 \r
8 package com.ibm.icu.dev.test.perf;\r
9 \r
10 import java.nio.ByteBuffer;\r
11 import java.util.ResourceBundle;\r
12 \r
13 import com.ibm.icu.util.UResourceBundle;\r
14 \r
15 public class ResourceBundlePerf extends PerfTest {\r
16     \r
17     private UResourceBundle icuRes  = null;\r
18     private ResourceBundle javaRes = null;\r
19     \r
20     public static void main(String[] org_args) throws Exception {\r
21       new ResourceBundlePerf().run(org_args);\r
22     }\r
23     \r
24     protected void setup(String[] args) {\r
25         icuRes = UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes");\r
26         javaRes = ResourceBundle.getBundle("com.ibm.icu.dev.data.TestDataElements_testtypes");\r
27     }    \r
28 \r
29     PerfTest.Function TestResourceBundleConstructionJava() {\r
30         return new PerfTest.Function() {\r
31             public void call() {\r
32                 javaRes = ResourceBundle.getBundle("com.ibm.icu.dev.data.TestDataElements_testtypes");\r
33             }\r
34         };\r
35     }\r
36     PerfTest.Function TestResourceBundleConstructionICU() {\r
37         return new PerfTest.Function() {\r
38             public void call() {\r
39                 UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes");\r
40             }       \r
41         };\r
42     }\r
43     \r
44     PerfTest.Function TestEmptyArrayJava() {\r
45         return new PerfTest.Function(){\r
46             public void call(){\r
47                 String[] s = javaRes.getStringArray("emptyarray");\r
48                 if (s.length != 0) throw new Error ("not zero");\r
49             }\r
50         };\r
51     }\r
52 \r
53     PerfTest.Function TestEmptyArrayICU() {\r
54         return new PerfTest.Function(){\r
55             public void call(){\r
56                 String[] s = icuRes.getStringArray("emptyarray");\r
57                 if (s.length != 0) throw new Error ("not zero");\r
58             }\r
59         };\r
60     }\r
61     \r
62     class GetStringJava extends PerfTest.Function {\r
63         String key;\r
64         String expected;\r
65         GetStringJava(String key, String expected) {\r
66             this.key = key;\r
67             this.expected = expected;\r
68         }\r
69         public void call() {\r
70             String s = javaRes.getString(key);\r
71             if (!s.equals(expected)) throw new Error("not equal");\r
72         }\r
73     }\r
74     \r
75     class GetStringIcu extends PerfTest.Function {\r
76         String key;\r
77         String expected;\r
78         GetStringIcu(String key, String expected) {\r
79             this.key = key;\r
80             this.expected = expected;\r
81         }\r
82         public void call() {\r
83             String s = icuRes.getString(key);\r
84             if (!s.equals(expected)) throw new Error("not equal");\r
85         }\r
86     }\r
87     \r
88     PerfTest.Function TestZeroTestJava(){\r
89         return new GetStringJava("zerotest", "abc\u0000def");\r
90     }\r
91 \r
92     PerfTest.Function TestZeroTestICU(){\r
93         return new GetStringIcu("zerotest", "abc\u0000def");\r
94     }\r
95 \r
96     PerfTest.Function TestEmptyExplicitStringJava(){\r
97         return new GetStringJava("emptyexplicitstring", "");\r
98     }\r
99     \r
100     PerfTest.Function TestEmptyExplicitStringICU(){\r
101         return new GetStringIcu("emptyexplicitstring", "");\r
102     }\r
103 \r
104     PerfTest.Function TestEmptyStringJava(){\r
105         return new GetStringJava("emptystring", "");\r
106     }\r
107     \r
108     PerfTest.Function TestEmptyStringICU(){\r
109         return new GetStringIcu("emptystring", "");\r
110     }\r
111 \r
112     class GetIntJava extends PerfTest.Function {\r
113         String key;\r
114         int expected;\r
115         GetIntJava(String key, int expected) {\r
116             this.key = key;\r
117             this.expected = expected;\r
118         }\r
119         public void call() {\r
120             Integer t = (Integer) javaRes.getObject(key);\r
121             if (t.intValue() != expected) throw new Error("not equal");\r
122         }\r
123     }\r
124     \r
125     class GetIntIcu extends PerfTest.Function {\r
126         String key;\r
127         int expected;\r
128         GetIntIcu(String key, int expected) {\r
129             this.key = key;\r
130             this.expected = expected;\r
131         }\r
132         public void call() {\r
133             UResourceBundle temp = icuRes.get(key);\r
134             int t = temp.getInt();\r
135             if (t != expected) throw new Error("not equal");\r
136         }\r
137     }\r
138 \r
139     PerfTest.Function TestGet123Java(){\r
140         return new GetIntJava("onehundredtwentythree", 123);\r
141     }\r
142     \r
143     PerfTest.Function TestGet123ICU(){\r
144         return new GetIntIcu("onehundredtwentythree", 123);\r
145     }\r
146 \r
147     PerfTest.Function TestGetEmptyIntJava(){\r
148         return new GetIntJava("emptyint", 0);\r
149     }\r
150     \r
151     PerfTest.Function TestGetEmptyIntICU(){\r
152         return new GetIntIcu("emptyint", 0);\r
153     }\r
154 \r
155     PerfTest.Function TestGetOneJava(){\r
156         return new GetIntJava("one", 1);\r
157     }\r
158     \r
159     PerfTest.Function TestGetOneICU(){\r
160         return new GetIntIcu("one", 1);\r
161     }\r
162     \r
163     PerfTest.Function TestGetMinusOneJava(){\r
164         return new GetIntJava("minusone", -1);\r
165     }\r
166     \r
167     PerfTest.Function TestGetMinusOneICU(){\r
168         return new GetIntIcu("minusone", -1);\r
169     }\r
170 \r
171     PerfTest.Function TestGetPlusOneJava(){\r
172         return new GetIntJava("plusone", 1);\r
173     }\r
174     \r
175     PerfTest.Function TestGetPlusOneICU(){\r
176         return new GetIntIcu("plusone", 1);\r
177     }\r
178 \r
179     PerfTest.Function TestGetMinusOneUintJava(){ // TODO: no equivalence?\r
180         return new PerfTest.Function(){\r
181             public void call(){\r
182                 Integer t = (Integer) javaRes.getObject("minusone");\r
183                 if (t.intValue() != -1 ) throw new Error("not equal");\r
184             }\r
185         };\r
186     }\r
187     \r
188     PerfTest.Function TestGetMinusOneUintICU(){\r
189         return new PerfTest.Function(){\r
190             public void call(){\r
191                 UResourceBundle sub = icuRes.get("minusone");\r
192                 int t = sub.getUInt();\r
193                 if (t != 0xFFFFFFF) throw new Error("not equal");\r
194             }\r
195         };\r
196     }\r
197     \r
198 \r
199     class GetIvJava  extends PerfTest.Function {\r
200         String key;\r
201         int[] expected;\r
202         GetIvJava(String key, int[] expected) {\r
203             this.key = key;\r
204             this.expected = expected;\r
205         }\r
206         public void call() {\r
207             Integer[] iv = (Integer[]) javaRes.getObject(key);\r
208             for (int i = 0; i < iv.length; i++){\r
209                 if (expected[i] != iv[i].intValue()) throw new Error("not equal"); \r
210             }\r
211         }\r
212     }\r
213     \r
214     class GetIvIcu  extends PerfTest.Function {\r
215         String key;\r
216         int[] expected;\r
217         GetIvIcu(String key, int[] expected) {\r
218             this.key = key;\r
219             this.expected = expected;\r
220         }\r
221         public void call() {\r
222             UResourceBundle temp = icuRes.get(key);\r
223             int[] iv = temp.getIntVector();\r
224             for (int i = 0; i < iv.length; i++){\r
225                 if (expected[i] != iv[i]) throw new Error("not equal"); \r
226             }\r
227         }\r
228     }\r
229 \r
230     PerfTest.Function TestGetIntegerArrayJava(){\r
231         return new GetIvJava("integerarray", new int[]{1,2,3,-3,4,5,6,7});\r
232     }\r
233     \r
234     PerfTest.Function TestGetIntegerArrayICU(){\r
235         return new GetIvIcu("integerarray", new int[]{1,2,3,-3,4,5,6,7});\r
236     }\r
237 \r
238     PerfTest.Function TestGetEmptyIntegerArrayJava(){\r
239         return new GetIvJava("emptyintv", new int[0]);\r
240     }\r
241     \r
242     PerfTest.Function TestGetEmptyIntegerArrayICU(){\r
243         return new GetIvIcu("emptyintv", new int[0]);\r
244     }\r
245 \r
246     \r
247     class GetBinaryIcu extends PerfTest.Function {\r
248         String key;\r
249         int expected_len;\r
250         GetBinaryIcu(String key, int expected_len) {\r
251             this.key = key;\r
252             this.expected_len = expected_len;\r
253         }\r
254         public void call() {\r
255             UResourceBundle temp = icuRes.get(key);\r
256             ByteBuffer got = temp.getBinary();\r
257             if(got.remaining() != expected_len) throw new Error("not the expected len");\r
258             for(int i=0; i< got.remaining(); i++){\r
259               byte b = got.get();\r
260               if (i != b) throw new Error("not equal");\r
261             }\r
262         }\r
263     }\r
264 \r
265     class GetBinaryJava extends PerfTest.Function {\r
266         String key;\r
267         int expected_len;\r
268         GetBinaryJava(String key, int expected_len) {\r
269             this.key = key;\r
270             this.expected_len = expected_len;\r
271         }\r
272         public void call() {\r
273             ByteBuffer got = ByteBuffer.wrap((byte[])javaRes.getObject(key));\r
274             if(got.remaining() != expected_len) throw new Error("not the expected len");\r
275             for(int i=0; i< got.remaining(); i++){\r
276               byte b = got.get();\r
277               if (i != b) throw new Error("not equal");\r
278             }\r
279         }\r
280     }\r
281 \r
282     PerfTest.Function TestGetBinaryTestICU(){\r
283         return new GetBinaryIcu("binarytest", 15);\r
284     }\r
285     \r
286     PerfTest.Function TestGetBinaryTestJava(){\r
287         return new GetBinaryJava("binarytest", 15);\r
288     }\r
289     \r
290     PerfTest.Function TestGetEmptyBinaryICU(){\r
291         return new GetBinaryIcu("emptybin", 0);\r
292     }\r
293     \r
294     PerfTest.Function TestGetEmptyBinaryJava(){\r
295         return new GetBinaryJava("emptybin", 0);\r
296     }\r
297 \r
298     class GetMenuJava extends PerfTest.Function {\r
299         String key;\r
300         String[] expected;\r
301         GetMenuJava(String key, String[] expected) {\r
302             this.key = key;\r
303             this.expected = expected;\r
304         }\r
305         public void call() {\r
306             int p = 0;\r
307             Object[][] menus = (Object[][]) javaRes.getObject(key);\r
308             int sizei = menus.length;\r
309             for (int i=0; i<sizei; i++){\r
310                 String menu_name = (String) menus[i][0];\r
311                 Object[][] menu_items = (Object[][]) menus[i][1];\r
312                 if (!expected[p++].equals(menu_name)) throw new Error("not equal");\r
313                 \r
314                 int sizej = menu_items.length;\r
315                 for (int j=0; j< sizej; j++){\r
316                     String itemKey = (String) menu_items[j][0];\r
317                     String value = (String) menu_items[j][1];\r
318                     if(!expected[p++].equals(itemKey)) throw new Error("not equal");\r
319                     if(!expected[p++].equals(value)) throw new Error("not equal");\r
320                 }\r
321             }\r
322             \r
323         }\r
324     }\r
325     \r
326     class GetMenuIcu extends PerfTest.Function {\r
327         String key;\r
328         String[] expected;\r
329         GetMenuIcu(String key, String[] expected) {\r
330             this.key = key;\r
331             this.expected = expected;\r
332         }\r
333         public void call() {\r
334             int p = 0;\r
335             UResourceBundle menus = icuRes.get(key);\r
336             int sizei = menus.getSize();\r
337             for (int i=0; i<sizei; i++){\r
338                 UResourceBundle menu = menus.get(i);\r
339                 String menu_name = menu.getKey();\r
340                 if (!expected[p++].equals(menu_name)) throw new Error("not equal");\r
341                 \r
342                 int sizej = menu.getSize();\r
343                 for (int j=0; j< sizej; j++){\r
344                     UResourceBundle menu_item = menu.get(j);\r
345                     String itemKey = menu_item.getKey();\r
346                     String value = menu_item.getString();\r
347                     if(!expected[p++].equals(itemKey)) throw new Error("not equal");\r
348                     if(!expected[p++].equals(value)) throw new Error("not equal");\r
349                 }\r
350             }\r
351             \r
352         }\r
353     }\r
354 \r
355     PerfTest.Function TestGetMenuJava(){\r
356         String[] expected = new String[]{"file", "exit", "Exit", "open", "Open", "save", "Save"};\r
357         return new GetMenuJava("menu", expected);\r
358     }\r
359     \r
360     PerfTest.Function TestGetMenuICU(){\r
361         String[] expected = new String[]{"file", "exit", "Exit", "open", "Open", "save", "Save"};\r
362         return new GetMenuIcu("menu", expected);\r
363     }\r
364 \r
365     PerfTest.Function TestGetEmptyMenuJava(){\r
366         return new GetMenuJava("emptytable", new String[]{});\r
367     }\r
368     \r
369     PerfTest.Function TestGetEmptyMenuICU(){\r
370         return new GetMenuIcu("emptytable", new String[]{});\r
371     }\r
372 }\r