1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/ptr2_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +#include <vector>
1.5 +#include <algorithm>
1.6 +#include <functional>
1.7 +
1.8 +#include "cppunit/cppunit_proxy.h"
1.9 +
1.10 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.11 +using namespace std;
1.12 +#endif
1.13 +
1.14 +//
1.15 +// TestCase class
1.16 +//
1.17 +class Ptr2Test : public CPPUNIT_NS::TestCase
1.18 +{
1.19 + CPPUNIT_TEST_SUITE(Ptr2Test);
1.20 + CPPUNIT_TEST(ptrbin1);
1.21 + CPPUNIT_TEST(ptrbin2);
1.22 + CPPUNIT_TEST(ptrun1);
1.23 + CPPUNIT_TEST(ptrun2);
1.24 + CPPUNIT_TEST_SUITE_END();
1.25 +
1.26 +protected:
1.27 + void ptrbin1();
1.28 + void ptrbin2();
1.29 + void ptrun1();
1.30 + void ptrun2();
1.31 +};
1.32 +
1.33 +CPPUNIT_TEST_SUITE_REGISTRATION(Ptr2Test);
1.34 +
1.35 +//
1.36 +// tests implementation
1.37 +//
1.38 +static int sum(int x_, int y_)
1.39 +{
1.40 + return x_ + y_;
1.41 +}
1.42 +bool even(int n_)
1.43 +{
1.44 + return(n_ % 2) == 0;
1.45 +}
1.46 +void Ptr2Test::ptrbin1()
1.47 +{
1.48 + int input1 [4] = { 7, 2, 3, 5 };
1.49 + int input2 [4] = { 1, 5, 5, 8 };
1.50 +
1.51 + int output [4];
1.52 + transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, pointer_to_binary_function<int, int, int>(sum));
1.53 +
1.54 + CPPUNIT_ASSERT(output[0]==8);
1.55 + CPPUNIT_ASSERT(output[1]==7);
1.56 + CPPUNIT_ASSERT(output[2]==8);
1.57 + CPPUNIT_ASSERT(output[3]==13);
1.58 +}
1.59 +void Ptr2Test::ptrbin2()
1.60 +{
1.61 + int input1 [4] = { 7, 2, 3, 5 };
1.62 + int input2 [4] = { 1, 5, 5, 8 };
1.63 +
1.64 + int output [4];
1.65 + transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, ptr_fun(sum));
1.66 +
1.67 + CPPUNIT_ASSERT(output[0]==8);
1.68 + CPPUNIT_ASSERT(output[1]==7);
1.69 + CPPUNIT_ASSERT(output[2]==8);
1.70 + CPPUNIT_ASSERT(output[3]==13);
1.71 +}
1.72 +void Ptr2Test::ptrun1()
1.73 +{
1.74 + int array [3] = { 1, 2, 3 };
1.75 +
1.76 + int* p = find_if((int*)array, (int*)array + 3, pointer_to_unary_function<int, bool>(even));
1.77 + CPPUNIT_ASSERT(p != array+3);
1.78 + CPPUNIT_ASSERT(*p==2);
1.79 +}
1.80 +void Ptr2Test::ptrun2()
1.81 +{
1.82 + int array [3] = { 1, 2, 3 };
1.83 +
1.84 + int* p = find_if((int*)array, (int*)array + 3, ptr_fun(even));
1.85 + CPPUNIT_ASSERT(p != array+3);
1.86 + CPPUNIT_ASSERT(*p==2);
1.87 +}