• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "TestRunner.h"
16 
17 #include <gtest/gtest.h>
18 
19 #include <meta/api/threading/mutex.h>
20 
21 #include "src/testing_objects.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 META_BEGIN_NAMESPACE()
27 
28 using CORE_NS::Mutex;
29 using CORE_NS::UniqueLock;
30 
31 class MutexTest : public testing::Test {
32 public:
SetUpTestSuite()33     static void SetUpTestSuite()
34     {
35         SetTest();
36     }
TearDownTestSuite()37     static void TearDownTestSuite()
38     {
39         TearDownTest();
40     }
SetUp()41     void SetUp() {}
TearDown()42     void TearDown() {}
43 };
44 
45 /**
46  * @tc.name: UniqueLock
47  * @tc.desc: test UniqueLock
48  * @tc.type:FUNC
49  * @tc.require:
50  */
51 HWTEST_F(MutexTest, UniqueLock, TestSize.Level1)
52 {
53     Mutex m;
54     {
55         UniqueLock l { m };
56         EXPECT_TRUE(l);
57         l.Unlock();
58         EXPECT_FALSE(l);
59     }
60     {
61         UniqueLock l { m };
62         EXPECT_TRUE(l);
63         l.Unlock();
64         EXPECT_FALSE(l);
65         l.Lock();
66         EXPECT_TRUE(l);
67     }
68     {
69         UniqueLock l { m };
70         EXPECT_TRUE(l);
71         UniqueLock l2 = BASE_NS::move(l);
72         EXPECT_FALSE(l);
73         EXPECT_TRUE(l2);
74         l = std::move(l2);
75         EXPECT_FALSE(l2);
76         EXPECT_TRUE(l);
77     }
78 }
79 
80 META_END_NAMESPACE()
81