source: trunk/test/unit/atomic.cpp @ 2360

Last change on this file since 2360 was 2360, checked in by sam, 6 years ago

test: add missing unit tests for the Atomic template class.

File size: 1.0 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cmath>
16
17#include "core.h"
18#include "lol/unit.h"
19
20namespace lol
21{
22
23LOLUNIT_FIXTURE(AtomicTest)
24{
25    LOLUNIT_TEST(SingleThread)
26    {
27        Atomic<int> i = 0;
28
29        LOLUNIT_ASSERT_EQUAL(0, (int)i);
30
31        int a1 = i++;
32        LOLUNIT_ASSERT_EQUAL(0, a1);
33        LOLUNIT_ASSERT_EQUAL(1, (int)i);
34
35        int a2 = i--;
36        LOLUNIT_ASSERT_EQUAL(1, a2);
37        LOLUNIT_ASSERT_EQUAL(0, (int)i);
38
39        int a3 = ++i;
40        LOLUNIT_ASSERT_EQUAL(1, a3);
41        LOLUNIT_ASSERT_EQUAL(1, (int)i);
42
43        int a4 = --i;
44        LOLUNIT_ASSERT_EQUAL(0, a4);
45        LOLUNIT_ASSERT_EQUAL(0, (int)i);
46    }
47};
48
49} /* namespace lol */
50
Note: See TracBrowser for help on using the repository browser.