diff options
author | Muxi Yan <mxyan@google.com> | 2018-01-19 17:32:27 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-01-19 17:32:27 -0800 |
commit | 61bb29f1411db01732f9a9cd6e153882992726ee (patch) | |
tree | 76efdcddc5948114d35e5ef49de5ac2ed0136efc /test/cpp/cocoapods/test | |
parent | 277e2e4f07744bd0f803efc80440f2e315f6d34a (diff) |
Clean up C++ tests and example
Diffstat (limited to 'test/cpp/cocoapods/test')
-rw-r--r-- | test/cpp/cocoapods/test/Info.plist | 22 | ||||
-rw-r--r-- | test/cpp/cocoapods/test/server_context_test_spouse_test.mm | 100 |
2 files changed, 122 insertions, 0 deletions
diff --git a/test/cpp/cocoapods/test/Info.plist b/test/cpp/cocoapods/test/Info.plist new file mode 100644 index 0000000000..6c40a6cd0c --- /dev/null +++ b/test/cpp/cocoapods/test/Info.plist @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>$(DEVELOPMENT_LANGUAGE)</string> + <key>CFBundleExecutable</key> + <string>$(EXECUTABLE_NAME)</string> + <key>CFBundleIdentifier</key> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>$(PRODUCT_NAME)</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> +</dict> +</plist> diff --git a/test/cpp/cocoapods/test/server_context_test_spouse_test.mm b/test/cpp/cocoapods/test/server_context_test_spouse_test.mm new file mode 100644 index 0000000000..fd6878efbf --- /dev/null +++ b/test/cpp/cocoapods/test/server_context_test_spouse_test.mm @@ -0,0 +1,100 @@ +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Hack TEST macro of gTest and make they conform XCTest style. We only +// need test name (b), not test case name (a). +#define TEST(a,b) - (void)test ## b +#define ASSERT_TRUE XCTAssert +#define ASSERT_EQ XCTAssertEqual + +#import <XCTest/XCTest.h> + +#include <grpc++/test/server_context_test_spouse.h> + +#include <cstring> +#include <vector> + +#include <grpc++/impl/grpc_library.h> + +static grpc::internal::GrpcLibraryInitializer g_initializer; + +const char key1[] = "metadata-key1"; +const char key2[] = "metadata-key2"; +const char val1[] = "metadata-val1"; +const char val2[] = "metadata-val2"; + +bool ClientMetadataContains(const grpc::ServerContext& context, + const grpc::string_ref& key, + const grpc::string_ref& value) { + const auto& client_metadata = context.client_metadata(); + for (auto iter = client_metadata.begin(); iter != client_metadata.end(); + ++iter) { + if (iter->first == key && iter->second == value) { + return true; + } + } + return false; +} + +@interface ServerContextTestSpouseTest : XCTestCase + +@end + +@implementation ServerContextTestSpouseTest + +TEST(ServerContextTestSpouseTest, ClientMetadata) { + grpc::ServerContext context; + grpc::testing::ServerContextTestSpouse spouse(&context); + + spouse.AddClientMetadata(key1, val1); + ASSERT_TRUE(ClientMetadataContains(context, key1, val1)); + + spouse.AddClientMetadata(key2, val2); + ASSERT_TRUE(ClientMetadataContains(context, key1, val1)); + ASSERT_TRUE(ClientMetadataContains(context, key2, val2)); +} + +TEST(ServerContextTestSpouseTest, InitialMetadata) { + grpc::ServerContext context; + grpc::testing::ServerContextTestSpouse spouse(&context); + std::multimap<grpc::string, grpc::string> metadata; + + context.AddInitialMetadata(key1, val1); + metadata.insert(std::pair<grpc::string, grpc::string>(key1, val1)); + ASSERT_EQ(metadata, spouse.GetInitialMetadata()); + + context.AddInitialMetadata(key2, val2); + metadata.insert(std::pair<grpc::string, grpc::string>(key2, val2)); + ASSERT_EQ(metadata, spouse.GetInitialMetadata()); +} + +TEST(ServerContextTestSpouseTest, TrailingMetadata) { + grpc::ServerContext context; + grpc::testing::ServerContextTestSpouse spouse(&context); + std::multimap<grpc::string, grpc::string> metadata; + + context.AddTrailingMetadata(key1, val1); + metadata.insert(std::pair<grpc::string, grpc::string>(key1, val1)); + ASSERT_EQ(metadata, spouse.GetTrailingMetadata()); + + context.AddTrailingMetadata(key2, val2); + metadata.insert(std::pair<grpc::string, grpc::string>(key2, val2)); + ASSERT_EQ(metadata, spouse.GetTrailingMetadata()); +} + +@end |