1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/bsearch_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,49 @@
1.4 +#include <algorithm>
1.5 +
1.6 +#include "cppunit/cppunit_proxy.h"
1.7 +
1.8 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.9 +using namespace std;
1.10 +#endif
1.11 +
1.12 +//
1.13 +// TestCase class
1.14 +//
1.15 +class BsearchTest : public CPPUNIT_NS::TestCase
1.16 +{
1.17 + CPPUNIT_TEST_SUITE(BsearchTest);
1.18 + CPPUNIT_TEST(bsearch1);
1.19 + CPPUNIT_TEST(bsearch2);
1.20 + CPPUNIT_TEST_SUITE_END();
1.21 +
1.22 +protected:
1.23 + void bsearch1();
1.24 + void bsearch2();
1.25 + static bool str_compare(const char* a_, const char* b_);
1.26 +};
1.27 +
1.28 +CPPUNIT_TEST_SUITE_REGISTRATION(BsearchTest);
1.29 +
1.30 +//
1.31 +// tests implementation
1.32 +//
1.33 +void BsearchTest::bsearch1()
1.34 +{
1.35 + int vector[100];
1.36 + for(int i = 0; i < 100; i++)
1.37 + vector[i] = i;
1.38 + CPPUNIT_ASSERT(binary_search(vector, vector + 100, 42));
1.39 +}
1.40 +
1.41 +void BsearchTest::bsearch2()
1.42 +{
1.43 + char const* labels[] = { "aa", "dd", "ff", "jj", "ss", "zz" };
1.44 + const unsigned count = sizeof(labels) / sizeof(labels[0]);
1.45 + // DEC C++ generates incorrect template instatiation code
1.46 + // for "ff" so must cast
1.47 + CPPUNIT_ASSERT(binary_search(labels, labels + count, (const char *)"ff", str_compare));
1.48 +}
1.49 +bool BsearchTest::str_compare(const char* a_, const char* b_)
1.50 +{
1.51 + return strcmp(a_, b_) < 0 ? 1 : 0;
1.52 +}