sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "cppunit/cppunit_proxy.h" sl@0: sl@0: #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) sl@0: using namespace std; sl@0: #endif sl@0: sl@0: // sl@0: // TestCase class sl@0: // sl@0: class TransformTest : public CPPUNIT_NS::TestCase sl@0: { sl@0: CPPUNIT_TEST_SUITE(TransformTest); sl@0: CPPUNIT_TEST(trnsfrm1); sl@0: CPPUNIT_TEST(trnsfrm2); sl@0: CPPUNIT_TEST(self_str); sl@0: CPPUNIT_TEST_SUITE_END(); sl@0: sl@0: protected: sl@0: void trnsfrm1(); sl@0: void trnsfrm2(); sl@0: void self_str(); sl@0: sl@0: static int negate_int(int a_) { sl@0: return -a_; sl@0: } sl@0: static char map_char(char a_, int b_) { sl@0: return char(a_ + b_); sl@0: } sl@0: static char shift( char c ) { sl@0: return char(((int)c + 1) % 256); sl@0: } sl@0: }; sl@0: sl@0: CPPUNIT_TEST_SUITE_REGISTRATION(TransformTest); sl@0: sl@0: // sl@0: // tests implementation sl@0: // sl@0: void TransformTest::trnsfrm1() sl@0: { sl@0: int numbers[6] = { -5, -1, 0, 1, 6, 11 }; sl@0: sl@0: int result[6]; sl@0: transform((int*)numbers, (int*)numbers + 6, (int*)result, negate_int); sl@0: sl@0: CPPUNIT_ASSERT(result[0]==5); sl@0: CPPUNIT_ASSERT(result[1]==1); sl@0: CPPUNIT_ASSERT(result[2]==0); sl@0: CPPUNIT_ASSERT(result[3]==-1); sl@0: CPPUNIT_ASSERT(result[4]==-6); sl@0: CPPUNIT_ASSERT(result[5]==-11); sl@0: } sl@0: void TransformTest::trnsfrm2() sl@0: { sl@0: #if defined (__MVS__) sl@0: int trans[] = {-11, 4, -6, -6, -18, 0, 18, -14, 6, 0, -1, -59}; sl@0: #else sl@0: int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77}; sl@0: #endif sl@0: char n[] = "Larry Mullen"; sl@0: const size_t count = ::strlen(n); sl@0: sl@0: string res; sl@0: transform(n, n + count, trans, back_inserter(res), map_char); sl@0: CPPUNIT_ASSERT( res == "Hello World!" ) sl@0: } sl@0: sl@0: void TransformTest::self_str() sl@0: { sl@0: string s( "0123456789abcdefg" ); sl@0: string r( "123456789:bcdefgh" ); sl@0: transform( s.begin(), s.end(), s.begin(), shift ); sl@0: CPPUNIT_ASSERT( s == r ); sl@0: } sl@0: