-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmock.h
71 lines (56 loc) · 2.44 KB
/
mock.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef MOCK_H
#define MOCK_H
#include <deque>
#include <string>
#include "grpc/impl/codegen/log.h"
#include "gtest/gtest.h"
#include "homa.h"
#include "wire.h"
/* This class defines additional variables and functions that can be used
* by unit tests as part of mocking out system features.
*/
class Mock {
public:
// Used by some methods as the errno to return after a simulated failure.
static int errorCode;
// The variables below can be set to non-zero values by unit tests in order
// to simulate error returns from various functions. If bit 0 is set to 1,
// the next call to the function will fail; bit 1 corresponds to the next
// call after that, and so on.
static int homaReplyErrors;
static int homaReplyvErrors;
static int homaSendvErrors;
static int recvmsgErrors;
static int buffersReturned;
// Holds all messages sent by homa_sendv and homa_replyv.
static std::deque<std::vector<uint8_t>> homaMessages;
// Return info for upcoming invocations of homa_recv.
static std::deque<Wire::Header> recvmsgHeaders;
static std::deque<ssize_t> recvmsgLengths;
static std::deque<ssize_t> recvmsgReturns;
// Accumulates various information over the course of a test, which
// can then be queried.
static std::string log;
// Buffer region for the Homa socket.
static uint8_t *bufRegion;
static int checkError(int *errorMask);
static grpc_core::Slice
dataSlice(size_t length, int firstValue);
static void gprLog(gpr_log_func_args* args);
static void logData(const char *separator, const void *data,
int length);
static void logMetadata(const char *separator,
const grpc_metadata_batch *batch);
static void logPrintf(const char *separator, const char* format, ...);
static void logSliceBuffer(const char *separator,
const grpc_core::SliceBuffer *sliceBuffer);
static void metadataBatchAppend(grpc_metadata_batch* batch,
const char *key, const char *value);
static void setUp(void);
static ::testing::AssertionResult
substr(const std::string& s,
const std::string& substring);
};
#define EXPECT_SUBSTR(sub, str) EXPECT_TRUE(Mock::substr((str), (sub)))
#define EXPECT_NSUBSTR(sub, str) EXPECT_FALSE(Mock::substr((str), (sub)))
#endif // MOCK_H