OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <math.h> | 5 #include <math.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 | 7 |
8 #include "ppapi/shared_impl/time_conversion.h" | 8 #include "ppapi/shared_impl/time_conversion.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now)); | 43 EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now)); |
44 | 44 |
45 // Units should be in seconds. | 45 // Units should be in seconds. |
46 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1); | 46 base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1); |
47 double event_one_second_from_now = one_second_from_now.ToDoubleT(); | 47 double event_one_second_from_now = one_second_from_now.ToDoubleT(); |
48 EXPECT_GE(kTimeSecondsSlop, | 48 EXPECT_GE(kTimeSecondsSlop, |
49 1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) - | 49 1.0 - ppapi::EventTimeToPPTimeTicks(event_one_second_from_now) - |
50 ppapi::EventTimeToPPTimeTicks(event_now)); | 50 ppapi::EventTimeToPPTimeTicks(event_now)); |
51 } | 51 } |
52 | 52 |
53 TEST(TimeConversion, EpochTime) { | |
54 // Should be able to round-trip. | |
55 base::Time epoch = base::Time::UnixEpoch(); | |
56 base::Time converted = ppapi::PPTimeToTime(TimeToPPTime(epoch)); | |
57 EXPECT_GE(kTimeInternalValueSlop, | |
58 abs(static_cast<int>((converted - epoch).ToInternalValue()))); | |
59 | |
60 // Units should be in seconds. | |
61 base::Time one_second_from_epoch = epoch + base::TimeDelta::FromSeconds(1); | |
62 double converted_one_second_from_epoch = | |
63 ppapi::TimeToPPTime(one_second_from_epoch) - ppapi::TimeToPPTime(epoch); | |
64 EXPECT_GE(kTimeSecondsSlop, fabs(converted_one_second_from_epoch - 1)); | |
Scott Hess - ex-Googler
2012/12/13 18:35:24
I think you should have a straight up test that PP
raymes
2012/12/14 17:28:22
Done.
| |
65 } | |
66 | |
53 } // namespace ppapi | 67 } // namespace ppapi |
OLD | NEW |