• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "testngpp/testngpp.hpp"
16 #include "plugin/core/plugin_manager.h"
17 
18 using namespace OHOS::Media::Plugin;
19 
20 // @fixture(tags=audio_play_fast)
FIXTURE(PluginsEnableAndDisable)21 FIXTURE(PluginsEnableAndDisable)
22 {
23     /**
24      *  Test Scenario:   Check package exists, package count.
25      *  1. [Done] Can disable one package.
26      *  2. [Done] Can enable one package.
27      *  3. [Done] Can disable two packages.
28      *  4. [Done] Can enable two packages.
29      *  5. [Done] Can not disable a package not exists.
30      *  6. [To Fix] Can not enable a package not exists.
31      *  7. [To Fix] Can not enable a package that also enabled.
32      *  8. [To Fix] The plugin manager seems only registered these plugins:
33      *  1 (wav_demuxer_plugin.cpp, 248) : Func(RegisterPlugin) RegisterPlugin called.
34         1 (audio_ffmpeg_decoder_plugin.cpp, 60) : Func(RegisterAudioDecoderPlugins) registering audio decoders
35         1 (audio_ffmpeg_encoder_plugin.cpp, 45) : Func(RegisterAudioEncoderPlugins) registering audio encoders
36         1 (minimp3_decoder_plugin.cpp, 242) : Func(RegisterDecoderPlugin) RegisterPlugins called.
37         1 (video_ffmpeg_encoder_plugin.cpp, 47) : Func(RegisterVideoEncoderPlugins) registering video encoders
38         1 (video_ffmpeg_decoder_plugin.cpp, 50) : Func(RegisterVideoDecoderPlugins) registering video decoders
39      * */
40     PluginManager& pluginManager = PluginManager::Instance();
41     int pluginCounts = pluginManager.GetAllRegisteredPluginCount();
42 
43     DATA_PROVIDER(plugins, 2,
44     DATA_GROUP(OHOS::Media::Plugin::PluginType::SOURCE, std::string("FileSource")),
45     DATA_GROUP(OHOS::Media::Plugin::PluginType::SOURCE, std::string("HttpSource")),
46     DATA_GROUP(OHOS::Media::Plugin::PluginType::DEMUXER, std::string("FFmpegDemuxer")),
47     DATA_GROUP(OHOS::Media::Plugin::PluginType::CODEC, std::string("Minimp3Decoder")));
48 
49     // @test(data="plugins",tags=fast)
50     PTEST((OHOS::Media::Plugin::PluginType type, std::string name), Can disable one package and enable it again)
51     {
52         pluginManager.DisablePackage(type, name);
53         ASSERT_FALSE(pluginManager.IsPackageExist(type, name));
54         ASSERT_TRUE(pluginManager.GetAllRegisteredPluginCount() < pluginCounts);
55         pluginManager.EnablePackage(type, name);
56         ASSERT_TRUE(pluginManager.IsPackageExist(type, name));
57         ASSERT_TRUE(pluginManager.GetAllRegisteredPluginCount() == pluginCounts);
58     }
59 
60     // @test(tags=fast)
61     TEST(Can disable two packages and enable them again)
62     {
63         pluginManager.DisablePackage(OHOS::Media::Plugin::PluginType::SOURCE, "FileSource");
64         pluginManager.DisablePackage(OHOS::Media::Plugin::PluginType::DEMUXER, "FFmpegDemuxer");
65         ASSERT_FALSE(pluginManager.IsPackageExist(OHOS::Media::Plugin::PluginType::SOURCE, "FileSource"));
66         ASSERT_FALSE(pluginManager.IsPackageExist(OHOS::Media::Plugin::PluginType::DEMUXER, "FFmpegDemuxer"));
67         ASSERT_TRUE(pluginManager.GetAllRegisteredPluginCount() < pluginCounts);
68         pluginManager.EnablePackage(OHOS::Media::Plugin::PluginType::SOURCE, "FileSource");
69         pluginManager.EnablePackage(OHOS::Media::Plugin::PluginType::DEMUXER, "FFmpegDemuxer");
70         ASSERT_TRUE(pluginManager.IsPackageExist(OHOS::Media::Plugin::PluginType::SOURCE, "FileSource"));
71         ASSERT_TRUE(pluginManager.IsPackageExist(OHOS::Media::Plugin::PluginType::DEMUXER, "FFmpegDemuxer"));
72         ASSERT_TRUE(pluginManager.GetAllRegisteredPluginCount() == pluginCounts);
73     }
74 
75     // @test(tags=fast)
76     TEST(Plugin counts should be decreased by the plugin count of package when the package disabled : FileSource)
77     {
78         int pluginCountInPkg = pluginManager.GetRegisteredPluginCountByPackageName("FileSource");
79         pluginManager.DisablePackage(OHOS::Media::Plugin::PluginType::SOURCE, "FileSource");
80         ASSERT_EQ(pluginManager.GetAllRegisteredPluginCount() + pluginCountInPkg, pluginCounts);
81         pluginManager.EnablePackage(OHOS::Media::Plugin::PluginType::SOURCE, "FileSource");
82     }
83 
84     // @test(tags=fast)
85     TEST(Plugin counts should be decreased by the plugin count of package when the package disabled : FFmpegDemuxer)
86     {
87         int pluginCountInPkg = pluginManager.GetRegisteredPluginCountByPackageName("FFmpegDemuxer");
88         pluginManager.DisablePackage(OHOS::Media::Plugin::PluginType::DEMUXER, "FFmpegDemuxer");
89         ASSERT_EQ(pluginManager.GetAllRegisteredPluginCount() + pluginCountInPkg, pluginCounts);
90         pluginManager.EnablePackage(OHOS::Media::Plugin::PluginType::DEMUXER, "FFmpegDemuxer");
91     }
92 };
93