| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fxcrt/include/cfx_count_ref.h" | 5 #include "core/fxcrt/include/cfx_count_ref.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "testing/fx_string_testhelpers.h" | 10 #include "testing/fx_string_testhelpers.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 { | 51 { |
| 52 CFX_CountRef<Object> ptr; | 52 CFX_CountRef<Object> ptr; |
| 53 EXPECT_EQ(nullptr, ptr.GetObject()); | 53 EXPECT_EQ(nullptr, ptr.GetObject()); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 TEST(fxcrt, CountRefCopy) { | 57 TEST(fxcrt, CountRefCopy) { |
| 58 Observer observer; | 58 Observer observer; |
| 59 { | 59 { |
| 60 CFX_CountRef<Object> ptr1; | 60 CFX_CountRef<Object> ptr1; |
| 61 ptr1.New(&observer, std::string("one")); | 61 ptr1.Emplace(&observer, std::string("one")); |
| 62 { | 62 { |
| 63 CFX_CountRef<Object> ptr2 = ptr1; | 63 CFX_CountRef<Object> ptr2 = ptr1; |
| 64 EXPECT_EQ(1, observer.GetConstructionCount("one")); | 64 EXPECT_EQ(1, observer.GetConstructionCount("one")); |
| 65 EXPECT_EQ(0, observer.GetDestructionCount("one")); | 65 EXPECT_EQ(0, observer.GetDestructionCount("one")); |
| 66 } | 66 } |
| 67 { | 67 { |
| 68 CFX_CountRef<Object> ptr3(ptr1); | 68 CFX_CountRef<Object> ptr3(ptr1); |
| 69 EXPECT_EQ(1, observer.GetConstructionCount("one")); | 69 EXPECT_EQ(1, observer.GetConstructionCount("one")); |
| 70 EXPECT_EQ(0, observer.GetDestructionCount("one")); | 70 EXPECT_EQ(0, observer.GetDestructionCount("one")); |
| 71 } | 71 } |
| 72 EXPECT_EQ(1, observer.GetConstructionCount("one")); | 72 EXPECT_EQ(1, observer.GetConstructionCount("one")); |
| 73 EXPECT_EQ(0, observer.GetDestructionCount("one")); | 73 EXPECT_EQ(0, observer.GetDestructionCount("one")); |
| 74 } | 74 } |
| 75 EXPECT_EQ(1, observer.GetDestructionCount("one")); | 75 EXPECT_EQ(1, observer.GetDestructionCount("one")); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST(fxcrt, CountRefAssignOverOld) { | 78 TEST(fxcrt, CountRefAssignOverOld) { |
| 79 Observer observer; | 79 Observer observer; |
| 80 { | 80 { |
| 81 CFX_CountRef<Object> ptr1; | 81 CFX_CountRef<Object> ptr1; |
| 82 ptr1.New(&observer, std::string("one")); | 82 ptr1.Emplace(&observer, std::string("one")); |
| 83 ptr1.New(&observer, std::string("two")); | 83 ptr1.Emplace(&observer, std::string("two")); |
| 84 EXPECT_EQ(1, observer.GetConstructionCount("one")); | 84 EXPECT_EQ(1, observer.GetConstructionCount("one")); |
| 85 EXPECT_EQ(1, observer.GetConstructionCount("two")); | 85 EXPECT_EQ(1, observer.GetConstructionCount("two")); |
| 86 EXPECT_EQ(1, observer.GetDestructionCount("one")); | 86 EXPECT_EQ(1, observer.GetDestructionCount("one")); |
| 87 EXPECT_EQ(0, observer.GetDestructionCount("two")); | 87 EXPECT_EQ(0, observer.GetDestructionCount("two")); |
| 88 } | 88 } |
| 89 EXPECT_EQ(1, observer.GetDestructionCount("two")); | 89 EXPECT_EQ(1, observer.GetDestructionCount("two")); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TEST(fxcrt, CountRefAssignOverRetained) { | 92 TEST(fxcrt, CountRefAssignOverRetained) { |
| 93 Observer observer; | 93 Observer observer; |
| 94 { | 94 { |
| 95 CFX_CountRef<Object> ptr1; | 95 CFX_CountRef<Object> ptr1; |
| 96 ptr1.New(&observer, std::string("one")); | 96 ptr1.Emplace(&observer, std::string("one")); |
| 97 CFX_CountRef<Object> ptr2(ptr1); | 97 CFX_CountRef<Object> ptr2(ptr1); |
| 98 ptr1.New(&observer, std::string("two")); | 98 ptr1.Emplace(&observer, std::string("two")); |
| 99 EXPECT_EQ(1, observer.GetConstructionCount("one")); | 99 EXPECT_EQ(1, observer.GetConstructionCount("one")); |
| 100 EXPECT_EQ(1, observer.GetConstructionCount("two")); | 100 EXPECT_EQ(1, observer.GetConstructionCount("two")); |
| 101 EXPECT_EQ(0, observer.GetDestructionCount("one")); | 101 EXPECT_EQ(0, observer.GetDestructionCount("one")); |
| 102 EXPECT_EQ(0, observer.GetDestructionCount("two")); | 102 EXPECT_EQ(0, observer.GetDestructionCount("two")); |
| 103 } | 103 } |
| 104 EXPECT_EQ(1, observer.GetDestructionCount("one")); | 104 EXPECT_EQ(1, observer.GetDestructionCount("one")); |
| 105 EXPECT_EQ(1, observer.GetDestructionCount("two")); | 105 EXPECT_EQ(1, observer.GetDestructionCount("two")); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST(fxcrt, CountRefGetModify) { | 108 TEST(fxcrt, CountRefGetModify) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 CFX_CountRef<Object> other(ptr); | 120 CFX_CountRef<Object> other(ptr); |
| 121 EXPECT_NE(nullptr, ptr.GetPrivateCopy(&observer, std::string("one"))); | 121 EXPECT_NE(nullptr, ptr.GetPrivateCopy(&observer, std::string("one"))); |
| 122 EXPECT_EQ(2, observer.GetConstructionCount("one")); | 122 EXPECT_EQ(2, observer.GetConstructionCount("one")); |
| 123 EXPECT_EQ(0, observer.GetDestructionCount("one")); | 123 EXPECT_EQ(0, observer.GetDestructionCount("one")); |
| 124 } | 124 } |
| 125 EXPECT_EQ(2, observer.GetConstructionCount("one")); | 125 EXPECT_EQ(2, observer.GetConstructionCount("one")); |
| 126 EXPECT_EQ(1, observer.GetDestructionCount("one")); | 126 EXPECT_EQ(1, observer.GetDestructionCount("one")); |
| 127 } | 127 } |
| 128 EXPECT_EQ(2, observer.GetDestructionCount("one")); | 128 EXPECT_EQ(2, observer.GetDestructionCount("one")); |
| 129 } | 129 } |
| OLD | NEW |