Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: third_party/grpc/test/cpp/common/auth_property_iterator_test.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_security.h>
35 #include <grpc++/security/auth_context.h>
36 #include <gtest/gtest.h>
37 #include "src/cpp/common/secure_auth_context.h"
38 #include "test/cpp/util/string_ref_helper.h"
39
40 extern "C" {
41 #include "src/core/security/security_context.h"
42 }
43
44 using ::grpc::testing::ToString;
45
46 namespace grpc {
47 namespace {
48
49 class TestAuthPropertyIterator : public AuthPropertyIterator {
50 public:
51 TestAuthPropertyIterator() {}
52 TestAuthPropertyIterator(const grpc_auth_property* property,
53 const grpc_auth_property_iterator* iter)
54 : AuthPropertyIterator(property, iter) {}
55 };
56
57 class AuthPropertyIteratorTest : public ::testing::Test {
58 protected:
59 void SetUp() GRPC_OVERRIDE {
60 ctx_ = grpc_auth_context_create(NULL);
61 grpc_auth_context_add_cstring_property(ctx_, "name", "chapi");
62 grpc_auth_context_add_cstring_property(ctx_, "name", "chapo");
63 grpc_auth_context_add_cstring_property(ctx_, "foo", "bar");
64 EXPECT_EQ(1,
65 grpc_auth_context_set_peer_identity_property_name(ctx_, "name"));
66 }
67 void TearDown() GRPC_OVERRIDE { grpc_auth_context_release(ctx_); }
68 grpc_auth_context* ctx_;
69 };
70
71 TEST_F(AuthPropertyIteratorTest, DefaultCtor) {
72 TestAuthPropertyIterator iter1;
73 TestAuthPropertyIterator iter2;
74 EXPECT_EQ(iter1, iter2);
75 }
76
77 TEST_F(AuthPropertyIteratorTest, GeneralTest) {
78 grpc_auth_property_iterator c_iter =
79 grpc_auth_context_property_iterator(ctx_);
80 const grpc_auth_property* property =
81 grpc_auth_property_iterator_next(&c_iter);
82 TestAuthPropertyIterator iter(property, &c_iter);
83 TestAuthPropertyIterator empty_iter;
84 EXPECT_FALSE(iter == empty_iter);
85 AuthProperty p0 = *iter;
86 ++iter;
87 AuthProperty p1 = *iter;
88 iter++;
89 AuthProperty p2 = *iter;
90 EXPECT_EQ("name", ToString(p0.first));
91 EXPECT_EQ("chapi", ToString(p0.second));
92 EXPECT_EQ("name", ToString(p1.first));
93 EXPECT_EQ("chapo", ToString(p1.second));
94 EXPECT_EQ("foo", ToString(p2.first));
95 EXPECT_EQ("bar", ToString(p2.second));
96 ++iter;
97 EXPECT_EQ(empty_iter, iter);
98 }
99
100 } // namespace
101 } // namespace grpc
102
103 int main(int argc, char** argv) {
104 ::testing::InitGoogleTest(&argc, argv);
105 return RUN_ALL_TESTS();
106 }
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/common/alarm_cpp_test.cc ('k') | third_party/grpc/test/cpp/common/channel_arguments_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698