|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <cstring> |
|
18 #include <vector> |
|
19 #include <algorithm> |
|
20 |
|
21 #include "cppunit/cppunit_proxy.h" |
|
22 |
|
23 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) |
|
24 using namespace std; |
|
25 #endif |
|
26 |
|
27 // |
|
28 // TestCase class |
|
29 // |
|
30 class IncludesTest : public CPPUNIT_NS::TestCase |
|
31 { |
|
32 CPPUNIT_TEST_SUITE(IncludesTest); |
|
33 CPPUNIT_TEST(incl0); |
|
34 CPPUNIT_TEST(incl1); |
|
35 CPPUNIT_TEST(incl2); |
|
36 CPPUNIT_TEST_SUITE_END(); |
|
37 |
|
38 protected: |
|
39 void incl0(); |
|
40 void incl1(); |
|
41 void incl2(); |
|
42 |
|
43 static bool compare_strings(const char* s1_, const char* s2_) |
|
44 { |
|
45 return strcmp(s1_, s2_) < 0 ? 1 : 0; |
|
46 } |
|
47 }; |
|
48 |
|
49 CPPUNIT_TEST_SUITE_REGISTRATION(IncludesTest); |
|
50 |
|
51 // |
|
52 // tests implementation |
|
53 // |
|
54 void IncludesTest::incl0() |
|
55 { |
|
56 int numbers1[5] = { 1, 2, 3, 4, 5 }; |
|
57 //int numbers2[5] = { 1, 2, 4, 8, 16 }; |
|
58 int numbers3[2] = { 4, 8 }; |
|
59 bool r1=includes(numbers1, numbers1 + 5, numbers3, numbers3 + 2); |
|
60 CPPUNIT_ASSERT(!r1); |
|
61 } |
|
62 void IncludesTest::incl1() |
|
63 { |
|
64 vector<int> v1(10); |
|
65 vector<int> v2(3); |
|
66 int i; |
|
67 for (i = 0; (size_t)i < v1.size(); ++i) { |
|
68 v1[i] = i; |
|
69 } |
|
70 |
|
71 bool r1=includes(v1.begin(), v1.end(), v2.begin(), v2.end()); |
|
72 CPPUNIT_ASSERT(!r1); |
|
73 |
|
74 for (i = 0; (size_t)i < v2.size(); ++i) |
|
75 v2[i] = i + 3; |
|
76 |
|
77 bool r2=includes(v1.begin(), v1.end(), v2.begin(), v2.end()); |
|
78 CPPUNIT_ASSERT(r2); |
|
79 } |
|
80 void IncludesTest::incl2() |
|
81 { |
|
82 char const* names[] = { "Todd", "Mike", "Graham", "Jack", "Brett"}; |
|
83 |
|
84 const unsigned nameSize = sizeof(names)/sizeof(names[0]); |
|
85 vector <char const*> v1(nameSize); |
|
86 for (int i = 0; (size_t)i < v1.size(); ++i) { |
|
87 v1[i] = names[i]; |
|
88 } |
|
89 vector <char const*> v2(2); |
|
90 |
|
91 v2[0] = "foo"; |
|
92 v2[1] = "bar"; |
|
93 sort(v1.begin(), v1.end(), compare_strings); |
|
94 sort(v2.begin(), v2.end(), compare_strings); |
|
95 |
|
96 bool r1 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings); |
|
97 CPPUNIT_ASSERT(!r1); |
|
98 |
|
99 v2[0] = "Brett"; |
|
100 v2[1] = "Todd"; |
|
101 bool r2 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings); |
|
102 CPPUNIT_ASSERT(r2); |
|
103 } |