6 #if 0 /* temporary: investigation of problem with swap */
11 #include "cppunit/cppunit_proxy.h"
13 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
20 class SwapTest : public CPPUNIT_NS::TestCase
22 CPPUNIT_TEST_SUITE(SwapTest);
24 CPPUNIT_TEST(swprnge1);
25 CPPUNIT_TEST(swap_container_non_spec);
26 #if defined (STLPORT) && \
27 !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) && !defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
30 CPPUNIT_TEST(swap_container_spec);
31 CPPUNIT_TEST_SUITE_END();
36 void swap_container_non_spec();
37 void swap_container_spec();
40 CPPUNIT_TEST_SUITE_REGISTRATION(SwapTest);
43 // tests implementation
45 void SwapTest::swap1()
51 CPPUNIT_ASSERT(a==19);
52 CPPUNIT_ASSERT(b==42);
55 void SwapTest::swprnge1()
57 char word1[] = "World";
58 char word2[] = "Hello";
59 swap_ranges((char*)word1, (char*)word1 + ::strlen(word1), (char*)word2);
60 CPPUNIT_ASSERT(!strcmp(word1, "Hello"));
61 CPPUNIT_ASSERT(!strcmp(word2, "World"));
74 Obj& operator =( const Obj& )
75 { v = 2; return *this; }
81 * Following two tests check the corectness of specialization of swap():
82 * for containers with container::swap method swap( a, b ) should
83 * use a.swap( b ), but don't try to do this substitution for container
84 * without swap method (in this case swap should be made via explicit members
85 * exchange; this assume usage of temporary object)
88 void SwapTest::swap_container_non_spec()
105 CPPUNIT_CHECK( v1.size() == 2 );
106 CPPUNIT_CHECK( v2.size() == 3 );
108 swap( v1, v2 ); // this shouldn't try make it as v1.swap( v2 ), no queue::swap method!
110 CPPUNIT_CHECK( v1.size() == 3 );
111 CPPUNIT_CHECK( v2.size() == 2 );
113 // either copy constructor or assignment operator
114 CPPUNIT_CHECK( v1.front().v == 1 || v1.front().v == 2 );
115 CPPUNIT_CHECK( v1.back().v == 1 || v1.back().v == 2 );
116 CPPUNIT_CHECK( v2.front().v == 1 || v2.front().v == 2 );
117 CPPUNIT_CHECK( v2.back().v == 1 || v2.back().v == 2 );
120 void SwapTest::swap_container_spec()
122 #if 0 /* temporary: investigation of problem with swap */
123 if ( typeid(/* _STLP_PRIV */ _SwapImplemented<vector<Obj> >::_Ret) == typeid(_STLP_PRIV __false_type) ) {
124 cerr << "false type" << endl;
125 } else if ( typeid(/* _STLP_PRIV */ _SwapImplemented<vector<Obj> >::_Ret) == typeid(_STLP_PRIV __true_type) ) {
126 cerr << "true type" << endl;
128 cerr << "unknown type" << endl;
130 #endif /* end of temporary */
131 #if !defined (STLPORT) || \
132 defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
136 v1.push_back( Obj() );
137 v1.push_back( Obj() );
142 v2.push_back( Obj() );
143 v2.push_back( Obj() );
144 v2.push_back( Obj() );
150 CPPUNIT_CHECK( v1.size() == 2 );
151 CPPUNIT_CHECK( v2.size() == 3 );
153 swap( v1, v2 ); // this should has effect v1.swap( v2 )
155 CPPUNIT_CHECK( v1.size() == 3 );
156 CPPUNIT_CHECK( v2.size() == 2 );
158 CPPUNIT_CHECK( v1[0].v == 10 );
159 CPPUNIT_CHECK( v1[1].v == 11 );
160 CPPUNIT_CHECK( v1[2].v == 12 );
162 CPPUNIT_CHECK( v2[0].v == -1 );
163 CPPUNIT_CHECK( v2[1].v == -2 );