OSDN Git Service

original
[gb-231r1-is01/GB_2.3_IS01.git] / ndk / tests / device / test-stlport / unit / reference_wrapper_test.cpp
1 #include <functional>
2
3 #if !defined(_STLP_NO_EXTENSIONS) && defined(_STLP_USE_BOOST_SUPPORT)
4
5 #include <typeinfo>
6 #include "cppunit/cppunit_proxy.h"
7
8 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
9 using namespace std;
10 #endif
11
12 class RefWrapperTest :
13     public CPPUNIT_NS::TestCase
14 {
15     CPPUNIT_TEST_SUITE(RefWrapperTest);
16     CPPUNIT_TEST(ref);
17     CPPUNIT_TEST(cref);
18     CPPUNIT_TEST_SUITE_END();
19
20   protected:
21     void ref();
22     void cref();
23 };
24
25 CPPUNIT_TEST_SUITE_REGISTRATION(RefWrapperTest);
26
27 void RefWrapperTest::ref()
28 {
29   typedef std::tr1::reference_wrapper<int> rr_type;
30
31   CPPUNIT_CHECK( (::boost::is_convertible<rr_type, int&>::value) );
32   CPPUNIT_CHECK( (::boost::is_same<rr_type::type, int>::value) );
33
34   int i = 1;
35   int j = 2;
36
37   rr_type r1 = std::tr1::ref(i);
38
39   CPPUNIT_CHECK( r1.get() == 1 );
40
41   r1 = std::tr1::ref(j);
42
43   CPPUNIT_CHECK( r1.get() == 2 );
44
45   i = 3;
46
47   CPPUNIT_CHECK( r1.get() == 2 );
48
49   j = 4;
50
51   CPPUNIT_CHECK( r1.get() == 4 );
52
53   r1.get() = 5;
54
55   CPPUNIT_CHECK( j == 5 );
56 }
57
58 void RefWrapperTest::cref()
59 {
60   typedef std::tr1::reference_wrapper<const int> crr_type;
61
62   CPPUNIT_CHECK( (::boost::is_convertible<crr_type, const int&>::value) );
63   CPPUNIT_CHECK( (::boost::is_same<crr_type::type, const int>::value) );
64
65   int i = 1;
66   int j = 2;
67
68   crr_type r1 = std::tr1::cref(i);
69
70   CPPUNIT_CHECK( r1.get() == 1 );
71
72   r1 = std::tr1::cref(j);
73
74   CPPUNIT_CHECK( r1.get() == 2 );
75
76   i = 3;
77
78   CPPUNIT_CHECK( r1.get() == 2 );
79
80   j = 4;
81
82   CPPUNIT_CHECK( r1.get() == 4 );
83 }
84
85 #endif /* !_STLP_NO_EXTENSIONS && _STLP_USE_BOOST_SUPPORT */