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.cfg;
017:
018: import com.google.gwt.core.ext.TreeLogger;
019: import com.google.gwt.core.ext.UnableToCompleteException;
020: import com.google.gwt.dev.cfg.test.caseinsensitive.GOO;
021: import com.google.gwt.dev.cfg.test.caseinsensitive.Good;
022: import com.google.gwt.dev.cfg.test.casesensitive.CaseSensitive_A_Foo;
023: import com.google.gwt.dev.cfg.test.casesensitive.CaseSensitive_a_Bar;
024: import com.google.gwt.dev.cfg.test.excludes.Excludes_Exclude1;
025: import com.google.gwt.dev.cfg.test.excludes.Excludes_Exclude2;
026: import com.google.gwt.dev.cfg.test.excludes.Excludes_Exclude3;
027: import com.google.gwt.dev.cfg.test.excludes.Excludes_Include1;
028: import com.google.gwt.dev.cfg.test.excludes.Excludes_Include2;
029: import com.google.gwt.dev.cfg.test.excludes.Excludes_Include3;
030: import com.google.gwt.dev.cfg.test.includeexclude.IncludeExclude_Exclude1;
031: import com.google.gwt.dev.cfg.test.includeexclude.IncludeExclude_Exclude2;
032: import com.google.gwt.dev.cfg.test.includeexclude.IncludeExclude_Exclude3;
033: import com.google.gwt.dev.cfg.test.includeexclude.IncludeExclude_Include1;
034: import com.google.gwt.dev.cfg.test.includeexclude.IncludeExclude_Include2;
035: import com.google.gwt.dev.cfg.test.includes.Includes_Exclude1;
036: import com.google.gwt.dev.cfg.test.includes.Includes_Exclude2;
037: import com.google.gwt.dev.cfg.test.includes.Includes_Exclude3;
038: import com.google.gwt.dev.cfg.test.includes.Includes_Include1;
039: import com.google.gwt.dev.cfg.test.includes.Includes_Include2;
040: import com.google.gwt.dev.cfg.test.includes.Includes_Include3;
041: import com.google.gwt.dev.cfg.test.recursive.bar.Recursive_Excluded1;
042: import com.google.gwt.dev.cfg.test.recursive.good.Recursive_Include1;
043: import com.google.gwt.dev.cfg.test.recursive.good.bar.Recursive_Excluded2;
044: import com.google.gwt.dev.cfg.test.recursive.good.bar.good.Recursive_Include2;
045: import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
046:
047: import junit.framework.TestCase;
048:
049: import java.io.PrintWriter;
050:
051: /**
052: * Common test code for testing the various permutations of GWT module's
053: * <source> and <super-source> source tags, specifically their
054: * ant-like inclusion support.
055: */
056: public abstract class TestSuperAndSourceTags extends TestCase {
057: private static TreeLogger getRootLogger() {
058: PrintWriterTreeLogger logger = new PrintWriterTreeLogger(
059: new PrintWriter(System.err, true));
060: logger.setMaxDetail(TreeLogger.ERROR);
061: return logger;
062: }
063:
064: private final ModuleDef moduleDef;
065:
066: public TestSuperAndSourceTags() throws UnableToCompleteException {
067: // Module has the same name as this class.
068: String moduleName = getClass().getCanonicalName();
069: moduleDef = ModuleDefLoader.loadFromClassPath(getRootLogger(),
070: moduleName);
071: }
072:
073: /**
074: * Returns the logical path for a class. This method is implemented by the
075: * subclasses because source and super-source compute logical paths
076: * differently.
077: */
078: protected abstract String getLogicalPath(Class<?> clazz);
079:
080: /**
081: * Validate that the source or super-source tags .
082: */
083: protected void validateTags() {
084: // Test case insensitive
085: validateIncluded(Good.class);
086: validateIncluded(GOO.class);
087:
088: // Test case sensitive
089: validateIncluded(CaseSensitive_A_Foo.class);
090: validateExcluded(CaseSensitive_a_Bar.class);
091:
092: // Test excludes
093: validateExcluded(Excludes_Exclude1.class);
094: validateExcluded(Excludes_Exclude2.class);
095: validateExcluded(Excludes_Exclude3.class);
096: validateIncluded(Excludes_Include1.class);
097: validateIncluded(Excludes_Include2.class);
098: validateIncluded(Excludes_Include3.class);
099:
100: // Test include and exclude
101: validateExcluded(IncludeExclude_Exclude1.class);
102: validateExcluded(IncludeExclude_Exclude2.class);
103: validateExcluded(IncludeExclude_Exclude3.class);
104: validateIncluded(IncludeExclude_Include1.class);
105: validateIncluded(IncludeExclude_Include2.class);
106:
107: // Test includes
108: validateExcluded(Includes_Exclude1.class);
109: validateExcluded(Includes_Exclude2.class);
110: validateExcluded(Includes_Exclude3.class);
111: validateIncluded(Includes_Include1.class);
112: validateIncluded(Includes_Include2.class);
113: validateIncluded(Includes_Include3.class);
114:
115: // Test recursive behavior
116: validateExcluded(Recursive_Excluded1.class);
117: validateExcluded(Recursive_Excluded2.class);
118: validateIncluded(Recursive_Include1.class);
119: validateIncluded(Recursive_Include2.class);
120: }
121:
122: private void validateExcluded(Class<?> clazz) {
123: assertNull(moduleDef.findSourceFile(getLogicalPath(clazz)));
124: }
125:
126: private void validateIncluded(Class<?> clazz) {
127: assertNotNull(moduleDef.findSourceFile(getLogicalPath(clazz)));
128: }
129: }
|