1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/transform_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,80 @@
1.4 +#include <string>
1.5 +#include <iterator>
1.6 +#include <vector>
1.7 +#include <algorithm>
1.8 +
1.9 +#include "cppunit/cppunit_proxy.h"
1.10 +
1.11 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.12 +using namespace std;
1.13 +#endif
1.14 +
1.15 +//
1.16 +// TestCase class
1.17 +//
1.18 +class TransformTest : public CPPUNIT_NS::TestCase
1.19 +{
1.20 + CPPUNIT_TEST_SUITE(TransformTest);
1.21 + CPPUNIT_TEST(trnsfrm1);
1.22 + CPPUNIT_TEST(trnsfrm2);
1.23 + CPPUNIT_TEST(self_str);
1.24 + CPPUNIT_TEST_SUITE_END();
1.25 +
1.26 +protected:
1.27 + void trnsfrm1();
1.28 + void trnsfrm2();
1.29 + void self_str();
1.30 +
1.31 + static int negate_int(int a_) {
1.32 + return -a_;
1.33 + }
1.34 + static char map_char(char a_, int b_) {
1.35 + return char(a_ + b_);
1.36 + }
1.37 + static char shift( char c ) {
1.38 + return char(((int)c + 1) % 256);
1.39 + }
1.40 +};
1.41 +
1.42 +CPPUNIT_TEST_SUITE_REGISTRATION(TransformTest);
1.43 +
1.44 +//
1.45 +// tests implementation
1.46 +//
1.47 +void TransformTest::trnsfrm1()
1.48 +{
1.49 + int numbers[6] = { -5, -1, 0, 1, 6, 11 };
1.50 +
1.51 + int result[6];
1.52 + transform((int*)numbers, (int*)numbers + 6, (int*)result, negate_int);
1.53 +
1.54 + CPPUNIT_ASSERT(result[0]==5);
1.55 + CPPUNIT_ASSERT(result[1]==1);
1.56 + CPPUNIT_ASSERT(result[2]==0);
1.57 + CPPUNIT_ASSERT(result[3]==-1);
1.58 + CPPUNIT_ASSERT(result[4]==-6);
1.59 + CPPUNIT_ASSERT(result[5]==-11);
1.60 +}
1.61 +void TransformTest::trnsfrm2()
1.62 +{
1.63 +#if defined (__MVS__)
1.64 + int trans[] = {-11, 4, -6, -6, -18, 0, 18, -14, 6, 0, -1, -59};
1.65 +#else
1.66 + int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77};
1.67 +#endif
1.68 + char n[] = "Larry Mullen";
1.69 + const size_t count = ::strlen(n);
1.70 +
1.71 + string res;
1.72 + transform(n, n + count, trans, back_inserter(res), map_char);
1.73 + CPPUNIT_ASSERT( res == "Hello World!" )
1.74 +}
1.75 +
1.76 +void TransformTest::self_str()
1.77 +{
1.78 + string s( "0123456789abcdefg" );
1.79 + string r( "123456789:bcdefgh" );
1.80 + transform( s.begin(), s.end(), s.begin(), shift );
1.81 + CPPUNIT_ASSERT( s == r );
1.82 +}
1.83 +