Changeset 1823 for trunk


Ignore:
Timestamp:
09/22/13 23:36:58 (11 years ago)
Author:
masberg
Message:

This test was disabled because it had suffered severe bit-rot. Update test to use new sorting APIs. Formatting fixes. Fix typos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaElementSorter.java

    r1088 r1823  
    4242package org.modelica.mdt.test;
    4343
     44import static org.junit.Assert.assertTrue;
     45import static org.junit.Assert.fail;
     46
    4447import org.eclipse.core.resources.IFile;
    4548import org.eclipse.core.runtime.CoreException;
     
    4750import org.eclipse.swt.widgets.Shell;
    4851import org.eclipse.ui.model.WorkbenchLabelProvider;
     52import org.junit.Before;
     53import org.junit.Test;
    4954import org.modelica.mdt.core.IModelicaClass;
    50 import org.modelica.mdt.core.IModelicaSourceFile;
    5155import org.modelica.mdt.core.IModelicaFolder;
    5256import org.modelica.mdt.core.IModelicaProject;
     57import org.modelica.mdt.core.IModelicaSourceFile;
    5358import org.modelica.mdt.core.compiler.CompilerInstantiationException;
    5459import org.modelica.mdt.core.compiler.ConnectException;
     
    5762import org.modelica.mdt.test.util.Area51Projects;
    5863import 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;
     64import org.modelica.mdt.ui.ModelicaElementComparator;
    6365
    6466/**
     
    6769public class TestModelicaElementSorter {
    6870
    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() {
    7473        Area51Projects.createProjects();
    7574    }
    7675
    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
    7977    public void testSorter()
    8078        throws ConnectException, UnexpectedReplyException, InvocationError, CoreException, CompilerInstantiationException {
    8179        /*
    8280         * 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
    8885        Object[] children = proj.getRootFolder().getChildren().toArray();
    89        
     86
    9087        /*
    9188         * we need to create a viewer and set a label provider,
    9289         * for the sorter. sorter uses label provider for sorting elements
    93          * within catagory
     90         * within a category
    9491         */
    9592        TreeViewer viewer = new TreeViewer(new Shell());
     
    9996         * let the sorter do the sorting
    10097         */
    101          
    102         //sorter.sort(viewer, children);
    103        
     98        ModelicaElementComparator sorter = new ModelicaElementComparator(ModelicaElementComparator.MODELICA);
     99        sorter.sort(viewer, children);
     100
    104101        int i = 0;
    105102        int order;
    106103        String previous = null;
    107104        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) {
    159140                fail("modelica folder in the wrong place");
    160141            }
    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
    170149        /*
    171150         * we don't have a class category in this test case
    172151         */
    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) {
    195167                fail("modelica folder/package in the wrong place");
    196168            }
    197             else if (elm instanceof IModelicaClass)
    198             {
     169            else if (elm instanceof IModelicaClass) {
    199170                fail("modelica class in the wrong place");
    200171            }
    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) {
    230193                fail("modelica folder/package in the wrong place");
    231194            }
    232             else if (elm instanceof IModelicaClass)
    233             {
     195            else if (elm instanceof IModelicaClass) {
    234196                fail("modelica class in the wrong place");
    235197            }
    236             else if (elm instanceof IModelicaSourceFile)
    237             {
     198            else if (elm instanceof IModelicaSourceFile) {
    238199                fail("modelica class in the wrong place");
    239200            }
    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
    250210         */
    251211    }
Note: See TracChangeset for help on using the changeset viewer.