summaryrefslogtreecommitdiff
path: root/absl/container/internal/test_instance_tracker.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container/internal/test_instance_tracker.h')
-rw-r--r--absl/container/internal/test_instance_tracker.h56
1 files changed, 49 insertions, 7 deletions
diff --git a/absl/container/internal/test_instance_tracker.h b/absl/container/internal/test_instance_tracker.h
index b4a84656..060077d0 100644
--- a/absl/container/internal/test_instance_tracker.h
+++ b/absl/container/internal/test_instance_tracker.h
@@ -19,12 +19,12 @@
#include <ostream>
namespace absl {
-inline namespace lts_2018_06_20 {
+inline namespace lts_2018_12_18 {
namespace test_internal {
// A type that counts number of occurences of the type, the live occurrences of
-// the type, as well as the number of copies, moves, and swaps that have
-// occurred on the type. This is used as a base class for the copyable,
+// the type, as well as the number of copies, moves, swaps, and comparisons that
+// have occurred on the type. This is used as a base class for the copyable,
// copyable+movable, and movable types below that are used in actual tests. Use
// InstanceTracker in tests to track the number of instances.
class BaseCountedInstance {
@@ -67,6 +67,36 @@ class BaseCountedInstance {
return *this;
}
+ bool operator==(const BaseCountedInstance& x) const {
+ ++num_comparisons_;
+ return value_ == x.value_;
+ }
+
+ bool operator!=(const BaseCountedInstance& x) const {
+ ++num_comparisons_;
+ return value_ != x.value_;
+ }
+
+ bool operator<(const BaseCountedInstance& x) const {
+ ++num_comparisons_;
+ return value_ < x.value_;
+ }
+
+ bool operator>(const BaseCountedInstance& x) const {
+ ++num_comparisons_;
+ return value_ > x.value_;
+ }
+
+ bool operator<=(const BaseCountedInstance& x) const {
+ ++num_comparisons_;
+ return value_ <= x.value_;
+ }
+
+ bool operator>=(const BaseCountedInstance& x) const {
+ ++num_comparisons_;
+ return value_ >= x.value_;
+ }
+
int value() const {
if (!is_live_) std::abort();
return value_;
@@ -109,6 +139,9 @@ class BaseCountedInstance {
// Number of times that BaseCountedInstance objects were swapped.
static int num_swaps_;
+
+ // Number of times that BaseCountedInstance objects were compared.
+ static int num_comparisons_;
};
// Helper to track the BaseCountedInstance instance counters. Expects that the
@@ -153,13 +186,21 @@ class InstanceTracker {
// construction or the last call to ResetCopiesMovesSwaps().
int swaps() const { return BaseCountedInstance::num_swaps_ - start_swaps_; }
- // Resets the base values for moves, copies and swaps to the current values,
- // so that subsequent Get*() calls for moves, copies and swaps will compare to
- // the situation at the point of this call.
+ // Returns the number of comparisons on BaseCountedInstance objects since
+ // construction or the last call to ResetCopiesMovesSwaps().
+ int comparisons() const {
+ return BaseCountedInstance::num_comparisons_ - start_comparisons_;
+ }
+
+ // Resets the base values for moves, copies, comparisons, and swaps to the
+ // current values, so that subsequent Get*() calls for moves, copies,
+ // comparisons, and swaps will compare to the situation at the point of this
+ // call.
void ResetCopiesMovesSwaps() {
start_moves_ = BaseCountedInstance::num_moves_;
start_copies_ = BaseCountedInstance::num_copies_;
start_swaps_ = BaseCountedInstance::num_swaps_;
+ start_comparisons_ = BaseCountedInstance::num_comparisons_;
}
private:
@@ -168,6 +209,7 @@ class InstanceTracker {
int start_moves_;
int start_copies_;
int start_swaps_;
+ int start_comparisons_;
};
// Copyable, not movable.
@@ -216,7 +258,7 @@ class MovableOnlyInstance : public BaseCountedInstance {
};
} // namespace test_internal
-} // inline namespace lts_2018_06_20
+} // inline namespace lts_2018_12_18
} // namespace absl
#endif // ABSL_CONTAINER_INTERNAL_TEST_INSTANCE_TRACKER_H_