1 /*
2  * Copyright (c) 2024 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 #include <cstdlib>
18 #include <unistd.h>
19 #include <sys/wait.h>
20 #include <csignal>
21 #include <cerrno>
22 #include <cstring>
23 #include <sys/prctl.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <sys/syscall.h>
28 #include <asm/unistd.h>
29 #include <syscall.h>
30 #include <climits>
31 #include <sched.h>
32 
33 #include "systemcapability.h"
34 
35 using namespace std;
36 using namespace testing::ext;
37 
38 namespace init_ut {
39 class SyscapUnitTest : public testing::Test {
40 public:
SetUpTestCase(void)41     static void SetUpTestCase(void) {};
TearDownTestCase(void)42     static void TearDownTestCase(void) {};
SetUp()43     void SetUp() {};
TearDown()44     void TearDown() {};
45 }
46 
HWTEST_F(SyscapUnitTest, HasSystemCapability_001, TestSize.Level1)47 HWTEST_F(SyscapUnitTest, HasSystemCapability_001, TestSize.Level1)
48 {
49     bool ret = HasSystemCapability("test.cap");
50     EXPECT_EQ(ret, false);
51     ret = HasSystemCapability(nullptr);
52     EXPECT_EQ(ret, false);
53     ret = HasSystemCapability("ArkUI.ArkUI.Napi");
54     EXPECT_EQ(ret, true);
55     ret = HasSystemCapability("SystemCapability.ArkUI.ArkUI.Napi");
56     EXPECT_EQ(ret, true);
57     char *wrongName = reinterpret_cast<char *>(malloc(SYSCAP_MAX_SIZE));
58     ASSERT_NE(wrongName, nullptr);
59     EXPECT_EQ(memset_s(wrongName, SYSCAP_MAX_SIZE, 1, SYSCAP_MAX_SIZE), 0);
60     HasSystemCapability(wrongName);
61     free(wrongName);
62 }
63 }