1*c2c66affSColin Finck #define _STLP_DO_IMPORT_CSTD_FUNCTIONS
2*c2c66affSColin Finck 
3*c2c66affSColin Finck #include <cstring>
4*c2c66affSColin Finck 
5*c2c66affSColin Finck #include "cppunit/cppunit_proxy.h"
6*c2c66affSColin Finck 
7*c2c66affSColin Finck //This test purpose is to check the right import of math.h C symbols
8*c2c66affSColin Finck //into the std namespace so we do not use the using namespace std
9*c2c66affSColin Finck //specification
10*c2c66affSColin Finck 
11*c2c66affSColin Finck //
12*c2c66affSColin Finck // TestCase class
13*c2c66affSColin Finck //
14*c2c66affSColin Finck class CStringTest : public CPPUNIT_NS::TestCase
15*c2c66affSColin Finck {
16*c2c66affSColin Finck   CPPUNIT_TEST_SUITE(CStringTest);
17*c2c66affSColin Finck #if defined (STLPORT) && !defined (_STLP_USE_NAMESPACES)
18*c2c66affSColin Finck   CPPUNIT_IGNORE;
19*c2c66affSColin Finck #endif
20*c2c66affSColin Finck   CPPUNIT_TEST(import_checks);
21*c2c66affSColin Finck   CPPUNIT_TEST_SUITE_END();
22*c2c66affSColin Finck 
23*c2c66affSColin Finck   protected:
24*c2c66affSColin Finck     void import_checks();
25*c2c66affSColin Finck };
26*c2c66affSColin Finck 
27*c2c66affSColin Finck CPPUNIT_TEST_SUITE_REGISTRATION(CStringTest);
28*c2c66affSColin Finck 
29*c2c66affSColin Finck #if defined (_MSC_VER) && (_MSC_VER >= 1400)
30*c2c66affSColin Finck //For deprecated symbols like strcat, strtok...
31*c2c66affSColin Finck #  pragma warning (disable : 4996)
32*c2c66affSColin Finck #endif
33*c2c66affSColin Finck 
34*c2c66affSColin Finck //
35*c2c66affSColin Finck // tests implementation
36*c2c66affSColin Finck //
import_checks()37*c2c66affSColin Finck void CStringTest::import_checks()
38*c2c66affSColin Finck {
39*c2c66affSColin Finck #if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
40*c2c66affSColin Finck   std::size_t bar = 0;
41*c2c66affSColin Finck   CPPUNIT_CHECK( bar == 0 );
42*c2c66affSColin Finck 
43*c2c66affSColin Finck   CPPUNIT_CHECK( std::memchr("foo", 'o', 3) != NULL );
44*c2c66affSColin Finck   CPPUNIT_CHECK( std::memcmp("foo1", "foo2", 3) == 0 );
45*c2c66affSColin Finck   char buf1[1], buf2[1];
46*c2c66affSColin Finck   CPPUNIT_CHECK( std::memcpy(buf1, buf2, 0) != NULL );
47*c2c66affSColin Finck   CPPUNIT_CHECK( std::memmove(buf1, buf2, 0) != NULL );
48*c2c66affSColin Finck   CPPUNIT_CHECK( std::memset(buf1, 0, 1) != NULL );
49*c2c66affSColin Finck   char buf[16]; buf[0] = 0;
50*c2c66affSColin Finck   const char* foo = "foo";
51*c2c66affSColin Finck #  if !defined(_WIN32_WCE)
52*c2c66affSColin Finck   CPPUNIT_CHECK( std::strcoll("foo", "foo") == 0 );
53*c2c66affSColin Finck   CPPUNIT_CHECK( std::strerror(0) != NULL );
54*c2c66affSColin Finck #  endif
55*c2c66affSColin Finck   CPPUNIT_CHECK( std::strcat((char*)buf, foo) == (char*)buf ); // buf <- foo
56*c2c66affSColin Finck   CPPUNIT_CHECK( std::strchr(foo, 'o') != NULL );
57*c2c66affSColin Finck   CPPUNIT_CHECK( std::strcmp("foo1", "foo2") < 0 );
58*c2c66affSColin Finck   CPPUNIT_CHECK( std::strcpy((char*)buf, foo) == (char*)buf ); // buf <- foo
59*c2c66affSColin Finck   CPPUNIT_CHECK( std::strcspn("foo", "o") == 1 );
60*c2c66affSColin Finck   CPPUNIT_CHECK( std::strlen("foo") == 3 );
61*c2c66affSColin Finck   CPPUNIT_CHECK( std::strncat((char*)buf, foo, 2) == (char*)buf ); // buf <- foofo
62*c2c66affSColin Finck   CPPUNIT_CHECK( std::strncmp("foo1", "foo2", 3) == 0 );
63*c2c66affSColin Finck   CPPUNIT_CHECK( std::strncpy((char*)buf, foo, 3) == (char*)buf ); // buf <- foo
64*c2c66affSColin Finck   CPPUNIT_CHECK( std::strpbrk(foo, "abcdo") == foo + 1 );
65*c2c66affSColin Finck   const char* foofoo = "foofoo";
66*c2c66affSColin Finck   CPPUNIT_CHECK( std::strrchr(foofoo, 'f') == foofoo + 3 );
67*c2c66affSColin Finck   CPPUNIT_CHECK( std::strspn(foofoo, "aofz") == 6 );
68*c2c66affSColin Finck   CPPUNIT_CHECK( std::strstr(foo, "") == foo );
69*c2c66affSColin Finck   char foofoobuf[] = "foofoo";
70*c2c66affSColin Finck   CPPUNIT_CHECK( std::strtok(foofoobuf, "z") != NULL );
71*c2c66affSColin Finck #  if !defined(_WIN32_WCE)
72*c2c66affSColin Finck   CPPUNIT_CHECK( std::strxfrm((char*)buf, foo, 3) != 0 );
73*c2c66affSColin Finck #  endif
74*c2c66affSColin Finck #endif
75*c2c66affSColin Finck }
76