Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0f5872f51b4cde7a47eb2e50ee1ea15f8389644f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*****************************************************************************
 * Copyright (c) 2009 CEA LIST & LIFL 
 *
 *    
 * 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:
 *  Cedric Dumoulin  Cedric.dumoulin@lifl.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider;
import org.eclipse.swt.SWT;


/**
 * @author dumoulin
 */
public class SimpleSashWindowsContentProviderTest extends TestCase {

	protected SimpleSashWindowsContentProvider contentProvider;

	/**
	 * Initialize the tree {@inheritDoc}
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		createContentProvider();
	}

	/**
	 * Create a tree
	 */
	private void createContentProvider() {
		contentProvider = new SimpleSashWindowsContentProvider();
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#addPage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel)}
	 * .
	 */
	public void testAddTabIPageModel() {
		IPageModel newModel = new FakePageModel();
		contentProvider.addPage(newModel);

		assertTrue("Folder contains added item", contentProvider.getCurrentTabFolder().getChildren().contains(newModel));
	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#movePage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, int)}
	 * .
	 */
	//	public void testMoveTabITabFolderModelIntInt() {
	//		fail("Not yet implemented");
	//	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#movePage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int)}
	 * .
	 */
	//	public void testMoveTabITabFolderModelIntITabFolderModelInt() {
	//		fail("Not yet implemented");
	//	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#createFolder(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int)}
	 * .
	 */
	public void testCreateFolder() {

		// Create pages and add them to the default folder
		List<IPageModel> models = new ArrayList<IPageModel>();
		for(int i = 0; i < 8; i++) {
			IPageModel newModel = new FakePageModel("model" + i);
			contentProvider.addPage(newModel);
			models.add(newModel);
		}

		ITabFolderModel folder = contentProvider.getCurrentTabFolder();

		//		// Do move tab 0 to right
		//		ITabFolderModel newFolder = contentProvider.createFolder(folder, 0, folder, SWT.RIGHT);
		//		// Check creation
		//		assertNotNull("Folder created", newFolder);
		//		// Check if correctly attached and reachable
		//		assertEquals("Tab 2 added in correct folder", folder, contentProvider.getParentFolder(newModel2));
		//		assertEquals("Tab 1 added in correct folder", newFolder, contentProvider.getParentFolder(newModel1));
		//		
		////		assertNotNull("folder attached", contentProvider.getParentFolder(newModel1));
		////		assertNotNull("folder attached", contentProvider.getParentFolder(newModel1));
		//		
		//		assertTrue("Folder contains added item", newFolder.getChildren().contains(newModel1));
		//		assertTrue("Folder contains added item", folder.getChildren().contains(newModel2));


		// 
		// Create another folder
		int index = 0;
		IPageModel movedTab = models.get(index++);
		assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
		contentProvider.createFolder(folder, 0, folder, SWT.UP);
		// Find created folder
		ITabFolderModel newFolder2 = contentProvider.getParentFolder(movedTab);
		assertFolderCreated(folder, newFolder2, movedTab);

		movedTab = models.get(index++);
		assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
		contentProvider.createFolder(folder, 0, newFolder2, SWT.UP);
		ITabFolderModel newFolder3 = contentProvider.getParentFolder(movedTab);
		assertFolderCreated(folder, newFolder3, movedTab);

		movedTab = models.get(index++);
		assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
		contentProvider.createFolder(folder, 0, newFolder2, SWT.DOWN);
		ITabFolderModel newFolder4 = contentProvider.getParentFolder(movedTab);
		assertFolderCreated(folder, newFolder4, movedTab);

		movedTab = models.get(index++);
		assertEquals("moved tab is the first in tab", movedTab, folder.getChildren().get(0));
		contentProvider.createFolder(folder, 0, folder, SWT.LEFT);
		ITabFolderModel newFolder5 = contentProvider.getParentFolder(movedTab);
		assertFolderCreated(folder, newFolder5, movedTab);

	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#createFolder(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int, org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel, int)}
	 * .
	 */
	public void testCreateFolder_ITabFolderModel_int() {

		// Create pages and add them to the default folder
		List<IPageModel> models = new ArrayList<IPageModel>();
		for(int i = 0; i < 8; i++) {
			IPageModel newModel = new FakePageModel("model" + i);
			contentProvider.addPage(newModel);
			models.add(newModel);
		}

		ITabFolderModel referenceFolder = contentProvider.getCurrentTabFolder();

		assertNotNull("referenceFolder exist", referenceFolder);
		
		// Create a new folder.
		ITabFolderModel createdFolder = contentProvider.createFolder(referenceFolder, SWT.TOP);
		
		assertNotNull("folder created", createdFolder);
		
	}

	/**
	 * Assert folder is correctly created
	 * 
	 * @param srcFolder
	 * @param newFolder
	 * @param movedTab
	 */
	protected void assertFolderCreated(ITabFolderModel srcFolder, ITabFolderModel newFolder, IPageModel movedTab) {
		// Check creation
		assertNotNull("Folder exist", newFolder);

		// Check if it is really a new folder
		assertNotSame("Old folder and new folder are differents", srcFolder, newFolder);

		// Check removed from source
		assertFalse("item removed from source folder", srcFolder.getChildren().contains(movedTab));
		// Check contained in created folder
		assertTrue("Folder contains added item", newFolder.getChildren().contains(movedTab));
	}
	/**
	 * Test method for {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#removePage(int)}.
	 */
	//	public void testRemoveTabInt() {
	//		fail("Not yet implemented");
	//	}

	/**
	 * Test method for
	 * {@link org.eclipse.papyrus.infra.core.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider#removePage(org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel)}
	 * .
	 */
	//	public void testRemoveTabIPageModel() {
	//		fail("Not yet implemented");
	//	}

}

Back to the top