1 /*
2  * Copyright (c) 2023 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 #define private public
18 #define protected public
19 #include "util/options.h"
20 #undef protected
21 #undef private
22 
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace OHOS::Idl;
26 
27 namespace OHOS {
28 namespace idl {
29 class OptionsUnitTest : public testing::Test {
30 public:
OptionsUnitTest()31     OptionsUnitTest() {}
~OptionsUnitTest()32     virtual ~OptionsUnitTest() {}
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase()39 void OptionsUnitTest::SetUpTestCase() {}
TearDownTestCase()40 void OptionsUnitTest::TearDownTestCase() {}
SetUp()41 void OptionsUnitTest::SetUp() {}
TearDown()42 void OptionsUnitTest::TearDown() {}
43 
44 /*
45  * @tc.name: OptionsUnitTest_0100
46  * @tc.desc: test GetDoHitraceState and GetLogState in OptionsUnitTest.
47  * @tc.type: FUNC
48  */
49 HWTEST_F(OptionsUnitTest, OptionsUnitTest_0100, Function | MediumTest | Level1)
50 {
51     /**
52      * @tc.steps: step1. Initialization parameters.
53      */
54     std::string strings[] = {"-t", "-log-domainid", "-log-tag"};
55     int32_t count = sizeof(strings) / sizeof(strings[0]);
56     char **argv = new char *[count];
57     for (int32_t i = 0; i < count; i++) {
58         argv[i] = const_cast<char*>(strings[i].c_str());
59     }
60 
61     /**
62      * @tc.steps: step2. Set options to call functions.
63      * @tc.expected: Can obtain the correct doHitrace, reasonAble and logState value.
64      */
65     Options options(count, argv);
66     auto doHitrace = options.DoHitraceState();
67     auto logOn = options.DoLogOn();
68     auto hitRaceTag = options.GetGenerateHitraceTag();
69     auto doMainId = options.GetDomainId();
70     auto logTag = options.GetLogTag();
71     auto attRibute = options.GetAttribute();
72     options.ShowUsage();
73     options.ShowWarning();
74     EXPECT_FALSE(doHitrace);
75     EXPECT_FALSE(logOn);
76     delete[] argv;
77 }
78 }
79 }