testsuite_allocator.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // -*- C++ -*-
  2. // Testing allocator for the C++ library testsuite.
  3. //
  4. // Copyright (C) 2002-2022 Free Software Foundation, Inc.
  5. //
  6. // This file is part of the GNU ISO C++ Library. This library is free
  7. // software; you can redistribute it and/or modify it under the
  8. // terms of the GNU General Public License as published by the
  9. // Free Software Foundation; either version 3, or (at your option)
  10. // any later version.
  11. //
  12. // This library is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License along
  18. // with this library; see the file COPYING3. If not see
  19. // <http://www.gnu.org/licenses/>.
  20. //
  21. #include <iostream>
  22. #include <testsuite_allocator.h>
  23. namespace __gnu_test
  24. {
  25. typedef tracker_allocator_counter counter_type;
  26. counter_type::size_type
  27. counter_type::allocationCount_ = 0;
  28. counter_type::size_type
  29. counter_type::deallocationCount_ = 0;
  30. int counter_type::constructCount_ = 0;
  31. int counter_type::destructCount_ = 0;
  32. bool
  33. check_construct_destroy(const char* tag, int expected_c, int expected_d)
  34. {
  35. bool ret = true;
  36. if (counter_type::get_construct_count() != expected_c
  37. || counter_type::get_destruct_count() != expected_d)
  38. {
  39. std::cerr << tag << ": "
  40. << " construct = " << counter_type::get_construct_count()
  41. << " (should be " << expected_c << "),"
  42. << " destroy = " << counter_type::get_destruct_count()
  43. << " (should be " << expected_d << ")"
  44. << std::endl;
  45. ret = false;
  46. }
  47. return ret;
  48. }
  49. } // namespace __cxx_test