Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / google_apis / gcm / base / mcs_message_unittest.cc
blob55ab49d130f91561ba6abdfcd0a34ebb69f894eb
1 // Copyright 2013 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.
5 #include "google_apis/gcm/base/mcs_message.h"
7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "google_apis/gcm/base/mcs_util.h"
10 #include "google_apis/gcm/protocol/mcs.pb.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace gcm {
15 const uint64 kAndroidId = 12345;
16 const uint64 kSecret = 54321;
18 class MCSMessageTest : public testing::Test {
19 public:
20 MCSMessageTest();
21 virtual ~MCSMessageTest();
22 private:
23 base::MessageLoop message_loop_;
26 MCSMessageTest::MCSMessageTest() {
29 MCSMessageTest::~MCSMessageTest() {
32 TEST_F(MCSMessageTest, Invalid) {
33 MCSMessage message;
34 EXPECT_FALSE(message.IsValid());
37 TEST_F(MCSMessageTest, InitInferTag) {
38 scoped_ptr<mcs_proto::LoginRequest> login_request(
39 BuildLoginRequest(kAndroidId, kSecret, ""));
40 scoped_ptr<google::protobuf::MessageLite> login_copy(
41 new mcs_proto::LoginRequest(*login_request));
42 MCSMessage message(*login_copy);
43 login_copy.reset();
44 ASSERT_TRUE(message.IsValid());
45 EXPECT_EQ(kLoginRequestTag, message.tag());
46 EXPECT_EQ(login_request->ByteSize(), message.size());
47 EXPECT_EQ(login_request->SerializeAsString(), message.SerializeAsString());
48 EXPECT_EQ(login_request->SerializeAsString(),
49 message.GetProtobuf().SerializeAsString());
50 login_copy = message.CloneProtobuf();
51 EXPECT_EQ(login_request->SerializeAsString(),
52 login_copy->SerializeAsString());
55 TEST_F(MCSMessageTest, InitWithTag) {
56 scoped_ptr<mcs_proto::LoginRequest> login_request(
57 BuildLoginRequest(kAndroidId, kSecret, ""));
58 scoped_ptr<google::protobuf::MessageLite> login_copy(
59 new mcs_proto::LoginRequest(*login_request));
60 MCSMessage message(kLoginRequestTag, *login_copy);
61 login_copy.reset();
62 ASSERT_TRUE(message.IsValid());
63 EXPECT_EQ(kLoginRequestTag, message.tag());
64 EXPECT_EQ(login_request->ByteSize(), message.size());
65 EXPECT_EQ(login_request->SerializeAsString(), message.SerializeAsString());
66 EXPECT_EQ(login_request->SerializeAsString(),
67 message.GetProtobuf().SerializeAsString());
68 login_copy = message.CloneProtobuf();
69 EXPECT_EQ(login_request->SerializeAsString(),
70 login_copy->SerializeAsString());
73 TEST_F(MCSMessageTest, InitPassOwnership) {
74 scoped_ptr<mcs_proto::LoginRequest> login_request(
75 BuildLoginRequest(kAndroidId, kSecret, ""));
76 scoped_ptr<google::protobuf::MessageLite> login_copy(
77 new mcs_proto::LoginRequest(*login_request));
78 MCSMessage message(kLoginRequestTag,
79 login_copy.PassAs<const google::protobuf::MessageLite>());
80 EXPECT_FALSE(login_copy.get());
81 ASSERT_TRUE(message.IsValid());
82 EXPECT_EQ(kLoginRequestTag, message.tag());
83 EXPECT_EQ(login_request->ByteSize(), message.size());
84 EXPECT_EQ(login_request->SerializeAsString(), message.SerializeAsString());
85 EXPECT_EQ(login_request->SerializeAsString(),
86 message.GetProtobuf().SerializeAsString());
87 login_copy = message.CloneProtobuf();
88 EXPECT_EQ(login_request->SerializeAsString(),
89 login_copy->SerializeAsString());
92 } // namespace gcm