aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/end2end/cq_verifier.h
blob: 0b3b3fb3495ad6cf891b2b82ded847466ec72e12 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 *
 * Copyright 2015 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
#define GRPC_TEST_CORE_END2END_CQ_VERIFIER_H

#include <stdbool.h>

#include <grpc/grpc.h>
#include "test/core/util/test_config.h"

#ifdef __cplusplus
extern "C" {
#endif

/* A cq_verifier can verify that expected events arrive in a timely fashion
   on a single completion queue */

typedef struct cq_verifier cq_verifier;

/* construct/destroy a cq_verifier */
cq_verifier* cq_verifier_create(grpc_completion_queue* cq);
void cq_verifier_destroy(cq_verifier* v);

/* ensure all expected events (and only those events) are present on the
   bound completion queue */
void cq_verify(cq_verifier* v);

/* ensure that the completion queue is empty */
void cq_verify_empty(cq_verifier* v);

/* ensure that the completion queue is empty, waiting up to \a timeout secs. */
void cq_verify_empty_timeout(cq_verifier* v, int timeout_sec);

/* Various expectation matchers
   Any functions taking ... expect a NULL terminated list of key/value pairs
   (each pair using two parameter slots) of metadata that MUST be present in
   the event. */
void cq_expect_completion(cq_verifier* v, const char* file, int line, void* tag,
                          bool success);
#define CQ_EXPECT_COMPLETION(v, tag, success) \
  cq_expect_completion(v, __FILE__, __LINE__, tag, success)

int byte_buffer_eq_slice(grpc_byte_buffer* bb, grpc_slice b);
int byte_buffer_eq_string(grpc_byte_buffer* byte_buffer, const char* string);
int contains_metadata(grpc_metadata_array* array, const char* key,
                      const char* value);
int contains_metadata_slices(grpc_metadata_array* array, grpc_slice key,
                             grpc_slice value);

#ifdef __cplusplus
}
#endif

#endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_H */