From 23ed262f77430d56a61c2bd1ee0eeff69ee17037 Mon Sep 17 00:00:00 2001 From: duyulu <784928376@qq.com> Date: Wed, 27 Nov 2024 20:29:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E7=BC=96=E8=BE=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0UT=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: duyulu <784928376@qq.com> --- .../base/shader_pass/shader_pass_rotate.cpp | 8 +- .../video_editor/test/unittest/BUILD.gn | 2 + .../video_decoder_engine_impl_test.cpp | 80 ++++ .../video_encoder_engine_impl_test.cpp | 367 ++++++++++++++++-- .../encoder/video_encoder_engine_test.cpp | 8 +- .../video/encoder/video_encoder_test.cpp | 10 + .../codec/video/encoder/video_muxer_test.cpp | 21 +- .../render/base/shader_pass_rotate_test.cpp | 72 ++++ .../render/base/shader_pass_surface_test.cpp | 71 ++++ .../graphics_render_engine_impl_test.cpp | 25 +- .../test/unittest/ut_common_data.h | 19 + .../test/unittest/video_editor_impl_test.cpp | 5 + test/unittest/resources/ohos_test.xml | 15 +- 13 files changed, 655 insertions(+), 48 deletions(-) create mode 100644 frameworks/native/video_editor/test/unittest/render/base/shader_pass_rotate_test.cpp create mode 100644 frameworks/native/video_editor/test/unittest/render/base/shader_pass_surface_test.cpp diff --git a/frameworks/native/video_editor/render/graphics/base/shader_pass/shader_pass_rotate.cpp b/frameworks/native/video_editor/render/graphics/base/shader_pass/shader_pass_rotate.cpp index c132c7bb1..2be169e94 100644 --- a/frameworks/native/video_editor/render/graphics/base/shader_pass/shader_pass_rotate.cpp +++ b/frameworks/native/video_editor/render/graphics/base/shader_pass/shader_pass_rotate.cpp @@ -62,10 +62,14 @@ SurfaceDataPtr ShaderPassRotate::GetRenderEffectData() void ShaderPassRotate::PreDraw() { SurfaceDataPtr surfaceData = std::static_pointer_cast(renderEffectData_); - if (shader_) { + if (shader_ == nullptr || surfaceData == nullptr) { + MEDIA_LOGE("ShaderPassRotate::PreDraw failed because the shader or surfaceData is nullptr."); + return; + } + if (surfaceData->inputTexture_ != nullptr) { shader_->BindTexture("sTexture", 0, surfaceData->inputTexture_->GetTextureId()); - shader_->SetMat4("uTexMatrix", surfaceData->uTexMatrix); } + shader_->SetMat4("uTexMatrix", surfaceData->uTexMatrix); } void ShaderPassRotate::PostDraw() diff --git a/frameworks/native/video_editor/test/unittest/BUILD.gn b/frameworks/native/video_editor/test/unittest/BUILD.gn index 89a672055..114ce727f 100644 --- a/frameworks/native/video_editor/test/unittest/BUILD.gn +++ b/frameworks/native/video_editor/test/unittest/BUILD.gn @@ -97,6 +97,8 @@ ohos_unittest("video_editor_unit_test") { "render/base/render_context_test.cpp", "render/base/render_surface_test.cpp", "render/base/shader_pass_on_screen_test.cpp", + "render/base/shader_pass_rotate_test.cpp", + "render/base/shader_pass_surface_test.cpp", "render/effect/image_effect_render_test.cpp", "render/render_engine/graphics_render_engine_impl_test.cpp", "render/render_engine/graphics_render_engine_test.cpp", diff --git a/frameworks/native/video_editor/test/unittest/codec/video/decoder/video_decoder_engine_impl_test.cpp b/frameworks/native/video_editor/test/unittest/codec/video/decoder/video_decoder_engine_impl_test.cpp index 50e5e58db..3ca9ea34c 100755 --- a/frameworks/native/video_editor/test/unittest/codec/video/decoder/video_decoder_engine_impl_test.cpp +++ b/frameworks/native/video_editor/test/unittest/codec/video/decoder/video_decoder_engine_impl_test.cpp @@ -139,6 +139,16 @@ HWTEST_F(VideoDecoderEngineImplTest, OnVideoDecodeResult_ok, TestSize.Level0) (void)close(srcFd); } +HWTEST_F(VideoDecoderEngineImplTest, OnVideoDecodeResult_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(1, srcFd, nullptr); + engine->OnVideoDecoderFrame(80); + ASSERT_EQ(engine->cb_, nullptr); + (void)close(srcFd); +} + HWTEST_F(VideoDecoderEngineImplTest, OnVideoDecodeResult_success, TestSize.Level0) { std::string fileName = "H264_AAC.mp4"; @@ -164,6 +174,22 @@ HWTEST_F(VideoDecoderEngineImplTest, GetVideoDuration_ok, TestSize.Level0) (void)close(srcFd); } +HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_GetVideoDuration_error, TestSize.Level0) +{ + VideoDecodeCallbackTester* cb = new VideoDecodeCallbackTester(); + auto engine = std::make_shared(1, 1, cb); + EXPECT_EQ(engine->InitDeMuxer(), VEFError::ERR_INTERNAL_ERROR); + EXPECT_EQ(engine->GetVideoDuration(), -1); +} + +HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_GetRotation_zero, TestSize.Level0) +{ + VideoDecodeCallbackTester* cb = new VideoDecodeCallbackTester(); + auto engine = std::make_shared(1, 1, cb); + EXPECT_EQ(engine->InitDeMuxer(), VEFError::ERR_INTERNAL_ERROR); + EXPECT_EQ(engine->GetRotation(), 0); +} + HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_StartDecode, TestSize.Level0) { std::string fileName = "H264_AAC_multi_track.mp4"; @@ -175,6 +201,30 @@ HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_StartDecode, TestSiz (void)close(srcFd); } +HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_StartDecode_audioDecoder_not_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + VideoDecodeCallbackTester* cb = new VideoDecodeCallbackTester(); + auto engine = std::make_shared(1, srcFd, cb); + EXPECT_EQ(engine->Init(), VEFError::ERR_OK); + engine->videoDecoder_->decoder_ = nullptr; + EXPECT_EQ(engine->StartDecode(), VEFError::ERR_INTERNAL_ERROR); + (void)close(srcFd); +} + +HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_StartDecode_audioDecoder_decoder_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + VideoDecodeCallbackTester* cb = new VideoDecodeCallbackTester(); + auto engine = std::make_shared(1, srcFd, cb); + EXPECT_EQ(engine->Init(), VEFError::ERR_OK); + engine->audioDecoder_->decoder_ = nullptr; + EXPECT_EQ(engine->StartDecode(), VEFError::ERR_INTERNAL_ERROR); + (void)close(srcFd); +} + HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_StopDecode, TestSize.Level0) { std::string fileName = "H264_AAC_multi_track.mp4"; @@ -272,5 +322,35 @@ HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_ReadAudioPacket, Tes (void)close(srcFd); OH_AVMemory_Destroy(sampleMem); } + +HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_ReadAudioPacket_err, TestSize.Level0) +{ + VideoDecodeCallbackTester* deCb = new VideoDecodeCallbackTester(); + auto decoderEngine = std::make_shared(1, 1, deCb); + EXPECT_EQ(decoderEngine->InitDeMuxer(), VEFError::ERR_INTERNAL_ERROR); + uint32_t buffersize = 1024 * 1024; + OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); + OH_AVCodecBufferAttr attr; + attr.size = 1024 * 1024; + attr.pts = 100; + attr.flags = 1; + EXPECT_EQ(decoderEngine->ReadAudioPacket(sampleMem, &attr), VEFError::ERR_INTERNAL_ERROR); + OH_AVMemory_Destroy(sampleMem); +} + +HWTEST_F(VideoDecoderEngineImplTest, VideoDecoderEngineImpl_ReadVideoPacket_err, TestSize.Level0) +{ + VideoDecodeCallbackTester* deCb = new VideoDecodeCallbackTester(); + auto decoderEngine = std::make_shared(1, 1, deCb); + EXPECT_EQ(decoderEngine->InitDeMuxer(), VEFError::ERR_INTERNAL_ERROR); + uint32_t buffersize = 1024 * 1024; + OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); + OH_AVCodecBufferAttr attr; + attr.size = 1024 * 1024; + attr.pts = 100; + attr.flags = 1; + EXPECT_EQ(decoderEngine->ReadVideoPacket(sampleMem, &attr), VEFError::ERR_INTERNAL_ERROR); + OH_AVMemory_Destroy(sampleMem); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_impl_test.cpp b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_impl_test.cpp index 2e67f8722..1c0d9c63d 100755 --- a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_impl_test.cpp +++ b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_impl_test.cpp @@ -15,6 +15,8 @@ #include "gtest/gtest.h" #include "codec/video/encoder/video_encoder_engine_impl.h" +#include "codec/video/decoder/video_decoder_engine_impl.h" +#include "render/graphics/render_engine/graphics_render_engine_impl.h" #include "composite_engine/impl/video_composite_engine.h" #include #include @@ -31,26 +33,38 @@ class VideoEncoderEngineImplTest : public testing::Test { protected: void SetUp() override { + cb_ = new VideoEncodeCallbackTester(); + deCb_ = new VideoDecodeCallbackTester(); } void TearDown() override { + if (cb_ != nullptr) { + delete cb_; + cb_ = nullptr; + } + if (deCb_ != nullptr) { + delete deCb_; + deCb_ = nullptr; + } } + +private: + VideoEncodeCallbackTester* cb_ = nullptr; + VideoDecodeCallbackTester* deCb_ = nullptr; }; // Test VideoEncoderEngineImpl constructor HWTEST_F(VideoEncoderEngineImplTest, construct, TestSize.Level0) { - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(20, cb); + auto engine = std::make_shared(20, cb_); EXPECT_EQ(engine->GetId(), 20); } // Test VideoEncoderEngineImpl Init method HWTEST_F(VideoEncoderEngineImplTest, init_error, TestSize.Level0) { - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(20, cb); + auto engine = std::make_shared(20, cb_); VideoEncodeParam enCoderParam; EXPECT_EQ(engine->Init(enCoderParam), VEFError::ERR_INTERNAL_ERROR); } @@ -66,11 +80,9 @@ HWTEST_F(VideoEncoderEngineImplTest, init_ok, TestSize.Level0) EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); VideoEncodeParam enCoderParam; EXPECT_EQ(videoCompositeEngine->BuildEncoderParameter(enCoderParam), VEFError::ERR_OK); - VideoDecodeCallbackTester* deCb = new VideoDecodeCallbackTester(); - auto decoderEngine = IVideoDecoderEngine::Create(srcFd, deCb); + auto decoderEngine = IVideoDecoderEngine::Create(srcFd, deCb_); VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, decoderEngine); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); EXPECT_EQ(engine->Init(enCoderParam), VEFError::ERR_INTERNAL_ERROR); EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); (void)close(srcFd); @@ -85,11 +97,9 @@ HWTEST_F(VideoEncoderEngineImplTest, StartEncode_ok, TestSize.Level0) ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); - VideoDecodeCallbackTester* deCb = new VideoDecodeCallbackTester(); - auto decoderEngine = IVideoDecoderEngine::Create(srcFd, deCb); + auto decoderEngine = IVideoDecoderEngine::Create(srcFd, deCb_); VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, decoderEngine); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); EXPECT_EQ(engine->StartEncode(), VEFError::ERR_OK); EXPECT_EQ(engine->StopEncode(), VEFError::ERR_OK); @@ -105,11 +115,9 @@ HWTEST_F(VideoEncoderEngineImplTest, UnInit_ok, TestSize.Level0) ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); - VideoDecodeCallbackTester* decodeCallback = new VideoDecodeCallbackTester(); - auto decoderEng = IVideoDecoderEngine::Create(srcFd, decodeCallback); + auto decoderEng = IVideoDecoderEngine::Create(srcFd, deCb_); VideoEncodeParam params = VideoResource::instance().getEncodeParam(srcFd, decoderEng); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); EXPECT_EQ(engine->Init(params), VEFError::ERR_OK); engine->UnInit(); EXPECT_EQ(engine->encoder_, nullptr); @@ -125,11 +133,9 @@ HWTEST_F(VideoEncoderEngineImplTest, Flush_ok, TestSize.Level0) ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); - VideoDecodeCallbackTester* decoderCb = new VideoDecodeCallbackTester(); - auto deEngine = IVideoDecoderEngine::Create(srcFd, decoderCb); + auto deEngine = IVideoDecoderEngine::Create(srcFd, deCb_); VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, deEngine); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); EXPECT_EQ(engine->Flush(), VEFError::ERR_INTERNAL_ERROR); (void)close(srcFd); @@ -144,11 +150,9 @@ HWTEST_F(VideoEncoderEngineImplTest, SendEos_ok, TestSize.Level0) ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); - VideoDecodeCallbackTester* deCallback = new VideoDecodeCallbackTester(); - auto decoEng = IVideoDecoderEngine::Create(srcFd, deCallback); + auto decoEng = IVideoDecoderEngine::Create(srcFd, deCb_); VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, decoEng); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); EXPECT_EQ(engine->SendEos(), VEFError::ERR_INTERNAL_ERROR); (void)close(srcFd); @@ -158,8 +162,7 @@ HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImplTest_OnEncodeResult, { std::string fileName = "H264_AAC.mp4"; int32_t srcFd = VideoResource::instance().getFileResource(fileName); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); CodecResult result = CodecResult::SUCCESS; engine->OnEncodeResult(result); engine->videoEncoderState_ = CodecState::FINISH_SUCCESS; @@ -177,8 +180,7 @@ HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImplTest_OnVideoNewOutput { std::string fileName = "H264_AAC.mp4"; int32_t srcFd = VideoResource::instance().getFileResource(fileName); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); uint32_t buffersize = 1024 * 1024; OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); OH_AVCodecBufferAttr attr; @@ -192,17 +194,88 @@ HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImplTest_OnVideoNewOutput engine->OnVideoNewOutputDataCallBack(sampleMem, nullptr); engine->OnVideoNewOutputDataCallBack(nullptr, &attr); engine->OnVideoNewOutputDataCallBack(sampleMem, &attr); + + OH_AVCodecBufferAttr attr1; + attr1.size = 1024 * 1024; + attr1.pts = 100; + attr1.flags = 1; + engine->OnVideoNewOutputDataCallBack(sampleMem, &attr1); + EXPECT_EQ(engine->videoEncoderState_, CodecState::FINISH_SUCCESS); + (void)close(srcFd); + OH_AVMemory_Destroy(sampleMem); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnVideoNewOutputDataCallBack_with_muxer_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(srcFd, cb_); + uint32_t buffersize = 1024 * 1024; + OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); + OH_AVCodecBufferAttr attr; + attr.size = 1024 * 1024; + attr.pts = 100; + attr.flags = 0; + engine->OnVideoNewOutputDataCallBack(sampleMem, &attr); + EXPECT_EQ(engine->videoEncoderState_, CodecState::INIT); + (void)close(srcFd); + OH_AVMemory_Destroy(sampleMem); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnVideoNewOutputDataCallBack_with_cb_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(srcFd, nullptr); + uint32_t buffersize = 1024 * 1024; + OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); + OH_AVCodecBufferAttr attr; + attr.size = 1024 * 1024; + attr.pts = 100; + attr.flags = 1; + VideoMuxerParam muxerParam; + muxerParam.targetFileFd = srcFd; + EXPECT_EQ(engine->InitVideoMuxer(muxerParam), VEFError::ERR_OK); + engine->OnVideoNewOutputDataCallBack(sampleMem, &attr); EXPECT_EQ(engine->videoEncoderState_, CodecState::INIT); (void)close(srcFd); OH_AVMemory_Destroy(sampleMem); } +HWTEST_F(VideoEncoderEngineImplTest, OnVideoNewOutputDataCallBack_with_cb_not_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(srcFd, cb_); + uint32_t buffersize = 1024 * 1024; + OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); + OH_AVCodecBufferAttr attr; + attr.size = 1024 * 1024; + attr.pts = 100; + attr.flags = 1; + VideoMuxerParam muxerParam; + muxerParam.targetFileFd = srcFd; + EXPECT_EQ(engine->InitVideoMuxer(muxerParam), VEFError::ERR_OK); + engine->OnVideoNewOutputDataCallBack(sampleMem, &attr); + EXPECT_EQ(engine->videoEncoderState_, CodecState::FINISH_SUCCESS); + + OH_AVCodecBufferAttr attr1; + attr1.size = 1024 * 1024; + attr1.pts = 100; + attr1.flags = 0; + auto engine1 = std::make_shared(srcFd, cb_); + EXPECT_EQ(engine1->InitVideoMuxer(muxerParam), VEFError::ERR_OK); + engine1->OnVideoNewOutputDataCallBack(sampleMem, &attr1); + EXPECT_EQ(engine1->videoEncoderState_, CodecState::INIT); + (void)close(srcFd); + OH_AVMemory_Destroy(sampleMem); +} + HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImplTest_OnAudioEncodeOutput, TestSize.Level0) { std::string fileName = "H264_AAC.mp4"; int32_t srcFd = VideoResource::instance().getFileResource(fileName); - VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); - auto engine = std::make_shared(srcFd, cb); + auto engine = std::make_shared(srcFd, cb_); uint32_t buffersize = 1024 * 1024; OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); OH_AVCodecBufferAttr attr; @@ -223,5 +296,239 @@ HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImplTest_OnAudioEncodeOut OH_AVMemory_Destroy(sampleMem); OH_VideoEncoder_Destroy(codec); } + +HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImpl_InitAudioStreamEncoder, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(srcFd, cb_); + EXPECT_EQ(engine->InitAudioStreamEncoder(nullptr), VEFError::ERR_OK); + (void)close(srcFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImpl_Init_with_format_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(srcFd, cb_); + VideoEncodeParam enCodeParam; + enCodeParam.videoTrunkFormat = nullptr; + enCodeParam.audioTrunkFormat = nullptr; + enCodeParam.muxerParam.targetFileFd = srcFd; + enCodeParam.muxerParam.avOutputFormat = AV_OUTPUT_FORMAT_MPEG_4; + enCodeParam.muxerParam.rotation = 90; + EXPECT_EQ(engine->Init(enCodeParam), VEFError::ERR_INTERNAL_ERROR); + (void)close(srcFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImpl_StartEncode_muxer_error, TestSize.Level0) +{ + std::string fileName = "H264_AAC_multi_track.mp4"; + int32_t fileFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(12); + auto dataCenter = IDataCenter::Create(); + ASSERT_EQ(dataCenter->AppendVideo(fileFd, WATER_MARK_DESC), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); + auto deEngine = IVideoDecoderEngine::Create(fileFd, deCb_); + VideoEncodeParam param = VideoResource::instance().getEncodeParam(fileFd, deEngine); + auto enEngine = std::make_shared(fileFd, cb_); + EXPECT_EQ(enEngine->Init(param), VEFError::ERR_OK); + enEngine->muxer_->muxer_ = nullptr; + EXPECT_EQ(enEngine->StartEncode(), VEFError::ERR_INTERNAL_ERROR); + (void)close(fileFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImpl_StartEncode_encoder_error, TestSize.Level0) +{ + std::string fileName = "H264_AAC_320x240.mp4"; + int32_t aacFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(12); + auto dataCenter = IDataCenter::Create(); + ASSERT_EQ(dataCenter->AppendVideo(aacFd, WATER_MARK_DESC), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); + auto deEngine = IVideoDecoderEngine::Create(aacFd, deCb_); + VideoEncodeParam param = VideoResource::instance().getEncodeParam(aacFd, deEngine); + auto engine = std::make_shared(aacFd, cb_); + EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); + engine->encoder_->encoder_ = nullptr; + EXPECT_EQ(engine->StartEncode(), VEFError::ERR_INTERNAL_ERROR); + (void)close(aacFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImpl_StartEncode_audioEncoder_error, TestSize.Level0) +{ + std::string fileName = "ChineseColor_H264_AAC_480p_15fps.mp4"; + int32_t aacFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(12); + auto dataCenter = IDataCenter::Create(); + ASSERT_EQ(dataCenter->AppendVideo(aacFd, WATER_MARK_DESC), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); + auto deEngine = IVideoDecoderEngine::Create(aacFd, deCb_); + VideoEncodeParam param = VideoResource::instance().getEncodeParam(aacFd, deEngine); + auto engine = std::make_shared(aacFd, cb_); + EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); + engine->audioEncoder_ = nullptr; + EXPECT_EQ(engine->StartEncode(), VEFError::ERR_OK); + (void)close(aacFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, VideoEncoderEngineImpl_SendEos_error, TestSize.Level0) +{ + std::string fileName = "ChineseColor_H264_AAC_480p_15fps.mp4"; + int32_t aacFd = VideoResource::instance().getFileResource(fileName); + auto engine = std::make_shared(aacFd, cb_); + EXPECT_EQ(engine->SendEos(), VEFError::ERR_INTERNAL_ERROR); + (void)close(aacFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, Flush_audioEncoder_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC_multi_track.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(36); + auto dataCenter = IDataCenter::Create(); + ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); + auto deEngine = IVideoDecoderEngine::Create(srcFd, deCb_); + VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, deEngine); + auto engine = std::make_shared(srcFd, cb_); + EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); + engine->audioEncoder_->encoder_ = nullptr; + EXPECT_EQ(engine->StopEncode(), VEFError::ERR_INTERNAL_ERROR); + engine->audioEncoder_ = nullptr; + EXPECT_EQ(engine->Flush(), VEFError::ERR_INTERNAL_ERROR); + EXPECT_EQ(engine->StopEncode(), VEFError::ERR_INTERNAL_ERROR); + (void)close(srcFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, Flush_encoder_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC_multi_track.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(36); + auto dataCenter = IDataCenter::Create(); + ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); + auto deEngine = IVideoDecoderEngine::Create(srcFd, deCb_); + VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, deEngine); + auto engine = std::make_shared(srcFd, cb_); + EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); + engine->muxer_->muxer_ = nullptr; + EXPECT_EQ(engine->StopEncode(), VEFError::ERR_INTERNAL_ERROR); + engine->audioEncoder_ = nullptr; + engine->encoder_ = nullptr; + EXPECT_EQ(engine->Flush(), VEFError::ERR_INTERNAL_ERROR); + (void)close(srcFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnAudioEncodeOutput_encoder_not_nullptr, TestSize.Level0) +{ + std::string fileName = "H264_AAC_multi_track.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(36); + auto dataCenter = IDataCenter::Create(); + ASSERT_EQ(dataCenter->AppendVideo(srcFd, WATER_MARK_DESC), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->Init(dataCenter), VEFError::ERR_OK); + EXPECT_EQ(videoCompositeEngine->OrchestratePipelines(), VEFError::ERR_INTERNAL_ERROR); + auto deEngine = IVideoDecoderEngine::Create(srcFd, deCb_); + VideoEncodeParam param = VideoResource::instance().getEncodeParam(srcFd, deEngine); + auto engine = std::make_shared(srcFd, cb_); + EXPECT_EQ(engine->Init(param), VEFError::ERR_OK); + + uint32_t buffersize = 1024 * 1024; + OH_AVMemory* sampleMem = OH_AVMemory_Create(buffersize); + OH_AVCodecBufferAttr attr; + attr.size = 1024 * 1024; + attr.pts = 100; + attr.flags = 0; + VideoMuxerParam muxerParam; + muxerParam.targetFileFd = srcFd; + EXPECT_EQ(engine->InitVideoMuxer(muxerParam), VEFError::ERR_OK); + OH_AVCodec* codec = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC); + EXPECT_EQ(engine->OnAudioEncodeOutput(codec, 1, sampleMem, &attr), VEFError::ERR_INTERNAL_ERROR); + (void)close(srcFd); + OH_AVMemory_Destroy(sampleMem); + OH_VideoEncoder_Destroy(codec); +} + +HWTEST_F(VideoEncoderEngineImplTest, StopComposite_init, TestSize.Level0) +{ + auto videoCompositeEngine = std::make_shared(12); + ASSERT_NE(videoCompositeEngine, nullptr); + videoCompositeEngine->state_ = VideoCompositeEngine::CompositeState::INIT; + ASSERT_EQ(videoCompositeEngine->StopComposite(), VEFError::ERR_OK); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnDecodeResult_canceled, TestSize.Level0) +{ + auto videoCompositeEngine = std::make_shared(9); + ASSERT_NE(videoCompositeEngine, nullptr); + CodecResult result = CodecResult::CANCELED; + videoCompositeEngine->OnDecodeResult(result); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnDecodeResult_success, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(9); + ASSERT_NE(videoCompositeEngine, nullptr); + static std::atomic codecId { 1 }; + videoCompositeEngine->taskMgr_ = std::make_shared("compositeEngine", TaskManagerTimeOpt::SEQUENTIAL); + videoCompositeEngine->decoderEngine_ = std::make_shared(codecId.fetch_add(1), srcFd, deCb_); + videoCompositeEngine->encoderEngine_ = std::make_shared(codecId.fetch_add(1), cb_); + CodecResult result = CodecResult::SUCCESS; + videoCompositeEngine->OnDecodeResult(result); + (void)close(srcFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnDecodeResult_success_1, TestSize.Level0) +{ + std::string fileName = "H264_AAC.mp4"; + int32_t srcFd = VideoResource::instance().getFileResource(fileName); + auto videoCompositeEngine = std::make_shared(9); + ASSERT_NE(videoCompositeEngine, nullptr); + static std::atomic codecId { 1 }; + videoCompositeEngine->taskMgr_ = std::make_shared("compositeEngine", TaskManagerTimeOpt::SEQUENTIAL); + videoCompositeEngine->decoderEngine_ = std::make_shared(codecId.fetch_add(1), srcFd, deCb_); + videoCompositeEngine->encoderEngine_ = std::make_shared(codecId.fetch_add(1), cb_); + CodecResult result = CodecResult::SUCCESS; + videoCompositeEngine->renderingCnt_ = 2; + videoCompositeEngine->OnDecodeResult(result); + (void)close(srcFd); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnEncodeFrame_state_init, TestSize.Level0) +{ + auto videoCompositeEngine = std::make_shared(9); + ASSERT_NE(videoCompositeEngine, nullptr); + videoCompositeEngine->state_ = VideoCompositeEngine::CompositeState::INIT; + videoCompositeEngine->OnEncodeFrame(66); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnEncodeFrame_state_compositing, TestSize.Level0) +{ + auto videoCompositeEngine = std::make_shared(9); + ASSERT_NE(videoCompositeEngine, nullptr); + videoCompositeEngine->state_ = VideoCompositeEngine::CompositeState::COMPOSITING; + videoCompositeEngine->callback_ = std::make_shared(); + videoCompositeEngine->duration_ = 0; + videoCompositeEngine->OnEncodeFrame(99); +} + +HWTEST_F(VideoEncoderEngineImplTest, OnEncodeFrame_state_compositing_1, TestSize.Level0) +{ + auto videoCompositeEngine = std::make_shared(9); + ASSERT_NE(videoCompositeEngine, nullptr); + videoCompositeEngine->state_ = VideoCompositeEngine::CompositeState::COMPOSITING; + videoCompositeEngine->callback_ = std::make_shared(); + videoCompositeEngine->duration_ = 33; + videoCompositeEngine->OnEncodeFrame(99); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_test.cpp b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_test.cpp index 6c56f7fdc..8f8c3a353 100755 --- a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_test.cpp +++ b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_engine_test.cpp @@ -37,7 +37,7 @@ protected: }; // Test when cb is nullptr then Create returns nullptr. -HWTEST_F(VideoEncoderEngineTest, create_when_cb_is_nullptr, TestSize.Level0) +HWTEST_F(VideoEncoderEngineTest, create_when_cb_is_not_nullptr, TestSize.Level0) { VideoEncodeParam enCodeParam; VideoEncodeCallbackTester* cb = new VideoEncodeCallbackTester(); @@ -54,5 +54,11 @@ HWTEST_F(VideoEncoderEngineTest, create_when_video_format_is_nullptr, TestSize.L EXPECT_EQ(engine, nullptr); } +HWTEST_F(VideoEncoderEngineTest, create_when_callback_is_nullptr, TestSize.Level0) +{ + VideoEncodeParam enCodeParam; + std::shared_ptr engine = IVideoEncoderEngine::Create(enCodeParam, nullptr); + EXPECT_EQ(engine, nullptr); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_test.cpp b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_test.cpp index 0b366c3df..5296b234c 100644 --- a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_test.cpp +++ b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_encoder_test.cpp @@ -101,6 +101,12 @@ HWTEST_F(VideoEncoderTest, VideoEncoder_ConfigureEncoder, TestSize.Level0) OH_AVFormat_Destroy(format); } +HWTEST_F(VideoEncoderTest, VideoEncoder_ConfigureEncoder_format_nullptr, TestSize.Level0) +{ + VideoEncoder videoEncoder(1, nullptr); + EXPECT_EQ(videoEncoder.ConfigureEncoder(nullptr), VEFError::ERR_INTERNAL_ERROR); +} + // test VideoEncoder CreateEncoder method HWTEST_F(VideoEncoderTest, VideoEncoder_CreateEncoder, TestSize.Level0) { @@ -174,6 +180,10 @@ HWTEST_F(VideoEncoderTest, VideoEncoder_WriteFrame, TestSize.Level0) auto encoder1 = std::make_shared(12, encoderCb); // 12 VideoEncoder构造函数入参id encoder1->codecState_ = true; EXPECT_EQ(encoder1->WriteFrame(sampleMem_, &attr), VEFError::ERR_OK); + + auto encoder2 = std::make_shared(12, nullptr); // 12 VideoEncoder构造函数入参id + encoder2->codecState_ = true; + EXPECT_EQ(encoder2->WriteFrame(sampleMem_, &attr), VEFError::ERR_OK); } } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_muxer_test.cpp b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_muxer_test.cpp index d1119d62b..be2d73a41 100644 --- a/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_muxer_test.cpp +++ b/frameworks/native/video_editor/test/unittest/codec/video/encoder/video_muxer_test.cpp @@ -29,17 +29,24 @@ protected: void SetUp() override { muxer_ = new VideoMuxer(1); + format_ = OH_AVFormat_Create(); } void TearDown() override { if (muxer_ != nullptr) { delete muxer_; + muxer_ = nullptr; + } + if (format_ != nullptr) { + OH_AVFormat_Destroy(format_); + format_ = nullptr; } - muxer_ = nullptr; } - VideoMuxer* muxer_; +private: + VideoMuxer* muxer_ = nullptr; + OH_AVFormat* format_ = nullptr; }; // test VideoMuxer Start method @@ -60,12 +67,22 @@ HWTEST_F(VideoMuxerTest, VideoMuxer_AddVideoTrack, TestSize.Level0) EXPECT_EQ(muxer_->AddVideoTrack(nullptr), VEFError::ERR_INTERNAL_ERROR); } +HWTEST_F(VideoMuxerTest, VideoMuxer_AddVideoTrack_format_not_nullptr, TestSize.Level0) +{ + EXPECT_EQ(muxer_->AddVideoTrack(format_), VEFError::ERR_INTERNAL_ERROR); +} + // test VideoMuxer AddAudioTrack method HWTEST_F(VideoMuxerTest, VideoMuxer_AddAudioTrack, TestSize.Level0) { EXPECT_EQ(muxer_->AddAudioTrack(nullptr), VEFError::ERR_INTERNAL_ERROR); } +HWTEST_F(VideoMuxerTest, VideoMuxer_AddAudioTrack_format_not_nullptr, TestSize.Level0) +{ + EXPECT_EQ(muxer_->AddAudioTrack(format_), VEFError::ERR_INTERNAL_ERROR); +} + // test VideoMuxer WriteAudioData method HWTEST_F(VideoMuxerTest, VideoMuxer_WriteAudioData, TestSize.Level0) { diff --git a/frameworks/native/video_editor/test/unittest/render/base/shader_pass_rotate_test.cpp b/frameworks/native/video_editor/test/unittest/render/base/shader_pass_rotate_test.cpp new file mode 100644 index 000000000..63b60e5b6 --- /dev/null +++ b/frameworks/native/video_editor/test/unittest/render/base/shader_pass_rotate_test.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2024 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 "gtest/gtest.h" +#include "render/graphics/base/shader_pass/shader_pass_rotate.h" +#include "render/graphics/base/shader_pass/shader_pass_program.h" +#include "render/graphics/base/shader_pass/shader_pass.h" +#include "ut_common_data.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Media { + +class ShaderPassRotateTest : public testing::Test { +protected: + void SetUp() override + { + context_ = new RenderContext(); + } + + void TearDown() override + { + if (context_ != nullptr) { + delete context_; + context_ = nullptr; + } + } + +private: + RenderContext* context_ = nullptr; +}; + +HWTEST_F(ShaderPassRotateTest, ShaderPassRotateTest_PreDraw_shade_nullptr, TestSize.Level0) +{ + auto shaderPassRotate = std::make_shared(context_); + ASSERT_NE(shaderPassRotate, nullptr); + shaderPassRotate->PreDraw(); + ASSERT_NE(shaderPassRotate->Render(), nullptr); +} + +HWTEST_F(ShaderPassRotateTest, ShaderPassRotateTest_PreDraw_shade_not_nullptr, TestSize.Level0) +{ + auto shaderPassRotate = std::make_shared(context_); + ASSERT_NE(shaderPassRotate, nullptr); + shaderPassRotate->shader_ = std::make_shared(context_, SURFACE_VERTEX_SHADER_CODE, + SURFACE_ROTATE_FRAGMENT_SHADER_CODE); + ASSERT_NE(shaderPassRotate->shader_, nullptr); + shaderPassRotate->PreDraw(); +} + +HWTEST_F(ShaderPassRotateTest, ShaderPassRotateTest_PostDraw_shade_nullptr, TestSize.Level0) +{ + auto shaderPassRotate = std::make_shared(context_); + ASSERT_NE(shaderPassRotate, nullptr); + shaderPassRotate->PostDraw(); +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/video_editor/test/unittest/render/base/shader_pass_surface_test.cpp b/frameworks/native/video_editor/test/unittest/render/base/shader_pass_surface_test.cpp new file mode 100644 index 000000000..fff95010c --- /dev/null +++ b/frameworks/native/video_editor/test/unittest/render/base/shader_pass_surface_test.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2024 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 "gtest/gtest.h" +#include "render/graphics/base/shader_pass/shader_pass_surface.h" +#include "render/graphics/base/shader_pass/shader_pass_program.h" +#include "render/graphics/base/shader_pass/shader_pass.h" +#include "ut_common_data.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Media { + +class ShaderPassSurfaceTest : public testing::Test { +protected: + void SetUp() override + { + context_ = new RenderContext(); + } + + void TearDown() override + { + if (context_ != nullptr) { + delete context_; + context_ = nullptr; + } + } + +private: + RenderContext* context_ = nullptr; +}; + +HWTEST_F(ShaderPassSurfaceTest, ShaderPassSurfaceTest_PreDraw_shade_nullptr, TestSize.Level0) +{ + auto shaderPassSurface = std::make_shared(context_); + ASSERT_NE(shaderPassSurface, nullptr); + shaderPassSurface->PreDraw(); +} + +HWTEST_F(ShaderPassSurfaceTest, ShaderPassSurfaceTest_PreDraw_shade_not_nullptr, TestSize.Level0) +{ + auto shaderPassSurface = std::make_shared(context_); + ASSERT_NE(shaderPassSurface, nullptr); + shaderPassSurface->shader_ = std::make_shared(context_, SURFACE_VERTEX_SHADER_CODE, + SURFACE_ROTATE_FRAGMENT_SHADER_CODE); + ASSERT_NE(shaderPassSurface->shader_, nullptr); + shaderPassSurface->PreDraw(); +} + +HWTEST_F(ShaderPassSurfaceTest, ShaderPassSurfaceTest_PostDraw_shade_nullptr, TestSize.Level0) +{ + auto shaderPassSurface = std::make_shared(context_); + ASSERT_NE(shaderPassSurface, nullptr); + shaderPassSurface->PostDraw(); +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/video_editor/test/unittest/render/render_engine/graphics_render_engine_impl_test.cpp b/frameworks/native/video_editor/test/unittest/render/render_engine/graphics_render_engine_impl_test.cpp index dd160a80f..1482a4086 100644 --- a/frameworks/native/video_editor/test/unittest/render/render_engine/graphics_render_engine_impl_test.cpp +++ b/frameworks/native/video_editor/test/unittest/render/render_engine/graphics_render_engine_impl_test.cpp @@ -16,6 +16,7 @@ #include "gtest/gtest.h" #include "render/graphics/render_engine/graphics_render_engine_impl.h" #include "render/graphics/graphics_render_engine.h" +#include "data_center/effect/effect_factory.h" #include "ut_common_data.h" #include @@ -49,6 +50,13 @@ HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_StopRender, EXPECT_EQ(graphicsRenderEngineImpl.StopRender(), VEFError::ERR_OK); } +HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_GetInputWindow_nullptr, TestSize.Level0) +{ + GraphicsRenderEngineImpl graphicsRenderEngineImpl(1); + graphicsRenderEngineImpl.surfaceTexture_ = nullptr; + EXPECT_EQ(graphicsRenderEngineImpl.GetInputWindow(), nullptr); +} + HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_GetInputWindow, TestSize.Level0) { std::string fileName = "H264_AAC_multi_track.mp4"; @@ -125,6 +133,21 @@ HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_RenderEffect EXPECT_EQ(renderEngine.RenderEffects(nullptr, renderInfo), nullptr); } +HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_RenderEffects_list_not_empty, TestSize.Level0) +{ + auto renderEngine = GraphicsRenderEngineImpl(1); + auto renderInfo = std::make_shared(); + auto effect = EffectFactory::CreateEffect(WATER_MARK_DESC); + renderInfo->effectInfoList_.emplace_back(effect->GetRenderInfo()); + EXPECT_EQ(renderEngine.RenderEffects(nullptr, renderInfo), nullptr); +} + +HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_CreateEffect_nullptr, TestSize.Level0) +{ + std::string description = ""; + EXPECT_EQ(EffectFactory::CreateEffect(description), nullptr); +} + HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_DrawFrame, TestSize.Level0) { std::string fileName = "H264_AAC_multi_track.mp4"; @@ -143,7 +166,7 @@ HWTEST_F(GraphicsRenderEngineImplTest, GraphicsRenderEngineImplTest_DrawFrame, T renderEngine.shaderPassOnScreen_ = std::make_shared(renderEngine.context_.get()); auto renderTexture = std::make_shared(renderEngine.context_.get(), 320, 480, GL_RGBA8); renderEngine.DrawFrame(100, renderTexture); - + renderEngine.DrawFrame(100, nullptr); auto renderEngine1 = GraphicsRenderEngineImpl(1); renderEngine1.context_ = std::make_shared(); renderEngine1.shaderPassOnScreen_ = std::make_shared(renderEngine1.context_.get()); diff --git a/frameworks/native/video_editor/test/unittest/ut_common_data.h b/frameworks/native/video_editor/test/unittest/ut_common_data.h index a0b948b09..d9285422f 100644 --- a/frameworks/native/video_editor/test/unittest/ut_common_data.h +++ b/frameworks/native/video_editor/test/unittest/ut_common_data.h @@ -31,6 +31,25 @@ constexpr const char* WATER_MARK_DESC = "{\"imageEffect\":{\"filters\":[{\"name\":\"InplaceSticker\",\"values\":" "{\"RESOURCE_DIRECTORY\":\"/sys_prod/resource/camera\"}}],\"name\":\"brandWaterMark\"}}"; +constexpr const char* SURFACE_VERTEX_SHADER_CODE = R"(uniform mat4 uTexMatrix; + attribute vec4 aPosition; + attribute vec4 aTextureCoord; + varying vec2 vTextureCoord; + void main() { + gl_Position = aPosition; + vTextureCoord = (uTexMatrix * vec4(aTextureCoord.xy, 0.0, 1.0)).xy; + } + )"; + +constexpr const char* SURFACE_ROTATE_FRAGMENT_SHADER_CODE = R"( + precision mediump float; + varying vec2 vTextureCoord; + uniform sampler2D sTexture; + void main() { + gl_FragColor = texture2D(sTexture, vTextureCoord); + } + )"; + class CompositionCallbackTesterImpl : public CompositionCallback { public: CompositionCallbackTesterImpl() = default; diff --git a/frameworks/native/video_editor/test/unittest/video_editor_impl_test.cpp b/frameworks/native/video_editor/test/unittest/video_editor_impl_test.cpp index 513d70a42..379666635 100644 --- a/frameworks/native/video_editor/test/unittest/video_editor_impl_test.cpp +++ b/frameworks/native/video_editor/test/unittest/video_editor_impl_test.cpp @@ -162,5 +162,10 @@ HWTEST_F(VideoEditorImplTest, cancel_composite_ok, TestSize.Level0) ASSERT_EQ(videoEditor->CancelComposite(), VEFError::ERR_OK); } +HWTEST_F(VideoEditorImplTest, CreateCompositeEngine_return_nullptr, TestSize.Level0) +{ + auto compositeEngine = ICompositeEngine::CreateCompositeEngine(nullptr); + ASSERT_EQ(compositeEngine, nullptr); +} } // namespace Media } // namespace OHOS diff --git a/test/unittest/resources/ohos_test.xml b/test/unittest/resources/ohos_test.xml index e6fa845a2..20aa0ddd6 100644 --- a/test/unittest/resources/ohos_test.xml +++ b/test/unittest/resources/ohos_test.xml @@ -108,18 +108,6 @@