Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 517b75895590f471f8b3d0a7a72515219c632fed (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
/*******************************************************************************
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*
 * Created on Jun 4, 2003
 * by bnicolle
 */
package org.eclipse.cdt.core.model.tests;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.ITranslationUnit;

/**
 * @author bnicolle
 *
 */
public class IIncludeTests extends IntegratedCModelTest {

	/**
	 * @param string
	 */
	public IIncludeTests(String string) {
		super( string );
	}

	/**
	 * @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
	 */
	public String getSourcefileSubdir() {
		return "resources/cmodel/";
	}

	/**
	 * @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
	 */
	public String getSourcefileResource() {
		return "IIncludeTest.h";
	}

	/**
	 * @returns a test suite named after this class
	 *          containing all its public members named "test*"
	 */
	public static Test suite() {
		TestSuite suite= new TestSuite(IIncludeTests.class);
		return suite;
	}		

	public void testGetIncludeName()
	{
		ITranslationUnit tu = getTU();
		IInclude[] theIncludes = null;
		try {
			theIncludes = tu.getIncludes();
		}
		catch( CModelException c )
		{
			assertNotNull("CModelException thrown",c);
		}

		String getIncludeNameList[] =  new String[] {
			new String("stdio.h"),
			new String("whatever.h"),
			new String("src/slash.h"),
			new String("src\\backslash.h"), // that's a single backslash, escaped
			new String("Program Files/space.h"),
			new String("../up1dir.h"),
			new String("./samedir.h"),
			new String("different_extension1.hpp"),
			new String("different_extension2.hh"),
			new String("different_extension3.x"),
			new String("no_extension"),
			new String("whitespace_after_hash"),
			new String("whitespace_before_hash"),
			new String("resync_after_bad_parse_1"),			
			new String("resync_after_bad_parse_2"),
			new String("one"),  // C-spec does not allow this, but that's OK for our present purposes
			new String("resync_after_bad_parse_3"),
			new String("invalid.h"),  // C-spec does not allow this, but that's OK for our present purposes
			new String("myInclude1.h"),
			new String("vers2.h")						
		};
		assertEquals( getIncludeNameList.length, theIncludes.length );
		for( int i=0; i<getIncludeNameList.length; i++ )
		{
			IInclude inc1 = theIncludes[i];
			assertEquals( getIncludeNameList[i], inc1.getIncludeName() );
		}
		
	}
	
	public void testIsStandard()
	{
		ITranslationUnit tu = getTU();
		IInclude[] theIncludes = null;
		try {
			theIncludes = tu.getIncludes();
		}
		catch( CModelException c )
		{
			assertNotNull("CModelException thrown",c);
		}
		boolean isStandardList[] =  new boolean[] {
			true, false
		};
		for( int i=0; i<isStandardList.length; i++ )
		{
			IInclude inc1 = theIncludes[i];
			assertEquals( isStandardList[i], inc1.isStandard() );
		}
	}
	
}

Back to the top