• 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 #include "sys_event_test.h"
16 
17 #include <ctime>
18 #include <iostream>
19 #include <memory>
20 #include <regex>
21 #include <vector>
22 
23 #include "sys_event.h"
24 namespace OHOS {
25 namespace HiviewDFX {
SetUpTestCase()26 void SysEventTest::SetUpTestCase()
27 {
28 }
29 
TearDownTestCase()30 void SysEventTest::TearDownTestCase()
31 {
32 }
33 
SetUp()34 void SysEventTest::SetUp()
35 {
36 }
37 
TearDown()38 void SysEventTest::TearDown()
39 {
40 }
41 
42 /**
43  * @tc.name: TestSendBaseType001
44  * @tc.desc: create base sys event
45  * @tc.type: FUNC
46  * @tc.require: AR000FT2Q2 AR000FT2Q3
47  */
48 HWTEST_F(SysEventTest, TestSendBaseType001, testing::ext::TestSize.Level3)
49 {
50     /**
51      * @tc.steps: step1. create base sys event
52      */
53     std::cout << "TestSendBaseType001 test base type" << std::endl;
54     SysEventCreator sysEventCreator("DEMO", "EVENT_NAME", SysEventCreator::FAULT);
55     sysEventCreator.SetKeyValue("KEY", 1);
56     std::shared_ptr<SysEvent> sysEvent = std::make_shared<SysEvent>("test", nullptr, sysEventCreator);
57     std::regex expValue(R"~(\{"domain_":"DEMO","name_":"EVENT_NAME","type_":1,"time_":\d+,"tz_":"[\+\-]\d+","pid_":\d+,"tid_":\d+,"uid_":\d+,"KEY":1\})~");
58     std::cout << "size=" << sysEvent->jsonExtraInfo_.size() << ", jsonStr:" << sysEvent->jsonExtraInfo_ << std::endl;
59     std::smatch baseMatch;
60     bool isMatch = std::regex_match(sysEvent->jsonExtraInfo_, baseMatch, expValue);
61     ASSERT_TRUE(isMatch);
62 }
63 
64 /**
65  * @tc.name: TestSendIntVectorType002
66  * @tc.desc: create base sys event
67  * @tc.type: FUNC
68  * @tc.require: AR000FT2Q2 AR000FT2Q3
69  */
70 HWTEST_F(SysEventTest, TestSendIntVectorType002, testing::ext::TestSize.Level3)
71 {
72     /**
73      * @tc.steps: step1. create base sys event
74      */
75     std::cout << "TestSendIntVectorType002 test vector<int> type" << std::endl;
76     SysEventCreator sysEventCreator("DEMO", "EVENT_NAME", SysEventCreator::FAULT);
77     std::vector<int> values = {1, 2, 3};
78     sysEventCreator.SetKeyValue("KEY", values);
79     std::shared_ptr<SysEvent> sysEvent = std::make_shared<SysEvent>("test", nullptr, sysEventCreator);
80     std::regex expValue(R"~(\{"domain_":"DEMO","name_":"EVENT_NAME","type_":1,"time_":\d+,"tz_":"[\+\-]\d+","pid_":\d+,"tid_":\d+,"uid_":\d+,"KEY":\[1,2,3\]\})~");
81     std::cout << "size=" << sysEvent->jsonExtraInfo_.size() << ", jsonStr:" << sysEvent->jsonExtraInfo_ << std::endl;
82     std::smatch baseMatch;
83     bool isMatch = std::regex_match(sysEvent->jsonExtraInfo_, baseMatch, expValue);
84     ASSERT_TRUE(isMatch);
85 }
86 } // HiviewDFX
87 } // OHOS