aboutsummaryrefslogtreecommitdiff
path: root/test/unit/includes_test.cpp
blob: d6417978351ea5b7a391a5d8769b85c625fec939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <cstring>
#include <vector>
#include <algorithm>

#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

//
// TestCase class
//
class IncludesTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(IncludesTest);
  CPPUNIT_TEST(incl0);
  CPPUNIT_TEST(incl1);
  CPPUNIT_TEST(incl2);
  CPPUNIT_TEST_SUITE_END();

protected:
  void incl0();
  void incl1();
  void incl2();

  static bool compare_strings(const char* s1_, const char* s2_)
  {
    return strcmp(s1_, s2_) < 0 ? 1 : 0;
  }
};

CPPUNIT_TEST_SUITE_REGISTRATION(IncludesTest);

//
// tests implementation
//
void IncludesTest::incl0()
{
  int numbers1[5] = { 1, 2, 3, 4, 5 };
  //int numbers2[5] = { 1, 2, 4, 8, 16 };
  int numbers3[2] = { 4, 8 };
  bool r1=includes(numbers1, numbers1 + 5, numbers3, numbers3 + 2);
  CPPUNIT_ASSERT(!r1);
}
void IncludesTest::incl1()
{
  vector<int> v1(10);
  vector<int> v2(3);
  int i;
  for (i = 0; (size_t)i < v1.size(); ++i) {
    v1[i] = i;
  }

  bool r1=includes(v1.begin(), v1.end(), v2.begin(), v2.end());
  CPPUNIT_ASSERT(!r1);

  for (i = 0; (size_t)i < v2.size(); ++i)
    v2[i] = i + 3;

  bool r2=includes(v1.begin(), v1.end(), v2.begin(), v2.end());
  CPPUNIT_ASSERT(r2);
}
void IncludesTest::incl2()
{
  char const* names[] = {  "Todd", "Mike", "Graham", "Jack", "Brett"};

  const unsigned nameSize = sizeof(names)/sizeof(names[0]);
  vector <char const*> v1(nameSize);
  for (int i = 0; (size_t)i < v1.size(); ++i) {
    v1[i] = names[i];
  }
  vector <char const*> v2(2);

  v2[0] = "foo";
  v2[1] = "bar";
  sort(v1.begin(), v1.end(), compare_strings);
  sort(v2.begin(), v2.end(), compare_strings);

  bool r1 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings);
  CPPUNIT_ASSERT(!r1);

  v2[0] = "Brett";
  v2[1] = "Todd";
  bool r2 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings);
  CPPUNIT_ASSERT(r2);
}