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.dev.jjs.test;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: import java.util.ArrayList;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: /**
25: * TODO: document me.
26: */
27: public class InnerClassTest extends GWTTestCase {
28:
29: /**
30: * TODO: document me.
31: */
32: public class InnerClass {
33: void callInner() {
34: testAppend.append("a");
35: class ReallyInnerClass {
36: void callReallyInner() {
37: testAppend.append("b");
38: }
39:
40: {
41: callReallyInner();
42: }
43: }
44: new ReallyInnerClass();
45: }
46:
47: {
48: callInner();
49: }
50: }
51:
52: public String getModuleName() {
53: return "com.google.gwt.dev.jjs.CompilerSuite";
54: }
55:
56: public void testInnerClassInitialization() {
57: assertEquals("ab", testAppend.toString());
58: }
59:
60: public void testInnerClassLoop() {
61: final StringBuffer b = new StringBuffer();
62: List results = new ArrayList();
63: abstract class AppendToStringBuffer {
64: public AppendToStringBuffer(int i) {
65: this .num = i;
66: }
67:
68: public abstract void act();
69:
70: int num;
71: }
72: for (int i = 0; i < 10; i++) {
73: AppendToStringBuffer ap = new AppendToStringBuffer(i) {
74: public void act() {
75: b.append(num);
76: }
77: };
78: results.add(ap);
79: }
80: for (Iterator it = results.iterator(); it.hasNext();) {
81: AppendToStringBuffer theAp = (AppendToStringBuffer) it
82: .next();
83: theAp.act();
84: }
85: assertEquals("0123456789", b.toString());
86: }
87:
88: protected void setUp() throws Exception {
89: testAppend = new StringBuffer();
90: new InnerClass();
91: }
92:
93: private StringBuffer testAppend;
94:
95: }
|