equal
deleted
inserted
replaced
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
73 // deleted. |
73 // deleted. |
74 LOCAL_C void Check(TInt aValue, TInt aLine) |
74 LOCAL_C void Check(TInt aValue, TInt aLine) |
75 { |
75 { |
76 if(!aValue) |
76 if(!aValue) |
77 { |
77 { |
|
78 TheTest.Printf(_L("*** Expression evaluated to false\r\n")); |
78 TestCleanup(); |
79 TestCleanup(); |
79 TheTest(EFalse, aLine); |
80 TheTest(EFalse, aLine); |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
85 // will be deleted. |
86 // will be deleted. |
86 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) |
87 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) |
87 { |
88 { |
88 if(aValue != aExpected) |
89 if(aValue != aExpected) |
89 { |
90 { |
90 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
91 TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
91 TestCleanup(); |
92 TestCleanup(); |
92 TheTest(EFalse, aLine); |
93 TheTest(EFalse, aLine); |
93 } |
94 } |
94 } |
95 } |
95 |
96 |
446 TheTest.Next(_L("Test for valid LIKE predicate queries")); |
447 TheTest.Next(_L("Test for valid LIKE predicate queries")); |
447 |
448 |
448 |
449 |
449 for(TInt i =0;i<KNumQueries;++i) |
450 for(TInt i =0;i<KNumQueries;++i) |
450 { |
451 { |
451 RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query)); |
452 TheTest.Printf(_L("Executing statement: %s \n"),(KQuery[i].query)); |
452 RDbView view; |
453 RDbView view; |
453 view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly); |
454 view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly); |
454 view.EvaluateAll(); |
455 view.EvaluateAll(); |
455 view.FirstL(); |
456 view.FirstL(); |
456 typedef TBuf<256> TScriptLine; |
457 typedef TBuf<256> TScriptLine; |
462 RDbColReadStream rd; |
463 RDbColReadStream rd; |
463 rd.OpenLC(view,1); |
464 rd.OpenLC(view,1); |
464 TScriptLine text; |
465 TScriptLine text; |
465 rd.ReadL(text,view.ColLength(1)); |
466 rd.ReadL(text,view.ColLength(1)); |
466 CleanupStack::PopAndDestroy(); |
467 CleanupStack::PopAndDestroy(); |
467 RDebug::Print(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&text); |
468 TheTest.Printf(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&text); |
468 TInt err = text.Compare(TPtrC(KQuery[i].result)); |
469 TInt err = text.Compare(TPtrC(KQuery[i].result)); |
469 TheTest(err ==0); |
470 TheTest(err ==0); |
470 view.NextL(); |
471 view.NextL(); |
471 } |
472 } |
472 view.Close(); |
473 view.Close(); |
477 TheTest.Next(_L("Test that illegal queries return KErrArgument")); |
478 TheTest.Next(_L("Test that illegal queries return KErrArgument")); |
478 |
479 |
479 |
480 |
480 for(TInt j =0;j<KNumBadQueries;++j) |
481 for(TInt j =0;j<KNumBadQueries;++j) |
481 { |
482 { |
482 RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query)); |
483 TheTest.Printf(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query)); |
483 RDbView view; |
484 RDbView view; |
484 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly); |
485 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly); |
485 TheTest(prepErr==KErrArgument); |
486 TheTest(prepErr==KErrArgument); |
486 view.Close(); |
487 view.Close(); |
487 } |
488 } |
540 TheTest.Next(_L("Test for valid LIKE predicate queries")); |
541 TheTest.Next(_L("Test for valid LIKE predicate queries")); |
541 |
542 |
542 |
543 |
543 for(TInt i =0;i<KNumQueries;++i) |
544 for(TInt i =0;i<KNumQueries;++i) |
544 { |
545 { |
545 RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query)); |
546 TheTest.Printf(_L("Executing statement: %s \n"),(KQuery[i].query)); |
546 RDbView view; |
547 RDbView view; |
547 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly); |
548 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly); |
548 TheTest(prepErr>=0); |
549 TheTest(prepErr>=0); |
549 TInt evErr = view.EvaluateAll(); |
550 TInt evErr = view.EvaluateAll(); |
550 TheTest(evErr==0); |
551 TheTest(evErr==0); |
558 view.GetL(); |
559 view.GetL(); |
559 RDbColReadStream rd; |
560 RDbColReadStream rd; |
560 rd.OpenLC(view,1); |
561 rd.OpenLC(view,1); |
561 rd.ReadL(colname,view.ColLength(1)); |
562 rd.ReadL(colname,view.ColLength(1)); |
562 CleanupStack::PopAndDestroy(); |
563 CleanupStack::PopAndDestroy(); |
563 RDebug::Print(_L("Expected result: %S Actual Result: %S\n"),&result,&colname); |
564 TheTest.Printf(_L("Expected result: %S Actual Result: %S\n"),&result,&colname); |
564 TInt err = colname.CompareF(result); |
565 TInt err = colname.CompareF(result); |
565 TheTest(err ==0); |
566 TheTest(err ==0); |
566 |
567 |
567 view.NextL(); |
568 view.NextL(); |
568 } |
569 } |
575 |
576 |
576 |
577 |
577 |
578 |
578 for(TInt j =0;j<KNumBadQueries;++j) |
579 for(TInt j =0;j<KNumBadQueries;++j) |
579 { |
580 { |
580 RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query)); |
581 TheTest.Printf(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query)); |
581 RDbView view; |
582 RDbView view; |
582 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly); |
583 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly); |
583 TheTest(prepErr==KErrArgument); |
584 TheTest(prepErr==KErrArgument); |
584 |
585 |
585 view.Close(); |
586 view.Close(); |
639 TheTest.Next(_L("Test for valid LIKE predicate queries")); |
640 TheTest.Next(_L("Test for valid LIKE predicate queries")); |
640 |
641 |
641 |
642 |
642 for(TInt i =0;i<KNumQueries;++i) |
643 for(TInt i =0;i<KNumQueries;++i) |
643 { |
644 { |
644 RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query)); |
645 TheTest.Printf(_L("Executing statement: %s \n"),(KQuery[i].query)); |
645 RDbView view; |
646 RDbView view; |
646 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly); |
647 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly); |
647 if(TPtrC(KQuery[i].result).Length() == 0) |
648 if(TPtrC(KQuery[i].result).Length() == 0) |
648 { |
649 { |
649 TheTest(prepErr != KErrNone); |
650 TheTest(prepErr != KErrNone); |
657 while (view.AtRow()) |
658 while (view.AtRow()) |
658 { |
659 { |
659 view.GetL(); |
660 view.GetL(); |
660 colname = view.ColDes(1); |
661 colname = view.ColDes(1); |
661 res= KQuery[i].result; |
662 res= KQuery[i].result; |
662 RDebug::Print(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&colname); |
663 TheTest.Printf(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&colname); |
663 TInt err = colname.Compare(TPtrC(KQuery[i].result)); |
664 TInt err = colname.Compare(TPtrC(KQuery[i].result)); |
664 TheTest(err ==0); |
665 TheTest(err ==0); |
665 view.NextL(); |
666 view.NextL(); |
666 } |
667 } |
667 view.Close(); |
668 view.Close(); |
670 // test for illegal statements, check they return KErrArgument |
671 // test for illegal statements, check they return KErrArgument |
671 TheTest.Next(_L("Test that illegal queries return KErrArgument")); |
672 TheTest.Next(_L("Test that illegal queries return KErrArgument")); |
672 |
673 |
673 for(TInt j =0;j<KNumBadQueries;++j) |
674 for(TInt j =0;j<KNumBadQueries;++j) |
674 { |
675 { |
675 RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query)); |
676 TheTest.Printf(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query)); |
676 RDbView view; |
677 RDbView view; |
677 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly); |
678 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly); |
678 TheTest(prepErr==KErrArgument); |
679 TheTest(prepErr==KErrArgument); |
679 view.Close(); |
680 view.Close(); |
680 } |
681 } |
1272 while(view.NextL()) |
1273 while(view.NextL()) |
1273 { |
1274 { |
1274 view.GetL(); |
1275 view.GetL(); |
1275 TPtrC t1 = view.ColDes(1); |
1276 TPtrC t1 = view.ColDes(1); |
1276 TPtrC t2 = view.ColDes(2); |
1277 TPtrC t2 = view.ColDes(2); |
1277 RDebug::Print(_L("T1=\"%S\", T2=\"%S\"\r\n"), &t1, &t2); |
1278 TheTest.Printf(_L("T1=\"%S\", T2=\"%S\"\r\n"), &t1, &t2); |
1278 ++cnt; |
1279 ++cnt; |
1279 } |
1280 } |
1280 view.Close(); |
1281 view.Close(); |
1281 TEST2(cnt, 1); |
1282 TEST2(cnt, 1); |
1282 |
1283 |