reactos/lib/3rdparty/stlport/test/unit/bsearch_test.cpp
Amine Khaldi 4efda499f7 [CMAKE]
Jerome Gardou:
- Add STLport 5.2.1 (yes, STLport, the c++ stl implementation) to build. For now, it works only in user mode.
- Link some c++ executables to it
- sol.exe : one step towards a complete and modern OS.
- Dedicated to Amine for his patience and his help.
- Might Break Things! (tm)

svn path=/branches/cmake-bringup/; revision=49046
2010-10-07 22:09:31 +00:00

50 lines
1.1 KiB
C++

#include <algorithm>
#include "cppunit/cppunit_proxy.h"
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif
//
// TestCase class
//
class BsearchTest : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(BsearchTest);
CPPUNIT_TEST(bsearch1);
CPPUNIT_TEST(bsearch2);
CPPUNIT_TEST_SUITE_END();
protected:
void bsearch1();
void bsearch2();
static bool str_compare(const char* a_, const char* b_);
};
CPPUNIT_TEST_SUITE_REGISTRATION(BsearchTest);
//
// tests implementation
//
void BsearchTest::bsearch1()
{
int vector[100];
for(int i = 0; i < 100; i++)
vector[i] = i;
CPPUNIT_ASSERT(binary_search(vector, vector + 100, 42));
}
void BsearchTest::bsearch2()
{
char const* labels[] = { "aa", "dd", "ff", "jj", "ss", "zz" };
const unsigned count = sizeof(labels) / sizeof(labels[0]);
// DEC C++ generates incorrect template instatiation code
// for "ff" so must cast
CPPUNIT_ASSERT(binary_search(labels, labels + count, (const char *)"ff", str_compare));
}
bool BsearchTest::str_compare(const char* a_, const char* b_)
{
return strcmp(a_, b_) < 0 ? 1 : 0;
}