You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

atomic.cpp 1.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cmath>
  14. #include "core.h"
  15. #include "lol/unit.h"
  16. namespace lol
  17. {
  18. LOLUNIT_FIXTURE(AtomicTest)
  19. {
  20. LOLUNIT_TEST(SingleThread)
  21. {
  22. Atomic<int> i = 0;
  23. LOLUNIT_ASSERT_EQUAL(0, (int)i);
  24. int a1 = i++;
  25. LOLUNIT_ASSERT_EQUAL(0, a1);
  26. LOLUNIT_ASSERT_EQUAL(1, (int)i);
  27. int a2 = i--;
  28. LOLUNIT_ASSERT_EQUAL(1, a2);
  29. LOLUNIT_ASSERT_EQUAL(0, (int)i);
  30. int a3 = ++i;
  31. LOLUNIT_ASSERT_EQUAL(1, a3);
  32. LOLUNIT_ASSERT_EQUAL(1, (int)i);
  33. int a4 = --i;
  34. LOLUNIT_ASSERT_EQUAL(0, a4);
  35. LOLUNIT_ASSERT_EQUAL(0, (int)i);
  36. }
  37. };
  38. } /* namespace lol */