• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "event_dispatch_queue_test.h"
17 
18 using namespace testing::ext;
19 using namespace OHOS::HiviewDFX;
20 
SetUp()21 void EventDispatchQueueTest::SetUp()
22 {
23     /**
24      * @tc.setup: create order and unordered event dispatch queue
25      */
26     printf("SetUp.\n");
27 }
28 
TearDown()29 void EventDispatchQueueTest::TearDown()
30 {
31     /**
32      * @tc.teardown: destroy the event dispatch queue we have created
33      */
34     printf("TearDown.\n");
35 }
36 
CreateEvent(const std::string & name,int32_t id,const std::string & message,Event::MessageType type)37 std::shared_ptr<Event> EventDispatchQueueTest::CreateEvent(const std::string& name, int32_t id,
38                                                            const std::string& message, Event::MessageType type)
39 {
40     auto event = std::make_shared<Event>(name);
41     event->messageType_ = type;
42     event->eventId_ = id;
43     event->SetValue("message", message);
44     return event;
45 }
46 
OnUnorderedEvent(const OHOS::HiviewDFX::Event & msg)47 void ExtendEventListener::OnUnorderedEvent(const OHOS::HiviewDFX::Event& msg)
48 {
49     printf("cur listener:%s OnUnorderedEvent eventId_:%u \n", name_.c_str(), msg.eventId_);
50     unorderEventCount_++;
51     auto message = msg.GetValue("message");
52     processedUnorderedEvents_[message] = msg.sender_;
53 }
54 
GetListenerName()55 std::string ExtendEventListener::GetListenerName()
56 {
57     return name_;
58 }
59 /**
60  * @tc.name: EventDispatchQueueCreateTest001
61  * @tc.desc: create and init an event dispatch queue
62  * @tc.type: FUNC
63  * @tc.require: AR000DPTSU
64  */
65 HWTEST_F(EventDispatchQueueTest, EventDispatchQueueCreateTest001, TestSize.Level3)
66 {
67     printf("EventDispatchQueueTest.\n");
68     OHOS::HiviewDFX::HiviewPlatform& platform = HiviewPlatform::GetInstance();
69     if (!platform.InitEnvironment("/data/test/test_data/hiview_platform_config0")) {
70         printf("Fail to init environment. \n");
71     }
72     auto unorderQueue = std::make_shared<EventDispatchQueue>("test1", Event::ManageType::UNORDERED, &platform);
73     ASSERT_EQ(false, unorderQueue->IsRunning());
74     unorderQueue->Start();
75     sleep(1);
76     ASSERT_EQ(true, unorderQueue->IsRunning());
77     unorderQueue->Stop();
78     ASSERT_EQ(false, unorderQueue->IsRunning());
79 }
80