• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
17 
18 #include "openvpn_config.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 constexpr const char *TEST_VPNID = "vpnId_";
24 constexpr const char *TEST_VPN_NAME = "vpnName_";
25 constexpr int32_t TEST_VPN_TYPE = 9;
26 constexpr const char *TEST_USER_NAME = "userName_";
27 constexpr const char *TEST_PASSWORD = "password_";
28 constexpr bool TEST_SAVE_LOGIN = false;
29 constexpr int32_t TEST_USERID = 0;
30 constexpr const char *TEST_FORWARD = "forwardingRoutes_";
31 
32 constexpr const char *TEST_OPENVPN_PORT = "ovpnPort_";
33 constexpr int32_t TEST_OPENVPN_PROTOVOL = 23;
34 constexpr const char *TEST_OPENVPN_CONFIG = "ovpnConfig_";
35 constexpr int32_t TEST_OPENVPN_AUTH_TYPE = 1;
36 constexpr const char *TEST_ASKPASS = "askpass_";
37 constexpr const char *TEST_OPENVPN_CONFIG_FILE_PATH = "ovpnConfigFilePath_";
38 constexpr const char *TEST_OPENVPN_CA_CERT_FILE_PATH = "ovpnCaCertFilePath_";
39 constexpr const char *TEST_OPENVPN_USER_CERT_FILE_PATH = "ovpnUserCertFilePath_";
40 constexpr const char *TEST_OPENVPN_PRIVATE_KEY_FILE_PATH = "ovpnPrivateKeyFilePath_";
41 
GetOpenvpnConfigData()42 OpenvpnConfig GetOpenvpnConfigData()
43 {
44     OpenvpnConfig infoSequence;
45     infoSequence.ovpnPort_ = TEST_OPENVPN_PORT;
46     infoSequence.ovpnProtocol_ = TEST_OPENVPN_PROTOVOL;
47     infoSequence.ovpnConfig_ = TEST_OPENVPN_CONFIG;
48     infoSequence.ovpnAuthType_ = TEST_OPENVPN_AUTH_TYPE;
49     infoSequence.askpass_ = TEST_ASKPASS;
50     infoSequence.ovpnConfigFilePath_ = TEST_OPENVPN_CONFIG_FILE_PATH;
51     infoSequence.ovpnCaCertFilePath_ = TEST_OPENVPN_CA_CERT_FILE_PATH;
52     infoSequence.ovpnUserCertFilePath_ = TEST_OPENVPN_USER_CERT_FILE_PATH;
53     infoSequence.ovpnPrivateKeyFilePath_ = TEST_OPENVPN_PRIVATE_KEY_FILE_PATH;
54 
55     infoSequence.vpnId_ = TEST_VPNID;
56     infoSequence.vpnName_ = TEST_VPN_NAME;
57     infoSequence.vpnType_ = TEST_VPN_TYPE;
58     infoSequence.userName_ = TEST_USER_NAME;
59     infoSequence.password_ = TEST_PASSWORD;
60     infoSequence.saveLogin_ = TEST_SAVE_LOGIN;
61     infoSequence.userId_ = TEST_USERID;
62     infoSequence.forwardingRoutes_ = TEST_FORWARD;
63     return infoSequence;
64 }
65 }
66 
67 using namespace testing::ext;
68 class OpenvpnConfigTest : public testing::Test {
69 public:
70     static void SetUpTestCase();
71     static void TearDownTestCase();
72     void SetUp();
73     void TearDown();
74 };
75 
SetUpTestCase()76 void OpenvpnConfigTest::SetUpTestCase() {}
77 
TearDownTestCase()78 void OpenvpnConfigTest::TearDownTestCase() {}
79 
SetUp()80 void OpenvpnConfigTest::SetUp() {}
81 
TearDown()82 void OpenvpnConfigTest::TearDown() {}
83 
84 HWTEST_F(OpenvpnConfigTest, MarshallingUnmarshallingTest001, TestSize.Level1)
85 {
86     Parcel parcel;
87     OpenvpnConfig info = GetOpenvpnConfigData();
88     EXPECT_TRUE(info.Marshalling(parcel));
89     int32_t type;
90     parcel.ReadInt32(type);
91     sptr<OpenvpnConfig> result = OpenvpnConfig::Unmarshalling(parcel);
92     ASSERT_TRUE(result != nullptr);
93     EXPECT_EQ(result->ovpnPort_, info.ovpnPort_);
94     EXPECT_EQ(result->ovpnProtocol_, info.ovpnProtocol_);
95     EXPECT_EQ(result->ovpnConfig_, info.ovpnConfig_);
96     EXPECT_EQ(result->ovpnAuthType_, info.ovpnAuthType_);
97     EXPECT_EQ(result->askpass_, info.askpass_);
98     EXPECT_EQ(result->ovpnConfigFilePath_, info.ovpnConfigFilePath_);
99     EXPECT_EQ(result->ovpnCaCertFilePath_, info.ovpnCaCertFilePath_);
100     EXPECT_EQ(result->ovpnUserCertFilePath_, info.ovpnUserCertFilePath_);
101     EXPECT_EQ(result->ovpnPrivateKeyFilePath_, info.ovpnPrivateKeyFilePath_);
102 }
103 } //namespace NetManagerStandard
104 } //namespace OHOS