| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    1 // Copyright 2014 The Chromium 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 <vector> |    5 #include <vector> | 
|    6  |    6  | 
|    7 #include "base/scoped_generic.h" |    7 #include "base/scoped_generic.h" | 
|    8 #include "testing/gtest/include/gtest/gtest.h" |    8 #include "testing/gtest/include/gtest/gtest.h" | 
|    9  |    9  | 
|   10 namespace base { |   10 namespace base { | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   78     EXPECT_TRUE(values_freed.empty());  // Nothing should be freed. |   78     EXPECT_TRUE(values_freed.empty());  // Nothing should be freed. | 
|   79     EXPECT_EQ(kSecond, a.get()); |   79     EXPECT_EQ(kSecond, a.get()); | 
|   80     EXPECT_EQ(kFirst, b.get()); |   80     EXPECT_EQ(kFirst, b.get()); | 
|   81   } |   81   } | 
|   82   // Values should be deleted in the opposite order. |   82   // Values should be deleted in the opposite order. | 
|   83   ASSERT_EQ(2u, values_freed.size()); |   83   ASSERT_EQ(2u, values_freed.size()); | 
|   84   EXPECT_EQ(kFirst, values_freed[0]); |   84   EXPECT_EQ(kFirst, values_freed[0]); | 
|   85   EXPECT_EQ(kSecond, values_freed[1]); |   85   EXPECT_EQ(kSecond, values_freed[1]); | 
|   86   values_freed.clear(); |   86   values_freed.clear(); | 
|   87  |   87  | 
|   88   // Pass. |   88   // Pass constructor. | 
|   89   { |   89   { | 
|   90     ScopedInt a(kFirst, traits); |   90     ScopedInt a(kFirst, traits); | 
|   91     ScopedInt b(a.Pass()); |   91     ScopedInt b(a.Pass()); | 
|   92     EXPECT_TRUE(values_freed.empty());  // Nothing should be freed. |   92     EXPECT_TRUE(values_freed.empty());  // Nothing should be freed. | 
|   93     ASSERT_EQ(IntTraits::InvalidValue(), a.get()); |   93     ASSERT_EQ(IntTraits::InvalidValue(), a.get()); | 
|   94     ASSERT_EQ(kFirst, b.get()); |   94     ASSERT_EQ(kFirst, b.get()); | 
|   95   } |   95   } | 
 |   96  | 
|   96   ASSERT_EQ(1u, values_freed.size()); |   97   ASSERT_EQ(1u, values_freed.size()); | 
|   97   ASSERT_EQ(kFirst, values_freed[0]); |   98   ASSERT_EQ(kFirst, values_freed[0]); | 
 |   99   values_freed.clear(); | 
 |  100  | 
 |  101   // Pass assign. | 
 |  102   { | 
 |  103     ScopedInt a(kFirst, traits); | 
 |  104     ScopedInt b(kSecond, traits); | 
 |  105     b = a.Pass(); | 
 |  106     ASSERT_EQ(1u, values_freed.size()); | 
 |  107     EXPECT_EQ(kSecond, values_freed[0]); | 
 |  108     ASSERT_EQ(IntTraits::InvalidValue(), a.get()); | 
 |  109     ASSERT_EQ(kFirst, b.get()); | 
 |  110   } | 
 |  111  | 
 |  112   ASSERT_EQ(2u, values_freed.size()); | 
 |  113   EXPECT_EQ(kFirst, values_freed[1]); | 
 |  114   values_freed.clear(); | 
|   98 } |  115 } | 
|   99  |  116  | 
|  100 TEST(ScopedGenericTest, Operators) { |  117 TEST(ScopedGenericTest, Operators) { | 
|  101   std::vector<int> values_freed; |  118   std::vector<int> values_freed; | 
|  102   IntTraits traits(&values_freed); |  119   IntTraits traits(&values_freed); | 
|  103  |  120  | 
|  104   static const int kFirst = 0; |  121   static const int kFirst = 0; | 
|  105   static const int kSecond = 1; |  122   static const int kSecond = 1; | 
|  106   { |  123   { | 
|  107     ScopedInt a(kFirst, traits); |  124     ScopedInt a(kFirst, traits); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  144  |  161  | 
|  145   // Implicit conversion to bool shouldn't work. |  162   // Implicit conversion to bool shouldn't work. | 
|  146   /*{ |  163   /*{ | 
|  147     ScopedInt a(kFirst, traits); |  164     ScopedInt a(kFirst, traits); | 
|  148     bool result = a; |  165     bool result = a; | 
|  149   }*/ |  166   }*/ | 
|  150 } |  167 } | 
|  151 #endif |  168 #endif | 
|  152  |  169  | 
|  153 }  // namespace base |  170 }  // namespace base | 
| OLD | NEW |