|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011 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 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.compare.tests; |
| 12 |
|
| 13 |
import java.io.ByteArrayInputStream; |
| 14 |
import java.io.InputStream; |
| 15 |
|
| 16 |
import junit.framework.TestCase; |
| 17 |
|
| 18 |
import org.eclipse.compare.CompareConfiguration; |
| 19 |
import org.eclipse.compare.IStreamContentAccessor; |
| 20 |
import org.eclipse.compare.ITypedElement; |
| 21 |
import org.eclipse.compare.internal.CompareUIPlugin; |
| 22 |
import org.eclipse.compare.internal.ViewerDescriptor; |
| 23 |
import org.eclipse.compare.structuremergeviewer.DiffNode; |
| 24 |
import org.eclipse.core.runtime.CoreException; |
| 25 |
import org.eclipse.swt.graphics.Image; |
| 26 |
|
| 27 |
public class CompareUIPluginTest extends TestCase { |
| 28 |
|
| 29 |
private static class UnknownTypedElement implements ITypedElement { |
| 30 |
public Image getImage() { |
| 31 |
return null; |
| 32 |
} |
| 33 |
|
| 34 |
public String getName() { |
| 35 |
return "test"; |
| 36 |
} |
| 37 |
|
| 38 |
public String getType() { |
| 39 |
return UNKNOWN_TYPE; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
private static class TextTypedElement implements ITypedElement { |
| 44 |
public Image getImage() { |
| 45 |
return null; |
| 46 |
} |
| 47 |
|
| 48 |
public String getName() { |
| 49 |
return "test"; |
| 50 |
} |
| 51 |
|
| 52 |
public String getType() { |
| 53 |
return TEXT_TYPE; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
private static class TextTypedElementStreamAccessor implements ITypedElement, IStreamContentAccessor { |
| 58 |
public Image getImage() { |
| 59 |
return null; |
| 60 |
} |
| 61 |
|
| 62 |
public String getName() { |
| 63 |
return "test"; |
| 64 |
} |
| 65 |
|
| 66 |
public String getType() { |
| 67 |
return TEXT_TYPE; |
| 68 |
} |
| 69 |
|
| 70 |
public InputStream getContents() throws CoreException { |
| 71 |
/* |
| 72 |
* Whatever we return has no importance as long as it is not "null", this is only to make |
| 73 |
* CompareUIPlugin#guessType happy. However, it is only happy if what we return resembles a text. |
| 74 |
*/ |
| 75 |
return new ByteArrayInputStream(new byte[] {' '}); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
public void testFindContentViewerDescriptor_UnknownType() { |
| 80 |
CompareConfiguration cc = new CompareConfiguration(); |
| 81 |
DiffNode in = new DiffNode(new UnknownTypedElement(), new UnknownTypedElement()); |
| 82 |
ViewerDescriptor[] result = CompareUIPlugin.getDefault().findContentViewerDescriptor(null, in, cc); |
| 83 |
|
| 84 |
// API Compatibility : "no descriptor found" should return a null array instead of a 0-lengthed one. |
| 85 |
assertNull(result); |
| 86 |
} |
| 87 |
|
| 88 |
public void testFindContentViewerDescriptor_TextType_NotStreamAccessor() { |
| 89 |
CompareConfiguration cc = new CompareConfiguration(); |
| 90 |
DiffNode in = new DiffNode(new TextTypedElement(), new TextTypedElement()); |
| 91 |
ViewerDescriptor[] result = CompareUIPlugin.getDefault().findContentViewerDescriptor(null, in, cc); |
| 92 |
|
| 93 |
/* |
| 94 |
* "TextTypedElement" is "text" typed : it thus has a Content Viewer attached. However, this content |
| 95 |
* viewer is currently NOT returned because of bug 293926 |
| 96 |
*/ |
| 97 |
assertNotNull(result); |
| 98 |
assertEquals(1, result.length); |
| 99 |
} |
| 100 |
|
| 101 |
public void testFindContentViewerDescriptorForTextType_StreamAccessor() { |
| 102 |
CompareConfiguration cc = new CompareConfiguration(); |
| 103 |
DiffNode in = new DiffNode(new TextTypedElementStreamAccessor(), new TextTypedElementStreamAccessor()); |
| 104 |
ViewerDescriptor[] result = CompareUIPlugin.getDefault().findContentViewerDescriptor(null, in, cc); |
| 105 |
|
| 106 |
/* |
| 107 |
* "TextTypedElement" is "text" typed : it thus has a Content Viewer attached. However, the content |
| 108 |
* viewer will only be returned because we made our "ITypedElement" be an IStreamContentAccessor. |
| 109 |
*/ |
| 110 |
assertNotNull(result); |
| 111 |
assertEquals(1, result.length); |
| 112 |
} |
| 113 |
} |