View | Details | Raw Unified | Return to bug 294650 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/tests/ccvs/ui/PatchTreeTest.java (+152 lines)
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.team.tests.ccvs.ui;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.jface.util.IPropertyChangeListener;
15
import org.eclipse.jface.util.PropertyChangeEvent;
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.jface.viewers.ViewerSorter;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Item;
21
import org.eclipse.swt.widgets.Widget;
22
import org.eclipse.team.core.TeamException;
23
import org.eclipse.team.core.synchronize.SyncInfoSet;
24
import org.eclipse.team.internal.ccvs.core.mapping.CVSActiveChangeSet;
25
import org.eclipse.team.internal.ui.synchronize.ChangeSetCapability;
26
import org.eclipse.team.internal.ui.synchronize.ChangeSetDiffNode;
27
import org.eclipse.team.internal.ui.synchronize.ChangeSetModelProvider;
28
import org.eclipse.team.internal.ui.synchronize.ChangeSetModelSorter;
29
import org.eclipse.team.internal.ui.synchronize.SynchronizeModelElementSorter;
30
import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration;
31
import org.eclipse.team.internal.ui.synchronize.TreeViewerAdvisor;
32
import org.eclipse.team.internal.ui.synchronize.UnchangedResourceModelElement;
33
import org.eclipse.team.tests.ccvs.core.EclipseTest;
34
import org.eclipse.team.ui.synchronize.ISynchronizePage;
35
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
36
import org.eclipse.team.ui.synchronize.ISynchronizePageSite;
37
import org.eclipse.ui.PartInitException;
38
import org.eclipse.ui.PlatformUI;
39
40
public class PatchTreeTest extends EclipseTest {
41
	
42
	private SynchronizePageConfiguration getMyConfiguration(final Viewer viewer){
43
		SynchronizePageConfiguration conf = new SynchronizePageConfiguration(null);
44
		conf.setPage(new ISynchronizePage() {
45
			
46
			public void init(ISynchronizePageSite site) throws PartInitException {}
47
			
48
			public Viewer getViewer() {
49
				return viewer;
50
			}
51
			
52
			public boolean aboutToChangeProperty(
53
					ISynchronizePageConfiguration configuration, String key,
54
					Object newValue) {return false;}
55
		});
56
		return conf;
57
	}	
58
	
59
	private class MyModelProvider extends ChangeSetModelProvider implements IPropertyChangeListener{
60
61
		public ChangeSetCapability getChangeSetCapability() {
62
			return new ChangeSetCapability() {
63
			};
64
		}
65
66
		public MyModelProvider(final Viewer viewer) {
67
			super(getMyConfiguration(viewer), new SyncInfoSet(), "sampleProviderId");
68
			addPropertyChangeListener(this);
69
		}
70
71
		public void propertyChange(PropertyChangeEvent event) {
72
			// nothing to do
73
		}
74
		
75
	}
76
	
77
	private class MyTreeViewer extends TreeViewerAdvisor.NavigableCheckboxTreeViewer {
78
79
		public MyTreeViewer(Composite parent, int style) {
80
			super(parent, style);
81
		}
82
		
83
		public void testInternalAdd(Object[] childElements){
84
			internalAdd(this.getTree(), null, childElements);
85
		}
86
		
87
		public Item[] testGetChildren(Widget widget){
88
			return this.getChildren(widget);
89
		}
90
		
91
		public void init(){
92
			ChangeSetModelProvider provider = new MyModelProvider(this); 
93
			provider.setViewerSorter(new SynchronizeModelElementSorter());
94
			ChangeSetModelSorter sorter = new ChangeSetModelSorter(provider, 0);
95
			
96
			
97
			setSorter(sorter);
98
		}
99
	}
100
	
101
	public void testChangeSetModelSorter() throws CoreException{
102
		MyTreeViewer tree = new MyTreeViewer(new Composite(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 0)
103
		, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
104
		tree.init();
105
		ViewerSorter sorter = tree.getSorter();
106
		
107
		UnchangedResourceModelElement element = new UnchangedResourceModelElement(null, getUniqueTestProject("z"));
108
		ChangeSetDiffNode nodeA = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "a"));
109
		ChangeSetDiffNode nodeB = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "b"));
110
		ChangeSetDiffNode nodeC = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "c"));
111
		Object[] elements = {nodeB, nodeC, element, nodeA};
112
		
113
		sorter.sort(tree, elements);
114
		
115
		Object firstElement = elements[0];
116
		for(int i=0; i<elements.length; i++){
117
			assertTrue("Comparator not transistant, element " + firstElement + " should be smaller than " + elements[i], sorter.compare(tree, firstElement, elements[i])<=0);
118
		}
119
		
120
	}
121
122
	public void testDuplicatedElementsInPatchTree() throws TeamException, CoreException {
123
		MyTreeViewer tree = new MyTreeViewer(new Composite(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 0)
124
				, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
125
		tree.init();
126
		
127
		
128
		UnchangedResourceModelElement element = new UnchangedResourceModelElement(null, getUniqueTestProject("z"));
129
		ChangeSetDiffNode nodeA = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "a"));
130
		ChangeSetDiffNode nodeB = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "b"));
131
		ChangeSetDiffNode nodeC = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "c"));
132
		ChangeSetDiffNode nodeD = new ChangeSetDiffNode(null, new CVSActiveChangeSet(null, "d"));
133
		
134
		Object children[] = {nodeC, nodeB, element, nodeA};
135
		tree.testInternalAdd(children);
136
		Item[] treeChildren = tree.testGetChildren(tree.getTree());
137
138
		
139
		Object children1[] = {nodeD, element, nodeA, nodeB};
140
		tree.testInternalAdd(children1);
141
		treeChildren = tree.testGetChildren(tree.getTree());
142
143
		for(int i=0; i<treeChildren.length-1; i++){
144
			Object tmpElement = treeChildren[i].getData();
145
			for(int j=i+1; j<treeChildren.length; j++){
146
				assertNotSame("Duplicated element in tree " + tmpElement, tmpElement, treeChildren[j].getData());
147
			}
148
		}
149
150
	}
151
152
}

Return to bug 294650