SingletonTestStructs.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2015-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <memory>
  18. #include <stdexcept>
  19. #include <vector>
  20. #include <glog/logging.h>
  21. #include <folly/portability/GTest.h>
  22. struct Watchdog {
  23. static std::vector<Watchdog*>& creation_order();
  24. Watchdog();
  25. ~Watchdog() {
  26. if (creation_order().back() != this) {
  27. LOG(FATAL) << "Watchdog destruction order mismatch";
  28. }
  29. creation_order().pop_back();
  30. }
  31. const size_t serial_number;
  32. size_t livingWatchdogCount() const {
  33. return creation_order().size();
  34. }
  35. Watchdog(const Watchdog&) = delete;
  36. Watchdog& operator=(const Watchdog&) = delete;
  37. Watchdog(Watchdog&&) noexcept = default;
  38. Watchdog& operator=(Watchdog&&) noexcept = default;
  39. };
  40. // Some basic types we use for tracking.
  41. struct ChildWatchdog : public Watchdog {};
  42. struct GlobalWatchdog : public Watchdog {};
  43. struct UnregisteredWatchdog : public Watchdog {};