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
9
* Rational Software - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.core.model.tests;
14
import java.io.FileInputStream;
15
import java.io.FileNotFoundException;
17
import junit.framework.Test;
18
import junit.framework.TestCase;
19
import junit.framework.TestSuite;
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;
36
* Contains unit test cases for Working Copies. Run using JUnit Plugin Test
37
* configuration launcher.
39
public class WorkingCopyTests extends TestCase {
40
private ICProject fCProject;
41
private IFile headerFile;
42
private NullProgressMonitor monitor;
44
public static void main(String[] args) {
45
TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), WorkingCopyTests.class, args);
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"));
55
public WorkingCopyTests(String name) {
59
protected void setUp() throws Exception {
60
monitor = new NullProgressMonitor();
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()) {
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) {
72
} catch (FileNotFoundException e) {
78
protected void tearDown() {
79
CProjectHelper.delete(fCProject);
83
public void testWorkingCopy() throws Exception {
84
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(headerFile);
87
IWorkingCopy wc = tu.getWorkingCopy();
89
assertNotNull (wc.getBuffer());
90
assertTrue (wc.exists());
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!");
98
// ReconcileWorkingCopy
102
wc.commit(true, monitor);
104
if(!tu.getBuffer().getContents().equals(wc.getBuffer().getContents()))
105
fail("Buffers should be equal at this point!");
107
// DestroyWorkingCopy
109
assertFalse(wc.exists());