001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.jjs.test;
017:
018: import com.google.gwt.junit.client.GWTTestCase;
019:
020: /**
021: * TODO: document me.
022: */
023: public class ClassCastTest extends GWTTestCase {
024:
025: static class Apple extends Food implements CanEatRaw {
026: }
027:
028: static interface CanEatRaw {
029: }
030:
031: static abstract class Food {
032: }
033:
034: public String getModuleName() {
035: return "com.google.gwt.dev.jjs.CompilerSuite";
036: }
037:
038: public void testBaseToInterface() {
039: Apple apple = (Apple) m_foodItem;
040: }
041:
042: public void testBaseToInterface_method() {
043: Apple apple = (Apple) getFoodItem();
044: }
045:
046: public void testBaseToInterfaceToConcrete_crazyInline() {
047: Apple apple = (Apple) (CanEatRaw) (Food) new Apple();
048: }
049:
050: public void testBaseToInterfaceToConcrete_field() {
051: Apple apple = (Apple) getFoodAsRawFood_field();
052: }
053:
054: public void testBaseToInterfaceToConcrete_inline() {
055: Apple apple = (Apple) (CanEatRaw) m_foodItem;
056: }
057:
058: public void testBaseToInterfaceToConcrete_method() {
059: Apple apple = (Apple) getFoodAsRawFood_method();
060: }
061:
062: public void testDownCastClass() {
063: Apple apple = (Apple) m_foodItem;
064: }
065:
066: public void testDownCastClass_method() {
067: Apple apple = (Apple) getFoodItem();
068: }
069:
070: public void testDownCastInterface() {
071: Apple apple = (Apple) m_rawFoodItem;
072: }
073:
074: public void testDownCastInterface_method() {
075: Apple apple = (Apple) getRawFoodItem();
076: }
077:
078: public void testInterfaceToBaseToConcrete_field() {
079: Apple apple = (Apple) getRawFoodAsFood_field();
080: }
081:
082: public void testInterfaceToBaseToConcrete_inline() {
083: Apple apple = (Apple) (Food) m_rawFoodItem;
084: }
085:
086: public void testInterfaceToBaseToConcrete_method() {
087: Apple apple = (Apple) getRawFoodAsFood_method();
088: }
089:
090: private CanEatRaw getFoodAsRawFood_field() {
091: return (CanEatRaw) m_foodItem;
092: }
093:
094: private CanEatRaw getFoodAsRawFood_method() {
095: return (CanEatRaw) getFoodItem();
096: }
097:
098: private Food getFoodItem() {
099: return m_foodItem;
100: }
101:
102: private Food getRawFoodAsFood_field() {
103: return (Food) m_rawFoodItem;
104: }
105:
106: private Food getRawFoodAsFood_method() {
107: return (Food) getRawFoodItem();
108: }
109:
110: private CanEatRaw getRawFoodItem() {
111: return m_rawFoodItem;
112: }
113:
114: private final Food m_foodItem = new Apple();
115: private final CanEatRaw m_rawFoodItem = new Apple();
116:
117: }
|