Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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 | |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 34 | #include <grpc/grpc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 35 | |
| 36 | #include "test/core/end2end/cq_verifier.h" |
| 37 | #include "test/core/util/test_config.h" |
Craig Tiller | 5fe7e5d | 2015-05-01 10:52:35 -0700 | [diff] [blame] | 38 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | #include <grpc/support/log.h> |
| 40 | |
| 41 | static void *tag(gpr_intptr x) { return (void *)x; } |
| 42 | |
| 43 | int main(int argc, char **argv) { |
| 44 | grpc_channel *chan; |
| 45 | grpc_call *call; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 46 | grpc_completion_queue *cq; |
| 47 | cq_verifier *cqv; |
Craig Tiller | 2365c7d | 2015-04-29 13:55:47 -0700 | [diff] [blame] | 48 | 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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 54 | |
| 55 | grpc_test_init(argc, argv); |
| 56 | grpc_init(); |
| 57 | |
Craig Tiller | 2365c7d | 2015-04-29 13:55:47 -0700 | [diff] [blame] | 58 | grpc_metadata_array_init(&trailing_metadata_recv); |
| 59 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 60 | chan = grpc_lame_client_channel_create(); |
| 61 | GPR_ASSERT(chan); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 62 | cq = grpc_completion_queue_create(); |
Craig Tiller | 2365c7d | 2015-04-29 13:55:47 -0700 | [diff] [blame] | 63 | call = grpc_channel_create_call(chan, cq, "/Foo", "anywhere", |
| 64 | GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100)); |
| 65 | GPR_ASSERT(call); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 66 | cqv = cq_verifier_create(cq); |
| 67 | |
Craig Tiller | 2365c7d | 2015-04-29 13:55:47 -0700 | [diff] [blame] | 68 | op = ops; |
| 69 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 70 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 71 | op->flags = 0; |
Craig Tiller | 2365c7d | 2015-04-29 13:55:47 -0700 | [diff] [blame] | 72 | 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 Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 78 | op->flags = 0; |
Craig Tiller | 2365c7d | 2015-04-29 13:55:47 -0700 | [diff] [blame] | 79 | op++; |
| 80 | GPR_ASSERT(GRPC_CALL_OK == |
| 81 | grpc_call_start_batch(call, ops, op - ops, tag(1))); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 82 | |
| 83 | /* the call should immediately fail */ |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 84 | cq_expect_completion(cqv, tag(1), 1); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | 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 Tiller | 5fe7e5d | 2015-05-01 10:52:35 -0700 | [diff] [blame] | 92 | grpc_metadata_array_destroy(&trailing_metadata_recv); |
| 93 | gpr_free(details); |
| 94 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 95 | grpc_shutdown(); |
| 96 | |
| 97 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 98 | } |