1 /*
2 * Copyright (c) 2022 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 "securec.h"
18
19 #include "softbus_bitmap.h"
20 #include "softbus_common.h"
21 #include "softbus_def.h"
22 #include "softbus_errcode.h"
23
24 #define BITNUM 32
25 #define TEST_POS 1
26 #define TEST_BIT 2
27
28 using namespace std;
29 using namespace testing::ext;
30
31 namespace OHOS {
32 class CommonCoreBitMapTest : public testing::Test {
33 public:
CommonCoreBitMapTest()34 CommonCoreBitMapTest() {}
~CommonCoreBitMapTest()35 ~CommonCoreBitMapTest() {}
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
SetUp()38 void SetUp() override {}
TearDown()39 void TearDown() override {}
40 };
41
SetUpTestCase(void)42 void CommonCoreBitMapTest::SetUpTestCase(void) {}
TearDownTestCase(void)43 void CommonCoreBitMapTest::TearDownTestCase(void) {}
44
45 /**
46 * @tc.name: CommonBitMapTest001
47 * @tc.desc: core common bit map test
48 * @tc.type: FUNC
49 * @tc.require:
50 */
51 HWTEST_F(CommonCoreBitMapTest, CommonBitMapTest001, TestSize.Level0)
52 {
53 uint8_t pos = BITNUM + 1;
54 uint32_t bitmap = 0;
55
56 SoftbusBitmapSet(nullptr, pos);
57 EXPECT_EQ(SOFTBUS_OK, bitmap);
58
59 SoftbusBitmapClr(nullptr, pos);
60 EXPECT_EQ(SOFTBUS_OK, bitmap);
61
62 bool result = SoftbusIsBitmapSet(nullptr, pos);
63 EXPECT_EQ(false, result);
64
65 bitmap = OSD_CAPABILITY_BITMAP;
66 SoftbusBitmapSet(&bitmap, pos);
67 EXPECT_EQ(OSD_CAPABILITY_BITMAP, bitmap);
68
69 bitmap = OSD_CAPABILITY_BITMAP;
70 SoftbusBitmapClr(&bitmap, pos);
71 EXPECT_EQ(OSD_CAPABILITY_BITMAP, bitmap);
72
73 bitmap = OSD_CAPABILITY_BITMAP;
74 result = SoftbusIsBitmapSet(&bitmap, pos);
75 EXPECT_EQ(false, result);
76
77 pos = TEST_POS;
78 bitmap = OSD_CAPABILITY_BITMAP;
79 SoftbusBitmapSet(&bitmap, pos);
80 EXPECT_EQ(OSD_CAPABILITY_BITMAP, bitmap);
81
82 bitmap = OSD_CAPABILITY_BITMAP;
83 SoftbusBitmapSet(&bitmap, pos);
84 EXPECT_EQ(OSD_CAPABILITY_BITMAP, bitmap);
85 }
86 } // namespace OHOS