Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentransform_test.cpp
Go to the documentation of this file.
00001 #include <string> 00002 #include <iterator> 00003 #include <vector> 00004 #include <algorithm> 00005 00006 #include "cppunit/cppunit_proxy.h" 00007 00008 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00009 using namespace std; 00010 #endif 00011 00012 // 00013 // TestCase class 00014 // 00015 class TransformTest : public CPPUNIT_NS::TestCase 00016 { 00017 CPPUNIT_TEST_SUITE(TransformTest); 00018 CPPUNIT_TEST(trnsfrm1); 00019 CPPUNIT_TEST(trnsfrm2); 00020 CPPUNIT_TEST(self_str); 00021 CPPUNIT_TEST_SUITE_END(); 00022 00023 protected: 00024 void trnsfrm1(); 00025 void trnsfrm2(); 00026 void self_str(); 00027 00028 static int negate_int(int a_) { 00029 return -a_; 00030 } 00031 static char map_char(char a_, int b_) { 00032 return char(a_ + b_); 00033 } 00034 static char shift( char c ) { 00035 return char(((int)c + 1) % 256); 00036 } 00037 }; 00038 00039 CPPUNIT_TEST_SUITE_REGISTRATION(TransformTest); 00040 00041 // 00042 // tests implementation 00043 // 00044 void TransformTest::trnsfrm1() 00045 { 00046 int numbers[6] = { -5, -1, 0, 1, 6, 11 }; 00047 00048 int result[6]; 00049 transform((int*)numbers, (int*)numbers + 6, (int*)result, negate_int); 00050 00051 CPPUNIT_ASSERT(result[0]==5); 00052 CPPUNIT_ASSERT(result[1]==1); 00053 CPPUNIT_ASSERT(result[2]==0); 00054 CPPUNIT_ASSERT(result[3]==-1); 00055 CPPUNIT_ASSERT(result[4]==-6); 00056 CPPUNIT_ASSERT(result[5]==-11); 00057 } 00058 void TransformTest::trnsfrm2() 00059 { 00060 #if defined (__MVS__) 00061 int trans[] = {-11, 4, -6, -6, -18, 0, 18, -14, 6, 0, -1, -59}; 00062 #else 00063 int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77}; 00064 #endif 00065 char n[] = "Larry Mullen"; 00066 const size_t count = ::strlen(n); 00067 00068 string res; 00069 transform(n, n + count, trans, back_inserter(res), map_char); 00070 CPPUNIT_ASSERT( res == "Hello World!" ) 00071 } 00072 00073 void TransformTest::self_str() 00074 { 00075 string s( "0123456789abcdefg" ); 00076 string r( "123456789:bcdefgh" ); 00077 transform( s.begin(), s.end(), s.begin(), shift ); 00078 CPPUNIT_ASSERT( s == r ); 00079 } 00080 Generated on Sat May 26 2012 04:34:47 for ReactOS by
1.7.6.1
|