blob: b2facd33b1ff68a02158c86372320dc554772d30 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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
Craig Tiller42bc87c2015-02-23 08:50:19 -080034#include <grpc/grpc.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035
36#include "test/core/end2end/cq_verifier.h"
37#include "test/core/util/test_config.h"
Craig Tiller5fe7e5d2015-05-01 10:52:35 -070038#include <grpc/support/alloc.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039#include <grpc/support/log.h>
40
41static void *tag(gpr_intptr x) { return (void *)x; }
42
43int main(int argc, char **argv) {
44 grpc_channel *chan;
45 grpc_call *call;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080046 grpc_completion_queue *cq;
47 cq_verifier *cqv;
Craig Tiller2365c7d2015-04-29 13:55:47 -070048 grpc_op ops[6];
49 grpc_op *op;
50 grpc_metadata_array trailing_metadata_recv;
51 grpc_status_code status;
52 char *details = NULL;
53 size_t details_capacity = 0;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080054
55 grpc_test_init(argc, argv);
56 grpc_init();
57
Craig Tiller2365c7d2015-04-29 13:55:47 -070058 grpc_metadata_array_init(&trailing_metadata_recv);
59
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080060 chan = grpc_lame_client_channel_create();
61 GPR_ASSERT(chan);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080062 cq = grpc_completion_queue_create();
Craig Tiller2365c7d2015-04-29 13:55:47 -070063 call = grpc_channel_create_call(chan, cq, "/Foo", "anywhere",
64 GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100));
65 GPR_ASSERT(call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080066 cqv = cq_verifier_create(cq);
67
Craig Tiller2365c7d2015-04-29 13:55:47 -070068 op = ops;
69 op->op = GRPC_OP_SEND_INITIAL_METADATA;
70 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -070071 op->flags = 0;
Craig Tiller2365c7d2015-04-29 13:55:47 -070072 op++;
73 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
74 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
75 op->data.recv_status_on_client.status = &status;
76 op->data.recv_status_on_client.status_details = &details;
77 op->data.recv_status_on_client.status_details_capacity = &details_capacity;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -070078 op->flags = 0;
Craig Tiller2365c7d2015-04-29 13:55:47 -070079 op++;
80 GPR_ASSERT(GRPC_CALL_OK ==
81 grpc_call_start_batch(call, ops, op - ops, tag(1)));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080082
83 /* the call should immediately fail */
Craig Tiller64be9f72015-05-04 14:53:51 -070084 cq_expect_completion(cqv, tag(1), 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080085 cq_verify(cqv);
86
87 grpc_call_destroy(call);
88 grpc_channel_destroy(chan);
89 cq_verifier_destroy(cqv);
90 grpc_completion_queue_destroy(cq);
91
Craig Tiller5fe7e5d2015-05-01 10:52:35 -070092 grpc_metadata_array_destroy(&trailing_metadata_recv);
93 gpr_free(details);
94
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080095 grpc_shutdown();
96
97 return 0;
Craig Tiller190d3602015-02-18 09:23:38 -080098}