gtest: use localhost server if the proxy isn't set 37/245937/1 accepted/tizen/unified/20201027.125420 submit/tizen/20201020.080343
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 20 Oct 2020 07:13:26 +0000 (16:13 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 20 Oct 2020 07:13:26 +0000 (16:13 +0900)
Change-Id: I9caffa40c4d9c013cdb2b5a084f86c7acf38f3bb

packaging/capi-network-http.spec
tests/CMakeLists.txt
tests/http-gtest-async.cpp

index 69d28683e80770884b4e5d0481b464be1705beea..00afd1a5a5eb9ad5fb2688d9e547299274777165 100644 (file)
@@ -51,6 +51,7 @@ export LDFLAGS+=" -lgcov"
 %endif
 
 %cmake -DBUILD_GTESTS=%{?gcov:1}%{!?gcov:0} \
+       -DUSE_LOCALHOST_SERVER=%{?gproxy:0}%{!?gproxy:1} \
        .
 
 make %{?_smp_mflags}
@@ -66,7 +67,11 @@ tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj
 
 %check
 %if 0%{?gcov:1}
+%if 0%{?gproxy:1}
 env all_proxy=%{gproxy} tests/http-gtest # http://[proxy addr]:[port]
+%else
+tests/http-gtest
+%endif
 %endif
 
 %if 0%{?gcov:1}
index d9399501308a6d468391d37c7161a84e385dc055..dcf4a65443106a41fa1720c32e690514ea6a1944 100644 (file)
@@ -1,6 +1,11 @@
 LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
 ADD_DEFINITIONS("-DHTTP_GTEST")
 
+IF(USE_LOCALHOST_SERVER)
+       MESSAGE("Use localhost server.")
+       ADD_DEFINITIONS("-DUSE_LOCALHOST_SERVER")
+ENDIF(USE_LOCALHOST_SERVER)
+
 pkg_check_modules(gtest_pkgs REQUIRED gmock glib-2.0)
 INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
index acb64fc475efe86225c4dce0b6785ae9df633ccc..d3946fe61338b23622087d9e0fbecae472e9c5ca 100755 (executable)
@@ -27,13 +27,21 @@ extern "C" {
 
 #include "http-gtest-util.h"
 
+#if defined USE_LOCALHOST_SERVER
+#define DEFAULT_TEST_URL "http://localhost"
+#else
+#define DEFAULT_TEST_URL "http://www.example.com"
+#endif
+
 static bool _completed_flag;
 static bool _canceled_flag;
 static bool _paused_flag;
 static bool _resumed_flag;
 
 static void _completed_cb(http_transaction_h http_transaction, void *user_data);
-static void _aborted_cb(http_transaction_h http_transaction, http_error_code_e error, void *user_data);
+static void _aborted_cb(http_transaction_h http_transaction,
+               http_error_code_e error, void *user_data);
+
 class HttpAsyncTest: public ::testing::Test {
        protected:
                http_session_h session = NULL;
@@ -55,7 +63,7 @@ class HttpAsyncTest: public ::testing::Test {
                        http_session_open_transaction(session, HTTP_METHOD_GET, &transaction);
                        http_transaction_set_completed_cb(transaction, _completed_cb, NULL);
                        http_transaction_set_aborted_cb(transaction, _aborted_cb, NULL);
-                       http_transaction_request_set_uri(transaction, "http://www.example.com");
+                       http_transaction_request_set_uri(transaction, DEFAULT_TEST_URL);
                }
 
                void TearDown() override