Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, Google Inc.
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions are
8 : * met:
9 : *
10 : * * Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * * Redistributions in binary form must reproduce the above
13 : * copyright notice, this list of conditions and the following disclaimer
14 : * in the documentation and/or other materials provided with the
15 : * distribution.
16 : * * Neither the name of Google Inc. nor the names of its
17 : * contributors may be used to endorse or promote products derived from
18 : * this software without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 : *
32 : */
33 :
34 : #include <grpc/grpc.h>
35 :
36 : #include "test/core/end2end/cq_verifier.h"
37 : #include "test/core/util/test_config.h"
38 : #include <grpc/support/alloc.h>
39 : #include <grpc/support/log.h>
40 :
41 2 : static void *tag(gpr_intptr x) { return (void *)x; }
42 :
43 1 : int main(int argc, char **argv) {
44 : grpc_channel *chan;
45 : grpc_call *call;
46 : grpc_completion_queue *cq;
47 : cq_verifier *cqv;
48 : grpc_op ops[6];
49 : grpc_op *op;
50 : grpc_metadata_array trailing_metadata_recv;
51 : grpc_status_code status;
52 : grpc_call_error error;
53 1 : char *details = NULL;
54 1 : size_t details_capacity = 0;
55 :
56 1 : grpc_test_init(argc, argv);
57 1 : grpc_init();
58 :
59 1 : grpc_metadata_array_init(&trailing_metadata_recv);
60 :
61 1 : chan = grpc_lame_client_channel_create(
62 : "lampoon:national", GRPC_STATUS_UNKNOWN, "Rpc sent on a lame channel.");
63 1 : GPR_ASSERT(chan);
64 1 : cq = grpc_completion_queue_create(NULL);
65 1 : call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
66 : "/Foo", "anywhere",
67 1 : GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100), NULL);
68 1 : GPR_ASSERT(call);
69 1 : cqv = cq_verifier_create(cq);
70 :
71 1 : op = ops;
72 1 : op->op = GRPC_OP_SEND_INITIAL_METADATA;
73 1 : op->data.send_initial_metadata.count = 0;
74 1 : op->flags = 0;
75 1 : op->reserved = NULL;
76 1 : op++;
77 1 : op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
78 1 : op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
79 1 : op->data.recv_status_on_client.status = &status;
80 1 : op->data.recv_status_on_client.status_details = &details;
81 1 : op->data.recv_status_on_client.status_details_capacity = &details_capacity;
82 1 : op->flags = 0;
83 1 : op->reserved = NULL;
84 1 : op++;
85 1 : error = grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), NULL);
86 1 : GPR_ASSERT(GRPC_CALL_OK == error);
87 :
88 : /* the call should immediately fail */
89 1 : cq_expect_completion(cqv, tag(1), 1);
90 1 : cq_verify(cqv);
91 :
92 1 : grpc_call_destroy(call);
93 1 : grpc_channel_destroy(chan);
94 1 : cq_verifier_destroy(cqv);
95 1 : grpc_completion_queue_destroy(cq);
96 :
97 1 : grpc_metadata_array_destroy(&trailing_metadata_recv);
98 1 : gpr_free(details);
99 :
100 1 : grpc_shutdown();
101 :
102 1 : return 0;
103 : }
|