| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/helium/compound_syncable.h" | 5 #include "blimp/helium/compound_syncable.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "blimp/helium/helium_test.h" |
| 12 #include "blimp/helium/lww_register.h" | 13 #include "blimp/helium/lww_register.h" |
| 13 #include "blimp/helium/revision_generator.h" | 14 #include "blimp/helium/revision_generator.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 17 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
| 17 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 18 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
| 18 | 19 |
| 19 namespace blimp { | 20 namespace blimp { |
| 20 namespace helium { | 21 namespace helium { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class SampleCompoundSyncable : public CompoundSyncable { | 24 class SampleCompoundSyncable : public CompoundSyncable { |
| 24 public: | 25 public: |
| 25 explicit SampleCompoundSyncable(Peer bias, Peer running_as) | 26 explicit SampleCompoundSyncable(Peer bias, Peer running_as) |
| 26 : child1_( | 27 : child1_( |
| 27 CreateAndRegister<LwwRegister<int>>(bias, running_as)), | 28 CreateAndRegister<LwwRegister<int>>(bias, running_as)), |
| 28 child2_( | 29 child2_( |
| 29 CreateAndRegister<LwwRegister<int>>(bias, running_as)) {} | 30 CreateAndRegister<LwwRegister<int>>(bias, running_as)) {} |
| 30 | 31 |
| 31 LwwRegister<int>* mutable_child1() { return child1_.get(); } | 32 LwwRegister<int>* mutable_child1() { return child1_.get(); } |
| 32 LwwRegister<int>* mutable_child2() { return child2_.get(); } | 33 LwwRegister<int>* mutable_child2() { return child2_.get(); } |
| 33 | 34 |
| 34 private: | 35 private: |
| 35 RegisteredMember<LwwRegister<int>> child1_; | 36 RegisteredMember<LwwRegister<int>> child1_; |
| 36 RegisteredMember<LwwRegister<int>> child2_; | 37 RegisteredMember<LwwRegister<int>> child2_; |
| 37 | 38 |
| 38 DISALLOW_COPY_AND_ASSIGN(SampleCompoundSyncable); | 39 DISALLOW_COPY_AND_ASSIGN(SampleCompoundSyncable); |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 class CompoundSyncableTest : public testing::Test { | 42 class CompoundSyncableTest : public HeliumTest { |
| 42 public: | 43 public: |
| 43 CompoundSyncableTest() | 44 CompoundSyncableTest() |
| 44 : last_sync_engine_(0), | 45 : last_sync_engine_(0), |
| 45 engine_(Peer::ENGINE, Peer::ENGINE), | 46 engine_(Peer::ENGINE, Peer::ENGINE), |
| 46 client_(Peer::ENGINE, Peer::CLIENT) {} | 47 client_(Peer::ENGINE, Peer::CLIENT) {} |
| 47 | 48 |
| 48 ~CompoundSyncableTest() override {} | 49 ~CompoundSyncableTest() override {} |
| 49 | 50 |
| 50 protected: | 51 protected: |
| 51 // Propagates pending changes from |engine_| to |client_|. | 52 // Propagates pending changes from |engine_| to |client_|. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 EXPECT_EQ(123, client_.mutable_child1()->Get()); | 106 EXPECT_EQ(123, client_.mutable_child1()->Get()); |
| 106 engine_.mutable_child2()->Set(456); | 107 engine_.mutable_child2()->Set(456); |
| 107 Synchronize(); | 108 Synchronize(); |
| 108 EXPECT_EQ(123, client_.mutable_child1()->Get()); | 109 EXPECT_EQ(123, client_.mutable_child1()->Get()); |
| 109 EXPECT_EQ(456, client_.mutable_child2()->Get()); | 110 EXPECT_EQ(456, client_.mutable_child2()->Get()); |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace | 113 } // namespace |
| 113 } // namespace helium | 114 } // namespace helium |
| 114 } // namespace blimp | 115 } // namespace blimp |
| OLD | NEW |