~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/atomics_test.cc

Merged Drizzle's Trunk.

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
 
 
23
#include <gtest/gtest.h>
 
24
 
 
25
#include <drizzled/atomics.h>
 
26
 
 
27
using namespace drizzled;
 
28
 
 
29
TEST(atomic_operations, fetch_and_store)
 
30
{
 
31
  atomic<uint32_t> u235;
 
32
 
 
33
  EXPECT_EQ(0, u235.fetch_and_store(1));
 
34
 
 
35
  u235.fetch_and_store(15);
 
36
 
 
37
  EXPECT_EQ(15, u235.fetch_and_store(100));
 
38
  EXPECT_EQ(100, u235);
 
39
}
 
40
 
 
41
TEST(atomic_operations, fetch_and_increment)
 
42
{
 
43
  atomic<uint32_t> u235;
 
44
 
 
45
  EXPECT_EQ(0, u235.fetch_and_increment());
 
46
  EXPECT_EQ(1, u235);
 
47
}
 
48
 
 
49
TEST(atomic_operations, fetch_and_add)
 
50
{
 
51
  atomic<uint32_t> u235;
 
52
 
 
53
  EXPECT_EQ(0, u235.fetch_and_add(2));
 
54
  EXPECT_EQ(2, u235);
 
55
}
 
56
 
 
57
TEST(atomic_operations, add_and_fetch)
 
58
{
 
59
  atomic<uint32_t> u235;
 
60
 
 
61
  EXPECT_EQ(10, u235.add_and_fetch(10));
 
62
  EXPECT_EQ(10, u235);
 
63
}
 
64
 
 
65
TEST(atomic_operations, fetch_and_decrement)
 
66
{
 
67
  atomic<uint32_t> u235;
 
68
 
 
69
  u235.fetch_and_store(15);
 
70
 
 
71
  EXPECT_EQ(15, u235.fetch_and_decrement());
 
72
  EXPECT_EQ(14, u235);
 
73
}
 
74
 
 
75
TEST(atomic_operations, compare_and_swap)
 
76
{
 
77
  atomic<uint32_t> u235;
 
78
 
 
79
  u235.fetch_and_store(100);
 
80
 
 
81
  EXPECT_EQ(false, u235.compare_and_swap(42, 200));
 
82
  EXPECT_EQ(true, u235.compare_and_swap(200, 100));
 
83
  EXPECT_EQ(200, u235);
 
84
}
 
85
 
 
86
TEST(atomic_operations, increment)
 
87
{
 
88
  atomic<uint32_t> u235;
 
89
  u235.fetch_and_store(200);
 
90
  EXPECT_EQ(201, u235.increment());
 
91
}
 
92
 
 
93
TEST(atomic_operations, decrement)
 
94
{
 
95
  atomic<uint32_t> u235;
 
96
  u235.fetch_and_store(200);
 
97
 
 
98
  EXPECT_EQ(199, u235.decrement());
 
99
}
 
100
 
 
101
/*
 
102
TEST(atomic_operations, increment_assign)
 
103
{
 
104
  atomic<uint32_t> u235;
 
105
  u235.fetch_and_store(200);
 
106
 
 
107
  EXPECT_EQ(242, u235+=42);
 
108
}
 
109
 
 
110
TEST(atomic_operations, decrement_assign)
 
111
{
 
112
  atomic<uint32_t> u235;
 
113
  u235.fetch_and_store(200);
 
114
 
 
115
  EXPECT_EQ(158, u235-=42);
 
116
}
 
117
*/
 
118
 
 
119