Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4147)

Unified Diff: blimp/net/helium/syncable_primitive_serializer_unittest.cc

Issue 2400303002: Add LwwRegister CRDT (Closed)
Patch Set: Refactor Serializer to use overloaded methods and add unit tests. Refactor LwwRegister to not be te… Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/net/helium/syncable_primitive_serializer_unittest.cc
diff --git a/blimp/net/helium/syncable_primitive_serializer_unittest.cc b/blimp/net/helium/syncable_primitive_serializer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e46de1308641adb8edd6ce6177017a4f7fe3c9f1
--- /dev/null
+++ b/blimp/net/helium/syncable_primitive_serializer_unittest.cc
@@ -0,0 +1,79 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/net/helium/syncable_primitive_serializer.h"
+
+#include <string>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/protobuf/src/google/protobuf/io/coded_stream.h"
+#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h"
+
+namespace blimp {
+namespace {
+
+class SyncablePrimitiveSerializerTest : public testing::Test {
+ protected:
+ template <class T>
+ void SerializeBetween(const T& input, T* output) {
+ std::string changeset;
+
+ google::protobuf::io::StringOutputStream raw_output_stream(&changeset);
+ google::protobuf::io::CodedOutputStream output_stream(&raw_output_stream);
+ SyncablePrimitiveSerializer::Serialize(input, &output_stream);
+
+ google::protobuf::io::ArrayInputStream raw_input_stream(changeset.data(),
+ changeset.size());
+ google::protobuf::io::CodedInputStream input_stream(&raw_input_stream);
+ SyncablePrimitiveSerializer::Deserialize(&input_stream, output);
+ }
+};
+
+TEST_F(SyncablePrimitiveSerializerTest, SerializesPositiveInt32) {
+ int32_t input = 123;
+ int32_t output;
+
+ SerializeBetween<int32_t>(input, &output);
Kevin M 2016/10/17 22:19:46 These tests should exercise serializing multiple v
steimel 2016/10/18 23:53:20 Done.
+
+ EXPECT_EQ(123, output);
+}
+
+TEST_F(SyncablePrimitiveSerializerTest, SerializesNegativeInt32) {
+ int32_t input = -456;
+ int32_t output;
+
+ SerializeBetween<int32_t>(input, &output);
+
+ EXPECT_EQ(-456, output);
+}
+
+TEST_F(SyncablePrimitiveSerializerTest, SerializesZeroInt32) {
+ int32_t input = 0;
+ int32_t output;
+
+ SerializeBetween<int32_t>(input, &output);
+
+ EXPECT_EQ(0, output);
+}
+
+TEST_F(SyncablePrimitiveSerializerTest, SerializesString) {
+ std::string input = "Hello, World";
+ std::string output;
+
+ SerializeBetween<std::string>(input, &output);
+
+ EXPECT_EQ("Hello, World", output);
Kevin M 2016/10/17 22:19:46 Why aren't we checking for round tripping inside t
steimel 2016/10/18 23:53:20 Discussed offline. Refactored current templated-he
+}
+
+TEST_F(SyncablePrimitiveSerializerTest, SerializesEmptyString) {
scf 2016/10/17 22:09:51 Create helper methods for testing ints/strings?
steimel 2016/10/18 23:53:20 Done.
+ std::string input = "";
+ std::string output;
+
+ SerializeBetween<std::string>(input, &output);
+
+ EXPECT_EQ("", output);
+}
+
+} // namespace
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698