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

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.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) 2002, 2006 IBM Corporation and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 * Rational Software - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.core.model.tests;
 
12
 
 
13
 
 
14
import java.io.FileInputStream;
 
15
import java.io.FileNotFoundException;
 
16
 
 
17
import junit.framework.Test;
 
18
import junit.framework.TestCase;
 
19
import junit.framework.TestSuite;
 
20
 
 
21
import org.eclipse.cdt.core.dom.IPDOMManager;
 
22
import org.eclipse.cdt.core.model.CoreModel;
 
23
import org.eclipse.cdt.core.model.IBuffer;
 
24
import org.eclipse.cdt.core.model.ICProject;
 
25
import org.eclipse.cdt.core.model.ITranslationUnit;
 
26
import org.eclipse.cdt.core.model.IWorkingCopy;
 
27
import org.eclipse.cdt.core.testplugin.CProjectHelper;
 
28
import org.eclipse.cdt.core.testplugin.CTestPlugin;
 
29
import org.eclipse.cdt.core.testplugin.TestPluginLauncher;
 
30
import org.eclipse.core.resources.IFile;
 
31
import org.eclipse.core.runtime.CoreException;
 
32
import org.eclipse.core.runtime.NullProgressMonitor;
 
33
import org.eclipse.core.runtime.Path;
 
34
 
 
35
/**
 
36
 * Contains unit test cases for Working Copies. Run using JUnit Plugin Test
 
37
 * configuration launcher.
 
38
 */
 
39
public class WorkingCopyTests extends TestCase {        
 
40
        private ICProject fCProject;
 
41
        private IFile headerFile;
 
42
        private NullProgressMonitor monitor;
 
43
        
 
44
        public static void main(String[] args) {
 
45
                TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), WorkingCopyTests.class, args);
 
46
        }
 
47
        
 
48
        public static Test suite() {
 
49
                TestSuite suite= new TestSuite(WorkingCopyTests.class.getName());
 
50
                suite.addTest(new WorkingCopyTests("testWorkingCopy"));
 
51
                //suite.addTest(new WorkingCopyTests("testHashing"));
 
52
                return suite;
 
53
        }               
 
54
        
 
55
        public WorkingCopyTests(String name) {
 
56
                super(name);
 
57
        }
 
58
        
 
59
        protected void setUp() throws Exception {
 
60
                monitor = new NullProgressMonitor();
 
61
        
 
62
                fCProject= CProjectHelper.createCCProject("TestProject1", "bin", IPDOMManager.ID_NO_INDEXER);
 
63
                //Path filePath = new Path(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()+ fCProject.getPath().toString()+ "/WorkingCopyTest.h");
 
64
                headerFile = fCProject.getProject().getFile("WorkingCopyTest.h");
 
65
                if (!headerFile.exists()) {
 
66
                        try{
 
67
                                FileInputStream fileIn = new FileInputStream(
 
68
                                                CTestPlugin.getDefault().getFileInPlugin(new Path("resources/cfiles/WorkingCopyTestStart.h"))); 
 
69
                                headerFile.create(fileIn,false, monitor);        
 
70
                        } catch (CoreException e) {
 
71
                                e.printStackTrace();
 
72
                        } catch (FileNotFoundException e) {
 
73
                                e.printStackTrace();
 
74
                        }
 
75
                }
 
76
        }
 
77
 
 
78
        protected void tearDown()  {
 
79
                CProjectHelper.delete(fCProject);
 
80
        }       
 
81
                
 
82
                
 
83
        public void testWorkingCopy() throws Exception {
 
84
                ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(headerFile);
 
85
                // CreateWorkingCopy            
 
86
                assertNotNull (tu);
 
87
                IWorkingCopy wc = tu.getWorkingCopy();
 
88
                assertNotNull (wc);
 
89
                assertNotNull (wc.getBuffer());
 
90
                assertTrue (wc.exists());
 
91
                
 
92
                // ModifyWorkingCopy
 
93
                IBuffer wcBuf = wc.getBuffer();
 
94
                wcBuf.append("\n class Hello{ int x; };");
 
95
                if (tu.getBuffer().getContents().equals(wc.getBuffer().getContents() ) )
 
96
                        fail("Buffers should NOT be equal at this point!");             
 
97
                
 
98
                // ReconcileWorkingCopy
 
99
                wc.reconcile();
 
100
                
 
101
                // CommitWorkingCopy
 
102
                wc.commit(true, monitor);
 
103
                
 
104
                if(!tu.getBuffer().getContents().equals(wc.getBuffer().getContents())) 
 
105
                        fail("Buffers should be equal at this point!");
 
106
                
 
107
                // DestroyWorkingCopy
 
108
                wc.destroy();
 
109
                assertFalse(wc.exists());       
 
110
                
 
111
                Thread.sleep(1000);     
 
112
        }
 
113
}