예제 #1
0
int
main (int, char *[])
{
  ACE_Time_Value tv1;
  ACE_Time_Value tv2 (2);
  ACE_Time_Value tv3 (100);
  ACE_Time_Value tv4 (1, 1000000);
  ACE_Time_Value tv5 (2);
  ACE_Time_Value tv6 (1, -1000000);

  ACE_ASSERT (tv1 == ACE_Time_Value (0));
  ACE_ASSERT (tv2 < tv3);
  ACE_ASSERT (tv2 <= tv2);
  ACE_ASSERT (tv2 >= tv4);
  ACE_ASSERT (tv5 >= tv6);
  ACE_ASSERT (tv2 == ACE_Time_Value (1, 1000000));
  ACE_ASSERT (tv5 == tv4);
  ACE_ASSERT (tv2 == tv4);
  ACE_ASSERT (tv1 != tv2);
  ACE_ASSERT (tv6 == tv1);

# if defined (ACE_NDEBUG)
  ACE_UNUSED_ARG (tv1);
  ACE_UNUSED_ARG (tv2);
  ACE_UNUSED_ARG (tv3);
  ACE_UNUSED_ARG (tv4);
  ACE_UNUSED_ARG (tv5);
  ACE_UNUSED_ARG (tv6);
# endif /* ACE_NDEBUG */

  cout << "0,0 :\t\t"        << ACE_Time_Value (0,0) << endl;
  cout << "-0,0 :\t\t"       << ACE_Time_Value (-0,0) << endl;
  cout << "0,-0 :\t\t"       << ACE_Time_Value (0,-0) << endl;
  cout << "-0,-0 :\t\t"      << ACE_Time_Value (-0,-0) << endl;
  cout << endl;

  cout << "0,1 :\t\t"        << ACE_Time_Value (0,1) << endl;
  cout << "1,0 :\t\t"        << ACE_Time_Value (1,0) << endl;
  cout << "-1,0 :\t\t"       << ACE_Time_Value (-1,0) << endl;
  cout << "-1,-0 :\t\t"      << ACE_Time_Value (-1,-0) << endl;
  cout << endl;

  cout << "1,1 :\t\t"        << ACE_Time_Value (1,1) << endl;
  cout << "-1,1 :\t\t"       << ACE_Time_Value (-1,1) << endl;
  cout << "1,-1 :\t\t"       << ACE_Time_Value (1,-1) << endl;
  cout << "-1,-1 :\t\t"      << ACE_Time_Value (-1,-1) << endl;
  cout << endl;

  cout << "1,-1111111 :\t"   << ACE_Time_Value (1,-1111111) << endl;
  cout << "1,-100000 :\t"    << ACE_Time_Value (1,-100000) << endl;
  cout << "1,-1000000 :\t"   << ACE_Time_Value (1,-1000000) << endl;
  cout << "-1,1000000 :\t"   << ACE_Time_Value (-1,1000000) << endl;
  cout << "5,-1000000 :\t"   << ACE_Time_Value (5,-1000000) << endl;
  cout << "5,-1500000 :\t"   << ACE_Time_Value (5,-1500000) << endl;
  cout << "2,-2500000 :\t"   << ACE_Time_Value (2,-2500000) << endl;
  cout << "2,-4500000 :\t"   << ACE_Time_Value (2,-4500000) << endl;

  return 0;
}
int
run_main (int, ACE_TCHAR *[])
{
    int ret = 0;

    ACE_START_TEST (ACE_TEXT ("Time_Value_Test"));

    ACE_Time_Value tv1;
    ACE_Time_Value tv2 (2);
    ACE_Time_Value tv3 (100U);
    ACE_Time_Value tv4 (1, 1000000);
    ACE_Time_Value tv5 (2UL);
    ACE_Time_Value tv6 (1, -1000000);
    ACE_Time_Value tv7 (ACE_static_cast (long, 2.0));

    // Beware!  2.5 gets truncated to 2!
    // NOTE:  this is intended to show what happens with
    // ACE_Time_Value (2.5).  Some compilers, such as g++ 2.7.2.3,
    // actually warn about it without the case.
    ACE_Time_Value tv8 (ACE_static_cast (long, 2.5));

    // Test assignment operator, tv9 and tv6 must be the same after this
    ACE_Time_Value tv9;
    tv9 = tv6;

    ACE_ASSERT (tv1 == ACE_Time_Value (0));
    ACE_ASSERT (tv2 < tv3);
    ACE_ASSERT (tv2 <= tv2);
    ACE_ASSERT (tv2 >= tv4);
    ACE_ASSERT (tv5 >= tv6);
    ACE_ASSERT (tv2 == ACE_Time_Value (1, 1000000));
    ACE_ASSERT (tv5 == tv4);
    ACE_ASSERT (tv2 == tv4);
    ACE_ASSERT (tv1 != tv2);
    ACE_ASSERT (tv6 == tv1);
    ACE_ASSERT (tv5 == tv7);
    ACE_ASSERT (tv7 == tv8); // That's right!  See above . . .
    ACE_ASSERT (tv9 == tv6);

#if defined (sun) && !defined (ACE_LACKS_LONGLONG_T)
    if (test_ace_u_longlong () != 0)
        ++ret;
#endif /* sun && ! ACE_LACKS_LONGLONG_T */

    ACE_END_TEST;
    return ret;
}
예제 #3
0
파일: test_timeval.cpp 프로젝트: psfu/ULib
int U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

   U_TRACE(5,"main(%d)",argc)

   UTimeVal x;

   x.set(0L);
   U_ASSERT(x.isZero());

   UTimeVal a(1L);
   UTimeVal y(a);

   a.add(8L, 1999999L);
   a.sub(8L, 1999999L);

   U_ASSERT(y == a);
   U_ASSERT(y == UTimeVal(1L));
   U_ASSERT(y <= UTimeVal(1L));
   U_ASSERT(y >= UTimeVal(1L));
   U_ASSERT(y >  UTimeVal(0L, 999999));
   U_ASSERT(y <  UTimeVal(1L, 2L));

   y = a;
   U_ASSERT(y == a);

   UTimeVal tv1;
   UTimeVal tv2(2);
   UTimeVal tv3(100);
   UTimeVal tv4(1, 100000);
   UTimeVal tv5(2);
   UTimeVal tv6(1, -100000);

   tv1.set(0L);

   U_ASSERT(tv1 == x);
   U_ASSERT(tv2 < tv3);
   U_ASSERT(tv2 <= tv2);
   U_ASSERT(tv2 >= tv4);
   U_ASSERT(tv5 >= tv6);
   U_ASSERT(tv5 != tv4);
   U_ASSERT(tv2 != tv4);
   U_ASSERT(tv1 != tv2);
   U_ASSERT(tv6 != tv1);

   U_gettimeofday

   U_ASSERT(y < *u_now);

   set_alarm();

   y.nanosleep();

   y += *u_now;

   U_ASSERT(y > *u_now);

   /*
   long start = (u_now->tv_sec - (u_now->tv_sec % U_ONE_HOUR_IN_SECOND));

   for (uint32_t i = 0; i <= U_ONE_DAY_IN_SECOND; ++i) check_time(start+i);
   */
}