From 8a3d31253c03695efacb848e78a7b8c1da6ab059 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Fri, 17 Feb 2006 16:28:36 +0000 Subject: [PATCH] - Added testcase for zypp::RW_pointer unique() --- testsuite/zypp/tests/Makefile.am | 2 + testsuite/zypp/tests/RWPtr.cc | 82 ++++++++++++++++++++++++++++++++++++++ testsuite/zypp/zypp.test/RWPtr.exp | 4 ++ 3 files changed, 88 insertions(+) create mode 100644 testsuite/zypp/tests/RWPtr.cc create mode 100644 testsuite/zypp/zypp.test/RWPtr.exp diff --git a/testsuite/zypp/tests/Makefile.am b/testsuite/zypp/tests/Makefile.am index 228afb5..4c4ee0a 100644 --- a/testsuite/zypp/tests/Makefile.am +++ b/testsuite/zypp/tests/Makefile.am @@ -8,6 +8,7 @@ SUBDIRS = ## ################################################## noinst_PROGRAMS = Arch Url1 Url2 Url3 Url4 Url5 \ + RWPtr \ Edition \ Capabilities @@ -23,6 +24,7 @@ Url2_SOURCES = Url2.cc Url3_SOURCES = Url3.cc Url4_SOURCES = Url4.cc Url5_SOURCES = Url5.cc +RWPtr_SOURCES = RWPtr.cc Edition_SOURCES = Edition.cc Capabilities_SOURCES = Capabilities.cc diff --git a/testsuite/zypp/tests/RWPtr.cc b/testsuite/zypp/tests/RWPtr.cc new file mode 100644 index 0000000..6e1ddc6 --- /dev/null +++ b/testsuite/zypp/tests/RWPtr.cc @@ -0,0 +1,82 @@ +#include +#include +#include + +struct Foo +{ + int _foo; + + Foo(int foo=0): _foo(foo) + { + std::cerr << "created Foo(" << _foo << ")" << std::endl; + } + ~Foo() + { + std::cerr << "destroy Foo(" << _foo << ")" << std::endl; + } +}; + +#define REF_TEST(ref,msg,exp,res) \ +do { \ + bool unique = exp; \ + std::cerr << msg << std::endl; \ + if( ref) { \ + std::cerr << "ref contains object" << std::endl; \ + } else { \ + std::cerr << "ref contains no object" << std::endl; \ + } \ + std::cerr << "ref counter is " << ref.use_count() << std::endl; \ + if( ref.unique()) { \ + std::cerr << "ref is unique" << std::endl; \ + if( unique) { \ + std::cerr << "EXPECTED" << std::endl; \ + } else { \ + std::cerr << "NOT EXPECTED" << std::endl; \ + res = 1; \ + } \ + } else { \ + std::cerr << "ref is shared" << std::endl; \ + if( !unique) { \ + std::cerr << "EXPECTED" << std::endl; \ + } else { \ + std::cerr << "NOT EXPECTED" << std::endl; \ + res = 1; \ + } \ + } \ + std::cerr << std::endl; \ +} while(0); + +int main(int argc, char *argv[]) +{ + (void)argv; + + bool skip_reset = argc > 1; + int result = 0; + + typedef zypp::RW_pointer FooRef; + + FooRef ref; + REF_TEST(ref,"=== REF(nil)", true, result); + + ref.reset(new Foo(42)); + REF_TEST(ref,"=== REF(object)", true, result); + + { + FooRef ref2(ref); + REF_TEST(ref,"=== REF2(REF)", false, result); + } + + REF_TEST(ref,"=== REF(object), REF2 out of scope now", true, result); + + if( !skip_reset) + { + ref.reset(); + REF_TEST(ref,"=== REF(nil), reset()", true, result); + } + + std::cerr << "RESULT: " + << (result == 0 ? "PASSED" : "FAILED") + << std::endl; + return result; +} + diff --git a/testsuite/zypp/zypp.test/RWPtr.exp b/testsuite/zypp/zypp.test/RWPtr.exp new file mode 100644 index 0000000..8d93e17 --- /dev/null +++ b/testsuite/zypp/zypp.test/RWPtr.exp @@ -0,0 +1,4 @@ +# RWPtr.exp +# run tests for RWPtr + + shouldPass "RWPtr" -- 2.7.4