Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9c531df5bbfdd05129d18a3b903a58e6495d1ea1 (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
/*******************************************************************************
 * Copyright (c) 2000, 2006 QNX Software Systems 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:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/

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

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

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;

/**
 *
 * CModelExceptionTest
 * 
 * @author Judy N. Green
 * @since Jul 19, 2002
 */
public class CModelExceptionTest extends TestCase {
    // Shared values setup and torn down
    private Throwable throwableException;
    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"
     */
    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.
     */
    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 not be null
        assertTrue("TestException is null", (testException != null));

        // 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 is null", (testException != null));

        // 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 be null
        assertTrue("TestException is null", (testException != null));

        
        // 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 be null
        assertTrue("TestException is null", (testException != null));

        
        // should not exist since this is the value we set on creation
        assertTrue("Object unexpectedly does not exist", testException.doesNotExist() == false);
    }
    

}

Back to the top