1/*
2 * Copyright (c) 2023-2023 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 <string>
17#include "gtest/gtest.h"
18#include "plugin/plugins/source/http_source/download/downloader.h"
19
20namespace OHOS {
21namespace Media {
22namespace Test {
23using namespace OHOS::Media::Plugin::HttpPlugin;
24using namespace testing::ext;
25
26HWTEST(HttpSourcePluginTest, test_download_request_save_header, TestSize.Level1)
27{
28    std::shared_ptr<HeaderInfo> headerInfo = std::make_shared<HeaderInfo>();
29
30    const size_t fileContentLen = 20;
31    headerInfo->fileContentLen = fileContentLen;
32
33    const char contentType[] = "audio";
34    strcpy_s(headerInfo->contentType, sizeof(headerInfo->contentType), contentType);
35
36    headerInfo->isChunked = true;
37    headerInfo->isClosed = true;
38
39    DataSaveFunc dataSaveFunc = [](uint8_t*, uint32_t) {
40        return false;
41    };
42
43    StatusCallbackFunc statusCallbackFunc = [](DownloadStatus, std::shared_ptr<Downloader>&,
44        std::shared_ptr<DownloadRequest>&) {};
45
46    const std::string url = "http://test";
47    DownloadRequest downloadRequest{url, dataSaveFunc, statusCallbackFunc};
48    downloadRequest.SaveHeader(headerInfo.get());
49
50    EXPECT_EQ(fileContentLen, downloadRequest.GetFileContentLength());
51
52    EXPECT_EQ(url, downloadRequest.GetUrl());
53
54    EXPECT_EQ(true, downloadRequest.IsChunked());
55
56    EXPECT_EQ(false, downloadRequest.IsClosed());
57
58    downloadRequest.Close();
59
60    EXPECT_EQ(true, downloadRequest.IsClosed());
61}
62} // namespace Test
63} // namespace Media
64} // namespace OHOS
65