cq_verifier.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
  19. #define GRPC_TEST_CORE_END2END_CQ_VERIFIER_H
  20. #include <stdbool.h>
  21. #include <grpc/grpc.h>
  22. #include "test/core/util/test_config.h"
  23. /* A cq_verifier can verify that expected events arrive in a timely fashion
  24. on a single completion queue */
  25. typedef struct cq_verifier cq_verifier;
  26. /* construct/destroy a cq_verifier */
  27. cq_verifier* cq_verifier_create(grpc_completion_queue* cq);
  28. void cq_verifier_destroy(cq_verifier* v);
  29. /* ensure all expected events (and only those events) are present on the
  30. bound completion queue within \a timeout_sec */
  31. void cq_verify(cq_verifier* v, int timeout_sec = 10);
  32. /* ensure that the completion queue is empty */
  33. void cq_verify_empty(cq_verifier* v);
  34. /* ensure that the completion queue is empty, waiting up to \a timeout secs. */
  35. void cq_verify_empty_timeout(cq_verifier* v, int timeout_sec);
  36. /* Various expectation matchers
  37. Any functions taking ... expect a NULL terminated list of key/value pairs
  38. (each pair using two parameter slots) of metadata that MUST be present in
  39. the event. */
  40. void cq_expect_completion(cq_verifier* v, const char* file, int line, void* tag,
  41. bool success);
  42. /* If the \a tag is seen, \a seen is set to true. */
  43. void cq_maybe_expect_completion(cq_verifier* v, const char* file, int line,
  44. void* tag, bool success, bool* seen);
  45. void cq_expect_completion_any_status(cq_verifier* v, const char* file, int line,
  46. void* tag);
  47. #define CQ_EXPECT_COMPLETION(v, tag, success) \
  48. cq_expect_completion(v, __FILE__, __LINE__, tag, success)
  49. #define CQ_MAYBE_EXPECT_COMPLETION(v, tag, success, seen) \
  50. cq_maybe_expect_completion(v, __FILE__, __LINE__, tag, success, seen)
  51. #define CQ_EXPECT_COMPLETION_ANY_STATUS(v, tag) \
  52. cq_expect_completion_any_status(v, __FILE__, __LINE__, tag)
  53. int byte_buffer_eq_slice(grpc_byte_buffer* bb, grpc_slice b);
  54. int byte_buffer_eq_string(grpc_byte_buffer* bb, const char* str);
  55. int contains_metadata(grpc_metadata_array* array, const char* key,
  56. const char* value);
  57. int contains_metadata_slices(grpc_metadata_array* array, grpc_slice key,
  58. grpc_slice value);
  59. #endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_H */