1 /* Copyright (c) 2015, Google Inc.
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
17 #include <gtest/gtest.h>
20 TEST(RefCountTest, Basic) {
21 CRYPTO_refcount_t count = 0;
23 CRYPTO_refcount_inc(&count);
26 EXPECT_TRUE(CRYPTO_refcount_dec_and_test_zero(&count));
29 count = CRYPTO_REFCOUNT_MAX;
30 CRYPTO_refcount_inc(&count);
31 EXPECT_EQ(CRYPTO_REFCOUNT_MAX, count)
32 << "Count did not saturate correctly when incrementing.";
33 EXPECT_FALSE(CRYPTO_refcount_dec_and_test_zero(&count));
34 EXPECT_EQ(CRYPTO_REFCOUNT_MAX, count)
35 << "Count did not saturate correctly when decrementing.";
38 EXPECT_FALSE(CRYPTO_refcount_dec_and_test_zero(&count));