~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik  
 
3
 * Rapperswil, University of applied sciences and others
 
4
 * All rights reserved. This program and the accompanying materials 
 
5
 * are made available under the terms of the Eclipse Public License v1.0 
 
6
 * which accompanies this distribution, and is available at 
 
7
 * http://www.eclipse.org/legal/epl-v10.html  
 
8
 *  
 
9
 * Contributors: 
 
10
 * Institute for Software - initial API and implementation
 
11
 *******************************************************************************/
 
12
package org.eclipse.cdt.core.parser.tests.rewrite;
 
13
 
 
14
import java.io.BufferedReader;
 
15
import java.io.InputStreamReader;
 
16
import java.util.Map;
 
17
import java.util.TreeMap;
 
18
import java.util.Vector;
 
19
 
 
20
import org.eclipse.cdt.core.tests.BaseTestFramework;
 
21
import org.eclipse.core.resources.IFile;
 
22
import org.eclipse.core.runtime.ILogListener;
 
23
import org.eclipse.core.runtime.IStatus;
 
24
import org.eclipse.core.runtime.NullProgressMonitor;
 
25
import org.eclipse.core.runtime.Path;
 
26
import org.eclipse.jface.text.TextSelection;
 
27
 
 
28
/**
 
29
 * @author Guido Zgraggen IFS
 
30
 *
 
31
 */
 
32
public abstract class RewriteBaseTest extends BaseTestFramework implements ILogListener{
 
33
        protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
 
34
        
 
35
        protected TreeMap<String, TestSourceFile> fileMap = new TreeMap<String, TestSourceFile>();
 
36
        protected String fileWithSelection;
 
37
        protected TextSelection selection;
 
38
 
 
39
        protected RewriteBaseTest(String name) {
 
40
                super(name);
 
41
        }
 
42
        
 
43
        public RewriteBaseTest(String name, Vector<TestSourceFile> files) {
 
44
                super(name);
 
45
                for (TestSourceFile file : files) {
 
46
                        fileMap.put(file.getName(), file);
 
47
                }
 
48
        }
 
49
 
 
50
        @Override
 
51
        protected abstract void runTest() throws Throwable;
 
52
        
 
53
 
 
54
        @Override
 
55
        protected void setUp() throws Exception {
 
56
                super.setUp();
 
57
                for (TestSourceFile testFile : fileMap.values()) {
 
58
                        if(testFile.getSource().length() > 0) {
 
59
                                importFile(testFile.getName(), testFile.getSource());
 
60
                        }
 
61
                }
 
62
        }
 
63
        
 
64
        protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
 
65
                StringBuffer code = getCodeFromIFile(file2);
 
66
                assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
 
67
        }
 
68
        
 
69
        protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
 
70
                for (String fileName : testResourceFiles.keySet()) {
 
71
                        TestSourceFile file = testResourceFiles.get(fileName);
 
72
                        IFile iFile = project.getFile(new Path(fileName));
 
73
                        StringBuffer code = getCodeFromIFile(iFile);
 
74
                        assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
 
75
                }
 
76
        }
 
77
 
 
78
        protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
 
79
                BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
 
80
                StringBuffer code = new StringBuffer();
 
81
                String line;
 
82
                while((line = br.readLine()) != null) {
 
83
                        code.append(line);
 
84
                        code.append('\n');
 
85
                }
 
86
                br.close();
 
87
                return code;
 
88
        }
 
89
 
 
90
        @Override
 
91
        protected void tearDown() throws Exception {
 
92
                System.gc();
 
93
                fileManager.closeAllFiles();
 
94
                super.tearDown();
 
95
        }
 
96
 
 
97
        public void logging(IStatus status, String plugin) {
 
98
                Throwable ex = status.getException();
 
99
                StringBuffer stackTrace = new StringBuffer();
 
100
                if(ex != null) {
 
101
                        stackTrace.append('\n');
 
102
                        for(StackTraceElement ste : ex.getStackTrace()) {
 
103
                                stackTrace.append(ste.toString());
 
104
                        }
 
105
                }
 
106
                fail("Log-Message: " + status.getMessage() + stackTrace.toString());             //$NON-NLS-1$
 
107
        }
 
108
 
 
109
        public void setFileWithSelection(String fileWithSelection) {
 
110
                this.fileWithSelection = fileWithSelection;
 
111
        }
 
112
 
 
113
        public void setSelection(TextSelection selection) {
 
114
                this.selection = selection;
 
115
        }
 
116
}