os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/copy_test.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/copy_test.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,91 @@
     1.4 +#include <algorithm>
     1.5 +#include <cstring>
     1.6 +#include <vector>
     1.7 +#include <iterator>
     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 CopyTest : public CPPUNIT_NS::TestCase
    1.19 +{
    1.20 +  CPPUNIT_TEST_SUITE(CopyTest);
    1.21 +  CPPUNIT_TEST(copy_array);
    1.22 +  CPPUNIT_TEST(copy_vector);
    1.23 +  CPPUNIT_TEST(copy_insert);
    1.24 +  CPPUNIT_TEST(copy_back);
    1.25 +  CPPUNIT_TEST(copy_back_array);
    1.26 +  CPPUNIT_TEST_SUITE_END();
    1.27 +
    1.28 +protected:
    1.29 +  void copy_array();
    1.30 +  void copy_vector();
    1.31 +  void copy_insert();
    1.32 +  void copy_back();
    1.33 +  void copy_back_array();
    1.34 +};
    1.35 +
    1.36 +CPPUNIT_TEST_SUITE_REGISTRATION(CopyTest);
    1.37 +
    1.38 +//
    1.39 +// tests implementation
    1.40 +//
    1.41 +void CopyTest::copy_array()
    1.42 +{
    1.43 +  char string[23] = "A string to be copied.";
    1.44 +  char result[23];
    1.45 +  copy(string, string + 23, result);
    1.46 +  CPPUNIT_ASSERT(!strncmp(string, result, 23));
    1.47 +}
    1.48 +
    1.49 +void CopyTest::copy_vector()
    1.50 +{
    1.51 +  vector<int> v1(10);
    1.52 +  for (int i = 0; (size_t)i < v1.size(); ++i)
    1.53 +    v1[i] = i;
    1.54 +
    1.55 +  vector<int> v2(v1.size());
    1.56 +  copy(v1.begin(), v1.end(), v2.begin());
    1.57 +
    1.58 +  CPPUNIT_ASSERT( v2 == v1 );
    1.59 +}
    1.60 +
    1.61 +void CopyTest::copy_insert() {
    1.62 +  vector<int> v1(10);
    1.63 +  for (int loc = 0; (size_t)loc < v1.size(); ++loc)
    1.64 +    v1[loc] = loc;
    1.65 +  vector<int> v2;
    1.66 +  insert_iterator<vector<int> > i(v2, v2.begin());
    1.67 +  copy(v1.begin(), v1.end(), i);
    1.68 +
    1.69 +  CPPUNIT_ASSERT( v2 == v1 );
    1.70 +}
    1.71 +
    1.72 +void CopyTest::copy_back()
    1.73 +{
    1.74 +  vector<int> v1(10);
    1.75 +  for (int i = 0; (size_t)i < v1.size(); ++i)
    1.76 +    v1[i] = i;
    1.77 +  vector<int> v2(v1.size());
    1.78 +  copy_backward(v1.begin(), v1.end(), v2.end());
    1.79 +
    1.80 +  CPPUNIT_ASSERT( v2 == v1 );
    1.81 +}
    1.82 +
    1.83 +void CopyTest::copy_back_array()
    1.84 +{
    1.85 +  int numbers[5] = { 1, 2, 3, 4, 5 };
    1.86 +
    1.87 +  int result[5];
    1.88 +  copy_backward(numbers, numbers + 5, (int*)result + 5);
    1.89 +  CPPUNIT_ASSERT(result[0]==numbers[0]);
    1.90 +  CPPUNIT_ASSERT(result[1]==numbers[1]);
    1.91 +  CPPUNIT_ASSERT(result[2]==numbers[2]);
    1.92 +  CPPUNIT_ASSERT(result[3]==numbers[3]);
    1.93 +  CPPUNIT_ASSERT(result[4]==numbers[4]);
    1.94 +}