Foo.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <cstdio>
  7. #ifndef ANKI_TESTS_FOO_VERBOSE
  8. # define ANKI_TESTS_FOO_VERBOSE 0
  9. #endif
  10. #if ANKI_TESTS_FOO_VERBOSE
  11. # define ANKI_TESTS_FOO_PRINT() printf("%s\n", __PRETTY_FUNCTION__)
  12. #else
  13. # define ANKI_TESTS_FOO_PRINT() ((void)0)
  14. #endif
  15. /// Struct for testing
  16. struct Foo
  17. {
  18. int x = 666;
  19. static int constructorCallCount;
  20. static int destructorCallCount;
  21. Foo()
  22. {
  23. ANKI_TESTS_FOO_PRINT();
  24. ++constructorCallCount;
  25. }
  26. Foo(int x_)
  27. : x(x_)
  28. {
  29. ANKI_TESTS_FOO_PRINT();
  30. ++constructorCallCount;
  31. }
  32. Foo(const Foo& b)
  33. : x(b.x)
  34. {
  35. ANKI_TESTS_FOO_PRINT();
  36. ++constructorCallCount;
  37. }
  38. Foo(Foo&& b)
  39. : x(b.x)
  40. {
  41. ANKI_TESTS_FOO_PRINT();
  42. b.x = 0;
  43. ++constructorCallCount;
  44. }
  45. ~Foo()
  46. {
  47. ANKI_TESTS_FOO_PRINT();
  48. ++destructorCallCount;
  49. }
  50. Foo& operator=(const Foo& b)
  51. {
  52. ANKI_TESTS_FOO_PRINT();
  53. x = b.x;
  54. return *this;
  55. }
  56. Foo& operator=(Foo&& b)
  57. {
  58. ANKI_TESTS_FOO_PRINT();
  59. x = b.x;
  60. b.x = 0;
  61. return *this;
  62. }
  63. bool operator==(const Foo& b) const
  64. {
  65. return x == b.x;
  66. }
  67. bool operator!=(const Foo& b) const
  68. {
  69. return x != b.x;
  70. }
  71. static void reset()
  72. {
  73. destructorCallCount = constructorCallCount = 0;
  74. }
  75. };