From da490cbd0083a23dbf034461eca9b86b10752baf Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Wed, 19 Mar 2003 20:37:16 +0000 Subject: [PATCH] Patch from Amer Hoda, to test the Core model working copy --- .../core/model/tests/WorkingCopyTests.java | 106 ++++++++++++++++++ .../resources/cfiles/WorkingCopyTestStart.h | 1 + 2 files changed, 107 insertions(+) create mode 100644 core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java create mode 100644 core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/resources/cfiles/WorkingCopyTestStart.h diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java new file mode 100644 index 00000000000..f2725bcaf76 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java @@ -0,0 +1,106 @@ +package org.eclipse.cdt.core.model.tests; +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * Rational Software - Initial API and implementation +***********************************************************************/ + + +import java.io.FileInputStream; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.core.model.IBuffer; +import org.eclipse.cdt.internal.core.model.IWorkingCopy; +import org.eclipse.cdt.internal.core.model.TranslationUnit; +import org.eclipse.cdt.testplugin.CProjectHelper; +import org.eclipse.cdt.testplugin.TestPluginLauncher; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + +/** + * Contains unit test cases for Working Copies. Run using JUnit Plugin Test + * configuration launcher. + */ +public class WorkingCopyTests extends TestCase { + private ICProject fCProject; + private IFile headerFile; + private NullProgressMonitor monitor; + + public static void main(String[] args) { + TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), WorkingCopyTests.class, args); + } + + public static Test suite() { + TestSuite suite= new TestSuite(); + suite.addTest(new WorkingCopyTests("testWorkingCopy")); + //suite.addTest(new WorkingCopyTests("testHashing")); + return suite; + } + + public WorkingCopyTests(String name) { + super(name); + } + + protected void setUp() throws Exception { + monitor = new NullProgressMonitor(); + String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile(); + + fCProject= CProjectHelper.createCProject("TestProject1", "bin"); + //Path filePath = new Path(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()+ fCProject.getPath().toString()+ "/WorkingCopyTest.h"); + headerFile = fCProject.getProject().getFile("WorkingCopyTest.h"); + if (!headerFile.exists()) { + try{ + FileInputStream fileIn = new FileInputStream(pluginRoot+ "model/org/eclipse/cdt/core/model/tests/resources/cfiles/WorkingCopyTestStart.h"); + headerFile.create(fileIn,false, monitor); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + protected void tearDown() throws Exception { + CProjectHelper.delete(fCProject); + } + + + public void testWorkingCopy() throws Exception { + ITranslationUnit tu = new TranslationUnit(fCProject, headerFile); + // CreateWorkingCopy + assertNotNull (tu); + IWorkingCopy wc = tu.getWorkingCopy(); + assertNotNull (wc); + assertNotNull (wc.getBuffer()); + assertTrue (wc.exists()); + + // ModifyWorkingCopy + IBuffer wcBuf = wc.getBuffer(); + wcBuf.append("\n class Hello{ int x; };"); + if (tu.getBuffer().getContents().equals(wc.getBuffer().getContents() ) ) + fail("Buffers should NOT be equal at this point!"); + + // ReconcileWorkingCopy + wc.reconcile(); + + // CommitWorkingCopy + wc.commit(true, monitor); + + if(!tu.getBuffer().getContents().equals(wc.getBuffer().getContents())) + fail("Buffers should be equal at this point!"); + + // DestroyWorkingCopy + wc.destroy(); + assertFalse(wc.exists()); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/resources/cfiles/WorkingCopyTestStart.h b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/resources/cfiles/WorkingCopyTestStart.h new file mode 100644 index 00000000000..a22241fbcf1 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/resources/cfiles/WorkingCopyTestStart.h @@ -0,0 +1 @@ +#include