summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quiche/quic/test_tools/mock_random.h
blob: 0a4918d0ddc096477f44f26a910f00171e8fa89c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef QUICHE_QUIC_TEST_TOOLS_MOCK_RANDOM_H_
#define QUICHE_QUIC_TEST_TOOLS_MOCK_RANDOM_H_

#include "quiche/quic/core/crypto/quic_random.h"
#include "quiche/quic/platform/api/quic_test.h"

namespace quic {
namespace test {

class MockRandom : public QuicRandom {
 public:
  // Initializes base_ to 0xDEADBEEF.
  MockRandom();
  explicit MockRandom(uint32_t base);
  MockRandom(const MockRandom&) = delete;
  MockRandom& operator=(const MockRandom&) = delete;

  MOCK_METHOD(void, RandBytes, (void* data, size_t len), (override));
  MOCK_METHOD(uint64_t, RandUint64, (), (override));
  MOCK_METHOD(void, InsecureRandBytes, (void* data, size_t len), (override));
  MOCK_METHOD(uint64_t, InsecureRandUint64, (), (override));

  // Default QuicRandom implementations. They are used if the caller does not
  // setup the MockRandom via EXPECT_CALLs.

  // Fills the |data| buffer with a repeating byte, initially 'r'.
  void DefaultRandBytes(void* data, size_t len);
  // Returns base + the current increment.
  uint64_t DefaultRandUint64();

  // InsecureRandBytes behaves equivalently to RandBytes.
  void DefaultInsecureRandBytes(void* data, size_t len);
  // InsecureRandUint64 behaves equivalently to RandUint64.
  uint64_t DefaultInsecureRandUint64();

  // ChangeValue increments |increment_|. This causes the value returned by
  // |RandUint64| and the byte that |RandBytes| fills with, to change.
  // Used by the Default implementations.
  void ChangeValue();

  // Sets the base to |base| and resets increment to zero.
  // Used by the Default implementations.
  void ResetBase(uint32_t base);

 private:
  uint32_t base_;
  uint8_t increment_;
};

}  // namespace test
}  // namespace quic

#endif  // QUICHE_QUIC_TEST_TOOLS_MOCK_RANDOM_H_