1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/BitSet.h"
11 // Work around issue with commas in macro use.
13 using BitSetUint8
= BitSet
<N
, uint8_t>;
15 using BitSetUint32
= BitSet
<N
, uint32_t>;
18 MOZ_RELEASE_ASSERT(BitSetUint8
<1>().Storage().LengthBytes() == 1);
19 MOZ_RELEASE_ASSERT(BitSetUint32
<1>().Storage().LengthBytes() == 4);
21 MOZ_RELEASE_ASSERT(BitSetUint8
<1>().Storage().Length() == 1);
22 MOZ_RELEASE_ASSERT(BitSetUint8
<8>().Storage().Length() == 1);
23 MOZ_RELEASE_ASSERT(BitSetUint8
<9>().Storage().Length() == 2);
25 MOZ_RELEASE_ASSERT(BitSetUint32
<1>().Storage().Length() == 1);
26 MOZ_RELEASE_ASSERT(BitSetUint32
<32>().Storage().Length() == 1);
27 MOZ_RELEASE_ASSERT(BitSetUint32
<33>().Storage().Length() == 2);
29 BitSetUint8
<10> bitset
;
30 MOZ_RELEASE_ASSERT(!bitset
.Test(3));
31 MOZ_RELEASE_ASSERT(!bitset
[3]);
34 MOZ_RELEASE_ASSERT(bitset
.Test(3));
35 MOZ_RELEASE_ASSERT(bitset
[3]);
38 for (size_t i
= 0; i
< bitset
.Size(); i
++) {
39 MOZ_RELEASE_ASSERT(!bitset
[i
]);
43 for (size_t i
= 0; i
< bitset
.Size(); i
++) {
44 MOZ_RELEASE_ASSERT(bitset
[i
]);
48 for (size_t i
= 0; i
< bitset
.Size(); i
++) {
49 MOZ_RELEASE_ASSERT(!bitset
[i
]);
52 // Test trailing unused bits are not set by SetAll().
54 BitSetUint8
<16> bitset2(bitset
.Storage());
55 MOZ_RELEASE_ASSERT(bitset
.Size() < bitset2
.Size());
56 MOZ_RELEASE_ASSERT(bitset
.Storage().Length() == bitset2
.Storage().Length());
57 for (size_t i
= 0; i
< bitset
.Size(); i
++) {
58 MOZ_RELEASE_ASSERT(bitset2
[i
]);
60 for (size_t i
= bitset
.Size(); i
< bitset2
.Size(); i
++) {
61 MOZ_RELEASE_ASSERT(!bitset2
[i
]);