1 /*
2 * Copyright (c) 2021 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
16 #include <gtest/gtest.h>
17
18 #define private public
19 #include "common_event_command.h"
20 #undef private
21 #include "common_event_manager.h"
22 #include "common_event_subscriber.h"
23 #include "mock_common_event_stub.h"
24 #include "singleton.h"
25
26 using namespace testing::ext;
27 using namespace OHOS;
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::EventFwk;
30
31 namespace {
32 const std::string STRING_EVENT = "com.ces.event";
33 } // namespace
34
35 class CemCommandPublishModuleTest : public ::testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 void SetMockObjects(const CommonEventCommand &cmd) const;
42
43 std::string cmd_ = "publish";
44 std::string toolName_ = TOOL_NAME;
45 };
46
SetUpTestCase()47 void CemCommandPublishModuleTest::SetUpTestCase()
48 {}
49
TearDownTestCase()50 void CemCommandPublishModuleTest::TearDownTestCase()
51 {}
52
SetUp()53 void CemCommandPublishModuleTest::SetUp()
54 {
55 // reset optind to 0
56 optind = 0;
57 }
58
TearDown()59 void CemCommandPublishModuleTest::TearDown()
60 {}
61
62
SetMockObjects(const CommonEventCommand & cmd) const63 void CemCommandPublishModuleTest::SetMockObjects(const CommonEventCommand &cmd) const
64 {}
65
66 class CommonEventSubscriberTest : public CommonEventSubscriber {
67 public:
CommonEventSubscriberTest(const CommonEventSubscribeInfo & subscribeInfo)68 explicit CommonEventSubscriberTest(const CommonEventSubscribeInfo &subscribeInfo)
69 : CommonEventSubscriber(subscribeInfo)
70 {}
71
~CommonEventSubscriberTest()72 ~CommonEventSubscriberTest()
73 {}
74
OnReceiveEvent(const CommonEventData & data)75 void OnReceiveEvent(const CommonEventData &data)
76 {}
77 };
78
79 /**
80 * @tc.number: Cem_Command_Publish_ModuleTest_0100
81 * @tc.name: ExecCommand
82 * @tc.desc: Verify the "cem publish -e <name>" command.
83 */
84 HWTEST_F(CemCommandPublishModuleTest, Cem_Command_Publish_ModuleTest_0100, Function | MediumTest | Level1)
85 {
86 char *argv[] = {
87 (char *)toolName_.c_str(),
88 (char *)cmd_.c_str(),
89 (char *)"-e",
90 (char *)STRING_EVENT.c_str(),
91 (char *)"",
92 };
93 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
94
95 CommonEventCommand cmd(argc, argv);
96 EXPECT_EQ(cmd.ExecCommand(), STRING_PUBLISH_COMMON_EVENT_OK);
97 }
98