Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / test / core / end2end / cq_verifier.h
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #ifndef GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
20 #define GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
21
22 #include <stdbool.h>
23
24 #include <grpc/grpc.h>
25
26 #include "test/core/util/test_config.h"
27
28 /* A cq_verifier can verify that expected events arrive in a timely fashion
29    on a single completion queue */
30
31 typedef struct cq_verifier cq_verifier;
32
33 /* construct/destroy a cq_verifier */
34 cq_verifier* cq_verifier_create(grpc_completion_queue* cq);
35 void cq_verifier_destroy(cq_verifier* v);
36
37 /* ensure all expected events (and only those events) are present on the
38    bound completion queue within \a timeout_sec */
39 void cq_verify(cq_verifier* v, int timeout_sec = 10);
40
41 /* ensure that the completion queue is empty */
42 void cq_verify_empty(cq_verifier* v);
43
44 /* ensure that the completion queue is empty, waiting up to \a timeout secs. */
45 void cq_verify_empty_timeout(cq_verifier* v, int timeout_sec);
46
47 /* Various expectation matchers
48    Any functions taking ... expect a NULL terminated list of key/value pairs
49    (each pair using two parameter slots) of metadata that MUST be present in
50    the event. */
51 void cq_expect_completion(cq_verifier* v, const char* file, int line, void* tag,
52                           bool success);
53 /* If the \a tag is seen, \a seen is set to true. */
54 void cq_maybe_expect_completion(cq_verifier* v, const char* file, int line,
55                                 void* tag, bool success, bool* seen);
56 void cq_expect_completion_any_status(cq_verifier* v, const char* file, int line,
57                                      void* tag);
58 #define CQ_EXPECT_COMPLETION(v, tag, success) \
59   cq_expect_completion(v, __FILE__, __LINE__, tag, success)
60 #define CQ_MAYBE_EXPECT_COMPLETION(v, tag, success, seen) \
61   cq_maybe_expect_completion(v, __FILE__, __LINE__, tag, success, seen)
62 #define CQ_EXPECT_COMPLETION_ANY_STATUS(v, tag) \
63   cq_expect_completion_any_status(v, __FILE__, __LINE__, tag)
64
65 int byte_buffer_eq_slice(grpc_byte_buffer* bb, grpc_slice b);
66 int byte_buffer_eq_string(grpc_byte_buffer* bb, const char* str);
67 int contains_metadata(grpc_metadata_array* array, const char* key,
68                       const char* value);
69 int contains_metadata_slices(grpc_metadata_array* array, grpc_slice key,
70                              grpc_slice value);
71
72 #endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_H */