This source file includes following definitions.
- RunTest
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
- TEST
 
#include "content/common/inter_process_time_ticks_converter.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeTicks;
namespace content {
namespace {
struct TestParams {
  int64 local_lower_bound;
  int64 remote_lower_bound;
  int64 remote_upper_bound;
  int64 local_upper_bound;
  int64 test_time;
  int64 test_delta;
};
struct TestResults {
  int64 result_time;
  int32 result_delta;
};
TestResults RunTest(const TestParams& params) {
  TimeTicks local_lower_bound = TimeTicks::FromInternalValue(
      params.local_lower_bound);
  TimeTicks local_upper_bound = TimeTicks::FromInternalValue(
      params.local_upper_bound);
  TimeTicks remote_lower_bound = TimeTicks::FromInternalValue(
      params.remote_lower_bound);
  TimeTicks remote_upper_bound = TimeTicks::FromInternalValue(
      params.remote_upper_bound);
  TimeTicks test_time = TimeTicks::FromInternalValue(params.test_time);
  InterProcessTimeTicksConverter converter(
      LocalTimeTicks::FromTimeTicks(local_lower_bound),
      LocalTimeTicks::FromTimeTicks(local_upper_bound),
      RemoteTimeTicks::FromTimeTicks(remote_lower_bound),
      RemoteTimeTicks::FromTimeTicks(remote_upper_bound));
  TestResults results;
  results.result_time = converter.ToLocalTimeTicks(
      RemoteTimeTicks::FromTimeTicks(
          test_time)).ToTimeTicks().ToInternalValue();
  results.result_delta = converter.ToLocalTimeDelta(
      RemoteTimeDelta::FromRawDelta(params.test_delta)).ToInt32();
  return results;
}
TEST(InterProcessTimeTicksConverterTest, NullTime) {
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 2;
  p.remote_upper_bound = 5;
  p.local_upper_bound = 6;
  p.test_time = 0;
  p.test_delta = 0;
  TestResults results = RunTest(p);
  EXPECT_EQ(0, results.result_time);
  EXPECT_EQ(0, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, NoSkew) {
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 2;
  p.remote_upper_bound = 5;
  p.local_upper_bound = 6;
  p.test_time = 3;
  p.test_delta = 1;
  TestResults results = RunTest(p);
  EXPECT_EQ(3, results.result_time);
  EXPECT_EQ(1, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, OffsetMidpoints) {
  
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 3;
  p.remote_upper_bound = 6;
  p.local_upper_bound = 6;
  p.test_time = 4;
  p.test_delta = 1;
  TestResults results = RunTest(p);
  EXPECT_EQ(3, results.result_time);
  EXPECT_EQ(1, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, DoubleEndedSkew) {
  
  
  
  
  
  TestParams p;
  p.local_lower_bound = 3;
  p.remote_lower_bound = 1;
  p.remote_upper_bound = 9;
  p.local_upper_bound = 7;
  p.test_time = 5;
  p.test_delta = 2;
  TestResults results = RunTest(p);
  EXPECT_EQ(5, results.result_time);
  EXPECT_EQ(1, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, FrontEndSkew) {
  
  
  
  
  TestParams p;
  p.local_lower_bound = 3;
  p.remote_lower_bound = 1;
  p.remote_upper_bound = 7;
  p.local_upper_bound = 7;
  p.test_time = 3;
  p.test_delta = 2;
  TestResults results = RunTest(p);
  EXPECT_EQ(4, results.result_time);
  EXPECT_EQ(1, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, BackEndSkew) {
  
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 1;
  p.remote_upper_bound = 7;
  p.local_upper_bound = 5;
  p.test_time = 3;
  p.test_delta = 2;
  TestResults results = RunTest(p);
  EXPECT_EQ(2, results.result_time);
  EXPECT_EQ(1, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, Instantaneous) {
  
  
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 2;
  p.remote_upper_bound = 2;
  p.local_upper_bound = 3;
  p.test_time = 2;
  p.test_delta = 0;
  TestResults results = RunTest(p);
  EXPECT_EQ(2, results.result_time);
  EXPECT_EQ(0, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, OffsetInstantaneous) {
  
  
  
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 3;
  p.remote_upper_bound = 3;
  p.local_upper_bound = 3;
  p.test_time = 3;
  p.test_delta = 0;
  TestResults results = RunTest(p);
  EXPECT_EQ(2, results.result_time);
  EXPECT_EQ(0, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, DisjointInstantaneous) {
  
  
  
  
  TestParams p;
  p.local_lower_bound = 1;
  p.remote_lower_bound = 2;
  p.remote_upper_bound = 2;
  p.local_upper_bound = 1;
  p.test_time = 2;
  p.test_delta = 0;
  TestResults results = RunTest(p);
  EXPECT_EQ(1, results.result_time);
  EXPECT_EQ(0, results.result_delta);
}
TEST(InterProcessTimeTicksConverterTest, RoundingNearEdges) {
  
  
  const int kMaxRange = 101;
  for (int i = 1; i < kMaxRange; ++i) {
    for (int j = 1; j < kMaxRange; ++j) {
      TestParams p;
      p.local_lower_bound = 1;
      p.remote_lower_bound = 1;
      p.remote_upper_bound = j;
      p.local_upper_bound = i;
      p.test_time = 1;
      p.test_delta = 0;
      TestResults results = RunTest(p);
      EXPECT_LE(1, results.result_time);
      EXPECT_EQ(0, results.result_delta);
      p.test_time = j;
      p.test_delta = j - 1;
      results = RunTest(p);
      EXPECT_GE(i, results.result_time);
      EXPECT_GE(i - 1, results.result_delta);
    }
  }
}
TEST(InterProcessTimeTicksConverterTest, DisjointRanges) {
  TestParams p;
  p.local_lower_bound = 10;
  p.remote_lower_bound = 30;
  p.remote_upper_bound = 41;
  p.local_upper_bound = 20;
  p.test_time = 41;
  p.test_delta = 0;
  TestResults results = RunTest(p);
  EXPECT_EQ(20, results.result_time);
  EXPECT_EQ(0, results.result_delta);
}
}  
}