Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 204452 Details for
Bug 347557
[Edit] NPE when saving a file in a compare editor (always)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Tests that don't fail
patch_347557_tests.txt (text/plain), 11.32 KB, created by
Malgorzata Janczarska
on 2011-10-03 11:38:47 EDT
(
hide
)
Description:
Tests that don't fail
Filename:
MIME Type:
Creator:
Malgorzata Janczarska
Created:
2011-10-03 11:38:47 EDT
Size:
11.32 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare.tests >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare.tests/META-INF/MANIFEST.MF,v >retrieving revision 1.6 >diff -u -r1.6 MANIFEST.MF >--- META-INF/MANIFEST.MF 18 Jul 2011 09:59:01 -0000 1.6 >+++ META-INF/MANIFEST.MF 3 Oct 2011 15:28:40 -0000 >@@ -14,7 +14,8 @@ > org.eclipse.core.resources, > org.eclipse.core.tests.resources, > org.eclipse.core.tests.harness, >- org.eclipse.core.filesystem >+ org.eclipse.core.filesystem, >+ org.eclipse.team.ui > Bundle-Activator: org.eclipse.compare.tests.CompareTestPlugin > Bundle-ActivationPolicy: lazy > Bundle-Vendor: %providerName >Index: src/org/eclipse/compare/tests/SaveableCompareEditorInputTest.java >=================================================================== >RCS file: src/org/eclipse/compare/tests/SaveableCompareEditorInputTest.java >diff -N src/org/eclipse/compare/tests/SaveableCompareEditorInputTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/tests/SaveableCompareEditorInputTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,330 @@ >+/******************************************************************************* >+ * Copyright (c) 2011, 2011 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.compare.tests; >+ >+import java.io.BufferedReader; >+import java.io.ByteArrayInputStream; >+import java.io.IOException; >+import java.io.InputStreamReader; >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.List; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.compare.CompareConfiguration; >+import org.eclipse.compare.ITypedElement; >+import org.eclipse.compare.contentmergeviewer.TextMergeViewer; >+import org.eclipse.compare.internal.MergeSourceViewer; >+import org.eclipse.compare.structuremergeviewer.Differencer; >+import org.eclipse.compare.structuremergeviewer.ICompareInput; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.team.internal.ui.mapping.AbstractCompareInput; >+import org.eclipse.team.internal.ui.mapping.CompareInputChangeNotifier; >+import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; >+import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.PlatformUI; >+ >+public class SaveableCompareEditorInputTest extends TestCase { >+ >+ private class FileElement implements ITypedElement { >+ >+ private IFile file; >+ >+ public IFile getFile() { >+ return file; >+ } >+ >+ public FileElement(IFile file) { >+ super(); >+ this.file = file; >+ } >+ >+ public String getName() { >+ return file.getName(); >+ } >+ >+ public Image getImage() { >+ return null; >+ } >+ >+ public String getType() { >+ return TEXT_TYPE; >+ } >+ >+ } >+ >+ public class TestDiffNode extends AbstractCompareInput { >+ >+ private CompareInputChangeNotifier notifier = new CompareInputChangeNotifier() { >+ >+ private IResource getResource(ITypedElement el) { >+ if (el instanceof LocalResourceTypedElement) { >+ return ((LocalResourceTypedElement) el).getResource(); >+ } >+ if (el instanceof FileElement) { >+ return ((FileElement) el).getFile(); >+ } >+ return null; >+ } >+ >+ protected IResource[] getResources(ICompareInput input) { >+ >+ List resources = new ArrayList(); >+ if (getResource(getLeft()) != null) { >+ resources.add(getResource(getLeft())); >+ } >+ if (getResource(getRight()) != null) { >+ resources.add(getResource(getRight())); >+ } >+ >+ return (IResource[]) resources.toArray(new IResource[2]); >+ } >+ }; >+ >+ public TestDiffNode(ITypedElement left, ITypedElement right) { >+ super(Differencer.CHANGE, null, left, right); >+ } >+ >+ public void fireChange() { >+ super.fireChange(); >+ } >+ >+ protected CompareInputChangeNotifier getChangeNotifier() { >+ return notifier; >+ } >+ >+ public boolean needsUpdate() { >+ // The remote never changes >+ return false; >+ } >+ >+ public void update() { >+ fireChange(); >+ } >+ } >+ >+ private class TestSaveableEditorInputLocal extends >+ SaveableCompareEditorInput { >+ >+ protected ITypedElement left; >+ protected ITypedElement right; >+ private ICompareInput input; >+ >+ public Object getCompareResult() { >+ return input; >+ } >+ >+ public TestSaveableEditorInputLocal(ITypedElement left, >+ ITypedElement right, CompareConfiguration conf) { >+ super(conf, PlatformUI.getWorkbench().getActiveWorkbenchWindow() >+ .getActivePage()); >+ this.left = left; >+ this.right = right; >+ } >+ >+ protected ICompareInput prepareCompareInput(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ input = createCompareInput(); >+ getCompareConfiguration().setLeftEditable(true); >+ getCompareConfiguration().setRightEditable(false); >+ return null; >+ } >+ >+ private ICompareInput createCompareInput() { >+ return new TestDiffNode(left, right); >+ } >+ >+ protected void fireInputChange() { >+ ((TestDiffNode) getCompareResult()).fireChange(); >+ >+ } >+ >+ public void saveChanges(IProgressMonitor monitor) throws CoreException { >+ super.saveChanges(monitor); >+ } >+ >+ } >+ >+ private TextMergeViewer viewer; >+ >+ public void testDirtyFlagOnStandardLeft() throws CoreException, >+ InvocationTargetException, InterruptedException, >+ IllegalArgumentException, SecurityException, >+ IllegalAccessException, NoSuchFieldException, >+ NoSuchMethodException, IOException { >+ IProject project = ResourcesPlugin.getWorkspace().getRoot() >+ .getProject("Project_" + System.currentTimeMillis()); >+ project.create(null); >+ project.open(null); >+ >+ String fileContents1 = "FileContents"; >+ String appendFileContents = "_append"; >+ String fileContents2 = "FileContents2"; >+ >+ IFile file1 = project.getFile("File1_" + System.currentTimeMillis() >+ + ".txt"); >+ file1.create(new ByteArrayInputStream(fileContents1.getBytes()), true, >+ null); >+ >+ IFile file2 = project.getFile("File2_" + System.currentTimeMillis() >+ + ".txt"); >+ file2.create(new ByteArrayInputStream(fileContents2.getBytes()), true, >+ null); >+ >+ LocalResourceTypedElement el1 = (LocalResourceTypedElement) SaveableCompareEditorInput >+ .createFileElement(file1); >+ ITypedElement el2 = new FileElement(file2); >+ >+ IWorkbenchPage page = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow().getActivePage(); >+ >+ CompareConfiguration conf = new CompareConfiguration(); >+ conf.setLeftEditable(true); >+ TestSaveableEditorInputLocal compareEditorInput = new TestSaveableEditorInputLocal( >+ el1, el2, conf); >+ >+ final TestSaveableEditorInputLocal[] editorInputs = { compareEditorInput }; >+ compareEditorInput.prepareCompareInput(null); >+ >+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() >+ .getShell(); >+ >+ Dialog dialog = new Dialog(shell) { >+ protected Control createDialogArea(Composite parent) { >+ Composite composite = (Composite) super >+ .createDialogArea(parent); >+ viewer = (TextMergeViewer) editorInputs[0].findContentViewer( >+ null, editorInputs[0].input, composite); >+ viewer.setInput(editorInputs[0].getCompareResult()); >+ return composite; >+ } >+ }; >+ dialog.setBlockOnOpen(false); >+ dialog.open(); >+ >+ MergeSourceViewer left = (MergeSourceViewer) ReflectionUtils.getField( >+ viewer, "fLeft"); >+ >+ StyledText leftText = left.getSourceViewer().getTextWidget(); >+ >+ // modify the left side of editor >+ leftText.append(appendFileContents); >+ >+ assertTrue(compareEditorInput.isDirty()); >+ >+ // save editor >+ viewer.flush(null); >+ >+ assertFalse(compareEditorInput.isDirty()); >+ >+ dialog.close(); >+ >+ // check weather file was saved >+ >+ BufferedReader reader = new BufferedReader(new InputStreamReader( >+ file1.getContents())); >+ String line = reader.readLine(); >+ >+ assertEquals(fileContents1 + appendFileContents, line); >+ >+ } >+ >+ >+ public void testDirtyFlagOnCustomLeft() throws CoreException, >+ InvocationTargetException, InterruptedException, >+ IllegalArgumentException, SecurityException, >+ IllegalAccessException, NoSuchFieldException, >+ NoSuchMethodException, IOException { >+ IProject project = ResourcesPlugin.getWorkspace().getRoot() >+ .getProject("Project_" + System.currentTimeMillis()); >+ project.create(null); >+ project.open(null); >+ >+ String fileContents1 = "FileContents"; >+ String appendFileContents = "_append"; >+ String fileContents2 = "FileContents2"; >+ >+ IFile file1 = project.getFile("File1_" + System.currentTimeMillis() >+ + ".txt"); >+ file1.create(new ByteArrayInputStream(fileContents1.getBytes()), true, >+ null); >+ >+ IFile file2 = project.getFile("File2_" + System.currentTimeMillis() >+ + ".txt"); >+ file2.create(new ByteArrayInputStream(fileContents2.getBytes()), true, >+ null); >+ >+ ITypedElement el1 = new FileElement(file1); >+ ITypedElement el2 = new FileElement(file2); >+ >+ IWorkbenchPage page = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow().getActivePage(); >+ >+ CompareConfiguration conf = new CompareConfiguration(); >+ conf.setLeftEditable(true); >+ TestSaveableEditorInputLocal compareEditorInput = new TestSaveableEditorInputLocal( >+ el1, el2, conf); >+ >+ final TestSaveableEditorInputLocal[] editorInputs = { compareEditorInput }; >+ compareEditorInput.prepareCompareInput(null); >+ >+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() >+ .getShell(); >+ >+ Dialog dialog = new Dialog(shell) { >+ protected Control createDialogArea(Composite parent) { >+ Composite composite = (Composite) super >+ .createDialogArea(parent); >+ viewer = (TextMergeViewer) editorInputs[0].findContentViewer( >+ null, editorInputs[0].input, composite); >+ viewer.setInput(editorInputs[0].getCompareResult()); >+ return composite; >+ } >+ }; >+ dialog.setBlockOnOpen(false); >+ dialog.open(); >+ >+ MergeSourceViewer left = (MergeSourceViewer) ReflectionUtils.getField( >+ viewer, "fLeft"); >+ >+ StyledText leftText = left.getSourceViewer().getTextWidget(); >+ >+ leftText.append(appendFileContents); >+ >+ assertTrue(compareEditorInput.isDirty()); >+ >+ viewer.flush(null); >+ >+ assertFalse(compareEditorInput.isDirty()); >+ >+ dialog.close(); >+ >+ /* >+ * not checking if changes were saved because in this case saving is not >+ * handled >+ */ >+ >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 347557
:
201902
|
201906
|
204202
|
204452
|
204457
|
204502
|
204754
|
204957
|
205359
|
205361
|
205407
|
205708