1 /* Copyright (c) 2015, Google Inc. 2 * 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. 6 * 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. */ 14 15 #include "internal.h" 16 17 #include <gtest/gtest.h> 18 19 20 TEST(RefCountTest, Basic) { 21 CRYPTO_refcount_t count = 0; 22 23 CRYPTO_refcount_inc(&count); 24 EXPECT_EQ(1u, count); 25 26 EXPECT_TRUE(CRYPTO_refcount_dec_and_test_zero(&count)); 27 EXPECT_EQ(0u, count); 28 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."; 36 37 count = 2; 38 EXPECT_FALSE(CRYPTO_refcount_dec_and_test_zero(&count)); 39 EXPECT_EQ(1u, count); 40 } 41