Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/net/helium/syncable_primitive_serializer.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | |
| 11 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite .h" | |
| 12 | |
| 13 namespace blimp { | |
| 14 namespace { | |
| 15 | |
| 16 class SyncablePrimitiveSerializerTest : public testing::Test { | |
| 17 protected: | |
| 18 template <class T> | |
| 19 void SerializeBetween(const T& input, T* output) { | |
| 20 std::string changeset; | |
| 21 | |
| 22 google::protobuf::io::StringOutputStream raw_output_stream(&changeset); | |
| 23 google::protobuf::io::CodedOutputStream output_stream(&raw_output_stream); | |
| 24 SyncablePrimitiveSerializer::Serialize(input, &output_stream); | |
| 25 | |
| 26 google::protobuf::io::ArrayInputStream raw_input_stream(changeset.data(), | |
| 27 changeset.size()); | |
| 28 google::protobuf::io::CodedInputStream input_stream(&raw_input_stream); | |
| 29 SyncablePrimitiveSerializer::Deserialize(&input_stream, output); | |
| 30 } | |
| 31 }; | |
| 32 | |
| 33 TEST_F(SyncablePrimitiveSerializerTest, SerializesPositiveInt32) { | |
| 34 int32_t input = 123; | |
| 35 int32_t output; | |
| 36 | |
| 37 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.
| |
| 38 | |
| 39 EXPECT_EQ(123, output); | |
| 40 } | |
| 41 | |
| 42 TEST_F(SyncablePrimitiveSerializerTest, SerializesNegativeInt32) { | |
| 43 int32_t input = -456; | |
| 44 int32_t output; | |
| 45 | |
| 46 SerializeBetween<int32_t>(input, &output); | |
| 47 | |
| 48 EXPECT_EQ(-456, output); | |
| 49 } | |
| 50 | |
| 51 TEST_F(SyncablePrimitiveSerializerTest, SerializesZeroInt32) { | |
| 52 int32_t input = 0; | |
| 53 int32_t output; | |
| 54 | |
| 55 SerializeBetween<int32_t>(input, &output); | |
| 56 | |
| 57 EXPECT_EQ(0, output); | |
| 58 } | |
| 59 | |
| 60 TEST_F(SyncablePrimitiveSerializerTest, SerializesString) { | |
| 61 std::string input = "Hello, World"; | |
| 62 std::string output; | |
| 63 | |
| 64 SerializeBetween<std::string>(input, &output); | |
| 65 | |
| 66 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
| |
| 67 } | |
| 68 | |
| 69 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.
| |
| 70 std::string input = ""; | |
| 71 std::string output; | |
| 72 | |
| 73 SerializeBetween<std::string>(input, &output); | |
| 74 | |
| 75 EXPECT_EQ("", output); | |
| 76 } | |
| 77 | |
| 78 } // namespace | |
| 79 } // namespace blimp | |
| OLD | NEW |