summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-30 22:40:07 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-30 22:40:07 +0000
commitd4e7ca034cbbe29911b08eb5c252aa0d05b6a429 (patch)
tree9620d3988a0d0aee8826c830adc1b8030bbf0b11 /testing
parent3b83e83fbfd24e521f7ecd7ce7f1019769bcaec7 (diff)
downloadpdfium-d4e7ca034cbbe29911b08eb5c252aa0d05b6a429.tar.xz
Add unit test for AutoRestorer<> on smart pointer types.
Test UnownedPtr<> and RetainPtr<>. We cannot operate against std::unique_ptr<> because we need a copyable type. Add test for self-reassignment on going out of scope. Move one test helper class to testing/ so it can be shared among unit tests. Allow it to recognize if it ever gets "destroyed", otherwise we can't be sure Retain/Release applied in the correct order. Change-Id: I13056094c70079f7283cbc7600948f81a64874b4 Reviewed-on: https://pdfium-review.googlesource.com/41690 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'testing')
-rw-r--r--testing/pseudo_retainable.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/testing/pseudo_retainable.h b/testing/pseudo_retainable.h
new file mode 100644
index 0000000000..c4390d697d
--- /dev/null
+++ b/testing/pseudo_retainable.h
@@ -0,0 +1,26 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_PSEUDO_RETAINABLE_H_
+#define TESTING_PSEUDO_RETAINABLE_H_
+
+class PseudoRetainable {
+ public:
+ PseudoRetainable() = default;
+ void Retain() { ++retain_count_; }
+ void Release() {
+ if (++release_count_ == retain_count_)
+ alive_ = false;
+ }
+ bool alive() const { return alive_; }
+ int retain_count() const { return retain_count_; }
+ int release_count() const { return release_count_; }
+
+ private:
+ bool alive_ = true;
+ int retain_count_ = 0;
+ int release_count_ = 0;
+};
+
+#endif // TESTING_PSEUDO_RETAINABLE_H_