1 // Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <log/interprocess/interprocess_sync_null.h>
10 #include <gtest/gtest.h>
11 
12 using namespace std;
13 using namespace isc::log::interprocess;
14 
15 namespace {
16 
TEST(InterprocessSyncNullTest,TestNull)17 TEST(InterprocessSyncNullTest, TestNull) {
18   InterprocessSyncNull sync("test1");
19   InterprocessSyncLocker locker(sync);
20 
21   // Check if the is_locked_ flag is set correctly during lock().
22   EXPECT_FALSE(locker.isLocked());
23   EXPECT_TRUE(locker.lock());
24   EXPECT_TRUE(locker.isLocked());
25 
26   // lock() must always return true (this is called 4 times, just an
27   // arbitrary number)
28   EXPECT_TRUE(locker.lock());
29   EXPECT_TRUE(locker.lock());
30   EXPECT_TRUE(locker.lock());
31   EXPECT_TRUE(locker.lock());
32 
33   // Check if the is_locked_ flag is set correctly during unlock().
34   EXPECT_TRUE(locker.isLocked());
35   EXPECT_TRUE(locker.unlock());
36   EXPECT_FALSE(locker.isLocked());
37 
38   // unlock() must always return true (this is called 4 times, just an
39   // arbitrary number)
40   EXPECT_TRUE(locker.unlock());
41   EXPECT_TRUE(locker.unlock());
42   EXPECT_TRUE(locker.unlock());
43   EXPECT_TRUE(locker.unlock());
44 
45   // Check if the is_locked_ flag is set correctly during tryLock().
46   EXPECT_FALSE(locker.isLocked());
47   EXPECT_TRUE(locker.tryLock());
48   EXPECT_TRUE(locker.isLocked());
49 
50   // tryLock() must always return true (this is called 4 times, just an
51   // arbitrary number)
52   EXPECT_TRUE(locker.tryLock());
53   EXPECT_TRUE(locker.tryLock());
54   EXPECT_TRUE(locker.tryLock());
55   EXPECT_TRUE(locker.tryLock());
56 
57   // Random order (should all return true)
58   EXPECT_TRUE(locker.unlock());
59   EXPECT_TRUE(locker.lock());
60   EXPECT_TRUE(locker.tryLock());
61   EXPECT_TRUE(locker.lock());
62   EXPECT_TRUE(locker.unlock());
63   EXPECT_TRUE(locker.lock());
64   EXPECT_TRUE(locker.tryLock());
65   EXPECT_TRUE(locker.unlock());
66   EXPECT_TRUE(locker.unlock());
67 }
68 
69 }
70