• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include <string>
18 #include <fcntl.h>
19 #include "upload_hilog_wrapper.h"
20 #include "upload_config.h"
21 #include "curl_adp.h"
22 #include "upload_test.h"
23 
24 using namespace testing::ext;
25 namespace OHOS::Request::Upload {
26 class UploadTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29 
30     static void TearDownTestCase(void);
31 
32     void SetUp();
33 
34     void TearDown();
35 };
36 
SetUpTestCase(void)37 void UploadTest::SetUpTestCase(void)
38 {
39 }
40 
TearDownTestCase(void)41 void UploadTest::TearDownTestCase(void)
42 {
43 }
44 
SetUp()45 void UploadTest::SetUp()
46 {
47 }
48 
TearDown()49 void UploadTest::TearDown()
50 {
51 }
52 
53 /**
54  * @tc.name: UploadTest.UploadTestTest_001
55  * @tc.type: FUNC
56  */
57 HWTEST_F(UploadTest, UploadTest_001, TestSize.Level1)
58 {
59     UPLOAD_HILOGD(UPLOAD_MODULE_TEST, "**********UploadUtTest_001**in**********");
60     FILE *fd1;
61     FILE *fd2;
62     FileData fileInfo1;
63     FileData fileInfo2;
64     std::vector<FileData> fileArray;
65     std::shared_ptr<UploadConfig> uploadConfig = std::make_shared<UploadConfig>();
66 
67     fd1 = fopen("upload_UT_test_1.xml", "rb");
68     fd2 = fopen("upload_UT_test_2.xml", "rb");
69     fileInfo1.fp = fd1;
70     fileInfo1.name = "upload_UT_test_1.xml";
71     fileInfo2.fp = fd2;
72     fileInfo2.name = "upload_UT_test_2.xml";
73     if (fd1 && fd2) {
74         // url needs to be configured according to the server URL
75         uploadConfig->url = "http://192.168.1.180/uploadservice/";
76         fileArray.push_back(fileInfo1);
77         fileArray.push_back(fileInfo2);
78         auto curl = std::make_shared<CUrlAdp>(fileArray, uploadConfig);
79         curl->DoUpload(nullptr);
80     } else {
81         UPLOAD_HILOGE(UPLOAD_MODULE_TEST, "open file failed");
82     }
83     UPLOAD_HILOGD(UPLOAD_MODULE_TEST, "**********UploadUtTest_001***out**********");
84     SUCCEED();
85 }
86 } // end of OHOS::Request::Upload