a3cd437a803de0f945129d73413c24c91595dab5
[folly.git] / folly / test / AtomicBitSetTest.cpp
1 /*
2  * Copyright 2013 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "folly/AtomicBitSet.h"
18
19 #include <glog/logging.h>
20 #include <gtest/gtest.h>
21
22 namespace folly { namespace test {
23
24 TEST(AtomicBitSet, Simple) {
25   constexpr size_t kSize = 1000;
26   AtomicBitSet<kSize> bs;
27
28   EXPECT_EQ(kSize, bs.size());
29
30   for (size_t i = 0; i < kSize; ++i) {
31     EXPECT_FALSE(bs[i]);
32   }
33
34   bs.set(42);
35   for (size_t i = 0; i < kSize; ++i) {
36     EXPECT_EQ(i == 42, bs[i]);
37   }
38
39   bs.set(43);
40   for (size_t i = 0; i < kSize; ++i) {
41     EXPECT_EQ((i == 42 || i == 43), bs[i]);
42   }
43
44   bs.reset(42);
45   for (size_t i = 0; i < kSize; ++i) {
46     EXPECT_EQ((i == 43), bs[i]);
47   }
48
49   bs.reset(43);
50   for (size_t i = 0; i < kSize; ++i) {
51     EXPECT_FALSE(bs[i]);
52   }
53 }
54
55 }}  // namespaces
56
57 int main(int argc, char *argv[]) {
58   testing::InitGoogleTest(&argc, argv);
59   google::ParseCommandLineFlags(&argc, &argv, true);
60   return RUN_ALL_TESTS();
61 }
62