1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/max_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,64 @@
1.4 +#include <vector>
1.5 +#include <algorithm>
1.6 +
1.7 +#include "cppunit/cppunit_proxy.h"
1.8 +
1.9 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.10 +using namespace std;
1.11 +#endif
1.12 +
1.13 +//
1.14 +// TestCase class
1.15 +//
1.16 +class MaxTest : public CPPUNIT_NS::TestCase
1.17 +{
1.18 + CPPUNIT_TEST_SUITE(MaxTest);
1.19 + CPPUNIT_TEST(max1);
1.20 + CPPUNIT_TEST(max2);
1.21 + CPPUNIT_TEST(maxelem1);
1.22 + CPPUNIT_TEST(maxelem2);
1.23 + CPPUNIT_TEST_SUITE_END();
1.24 +
1.25 +protected:
1.26 + void max1();
1.27 + void max2();
1.28 + void maxelem1();
1.29 + void maxelem2();
1.30 +
1.31 + static bool str_compare(const char* a_, const char* b_)
1.32 + { return strcmp(a_, b_) < 0 ? 1 : 0; }
1.33 +};
1.34 +
1.35 +CPPUNIT_TEST_SUITE_REGISTRATION(MaxTest);
1.36 +
1.37 +//
1.38 +// tests implementation
1.39 +//
1.40 +void MaxTest::max1()
1.41 +{
1.42 + int r = max(42, 100);
1.43 + CPPUNIT_ASSERT( r == 100 );
1.44 +
1.45 + r = max(++r, r);
1.46 + CPPUNIT_ASSERT( r == 101 );
1.47 +}
1.48 +void MaxTest::max2()
1.49 +{
1.50 + const char* r = max((const char*)"shoe", (const char*)"shine", str_compare);
1.51 + CPPUNIT_ASSERT(!strcmp(r, "shoe"));
1.52 +}
1.53 +void MaxTest::maxelem1()
1.54 +{
1.55 + int numbers[6] = { 4, 10, 56, 11, -42, 19 };
1.56 +
1.57 + int* r = max_element((int*)numbers, (int*)numbers + 6);
1.58 + CPPUNIT_ASSERT(*r==56);
1.59 +}
1.60 +void MaxTest::maxelem2()
1.61 +{
1.62 + const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
1.63 +
1.64 + const unsigned namesCt = sizeof(names) / sizeof(names[0]);
1.65 + const char** r = max_element((const char**)names, (const char**)names + namesCt, str_compare);
1.66 + CPPUNIT_ASSERT(!strcmp(*r, "Todd"));
1.67 +}