Ignore:
Timestamp:
05/30/08 10:14:43 (16 years ago)
Author:
ra33
Message:

Added some more unit tests
Did a bunch of refactoring
AND added a few new features... @b @v were the most significant

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r78 r80  
    88import java.util.ArrayList;
    99import java.util.Collection;
     10import java.util.HashMap;
    1011import java.util.LinkedList;
    1112import java.util.List;
     13import java.util.Map;
    1214import java.util.Random;
    1315
     
    6365        private static final String DEFAULT_FRAME = "$fp.";
    6466
     67        private static final String DEFAULT_ASSOCIATION = "$ap.";
     68
    6569        private static final String EXIT_TEXT = "exitall";
    6670
     
    121125                List<String> actions = new ArrayList<String>();
    122126                actions.add(RUN_FRAME_ACTION);
    123                 newSimpleTest.getTitle().setActions(actions);
     127                newSimpleTest.getTitleItem().setActions(actions);
    124128                FrameUtils.DisplayFrame(newSimpleTest, true);
    125129                FrameGraphics.DisplayMessage("New test created");
     
    131135                        next = FrameIO.LoadNext(next);
    132136                } while (next != null
    133                                 && (next.getTitle() == null || !RUN_FRAME_ACTION
    134                                                 .equalsIgnoreCase(next.getTitle().getFirstAction())));
     137                                && (next.getTitleItem() == null || !RUN_FRAME_ACTION
     138                                                .equalsIgnoreCase(next.getTitleItem().getFirstAction())));
    135139                FrameUtils.DisplayFrame(next, true);
    136140        }
     
    141145                        prev = FrameIO.LoadPrevious(prev);
    142146                } while (prev != null
    143                                 && (prev.getTitle() == null || !RUN_FRAME_ACTION
    144                                                 .equalsIgnoreCase(prev.getTitle().getFirstAction())));
     147                                && (prev.getTitleItem() == null || !RUN_FRAME_ACTION
     148                                                .equalsIgnoreCase(prev.getTitleItem().getFirstAction())));
    145149
    146150                FrameUtils.DisplayFrame(prev, true);
     
    153157                        // check if its a test frame
    154158                        if (next != null
    155                                         && next.getTitle() != null
    156                                         && RUN_FRAME_ACTION.equalsIgnoreCase(next.getTitle()
     159                                        && next.getTitleItem() != null
     160                                        && RUN_FRAME_ACTION.equalsIgnoreCase(next.getTitleItem()
    157161                                                        .getFirstAction())) {
    158162                                lastTest = next;
     
    191195                        if (nextFrame == null)
    192196                                continue;
    193                         Item frameTitle = nextFrame.getTitle();
     197                        Item frameTitle = nextFrame.getTitleItem();
    194198                        if (frameTitle == null)
    195199                                continue;
     
    248252                        if (current.getLink() == null) {
    249253                                current = current.copy();
    250                                 current.setLink(DisplayIO.getCurrentFrame().getFrameName());
     254                                current.setLink(DisplayIO.getCurrentFrame().getName());
    251255                        }
    252256
     
    264268
    265269        private static void FlagError(Item item) {
    266                 FrameUtils.DisplayFrame(item.getParent().getFrameName(), true);
     270                FrameUtils.DisplayFrame(item.getParent().getName(), true);
    267271                item.setSelectedMode(SelectedMode.Normal);
    268272                item.setSelectionColor(Color.CYAN);
     
    342346                Frame frame = i.getParent();
    343347
    344                 if (i == frame.getTitle() || i == frame.getFrameNameItem()
     348                if (i == frame.getTitleItem() || i == frame.getNameItem()
    345349                                || i.isAnnotation()) {
    346350                        return false;
     
    357361         */
    358362        private static String[] parseStatement(Text code) throws Exception {
    359                 String statement = code.getTextNoList();
     363                String statement = code.getText();
    360364                ArrayList<String> tokens = new ArrayList<String>();
    361365
     
    420424                // Add call to the start of the title if it doesnt exist
    421425                // This makes the call and signature tokens counts match
    422                 String procedureTitle = procedure.getTitle().getFirstLine();
     426                String procedureTitle = procedure.getTitleItem().getFirstLine();
    423427                if (!procedureTitle.toLowerCase().startsWith("call "))
    424428                        procedureTitle = "call " + procedureTitle;
     
    588592                                        throw new RuntimeException(e.getMessage());
    589593                                }
     594                        } else if (tokens[0].equals("setassociation")) {
     595                                assertMinParametreCount(tokens, 3);
     596
     597                                Map map = (Map) context.getPointers().getVariable(tokens[1])
     598                                                .getValue();
     599                                String attribute = context.getPrimitives().getStringValue(
     600                                                tokens[2]);
     601                                String value = context.getPrimitives()
     602                                                .getStringValue(tokens[3]);
     603                                map.put(attribute, value);
     604                                return Status.OK;
    590605                        } else if (tokens[0].equals("setframevalue")) {
    591606                                assertMinParametreCount(tokens, 3);
     
    605620                                // Begin the search
    606621                                for (Text text : targetFrame.getBodyTextItems(true)) {
    607                                         String s = text.getTextNoList().toLowerCase();
     622                                        String s = text.getText().toLowerCase();
    608623
    609624                                        if (s.startsWith(targetAttribute)) {
     
    697712                                        Item item = (Item) context.getPointers().getVariable(
    698713                                                        tokens[1]).getValue();
    699                                         item.setAction(context.getPrimitives().getVariable(tokens[2])
    700                                                         .stringValue());
     714                                        item.setAction(context.getPrimitives().getVariable(
     715                                                        tokens[2]).stringValue());
    701716                                } else if (tokens[0].equals("setitemfillcolor")) {
    702717                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     
    757772                                Text item = (Text) context.getPointers().getVariable(tokens[1])
    758773                                                .getValue();
    759                                 List<String> itemText = item.getText();
     774                                List<String> itemText = item.getTextList();
    760775
    761776                                while (row >= itemText.size()) {
     
    858873                                        // Begin the search
    859874                                        for (Text text : targetFrame.getBodyTextItems(true)) {
    860                                                 String s = text.getTextNoList().toLowerCase();
     875                                                String s = text.getText().toLowerCase();
    861876                                                if (s.startsWith(targetAttribute)) {
    862877                                                        attributeItem = text;
    863                                                         value = AttributeUtils.stripValue(s);
     878                                                        value = AttributeUtils.getValue(s);
    864879                                                        if (value.length() > 0) {
    865880                                                                found = true;
     
    880895                                                                found = true;
    881896                                                                valueItem = text;
    882                                                                 value = text.getTextNoList();
     897                                                                value = text.getText();
    883898                                                                break;
    884899                                                        }
     
    915930                                                        frameVar).getValue();
    916931                                        context.getPrimitives().setValue(frameNameVar,
    917                                                         frame.getFrameName());
     932                                                        frame.getName());
    918933                                        return Status.OK;
    919934                                } else if (tokens[0].startsWith("getframefilepath")) {
     
    932947                                        String log = SessionStats.getFrameEventList();
    933948                                        Text t;
    934                                         // try {
     949
    935950                                        t = (Text) context.getPointers().getVariable(tokens[1])
    936951                                                        .getValue();
    937952                                        t.setText(log);
    938                                         // } catch (Exception e) {
    939                                         // t = new Text(-1, log);
    940                                         // context.getPointers().setObject(tokens[1], t);
    941                                         // }
    942953
    943954                                        return Status.OK;
    944955                                }
     956                        } else if (tokens[0].equals("getassociation")) {
     957                                assertMinParametreCount(tokens, 3);
     958                                Map map = (Map) context.getPointers().getVariable(tokens[1])
     959                                                .getValue();
     960                                String attribute = context.getPrimitives().getStringValue(
     961                                                tokens[2]);
     962                                String newValue = map.get(attribute).toString();
     963                                context.getPrimitives().setValue(tokens[3], newValue);
     964                                return Status.OK;
    945965                        } else if (tokens[0].startsWith("getcurrent")) {
    946966                                if (tokens[0].equals("getcurrentframe")) {
     
    954974                                        if (tokens.length > 2) {
    955975                                                context.getPrimitives().setValue(tokens[2],
    956                                                                 new SString(currentFrame.getFrameName()));
     976                                                                new SString(currentFrame.getName()));
    957977                                        }
    958978                                        return Status.OK;
     
    10171037                                        context.getPrimitives().setValue(tokens[2],
    10181038                                                        new SString(action));
    1019                                 }else if (tokens[0].equals("getitemfillcolor")) {
     1039                                } else if (tokens[0].equals("getitemfillcolor")) {
    10201040                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    10211041                                        // assertPrimitiveType(tokens[2], 2);
     
    10431063                                                        tokens[2],
    10441064                                                        new SString((item instanceof Text) ? ((Text) item)
    1045                                                                         .getTextNoList() : ""));
     1065                                                                        .getText() : ""));
    10461066                                } else
    10471067                                        throw new Exception("Unsupported getItem command: "
     
    12091229                        String s = getMessage(tokens, context, code.toString(), " ", 2);
    12101230                        for (int i = 0; i < s.length(); i++) {
    1211                                 FrameKeyboardActions.processChar(s.charAt(i));
     1231                                FrameKeyboardActions.processChar(s.charAt(i), false);
    12121232                                Thread.sleep((int) (delay * 1000));
    12131233                        }
     
    12181238                                        .equals("type") ? " " : "", 1);
    12191239                        for (int i = 0; i < s.length(); i++) {
    1220                                 FrameKeyboardActions.processChar(s.charAt(i));
     1240                                FrameKeyboardActions.processChar(s.charAt(i), false);
    12211241                                Thread.sleep(25);
    12221242                        }
     
    15661586                                        tokens[1]).getValue();
    15671587                        FrameIO.SuspendCache();
    1568                         Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getFrameName());
     1588                        Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getName());
    15691589                        // Change the frameset if one was provided
    15701590                        if (tokens.length > 3) {
     
    16581678                                                new SCharacter(nextChar));
    16591679
     1680                        return Status.OK;
     1681                } else if (tokens[0].equals("createassociation")) {
     1682
     1683                        String associationVar = DEFAULT_ASSOCIATION;
     1684
     1685                        if (tokens.length > 0) {
     1686                                assertVariableType(tokens[1], 2, SPointer.associationPrefix);
     1687                                associationVar = tokens[1];
     1688                        }
     1689                        Map<String, String> newMap = new HashMap<String, String>();
     1690                        context.getPointers().setObject(associationVar, newMap);
     1691                        return Status.OK;
     1692                } else if (tokens[0].equals("deleteassociation")) {
     1693
     1694                        String associationVar = DEFAULT_ASSOCIATION;
     1695
     1696                        if (tokens.length > 0) {
     1697                                assertVariableType(tokens[1], 2, SPointer.associationPrefix);
     1698                                associationVar = tokens[1];
     1699                        }
     1700                        context.getPointers().delete(associationVar);
    16601701                        return Status.OK;
    16611702                } else if (tokens[0].equals("openreadfile")) {
     
    18471888                        int count = 0;
    18481889                        if (item instanceof Text)
    1849                                 count = countCharsInString(((Text) item).getTextNoList(),
    1850                                                 pattern);
     1890                                count = countCharsInString(((Text) item).getText(), pattern);
    18511891                        context.getPrimitives().setValue(tokens[3], new SInteger(count));
    18521892                        return Status.OK;
     
    21412181                                }
    21422182
    2143                                 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    2144                                 assertVariableType(tokens[2], 2, SPointer.framePrefix);
     2183                                assertVariableType(tokens[2], 2, SPointer.itemPrefix);
     2184                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
    21452185                                Frame currFrame = (Frame) context.getPointers().getVariable(
    2146                                                 tokens[2]).getValue();
     2186                                                tokens[1]).getValue();
    21472187                                // Create the ip variable
    2148                                 Item frameName = currFrame.getFrameNameItem();
    2149                                 Item frameTitle = currFrame.getTitle();
     2188                                Item frameTitle = currFrame.getTitleItem();
    21502189
    21512190                                for (Item i : currFrame.getItems()) {
    2152                                         if (i == frameName || i == frameTitle)
     2191                                        if (i == frameTitle)
    21532192                                                continue;
    21542193                                        if (!(itemType.isInstance(i)))
    21552194                                                continue;
    21562195
    2157                                         context.getPointers().setObject(tokens[1], i);
     2196                                        context.getPointers().setObject(tokens[2], i);
    21582197                                        Status status = RunFrameAndReportError(code, context);
    21592198                                        // check if we need to exit this loop because of
     
    21822221                                        context.getPrimitives().exp(tokens[1], tokens[2]);
    21832222                                } else if (tokens[0].equals("log")) {
    2184                                         context.getPrimitives().log(tokens[1], tokens[2]);
     2223                                        context.getPrimitives().log(tokens[2], tokens[2]);
    21852224                                } else if (tokens[0].equals("log10")) {
    21862225                                        context.getPrimitives().log10(tokens[1], tokens[2]);
     
    21882227                                        context.getPrimitives().sqrt(tokens[1], tokens[2]);
    21892228                                } else if (tokens[0].equals("add")) {
    2190                                         context.getPrimitives().add(tokens[1], tokens[2]);
     2229                                        context.getPrimitives().add(tokens[2], tokens[1]);
    21912230                                } else if (tokens[0].equals("subtract")) {
    2192                                         context.getPrimitives().subtract(tokens[1], tokens[2]);
     2231                                        context.getPrimitives().subtract(tokens[2], tokens[1]);
    21932232                                } else if (tokens[0].equals("multiply")) {
    2194                                         context.getPrimitives().multiply(tokens[1], tokens[2]);
     2233                                        context.getPrimitives().multiply(tokens[2], tokens[1]);
    21952234                                } else if (tokens[0].equals("divide")) {
    2196                                         context.getPrimitives().divide(tokens[1], tokens[2]);
     2235                                        context.getPrimitives().divide(tokens[2], tokens[1]);
    21972236                                } else
    21982237                                        throw new RuntimeException("Invalid statement:");
     
    22002239                        }
    22012240                } else if (tokens.length == 4) {
     2241                        if (tokens[0].equals("foreachassociation")) {
     2242                                assertExactParametreCount(tokens, 3);
     2243                                assertVariableType(tokens[1], 1, SPointer.associationPrefix);
     2244                                Map<String,String> map = (Map<String,String>) context.getPointers().getVariable(
     2245                                                tokens[1]).getValue();
     2246                                for(Map.Entry entry: map.entrySet()){
     2247                                        String value = entry.getValue().toString();
     2248                                        String key = entry.getKey().toString();
     2249                                        context.getPrimitives().setValue(tokens[2], key);
     2250                                        context.getPrimitives().setValue(tokens[3], value);
     2251                                        Status status = RunFrameAndReportError(code, context);
     2252                                        // check if we need to exit this loop because of
     2253                                        // statements in the code that was run
     2254                                        if (status == Status.Exit || status == Status.Return)
     2255                                                return status;
     2256                                        else if (status == Status.Break)
     2257                                                return Status.OK;
     2258                                }
     2259                                return Status.OK;
     2260                        }
     2261                       
    22022262                        if (Primitives.isPrimitive(tokens[1])
    22032263                                        && Primitives.isPrimitive(tokens[2])
Note: See TracChangeset for help on using the changeset viewer.