01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: import java.util.Collection;
21: import java.util.Map;
22: import java.util.Set;
23:
24: /**
25: * Tests <code>FastStringMap</code>Right now, no tests are directly run here,
26: * because the tests are run in mapTest.FastStringMapTest. This is because
27: * otherwise the inclusion of the map testing code causes the system to generate
28: * many compiler errors during unit testing, thereby making real errors harder
29: * to spot.
30: */
31: public class FastStringMapTest extends GWTTestCase {
32:
33: /**
34: * These is an example of two correctly formatted java API specification.
35: */
36: public static Map<String, String> makeEmptyMap() {
37: return new FastStringMap<String>();
38: }
39:
40: public String getModuleName() {
41: return "com.google.gwt.user.User";
42: }
43:
44: public void test() {
45: // Only FastStringMap specific tests should go here. Look in
46: // com.google.gwt.user.maptests.FastStringMapTest for all apache Map tests.
47: }
48:
49: /*
50: * Test for collisions between stored strings and JavaScript Object
51: * properties.
52: */
53: public void testJSOCollision() {
54: Map<String, String> map = makeEmptyMap();
55: assertEquals(0, map.size());
56: map.put("k1", "v1");
57: assertEquals(1, map.size());
58: assertEquals("v1", map.get("k1"));
59: map.put("toString", "toStringVal");
60: assertEquals(2, map.size());
61: assertEquals("toStringVal", map.get("toString"));
62: map.put("watch", "watchVal");
63: Set<String> keys = map.keySet();
64: assertEquals(3, keys.size());
65: map.put("__proto__", "__proto__Val");
66: assertEquals(4, map.size());
67: assertEquals("__proto__Val", map.get("__proto__"));
68: map.put("k1", "v1b");
69: keys = map.keySet();
70: assertEquals(4, keys.size());
71: Collection<String> values = map.values();
72: assertEquals(4, values.size());
73: map.put("k2", "v1b");
74: values = map.values();
75: assertEquals(5, values.size());
76: map.put("", "empty");
77: assertEquals("empty", map.get(""));
78: map.remove("k2");
79: assertEquals(5, values.size());
80: }
81:
82: }
|