aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-12-11 11:13:54 -0800
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-12-11 11:13:54 -0800
commitd55171c6cbd5d03ffe5f48e4be21733f5e621aeb (patch)
treea4bf47ae853961e14f082abcc011f59378dc31ec /test
parent12fa8c83aff22c84ee92ea00c79b2f6236c93d26 (diff)
Add tests for set/get port
Diffstat (limited to 'test')
-rw-r--r--test/core/iomgr/sockaddr_utils_test.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c
index 5009a641ea..2596095bc9 100644
--- a/test/core/iomgr/sockaddr_utils_test.c
+++ b/test/core/iomgr/sockaddr_utils_test.c
@@ -236,6 +236,29 @@ static void test_sockaddr_to_string(void) {
GPR_ASSERT(errno == 0x7EADBEEF);
}
+static void test_sockaddr_set_get_port(void) {
+ struct sockaddr_in input4;
+ struct sockaddr_in6 input6;
+ struct sockaddr dummy;
+
+ gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port");
+
+ input4 = make_addr4(kIPv4, sizeof(kIPv4));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input4) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr*)&input4, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input4) == 54321);
+
+ input6 = make_addr6(kIPv6, sizeof(kIPv6));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input6) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr*)&input6, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input6) == 54321);
+
+ memset(&dummy, 0, sizeof(dummy));
+ dummy.sa_family = 123;
+ GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0);
+ GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0);
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
@@ -243,6 +266,7 @@ int main(int argc, char **argv) {
test_sockaddr_to_v4mapped();
test_sockaddr_is_wildcard();
test_sockaddr_to_string();
+ test_sockaddr_set_get_port();
return 0;
}