| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/internal_api/public/util/immutable.h" | 5 #include "sync/internal_api/public/util/immutable.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <list> | 10 #include <list> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace csync { | 19 namespace syncer { |
| 20 | 20 |
| 21 // Helper class that keeps track of the token passed in at | 21 // Helper class that keeps track of the token passed in at |
| 22 // construction and how many times that token is copied. | 22 // construction and how many times that token is copied. |
| 23 class TokenCore : public base::RefCounted<TokenCore> { | 23 class TokenCore : public base::RefCounted<TokenCore> { |
| 24 public: | 24 public: |
| 25 explicit TokenCore(const char* token) : token_(token), copy_count_(0) {} | 25 explicit TokenCore(const char* token) : token_(token), copy_count_(0) {} |
| 26 | 26 |
| 27 const char* GetToken() const { return token_; } | 27 const char* GetToken() const { return token_; } |
| 28 | 28 |
| 29 void RecordCopy() { ++copy_count_; } | 29 void RecordCopy() { ++copy_count_; } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 typedef TokenBase<USE_DEFAULT_SWAP> Token; | 97 typedef TokenBase<USE_DEFAULT_SWAP> Token; |
| 98 typedef TokenBase<USE_FAST_SWAP_VIA_ADL> ADLToken; | 98 typedef TokenBase<USE_FAST_SWAP_VIA_ADL> ADLToken; |
| 99 typedef TokenBase<USE_FAST_SWAP_VIA_SPECIALIZATION> SpecializationToken; | 99 typedef TokenBase<USE_FAST_SWAP_VIA_SPECIALIZATION> SpecializationToken; |
| 100 | 100 |
| 101 void swap(ADLToken& t1, ADLToken& t2) { | 101 void swap(ADLToken& t1, ADLToken& t2) { |
| 102 t1.Swap(&t2); | 102 t1.Swap(&t2); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace csync | 105 } // namespace syncer |
| 106 | 106 |
| 107 // Allowed by the standard (17.4.3.1/1). | 107 // Allowed by the standard (17.4.3.1/1). |
| 108 namespace std { | 108 namespace std { |
| 109 | 109 |
| 110 template <> | 110 template <> |
| 111 void swap(csync::SpecializationToken& t1, | 111 void swap(syncer::SpecializationToken& t1, |
| 112 csync::SpecializationToken& t2) { | 112 syncer::SpecializationToken& t2) { |
| 113 t1.Swap(&t2); | 113 t1.Swap(&t2); |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 namespace csync { | 118 namespace syncer { |
| 119 namespace { | 119 namespace { |
| 120 | 120 |
| 121 class ImmutableTest : public ::testing::Test {}; | 121 class ImmutableTest : public ::testing::Test {}; |
| 122 | 122 |
| 123 TEST_F(ImmutableTest, Int) { | 123 TEST_F(ImmutableTest, Int) { |
| 124 int x = 5; | 124 int x = 5; |
| 125 Immutable<int> ix(&x); | 125 Immutable<int> ix(&x); |
| 126 EXPECT_EQ(5, ix.Get()); | 126 EXPECT_EQ(5, ix.Get()); |
| 127 EXPECT_EQ(0, x); | 127 EXPECT_EQ(0, x); |
| 128 } | 128 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 RunTokenContainerTest<std::list<Token>, Immutable<std::list<Token> > >( | 240 RunTokenContainerTest<std::list<Token>, Immutable<std::list<Token> > >( |
| 241 "List"); | 241 "List"); |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(ImmutableTest, Set) { | 244 TEST_F(ImmutableTest, Set) { |
| 245 RunTokenContainerTest<std::set<Token>, Immutable<std::set<Token> > >( | 245 RunTokenContainerTest<std::set<Token>, Immutable<std::set<Token> > >( |
| 246 "Set"); | 246 "Set"); |
| 247 } | 247 } |
| 248 | 248 |
| 249 } // namespace | 249 } // namespace |
| 250 } // namespace csync | 250 } // namespace syncer |
| OLD | NEW |