Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 030dc584afbf9615c51e05dbaf80af673b62b648 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (c) 2001 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v0.5 
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *     IBM Corp. - Rational Software - initial implementation
 ******************************************************************************/

package org.eclipse.cdt.core.parser.tests;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;

import junit.framework.AssertionFailedError;
import junit.framework.Test;

import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.core.runtime.Path;



/**
 * @author aniefer
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class AutomatedTest extends AutomatedFramework {

	public AutomatedTest() {
	}
	public AutomatedTest(String name){
		super(name);
	}
	
	public void doFile() throws Throwable {
		assertNotNull( fileList );
		
		File file = null;
		IParser parser = null;
		
		try{
			file = (File)fileList.removeFirst();
			FileInputStream stream = new FileInputStream( file );

			String filePath = file.getCanonicalPath();
			String nature = (String)natures.get( filePath );
			
			boolean cppNature = nature.equalsIgnoreCase("cpp");
			
			parser = new Parser( stream, nullCallback, true);
			parser.setCppNature( cppNature );
			parser.mapLineNumbers(true);
			
			assertTrue( parser.parse() );
		} 
		catch( Throwable e )
		{
			String output = null;
			if( e instanceof AssertionFailedError ){
				output = file.getCanonicalPath() + ": Parse failed on line ";
				output += parser.getLineNumberForOffset(parser.getLastErrorOffset()) + "\n";
			} else {
				output = file.getCanonicalPath() + ": " + e.getClass().toString();
				output += " on line " + parser.getLineNumberForOffset(parser.getLastErrorOffset()) + "\n";
			}
			if( report != null ){
				report.write( output.getBytes() );
			}

			fail( output );
		}
	}
	
	protected AutomatedFramework newTest( String name ){
		return new AutomatedTest( name );
	}
	
	public static Test suite()
	{
		AutomatedFramework frame = new AutomatedTest();
		
		return frame.createSuite();
	}

	protected void tearDown () throws Exception	{
		if( fileList != null && fileList.size() == 0 && report != null ){
			report.flush();
			report.close();
		}
	}
	
	protected void loadProperties() throws Exception{
		String resourcePath = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
		resourcePath += "/parser/org/eclipse/cdt/core/parser/resources";
		
		try{
			FileInputStream propertiesIn = new FileInputStream( resourcePath + "/AutomatedTest.properties");
			properties.load( propertiesIn );
			
			outputFile = properties.getProperty( "outputFile", "" );
			String sourceInfo = properties.getProperty( "source", "" );
			if( sourceInfo.equals("") )
				throw new FileNotFoundException();
			else{
				StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," );
				String str = null, val = null;
				try{
					while( tokenizer.hasMoreTokens() ){
						str = tokenizer.nextToken().trim();
						val = tokenizer.nextToken().trim();
						
						testSources.put( str, val );
					}
				} catch ( NoSuchElementException e ){
					//only way to get here is to have a missing val, assume cpp for that str
					testSources.put( str, "cpp" );
				}
				
			}
		} catch ( FileNotFoundException e ){
			testSources.put( resourcePath + "/cppFiles", "cpp" );
			testSources.put( resourcePath + "/cFiles", "c" );
		}
	}

}

Back to the top