This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/profiler/tracked_time.h"
#include "base/time/time.h"
#include "base/tracked_objects.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace tracked_objects {
TEST(TrackedTimeTest, TrackedTimerMilliseconds) {
int32 kSomeMilliseconds = 243;
int64 kReallyBigMilliseconds = (1LL << 35) + kSomeMilliseconds;
TrackedTime some = TrackedTime() +
Duration::FromMilliseconds(kSomeMilliseconds);
EXPECT_EQ(kSomeMilliseconds, (some - TrackedTime()).InMilliseconds());
EXPECT_FALSE(some.is_null());
base::TimeTicks big = base::TimeTicks() +
base::TimeDelta::FromMilliseconds(kReallyBigMilliseconds);
EXPECT_EQ(kReallyBigMilliseconds, (big - base::TimeTicks()).InMilliseconds());
TrackedTime wrapped_big(big);
EXPECT_EQ(kSomeMilliseconds, (wrapped_big - TrackedTime()).InMilliseconds());
}
TEST(TrackedTimeTest, TrackedTimerDuration) {
int kFirstMilliseconds = 793;
int kSecondMilliseconds = 14889;
Duration first = Duration::FromMilliseconds(kFirstMilliseconds);
Duration second = Duration::FromMilliseconds(kSecondMilliseconds);
EXPECT_EQ(kFirstMilliseconds, first.InMilliseconds());
EXPECT_EQ(kSecondMilliseconds, second.InMilliseconds());
Duration sum = first + second;
EXPECT_EQ(kFirstMilliseconds + kSecondMilliseconds, sum.InMilliseconds());
}
TEST(TrackedTimeTest, TrackedTimerVsTimeTicks) {
base::TimeTicks ticks_before = base::TimeTicks::Now();
EXPECT_FALSE(ticks_before.is_null());
TrackedTime now = TrackedTime::Now();
base::TimeTicks ticks_after = base::TimeTicks::Now();
EXPECT_FALSE(ticks_after.is_null());
Duration before = now - TrackedTime(ticks_before);
EXPECT_LE(0, before.InMilliseconds());
Duration after = now - TrackedTime(ticks_after);
EXPECT_GE(0, after.InMilliseconds());
}
TEST(TrackedTimeTest, TrackedTimerDisabled) {
if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED))
return;
TrackedTime track_now = ThreadData::Now();
EXPECT_TRUE(track_now.is_null());
track_now = ThreadData::NowForStartOfRun(NULL);
EXPECT_TRUE(track_now.is_null());
track_now = ThreadData::NowForEndOfRun();
EXPECT_TRUE(track_now.is_null());
}
TEST(TrackedTimeTest, TrackedTimerEnabled) {
if (!ThreadData::InitializeAndSetTrackingStatus(
ThreadData::PROFILING_CHILDREN_ACTIVE))
return;
base::TimeTicks ticks_before = base::TimeTicks::Now();
EXPECT_FALSE(ticks_before.is_null());
TrackedTime now = ThreadData::Now();
base::TimeTicks ticks_after = base::TimeTicks::Now();
EXPECT_FALSE(ticks_after.is_null());
Duration before = now - TrackedTime(ticks_before);
EXPECT_LE(0, before.InMilliseconds());
Duration after = now - TrackedTime(ticks_after);
EXPECT_GE(0, after.InMilliseconds());
}
}