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

includes_test.cpp
Go to the documentation of this file.
00001 #include <cstring>
00002 #include <vector>
00003 #include <algorithm>
00004 
00005 #include "cppunit/cppunit_proxy.h"
00006 
00007 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00008 using namespace std;
00009 #endif
00010 
00011 //
00012 // TestCase class
00013 //
00014 class IncludesTest : public CPPUNIT_NS::TestCase
00015 {
00016   CPPUNIT_TEST_SUITE(IncludesTest);
00017   CPPUNIT_TEST(incl0);
00018   CPPUNIT_TEST(incl1);
00019   CPPUNIT_TEST(incl2);
00020   CPPUNIT_TEST_SUITE_END();
00021 
00022 protected:
00023   void incl0();
00024   void incl1();
00025   void incl2();
00026 
00027   static bool compare_strings(const char* s1_, const char* s2_)
00028   {
00029     return strcmp(s1_, s2_) < 0 ? 1 : 0;
00030   }
00031 };
00032 
00033 CPPUNIT_TEST_SUITE_REGISTRATION(IncludesTest);
00034 
00035 //
00036 // tests implementation
00037 //
00038 void IncludesTest::incl0()
00039 {
00040   int numbers1[5] = { 1, 2, 3, 4, 5 };
00041   //int numbers2[5] = { 1, 2, 4, 8, 16 };
00042   int numbers3[2] = { 4, 8 };
00043   bool r1=includes(numbers1, numbers1 + 5, numbers3, numbers3 + 2);
00044   CPPUNIT_ASSERT(!r1);
00045 }
00046 void IncludesTest::incl1()
00047 {
00048   vector<int> v1(10);
00049   vector<int> v2(3);
00050   int i;
00051   for (i = 0; (size_t)i < v1.size(); ++i) {
00052     v1[i] = i;
00053   }
00054 
00055   bool r1=includes(v1.begin(), v1.end(), v2.begin(), v2.end());
00056   CPPUNIT_ASSERT(!r1);
00057 
00058   for (i = 0; (size_t)i < v2.size(); ++i)
00059     v2[i] = i + 3;
00060 
00061   bool r2=includes(v1.begin(), v1.end(), v2.begin(), v2.end());
00062   CPPUNIT_ASSERT(r2);
00063 }
00064 void IncludesTest::incl2()
00065 {
00066   char const* names[] = {  "Todd", "Mike", "Graham", "Jack", "Brett"};
00067 
00068   const unsigned nameSize = sizeof(names)/sizeof(names[0]);
00069   vector <char const*> v1(nameSize);
00070   for (int i = 0; (size_t)i < v1.size(); ++i) {
00071     v1[i] = names[i];
00072   }
00073   vector <char const*> v2(2);
00074 
00075   v2[0] = "foo";
00076   v2[1] = "bar";
00077   sort(v1.begin(), v1.end(), compare_strings);
00078   sort(v2.begin(), v2.end(), compare_strings);
00079 
00080   bool r1 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings);
00081   CPPUNIT_ASSERT(!r1);
00082 
00083   v2[0] = "Brett";
00084   v2[1] = "Todd";
00085   bool r2 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings);
00086   CPPUNIT_ASSERT(r2);
00087 }

Generated on Sat May 26 2012 04:34:17 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.