equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
17 */ |
17 */ |
18 |
18 |
19 |
19 |
20 #include "UniqueInstanceImpl.h" |
20 #include "UniqueInstanceImpl.h" |
21 #include <e32test.h> |
21 #include <e32test.h> |
22 #include "tunique.h" |
|
23 |
22 |
24 using namespace UniqueInstance; |
23 using namespace UniqueInstance; |
25 |
24 |
26 #define UNUSED_VAR(a) a = a |
25 #define UNUSED_VAR(a) a = a |
27 |
26 |
45 { |
44 { |
46 delete reinterpret_cast<TInt*>(a); |
45 delete reinterpret_cast<TInt*>(a); |
47 } |
46 } |
48 void DeleteTInt(TInt* a) { delete a; } |
47 void DeleteTInt(TInt* a) { delete a; } |
49 |
48 |
50 CTUniqueStep* TestStep; |
49 CTrapCleanup* TrapCleanup; |
51 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__) |
50 RTest test(_L("TUnique - Unique instance repository tests")); |
52 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__) |
|
53 } |
51 } |
54 |
52 |
55 ///////////////// |
53 ///////////////// |
56 // // |
54 // // |
57 // RSkipList // |
55 // RSkipList // |
62 { |
60 { |
63 TInt TestEmpty(RSkipList& a) |
61 TInt TestEmpty(RSkipList& a) |
64 { |
62 { |
65 if (!a.IsEmpty()) |
63 if (!a.IsEmpty()) |
66 { |
64 { |
67 TESTPRINT(_L("RSkipList : unexpectedly has elements")); |
65 test.Printf(_L("RSkipList : unexpectedly has elements")); |
68 return 1; |
66 return 1; |
69 } |
67 } |
70 return 0; |
68 return 0; |
71 } |
69 } |
72 TInt TestAddL(RSkipList& a, void* aElt, TInt aExpectedRefCount) |
70 TInt TestAddL(RSkipList& a, void* aElt, TInt aExpectedRefCount) |
74 SElement* e = a.AddExisting(aElt); |
72 SElement* e = a.AddExisting(aElt); |
75 if (!e) |
73 if (!e) |
76 e = a.AddNewL(aElt); |
74 e = a.AddNewL(aElt); |
77 if (CompareVoids(e->iObject,aElt)) |
75 if (CompareVoids(e->iObject,aElt)) |
78 { |
76 { |
79 TESTPRINT(_L("RSkipList : added element does not compare equal to returned value")); |
77 test.Printf(_L("RSkipList : added element does not compare equal to returned value")); |
80 return 1; |
78 return 1; |
81 } |
79 } |
82 if (e->iRefCount != aExpectedRefCount) |
80 if (e->iRefCount != aExpectedRefCount) |
83 { |
81 { |
84 TESTPRINT(_L("RSkipList : unexpected reference count")); |
82 test.Printf(_L("RSkipList : unexpected reference count")); |
85 return 1; |
83 return 1; |
86 } |
84 } |
87 return 0; |
85 return 0; |
88 } |
86 } |
89 TInt TestRemove(RSkipList& a, void* aElt) |
87 TInt TestRemove(RSkipList& a, void* aElt) |
90 { |
88 { |
91 if (CompareVoids(a.Remove(aElt), aElt)) |
89 if (CompareVoids(a.Remove(aElt), aElt)) |
92 { |
90 { |
93 TESTPRINT(_L("RSkipList : removed element does not compare equal to returned value")); |
91 test.Printf(_L("RSkipList : removed element does not compare equal to returned value")); |
94 return 1; |
92 return 1; |
95 } |
93 } |
96 return 0; |
94 return 0; |
97 } |
95 } |
98 void Test(RSkipList& a) |
96 void Test(RSkipList& a) |
516 { |
514 { |
517 TInt TestObject(SElement* e, TInt val) |
515 TInt TestObject(SElement* e, TInt val) |
518 { |
516 { |
519 if (!e->iObject) |
517 if (!e->iObject) |
520 { |
518 { |
521 TESTPRINT(_L("CRepositoryImpl : object undefined")); |
519 test.Printf(_L("CRepositoryImpl : object undefined")); |
522 return 1; |
520 return 1; |
523 } |
521 } |
524 if (*reinterpret_cast<TInt*>(e->iObject) != val) |
522 if (*reinterpret_cast<TInt*>(e->iObject) != val) |
525 { |
523 { |
526 TESTPRINT(_L("CRepositoryImpl : object has wrong value")); |
524 test.Printf(_L("CRepositoryImpl : object has wrong value")); |
527 return 1; |
525 return 1; |
528 } |
526 } |
529 return 0; |
527 return 0; |
530 } |
528 } |
531 void TestCRepositoryImplL() |
529 void TestCRepositoryImplL() |
550 z = new(ELeave) TInt(0); |
548 z = new(ELeave) TInt(0); |
551 SElement* z3ui = rep->IncOrCopyL(z); |
549 SElement* z3ui = rep->IncOrCopyL(z); |
552 delete z; |
550 delete z; |
553 |
551 |
554 // test equal objects are nullified |
552 // test equal objects are nullified |
555 TESTPOINT(zui->iObject == z2ui->iObject); |
553 test(zui->iObject == z2ui->iObject); |
556 TESTPOINT(zui->iObject == z0ui->iObject); |
554 test(zui->iObject == z0ui->iObject); |
557 TESTPOINT(zui->iObject == z3ui->iObject); |
555 test(zui->iObject == z3ui->iObject); |
558 |
556 |
559 rep->DeleteOrDec(z0ui); |
557 rep->DeleteOrDec(z0ui); |
560 rep->DeleteOrDec(z3ui); |
558 rep->DeleteOrDec(z3ui); |
561 |
559 |
562 TestObject(zui, 0); |
560 TestObject(zui, 0); |
571 z = reinterpret_cast<TInt*>(rep->DetatchOrCopyL(zui)); |
569 z = reinterpret_cast<TInt*>(rep->DetatchOrCopyL(zui)); |
572 z2 = reinterpret_cast<TInt*>(rep->DetatchOrCopyL(z2ui)); |
570 z2 = reinterpret_cast<TInt*>(rep->DetatchOrCopyL(z2ui)); |
573 rep->DeleteOrDec(p8765ui); |
571 rep->DeleteOrDec(p8765ui); |
574 |
572 |
575 // test that copyable objects are not aliased |
573 // test that copyable objects are not aliased |
576 TESTPOINT(z != z2); |
574 test(z != z2); |
577 // test that a valid copy is returned |
575 // test that a valid copy is returned |
578 TESTPOINT(*z == 0); |
576 test(*z == 0); |
579 TESTPOINT(*z2 == 0); |
577 test(*z2 == 0); |
580 |
578 |
581 delete z; |
579 delete z; |
582 delete z2; |
580 delete z2; |
583 |
581 |
584 delete rep; |
582 delete rep; |
598 { |
596 { |
599 TInt TestNull(const RUniqueInstance<TInt>& a) |
597 TInt TestNull(const RUniqueInstance<TInt>& a) |
600 { |
598 { |
601 if (a.Peek()) |
599 if (a.Peek()) |
602 { |
600 { |
603 TESTPRINT(_L("RUniqueInstance : null object has value")); |
601 test.Printf(_L("RUniqueInstance : null object has value")); |
604 return 1; |
602 return 1; |
605 } |
603 } |
606 return 0; |
604 return 0; |
607 } |
605 } |
608 TInt TestValue(const RUniqueInstance<TInt>& a, TInt val) |
606 TInt TestValue(const RUniqueInstance<TInt>& a, TInt val) |
609 { |
607 { |
610 if (!a.Peek()) |
608 if (!a.Peek()) |
611 { |
609 { |
612 TESTPRINT(_L("RUniqueInstance : unexpected null object")); |
610 test.Printf(_L("RUniqueInstance : unexpected null object")); |
613 return 1; |
611 return 1; |
614 } |
612 } |
615 if (*a.Peek() != val) |
613 if (*a.Peek() != val) |
616 { |
614 { |
617 TESTPRINT(_L("RUniqueInstance : object has wrong value")); |
615 test.Printf(_L("RUniqueInstance : object has wrong value")); |
618 return 1; |
616 return 1; |
619 } |
617 } |
620 return 0; |
618 return 0; |
621 } |
619 } |
622 TInt TestRaw(TInt* ob, TInt val) |
620 TInt TestRaw(TInt* ob, TInt val) |
623 { |
621 { |
624 if (!ob) |
622 if (!ob) |
625 { |
623 { |
626 TESTPRINT(_L("RUniqueInstance : object unexpectedly does not own")); |
624 test.Printf(_L("RUniqueInstance : object unexpectedly does not own")); |
627 return 1; |
625 return 1; |
628 } |
626 } |
629 if (*ob != val) |
627 if (*ob != val) |
630 { |
628 { |
631 TESTPRINT(_L("RUniqueInstance : object owns incorrect value")); |
629 test.Printf(_L("RUniqueInstance : object owns incorrect value")); |
632 return 1; |
630 return 1; |
633 } |
631 } |
634 return 0; |
632 return 0; |
635 } |
633 } |
636 void TestRUniqueInstanceL() |
634 void TestRUniqueInstanceL() |
647 a.TakeL(new(ELeave) TInt(45)); |
645 a.TakeL(new(ELeave) TInt(45)); |
648 b.TakeL(new(ELeave) TInt(-6)); |
646 b.TakeL(new(ELeave) TInt(-6)); |
649 c.TakeL(new(ELeave) TInt(45)); |
647 c.TakeL(new(ELeave) TInt(45)); |
650 |
648 |
651 // test that equal elements are unified |
649 // test that equal elements are unified |
652 TESTPOINT(a.Peek() == c.Peek()); |
650 test(a.Peek() == c.Peek()); |
653 |
651 |
654 TestValue(a, 45); |
652 TestValue(a, 45); |
655 TestValue(b, -6); |
653 TestValue(b, -6); |
656 TestValue(c, 45); |
654 TestValue(c, 45); |
657 |
655 |
727 TestValue(d, 123); |
725 TestValue(d, 123); |
728 e.MoveTo(a); |
726 e.MoveTo(a); |
729 e.TakeL(new(ELeave) TInt(18)); |
727 e.TakeL(new(ELeave) TInt(18)); |
730 |
728 |
731 // test that equal objects are unified |
729 // test that equal objects are unified |
732 TESTPOINT(a.Peek() == e.Peek()); |
730 test(a.Peek() == e.Peek()); |
733 |
731 |
734 d.TakeL(new(ELeave) TInt(-445)); |
732 d.TakeL(new(ELeave) TInt(-445)); |
735 |
733 |
736 // test that equal objects are unified |
734 // test that equal objects are unified |
737 TESTPOINT(b.Peek() == d.Peek()); |
735 test(b.Peek() == d.Peek()); |
738 |
736 |
739 a.TakeL(new(ELeave) TInt(-445)); |
737 a.TakeL(new(ELeave) TInt(-445)); |
740 |
738 |
741 // test that objects from different repositories are not unified |
739 // test that objects from different repositories are not unified |
742 TESTPOINT(a.Peek() != b.Peek()); |
740 test(a.Peek() != b.Peek()); |
743 |
741 |
744 a.Close(); |
742 a.Close(); |
745 |
743 |
746 // test that destroyed object peeks null |
744 // test that destroyed object peeks null |
747 TESTPOINT(a.Peek() == 0); |
745 test(a.Peek() == 0); |
748 |
746 |
749 b.MoveTo(c); |
747 b.MoveTo(c); |
750 b.Close(); |
748 b.Close(); |
751 c.Close(); |
749 c.Close(); |
752 d.Close(); |
750 d.Close(); |
764 // // |
762 // // |
765 // Main // |
763 // Main // |
766 // // |
764 // // |
767 //////////// |
765 //////////// |
768 |
766 |
769 TVerdict CTUniqueStep::doTestStepL() |
767 void RunTests() |
770 { |
768 { |
771 SetTestStepResult(EPass); |
769 __UHEAP_MARK; |
772 TestStep = this; |
770 test.Title(); |
773 TESTPRINT(_L("TUnique - Unique instance repository tests")); |
771 test.Start(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-UNIQUE-0001 Unique Instance Tests: ")); |
774 TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-UNIQUE-0001 Unique Instance Tests: ")); |
|
775 |
772 |
776 TestRSkipListL(); |
773 TestRSkipListL(); |
777 TestCRepositoryImplL(); |
774 TestCRepositoryImplL(); |
778 TestRUniqueInstanceL(); |
775 TestRUniqueInstanceL(); |
779 |
776 |
780 return TestStepResult(); |
777 test.End(); |
781 } |
778 test.Close(); |
|
779 |
|
780 __UHEAP_MARKENDC(0); |
|
781 } |
|
782 |
|
783 TInt E32Main() |
|
784 { |
|
785 TrapCleanup = CTrapCleanup::New(); |
|
786 TRAPD(err, RunTests()); |
|
787 test(err == KErrNone); |
|
788 delete TrapCleanup; |
|
789 return 0; |
|
790 } |