1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/*
* Copyright (c) 2018 Balabit
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include <criterion/criterion.h>
#include "atomic-gssize.h"
Test(test_atomic_gssize, set_min_value)
{
atomic_gssize min;
atomic_gssize_set(&min, G_MINSSIZE);
cr_assert_eq(atomic_gssize_get(&min), G_MINSSIZE);
atomic_gssize_inc(&min);
cr_assert_eq(atomic_gssize_get(&min), G_MINSSIZE+1);
atomic_gssize_sub(&min, 2);
cr_assert_eq(atomic_gssize_get(&min), G_MAXSSIZE);
}
Test(test_atomic_gssize, set_max_value)
{
atomic_gssize max;
atomic_gssize_set(&max, G_MAXSSIZE);
cr_assert_eq(atomic_gssize_get(&max), G_MAXSSIZE);
atomic_gssize_dec(&max);
cr_assert_eq(atomic_gssize_get(&max), G_MAXSSIZE - 1);
gssize old = atomic_gssize_add(&max, 2);
cr_assert_eq(old, G_MAXSSIZE - 1);
cr_assert_eq(atomic_gssize_get(&max), G_MINSSIZE);
}
Test(test_atomic_gssize, use_as_unsigned)
{
atomic_gssize a;
atomic_gssize_set(&a, G_MAXSIZE);
cr_assert_eq(atomic_gssize_get_unsigned(&a), G_MAXSIZE);
atomic_gssize_inc(&a);
cr_assert_eq(atomic_gssize_get_unsigned(&a), 0);
atomic_gssize_dec(&a);
cr_assert_eq(atomic_gssize_get_unsigned(&a), G_MAXSIZE);
}
Test(test_atomic_gssize, or_xor_and)
{
atomic_gssize a;
atomic_gssize_set(&a, 1);
atomic_gssize_or(&a, 2);
cr_assert_eq(atomic_gssize_get_unsigned(&a), 3);
atomic_gssize_xor(&a, 3);
cr_assert_eq(atomic_gssize_get_unsigned(&a), 0);
atomic_gssize_set(&a, 3);
atomic_gssize_and(&a, 2);
cr_assert_eq(atomic_gssize_get_unsigned(&a), 2);
}
|