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 <stdio.h> 18 19#include <openssl/type_check.h> 20 21 22int main(int argc, char **argv) { 23 CRYPTO_refcount_t count = 0; 24 25 CRYPTO_refcount_inc(&count); 26 if (count != 1) { 27 fprintf(stderr, "Incrementing reference count did not work.\n"); 28 return 1; 29 } 30 if (!CRYPTO_refcount_dec_and_test_zero(&count) || count != 0) { 31 fprintf(stderr, "Decrementing reference count to zero did not work.\n"); 32 return 1; 33 } 34 35 count = CRYPTO_REFCOUNT_MAX; 36 CRYPTO_refcount_inc(&count); 37 if (count != CRYPTO_REFCOUNT_MAX) { 38 fprintf(stderr, "Count did not saturate correctly when incrementing.\n"); 39 return 1; 40 } 41 if (CRYPTO_refcount_dec_and_test_zero(&count) || 42 count != CRYPTO_REFCOUNT_MAX) { 43 fprintf(stderr, "Count did not saturate correctly when decrementing.\n"); 44 return 1; 45 } 46 47 count = 2; 48 if (CRYPTO_refcount_dec_and_test_zero(&count)) { 49 fprintf(stderr, "Decrementing two resulted in zero!\n"); 50 return 1; 51 } 52 if (count != 1) { 53 fprintf(stderr, "Decrementing two did not produce one!"); 54 return 1; 55 } 56 57 printf("PASS\n"); 58 return 0; 59} 60