use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class Def_Function_Writer method writeDefinitionStatement.
// updated
public void writeDefinitionStatement(Definition_Statement tc_defStatement) {
defCounter++;
if (tc_defStatement.getDefinition() instanceof Def_Timer) {
Def_Timer def_Timer = (Def_Timer) tc_defStatement.getDefinition();
functionString.append("rownum=" + def_Timer.getLocation().getLine() + ";\r\n");
functionString.append("Timer " + def_Timer.getIdentifier().toString() + " = new Timer(" + functionVarValues.get(defCounter) + ");\r\n");
functionString.append("TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timer " + def_Timer.getIdentifier().toString() + " set to " + functionVarValues.get(defCounter) + ".\", false);" + "\r\n");
} else if (functionVarTypes.get(defCounter).equals("BITSTRING")) {
functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (functionVarIsConstant.get(defCounter)) {
functionString.append("final ");
}
if (functionVarValues.get(defCounter) == null) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BITSTRING();\r\n");
} else if (functionValueIsAValueReference.get(defCounter)) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
} else {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BITSTRING(\"" + functionVarValues.get(defCounter) + "\");\r\n");
}
// TODO: add logging here
} else if (functionVarTypes.get(defCounter).equals("INTEGER")) {
functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (functionVarIsConstant.get(defCounter)) {
functionString.append("final ");
}
if (functionVarValues.get(defCounter) == null) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new INTEGER();\r\n");
} else if (functionValueIsAValueReference.get(defCounter)) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
} else {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new INTEGER(\"" + functionVarValues.get(defCounter) + "\");\r\n");
}
// TODO: add logging here
} else if (functionVarTypes.get(defCounter).equals("CHARSTRING")) {
functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (functionVarIsConstant.get(defCounter)) {
functionString.append("final ");
}
if (functionVarValues.get(defCounter) == null) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new CHARSTRING();\r\n");
} else if (functionValueIsAValueReference.get(defCounter)) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
} else {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new CHARSTRING(\"" + functionVarValues.get(defCounter) + "\");\r\n");
}
// TODO: add logging here
} else if (functionVarTypes.get(defCounter).equals("BOOLEAN")) {
functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (functionVarIsConstant.get(defCounter)) {
functionString.append("final ");
}
if (functionVarValues.get(defCounter) == null) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BOOLEAN();\r\n");
} else if (functionValueIsAValueReference.get(defCounter)) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
} else {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + " = BOOLEAN.valueOf(" + functionVarValues.get(defCounter) + ");\r\n");
}
// TODO: add logging here
} else if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(functionVarTypes.get(defCounter))) {
functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (functionVarValues.get(defCounter) != null) {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "= new " + functionVarTypes.get(defCounter) + "(" + functionVarValues.get(defCounter) + ")" + ";\r\n");
} else {
functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + ";\r\n");
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class Def_Testcase_Writer method writeDefinitionStatement.
public void writeDefinitionStatement(Definition_Statement tc_defStatement) {
if (tc_defStatement.getDefinition() instanceof Def_Timer) {
Def_Timer def_Timer = (Def_Timer) tc_defStatement.getDefinition();
testCaseString.append("rownum=" + def_Timer.getLocation().getLine() + ";\r\n");
testCaseString.append("Timer " + def_Timer.getIdentifier().toString() + " = new Timer(" + tcVarValues.get(defCounter) + ");\r\n");
testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timer " + def_Timer.getIdentifier().toString() + " set to " + tcVarValues.get(defCounter) + ".\", false);" + "\r\n");
} else if (tcVarTypes.get(defCounter).equals("BITSTRING")) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BITSTRING();\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BITSTRING(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
// TODO: add logging here
}
} else if (tcVarTypes.get(defCounter).equals("INTEGER")) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new INTEGER();\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new INTEGER(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
// TODO: add logging here
}
} else if (tcVarTypes.get(defCounter).equals("CHARSTRING")) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new CHARSTRING();\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new CHARSTRING(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
// TODO: add logging here
}
} else if (tcVarTypes.get(defCounter).equals("OCTETSTRING")) {
testCaseString.append("rownum = ").append(tc_defStatement.getLocation().getLine()).append(";").append("\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new OCTETSTRING();\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new OCTETSTRING(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
// TODO: add logging here
}
} else if (tcVarTypes.get(defCounter).equals("BOOLEAN")) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BOOLEAN();\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BOOLEAN(" + tcVarValues.get(defValueCounter) + ");\r\n");
// TODO: add logging here
}
} else if (tcVarTypes.get(defCounter).equals("FLOAT")) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new FLOAT();\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new FLOAT(" + tcVarValues.get(defValueCounter) + ");\r\n");
// TODO: add logging here
}
} else if (nodeVarIsRecord.get(defCounter)) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "= new " + tcVarTypes.get(defCounter) + "();\r\n");
int childSize = myASTVisitor.nodeNameChildrenNamesHashMap.get(tcVarTypes.get(defCounter)).length;
for (int i = 0; i < childSize; i++) {
String childType = myASTVisitor.nodeNameChildrenTypesHashMap.get(tcVarTypes.get(defCounter))[i];
String childName = myASTVisitor.nodeNameChildrenNamesHashMap.get(tcVarTypes.get(defCounter))[i];
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
writeRecordChildren(childType, childName);
if (i + 1 < childSize) {
defValueCounter++;
}
}
} else if (tcValueTypeIsAReference.get(defCounter)) {
testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
if (tcVarIsConstant.get(defCounter)) {
testCaseString.append("final ");
}
if (tcVarIsTemplate.get(defCounter)) {
testCaseString.append("template ");
}
if (tcVarValues.get(defValueCounter) == null) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + ";\r\n");
// TODO: add logging here
} else if (tcValueIsAValueReference.get(defCounter)) {
if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(tcVarTypes.get(defCounter))) {
if (myASTVisitor.nodeNameNodeTypeHashMap.get(tcVarTypes.get(defCounter)).equals("enum")) {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "= new " + tcVarTypes.get(defCounter) + "(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
}
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
}
// TODO: add logging here
} else {
testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
// TODO: add logging here
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement in project titan.EclipsePlug-ins by eclipse.
the class Def_Testcase_Writer method writeTestCaseFunction.
public String writeTestCaseFunction(StatementBlock tcStatementBlock) {
int testcaseSize = tcStatementBlock.getSize();
for (int j = 0; j < testcaseSize; j++) {
if (tcStatementBlock.getStatementByIndex(j) instanceof Definition_Statement) {
Definition_Statement tc_defStatement = (Definition_Statement) tcStatementBlock.getStatementByIndex(j);
defCounter++;
defValueCounter++;
writeDefinitionStatement(tc_defStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Assignment_Statement) {
Assignment_Statement tc_assignStatement = (Assignment_Statement) tcStatementBlock.getStatementByIndex(j);
assignCounter++;
testCaseString.append(writeAssignmentStatement(tc_assignStatement));
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Connect_Statement) {
Connect_Statement tc_connectStatement = (Connect_Statement) tcStatementBlock.getStatementByIndex(j);
connectCounter++;
writeConnectStatement(tc_connectStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Start_Statement) {
Unknown_Start_Statement tc_startStatement = (Unknown_Start_Statement) tcStatementBlock.getStatementByIndex(j);
writeUnknownStartStatement(tc_startStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Done_Statement) {
testCaseString.append("hc.done(\"all component\");" + "\r\n");
// TODO: where is all coming from?
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Map_Statement) {
Map_Statement tc_mapStatement = (Map_Statement) tcStatementBlock.getStatementByIndex(j);
mapCounter++;
writeMapStatement(tc_mapStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof If_Statement) {
If_Statement tc_ifStatement = (If_Statement) tcStatementBlock.getStatementByIndex(j);
tcIfConditionCounter++;
writeIfStatement(tc_ifStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Setverdict_Statement) {
Setverdict_Statement tc_setVerdictStatement = (Setverdict_Statement) tcStatementBlock.getStatementByIndex(j);
writeSetVerdictStatement(tc_setVerdictStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof DoWhile_Statement) {
doWhileCounter++;
DoWhile_Statement doWhileStatement = (DoWhile_Statement) tcStatementBlock.getStatementByIndex(j);
String test = doWhileStatement.getExpression().toString();
testCaseString.append("do{" + "\r\n");
this.writeTestCaseFunction(doWhileStatement.getStatementBlock());
testCaseString.append("while(" + doWhileExpressions.get(doWhileCounter) + ".getValue());\r\n");
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Send_Statement) {
Send_Statement tc_SendStatement = (Send_Statement) tcStatementBlock.getStatementByIndex(j);
sendCounter++;
testCaseString.append(writeSendStatement(tc_SendStatement));
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Receive_Port_Statement) {
Receive_Port_Statement tc_ReceiveStatement = (Receive_Port_Statement) tcStatementBlock.getStatementByIndex(j);
receiveCounter++;
blockStatementBlockStatementWriter = true;
testCaseString.append(writeReceiveStatement(tc_ReceiveStatement));
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Stop_Statement) {
Unknown_Stop_Statement tc_StopStatement = (Unknown_Stop_Statement) tcStatementBlock.getStatementByIndex(j);
writeUnknownStopStatement(tc_StopStatement);
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Alt_Statement) {
altStatementCounter++;
altStatements.get(altStatementCounter).setTimerInfo(isThereAStartedTimer, currentTimerName);
testCaseString.append(altStatements.get(altStatementCounter).getJavaSource());
} else if (tcStatementBlock.getStatementByIndex(j) instanceof Disconnect_Statement) {
Disconnect_Statement tc_disconnectStatement = (Disconnect_Statement) tcStatementBlock.getStatementByIndex(j);
disconnectCounter++;
writeDisconnectStatement(tc_disconnectStatement);
} else if ((tcStatementBlock.getStatementByIndex(j) instanceof StatementBlock_Statement) && !blockStatementBlockStatementWriter) {
StatementBlock_Statement tc_statementBlockStatement = (StatementBlock_Statement) tcStatementBlock.getStatementByIndex(j);
blockStatementBlockStatementWriter = false;
testCaseString.append("{\r\n");
blockWriter = true;
writeTestCaseFunction(tc_statementBlockStatement.getStatementBlock());
blockWriter = false;
testCaseString.append("}\r\n");
}
}
if (!blockWriter) {
testCaseString.append("}" + "\r\n");
}
return testCaseString.toString();
}
Aggregations