1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/includes_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,87 @@
1.4 +#include <cstring>
1.5 +#include <vector>
1.6 +#include <algorithm>
1.7 +
1.8 +#include "cppunit/cppunit_proxy.h"
1.9 +
1.10 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.11 +using namespace std;
1.12 +#endif
1.13 +
1.14 +//
1.15 +// TestCase class
1.16 +//
1.17 +class IncludesTest : public CPPUNIT_NS::TestCase
1.18 +{
1.19 + CPPUNIT_TEST_SUITE(IncludesTest);
1.20 + CPPUNIT_TEST(incl0);
1.21 + CPPUNIT_TEST(incl1);
1.22 + CPPUNIT_TEST(incl2);
1.23 + CPPUNIT_TEST_SUITE_END();
1.24 +
1.25 +protected:
1.26 + void incl0();
1.27 + void incl1();
1.28 + void incl2();
1.29 +
1.30 + static bool compare_strings(const char* s1_, const char* s2_)
1.31 + {
1.32 + return strcmp(s1_, s2_) < 0 ? 1 : 0;
1.33 + }
1.34 +};
1.35 +
1.36 +CPPUNIT_TEST_SUITE_REGISTRATION(IncludesTest);
1.37 +
1.38 +//
1.39 +// tests implementation
1.40 +//
1.41 +void IncludesTest::incl0()
1.42 +{
1.43 + int numbers1[5] = { 1, 2, 3, 4, 5 };
1.44 + //int numbers2[5] = { 1, 2, 4, 8, 16 };
1.45 + int numbers3[2] = { 4, 8 };
1.46 + bool r1=includes(numbers1, numbers1 + 5, numbers3, numbers3 + 2);
1.47 + CPPUNIT_ASSERT(!r1);
1.48 +}
1.49 +void IncludesTest::incl1()
1.50 +{
1.51 + vector<int> v1(10);
1.52 + vector<int> v2(3);
1.53 + int i;
1.54 + for (i = 0; (size_t)i < v1.size(); ++i) {
1.55 + v1[i] = i;
1.56 + }
1.57 +
1.58 + bool r1=includes(v1.begin(), v1.end(), v2.begin(), v2.end());
1.59 + CPPUNIT_ASSERT(!r1);
1.60 +
1.61 + for (i = 0; (size_t)i < v2.size(); ++i)
1.62 + v2[i] = i + 3;
1.63 +
1.64 + bool r2=includes(v1.begin(), v1.end(), v2.begin(), v2.end());
1.65 + CPPUNIT_ASSERT(r2);
1.66 +}
1.67 +void IncludesTest::incl2()
1.68 +{
1.69 + char const* names[] = { "Todd", "Mike", "Graham", "Jack", "Brett"};
1.70 +
1.71 + const unsigned nameSize = sizeof(names)/sizeof(names[0]);
1.72 + vector <char const*> v1(nameSize);
1.73 + for (int i = 0; (size_t)i < v1.size(); ++i) {
1.74 + v1[i] = names[i];
1.75 + }
1.76 + vector <char const*> v2(2);
1.77 +
1.78 + v2[0] = "foo";
1.79 + v2[1] = "bar";
1.80 + sort(v1.begin(), v1.end(), compare_strings);
1.81 + sort(v2.begin(), v2.end(), compare_strings);
1.82 +
1.83 + bool r1 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings);
1.84 + CPPUNIT_ASSERT(!r1);
1.85 +
1.86 + v2[0] = "Brett";
1.87 + v2[1] = "Todd";
1.88 + bool r2 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings);
1.89 + CPPUNIT_ASSERT(r2);
1.90 +}