Atomic_unittest.cc revision e3f3104a
1cd139dc7SShuo Chen#include "../Atomic.h"
2cd139dc7SShuo Chen#include <assert.h>
3cd139dc7SShuo Chen
4cd139dc7SShuo Chenint main()
5cd139dc7SShuo Chen{
6e3f3104aSShuo Chen  {
7cd139dc7SShuo Chen  muduo::AtomicInt64 a0;
8cd139dc7SShuo Chen  assert(a0.get() == 0);
9cd139dc7SShuo Chen  assert(a0.getAndAdd(1) == 0);
10cd139dc7SShuo Chen  assert(a0.get() == 1);
11cd139dc7SShuo Chen  assert(a0.addAndGet(2) == 3);
12cd139dc7SShuo Chen  assert(a0.get() == 3);
13cd139dc7SShuo Chen  assert(a0.incrementAndGet() == 4);
14cd139dc7SShuo Chen  assert(a0.get() == 4);
15cd139dc7SShuo Chen  a0.increment();
16cd139dc7SShuo Chen  assert(a0.get() == 5);
17cd139dc7SShuo Chen  assert(a0.addAndGet(-3) == 2);
18cd139dc7SShuo Chen  assert(a0.getAndSet(100) == 2);
19cd139dc7SShuo Chen  assert(a0.get() == 100);
20e3f3104aSShuo Chen  }
21e3f3104aSShuo Chen
22e3f3104aSShuo Chen  {
23e3f3104aSShuo Chen  muduo::AtomicInt32 a1;
24e3f3104aSShuo Chen  assert(a1.get() == 0);
25e3f3104aSShuo Chen  assert(a1.getAndAdd(1) == 0);
26e3f3104aSShuo Chen  assert(a1.get() == 1);
27e3f3104aSShuo Chen  assert(a1.addAndGet(2) == 3);
28e3f3104aSShuo Chen  assert(a1.get() == 3);
29e3f3104aSShuo Chen  assert(a1.incrementAndGet() == 4);
30e3f3104aSShuo Chen  assert(a1.get() == 4);
31e3f3104aSShuo Chen  a1.increment();
32e3f3104aSShuo Chen  assert(a1.get() == 5);
33e3f3104aSShuo Chen  assert(a1.addAndGet(-3) == 2);
34e3f3104aSShuo Chen  assert(a1.getAndSet(100) == 2);
35e3f3104aSShuo Chen  assert(a1.get() == 100);
36e3f3104aSShuo Chen  }
37cd139dc7SShuo Chen}
38cd139dc7SShuo Chen
39