blob: 79d2af8c90890cd4a74574affa127a92bb5c3869 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h"
6
7#include "testing/gtest/include/gtest/gtest-spi.h"
8#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
9
10namespace quic {
11namespace test {
12
13class QuicTestUtilsTest : public QuicTest {};
14
15TEST_F(QuicTestUtilsTest, ConnectionId) {
16 EXPECT_NE(EmptyQuicConnectionId(), TestConnectionId());
17 EXPECT_NE(EmptyQuicConnectionId(), TestConnectionId(1));
18 EXPECT_EQ(TestConnectionId(), TestConnectionId());
19 EXPECT_EQ(TestConnectionId(33), TestConnectionId(33));
20 EXPECT_NE(TestConnectionId(0xdead), TestConnectionId(0xbeef));
21 EXPECT_EQ(0x1337u, TestConnectionIdToUInt64(TestConnectionId(0x1337)));
22 EXPECT_NE(0xdeadu, TestConnectionIdToUInt64(TestConnectionId(0xbeef)));
23}
24
25TEST_F(QuicTestUtilsTest, BasicApproxEq) {
26 ExpectApproxEq(10, 10, 1e-6f);
27 ExpectApproxEq(1000, 1001, 0.01f);
28 EXPECT_NONFATAL_FAILURE(ExpectApproxEq(1000, 1100, 0.01f), "");
29
30 ExpectApproxEq(64, 31, 0.55f);
31 EXPECT_NONFATAL_FAILURE(ExpectApproxEq(31, 64, 0.55f), "");
32}
33
34TEST_F(QuicTestUtilsTest, QuicTimeDelta) {
35 ExpectApproxEq(QuicTime::Delta::FromMicroseconds(1000),
36 QuicTime::Delta::FromMicroseconds(1003), 0.01f);
37 EXPECT_NONFATAL_FAILURE(
38 ExpectApproxEq(QuicTime::Delta::FromMicroseconds(1000),
39 QuicTime::Delta::FromMicroseconds(1200), 0.01f),
40 "");
41}
42
43TEST_F(QuicTestUtilsTest, QuicBandwidth) {
44 ExpectApproxEq(QuicBandwidth::FromBytesPerSecond(1000),
45 QuicBandwidth::FromBitsPerSecond(8005), 0.01f);
46 EXPECT_NONFATAL_FAILURE(
47 ExpectApproxEq(QuicBandwidth::FromBytesPerSecond(1000),
48 QuicBandwidth::FromBitsPerSecond(9005), 0.01f),
49 "");
50}
51
52// Ensure that SimpleRandom does not change its output for a fixed seed.
53TEST_F(QuicTestUtilsTest, SimpleRandomStability) {
54 SimpleRandom rng;
55 rng.set_seed(UINT64_C(0x1234567800010001));
56 EXPECT_EQ(UINT64_C(14865409841904857791), rng.RandUint64());
57 EXPECT_EQ(UINT64_C(12139094019410129741), rng.RandUint64());
58}
59
60} // namespace test
61} // namespace quic