1da853ecaSopenharmony_ci/* 2da853ecaSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 3da853ecaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4da853ecaSopenharmony_ci * you may not use this file except in compliance with the License. 5da853ecaSopenharmony_ci * You may obtain a copy of the License at 6da853ecaSopenharmony_ci * 7da853ecaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8da853ecaSopenharmony_ci * 9da853ecaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10da853ecaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11da853ecaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12da853ecaSopenharmony_ci * See the License for the specific language governing permissions and 13da853ecaSopenharmony_ci * limitations under the License. 14da853ecaSopenharmony_ci */ 15da853ecaSopenharmony_ci 16da853ecaSopenharmony_ci#include <thread> 17da853ecaSopenharmony_ci#include "gtest/gtest.h" 18da853ecaSopenharmony_ci#include "avcodec_xcollie.h" 19da853ecaSopenharmony_ci#include "avcodec_errors.h" 20da853ecaSopenharmony_ci 21da853ecaSopenharmony_ciusing namespace testing::ext; 22da853ecaSopenharmony_ciusing namespace OHOS::MediaAVCodec; 23da853ecaSopenharmony_ci 24da853ecaSopenharmony_cinamespace { 25da853ecaSopenharmony_ciconstexpr uint32_t SLEEP_TIME = 1'000'000; // 1s 26da853ecaSopenharmony_ci} 27da853ecaSopenharmony_ci 28da853ecaSopenharmony_cinamespace OHOS::MediaAVCodec { 29da853ecaSopenharmony_ciclass XCollieTestSuilt : public testing::Test { 30da853ecaSopenharmony_cipublic: 31da853ecaSopenharmony_ci static void SetUpTestCase(void) {}; 32da853ecaSopenharmony_ci static void TearDownTestCase(void) {}; 33da853ecaSopenharmony_ci void SetUp(void) {}; 34da853ecaSopenharmony_ci void TearDown(void) {}; 35da853ecaSopenharmony_ci}; 36da853ecaSopenharmony_ci 37da853ecaSopenharmony_ciHWTEST_F(XCollieTestSuilt, INTERFACE_TEST, TestSize.Level1) 38da853ecaSopenharmony_ci{ 39da853ecaSopenharmony_ci COLLIE_LISTEN(usleep(SLEEP_TIME), "CollieTest", true, false, 5); 40da853ecaSopenharmony_ci CLIENT_COLLIE_LISTEN(usleep(SLEEP_TIME), "CollieTest"); 41da853ecaSopenharmony_ci int32_t ret = AVCodecXCollie::GetInstance().Dump(0); 42da853ecaSopenharmony_ci ASSERT_EQ(ret, AVCS_ERR_OK); 43da853ecaSopenharmony_ci} 44da853ecaSopenharmony_ci 45da853ecaSopenharmony_ciHWTEST_F(XCollieTestSuilt, DUMP_TEST, TestSize.Level1) 46da853ecaSopenharmony_ci{ 47da853ecaSopenharmony_ci // Test for no dumper 48da853ecaSopenharmony_ci int32_t ret = AVCodecXCollie::GetInstance().Dump(0); 49da853ecaSopenharmony_ci ASSERT_EQ(ret, AVCS_ERR_OK); 50da853ecaSopenharmony_ci 51da853ecaSopenharmony_ci std::thread task([] COLLIE_LISTEN(usleep(SLEEP_TIME), "CollieTest", true, false, 5)); 52da853ecaSopenharmony_ci if (task.joinable()) { 53da853ecaSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(20)); // 20 ms 54da853ecaSopenharmony_ci ret = AVCodecXCollie::GetInstance().Dump(0); 55da853ecaSopenharmony_ci ASSERT_EQ(ret, AVCS_ERR_OK); 56da853ecaSopenharmony_ci task.join(); 57da853ecaSopenharmony_ci } else { 58da853ecaSopenharmony_ci std::cout << "task create failed" << std::endl; 59da853ecaSopenharmony_ci } 60da853ecaSopenharmony_ci} 61da853ecaSopenharmony_ci}