This source file includes following definitions.
- TEST
- TEST
- TEST
#include <math.h>
#include <stdlib.h>
#include "ppapi/shared_impl/time_conversion.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ppapi {
static const int kTimeInternalValueSlop = 2;
static const double kTimeSecondsSlop =
static_cast<double>(kTimeInternalValueSlop) /
base::Time::kMicrosecondsPerSecond;
TEST(TimeConversion, Time) {
base::Time now = base::Time::Now();
base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(now));
EXPECT_GE(kTimeInternalValueSlop,
abs(static_cast<int>((converted - now).ToInternalValue())));
base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
double converted_one_second_from_now =
ppapi::TimeToPPTime(one_second_from_now) - ppapi::TimeToPPTime(now);
EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_now - 1));
}
TEST(TimeConversion, EventTime) {
base::Time now = base::Time::Now();
double event_now = now.ToDoubleT();
double converted =
ppapi::EventTimeToPPTimeTicks(ppapi::PPTimeTicksToEventTime(event_now));
EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now));
base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
double event_one_second_from_now = one_second_from_now.ToDoubleT();
EXPECT_GE(kTimeSecondsSlop,
1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) -
ppapi::EventTimeToPPTimeTicks(event_now));
}
TEST(TimeConversion, EpochTime) {
base::Time epoch = base::Time::UnixEpoch();
base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(epoch));
EXPECT_GE(kTimeInternalValueSlop,
abs(static_cast<int>((converted - epoch).ToInternalValue())));
base::Time one_second_from_epoch = epoch + base::TimeDelta::FromSeconds(1);
double converted_one_second_from_epoch =
ppapi::TimeToPPTime(one_second_from_epoch) - ppapi::TimeToPPTime(epoch);
EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_epoch - 1));
EXPECT_GE(kTimeSecondsSlop, fabs(ppapi::TimeToPPTime(epoch) - 0.0));
EXPECT_GE(kTimeInternalValueSlop,
abs(static_cast<int>(
(ppapi::PPTimeToTime(0.0) - epoch).ToInternalValue())));
}
}