From 83225e9dde6a6674395017277a67b0a1e339ed0d Mon Sep 17 00:00:00 2001 From: chenshuo Date: Thu, 20 Jul 2023 11:46:42 +0800 Subject: [PATCH 01/13] add UT Signed-off-by: chenshuo --- .../test/unittest/common/BUILD.gn | 66 +++ .../include/histreamer_ability_querier_test.h | 38 ++ .../src/histreamer_ability_querier_test.cpp | 512 ++++++++++++++++++ bundle.json | 1 + 4 files changed, 617 insertions(+) create mode 100644 av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn create mode 100644 av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h create mode 100644 av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn new file mode 100644 index 00000000..5bd744cf --- /dev/null +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2022-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/test.gni") + +import( + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") + +module_out_path = "distributed_hardware_fwk/histreamer_ability_querier_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "//third_party/json/include", + "${handler_path}/histreamer_ability_querier/include", + "${engine_path}/av_sender/include", + "${engine_path}/av_receiver/include", + "${interface_path}", + "${common_path}/include", + "${media_standard_path}/interfaces/inner_api/native", + ] +} + +ohos_unittest("HistreamerAbilityQuerierTest") { + module_out_path = module_out_path + + sources = [ + "src/histreamer_ability_querier_test.cpp" , + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${handler_path}/histreamer_ability_querier:histreamer_ability_querier", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"HistreamerAbilityQuerierTest\"", + ] +} + +group("histreamer_ability_querier_test") { + testonly = true + deps = [ ":HistreamerAbilityQuerierTest" ] +} \ No newline at end of file diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h new file mode 100644 index 00000000..38b7f6f2 --- /dev/null +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_HISTREAMER_ABILITY_QUERIER_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_HISTREAMER_ABILITY_QUERIER_TEST_H + +#include "nlohmann/json.hpp" +#include + +namespace OHOS { +namespace DistributedHardware { +class HistreamerAbilityQuerierTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +bool IsUInt8(const nlohmann::json& jsonObj, const std::string& key); + +bool IsUInt32(const nlohmann::json& jsonObj, const std::string& key); + +bool IsString(const nlohmann::json& jsonObj, const std::string& key); +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp new file mode 100644 index 00000000..4be87b76 --- /dev/null +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp @@ -0,0 +1,512 @@ +/* + * Copyright (c) 2021-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 "histreamer_ability_querier_test.h" +#include "histreamer_ability_querier.h" + +#include +#include +#include +#include + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void HistreamerAbilityQuerierTest::SetUpTestCase(void) {} + +void HistreamerAbilityQuerierTest::TearDownTestCase(void) {} + +void HistreamerAbilityQuerierTest::SetUp() {} + +void HistreamerAbilityQuerierTest::TearDown() {} + +namespace { +int32_t MAX_MESSAGES_LEN = 1 * 1024 * 1024; +static const std::uint16_t NUM = 1; +static const std::string KEY = "key"; +static const std::string NAME = "name"; +static const std::string MIME = "mime"; +static const std::string AD_MPEG_VER = "ad_mpeg_ver"; +static const std::string AUDIO_AAC_PROFILE = "aac_profile"; +static const std::string AUDIO_AAC_STREAM_FORMAT = "aac_stm_fmt"; + +static const std::vector AUDIO_ENCODER_WANT = { "ffmpegAuEnc_aac" }; +static const std::vector AUDIO_DECODER_WANT = { "ffmpegAuDec_aac" }; +static const std::vector VIDEO_ENCODER_WANT = { + "HdiCodecAdapter.OMX.hisi.video.encoder.hevc", + "HdiCodecAdapter.OMX.hisi.video.encoder.avc", + "HdiCodecAdapter.OMX.rk.video_encoder.hevc", + "HdiCodecAdapter.OMX.rk.video_encoder.avc" + }; +static const std::vector VIDEO_DECODER_WANT = { + "HdiCodecAdapter.OMX.hisi.video.decoder.hevc", + "HdiCodecAdapter.OMX.hisi.video.decoder.avc", + "HdiCodecAdapter.OMX.rk.video_decoder.hevc", + "HdiCodecAdapter.OMX.rk.video_decoder.avc" + }; +} + +/** + * @tc.name:histreamer_ability_querier_test_001 + * @tc.desc: Verify the QueryAudioEncoderAbility function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_001, TestSize.Level0) +{ + std::vector audioEncoders = QueryAudioEncoderAbility(); + EXPECT_FALSE(audioEncoders.empty()); + EXPECT_EQ(NUM, audioEncoders.size()); + EXPECT_STREQ(AUDIO_ENCODER_WANT.front().c_str(), audioEncoders.front().name.c_str()); +} + +/** + * @tc.name: histreamer_ability_querier_test_002 + * @tc.desc: Verify QueryAudioDecoderAbility function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_002, TestSize.Level0) +{ + std::vector audioDecoders = QueryAudioDecoderAbility(); + EXPECT_FALSE(audioDecoders.empty()); + EXPECT_EQ(NUM, audioDecoders.size()); + EXPECT_STREQ(AUDIO_DECODER_WANT.front().c_str(), audioDecoders.front().name.c_str()); +} + +/** + * @tc.name: histreamer_ability_querier_test_003 + * @tc.desc: Verify QueryVideoEncoderAbility function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_003, TestSize.Level0) +{ + std::vector videoEncoders = QueryVideoEncoderAbility(); + EXPECT_FALSE(videoEncoders.empty() || videoEncoders.size() > 4); + for (std::uint16_t i = 0; i < videoEncoders.size(); i++) { + EXPECT_TRUE(find(VIDEO_ENCODER_WANT.begin(), VIDEO_ENCODER_WANT.end(), videoEncoders[i].name) != VIDEO_ENCODER_WANT.end()); + } +} + +/** + * @tc.name: histreamer_ability_querier_test_004 + * @tc.desc: Verify QueryVideoDecoderAbility function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + * + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_004, TestSize.Level0) +{ + std::vector videoDecoders = QueryVideoDecoderAbility(); + EXPECT_FALSE(videoDecoders.empty() || videoDecoders.size() > 4); + for (std::uint16_t i = 0; i < videoDecoders.size(); i++) { + EXPECT_TRUE(find(VIDEO_DECODER_WANT.begin(), VIDEO_DECODER_WANT.end(), videoDecoders[i].name) != VIDEO_DECODER_WANT.end()); + } +} + +/** + * @tc.name: histreamer_ability_querier_test_005 + * @tc.desc: Verify QueryAudioEncoderAbilityStr function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_005, TestSize.Level0) +{ + char* RES_MAX = new char[MAX_MESSAGES_LEN]; + EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) >= 0); + EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + delete[] RES_MAX; +} + +/** + * @tc.name: histreamer_ability_querier_test_006 + * @tc.desc: Verify QueryAudioDecoderAbilityStr function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_006, TestSize.Level0) +{ + char* RES_MAX = new char[MAX_MESSAGES_LEN]; + EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) >= 0); + EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + delete[] RES_MAX; +} + +/** + * @tc.name: histreamer_ability_querier_test_007 + * @tc.desc: Verify QueryVideoEncoderAbilityStr function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_007, TestSize.Level0) +{ + char* RES_MAX = new char[MAX_MESSAGES_LEN]; + EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) >= 0); + EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + delete[] RES_MAX; +} + +/** + * @tc.name: histreamer_ability_querier_test_008 + * @tc.desc: Verify the QueryVideoDecoderAbilityStr function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_008, TestSize.Level0) +{ + char* RES_MAX = new char[MAX_MESSAGES_LEN]; + EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) >= 0); + EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + delete[] RES_MAX; +} + +/** + * @tc.name: histreamer_ability_querier_test_009 + * @tc.desc: Verify the IsString function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_009, TestSize.Level0) +{ + nlohmann::json jsonObject; + jsonObject[KEY] = "testing str"; + EXPECT_TRUE(IsString(jsonObject, KEY)); + + jsonObject[KEY] = 1; + EXPECT_FALSE(IsString(jsonObject, KEY)); +} + +/** + * @tc.name: histreamer_ability_querier_test_010 + * @tc.desc: Verify the IsUint8 function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_010, TestSize.Level0) +{ + nlohmann::json jsonObject; + const uint8_t num_s = 1; + jsonObject[KEY] = num_s; + EXPECT_TRUE(IsUInt8(jsonObject, KEY)); + + const uint16_t num_b = UINT8_MAX + 1 ; + jsonObject[KEY] = num_b; + EXPECT_FALSE(IsUInt8(jsonObject, KEY)); +} + +/** + * @tc.name: histreamer_ability_querier_test_011 + * @tc.desc: Verify the IsUInt32 function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_011, TestSize.Level0) +{ + nlohmann::json jsonObject; + const uint32_t num_s = 1; + jsonObject[KEY] = num_s; + EXPECT_TRUE(IsUInt32(jsonObject, KEY)); + + const int32_t num_i = -1; + jsonObject[KEY] = num_i; + EXPECT_FALSE(IsUInt32(jsonObject, KEY)); +} + +/** + * @tc.name: histreamer_ability_querier_test_012 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioEncoderIn &audioEncoderIn) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_012, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoderIn audioEncoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioEncoderIn); + EXPECT_TRUE(audioEncoderIn.mime.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_013 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioEncoderOut &audioEncoderOut) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_013, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoderOut audioEncoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioEncoderOut); + EXPECT_TRUE(audioEncoderOut.mime.empty()); + + jsonObject[MIME] = "audio/mp4a-latm"; + jsonObject[AD_MPEG_VER] = "hello"; + FromJson(jsonObject, audioEncoderOut); + EXPECT_EQ("audio/mp4a-latm", audioEncoderOut.mime); + + jsonObject[AD_MPEG_VER] = (uint32_t)4; + jsonObject[AUDIO_AAC_PROFILE] = "hello"; + FromJson(jsonObject, audioEncoderOut); + EXPECT_EQ(4, (uint32_t)audioEncoderOut.ad_mpeg_ver); + + jsonObject[AUDIO_AAC_PROFILE] = 0; + jsonObject[AUDIO_AAC_STREAM_FORMAT] = "hello"; + FromJson(jsonObject, audioEncoderOut); + EXPECT_EQ(0, (uint32_t)audioEncoderOut.aac_profile); +} + +/** + * @tc.name: histreamer_ability_querier_test_014 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioEncoder &audioEncoder) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_014, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoder audioEncoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, audioEncoder); + EXPECT_TRUE(audioEncoder.name.empty()); + + jsonObject[NAME] = "ffmpegAuEnc_aac"; + FromJson(jsonObject, audioEncoder); + EXPECT_EQ("ffmpegAuEnc_aac", audioEncoder.name); + EXPECT_TRUE(audioEncoder.ins.empty()); + + AudioEncoderIn audioEncoderIn; + audioEncoderIn.mime = "audio/raw"; + audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350}; + audioEncoder.ins.push_back(audioEncoderIn); + FromJson(jsonObject, audioEncoder); + EXPECT_FALSE(audioEncoder.ins.empty()); + EXPECT_TRUE(audioEncoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_015 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioDecoderIn &audioDecoderIn) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_015, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoderIn audioDecoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioDecoderIn); + EXPECT_TRUE(audioDecoderIn.mime.empty()); + + jsonObject[MIME] = "audio/mp4a-latm"; + FromJson(jsonObject, audioDecoderIn); + EXPECT_EQ("audio/mp4a-latm", audioDecoderIn.mime); + EXPECT_TRUE(audioDecoderIn.channel_layout.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_016 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioDecoderOut &audioDecoderOut) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_016, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoderOut audioDecoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioDecoderOut); + EXPECT_TRUE(audioDecoderOut.mime.empty()); + + jsonObject[MIME] = "audio/raw"; + FromJson(jsonObject, audioDecoderOut); + EXPECT_EQ("audio/raw", audioDecoderOut.mime); + EXPECT_TRUE(audioDecoderOut.sample_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_017 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioDecoder &audioDecoder) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_017, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoder audioDecoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, audioDecoder); + EXPECT_TRUE(audioDecoder.name.empty()); + + jsonObject[NAME] = "ffmpegAuDec_aac"; + FromJson(jsonObject, audioDecoder); + EXPECT_EQ("ffmpegAuDec_aac", audioDecoder.name); + EXPECT_TRUE(audioDecoder.ins.empty()); + + AudioDecoderIn audioDecoderIn; + audioDecoderIn.mime = "audio/mp4a-latm"; + audioDecoderIn.channel_layout = { + AudioChannelLayout::CH_2POINT1, + AudioChannelLayout::CH_2_1, + AudioChannelLayout::SURROUND, + }; + audioDecoder.ins.push_back(audioDecoderIn); + FromJson(jsonObject, audioDecoder); + EXPECT_FALSE(audioDecoder.ins.empty()); + EXPECT_TRUE(audioDecoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_018 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoEncoderIn &videoEncoderIn) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_018, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoderIn videoEncoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoEncoderIn); + EXPECT_TRUE(videoEncoderIn.mime.empty()); + + jsonObject[MIME] = "video/raw"; + FromJson(jsonObject, videoEncoderIn); + EXPECT_EQ("video/raw", videoEncoderIn.mime); + EXPECT_TRUE(videoEncoderIn.pixel_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_019 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoEncoderOut &videoEncoderOut) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_019, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoderOut videoEncoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoEncoderOut); + EXPECT_TRUE(videoEncoderOut.mime.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_020 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoEncoder &videoEncoder) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_020, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoder videoEncoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, videoEncoder); + EXPECT_TRUE(videoEncoder.name.empty()); + + jsonObject[NAME] = "HdiCodecAdapter.OMX.rk.video_encoder.hevc"; + FromJson(jsonObject, videoEncoder); + EXPECT_EQ("HdiCodecAdapter.OMX.rk.video_encoder.hevc", videoEncoder.name); + EXPECT_TRUE(videoEncoder.ins.empty()); + + VideoEncoderIn videoEncoderIn; + videoEncoderIn.mime = "vide/raw"; + videoEncoderIn.pixel_fmt = { + VideoPixelFormat::YUV410P, + VideoPixelFormat::RGBA, + }; + videoEncoder.ins.push_back(videoEncoderIn); + FromJson(jsonObject, videoEncoder); + EXPECT_FALSE(videoEncoder.ins.empty()); + EXPECT_TRUE(videoEncoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_021 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoDecoderIn &videoDecoderIn) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_021, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoderIn videoDecoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoDecoderIn); + EXPECT_TRUE(videoDecoderIn.mime.empty()); + + jsonObject[MIME] = "video/hevc"; + FromJson(jsonObject, videoDecoderIn); + EXPECT_EQ("video/hevc", videoDecoderIn.mime); + EXPECT_TRUE(videoDecoderIn.vd_bit_stream_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_022 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoDecoderOut &videoDecoderOut) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_022, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoderOut videoDecoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoDecoderOut); + EXPECT_TRUE(videoDecoderOut.mime.empty()); + + jsonObject[MIME] = "video/raw"; + FromJson(jsonObject, videoDecoderOut); + EXPECT_EQ("video/raw", videoDecoderOut.mime); + EXPECT_TRUE(videoDecoderOut.pixel_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_querier_test_023 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoDecoder &videoDecoder) function. + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_023, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoder videoDecoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, videoDecoder); + EXPECT_TRUE(videoDecoder.name.empty()); + + jsonObject[NAME] = "HdiCodecAdapter.OMX.rk.video_decoder.hevc"; + FromJson(jsonObject, videoDecoder); + EXPECT_EQ("HdiCodecAdapter.OMX.rk.video_decoder.hevc", videoDecoder.name); + EXPECT_TRUE(videoDecoder.ins.empty()); + + VideoDecoderIn videoDecoderIn; + videoDecoderIn.mime = "vide/avc"; + videoDecoderIn.vd_bit_stream_fmt = { + VideoBitStreamFormat::AVC1, + VideoBitStreamFormat::HEVC, + }; + videoDecoder.ins.push_back(videoDecoderIn); + FromJson(jsonObject, videoDecoder); + EXPECT_FALSE(videoDecoder.ins.empty()); + EXPECT_TRUE(videoDecoder.outs.empty()); +} + +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/bundle.json b/bundle.json index bfe9c1cc..2e00f11c 100644 --- a/bundle.json +++ b/bundle.json @@ -107,6 +107,7 @@ } ], "test": [ + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common:histreamer_ability_querier_test", "//foundation/distributedhardware/distributed_hardware_fwk/utils/test/unittest:utils_test", "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice/test/unittest:test", "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/inner_kits/test/unittest:kit_test", -- Gitee From 1345e4f8b1e287ada3ff38d1d3d22289145a745e Mon Sep 17 00:00:00 2001 From: chenshuo Date: Thu, 20 Jul 2023 15:15:28 +0800 Subject: [PATCH 02/13] add UT histreamer_ability_querier Signed-off-by: chenshuo --- .../test/unittest/common/BUILD.gn | 6 ++---- .../common/include/histreamer_ability_querier_test.h | 2 +- .../unittest/common/src/histreamer_ability_querier_test.cpp | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn index 5bd744cf..7e49d779 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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 @@ -35,9 +35,7 @@ config("module_private_config") { ohos_unittest("HistreamerAbilityQuerierTest") { module_out_path = module_out_path - sources = [ - "src/histreamer_ability_querier_test.cpp" , - ] + sources = [ "src/histreamer_ability_querier_test.cpp" ] configs = [ ":module_private_config" ] diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h index 38b7f6f2..abbbf30a 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/include/histreamer_ability_querier_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp index 4be87b76..f6a04a0e 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * 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 -- Gitee From fa7282397592daa93b7c2327d89dfdbaf3547546 Mon Sep 17 00:00:00 2001 From: chenshuo Date: Thu, 20 Jul 2023 19:24:12 +0800 Subject: [PATCH 03/13] gn_formater Signed-off-by: chenshuo --- .../test/unittest/common/src/BUILD.gn | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn new file mode 100644 index 00000000..c6ba00f3 --- /dev/null +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn @@ -0,0 +1,64 @@ +# 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/test.gni") + +import( + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") + +module_out_path = "distributed_hardware_fwk/histreamer_ability_querier_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "//third_party/json/include", + "${handler_path}/histreamer_ability_querier/include", + "${engine_path}/av_sender/include", + "${engine_path}/av_receiver/include", + "${interface_path}", + "${common_path}/include", + "${media_standard_path}/interfaces/inner_api/native", + ] +} + +ohos_unittest("HistreamerAbilityQuerierTest") { + module_out_path = module_out_path + + sources = [ "src/histreamer_ability_querier_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${handler_path}/histreamer_ability_querier:histreamer_ability_querier", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"HistreamerAbilityQuerierTest\"", + ] +} + +group("histreamer_ability_querier_test") { + testonly = true + deps = [ ":HistreamerAbilityQuerierTest" ] +} -- Gitee From 10d68786b773876bf11c3505b647a75f4329e387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=83=81?= Date: Thu, 20 Jul 2023 12:34:21 +0000 Subject: [PATCH 04/13] update av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈烁 --- .../test/unittest/common/src/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn index c6ba00f3..7e49d779 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn @@ -61,4 +61,4 @@ ohos_unittest("HistreamerAbilityQuerierTest") { group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] -} +} \ No newline at end of file -- Gitee From 5906c6c8988ffba4c646e1ec29c14bb8b8656801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=83=81?= Date: Thu, 20 Jul 2023 12:34:35 +0000 Subject: [PATCH 05/13] update av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈烁 --- .../test/unittest/common/src/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn index 7e49d779..c6ba00f3 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn @@ -61,4 +61,4 @@ ohos_unittest("HistreamerAbilityQuerierTest") { group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] -} \ No newline at end of file +} -- Gitee From c9165006ea45a674031b2da0a7fd85ec4042ef6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=83=81?= Date: Fri, 21 Jul 2023 01:26:30 +0000 Subject: [PATCH 06/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20av?= =?UTF-8?q?=5Ftransport/av=5Ftrans=5Fhandler/histreamer=5Fability=5Fquerie?= =?UTF-8?q?r/test/unittest/common/src/BUILD.gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/unittest/common/src/BUILD.gn | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn deleted file mode 100644 index c6ba00f3..00000000 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/BUILD.gn +++ /dev/null @@ -1,64 +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. - -import("//build/test.gni") - -import( - "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") - -module_out_path = "distributed_hardware_fwk/histreamer_ability_querier_test" - -config("module_private_config") { - visibility = [ ":*" ] - include_dirs = [ - "include", - "//third_party/json/include", - "${handler_path}/histreamer_ability_querier/include", - "${engine_path}/av_sender/include", - "${engine_path}/av_receiver/include", - "${interface_path}", - "${common_path}/include", - "${media_standard_path}/interfaces/inner_api/native", - ] -} - -ohos_unittest("HistreamerAbilityQuerierTest") { - module_out_path = module_out_path - - sources = [ "src/histreamer_ability_querier_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "${handler_path}/histreamer_ability_querier:histreamer_ability_querier", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "histreamer:histreamer_base", - "histreamer:histreamer_codec_filters", - "histreamer:histreamer_ffmpeg_convert", - "histreamer:histreamer_plugin_base", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"HistreamerAbilityQuerierTest\"", - ] -} - -group("histreamer_ability_querier_test") { - testonly = true - deps = [ ":HistreamerAbilityQuerierTest" ] -} -- Gitee From 61780e5213bbc89a6791d14cba3516970a2bab1e Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 09:26:00 +0800 Subject: [PATCH 07/13] edit BUILD.gn Signed-off-by: chenshuo --- .../histreamer_ability_querier/test/unittest/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn index 7e49d779..c6ba00f3 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -61,4 +61,4 @@ ohos_unittest("HistreamerAbilityQuerierTest") { group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] -} \ No newline at end of file +} -- Gitee From 39c42fa3341348cb22f48b03df28a881ac653a3b Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 09:36:10 +0800 Subject: [PATCH 08/13] edit BUILD.gn Signed-off-by: chenshuo --- .../histreamer_ability_querier/test/unittest/common/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn index c6ba00f3..5189d259 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -62,3 +62,4 @@ group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] } + -- Gitee From f545e400224ccf98cce91dc4f98c6687041abd1a Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 09:52:16 +0800 Subject: [PATCH 09/13] edit Signed-off-by: chenshuo --- .../histreamer_ability_querier/test/unittest/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn index 5189d259..c3d347ab 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -61,5 +61,5 @@ ohos_unittest("HistreamerAbilityQuerierTest") { group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] -} +} -- Gitee From d1dbf5522eb63c5662f588e8f662df6e600b6d8f Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 09:53:37 +0800 Subject: [PATCH 10/13] delete another BUILD.gn Signed-off-by: chenshuo Signed-off-by: chenshuo --- .../histreamer_ability_querier/test/unittest/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn index c3d347ab..5189d259 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -61,5 +61,5 @@ ohos_unittest("HistreamerAbilityQuerierTest") { group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] -} +} -- Gitee From f630211a89106988f53114381a537eaedc92d976 Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 14:53:27 +0800 Subject: [PATCH 11/13] edit histreamer_ability_parser/BUILD.gn add UT histreamer_ability_parser Signed-off-by: chenshuo --- .../test/unittest/common/BUILD.gn | 1 - utils/test/unittest/BUILD.gn | 3 +- .../common/histreamer_ability_parser/BUILD.gn | 49 +++ .../histreamer_ability_parser_test.cpp | 409 ++++++++++++++++++ .../histreamer_ability_parser_test.h | 37 ++ 5 files changed, 497 insertions(+), 2 deletions(-) create mode 100644 utils/test/unittest/common/histreamer_ability_parser/BUILD.gn create mode 100644 utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp create mode 100644 utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.h diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn index 5189d259..c6ba00f3 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/BUILD.gn @@ -62,4 +62,3 @@ group("histreamer_ability_querier_test") { testonly = true deps = [ ":HistreamerAbilityQuerierTest" ] } - diff --git a/utils/test/unittest/BUILD.gn b/utils/test/unittest/BUILD.gn index 9333ec9c..fb9faf0b 100644 --- a/utils/test/unittest/BUILD.gn +++ b/utils/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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 @@ -16,6 +16,7 @@ group("utils_test") { deps = [ "common/eventbus:event_bus_test", "common/eventtrance:event_trance_test", + "common/histreamer_ability_parser:histreamer_ability_parser_test", "common/utilstool:utils_tool_test", ] } diff --git a/utils/test/unittest/common/histreamer_ability_parser/BUILD.gn b/utils/test/unittest/common/histreamer_ability_parser/BUILD.gn new file mode 100644 index 00000000..0f2046f3 --- /dev/null +++ b/utils/test/unittest/common/histreamer_ability_parser/BUILD.gn @@ -0,0 +1,49 @@ +# 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/test.gni") +import( + "//foundation/distributedhardware/distributed_hardware_fwk/distributedhardwarefwk.gni") + +module_out_path = "distributed_hardware_fwk/histreamer_ability_parser_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${utils_path}/include", + "${utils_path}/include/log", + "//third_party/json/include", + ] +} + +## UnitTest histreamer_ability_parser_test +ohos_unittest("HistreamerAbilityParserTest") { + module_out_path = module_out_path + + sources = [ "${utils_path}/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${utils_path}:distributedhardwareutils", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ "c_utils:utils" ] +} + +group("histreamer_ability_parser_test") { + testonly = true + deps = [ ":HistreamerAbilityParserTest" ] +} diff --git a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp new file mode 100644 index 00000000..5280a441 --- /dev/null +++ b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp @@ -0,0 +1,409 @@ +/* + * 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 "histreamer_ability_parser_test.h" +#include +#include + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +static const std::string NAME = "name"; +static const std::string INS = "ins"; +static const std::string OUTS = "outs"; +static const std::string MIME = "mime"; +static const std::string SAMPLE_RATE = "sample_rate"; +static const std::string AD_MPEG_VER = "ad_mpeg_ver"; +static const std::string AUDIO_AAC_PROFILE = "aac_profile"; +static const std::string AUDIO_AAC_STREAM_FORMAT = "aac_stm_fmt"; +static const std::string VIDEO_PIXEL_FMT = "pixel_fmt"; + +void HistreamerAbilityParserTest::SetUpTestCase(void) {} + +void HistreamerAbilityParserTest::TearDownTestCase(void) {} + +void HistreamerAbilityParserTest::SetUp() {} + +void HistreamerAbilityParserTest::TearDown() {} + +/** + * @tc.name: histreamer_ability_parser_test_001 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioEncoderIn &audioEncoderIn) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_001, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoderIn audioEncoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioEncoderIn); + EXPECT_TRUE(audioEncoderIn.mime.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_002 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioEncoderOut &audioEncoderOut) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_002, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoderOut audioEncoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioEncoderOut); + EXPECT_TRUE(audioEncoderOut.mime.empty()); + + jsonObject[MIME] = "audio/mp4a-latm"; + jsonObject[AD_MPEG_VER] = "hello"; + FromJson(jsonObject, audioEncoderOut); + EXPECT_EQ("audio/mp4a-latm", audioEncoderOut.mime); + + jsonObject[AD_MPEG_VER] = (uint32_t)4; + jsonObject[AUDIO_AAC_PROFILE] = "hello"; + FromJson(jsonObject, audioEncoderOut); + EXPECT_EQ(4, (uint32_t)audioEncoderOut.ad_mpeg_ver); + + jsonObject[AUDIO_AAC_PROFILE] = 0; + jsonObject[AUDIO_AAC_STREAM_FORMAT] = "hello"; + FromJson(jsonObject, audioEncoderOut); + EXPECT_EQ(0, (uint32_t)audioEncoderOut.aac_profile); +} + +/** + * @tc.name: histreamer_ability_parser_test_003 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioEncoder &audioEncoder) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_003, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoder audioEncoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, audioEncoder); + EXPECT_TRUE(audioEncoder.name.empty()); + + jsonObject[NAME] = "ffmpegAuEnc_aac"; + FromJson(jsonObject, audioEncoder); + EXPECT_EQ("ffmpegAuEnc_aac", audioEncoder.name); + EXPECT_TRUE(audioEncoder.ins.empty()); + + AudioEncoderIn audioEncoderIn; + audioEncoderIn.mime = "audio/raw"; + audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350}; + audioEncoder.ins.push_back(audioEncoderIn); + FromJson(jsonObject, audioEncoder); + EXPECT_FALSE(audioEncoder.ins.empty()); + EXPECT_TRUE(audioEncoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_004 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioDecoderIn &audioDecoderIn) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_004, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoderIn audioDecoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioDecoderIn); + EXPECT_TRUE(audioDecoderIn.mime.empty()); + + jsonObject[MIME] = "audio/mp4a-latm"; + FromJson(jsonObject, audioDecoderIn); + EXPECT_EQ("audio/mp4a-latm", audioDecoderIn.mime); + EXPECT_TRUE(audioDecoderIn.channel_layout.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_005 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioDecoderOut &audioDecoderOut) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_005, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoderOut audioDecoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, audioDecoderOut); + EXPECT_TRUE(audioDecoderOut.mime.empty()); + + jsonObject[MIME] = "audio/raw"; + FromJson(jsonObject, audioDecoderOut); + EXPECT_EQ("audio/raw", audioDecoderOut.mime); + EXPECT_TRUE(audioDecoderOut.sample_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_006 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, AudioDecoder &audioDecoder) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_006, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoder audioDecoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, audioDecoder); + EXPECT_TRUE(audioDecoder.name.empty()); + + jsonObject[NAME] = "ffmpegAuDec_aac"; + FromJson(jsonObject, audioDecoder); + EXPECT_EQ("ffmpegAuDec_aac", audioDecoder.name); + EXPECT_TRUE(audioDecoder.ins.empty()); + + AudioDecoderIn audioDecoderIn; + audioDecoderIn.mime = "audio/mp4a-latm"; + audioDecoderIn.channel_layout = { + AudioChannelLayout::CH_2POINT1, + AudioChannelLayout::CH_2_1, + AudioChannelLayout::SURROUND, + }; + audioDecoder.ins.push_back(audioDecoderIn); + FromJson(jsonObject, audioDecoder); + EXPECT_FALSE(audioDecoder.ins.empty()); + EXPECT_TRUE(audioDecoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_007 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoEncoderIn &videoEncoderIn) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_007, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoderIn videoEncoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoEncoderIn); + EXPECT_TRUE(videoEncoderIn.mime.empty()); + + jsonObject[MIME] = "video/raw"; + FromJson(jsonObject, videoEncoderIn); + EXPECT_EQ("video/raw", videoEncoderIn.mime); + EXPECT_TRUE(videoEncoderIn.pixel_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_008 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoEncoderOut &videoEncoderOut) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_008, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoderOut videoEncoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoEncoderOut); + EXPECT_TRUE(videoEncoderOut.mime.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_009 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoEncoder &videoEncoder) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_009, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoder videoEncoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, videoEncoder); + EXPECT_TRUE(videoEncoder.name.empty()); + + jsonObject[NAME] = "HdiCodecAdapter.OMX.rk.video_encoder.hevc"; + FromJson(jsonObject, videoEncoder); + EXPECT_EQ("HdiCodecAdapter.OMX.rk.video_encoder.hevc", videoEncoder.name); + EXPECT_TRUE(videoEncoder.ins.empty()); + + VideoEncoderIn videoEncoderIn; + videoEncoderIn.mime = "vide/raw"; + videoEncoderIn.pixel_fmt = { + VideoPixelFormat::YUV410P, + VideoPixelFormat::RGBA, + }; + videoEncoder.ins.push_back(videoEncoderIn); + FromJson(jsonObject, videoEncoder); + EXPECT_FALSE(videoEncoder.ins.empty()); + EXPECT_TRUE(videoEncoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_010 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoDecoderIn &videoDecoderIn) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_010, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoderIn videoDecoderIn; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoDecoderIn); + EXPECT_TRUE(videoDecoderIn.mime.empty()); + + jsonObject[MIME] = "video/hevc"; + FromJson(jsonObject, videoDecoderIn); + EXPECT_EQ("video/hevc", videoDecoderIn.mime); + EXPECT_TRUE(videoDecoderIn.vd_bit_stream_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_011 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoDecoderOut &videoDecoderOut) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_011, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoderOut videoDecoderOut; + jsonObject[MIME] = 1; + FromJson(jsonObject, videoDecoderOut); + EXPECT_TRUE(videoDecoderOut.mime.empty()); + + jsonObject[MIME] = "video/raw"; + FromJson(jsonObject, videoDecoderOut); + EXPECT_EQ("video/raw", videoDecoderOut.mime); + EXPECT_TRUE(videoDecoderOut.pixel_fmt.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_012 + * @tc.desc: Verify the FromJson(const nlohmann::json &jsonObject, VideoDecoder &videoDecoder) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_012, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoder videoDecoder; + jsonObject[NAME] = 1; + FromJson(jsonObject, videoDecoder); + EXPECT_TRUE(videoDecoder.name.empty()); + + jsonObject[NAME] = "HdiCodecAdapter.OMX.rk.video_decoder.hevc"; + FromJson(jsonObject, videoDecoder); + EXPECT_EQ("HdiCodecAdapter.OMX.rk.video_decoder.hevc", videoDecoder.name); + EXPECT_TRUE(videoDecoder.ins.empty()); + + VideoDecoderIn videoDecoderIn; + videoDecoderIn.mime = "vide/avc"; + videoDecoderIn.vd_bit_stream_fmt = { + VideoBitStreamFormat::AVC1, + VideoBitStreamFormat::HEVC, + }; + videoDecoder.ins.push_back(videoDecoderIn); + FromJson(jsonObject, videoDecoder); + EXPECT_FALSE(videoDecoder.ins.empty()); + EXPECT_TRUE(videoDecoder.outs.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_013 + * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_013, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioEncoder audioEncoder; + jsonObject[NAME] = "ffmpegAuEnc_aac"; + audioEncoder.name = "ffmpegAuEnc_aac"; + std::vectoraudioEncoders; + + FromJson(VIDEO_PIXEL_FMT, jsonObject, audioEncoders); + EXPECT_TRUE(audioEncoders.empty()); + + FromJson(NAME, jsonObject, audioEncoders); + EXPECT_FALSE(audioEncoders.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_014 + * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_014, TestSize.Level0) +{ + nlohmann::json jsonObject; + AudioDecoder audioDecoder; + jsonObject[NAME] = "ffmpegAuDec_aac"; + audioDecoder.name = "ffmpegAuDec_aac"; + std::vectoraudioDecoders; + + FromJson(VIDEO_PIXEL_FMT, jsonObject, audioDecoders); + EXPECT_TRUE(audioDecoders.empty()); + + FromJson(NAME, jsonObject, audioDecoders); + EXPECT_FALSE(audioDecoders.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_015 + * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_015, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoEncoder videoEncoder; + jsonObject[NAME] = "HdiCodecAdapter.OMX.rk.video_encoder.hevc"; + videoEncoder.name = "HdiCodecAdapter.OMX.rk.video_encoder.hevc"; + std::vectorvideoEncoders; + + FromJson(AUDIO_AAC_PROFILE, jsonObject, videoEncoders); + EXPECT_TRUE(videoEncoders.empty()); + + FromJson(NAME, jsonObject, videoEncoders); + EXPECT_FALSE(videoEncoders.empty()); +} + +/** + * @tc.name: histreamer_ability_parser_test_016 + * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.type: FUNC + * @tc.require: issuelI7MJPJ + */ +HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_016, TestSize.Level0) +{ + nlohmann::json jsonObject; + VideoDecoder videoDecoder; + jsonObject[NAME] = "HdiCodecAdapter.OMX.rk.video_decoder.hevc"; + videoDecoder.name = "HdiCodecAdapter.OMX.rk.video_decoder.hevc"; + std::vectorvideoDecoders; + + FromJson(AUDIO_AAC_PROFILE, jsonObject, videoDecoders); + EXPECT_TRUE(videoDecoders.empty()); + + FromJson(NAME, jsonObject, videoDecoders); + EXPECT_FALSE(videoDecoders.empty()); +} + +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.h b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.h new file mode 100644 index 00000000..65d7279d --- /dev/null +++ b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_HISTREAMER_ABILITY_PARSER_TEST_H +#define OHOS_DISTRIBUTED_HARDWARE_HISTREAMER_ABILITY_PARSER_TEST_H + +#include "histreamer_ability_parser.h" +#include "nlohmann/json.hpp" +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class HistreamerAbilityParserTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file -- Gitee From 019a09aeca33e57c13cdc18403740595eacbe638 Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 16:43:10 +0800 Subject: [PATCH 12/13] edit UT Signed-off-by: chenshuo --- .../src/histreamer_ability_querier_test.cpp | 39 +++++++++++-------- .../histreamer_ability_parser_test.cpp | 19 +++++---- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp index f6a04a0e..5f0e72a6 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp @@ -34,7 +34,7 @@ void HistreamerAbilityQuerierTest::SetUp() {} void HistreamerAbilityQuerierTest::TearDown() {} namespace { -int32_t MAX_MESSAGES_LEN = 1 * 1024 * 1024; +int32_t g_maxMessagesLen = 1 * 1024 * 1024; static const std::uint16_t NUM = 1; static const std::string KEY = "key"; static const std::string NAME = "name"; @@ -98,7 +98,8 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_003, Test std::vector videoEncoders = QueryVideoEncoderAbility(); EXPECT_FALSE(videoEncoders.empty() || videoEncoders.size() > 4); for (std::uint16_t i = 0; i < videoEncoders.size(); i++) { - EXPECT_TRUE(find(VIDEO_ENCODER_WANT.begin(), VIDEO_ENCODER_WANT.end(), videoEncoders[i].name) != VIDEO_ENCODER_WANT.end()); + auto it = find(VIDEO_ENCODER_WANT.begin(), VIDEO_ENCODER_WANT.end(), videoEncoders[i].name); + EXPECT_TRUE(it != VIDEO_ENCODER_WANT.end()); } } @@ -114,7 +115,8 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_004, Test std::vector videoDecoders = QueryVideoDecoderAbility(); EXPECT_FALSE(videoDecoders.empty() || videoDecoders.size() > 4); for (std::uint16_t i = 0; i < videoDecoders.size(); i++) { - EXPECT_TRUE(find(VIDEO_DECODER_WANT.begin(), VIDEO_DECODER_WANT.end(), videoDecoders[i].name) != VIDEO_DECODER_WANT.end()); + auto it = find(VIDEO_DECODER_WANT.begin(), VIDEO_DECODER_WANT.end(), videoDecoders[i].name); + EXPECT_TRUE(it != VIDEO_DECODER_WANT.end()); } } @@ -126,9 +128,9 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_004, Test */ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_005, TestSize.Level0) { - char* RES_MAX = new char[MAX_MESSAGES_LEN]; + char* RES_MAX = new char[g_maxMessagesLen]; EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) >= 0); - EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + EXPECT_TRUE(QueryAudioEncoderAbilityStr(RES_MAX) <= g_maxMessagesLen); delete[] RES_MAX; } @@ -140,9 +142,9 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_005, Test */ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_006, TestSize.Level0) { - char* RES_MAX = new char[MAX_MESSAGES_LEN]; + char* RES_MAX = new char[g_maxMessagesLen]; EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) >= 0); - EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + EXPECT_TRUE(QueryAudioDecoderAbilityStr(RES_MAX) <= g_maxMessagesLen); delete[] RES_MAX; } @@ -154,9 +156,9 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_006, Test */ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_007, TestSize.Level0) { - char* RES_MAX = new char[MAX_MESSAGES_LEN]; + char* RES_MAX = new char[g_maxMessagesLen]; EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) >= 0); - EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + EXPECT_TRUE(QueryVideoEncoderAbilityStr(RES_MAX) <= g_maxMessagesLen); delete[] RES_MAX; } @@ -168,9 +170,9 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_007, Test */ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_008, TestSize.Level0) { - char* RES_MAX = new char[MAX_MESSAGES_LEN]; + char* RES_MAX = new char[g_maxMessagesLen]; EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) >= 0); - EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) <= MAX_MESSAGES_LEN); + EXPECT_TRUE(QueryVideoDecoderAbilityStr(RES_MAX) <= g_maxMessagesLen); delete[] RES_MAX; } @@ -199,7 +201,7 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_009, Test HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_010, TestSize.Level0) { nlohmann::json jsonObject; - const uint8_t num_s = 1; + const uint8_t num_s = 1; jsonObject[KEY] = num_s; EXPECT_TRUE(IsUInt8(jsonObject, KEY)); @@ -258,12 +260,12 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_013, Test jsonObject[MIME] = "audio/mp4a-latm"; jsonObject[AD_MPEG_VER] = "hello"; FromJson(jsonObject, audioEncoderOut); - EXPECT_EQ("audio/mp4a-latm", audioEncoderOut.mime); + EXPECT_EQ("audio/mp4a-latm", audioEncoderOut.mime); jsonObject[AD_MPEG_VER] = (uint32_t)4; jsonObject[AUDIO_AAC_PROFILE] = "hello"; FromJson(jsonObject, audioEncoderOut); - EXPECT_EQ(4, (uint32_t)audioEncoderOut.ad_mpeg_ver); + EXPECT_EQ(4, (uint32_t)audioEncoderOut.ad_mpeg_ver); jsonObject[AUDIO_AAC_PROFILE] = 0; jsonObject[AUDIO_AAC_STREAM_FORMAT] = "hello"; @@ -292,7 +294,10 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_014, Test AudioEncoderIn audioEncoderIn; audioEncoderIn.mime = "audio/raw"; - audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350}; + audioEncoderIn.sample_rate = { + 96000, 88200, 64000, 48000, 44100, 32000, + 22050, 16000, 12000, 11025, 8000, 7350,24000 + }; audioEncoder.ins.push_back(audioEncoderIn); FromJson(jsonObject, audioEncoder); EXPECT_FALSE(audioEncoder.ins.empty()); @@ -333,10 +338,10 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_016, Test FromJson(jsonObject, audioDecoderOut); EXPECT_TRUE(audioDecoderOut.mime.empty()); - jsonObject[MIME] = "audio/raw"; + jsonObject[MIME] = "audio/raw"; FromJson(jsonObject, audioDecoderOut); EXPECT_EQ("audio/raw", audioDecoderOut.mime); - EXPECT_TRUE(audioDecoderOut.sample_fmt.empty()); + EXPECT_TRUE(audioDecoderOut.sample_fmt.empty()); } /** diff --git a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp index 5280a441..70f0e179 100644 --- a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp +++ b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp @@ -71,12 +71,12 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_002, TestSi jsonObject[MIME] = "audio/mp4a-latm"; jsonObject[AD_MPEG_VER] = "hello"; FromJson(jsonObject, audioEncoderOut); - EXPECT_EQ("audio/mp4a-latm", audioEncoderOut.mime); + EXPECT_EQ("audio/mp4a-latm", audioEncoderOut.mime); jsonObject[AD_MPEG_VER] = (uint32_t)4; jsonObject[AUDIO_AAC_PROFILE] = "hello"; FromJson(jsonObject, audioEncoderOut); - EXPECT_EQ(4, (uint32_t)audioEncoderOut.ad_mpeg_ver); + EXPECT_EQ(4, (uint32_t)audioEncoderOut.ad_mpeg_ver); jsonObject[AUDIO_AAC_PROFILE] = 0; jsonObject[AUDIO_AAC_STREAM_FORMAT] = "hello"; @@ -105,7 +105,10 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_003, TestSi AudioEncoderIn audioEncoderIn; audioEncoderIn.mime = "audio/raw"; - audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350}; + audioEncoderIn.sample_rate = { + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000, 7350 + }; audioEncoder.ins.push_back(audioEncoderIn); FromJson(jsonObject, audioEncoder); EXPECT_FALSE(audioEncoder.ins.empty()); @@ -146,7 +149,7 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_005, TestSi FromJson(jsonObject, audioDecoderOut); EXPECT_TRUE(audioDecoderOut.mime.empty()); - jsonObject[MIME] = "audio/raw"; + jsonObject[MIME] = "audio/raw"; FromJson(jsonObject, audioDecoderOut); EXPECT_EQ("audio/raw", audioDecoderOut.mime); EXPECT_TRUE(audioDecoderOut.sample_fmt.empty()); @@ -323,7 +326,7 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_012, TestSi /** * @tc.name: histreamer_ability_parser_test_013 - * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.desc: Verify the FromJson function * @tc.type: FUNC * @tc.require: issuelI7MJPJ */ @@ -344,7 +347,7 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_013, TestSi /** * @tc.name: histreamer_ability_parser_test_014 - * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.desc: Verify the FromJson function * @tc.type: FUNC * @tc.require: issuelI7MJPJ */ @@ -365,7 +368,7 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_014, TestSi /** * @tc.name: histreamer_ability_parser_test_015 - * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.desc: Verify the FromJson function * @tc.type: FUNC * @tc.require: issuelI7MJPJ */ @@ -386,7 +389,7 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_015, TestSi /** * @tc.name: histreamer_ability_parser_test_016 - * @tc.desc: Verify the FromJson(const std::string &key, const nlohmann::json &jsonObject, std::vector &objs) function + * @tc.desc: Verify the FromJson function * @tc.type: FUNC * @tc.require: issuelI7MJPJ */ -- Gitee From 619a3b012fde3e1e1c185a4d3261827a4851513f Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 21 Jul 2023 17:09:21 +0800 Subject: [PATCH 13/13] edit ut Signed-off-by: chenshuo --- .../unittest/common/src/histreamer_ability_querier_test.cpp | 5 +---- .../histreamer_ability_parser_test.cpp | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp index 5f0e72a6..3da6be10 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp +++ b/av_transport/av_trans_handler/histreamer_ability_querier/test/unittest/common/src/histreamer_ability_querier_test.cpp @@ -294,10 +294,7 @@ HWTEST_F(HistreamerAbilityQuerierTest, histreamer_ability_querier_test_014, Test AudioEncoderIn audioEncoderIn; audioEncoderIn.mime = "audio/raw"; - audioEncoderIn.sample_rate = { - 96000, 88200, 64000, 48000, 44100, 32000, - 22050, 16000, 12000, 11025, 8000, 7350,24000 - }; + audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000}; audioEncoder.ins.push_back(audioEncoderIn); FromJson(jsonObject, audioEncoder); EXPECT_FALSE(audioEncoder.ins.empty()); diff --git a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp index 70f0e179..d3bfea9b 100644 --- a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp +++ b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp @@ -105,10 +105,7 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_003, TestSi AudioEncoderIn audioEncoderIn; audioEncoderIn.mime = "audio/raw"; - audioEncoderIn.sample_rate = { - 96000, 88200, 64000, 48000, 44100, 32000, - 24000, 22050, 16000, 12000, 11025, 8000, 7350 - }; + audioEncoderIn.sample_rate = {96000, 88200, 64000, 48000, 44100, 32000}; audioEncoder.ins.push_back(audioEncoderIn); FromJson(jsonObject, audioEncoder); EXPECT_FALSE(audioEncoder.ins.empty()); -- Gitee