1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Stewart Smith
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <gtest/gtest.h>
25
#include <drizzled/atomics.h>
27
using namespace drizzled;
29
TEST(atomic_operations, fetch_and_store)
31
atomic<uint32_t> u235;
33
EXPECT_EQ(0, u235.fetch_and_store(1));
35
u235.fetch_and_store(15);
37
EXPECT_EQ(15, u235.fetch_and_store(100));
41
TEST(atomic_operations, fetch_and_increment)
43
atomic<uint32_t> u235;
45
EXPECT_EQ(0, u235.fetch_and_increment());
49
TEST(atomic_operations, fetch_and_add)
51
atomic<uint32_t> u235;
53
EXPECT_EQ(0, u235.fetch_and_add(2));
57
TEST(atomic_operations, add_and_fetch)
59
atomic<uint32_t> u235;
61
EXPECT_EQ(10, u235.add_and_fetch(10));
65
TEST(atomic_operations, fetch_and_decrement)
67
atomic<uint32_t> u235;
69
u235.fetch_and_store(15);
71
EXPECT_EQ(15, u235.fetch_and_decrement());
75
TEST(atomic_operations, compare_and_swap)
77
atomic<uint32_t> u235;
79
u235.fetch_and_store(100);
81
EXPECT_EQ(false, u235.compare_and_swap(42, 200));
82
EXPECT_EQ(true, u235.compare_and_swap(200, 100));
86
TEST(atomic_operations, increment)
88
atomic<uint32_t> u235;
89
u235.fetch_and_store(200);
90
EXPECT_EQ(201, u235.increment());
93
TEST(atomic_operations, decrement)
95
atomic<uint32_t> u235;
96
u235.fetch_and_store(200);
98
EXPECT_EQ(199, u235.decrement());
102
TEST(atomic_operations, increment_assign)
104
atomic<uint32_t> u235;
105
u235.fetch_and_store(200);
107
EXPECT_EQ(242, u235+=42);
110
TEST(atomic_operations, decrement_assign)
112
atomic<uint32_t> u235;
113
u235.fetch_and_store(200);
115
EXPECT_EQ(158, u235-=42);