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 <thread> 17#include "gtest/gtest.h" 18#include "avcodec_xcollie.h" 19#include "avcodec_errors.h" 20 21using namespace testing::ext; 22using namespace OHOS::MediaAVCodec; 23 24namespace { 25constexpr uint32_t SLEEP_TIME = 1'000'000; // 1s 26} 27 28namespace OHOS::MediaAVCodec { 29class XCollieTestSuilt : public testing::Test { 30public: 31 static void SetUpTestCase(void) {}; 32 static void TearDownTestCase(void) {}; 33 void SetUp(void) {}; 34 void TearDown(void) {}; 35}; 36 37HWTEST_F(XCollieTestSuilt, INTERFACE_TEST, TestSize.Level1) 38{ 39 COLLIE_LISTEN(usleep(SLEEP_TIME), "CollieTest", true, false, 5); 40 CLIENT_COLLIE_LISTEN(usleep(SLEEP_TIME), "CollieTest"); 41 int32_t ret = AVCodecXCollie::GetInstance().Dump(0); 42 ASSERT_EQ(ret, AVCS_ERR_OK); 43} 44 45HWTEST_F(XCollieTestSuilt, DUMP_TEST, TestSize.Level1) 46{ 47 // Test for no dumper 48 int32_t ret = AVCodecXCollie::GetInstance().Dump(0); 49 ASSERT_EQ(ret, AVCS_ERR_OK); 50 51 std::thread task([] COLLIE_LISTEN(usleep(SLEEP_TIME), "CollieTest", true, false, 5)); 52 if (task.joinable()) { 53 std::this_thread::sleep_for(std::chrono::milliseconds(20)); // 20 ms 54 ret = AVCodecXCollie::GetInstance().Dump(0); 55 ASSERT_EQ(ret, AVCS_ERR_OK); 56 task.join(); 57 } else { 58 std::cout << "task create failed" << std::endl; 59 } 60} 61}