Remove const_iterator typedef and add a range based loop test

pull/2451/head
yang-g 10 years ago
parent 811536efce
commit 14b3684dee
  1. 5
      include/grpc++/auth_context.h
  2. 4
      src/cpp/common/secure_auth_context.cc
  3. 4
      src/cpp/common/secure_auth_context.h
  4. 22
      test/cpp/common/secure_auth_context_test.cc

@ -70,7 +70,6 @@ class AuthContext {
size_t index_;
const char* name_;
};
typedef PropertyIterator const_iterator;
virtual ~AuthContext() {}
@ -84,8 +83,8 @@ class AuthContext {
const grpc::string& name) const = 0;
// Iteration over all the properties.
virtual const_iterator begin() const = 0;
virtual const_iterator end() const = 0;
virtual PropertyIterator begin() const = 0;
virtual PropertyIterator end() const = 0;
};
} // namespace grpc

@ -124,7 +124,7 @@ const AuthContext::Property AuthContext::PropertyIterator::operator*() {
grpc::string(property_->value, property_->value_length));
}
SecureAuthContext::const_iterator SecureAuthContext::begin() const {
AuthContext::PropertyIterator SecureAuthContext::begin() const {
if (ctx_) {
grpc_auth_property_iterator iter =
grpc_auth_context_property_iterator(ctx_);
@ -136,7 +136,7 @@ SecureAuthContext::const_iterator SecureAuthContext::begin() const {
}
}
SecureAuthContext::const_iterator SecureAuthContext::end() const {
AuthContext::PropertyIterator SecureAuthContext::end() const {
return AuthContext::PropertyIterator();
}

@ -53,9 +53,9 @@ class SecureAuthContext GRPC_FINAL : public AuthContext {
std::vector<grpc::string> FindPropertyValues(const grpc::string& name) const
GRPC_OVERRIDE;
const_iterator begin() const GRPC_OVERRIDE;
PropertyIterator begin() const GRPC_OVERRIDE;
const_iterator end() const GRPC_OVERRIDE;
PropertyIterator end() const GRPC_OVERRIDE;
private:
grpc_auth_context* ctx_;

@ -77,7 +77,7 @@ TEST_F(SecureAuthContextTest, Iterators) {
ctx->peer_identity_property_name = ctx->properties[0].name;
SecureAuthContext context(ctx);
AuthContext::const_iterator iter = context.begin();
AuthContext::PropertyIterator iter = context.begin();
EXPECT_TRUE(context.end() != iter);
AuthContext::Property p0 = *iter;
++iter;
@ -92,6 +92,26 @@ TEST_F(SecureAuthContextTest, Iterators) {
EXPECT_EQ("bar", p2.second);
++iter;
EXPECT_EQ(context.end(), iter);
// Range-based for loop test.
int i = 0;
for (const AuthContext::Property p : context) {
switch (i++) {
case 0:
EXPECT_EQ("name", p.first);
EXPECT_EQ("chapi", p.second);
break;
case 1:
EXPECT_EQ("name", p.first);
EXPECT_EQ("chapo", p.second);
break;
case 2:
EXPECT_EQ("foo", p.first);
EXPECT_EQ("bar", p.second);
break;
default:
EXPECT_TRUE(0);
}
}
}
} // namespace

Loading…
Cancel
Save