diff --git a/tests/lib/item-wrapper-test.cpp b/tests/lib/item-wrapper-test.cpp index e341fd115..b7532ef4b 100644 --- a/tests/lib/item-wrapper-test.cpp +++ b/tests/lib/item-wrapper-test.cpp @@ -29,10 +29,11 @@ #include "lib/wrapper.hpp" //#include +#include #include -//#include #include #include +#include @@ -45,7 +46,8 @@ namespace test{ using util::isSameObject; // using util::for_each; // using util::isnil; -// using std::vector; + using std::tr1::bind; + using std::vector; using std::string; using lib::test::randStr; using lib::test::showSizeof; @@ -113,6 +115,8 @@ namespace test{ verifySaneInstanceHandling(); verifyWrappedRef (); + + verifyFunctionResult (); } @@ -225,7 +229,39 @@ namespace test{ } - + /** @test verify an extension built on top of the ItemWrapper: + * a function which remembers the last result */ + void + verifyFunctionResult() + { + vector testVec; + for (uint i=0; i<10; ++i) + testVec.push_back(i); + + FunctionResult funRes (bind (&vector::at, _1 )); + + // function was never invoked, thus the remembered result is NIL + ASSERT (!funRes); + VERIFY_ERROR (BOTTOM_VALUE, *funRes ); + + int& r5 = funRes (5); + ASSERT (5 == r5); + ASSERT (isSameObject (r5, testVec[5])); + + int r5x = *funRes; + ASSERT (isSameObject (r5, r5x)); + + ASSERT ( isSameObject (r5, *funRes)); + int r7 = funRes (7); + ASSERT (!isSameObject (r5, *funRes)); + ASSERT (!isSameObject (r7, *funRes)); + + -- r5x; + ++ *funRes; + ASSERT (5+1 == testVec[5]); + ASSERT (7+1 == testVec[7]); + ASSERT (7+1 == r7); + } }; LAUNCHER (ItemWrapper_test, "unit common");