Revert "Roll NDK to r11c and extract it into its own repository."
[android_tools.git] / ndk / tests / device / test-gnustl-full / unit / unique_test.cpp
blobb080b7b87e15d445e2c4bcf150dc2c9254f6010e
1 #include <algorithm>
3 #include "cppunit/cppunit_proxy.h"
5 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
6 using namespace std;
7 #endif
9 //
10 // TestCase class
12 class UniqueTest : public CPPUNIT_NS::TestCase
14 CPPUNIT_TEST_SUITE(UniqueTest);
15 CPPUNIT_TEST(uniqcpy1);
16 CPPUNIT_TEST(uniqcpy2);
17 CPPUNIT_TEST(unique1);
18 CPPUNIT_TEST(unique2);
19 CPPUNIT_TEST_SUITE_END();
21 protected:
22 void uniqcpy1();
23 void uniqcpy2();
24 void unique1();
25 void unique2();
28 CPPUNIT_TEST_SUITE_REGISTRATION(UniqueTest);
30 static bool str_equal(const char* a_, const char* b_)
31 { return *a_ == *b_; }
33 // tests implementation
35 void UniqueTest::unique1()
37 int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 };
38 unique((int*)numbers, (int*)numbers + 8);
39 // 0 1 2 3 4 2 3 4
40 CPPUNIT_ASSERT(numbers[0]==0);
41 CPPUNIT_ASSERT(numbers[1]==1);
42 CPPUNIT_ASSERT(numbers[2]==2);
43 CPPUNIT_ASSERT(numbers[3]==3);
44 CPPUNIT_ASSERT(numbers[4]==4);
45 CPPUNIT_ASSERT(numbers[5]==2);
46 CPPUNIT_ASSERT(numbers[6]==3);
47 CPPUNIT_ASSERT(numbers[7]==4);
50 void UniqueTest::unique2()
52 const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"};
54 const unsigned count = sizeof(labels) / sizeof(labels[0]);
56 unique((const char**)labels, (const char**)labels + count, str_equal);
58 // QWERTY
59 CPPUNIT_ASSERT(*labels[0] == 'Q');
60 CPPUNIT_ASSERT(*labels[1] == 'W');
61 CPPUNIT_ASSERT(*labels[2] == 'E');
62 CPPUNIT_ASSERT(*labels[3] == 'R');
63 CPPUNIT_ASSERT(*labels[4] == 'T');
64 CPPUNIT_ASSERT(*labels[5] == 'Y');
68 void UniqueTest::uniqcpy1()
70 int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 };
71 int result[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
73 unique_copy((int*)numbers, (int*)numbers + 8, (int*)result);
75 // 0 1 2 3 4 0 0 0
76 CPPUNIT_ASSERT(result[0]==0);
77 CPPUNIT_ASSERT(result[1]==1);
78 CPPUNIT_ASSERT(result[2]==2);
79 CPPUNIT_ASSERT(result[3]==3);
80 CPPUNIT_ASSERT(result[4]==4);
81 CPPUNIT_ASSERT(result[5]==0);
82 CPPUNIT_ASSERT(result[6]==0);
83 CPPUNIT_ASSERT(result[7]==0);
86 void UniqueTest::uniqcpy2()
88 const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"};
89 const char **plabels = (const char**)labels;
91 const size_t count = sizeof(labels) / sizeof(labels[0]);
92 const char* uCopy[count];
93 const char **puCopy = &uCopy[0];
94 fill(puCopy, puCopy + count, "");
96 unique_copy(plabels, plabels + count, puCopy, str_equal);
98 //QWERTY
99 CPPUNIT_ASSERT(*uCopy[0] == 'Q');
100 CPPUNIT_ASSERT(*uCopy[1] == 'W');
101 CPPUNIT_ASSERT(*uCopy[2] == 'E');
102 CPPUNIT_ASSERT(*uCopy[3] == 'R');
103 CPPUNIT_ASSERT(*uCopy[4] == 'T');
104 CPPUNIT_ASSERT(*uCopy[5] == 'Y');