• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "curl/curl.h"
17 #include "net_conn_client.h"
18 #include "net_connection.h"
19 #include "pac_server.h"
20 #include "proxy_server.h"
21 #include "security_config.h"
22 #include "gtest/gtest.h"
23 #include <iostream>
24 
25 using namespace OHOS::NetManagerStandard;
26 std::map<int32_t, std::shared_ptr<ProxyServer>> services;
27 #define PAC_PROXY_SERVER 9000
28 #define GLOBAL_PROXY_SERVER 9001
29 #define PROT_8080 8080
30 #define PROT_8889 8889
31 #define TIME 10
32 
StartProxyServer(int32_t port)33 static void StartProxyServer(int32_t port)
34 {
35     std::shared_ptr<ProxyServer> server = std::make_shared<ProxyServer>(port);
36     services.insert({port, server});
37     server->Start();
38 }
39 
TEST(PROXY_SWITCH_TEST,PacFileUrlClient)40 TEST(PROXY_SWITCH_TEST, PacFileUrlClient)
41 {
42     StartProxyServer(GLOBAL_PROXY_SERVER);
43     StartProxyServer(PAC_PROXY_SERVER);
44     SetUpPermission();
45     StartHttpServer(PROT_8080, "", "");
46     std::string script = ProxyServer::pacScripts[LOCAL_PROXY_9000];
47     printf(" pac script  %s \n", script.c_str());
48     StartHttpServer(PROT_8889, "", script);
49     EXPECT_EQ(services.empty(), false);
50     sleep(TIME);
51     UnsetUpPermission();
52 }