diff --git a/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp b/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp index 73f6da8a61be9fb7e4330f761645160496d5fa4e..61147d938e38c70792a058137583d4be8120fdec 100644 --- a/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp +++ b/common/dfx_utils/test/unittest/src/daudio_hidumper_test.cpp @@ -56,6 +56,5 @@ HWTEST_F(DAudioHidumperTest, Dump_001, TestSize.Level1) args = {"-h", "--ability"}; EXPECT_EQ(true, hidumper_->Dump(args, result)); } - } // DistributedHardware } // OHOS diff --git a/common/include/daudio_latency_test.h b/common/include/daudio_latency_test.h index 42e62167a26761b444eb7ec454dc58dacfc40c4a..6281ff096f83bb6a8a2c083058e0c98893eeb61d 100644 --- a/common/include/daudio_latency_test.h +++ b/common/include/daudio_latency_test.h @@ -19,6 +19,7 @@ #include #include "single_instance.h" + namespace OHOS { namespace DistributedHardware { class DAudioLatencyTest { @@ -26,7 +27,6 @@ DECLARE_SINGLE_INSTANCE_BASE(DAudioLatencyTest); public: int32_t AddPlayTime(const int64_t playBeepTime); int32_t AddRecordTime(const int64_t recordBeepTime); - int64_t GetNowTimeUs(); int64_t RecordBeepTime(const uint8_t *base, const int32_t &sizePerFrame, bool &status); bool IsFrameHigh(const int16_t *audioData, const int32_t size, int32_t threshhold); int32_t ComputeLatency(); diff --git a/common/src/daudio_latency_test.cpp b/common/src/daudio_latency_test.cpp index 32154f71d8b852fcd8b652d391f0a12b02dfb868..1fd78732e18e31a0098131afddb5983e0d22149c 100644 --- a/common/src/daudio_latency_test.cpp +++ b/common/src/daudio_latency_test.cpp @@ -14,11 +14,14 @@ */ #include "daudio_latency_test.h" -#include "daudio_log.h" #include #include +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" + #undef DH_LOG_TAG #define DH_LOG_TAG "DAudioLatencyTest" @@ -38,36 +41,30 @@ DAudioLatencyTest::~DAudioLatencyTest() int32_t DAudioLatencyTest::AddPlayTime(const int64_t playBeepTime) { if (GetNowTimeUs() - lastPlayTime_ <= TWO_BEEP_TIME_INTERVAL) { - DHLOGE("Catch play high frame, but not in 900ms."); - return -1; + DHLOGE("Catch play high frame, but not in %d ms.", TWO_BEEP_TIME_INTERVAL); + return ERR_DH_AUDIO_FAILED; } DHLOGI("Catch play high frame, playTime: %lld.", playBeepTime); playBeepTime_.push_back(playBeepTime); lastPlayTime_ = GetNowTimeUs(); - return 0; + return DH_SUCCESS; } int32_t DAudioLatencyTest::AddRecordTime(const int64_t recordBeepTime) { if (captureBeepTime_.size() >= playBeepTime_.size()) { - DHLOGE("Catch record high frame, but capturesize >= playsize."); - return -1; + DHLOGE("Catch record high frame size error, capturesize %zu, playsize %zu.", + captureBeepTime_.size(), playBeepTime_.size()); + return ERR_DH_AUDIO_BAD_VALUE; } if (GetNowTimeUs() - lastRecordTime_ <= TWO_BEEP_TIME_INTERVAL) { - DHLOGE("Catch record high frame, but not in 900ms."); - return -1; + DHLOGE("Catch record high frame, but not in %d ms.", TWO_BEEP_TIME_INTERVAL); + return ERR_DH_AUDIO_FAILED; } DHLOGI("Catch record high frame, recordTime: %lld.", recordBeepTime); captureBeepTime_.push_back(recordBeepTime); lastRecordTime_ = GetNowTimeUs(); - return 0; -} - -int64_t DAudioLatencyTest::GetNowTimeUs() -{ - std::chrono::microseconds nowUs = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); - return nowUs.count(); + return DH_SUCCESS; } bool DAudioLatencyTest::IsFrameHigh(const int16_t *audioData, const int32_t size, int32_t threshhold) @@ -85,11 +82,12 @@ bool DAudioLatencyTest::IsFrameHigh(const int16_t *audioData, const int32_t size int64_t DAudioLatencyTest::RecordBeepTime(const uint8_t *base, const int32_t &sizePerFrame, bool &status) { int32_t threshhold = BEEP_THRESHHOLD; - if (IsFrameHigh((int16_t *)base, sizePerFrame / sizeof(int16_t), threshhold) == true && - status == true) { + bool isHigh = IsFrameHigh(reinterpret_cast(const_cast(base)), + sizePerFrame / sizeof(int16_t), threshhold); + if (isHigh && status) { status = false; return GetNowTimeUs(); - } else if (IsFrameHigh((int16_t *)base, sizePerFrame / sizeof(int16_t), threshhold) == false) { + } else if (!isHigh) { status = true; } return 0; diff --git a/common/src/daudio_util.cpp b/common/src/daudio_util.cpp index 84419659083ee2a39e3ebcfc5e248ef64f476d7b..33cc2dc707cd5e913bac858a9719567ff3a5f103 100644 --- a/common/src/daudio_util.cpp +++ b/common/src/daudio_util.cpp @@ -169,7 +169,12 @@ int32_t GetAudioParamStr(const std::string ¶ms, const std::string &key, std: int32_t GetAudioParamBool(const std::string ¶ms, const std::string &key, bool &value) { std::string val; - GetAudioParamStr(params, key, val); + int32_t ret = GetAudioParamStr(params, key, val); + if (ret != DH_SUCCESS) { + DHLOGE("Get audio param string fail, error code %d.", ret); + return ret; + } + value = (val != "0"); return DH_SUCCESS; } @@ -178,8 +183,13 @@ int32_t GetAudioParamInt(const std::string ¶ms, const std::string &key, int3 { std::string val = "0"; int32_t ret = GetAudioParamStr(params, key, val); + if (ret != DH_SUCCESS) { + DHLOGE("Get audio param string fail, error code %d.", ret); + return ret; + } + value = std::stoi(val); - return ret; + return DH_SUCCESS; } bool JsonParamCheck(const json &jsonObj, const std::initializer_list &keys) diff --git a/common/test/unittest/BUILD.gn b/common/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b6231b5d62b2f41e32cf5769a737e8b524a3f726 --- /dev/null +++ b/common/test/unittest/BUILD.gn @@ -0,0 +1,58 @@ +# 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. + +import("//build/ohos.gni") +import("//build/ohos_var.gni") +import("//build/test.gni") +import("../../../distributedaudio.gni") + +module_output_path = "distributed_audio/common/daudio_util_test" + +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${fwk_common_path}/utils/include", + "//third_party/json/include", + ] + + include_dirs += [ + "${common_path}/include", + "include", + ] +} + +ohos_unittest("DaudioUtilsTest") { + module_out_path = module_output_path + + sources = [ "src/daudio_utils_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${services_path}/common:distributed_audio_utils", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "LOG_DOMAIN=0xD004100", + ] +} + +group("daudio_utils_test") { + testonly = true + deps = [ ":DaudioUtilsTest" ] +} diff --git a/services/common/test/unittest/audiodata/include/daudio_latency_unit_test.h b/common/test/unittest/include/daudio_utils_test.h similarity index 80% rename from services/common/test/unittest/audiodata/include/daudio_latency_unit_test.h rename to common/test/unittest/include/daudio_utils_test.h index 5a988c8a746c5d6da70e71140dd94905c8f29b41..210c4191bc4a8ad41a90fce8f43059ee57de33a0 100644 --- a/services/common/test/unittest/audiodata/include/daudio_latency_unit_test.h +++ b/common/test/unittest/include/daudio_utils_test.h @@ -13,17 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_DAUDIO_LATENCY_UNIT_TEST_H -#define OHOS_DAUDIO_LATENCY_UNIT_TEST_H +#ifndef OHOS_DAUDIO_UTILS_TEST +#define OHOS_DAUDIO_UTILS_TEST #include #include -#include "daudio_latency_test.h" - namespace OHOS { namespace DistributedHardware { -class DAudioLatencyUnitTest : public testing::Test { +class DAudioUtilsTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -32,4 +30,4 @@ public: }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DAUDIO_LATENCY_UNIT_TEST_H \ No newline at end of file +#endif // OHOS_DAUDIO_UTILS_TEST \ No newline at end of file diff --git a/common/test/unittest/src/daudio_utils_test.cpp b/common/test/unittest/src/daudio_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49b070b59ab90c869aaf8f83ac0ac24b6b1eede1 --- /dev/null +++ b/common/test/unittest/src/daudio_utils_test.cpp @@ -0,0 +1,311 @@ +/* + * 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 "daudio_utils_test.h" + +#include + +#include "securec.h" + +#include "daudio_constants.h" +#include "daudio_errorcode.h" +#include "daudio_latency_test.h" +#include "daudio_log.h" +#include "daudio_util.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "DAudioUtilsTest" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +constexpr static int64_t TEMP_BEEP_TIME_INTERVAL_US = 10000; // 10ms +constexpr static int64_t MIN_BEEP_TIME_INTERVAL_US = 900000; // 900ms + +void DAudioUtilsTest::SetUpTestCase(void) {} + +void DAudioUtilsTest::TearDownTestCase(void) {} + +void DAudioUtilsTest::SetUp(void) {} + +void DAudioUtilsTest::TearDown(void) {} + +/** + * @tc.name: DAudioLatencyTest_001 + * @tc.desc: Verify the DAudioLatencyTest AddPlayTime, AddRecordTime and ComputeLatency function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioLatencyTest_001, TestSize.Level1) +{ + int32_t latency = DAudioLatencyTest::GetInstance().ComputeLatency(); + EXPECT_EQ(-1, latency); + + int64_t t = GetNowTimeUs(); + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, DAudioLatencyTest::GetInstance().AddRecordTime(t)); + + t = GetNowTimeUs(); + EXPECT_EQ(DH_SUCCESS, DAudioLatencyTest::GetInstance().AddPlayTime(t)); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, DAudioLatencyTest::GetInstance().AddPlayTime(t + TEMP_BEEP_TIME_INTERVAL_US)); + + std::this_thread::sleep_for(std::chrono::microseconds(MIN_BEEP_TIME_INTERVAL_US)); + t = GetNowTimeUs(); + EXPECT_EQ(DH_SUCCESS, DAudioLatencyTest::GetInstance().AddPlayTime(t)); + + t = GetNowTimeUs(); + EXPECT_EQ(DH_SUCCESS, DAudioLatencyTest::GetInstance().AddRecordTime(t)); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, DAudioLatencyTest::GetInstance().AddRecordTime(t + TEMP_BEEP_TIME_INTERVAL_US)); + + latency = DAudioLatencyTest::GetInstance().ComputeLatency(); + EXPECT_EQ(-1, latency); + + std::this_thread::sleep_for(std::chrono::microseconds(MIN_BEEP_TIME_INTERVAL_US)); + t = GetNowTimeUs(); + EXPECT_EQ(DH_SUCCESS, DAudioLatencyTest::GetInstance().AddRecordTime(t)); + + latency = DAudioLatencyTest::GetInstance().ComputeLatency(); + EXPECT_LE(0, latency); +} + +/** + * @tc.name: DAudioLatencyTest_002 + * @tc.desc: Verify the DAudioLatencyTest IsFrameHigh function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioLatencyTest_002, TestSize.Level1) +{ + int32_t threshhold = 5000; + int32_t spanSizeInByte = 960; + std::unique_ptr buf = std::make_unique(spanSizeInByte); + memset_s(buf.get(), spanSizeInByte, 0, spanSizeInByte); + bool isHigh = DAudioLatencyTest::GetInstance().IsFrameHigh(reinterpret_cast(buf.get()), + spanSizeInByte / sizeof(int16_t), threshhold); + EXPECT_EQ(false, isHigh); + + memset_s(buf.get(), spanSizeInByte, threshhold, spanSizeInByte); + isHigh = DAudioLatencyTest::GetInstance().IsFrameHigh(reinterpret_cast(buf.get()), + spanSizeInByte / sizeof(int16_t), threshhold); + EXPECT_EQ(true, isHigh); +} + +/** + * @tc.name: DAudioLatencyTest_003 + * @tc.desc: Verify the DAudioLatencyTest IsFrameHigh function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioLatencyTest_003, TestSize.Level1) +{ + bool status = true; + int32_t threshhold = 8000; + int32_t spanSizeInByte = 960; + std::unique_ptr buf = std::make_unique(spanSizeInByte); + memset_s(buf.get(), spanSizeInByte, threshhold, spanSizeInByte); + int64_t beepTime = DAudioLatencyTest::GetInstance().RecordBeepTime(static_cast(buf.get()), + spanSizeInByte, status); + EXPECT_NE(0, beepTime); + EXPECT_EQ(false, status); + + memset_s(buf.get(), spanSizeInByte, 0, spanSizeInByte); + beepTime = DAudioLatencyTest::GetInstance().RecordBeepTime(static_cast(buf.get()), + spanSizeInByte, status); + EXPECT_EQ(0, beepTime); + EXPECT_EQ(true, status); +} + +/** + * @tc.name: DAudioLogTest_001 + * @tc.desc: Verify the DHLOG definition and DHLog function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioLogTest_001, TestSize.Level1) +{ + DHLOGD("DAudio TDD test DHLOGD print."); + DHLOGI("DAudio TDD test DHLOGI print."); + DHLOGW("DAudio TDD test DHLOGW print."); + DHLOGE("DAudio TDD test DHLOGE print."); + DHLog(DHLogLevel::DH_LOG_ERROR, ""); +} + +/** + * @tc.name: DAudioLogTest_001 + * @tc.desc: Verify the GetCurrentTime function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_001, TestSize.Level1) +{ + int64_t tvSec; + int64_t tvNSec; + GetCurrentTime(tvSec, tvNSec); +} + +/** + * @tc.name: DAudioLogTest_002 + * @tc.desc: Verify the GetCurrentTime, GetCurNano and AbsoluteSleep function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_002, TestSize.Level1) +{ + int64_t tvSec; + int64_t tvNSec; + GetCurrentTime(tvSec, tvNSec); + + int64_t curNano = GetCurNano(); + EXPECT_NE(0, curNano); + + int32_t ret = AbsoluteSleep(curNano); + EXPECT_EQ(0, ret); +} + +/** + * @tc.name: DAudioLogTest_003 + * @tc.desc: Verify the CalculateSampleNum and UpdateTimeOffset function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_003, TestSize.Level1) +{ + uint32_t sampleRate = 48000; + uint32_t timeInterval = 5; + int32_t desiredSpanSizeInFrame = 240; + int32_t spanSizeInFrame = CalculateSampleNum(sampleRate, timeInterval); + EXPECT_EQ(desiredSpanSizeInFrame, spanSizeInFrame); + + int64_t frameIndex = 0; + int64_t framePeriodNs = 5000000; + int64_t startTime = 0; + int64_t timeOffset = UpdateTimeOffset(frameIndex, framePeriodNs, startTime); + EXPECT_NE(0, startTime); + EXPECT_EQ(0, timeOffset); + + frameIndex = AUDIO_OFFSET_FRAME_NUM / 2; + timeOffset = UpdateTimeOffset(frameIndex, framePeriodNs, startTime); + EXPECT_EQ(0, timeOffset); + + frameIndex = AUDIO_OFFSET_FRAME_NUM; + timeOffset = UpdateTimeOffset(frameIndex, framePeriodNs, startTime); + EXPECT_NE(0, timeOffset); +} + +/** + * @tc.name: DAudioLogTest_004 + * @tc.desc: Verify the GetAudioParamBool function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_004, TestSize.Level1) +{ + std::string params = ""; + std::string key = ""; + bool value = false; + EXPECT_EQ(ERR_DH_AUDIO_FAILED, GetAudioParamBool(params, key, value)); + + params = "params"; + key = "key"; + EXPECT_EQ(ERR_DH_AUDIO_NOT_FOUND_KEY, GetAudioParamBool(params, key, value)); + + params = "key=0"; + EXPECT_EQ(DH_SUCCESS, GetAudioParamBool(params, key, value)); + EXPECT_EQ(false, value); + + params = "param1=true;key=1;param2=false;"; + EXPECT_EQ(DH_SUCCESS, GetAudioParamBool(params, key, value)); + EXPECT_EQ(true, value); +} + +/** + * @tc.name: DAudioLogTest_005 + * @tc.desc: Verify the GetAudioParamInt function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_005, TestSize.Level1) +{ + std::string params = ""; + std::string key = ""; + int32_t value = 5; + EXPECT_EQ(ERR_DH_AUDIO_FAILED, GetAudioParamInt(params, key, value)); + + params = "params"; + key = "key"; + EXPECT_EQ(ERR_DH_AUDIO_NOT_FOUND_KEY, GetAudioParamInt(params, key, value)); + + params = "key=0"; + EXPECT_EQ(DH_SUCCESS, GetAudioParamInt(params, key, value)); + EXPECT_EQ(0, value); + + params = "param1=true;key=1;param2=false;"; + EXPECT_EQ(DH_SUCCESS, GetAudioParamInt(params, key, value)); + EXPECT_EQ(1, value); +} + +/** + * @tc.name: DAudioLogTest_006 + * @tc.desc: Verify the JsonParamCheck function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_006, TestSize.Level1) +{ + std::string tempKey = "TestParam"; + json jParam = { { KEY_DEV_ID, "TEST_DEV_ID" }, {KEY_AUDIO_PARAM, "TEST_PARAM" }, {KEY_FORMAT, "TEST_8000" }, + { tempKey, "TEST_TEMP_KEY" } }; + EXPECT_EQ(false, JsonParamCheck(jParam, { KEY_ATTRS })); + EXPECT_EQ(false, JsonParamCheck(jParam, { KEY_AUDIO_PARAM })); + EXPECT_EQ(false, JsonParamCheck(jParam, { KEY_FORMAT })); + EXPECT_EQ(false, JsonParamCheck(jParam, { tempKey })); + EXPECT_EQ(true, JsonParamCheck(jParam, { KEY_DEV_ID })); +} + +/** + * @tc.name: DAudioLogTest_007 + * @tc.desc: Verify the CheckIsNum and CheckDevIdIsLegal function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_007, TestSize.Level1) +{ + uint8_t maxDhIdLen = 20; + std::string tempDhIdStr(maxDhIdLen + 1, 'a'); + EXPECT_EQ(false, CheckIsNum(tempDhIdStr)); + + tempDhIdStr = ""; + EXPECT_EQ(false, CheckIsNum(tempDhIdStr)); + + tempDhIdStr = "TestParams"; + EXPECT_EQ(false, CheckIsNum(tempDhIdStr)); + + tempDhIdStr = "1"; + EXPECT_EQ(true, CheckIsNum(tempDhIdStr)); + + std::string tempDevIdStr(DAUDIO_MAX_DEVICE_ID_LEN + 1, 'a'); + EXPECT_EQ(false, CheckDevIdIsLegal(tempDevIdStr)); + + tempDevIdStr = ""; + EXPECT_EQ(false, CheckDevIdIsLegal(tempDevIdStr)); + + tempDevIdStr = "Test*Params#"; + EXPECT_EQ(false, CheckDevIdIsLegal(tempDevIdStr)); + + tempDevIdStr = "Test1"; + EXPECT_EQ(true, CheckDevIdIsLegal(tempDevIdStr)); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn index 583e2b94397a68efc8b3777dad0b3c3f021db6d2..cdb2083e89af42c8b5b9712f51468875988e1e5b 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn @@ -18,6 +18,7 @@ import("../../../../../distributedaudio.gni") group("unittest") { testonly = true deps = [ + "${common_path}/test/unittest:daudio_utils_test", "${distributedaudio_path}/audiohandler/test/unittest:audio_handler_test", "${hdf_service_path}/hdi_service/audio/v1_0/test/unittest:hdi_service_audio_test", "${hdf_service_path}/hdi_service/audio_ext/v1_0/test/unittest:hdi_service_audio_ext_test", diff --git a/services/common/test/unittest/audiodata/src/daudio_latency_unit_test.cpp b/services/common/test/unittest/audiodata/src/daudio_latency_unit_test.cpp deleted file mode 100644 index 011c22e34fae21b18a531cd7978ccbfe51d0c51c..0000000000000000000000000000000000000000 --- a/services/common/test/unittest/audiodata/src/daudio_latency_unit_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - */ - -#define private public -#include "audio_data_test.h" -#undef private - -#include "daudio_constants.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void DAudioLatencyUnitTest::SetUpTestCase(void) {} - -void DAudioLatencyUnitTest::TearDownTestCase(void) {} - -void DAudioLatencyUnitTest::SetUp(void) {} - -void DAudioLatencyUnitTest::TearDown(void) {} - -/** - * @tc.name: AddPlayRecordTime_001 - * @tc.desc: Verify the AddPlayTime & Add RecordTime function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(DAudioLatencyUnitTest, AddPlayRecordTime_001, TestSize.Level1) -{ - int64_t t = DAudioLatencyTest::GetInstance()->GetNowTimeUs(); - int ret = DAudioLatencyTest::GetInstance()->AddPlayTime(t); - EXPECT_EQ(0, ret); - t = DAudioLatencyTest::GetInstance()->GetNowTimeUs(); - ret = DAudioLatencyTest::GetInstance()->AddRecordTime(t); - EXPECT_EQ(0, ret); - int latency = DAudioLatencyTest::GetInstance()->ComputeLatency(); - EXPECT_LE(0, latency); -} -} // namespace DistributedHardware -} // namespace OHOS