- Timestamp:
- 09/22/13 23:36:58 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaElementSorter.java
r1088 r1823 42 42 package org.modelica.mdt.test; 43 43 44 import static org.junit.Assert.assertTrue; 45 import static org.junit.Assert.fail; 46 44 47 import org.eclipse.core.resources.IFile; 45 48 import org.eclipse.core.runtime.CoreException; … … 47 50 import org.eclipse.swt.widgets.Shell; 48 51 import org.eclipse.ui.model.WorkbenchLabelProvider; 52 import org.junit.Before; 53 import org.junit.Test; 49 54 import org.modelica.mdt.core.IModelicaClass; 50 import org.modelica.mdt.core.IModelicaSourceFile;51 55 import org.modelica.mdt.core.IModelicaFolder; 52 56 import org.modelica.mdt.core.IModelicaProject; 57 import org.modelica.mdt.core.IModelicaSourceFile; 53 58 import org.modelica.mdt.core.compiler.CompilerInstantiationException; 54 59 import org.modelica.mdt.core.compiler.ConnectException; … … 57 62 import org.modelica.mdt.test.util.Area51Projects; 58 63 import org.modelica.mdt.test.util.Utility; 59 //import org.modelica.mdt.ui.ModelicaElementSorter; 60 61 import static org.junit.Assert.assertTrue; 62 import static org.junit.Assert.fail; 64 import org.modelica.mdt.ui.ModelicaElementComparator; 63 65 64 66 /** … … 67 69 public class TestModelicaElementSorter { 68 70 69 /* the test subject */ 70 //private ModelicaElementSorter sorter = new ModelicaElementSorter(ModelicaElementSorter.NAME); 71 72 @org.junit.Before 73 public void setUp() throws Exception { 71 @Before 72 public void setUp() { 74 73 Area51Projects.createProjects(); 75 74 } 76 75 77 // We disable this test for now, because it wants to use functionality that has been removed from MDT. 78 //@org.junit.Test 76 @Test 79 77 public void testSorter() 80 78 throws ConnectException, UnexpectedReplyException, InvocationError, CoreException, CompilerInstantiationException { 81 79 /* 82 80 * let the sorter sort children elements of Area51 modelica project 83 * and check the order 84 */ 85 IModelicaProject proj = 86 Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME); 87 81 * and check the order 82 */ 83 IModelicaProject proj = Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME); 84 88 85 Object[] children = proj.getRootFolder().getChildren().toArray(); 89 86 90 87 /* 91 88 * we need to create a viewer and set a label provider, 92 89 * for the sorter. sorter uses label provider for sorting elements 93 * within catagory90 * within a category 94 91 */ 95 92 TreeViewer viewer = new TreeViewer(new Shell()); … … 99 96 * let the sorter do the sorting 100 97 */ 101 102 //sorter.sort(viewer, children);103 98 ModelicaElementComparator sorter = new ModelicaElementComparator(ModelicaElementComparator.MODELICA); 99 sorter.sort(viewer, children); 100 104 101 int i = 0; 105 102 int order; 106 103 String previous = null; 107 104 String current; 108 Object elm; 109 110 /* check folders catagory */ 111 for (; i < children.length; i++) 112 { 113 elm = children[i]; 114 115 if (elm instanceof IModelicaFolder && 116 !(elm instanceof IModelicaClass)) 117 { 118 current = ((IModelicaFolder)elm).getElementName(); 119 if (previous != null) 120 { 121 order = 122 String.CASE_INSENSITIVE_ORDER.compare(previous, 123 current); 124 125 assertTrue("element are not in assending order", 126 order <= 0 ); 127 } 128 previous = current; 129 } 130 else 131 { 132 /* next catagory begun */ 133 previous = null; 134 break; 135 } 136 } 137 138 /* check packages catagory */ 139 for (; i < children.length; i++) 140 { 141 elm = children[i]; 142 143 if (elm instanceof IModelicaClass) 144 { 145 current = ((IModelicaClass)elm).getElementName(); 146 if (previous != null) 147 { 148 order = 149 String.CASE_INSENSITIVE_ORDER.compare(previous, 150 current); 151 152 assertTrue("element are not in assending order", 153 order <= 0 ); 154 } 155 previous = current; 156 } 157 else if (elm instanceof IModelicaFolder) 158 { 105 106 /* check folders category */ 107 for (; i < children.length; i++) { 108 Object elm = children[i]; 109 if (elm instanceof IModelicaFolder) { 110 IModelicaFolder modelicaFolder = (IModelicaFolder)elm; 111 current = modelicaFolder.getElementName(); 112 if (previous != null) { 113 order = String.CASE_INSENSITIVE_ORDER.compare(previous, current); 114 115 assertTrue("folder elements are not in assending order", order <= 0); 116 } 117 previous = current; 118 } 119 else { 120 /* next category begun */ 121 previous = null; 122 break; 123 } 124 } 125 126 /* check packages category */ 127 for (; i < children.length; i++) { 128 Object elm = children[i]; 129 if (elm instanceof IModelicaClass) { 130 IModelicaClass modelicaClass = (IModelicaClass)elm; 131 current = modelicaClass.getElementName(); 132 if (previous != null) { 133 order = String.CASE_INSENSITIVE_ORDER.compare(previous, current); 134 135 assertTrue("class elements are not in assending order", order <= 0); 136 } 137 previous = current; 138 } 139 else if (elm instanceof IModelicaFolder) { 159 140 fail("modelica folder in the wrong place"); 160 141 } 161 162 else 163 { 164 /* next catagory begun */ 165 previous = null; 166 break; 167 } 168 } 169 142 else { 143 /* next category begun */ 144 previous = null; 145 break; 146 } 147 } 148 170 149 /* 171 150 * we don't have a class category in this test case 172 151 */ 173 174 /* check modelica files catagory */ 175 for (; i < children.length; i++) 176 { 177 elm = children[i]; 178 179 if (elm instanceof IModelicaSourceFile) 180 { 181 current = ((IModelicaSourceFile)elm).getElementName(); 182 if (previous != null) 183 { 184 order = 185 String.CASE_INSENSITIVE_ORDER.compare(previous, 186 current); 187 188 assertTrue("element are not in assending order", 189 order <= 0 ); 190 } 191 previous = current; 192 } 193 else if (elm instanceof IModelicaFolder) 194 { 152 153 /* check modelica files category */ 154 for (; i < children.length; i++) { 155 Object elm = children[i]; 156 if (elm instanceof IModelicaSourceFile) { 157 IModelicaSourceFile modelicaSourceFile = (IModelicaSourceFile)elm; 158 current = modelicaSourceFile.getElementName(); 159 if (previous != null) { 160 order = String.CASE_INSENSITIVE_ORDER.compare(previous, current); 161 162 assertTrue("sourcefile elements are not in assending order", order <= 0); 163 } 164 previous = current; 165 } 166 else if (elm instanceof IModelicaFolder) { 195 167 fail("modelica folder/package in the wrong place"); 196 168 } 197 else if (elm instanceof IModelicaClass) 198 { 169 else if (elm instanceof IModelicaClass) { 199 170 fail("modelica class in the wrong place"); 200 171 } 201 else 202 { 203 /* next catagory begun */ 204 previous = null; 205 break; 206 } 207 } 208 209 /* check plain files catagory */ 210 for (; i < children.length; i++) 211 { 212 elm = children[i]; 213 214 if (elm instanceof IFile) 215 { 216 current = ((IFile)elm).getName(); 217 if (previous != null) 218 { 219 order = 220 String.CASE_INSENSITIVE_ORDER.compare(previous, 221 current); 222 223 assertTrue("element are not in assending order", 224 order <= 0 ); 225 } 226 previous = current; 227 } 228 else if (elm instanceof IModelicaFolder) 229 { 172 else { 173 /* next category begun */ 174 previous = null; 175 break; 176 } 177 } 178 179 /* check plain files category */ 180 for (; i < children.length; i++) { 181 Object elm = children[i]; 182 if (elm instanceof IFile) { 183 IFile file = (IFile)elm; 184 current = file.getName(); 185 if (previous != null) { 186 order = String.CASE_INSENSITIVE_ORDER.compare(previous, current); 187 188 assertTrue("file elements are not in assending order", order <= 0); 189 } 190 previous = current; 191 } 192 else if (elm instanceof IModelicaFolder) { 230 193 fail("modelica folder/package in the wrong place"); 231 194 } 232 else if (elm instanceof IModelicaClass) 233 { 195 else if (elm instanceof IModelicaClass) { 234 196 fail("modelica class in the wrong place"); 235 197 } 236 else if (elm instanceof IModelicaSourceFile) 237 { 198 else if (elm instanceof IModelicaSourceFile) { 238 199 fail("modelica class in the wrong place"); 239 200 } 240 else 241 { 242 /* next catagory begun */ 243 previous = null; 244 break; 245 } 246 } 247 248 /* 249 * we don't have a system library catagory in this test case 201 else { 202 /* next category begun */ 203 previous = null; 204 break; 205 } 206 } 207 208 /* 209 * we don't have a system library category in this test case 250 210 */ 251 211 }
Note: See TracChangeset
for help on using the changeset viewer.