~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/atomics_test.cc

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 Stewart Smith
5
 
 *
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.
10
 
 *
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.
15
 
 *
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
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
#define BOOST_TEST_DYN_LINK
23
 
#include <boost/test/unit_test.hpp>
24
 
 
25
 
#include <drizzled/atomics.h>
26
 
 
27
 
using namespace drizzled;
28
 
 
29
 
BOOST_AUTO_TEST_SUITE(AtomicOperations)
30
 
BOOST_AUTO_TEST_CASE(fetch_and_store)
31
 
{
32
 
  atomic<uint32_t> u235;
33
 
 
34
 
  BOOST_REQUIRE_EQUAL(0, u235.fetch_and_store(1));
35
 
 
36
 
  u235.fetch_and_store(15);
37
 
 
38
 
  BOOST_REQUIRE_EQUAL(15, u235.fetch_and_store(100));
39
 
  BOOST_REQUIRE_EQUAL(100, u235);
40
 
}
41
 
 
42
 
BOOST_AUTO_TEST_CASE(fetch_and_increment)
43
 
{
44
 
  atomic<uint32_t> u235;
45
 
 
46
 
  BOOST_REQUIRE_EQUAL(0, u235.fetch_and_increment());
47
 
  BOOST_REQUIRE_EQUAL(1, u235);
48
 
}
49
 
 
50
 
BOOST_AUTO_TEST_CASE(fetch_and_add)
51
 
{
52
 
  atomic<uint32_t> u235;
53
 
 
54
 
  BOOST_REQUIRE_EQUAL(0, u235.fetch_and_add(2));
55
 
  BOOST_REQUIRE_EQUAL(2, u235);
56
 
}
57
 
 
58
 
BOOST_AUTO_TEST_CASE(add_and_fetch)
59
 
{
60
 
  atomic<uint32_t> u235;
61
 
 
62
 
  BOOST_REQUIRE_EQUAL(10, u235.add_and_fetch(10));
63
 
  BOOST_REQUIRE_EQUAL(10, u235);
64
 
}
65
 
 
66
 
BOOST_AUTO_TEST_CASE(fetch_and_decrement)
67
 
{
68
 
  atomic<uint32_t> u235;
69
 
 
70
 
  u235.fetch_and_store(15);
71
 
 
72
 
  BOOST_REQUIRE_EQUAL(15, u235.fetch_and_decrement());
73
 
  BOOST_REQUIRE_EQUAL(14, u235);
74
 
}
75
 
 
76
 
BOOST_AUTO_TEST_CASE(compare_and_swap)
77
 
{
78
 
  atomic<uint32_t> u235;
79
 
 
80
 
  u235.fetch_and_store(100);
81
 
 
82
 
  BOOST_REQUIRE(not u235.compare_and_swap(42, 200));
83
 
  BOOST_REQUIRE(u235.compare_and_swap(200, 100));
84
 
  BOOST_REQUIRE_EQUAL(200, u235);
85
 
}
86
 
 
87
 
BOOST_AUTO_TEST_CASE(increment)
88
 
{
89
 
  atomic<uint32_t> u235;
90
 
  u235.fetch_and_store(200);
91
 
  BOOST_REQUIRE_EQUAL(201, u235.increment());
92
 
}
93
 
 
94
 
BOOST_AUTO_TEST_CASE(decrement)
95
 
{
96
 
  atomic<uint32_t> u235;
97
 
  u235.fetch_and_store(200);
98
 
 
99
 
  BOOST_REQUIRE_EQUAL(199, u235.decrement());
100
 
}
101
 
 
102
 
BOOST_AUTO_TEST_SUITE_END()
103
 
 
104
 
/* TODO: add tests for += and -= when supported */
105