Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fb6573d788eb8ca03d0b05652e4025fcf3935253 (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
/*******************************************************************************
 * Copyright (c) 2000, 2012 QNX Software Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/

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

import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.internal.core.model.CModelStatus;
import org.eclipse.core.runtime.CoreException;

import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * CModelExceptionTest
 *
 * @author Judy N. Green
 * @since Jul 19, 2002
 */
public class CModelExceptionTest extends TestCase {
	// Shared values setup and torn down
	private CModelStatus cModelStatus;
	private CoreException coreException;

	/**
	 * Constructor for TestCModelException.
	 * @param name
	 */
	public CModelExceptionTest(String name) {
		super(name);
	}

	/**
	 * Sets up the test fixture.
	 *
	 * Called before every test case method.
	 *
	 * Example code test the packages in the project
	 *  "com.qnx.tools.ide.cdt.core"
	 */
	@Override
	protected void setUp() {
		// create shared resources and setup the test fixture
		cModelStatus = new CModelStatus();
		coreException = new CoreException(cModelStatus);
	}

	/**
	* Tears down the test fixture.
	*
	* Called after every test case method.
	*/
	@Override
	protected void tearDown() {
		// release resources here and clean-up
	}

	public static TestSuite suite() {
		return new TestSuite(CModelExceptionTest.class);
	}

	public static void main(String[] args) {
		junit.textui.TestRunner.run(suite());
	}

	public void testCreationNoStatus() {
		CModelException testException = new CModelException(coreException);
		// should be the same object inside
		assertTrue("Object compare failed", testException.getException() == coreException);
	}

	public void testCreationWithStatus() {
		CModelException testException = new CModelException(coreException, ICModelStatusConstants.INDEX_OUT_OF_BOUNDS);
		// should not be null
		assertTrue("TestException.getStatus() is null", (testException.getStatus() != null));

		// should have the same status as was set on creation
		assertTrue("Object compare failed",
				testException.getStatus().getCode() == ICModelStatusConstants.INDEX_OUT_OF_BOUNDS);
	}

	public void testElementDoesNotExist() {
		CModelException testException = new CModelException(coreException,
				ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST);
		// should not exist since this is the value we set on creation
		assertTrue("Object unexpectedly exists", testException.doesNotExist());
	}

	public void testElementExists() {
		CModelException testException = new CModelException(coreException, ICModelStatusConstants.INVALID_CONTENTS);
		// should not exist since this is the value we set on creation
		assertTrue("Object unexpectedly does not exist", !testException.doesNotExist());
	}
}

Back to the top