• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_TEST_TOOLS_MOCK_RANDOM_H_
6 #define QUICHE_QUIC_TEST_TOOLS_MOCK_RANDOM_H_
7 
8 #include "quiche/quic/core/crypto/quic_random.h"
9 #include "quiche/quic/platform/api/quic_test.h"
10 
11 namespace quic {
12 namespace test {
13 
14 class MockRandom : public QuicRandom {
15  public:
16   // Initializes base_ to 0xDEADBEEF.
17   MockRandom();
18   explicit MockRandom(uint32_t base);
19   MockRandom(const MockRandom&) = delete;
20   MockRandom& operator=(const MockRandom&) = delete;
21 
22   MOCK_METHOD(void, RandBytes, (void* data, size_t len), (override));
23   MOCK_METHOD(uint64_t, RandUint64, (), (override));
24   MOCK_METHOD(void, InsecureRandBytes, (void* data, size_t len), (override));
25   MOCK_METHOD(uint64_t, InsecureRandUint64, (), (override));
26 
27   // Default QuicRandom implementations. They are used if the caller does not
28   // setup the MockRandom via EXPECT_CALLs.
29 
30   // Fills the |data| buffer with a repeating byte, initially 'r'.
31   void DefaultRandBytes(void* data, size_t len);
32   // Returns base + the current increment.
33   uint64_t DefaultRandUint64();
34 
35   // InsecureRandBytes behaves equivalently to RandBytes.
36   void DefaultInsecureRandBytes(void* data, size_t len);
37   // InsecureRandUint64 behaves equivalently to RandUint64.
38   uint64_t DefaultInsecureRandUint64();
39 
40   // ChangeValue increments |increment_|. This causes the value returned by
41   // |RandUint64| and the byte that |RandBytes| fills with, to change.
42   // Used by the Default implementations.
43   void ChangeValue();
44 
45   // Sets the base to |base| and resets increment to zero.
46   // Used by the Default implementations.
47   void ResetBase(uint32_t base);
48 
49  private:
50   uint32_t base_;
51   uint8_t increment_;
52 };
53 
54 }  // namespace test
55 }  // namespace quic
56 
57 #endif  // QUICHE_QUIC_TEST_TOOLS_MOCK_RANDOM_H_
58