package tool.model.grammar;
import static org.junit.Assert.fail;
import junit.framework.Assert;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.junit.Test;
import tool.model.grammar.ForteParser.expression_return;
import tool.model.grammar.ForteParser.qualifiedIdentExpression_return;
import tool.model.grammar.ForteParser.qualifiedName_return;
import tool.model.grammar.ForteParser.statement_return;
public class StatementTest {
private static final boolean PRINT_TREE = false;
private ErrorReporter reporter;
private void failOnSyntaxError(String string, ForteParser parser, ForteAST ast){
int errors = 0;
int treeErrors = 0;
errors = parser.getNumberOfSyntaxErrors();
if (errors > 0 && this.reporter != null){
System.out.println(this.reporter.toString());
}
if (ast != null)
treeErrors = ast.getNumberOfSyntaxErrors();
System.out.println(string + " syntax errors: " + errors + " tree errors: " + treeErrors);
if (errors + treeErrors> 0){
fail("Syntax errors: " + errors);
}
}
private void printTree(CommonTree tree, int indent){
if (tree != null){
StringBuffer sb = new StringBuffer(indent);
for (int i = 0; i < indent; i++)
sb = sb.append(" ");
for (int i = 0; i < tree.getChildCount(); i++){
System.out.println(sb.toString() + tree.getChild(i).toString());
printTree((CommonTree)tree.getChild(i), indent+1);
}
}
}
public int testStatement(String name, String source) throws Exception{
int errors = 0;
ForteAST walker = null;
ForteParser parser = null;
System.out.println("===== Statement: " + name + " =====");
CharStream stream =
new NoCaseStringStream(source);
ForteLexer lexer = new ForteLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
parser = new ForteParser(tokens);
reporter = new ErrorReporter();
parser.setErrorReporter(reporter);
statement_return result = parser.statement();
CommonTree tree = (CommonTree) result.getTree();
if (PRINT_TREE)
System.out.println("Tree==>"+tree.toStringTree());
// printTree(tree, 0);
errors = parser.getNumberOfSyntaxErrors();
if (errors == 0){
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
walker = new ForteAST(nodes);
walker.statement();
}
failOnSyntaxError(name, parser, walker);
return errors;
}
public int testExpression(String name, String source) throws Exception{
int errors = 0;
ForteAST walker = null;
ForteParser parser = null;
try {
System.out.println("===== Expression: " + name + " =====");
CharStream stream =
new NoCaseStringStream(source);
ForteLexer lexer = new ForteLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
parser = new ForteParser(tokens);
reporter = new ErrorReporter();
parser.setErrorReporter(reporter);
parser.setTokenStream(tokens);
expression_return result = parser.expression();
CommonTree tree = (CommonTree) result.getTree();
errors = parser.getNumberOfSyntaxErrors();
if (errors == 0){
if (PRINT_TREE)
System.out.println("Tree==>"+tree.toStringTree());
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
walker = new ForteAST(nodes);
walker.expression();
}
} finally {
failOnSyntaxError(name, parser, walker);
}
return errors;
}
public int testQualifiedName(String source) throws Exception{
int errors = 0;
ForteAST walker = null;
ForteParser parser = null;
try {
System.out.println("===== QualifiedName: " + source + " =====");
CharStream stream =
new NoCaseStringStream(source);
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokens = new CommonTokenStream(lexer);
reporter = new ErrorReporter();
parser = new ForteParser(tokens);
parser.setErrorReporter(reporter);
parser.setTokenStream(tokens);
qualifiedName_return result = parser.qualifiedName();
CommonTree tree = (CommonTree) result.getTree();
errors = parser.getNumberOfSyntaxErrors();
if (errors == 0){
if (PRINT_TREE)
System.out.println("Tree==>"+tree.toStringTree());
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
walker = new ForteAST(nodes);
walker.qualifiedName();
}
} finally {
failOnSyntaxError(source, parser, walker);
}
return errors;
}
public int testQualifiedIdentExpression(String source) throws Exception{
int errors = 0;
ForteAST walker = null;
ForteParser parser = null;
try {
System.out.println("===== QualifiedName: " + source + " =====");
CharStream stream =
new NoCaseStringStream(source);
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokens = new CommonTokenStream(lexer);
parser = new ForteParser(tokens);
parser.setTokenStream(tokens);
qualifiedIdentExpression_return result = parser.qualifiedIdentExpression();
CommonTree tree = (CommonTree) result.getTree();
errors = parser.getNumberOfSyntaxErrors();
if (errors == 0){
if (PRINT_TREE)
System.out.println("Tree==>"+tree.toStringTree());
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
nodes.setTokenStream(tokens);
walker = new ForteAST(nodes);
//walker.qualifiedIdentExpression();
}
} finally {
failOnSyntaxError(source, parser, walker);
}
return errors;
}
@Test
public void localVariableSimple() throws Exception{
testStatement("Simple local variable with init", "a : integer = 2;");
}
@Test
public void forEach() throws Exception{
testStatement("For Each",
" for p in self.PaintingData do\n" +
" if p.Name = deletedName then\n" +
" -- This is the one. Delete it.\n" +
" self.PaintingData.DeleteRow(p);\n" +
" exit;\n" +
" end if;\n" +
" end for;\n" +
"");
}
@Test
public void forCountControlled() throws Exception{
testStatement("For count controlled",
"for i in 1 to self.PaintingsUnderBid.Items do\n" +
" trc.Put(' ----BID NUMBER ');\n" +
" trc.Put(i);\n" +
" trc.PutLine('-----------------------------------');\n" +
" self.PaintingsUnderBid[i].WriteToLog();\n" +
"end for ;\n" +
"");
}
@Test
public void expressionWithLiteral() throws Exception{
testStatement("expressionWithLiteral", "begin\n" +
"/******************************************************************************\n" +
"\n" +
"NAME : __retrieveLedgerBalance\n" +
"\n" +
"DESCRIPTION : Retrieves from the database, the current balance of the\n" +
" ledger account. This passes in the ledger account number\n" +
" as an input parameter so this method can be used by other\n" +
" methods in this handler, without having to alter the\n" +
" ledger account number set on the business object.\n" +
"\n" +
"PRE CONDITION \n" +
"PARAMETERS : None\n" +
"\n" +
"POST CONDITION \n" +
"PARAMETERS : None\n" +
"\n" +
"RETURN VALUE : DecimalNullable The value of the current ledger balance\n" +
"\n" +
"EXCEPTIONS : None\n" +
"\n" +
"******************************************************************************/ \n" +
"\n" +
"lSQLText : TextData = new();\n" +
"lWhereParameters : Array of DataValue = new();\n" +
"lSummary : AccBalSummary = getAccountBalanceSummary();\n" +
"lBalance : DecimalNullable = new(IsNull = TRUE);\n" +
"lGetCurrent : boolean = FALSE;\n" +
"lResultSet : Array of Object = NIL;\n" +
"\n" +
// "lSingleQuote : String = '\\'' ;\n" +
"lTimestampFormat : TextData = new (Value= lSingleQuote) ;\n" +
"lTimestampFormat.Concat(FMT_TIMESTAMP) ;\n" +
"lTimestampFormat.Concat(lSingleQuote) ;\n" +
"\n" +
"if lSummary.dnEffectiveFromDate.IsNull then\n" +
"\n" +
" lGetCurrent = TRUE;\n" +
" \n" +
"else\n" +
"\n" +
" lGetCurrent = FALSE;\n" +
" \n" +
"end if;\n" +
"\n" +
"lSQLText.Concat(source = 'SELECT SUM(ledger_acc_bal)\\n');\n" +
"lSQLText.Concat(source = 'FROM acc_bal_summary\\n');\n" +
"lSQLText.Concat(source = 'WHERE acc_id = ?\\n');\n" +
"lSQLText.Concat(source = 'AND acc_type = ?\\n');\n" +
"lSQLText.Concat(source = 'AND ledger_acc_num = ?\\n');\n" +
"\n" +
"lWhereParameters.AppendRow(Object = DoubleData(DoubleValue = lSummary.dAccId));\n" +
"lWhereParameters.AppendRow(Object = TextData(value = lSummary.sAccType));\n" +
"lWhereParameters.AppendRow(Object = IntegerData(IntegerValue = pLedgerNumber));\n" +
"\n" +
"if lGetCurrent then\n" +
"\n" +
" lSQLText.Concat(source = 'AND (eff_to_date IS NULL)\\n');\n" +
" \n" +
"else\n" +
"\n" +
" lDateNoTime : DateTimeNullable = Date().TruncateTime(dnSeedDate = lSummary.dnEffectiveFromDate);\n" +
" \n" +
" lSQLText.Concat(source = 'AND eff_from_date <= TO_TIMESTAMP ( ? , ');\n" +
" lSQLText.Concat(lTimeStampFormat );\n" +
" lSQLText.Concat(source = ' ) ');\n" +
" lSQLText.Concat(source = 'AND (eff_to_date IS NULL OR eff_to_date >= TO_TIMESTAMP( ? , ');\n" +
" lSQLText.Concat(lTimeStampFormat);\n" +
" lSQLText.Concat(source = ' )) '); \n" +
" lWhereParameters.AppendRow(Object = lDateNoTime);\n" +
" lWhereParameters.AppendRow(Object = lDateNoTime);\n" +
"\n" +
" \n" +
"end if; \n" +
"\n" +
"// The following will return only one row because query is an aggregate\n" +
"lResultSet = FetchData(pSQLCommand = lSQLText,\n" +
" pWhereParameters = lWhereParameters,\n" +
" pAppendResultToResultObj = FALSE,\n" +
" pPopulateStyle = PS_SUM);\n" +
" \n" +
"if (lResultSet <> NIL) then\n" +
"\n" +
" lResult : DecimalNullable = (DecimalNullable)(lResultSet[1]);\n" +
" \n" +
" if (lResult <> NIL) and (not lResult.IsNull) then\n" +
" \n" +
" lBalance.SetValue(source = lResult);\n" +
" \n" +
" end if;\n" +
"\n" +
"end if;\n" +
"\n" +
"return lBalance;\n" +
"\n" +
"end;\n" +
"");
}
@Test
public void forSQL() throws Exception{
testStatement("For SQL",
"for (ptg : Painting) in " +
"sql select * from PaintingTab\n" +
" where Painter = :painter.name\n" +
" on session self.MGRSession do\n" +
" painter.ListOfPaintings.AppendRow(ptg);\n" +
"end for;"
);
}
@Test
public void eventLoop() throws Exception{
testStatement("Event Loop:", "event loop\n" +
" when task.Shutdown do\n" +
" if self.IsAuctioneer then\n" +
" -- Give up Auctioneer status. \n" +
" AuctionService.RelinquishAuctioneerStatus();\n" +
" end if;\n" +
" exit;\n" +
"\n" +
" --\n" +
" -- Events that might come in from the AuctionMgr, \n" +
" -- regarding updating of the painting list.\n" +
" --\n" +
" when AuctionService.PaintingDeleted \n" +
" (deletedName=paintingName) do\n" +
" --\n" +
" -- A row from the array is to be deleted. Find it \n" +
" -- and remove. If it is being displayed, the \n" +
" -- corresponding ViewPainting window will get the \n" +
" -- event as well, and close down.\n" +
" for p in self.PaintingData do\n" +
" if p.Name = deletedName then\n" +
" -- This is the one. Delete it.\n" +
" self.PaintingData.DeleteRow(p);\n" +
" exit;\n" +
" end if;\n" +
" end;\n" +
"end event;");
}
@Test
public void eventWhen() throws Exception{
CharStream stream =
new NoCaseStringStream(
" when task.Shutdown do\n" +
" if self.IsAuctioneer then\n" +
" -- Give up Auctioneer status. \n" +
" AuctionService.RelinquishAuctioneerStatus();\n" +
" end if;\n" +
" exit;\n" +
"\n" +
" --\n" +
" -- Events that might come in from the AuctionMgr, \n" +
" -- regarding updating of the painting list.\n" +
" --\n" +
" when AuctionService.PaintingDeleted \n" +
" (deletedName=paintingName) do\n" +
" --\n" +
" -- A row from the array is to be deleted. Find it \n" +
" -- and remove. If it is being displayed, the \n" +
" -- corresponding ViewPainting window will get the \n" +
" -- event as well, and close down.\n" +
" for p in self.PaintingData do\n" +
" if p.Name = deletedName then\n" +
" -- This is the one. Delete it.\n" +
" self.PaintingData.DeleteRow(p);\n" +
" exit;\n" +
" end if;\n" +
" end for;\n"
);
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
CommonTree tree = (CommonTree) parser.whenss().getTree();
System.out.println(tree.toStringTree());
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("eventWhen " + errors + " errors");
}
}
@Test
public void assignmentStatement_1() throws Exception{
CharStream stream =
new NoCaseStringStream("self.legs(34).value = 7;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("assignmentStatement completed with " + errors + " errors");
}
}
@Test
public void assignmentStatement_2() throws Exception{
CharStream stream =
new NoCaseStringStream("self.legs[34].value = 7;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("assignmentStatement_2 completed with " + errors + " errors");
}
}
@Test
public void assignmentStatement_3() throws Exception{
CharStream stream =
new NoCaseStringStream("self.legs[34] = 7;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("assignmentStatement completed with " + errors + " errors");
}
}
@Test
public void simpleMethodInvocationStatement() throws Exception{
CharStream stream =
new NoCaseStringStream("__PutProperty(17,OLE.VariantI2(Value='Action'));");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("simpleMethodInvocationStatement completed with " + errors + " errors");
}
}
@Test
public void ifStatement_1() throws Exception{
CharStream stream =
new NoCaseStringStream("if a then\n" +
"x = y;" +
"end if;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("ifStatement_1 completed with " + errors + " errors");
}
}
@Test
public void ifStatement_2() throws Exception{
CharStream stream =
new NoCaseStringStream("if a = b then\n" +
"x = y;" +
"end if;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("ifStatement_2 completed with " + errors + " errors");
}
}
@Test
public void ifStatement_3() throws Exception{
CharStream stream =
new NoCaseStringStream("if p.Name = deletedName then\n" +
" -- This is the one. Delete it.\n" +
" self.PaintingData.DeleteRow(p);\n" +
" exit;\n" +
" end if;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("ifStatement_3 completed with " + errors + " errors");
}
}
@Test
public void ifStatement_4() throws Exception{
CharStream stream =
new NoCaseStringStream("if (a = b) and bob then\n" +
// "x = y;" +
"end if;");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("ifStatement_4 completed with " + errors + " errors");
}
}
@Test
public void ifStatement_5() throws Exception{
CharStream stream =
new NoCaseStringStream(
" if (PreferenceList[i].WindowName.ToUpper().Value = pWindow) \r\n" +
" AND (PreferenceList[i].PreferenceName.ToUpper().Value = pPreferenceName) " +
" then\r\n" +
" PreferenceList[i].PreferenceValue.SetValue(pPreferenceValue);\r\n" +
" ReturnObj = PreferenceList[i].Clone(TRUE);\r\n" +
" found = TRUE;\r\n" +
" exit;\r\n" +
" end if;\r\n");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("ifStatement_5 completed with " + errors + " errors");
}
}
@Test
public void startTaskStatement_simple() throws Exception{
CharStream stream =
new NoCaseStringStream("start task theBid.StartBid();\n");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("startTaskStatement_simplest completed with " + errors + " errors");
}
}
@Test
public void startTaskStatement_Event() throws Exception{
CharStream stream =
new NoCaseStringStream("start task theBid.StartBid(\n" +
" bidderName = theUserName,\n" +
" bidValue = theBidValue,\n" +
" lastBidTime = theLastBidTime,\n" +
" bidInProgress = theBidInProgress)\n" +
" where completion = event;\n");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("startTaskStatement_simple completed with " + errors + " errors");
}
}
@Test
public void startTaskStatement_Event_Transaction() throws Exception{
CharStream stream =
new NoCaseStringStream("start task self.theBid.StartBid(\n" +
" bidderName = self.theUserName,\n" +
" bidValue = self.theBidValue,\n" +
" lastBidTime = self.theLastBidTime,\n" +
" bidInProgress = self.theBidInProgress)\n" +
" where completion = event, transaction = dependent;\n");
ForteLexer lexer = new ForteLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
ForteParser parser = new ForteParser(tokenStream);
parser.statement();
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0){
Assert.fail("startTaskStatement completed with " + errors + " errors");
}
}
@Test
public void startTaskStatement_Event_EventDesc() throws Exception{
testStatement("TaskStatement_Event_EventDesc",
"" +
" bidding_task : TaskDesc;\n" +
" bidding_task = start task self.theBid.StartBid(\n" +
" bidderName = self.theUserName,\n" +
" bidValue = self.theBidValue,\n" +
" lastBidTime = self.theLastBidTime,\n" +
" bidInProgress = self.theBidInProgress);\n" +
" where completion = event, transaction = dependent;\n" +
"");
}
@Test
public void method_invocation() throws Exception{
testStatement("method_invocation",
" bidding_task = start task self.theBid.StartBid(\n" +
" bidderName = self.theUserName,\n" +
" bidValue = self.theBidValue,\n" +
" lastBidTime = self.theLastBidTime,\n" +
" bidInProgress = self.theBidInProgress);\n" +
"");
}
@Test
public void startTaskStatement() throws Exception{
testStatement("startTaskStatement",
" bidding_task : TaskDesc;\n" +
" bidding_task = start task self.theBid.StartBid(\n" +
" bidderName = self.theUserName,\n" +
" bidValue = self.theBidValue,\n" +
" lastBidTime = self.theLastBidTime,\n" +
" bidInProgress = self.theBidInProgress)\n" +
" where completion = event, transaction = dependent;\n" +
"");
}
@Test
public void startTaskStatement_block() throws Exception{
testStatement("startTaskStatement_block",
"begin" +
" bidding_task : TaskDesc;\n" +
" bidding_task = start task self.theBid.StartBid(\n" +
" bidderName = self.theUserName,\n" +
" bidValue = self.theBidValue,\n" +
" lastBidTime = self.theLastBidTime,\n" +
" bidInProgress = self.theBidInProgress)\n" +
" where completion = event, transaction = dependent;\n" +
"end;");
}
@Test
public void beginTransaction() throws Exception{
testStatement("block",
"begin transaction\n" +
" -- Specify some output parameters, even though \n" +
" -- they will not be filled in here, but will be \n" +
" -- filled in on the StartBid_return event.\n" +
" ptg : Painting;\n" +
" bidding_task : TaskDesc;\n" +
" theMessage = 'Waiting for bid to become available.';\n" +
"\n" +
"end transaction;");
}
@Test
public void beginDependentTransaction() throws Exception{
testStatement("DependentTransaction",
"begin dependent transaction\n" +
"end transaction;");
}
@Test
public void beginNestedTransaction() throws Exception{
testStatement("NestedTransaction",
"begin nested transaction\n" +
"end transaction;");
}
@Test
public void beginIndependentTransaction() throws Exception{
testStatement("IndependentTransaction",
"begin independent transaction\n" +
"end transaction;");
}
@Test
public void windowQualifiedName() throws Exception{
testQualifiedName("<Bob.IncreaseButton>.state");
}
@Test
public void windowAttributeExpression() throws Exception{
testExpression("window Attribute", "<IncreaseButton>.state = FS_UPDATE;");
}
@Test
public void beginTransactionStatement() throws Exception{
testStatement("block",
"begin transaction do\n" +
" -- Specify some output parameters, even though \n" +
" -- they will not be filled in here, but will be \n" +
" -- filled in on the StartBid_return event.\n" +
" ptg : Painting;\n" +
" bidding_task : TaskDesc;\n" +
" theMessage = 'Waiting for bid to become available.';\n" +
"\n" +
" event loop\n" +
" when self.theBid.StartBid_return (\n" +
" nvalue = bidValue, ntime = lastBidTime,\n" +
" nprogress = bidInProgress, nname = return) do\n" +
" -- The lock has been granted. \n" +
" -- Now let the OK button\n" +
" -- and updates on the bid amount be allowed.\n" +
" theMessage = 'Bid lock granted to you.';\n" +
" \n" +
" <IncreaseButton>.State = FS_UPDATE;\n" +
" <OKButton>.State = FS_UPDATE;\n" +
"\n" +
" -- Set the data again (just to be sure).\n" +
" self.theOriginalBidValue = nvalue;\n" +
" self.theBidValue = nvalue;\n" +
" self.theLastBidTime.SetValue(ntime);\n" +
" self.theBidInProgress = nprogress;\n" +
" self.hasBidLock = TRUE;\n" +
"\n" +
" when self.theBid.StartBid_exception (e = exception) \n" +
" do\n" +
" -- Add the exception to the errors for this task, \n" +
" -- and then re-raise the exception to get out.\n" +
" task.ErrorMgr.AddError(GenericException(e));\n" +
" raise e;\n" +
"\n" +
" -- Process the button clicks that might occur\n" +
" when <OKButton>.Click do\n" +
" -- This completes the bid, commits the \n" +
" -- transaction and gets out.\n" +
" self.theBid.CompleteBid (bid = theBidValue);\n" +
" exit;\n" +
"\n" +
" when task.Shutdown do\n" +
" if self.hasBidLock then\n" +
" post self.theBid.BidCancelled;\n" +
" self.theBidValue = self.theOriginalBidValue;\n" +
" end if;\n" +
" transaction.Abort(TRUE);\n" +
" exit;\n" +
"\n" +
" when <CancelButton>.Click do\n" +
" -- This cancels the bid by aborting the \n" +
" -- transaction. This will drop out of the event \n" +
" -- loop and into the exception section of the \n" +
" -- transaction.\n" +
" if self.hasBidLock then\n" +
" post self.theBid.BidCancelled;\n" +
" self.theBidValue = self.theOriginalBidValue;\n" +
" end if;\n" +
" transaction.Abort(TRUE);\n" +
" exit;\n" +
"\n" +
" when <IncreaseButton>.Click do\n" +
" -- Increase by the minimum.\n" +
" self.theBidValue = self.theBidValue + 50000;\n" +
"\n" +
" -- Process the update events on the data.\n" +
" when self.theBid.BidCompleted (nBid = newBid, \n" +
" tBid = timeOfBid, wBid = whoBid) do\n" +
" self.theOriginalBidValue = nBid;\n" +
" self.theBidValue = nBid;\n" +
" self.theLastBidTime.SetValue(tBid);\n" +
" self.theLastBidder = wBid;\n" +
" -- If this is the last concurrent bidder, the \n" +
" -- GotLock event will arrive right after this.\n" +
" end event;\n" +
"\n" +
"exception -- For the transaction\n" +
" when e : GenericException do\n" +
" -- Transaction is aborted. Get out.\n" +
" task.ErrMgr.ShowErrors(TRUE);\n" +
"\n" +
" when e : AbortException do\n" +
" task.ErrMgr.Clear(); -- Do not show errors.\n" +
"end transaction; -- Commits transaction.\n" +
"");
}
@Test
public void sqlSelect() throws Exception{
testStatement("SQl select",
"begin\n" +
"sql SELECT transferred_amt\n" +
" INTO :lTranserredAmt\n" +
" FROM actual_bank_reconciliation \n" +
" WHERE actual_bank_rec_id = :theInterBankTransferHistory.dActualBankRecId\n" +
" AND expected_bank_rec_id = :theInterBankTransferHistory.dExpectedBankRecId\n" +
" ON SESSION SessionToUse;\n" +
"end;");
}
@Test
public void sqlImmediate() throws Exception{
testStatement("SQl immediate",
"begin\n" +
"sql execute immediate \n" +
" 'create table ArtistTab(Name varchar(30) not null, Country varchar(30) not null, Comments varchar(200) not null)'\n" +
" on session self.MGRSession;\n" +
"end;");
}
@Test
public void sqlInsert() throws Exception{
testStatement("SQL insert",
"begin\n" +
"sql insert into ArtistTab values (:artists) \n" +
" on session self.MGRSession;" +
"end;");
}
@Test
public void sqlOpenCursor() throws Exception{
testStatement("SQl open cursor",
"begin\n" +
"sql open cursor blobCurs(name) on session self.MGRSession;\n" +
"end;");
}
@Test
public void sqlUpdate() throws Exception{
testStatement("SQl update",
"begin\n" +
" sql UPDATE actual_bank_rec\n" +
" SET inter_bank_transfer_ind = 0\n" +
" WHERE actual_bank_rec_id = :theInterBankTransferHistory.dActualBankRecId\n" +
" ON SESSION SessionToUse;\n"+
"end;");
}
@Test
public void sqlFetchCursor() throws Exception{
testStatement("SQl fetch cursor", "begin\n" +
"sql fetch cursor blobCurs into :binData;\n" +
"end;" );
}
@Test
public void sqlCloseCursor() throws Exception{
testStatement("SQl close cursor", "begin\n" +
"sql close cursor blobCurs;\n" +
"end;");
}
@Test
public void localDeclarationExpression() throws Exception{
testExpression("localDeclaration expression", "a:b='\\''");
}
@Test
public void localDeclarationStatement() throws Exception{
testStatement("localDeclaration statement", "a:b='\\'';");
}
@Test
public void selectWithRowCount() throws Exception{
testStatement("selectWithRowCount", "begin\n" +
"iRowsReturned = (\n" +
" SQL UPDATE allocated_EFT_prod\n" +
" SET \n" +
" REG_CLIENT_ID = :eft.RegClientID,\n" +
" REG_PROD_ID = :eft.RegProdID,\n" +
" DATA_MASSAGING_TYPE = :eft.DataMessagingType,\n" +
" BNK_SVC_CODE = :eft.BankServiceCode,\n" +
" DESCRPTN = :eft.Description,\n" +
" EFF_FROM_DATE = TO_TIMESTAMP(:eft.EffFromDate, :lTimestampFormat),\n" +
" EFF_TO_DATE = TO_TIMESTAMP(:eft.EffToDate, :lTimestampFormat),\n" +
" UPDATED_BY = :lUserId,\n" +
" LOCK_COUNT = :eft.LockCount + 1\n" +
" \n" +
" WHERE ALLOCATED_EFT_PROD_ID = :eft.AllocatedEFTProdID\n" +
" AND lock_count = :EFT.LockCount\n" +
" \n" +
" ON SESSION SessionToUse);\n" +
"end;");
}
@Test
public void escapedQuote() throws Exception{
testStatement("escapedQuote", "lSingleQuote : String = '\\''");
}
}