ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

copy_test.cpp
Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <cstring>
00003 #include <vector>
00004 #include <iterator>
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 CopyTest : public CPPUNIT_NS::TestCase
00016 {
00017   CPPUNIT_TEST_SUITE(CopyTest);
00018   CPPUNIT_TEST(copy_array);
00019   CPPUNIT_TEST(copy_volatile);
00020   CPPUNIT_TEST(copy_vector);
00021   CPPUNIT_TEST(copy_insert);
00022   CPPUNIT_TEST(copy_back);
00023   CPPUNIT_TEST(copy_back_array);
00024   CPPUNIT_TEST_SUITE_END();
00025 
00026 protected:
00027   void copy_array();
00028   void copy_volatile();
00029   void copy_vector();
00030   void copy_insert();
00031   void copy_back();
00032   void copy_back_array();
00033 };
00034 
00035 CPPUNIT_TEST_SUITE_REGISTRATION(CopyTest);
00036 
00037 //
00038 // tests implementation
00039 //
00040 void CopyTest::copy_array()
00041 {
00042   char string[23] = "A string to be copied.";
00043   char result[23];
00044   copy(string, string + 23, result);
00045   CPPUNIT_ASSERT(!strncmp(string, result, 23));
00046 }
00047 
00048 void CopyTest::copy_volatile()
00049 {
00050   {
00051     int a[] = {0, 1, 2, 3, 4, 5};
00052     const size_t size = sizeof(a) / sizeof(a[0]);
00053     volatile int va[size]; 
00054     copy(a, a + size, va);
00055     for (size_t i = 0; i != size; ++i) {
00056       CPPUNIT_ASSERT( a[i] == va[i] );
00057     }
00058   }
00059 
00060   {
00061     const int a[] = {0, 1, 2, 3, 4, 5};
00062     const size_t size = sizeof(a) / sizeof(a[0]);
00063     volatile int va[size]; 
00064     copy(a, a + size, va);
00065     for (size_t i = 0; i != size; ++i) {
00066       CPPUNIT_ASSERT( a[i] == va[i] );
00067     }
00068   }
00069 
00070   // Following code can be activated to check that it doesn't compiled
00071 #if 0
00072   {
00073     int a[] = {0, 1, 2, 3, 4, 5};
00074     const size_t size = sizeof(a) / sizeof(a[0]);
00075     const volatile int va[size] = {5, 4, 3, 2, 1, 0}; 
00076     copy(a, a + size, va);
00077     for (size_t i = 0; i != size; ++i) {
00078       CPPUNIT_ASSERT( a[i] == va[i] );
00079     }
00080   }
00081 #endif
00082 }
00083 
00084 void CopyTest::copy_vector()
00085 {
00086   vector<int> v1(10);
00087   for (int i = 0; (size_t)i < v1.size(); ++i)
00088     v1[i] = i;
00089 
00090   vector<int> v2(v1.size());
00091   copy(v1.begin(), v1.end(), v2.begin());
00092 
00093   CPPUNIT_ASSERT( v2 == v1 );
00094 }
00095 
00096 void CopyTest::copy_insert() {
00097   vector<int> v1(10);
00098   for (int loc = 0; (size_t)loc < v1.size(); ++loc)
00099     v1[loc] = loc;
00100   vector<int> v2;
00101   insert_iterator<vector<int> > i(v2, v2.begin());
00102   copy(v1.begin(), v1.end(), i);
00103 
00104   CPPUNIT_ASSERT( v2 == v1 );
00105 }
00106 
00107 void CopyTest::copy_back()
00108 {
00109   vector<int> v1(10);
00110   for (int i = 0; (size_t)i < v1.size(); ++i)
00111     v1[i] = i;
00112   vector<int> v2(v1.size());
00113   copy_backward(v1.begin(), v1.end(), v2.end());
00114 
00115   CPPUNIT_ASSERT( v2 == v1 );
00116 }
00117 
00118 void CopyTest::copy_back_array()
00119 {
00120   int numbers[5] = { 1, 2, 3, 4, 5 };
00121 
00122   int result[5];
00123   copy_backward(numbers, numbers + 5, (int*)result + 5);
00124   CPPUNIT_ASSERT(result[0]==numbers[0]);
00125   CPPUNIT_ASSERT(result[1]==numbers[1]);
00126   CPPUNIT_ASSERT(result[2]==numbers[2]);
00127   CPPUNIT_ASSERT(result[3]==numbers[3]);
00128   CPPUNIT_ASSERT(result[4]==numbers[4]);
00129 }

Generated on Sat May 26 2012 04:34:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.