/* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "m3u8_unit_test.h" #define LOCAL true using namespace OHOS; using namespace OHOS::Media; namespace OHOS::Media::Plugins::HttpPlugin { using namespace testing::ext; using namespace std; void M3u8UnitTest::SetUpTestCase(void) {} void M3u8UnitTest::TearDownTestCase(void) {} void M3u8UnitTest::SetUp(void) {} void M3u8UnitTest::TearDown(void) {} HWTEST_F(M3u8UnitTest, Init_Tag_Updaters_Map_001, TestSize.Level1) { double duration = testM3u8->GetDuration(); bool isLive = testM3u8->IsLive(); EXPECT_GE(duration, 0.0); EXPECT_EQ(isLive, false); } HWTEST_F(M3u8UnitTest, is_live_001, TestSize.Level1) { EXPECT_NE(testM3u8->GetDuration(), 0.0); } HWTEST_F(M3u8UnitTest, parse_key_001, TestSize.Level1) { testM3u8->ParseKey(std::make_shared(HlsTag::EXTXKEY, tagAttribute)); testM3u8->DownloadKey(); } HWTEST_F(M3u8UnitTest, base_64_decode_001, TestSize.Level1) { EXPECT_EQ(testM3u8->Base64Decode((uint8_t *)0x20000550, (uint32_t)16, (uint8_t *)0x20000550, (uint32_t *)16), true); EXPECT_EQ(testM3u8->Base64Decode((uint8_t *)0x20000550, (uint32_t)10, (uint8_t *)0x20000550, (uint32_t *)10), true); EXPECT_EQ(testM3u8->Base64Decode(nullptr, (uint32_t)10, (uint8_t *)0x20000550, (uint32_t *)10), true); } HWTEST_F(M3u8UnitTest, ConstructorTest, TestSize.Level1) { M3U8 m3u8(testUri, testName); // 检查 URI 和名称是否正确设置 ASSERT_EQ(m3u8.uri_, testUri); ASSERT_EQ(m3u8.name_, testName); // 这里可以添加更多的断言来检查初始化的状态 } // 测试 Update 方法 HWTEST_F(M3u8UnitTest, UpdateTest, TestSize.Level1) { M3U8 m3u8("http://example.com/test.m3u8", "TestPlaylist"); std::string testPlaylist = "#EXTM3U\n#EXT-X-TARGETDURATION:10\n..."; // 测试有效的播放列表更新 EXPECT_TRUE(m3u8.Update(testPlaylist)); // 测试当播放列表不变时的更新 EXPECT_TRUE(m3u8.Update(testPlaylist)); // 测试无效的播放列表更新 EXPECT_FALSE(m3u8.Update("Invalid Playlist")); } // 测试 IsLive 方法 HWTEST_F(M3u8UnitTest, IsLiveTest, TestSize.Level1) { M3U8 m3u8(testUri, "LivePlaylist"); EXPECT_FALSE(m3u8.IsLive()); } // 测试 M3U8Fragment 构造函数 HWTEST_F(M3u8UnitTest, M3U8FragmentConstructorTest, TestSize.Level1) { std::string testTitle = "FragmentTitle"; double testDuration = 10.0; int testSequence = 1; bool testDiscont = false; M3U8Fragment fragment(testUri, testTitle, testDuration, testSequence, testDiscont); ASSERT_EQ(fragment.uri_, testUri); ASSERT_EQ(fragment.title_, testTitle); ASSERT_DOUBLE_EQ(fragment.duration_, testDuration); ASSERT_EQ(fragment.sequence_, testSequence); ASSERT_EQ(fragment.discont_, testDiscont); } }