~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/atomics_test.cc

  • Committer: Andrew Hutchings
  • Date: 2011-01-20 17:22:18 UTC
  • mto: (2108.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: andrew@linuxjedi.co.uk-20110120172218-bq8pibrpzt7io4q6
Start of migration to boost::test

Show diffs side-by-side

added added

removed removed

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