Search in sources :

Example 1 with Receive_Port_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement in project titan.EclipsePlug-ins by eclipse.

the class Def_AltStatement_Writer method writeTestCaseAltStatement.

public void writeTestCaseAltStatement(Alt_Statement altStatement) {
    AltGuards currentAltGuards = altStatement.getAltGuards();
    String[] negativeConditions = new String[currentAltGuards.getNofAltguards()];
    String[] positiveConditions = new String[currentAltGuards.getNofAltguards()];
    // initialize values
    for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) {
        AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i);
        if (currentAltGuard instanceof Operation_Altguard) {
            Statement currentStatement = ((Operation_Altguard) currentAltGuard).getGuardStatement();
            if (currentStatement instanceof Receive_Port_Statement) {
                altReceiveCounter++;
                if (altGuardConditions.get(i) != null) {
                    // alt guard present && any port receive
                    if (altGuardPortReference.get(altReceiveCounter).equals("any port")) {
                        positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + "anyPortReceive(true))";
                        negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + "anyPortReceive(false))";
                    } else {
                        // alt guard present && normal port receive
                        positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",true)!=null)";
                        negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",false)!=null)";
                        if (altGuardReceiveValue.get(altReceiveCounter).startsWith("Templates")) {
                            altGuardReceiveType.set(altReceiveCounter, "Templates");
                        }
                    }
                } else {
                    // no alt guard && any port recieve
                    if (altGuardPortReference.get(altReceiveCounter).equals("any port")) {
                        positiveConditions[i] = "anyPortReceive(true)";
                        negativeConditions[i] = "anyPortReceive(false)";
                    } else {
                        // no alt guard && no receive parameter
                        if (altGuardReceiveType.get(altReceiveCounter).equals("noparam")) {
                            positiveConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(true)!=null";
                            negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(false)!=null";
                        } else if (// no alt guard && typed port recieve
                        altGuardReceiveType.get(altReceiveCounter).equals("_TYPED_PARAM_")) {
                            negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive_" + altGuardReceiveValue.get(altReceiveCounter) + "(false)!=null";
                            if (altGuardReceiveAnyValValue.get(altReceiveCounter) != null) {
                                positiveConditions[i] = "(" + altGuardReceiveAnyValValue.get(altReceiveCounter) + "=" + altGuardPortReference.get(altReceiveCounter) + ".receive_" + altGuardReceiveValue.get(altReceiveCounter) + "(true))!=null";
                            } else {
                            }
                        } else {
                            // no alt guard && normal port recieve
                            positiveConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",true)!=null";
                            negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",false)!=null";
                        }
                        if (altGuardReceiveValue.get(altReceiveCounter) != null && altGuardReceiveValue.get(altReceiveCounter).startsWith("Templates")) {
                            altGuardReceiveType.set(altReceiveCounter, "Templates");
                        }
                    }
                }
            }
            if (currentStatement instanceof Timeout_Statement) {
                timeOutCounter++;
                if (altGuardConditions.get(i) != null) {
                    positiveConditions[i] = altGuardConditions.get(i) + "&&(" + altGuardTimeout.get(timeOutCounter) + ".timeout()";
                    negativeConditions[i] = altGuardConditions.get(i) + "&&(!" + altGuardTimeout.get(i) + ".timeout()";
                } else {
                    positiveConditions[i] = altGuardTimeout.get(timeOutCounter) + ".timeout()";
                    negativeConditions[i] = "!" + altGuardTimeout.get(timeOutCounter) + ".timeout()";
                }
            }
        }
    }
    // write
    altString.append("rownum=" + altStatement.getLocation().getLine() + ";\r\n");
    altString.append("for(;;){" + "\r\n");
    altString.append("if(!(");
    for (int j = 0; j < negativeConditions.length; j++) {
        altString.append(negativeConditions[j]);
        if (j + 1 < negativeConditions.length) {
            altString.append("||");
        }
    }
    altString.append(")){" + "\r\n");
    // timer
    if (isThereAStartedTimer) {
        altString.append("long timeout = -1;" + "\r\n");
        altString.append("long newtimeout;" + "\r\n");
        altString.append("if(" + currentTimerName + ".running)if((newtimeout=(long)(" + currentTimerName + ".read().value*1000.0))<timeout || timeout == -1) timeout=newtimeout;" + "\r\n");
        altString.append("if(timeout>0) try{queue.poll(timeout,TimeUnit.MILLISECONDS);}catch(InterruptedException e){} " + "\r\n");
    } else {
        altString.append("try{queue.take();}catch(InterruptedException e){}" + "\r\n");
    }
    // endoftimer
    altString.append("}" + "\r\n");
    altString.append("this.lock();" + "\r\n");
    // ifwriter
    altReceiveCounter = -1;
    boolean isFirstIf = true;
    for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) {
        AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i);
        if (currentAltGuard instanceof Operation_Altguard) {
            Statement currentStatement = ((Operation_Altguard) currentAltGuard).getGuardStatement();
            StatementBlock currentStatementBlock = ((Operation_Altguard) currentAltGuard).getStatementBlock();
            if (isFirstIf) {
                altString.append("if(" + positiveConditions[i] + "){\r\n");
                isFirstIf = false;
            } else {
                altString.append("else if(" + positiveConditions[i] + "){\r\n");
            }
            if (currentStatement instanceof Receive_Port_Statement) {
                altReceiveCounter++;
                altString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n");
                if (altGuardReceiveType.get(altReceiveCounter).equals("noparam")) {
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + "\", true);" + "\r\n");
                } else if (altGuardReceiveType.get(altReceiveCounter).equals("Templates")) {
                    String methodName = altGuardReceiveValue.get(altReceiveCounter);
                    if (methodName.endsWith("()") && methodName.startsWith("Templates.")) {
                        methodName = (String) methodName.subSequence(10, methodName.length() - 2);
                    }
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ":\\n " + methodName + ":=\" + " + altGuardReceiveValue.get(altReceiveCounter) + ".toString(), true);" + "\r\n");
                } else if (altGuardReceiveType.get(altReceiveCounter).equals("any port")) {
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port any port\", true);" + "\r\n");
                } else if (altGuardReceiveType.get(altReceiveCounter).equals("_TYPED_PARAM_")) {
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ": type " + altGuardReceiveValue.get(altReceiveCounter) + "\", true);" + "\r\n");
                } else {
                    if (altGuardReceiveValue.get(altReceiveCounter) != null) {
                        altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ":\" + " + altGuardReceiveValue.get(altReceiveCounter) + ".toString(), true);" + "\r\n");
                    }
                }
            } else if (currentStatement instanceof Timeout_Statement) {
                altString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n" + "TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timeout on timer " + currentTimerName + ".\", false);" + "\r\n");
            }
            boolean isThereARepeatStatement = false;
            for (int j = 0; j < currentStatementBlock.getSize(); j++) {
                Statement currentStatementBlockStatement = currentStatementBlock.getStatementByIndex(j);
                if (currentStatementBlockStatement instanceof Setverdict_Statement) {
                    Setverdict_Statement setVerdictStatement = (Setverdict_Statement) currentStatementBlockStatement;
                    String verdict = "";
                    if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) {
                        Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue();
                        if (verdictValue.getValue().toString().equals("PASS")) {
                            verdict = "pass";
                        } else if (verdictValue.getValue().toString().equals("INCONC")) {
                            verdict = "inconc";
                        } else {
                            verdict = "fail";
                        }
                    }
                    altString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n");
                    altString.append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + "\", true);" + "\r\n");
                    altString.append("setVerdict(\"" + verdict + "\");" + "\r\n");
                }
                if (currentStatementBlockStatement instanceof Assignment_Statement) {
                    if (isFunction) {
                        functionParent.assignCounter++;
                        altString.append(functionParent.writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement));
                        String test = "";
                        test.toString();
                    } else if (isTestCase) {
                        testcaseParent.assignCounter++;
                        altString.append(testcaseParent.writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement));
                    }
                }
                if (currentStatementBlockStatement instanceof Send_Statement) {
                    if (isFunction) {
                        functionParent.sendCounter++;
                        altString.append(functionParent.writeSendStatement((Send_Statement) currentStatementBlockStatement));
                    } else if (isTestCase) {
                        testcaseParent.sendCounter++;
                        altString.append(testcaseParent.writeSendStatement((Send_Statement) currentStatementBlockStatement));
                    }
                }
                if (currentStatementBlockStatement instanceof Repeat_Statement) {
                    isThereARepeatStatement = true;
                }
            }
            if (isThereARepeatStatement) {
                isThereARepeatStatement = false;
            } else {
                altString.append("break;\r\n");
            }
            altString.append("}\r\n");
        }
    }
    altString.append("this.unlock();" + "\r\n");
    altString.append("}" + "\r\n");
}
Also used : AltGuard(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Repeat_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Repeat_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) AltGuards(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Repeat_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Repeat_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 2 with Receive_Port_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement in project titan.EclipsePlug-ins by eclipse.

the class TestCase_Function_Visit_Handler method leave.

public void leave(IVisitableNode node) {
    if (waitForTC || waitForFunction) {
        if (node instanceof Definition_Statement) {
            if (!waitForRecord) {
                nodeVarIsRecord.add(false);
            }
            waitForRecord = false;
            waitForValue = false;
            evaluateExpression();
        }
        if (node instanceof Undefined_LowerIdentifier_Value) {
            blockReferenceListing = false;
        }
        if ((node instanceof Assignment_Statement) || ((node instanceof If_Clause))) {
            waitForValue = false;
            // if assignment is a createExpression
            if (node instanceof Assignment_Statement) {
                if (((Assignment_Statement) node).getTemplate() instanceof SpecificValue_Template) {
                    SpecificValue_Template specValTemplate = (SpecificValue_Template) ((Assignment_Statement) node).getTemplate();
                    if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
                        isCreate = true;
                    }
                }
            }
            evaluateExpression();
        }
        if (node instanceof SequenceOf_Value) {
            evaluateExpression();
        }
        if ((waitForFunction && (node instanceof Return_Statement)) || (waitForTC && (node instanceof ComponentCreateExpression)) || (node instanceof Send_Statement) || (node instanceof Receive_Port_Statement)) {
            evaluateExpression();
        }
        if (waitForTcStartValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
            myASTVisitor.blockIdListing = false;
        }
        if (waitForTcStopValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
            myASTVisitor.blockIdListing = false;
        }
        if (node instanceof Connect_Statement) {
            waitForTcConnectValues = false;
        }
        if (node instanceof Disconnect_Statement) {
            waitForTcDisconnectValues = false;
        }
        if (node instanceof Unknown_Start_Statement) {
            waitForTcStartValues = false;
        }
        if (node instanceof Unknown_Stop_Statement) {
            waitForTcStopValues = false;
        }
        if (node instanceof Definition_Statement) {
            waitForDefStatement = false;
            if (waitForValue) {
                nodeVarValues.add(null);
                nodeVarIsAValueReference.add(false);
                waitForValue = false;
            }
        }
        if (node instanceof Map_Statement) {
            waitForMapIdentifiers = false;
        }
        if (node instanceof ComponentCreateExpression) {
            // switch first two values
            testCaseCreateValues.add(testCaseCreateCharValues.get(0));
            testCaseCreateValues.add(testCaseCreateRefValues.get(0));
            for (int i = 1; i < testCaseCreateCharValues.size(); i++) {
                testCaseCreateValues.add(testCaseCreateCharValues.get(i));
            }
            testCaseCreateCharValues.clear();
            testCaseCreateRefValues.clear();
            waitForTcCreateValues = false;
        }
        if (node instanceof Assignment_Statement) {
            waitForAssignmentIdentifiers = false;
            waitForValue = true;
        }
        if (waitForTcIfCondition && (node instanceof If_Clause)) {
            waitForTcIfCondition = false;
        }
        if (waitForTcStartParameter && (node instanceof Unknown_Start_Statement)) {
            testCaseStartValueParameters.add(null);
        }
        if (waitForTcStopParameter && (node instanceof Unknown_Stop_Statement)) {
            testCaseStopValueParameters.add(null);
        }
        if (isAltGuards && (node instanceof Operation_Altguard)) {
            altGuardConditions.add(null);
        }
        if (node instanceof Operation_Altguard) {
            waitForAltStatements = false;
            isAltGuards = false;
            isReceiveValue = false;
        }
        handleAltCases(node);
        if (node instanceof Unknown_Start_Statement) {
            waitForUnknownStartStatement = false;
        }
        if (node instanceof Unknown_Stop_Statement) {
            waitForUnknownStopStatement = false;
        }
        if (node instanceof Receive_Port_Statement) {
            if (waitForReceiveParameter) {
                altGuardReceiveType.add("noparam");
            }
        // TODO checkAnyport = true;
        }
    }
    if (node instanceof Def_Testcase) {
        handleTestcase(node);
        waitForTC = false;
    }
    if (node instanceof Def_Function) {
        handleFunction(node);
        waitForTC = false;
    }
    if (waitForAssignmentIdentifiers && (node instanceof ArraySubReference)) {
        waitForAssignmentIdentifiers = false;
    }
}
Also used : Connect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement) Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ComponentCreateExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Identifier(org.eclipse.titan.designer.AST.Identifier) Unknown_Stop_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement) Return_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Disconnect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement) Unknown_Start_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement) Map_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 3 with Receive_Port_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement in project titan.EclipsePlug-ins by eclipse.

the class Def_Testcase_Writer method writeReceiveStatement.

public String writeReceiveStatement(Receive_Port_Statement currentStatement) {
    StringBuilder testCaseString = new StringBuilder("");
    String receiveStatement = "";
    // no alt guard && any port recieve
    if (receivePortReference.get(receiveCounter).equals("any port")) {
        receiveStatement = "anyPortReceive(true)";
    } else {
        // no alt guard && typed port recieve
        if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) {
            if (receiveAnyValValue.get(receiveCounter) != null) {
                receiveStatement = "(" + receiveAnyValValue.get(receiveCounter) + "=" + receivePortReference.get(receiveCounter) + ".receive_" + receiveValue.get(receiveCounter) + "(true))!=null";
            } else {
            }
        } else {
            // no alt guard && normal port recieve
            receiveStatement = receivePortReference.get(receiveCounter) + ".receive(" + receiveValue.get(receiveCounter) + ",true)!=null";
        }
        if (receiveValue.get(receiveCounter).startsWith("Templates")) {
            receiveType.set(receiveCounter, "Templates");
        }
    }
    testCaseString.append("if(" + receiveStatement + "){\r\n");
    testCaseString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n");
    if (receiveType.get(receiveCounter).equals("Templates")) {
        String methodName = receiveValue.get(receiveCounter);
        if (methodName.endsWith("()") && methodName.startsWith("Templates.")) {
            methodName = (String) methodName.subSequence(10, methodName.length() - 2);
        }
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + ":\\n " + methodName + ":=\" + " + receiveValue.get(receiveCounter) + ".toString(), true);" + "\r\n");
    } else if (receiveType.get(receiveCounter).equals("any port")) {
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port any port\", true);" + "\r\n");
    } else if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) {
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + ": type " + receiveValue.get(receiveCounter) + "\", true);" + "\r\n");
    } else {
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + ":\" + " + receiveValue.get(receiveCounter) + ".toString(), true);" + "\r\n");
    }
    for (int i = 0; i < receiveStatements.get(receiveCounter).getSize(); i++) {
        if (receiveStatements.get(receiveCounter).getStatementByIndex(i) instanceof Setverdict_Statement) {
            Setverdict_Statement setVerdictStatement = (Setverdict_Statement) receiveStatements.get(receiveCounter).getStatementByIndex(i);
            String verdict = "";
            if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) {
                Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue();
                if (verdictValue.getValue().toString().equals("PASS")) {
                    verdict = "pass";
                } else if (verdictValue.getValue().toString().equals("INCONC")) {
                    verdict = "inconc";
                } else {
                    verdict = "fail";
                }
            }
            testCaseString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n");
            testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + "\", true);" + "\r\n");
            testCaseString.append("setVerdict(\"" + verdict + "\");" + "\r\n");
        }
    }
    testCaseString.append("}\r\n");
    return testCaseString.toString();
}
Also used : Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 4 with Receive_Port_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement in project titan.EclipsePlug-ins by eclipse.

the class ContainsRef method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Operation_Altguard) {
        final Operation_Altguard ag = (Operation_Altguard) node;
        final Statement action = ag.getGuardStatement();
        if (action instanceof Receive_Port_Statement) {
            final Receive_Port_Statement receive = (Receive_Port_Statement) action;
            final SuspiciouslyUsedIf susp = new SuspiciouslyUsedIf(receive);
            ag.accept(susp);
            if (susp.doesSmell()) {
                problems.report(susp.getSuspicious().getLocation(), SHOULD_BRANCH);
            }
        }
    }
}
Also used : Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard)

Example 5 with Receive_Port_Statement

use of org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement in project titan.EclipsePlug-ins by eclipse.

the class Def_Function_Writer method writeReceiveStatement.

public String writeReceiveStatement(Receive_Port_Statement currentStatement) {
    StringBuilder testCaseString = new StringBuilder("");
    String receiveStatement = "";
    // no alt guard && any port recieve
    if (receivePortReference.get(receiveCounter).equals("any port")) {
        receiveStatement = "anyPortReceive(true)";
    } else {
        // no alt guard && typed port recieve
        if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) {
            if (receiveAnyValValue.get(receiveCounter) != null) {
                receiveStatement = "(" + receiveAnyValValue.get(receiveCounter) + "=" + receivePortReference.get(receiveCounter) + ".receive_" + receiveValue.get(receiveCounter) + "(true))!=null";
            } else {
            }
        } else {
            // no alt guard && normal port recieve
            receiveStatement = receivePortReference.get(receiveCounter) + ".receive(" + receiveValue.get(receiveCounter) + ",true)!=null";
        }
        if (receiveValue.get(receiveCounter).startsWith("Templates")) {
            receiveType.set(receiveCounter, "Templates");
        }
    }
    testCaseString.append("if(" + receiveStatement + "){\r\n");
    testCaseString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n");
    if (receiveType.get(receiveCounter).equals("Templates")) {
        String methodName = receiveValue.get(receiveCounter);
        if (methodName.endsWith("()") && methodName.startsWith("Templates.")) {
            methodName = (String) methodName.subSequence(10, methodName.length() - 2);
        }
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + ":\\n " + methodName + ":=\" + " + receiveValue.get(receiveCounter) + ".toString(), true);" + "\r\n");
    } else if (receiveType.get(receiveCounter).equals("any port")) {
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port any port\", true);" + "\r\n");
    } else if (receiveType.get(receiveCounter).equals("_TYPED_PARAM_")) {
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + ": type " + receiveValue.get(receiveCounter) + "\", true);" + "\r\n");
    } else {
        testCaseString.append("	TTCN3Logger.writeLog(\"mtc\", \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + receivePortReference.get(receiveCounter) + ":\" + " + receiveValue.get(receiveCounter) + ".toString(), true);" + "\r\n");
    }
    for (int i = 0; i < receiveStatements.get(receiveCounter).getSize(); i++) {
        if (receiveStatements.get(receiveCounter).getStatementByIndex(i) instanceof Setverdict_Statement) {
            Setverdict_Statement setVerdictStatement = (Setverdict_Statement) receiveStatements.get(receiveCounter).getStatementByIndex(i);
            String verdict = "";
            if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) {
                Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue();
                if (verdictValue.getValue().toString().equals("PASS")) {
                    verdict = "pass";
                } else if (verdictValue.getValue().toString().equals("INCONC")) {
                    verdict = "inconc";
                } else {
                    verdict = "fail";
                }
            }
            testCaseString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n");
            testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + "\", true);" + "\r\n");
            testCaseString.append("setVerdict(\"" + verdict + "\");" + "\r\n");
        }
    }
    testCaseString.append("}\r\n");
    return testCaseString.toString();
}
Also used : Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Aggregations

Receive_Port_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement)6 Operation_Altguard (org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard)4 Setverdict_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)4 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)4 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)3 Assignment_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement)3 Send_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement)3 Verdict_Value (org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value)3 Connect_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement)2 Definition_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement)2 Disconnect_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement)2 Done_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement)2 If_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement)2 Map_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement)2 Timeout_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement)2 Unknown_Start_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement)2 Unknown_Stop_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)1