Beispiel #1
0
//
// tests implementation
//
void CStringTest::import_checks()
{
#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
  std::size_t bar = 0;
  CPPUNIT_CHECK( bar == 0 );

  CPPUNIT_CHECK( std::memchr("foo", 'o', 3) != NULL );
  CPPUNIT_CHECK( std::memcmp("foo1", "foo2", 3) == 0 );
  char buf1[1], buf2[1];
  CPPUNIT_CHECK( std::memcpy(buf1, buf2, 0) != NULL );
  CPPUNIT_CHECK( std::memmove(buf1, buf2, 0) != NULL );
  CPPUNIT_CHECK( std::memset(buf1, 0, 1) != NULL );
  char buf[16]; buf[0] = 0;
  const char* foo = "foo";
  CPPUNIT_CHECK( std::strcat((char*)buf, foo) == (char*)buf ); // buf <- foo
  CPPUNIT_CHECK( std::strchr(foo, 'o') != NULL );
  CPPUNIT_CHECK( std::strcmp("foo1", "foo2") < 0 );
  CPPUNIT_CHECK( std::strcoll("foo", "foo") == 0 );
  CPPUNIT_CHECK( std::strcpy((char*)buf, foo) == (char*)buf ); // buf <- foo
  CPPUNIT_CHECK( std::strcspn("foo", "o") == 1 );
  CPPUNIT_CHECK( std::strerror(0) != NULL );
  CPPUNIT_CHECK( std::strlen("foo") == 3 );
  CPPUNIT_CHECK( std::strncat((char*)buf, foo, 2) == (char*)buf ); // buf <- foofo
  CPPUNIT_CHECK( std::strncmp("foo1", "foo2", 3) == 0 );
  CPPUNIT_CHECK( std::strncpy((char*)buf, foo, 3) == (char*)buf ); // buf <- foo
  CPPUNIT_CHECK( std::strpbrk(foo, "abcdo") == foo + 1 );
  const char* foofoo = "foofoo";
  CPPUNIT_CHECK( std::strrchr(foofoo, 'f') == foofoo + 3 );
  CPPUNIT_CHECK( std::strspn(foofoo, "aofz") == 6 );
  CPPUNIT_CHECK( std::strstr(foo, "") == foo );
  char foofoobuf[] = "foofoo";
  CPPUNIT_CHECK( std::strtok(foofoobuf, "z") != NULL );
  CPPUNIT_CHECK( std::strxfrm((char*)buf, foo, 3) != 0 );
#endif
}
Beispiel #2
0
//
// tests implementation
//
void CMathTest::test()
{
  int int_val = -1;
  long long_val = -1l;
  float float_val = -1.0f;
  double double_val = -1.0;
#if !defined (_STLP_NO_LONG_DOUBLE)
  long double long_double_val = -1.0l;
#endif

  CPPUNIT_CHECK( are_equals(std::abs(int_val), -int_val) );
  CPPUNIT_CHECK( are_equals(std::abs(long_val), -long_val) );
  CPPUNIT_CHECK( are_equals(std::labs(long_val), -long_val) );
  CPPUNIT_CHECK( are_equals(std::abs(float_val), -float_val) );
  CPPUNIT_CHECK( are_equals(std::abs(double_val), -double_val) );
#if !defined (_STLP_NO_LONG_DOUBLE)
  CPPUNIT_CHECK( are_equals(std::abs(long_double_val), -long_double_val) );
#endif

  CPPUNIT_CHECK( are_equals(std::fabs(float_val), -float_val) );
  CPPUNIT_CHECK( are_equals(std::fabs(double_val), -double_val) );
#if !defined (_STLP_NO_LONG_DOUBLE)
  CPPUNIT_CHECK( are_equals(std::fabs(long_double_val), -long_double_val) );
#endif

  std::div_t div_res = std::div(3, 2);
  CPPUNIT_CHECK( div_res.quot == 1 );
  CPPUNIT_CHECK( div_res.rem == 1 );
  std::ldiv_t ldiv_res = std::ldiv(3l, 2l);
  CPPUNIT_CHECK( ldiv_res.quot == 1l );
  CPPUNIT_CHECK( ldiv_res.rem == 1l );
  ldiv_res = std::div(3l, 2l);
  CPPUNIT_CHECK( ldiv_res.quot == 1l );
  CPPUNIT_CHECK( ldiv_res.rem == 1l );

  std::srand(2);
  int rand_val = std::rand();
  CPPUNIT_CHECK( rand_val >= 0 && rand_val <= RAND_MAX );

  CPPUNIT_CHECK( are_equals(std::floor(1.5), 1.0) );
  CPPUNIT_CHECK( are_equals(std::ceil(1.5), 2.0) );
  CPPUNIT_CHECK( are_equals(std::fmod(1.5, 1.0), 0.5) );
  CPPUNIT_CHECK( are_equals(std::sqrt(4.0), 2.0) );
  CPPUNIT_CHECK( are_equals(std::pow(2.0, 2), 4.0) );
  /*
   * Uncomment the following to check that it generates an ambiguous call
   * as there is no Standard pow(int, int) function only pow(double, int),
   * pow(float, int) and some others...
   * If it do not generate a compile time error it should at least give
   * the good result.
   */
  //CPPUNIT_CHECK( are_equals(std::pow(10, -2), 0.01) );
  CPPUNIT_CHECK( are_equals(std::pow(10.0, -2), 0.01) );
  CPPUNIT_CHECK( are_equals(std::exp(0.0), 1.0) );
  CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0)), 1.0) );
  CPPUNIT_CHECK( are_equals(std::log10(100.0), 2.0) );
#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64)
  CPPUNIT_CHECK( are_equals(std::modf(100.5, &double_val), 0.5) );
  CPPUNIT_CHECK( are_equals(double_val, 100.0) );
#endif
  double_val = std::frexp(8.0, &int_val);
  CPPUNIT_CHECK( are_equals(double_val * std::pow(2.0, int_val), 8.0) );
  CPPUNIT_CHECK( are_equals(std::ldexp(1.0, 2), 4.0) );
  CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0)), 1.0) );
  CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0)), 1.0) );
  CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0)), 1.0) );
  CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0, 1.0)), 1.0) );
  CPPUNIT_CHECK( are_equals(std::cosh(0.0), 1.0) );
  CPPUNIT_CHECK( are_equals(std::sinh(0.0), 0.0) );
#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64)
  CPPUNIT_CHECK( are_equals(std::tanh(0.0), 0.0) );
#endif

  CPPUNIT_CHECK( are_equals(std::floor(1.5f), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::ceil(1.5f), 2.0f) );
  CPPUNIT_CHECK( are_equals(std::fmod(1.5f, 1.0f), 0.5f) );
  CPPUNIT_CHECK( are_equals(std::sqrt(4.0f), 2.0f) );
  CPPUNIT_CHECK( are_equals(std::pow(2.0f, 2), 4.0f) );
  CPPUNIT_CHECK( are_equals(std::exp(0.0f), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0f)), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::log10(100.0f), 2.0f) );
#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64)
  CPPUNIT_CHECK( are_equals(std::modf(100.5f, &float_val), 0.5f) );
  CPPUNIT_CHECK( are_equals(float_val, 100.0f) );
#endif
  float_val = std::frexp(8.0f, &int_val);
  CPPUNIT_CHECK( are_equals(float_val * std::pow(2.0f, int_val), 8.0f) );
  CPPUNIT_CHECK( are_equals(std::ldexp(1.0f, 2), 4.0f) );
  CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0f)), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0f)), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0f)), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0f, 1.0f)), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::cosh(0.0f), 1.0f) );
  CPPUNIT_CHECK( are_equals(std::sinh(0.0f), 0.0f) );
#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64)
  CPPUNIT_CHECK( are_equals(std::tanh(0.0f), 0.0f) );
#endif

#if !defined (_STLP_NO_LONG_DOUBLE)
  CPPUNIT_CHECK( are_equals(std::floor(1.5l), 1.0l) );
  CPPUNIT_CHECK( are_equals(std::ceil(1.5l), 2.0l) );
  CPPUNIT_CHECK( are_equals(std::fmod(1.5l, 1.0l), 0.5l) );
  CPPUNIT_CHECK( are_equals(std::sqrt(4.0l), 2.0l) );
  CPPUNIT_CHECK( are_equals(std::pow(2.0l, 2), 4.0l) );
  CPPUNIT_CHECK( are_equals(std::exp(0.0l), 1.0l) );
  CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0l)), 1.0l) );
  CPPUNIT_CHECK( are_equals(std::log10(100.0l), 2.0l) );
#  if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64)
  CPPUNIT_CHECK( are_equals(std::modf(100.5l, &long_double_val), 0.5l) );
  CPPUNIT_CHECK( are_equals(long_double_val, 100.0l) );
#  endif
  long_double_val = std::frexp(8.0l, &int_val);
  CPPUNIT_CHECK( are_equals(long_double_val * std::pow(2.0l, int_val), 8.0l) );
  CPPUNIT_CHECK( are_equals(std::ldexp(1.0l, 2), 4.0l) );
  CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0l)), 1.0l) );
  CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0l)), 1.0l) );
  CPPUNIT_CHECK( are_equals(std::tan(0.0l), 0.0l) );
  CPPUNIT_CHECK( are_equals(std::atan(0.0l), 0.0l) );
  CPPUNIT_CHECK( are_equals(std::atan2(0.0l, 1.0l), 0.0l) );
  CPPUNIT_CHECK( are_equals(std::cosh(0.0l), 1.0l) );
  CPPUNIT_CHECK( are_equals(std::sinh(0.0l), 0.0l) );
#  if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64)
  CPPUNIT_CHECK( are_equals(std::tanh(0.0l), 0.0l) );
#  endif
#endif

  CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0))), 2.0) );
  CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0f))), 2.0f) );
#if !defined (_STLP_NO_LONG_DOUBLE)
  CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0l))), 2.0l) );
#endif
}