OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 <string> |
| 6 |
| 7 #include "google_apis/gcm/engine/account_info.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace gcm { |
| 11 |
| 12 namespace { |
| 13 |
| 14 TEST(AccountInfoTest, SerializeAccountInfo) { |
| 15 AccountInfo account_info; |
| 16 account_info.account_id = "acc_id"; |
| 17 account_info.email = "test@example.com"; |
| 18 account_info.last_message_id = "last_message_id_1"; |
| 19 account_info.last_message_type = AccountInfo::MSG_ADD; |
| 20 account_info.last_message_timestamp = base::Time::FromInternalValue( |
| 21 1305797421259935LL); // Arbitrary timestamp. |
| 22 |
| 23 EXPECT_EQ("test@example.com&add&last_message_id_1&1305797421259935", |
| 24 account_info.SerializeAsString()); |
| 25 |
| 26 account_info.account_id = "acc_id2"; |
| 27 account_info.email = "test@gmail.com"; |
| 28 account_info.last_message_id = "last_message_id_2"; |
| 29 account_info.last_message_type = AccountInfo::MSG_REMOVE; |
| 30 account_info.last_message_timestamp = |
| 31 base::Time::FromInternalValue(1305734521259935LL); // Other timestamp. |
| 32 |
| 33 EXPECT_EQ("test@gmail.com&remove&last_message_id_2&1305734521259935", |
| 34 account_info.SerializeAsString()); |
| 35 |
| 36 account_info.last_message_type = AccountInfo::MSG_NONE; |
| 37 |
| 38 EXPECT_EQ("test@gmail.com&none", account_info.SerializeAsString()); |
| 39 } |
| 40 |
| 41 TEST(AccountInfoTest, DeserializeAccountInfo) { |
| 42 AccountInfo account_info; |
| 43 account_info.account_id = "acc_id"; |
| 44 EXPECT_TRUE(account_info.ParseFromString( |
| 45 "test@example.com&add&last_message_id_1&1305797421259935")); |
| 46 EXPECT_EQ("acc_id", account_info.account_id); |
| 47 EXPECT_EQ("test@example.com", account_info.email); |
| 48 EXPECT_EQ(AccountInfo::MSG_ADD, account_info.last_message_type); |
| 49 EXPECT_EQ("last_message_id_1", account_info.last_message_id); |
| 50 EXPECT_EQ(base::Time::FromInternalValue(1305797421259935LL), |
| 51 account_info.last_message_timestamp); |
| 52 |
| 53 EXPECT_TRUE(account_info.ParseFromString( |
| 54 "test@gmail.com&remove&last_message_id_2&1305734521259935")); |
| 55 EXPECT_EQ("acc_id", account_info.account_id); |
| 56 EXPECT_EQ("test@gmail.com", account_info.email); |
| 57 EXPECT_EQ(AccountInfo::MSG_REMOVE, account_info.last_message_type); |
| 58 EXPECT_EQ("last_message_id_2", account_info.last_message_id); |
| 59 EXPECT_EQ(base::Time::FromInternalValue(1305734521259935LL), |
| 60 account_info.last_message_timestamp); |
| 61 |
| 62 EXPECT_TRUE(account_info.ParseFromString("test@gmail.com&none")); |
| 63 EXPECT_EQ("acc_id", account_info.account_id); |
| 64 EXPECT_EQ("test@gmail.com", account_info.email); |
| 65 EXPECT_EQ(AccountInfo::MSG_NONE, account_info.last_message_type); |
| 66 EXPECT_EQ("", account_info.last_message_id); |
| 67 EXPECT_EQ(base::Time(), account_info.last_message_timestamp); |
| 68 } |
| 69 |
| 70 TEST(AccountInfoTest, DeserializeAccountInfoInvalidInput) { |
| 71 AccountInfo account_info; |
| 72 account_info.account_id = "acc_id"; |
| 73 // Too many agruments. |
| 74 EXPECT_FALSE(account_info.ParseFromString( |
| 75 "test@example.com&add&last_message_id_1&1305797421259935&stuff_here")); |
| 76 // Too few arguments. |
| 77 EXPECT_FALSE(account_info.ParseFromString( |
| 78 "test@example.com&remove&last_message_id_1")); |
| 79 // Too few arguments. |
| 80 EXPECT_FALSE(account_info.ParseFromString( |
| 81 "test@example.com")); |
| 82 // Missing email. |
| 83 EXPECT_FALSE(account_info.ParseFromString( |
| 84 "&remove&last_message_id_2&1305734521259935")); |
| 85 // Missing message type. |
| 86 EXPECT_FALSE(account_info.ParseFromString( |
| 87 "test@gmail.com&&last_message_id_2&1305734521259935")); |
| 88 // Unkown message type. |
| 89 EXPECT_FALSE(account_info.ParseFromString( |
| 90 "test@gmail.com&random&last_message_id_2&1305734521259935")); |
| 91 // Message type is none when message details specified. |
| 92 EXPECT_FALSE(account_info.ParseFromString( |
| 93 "test@gmail.com&none&last_message_id_2&1305734521259935")); |
| 94 // Message type is messed up, but we have no message -- that's OK. |
| 95 EXPECT_TRUE(account_info.ParseFromString( |
| 96 "test@gmail.com&random")); |
| 97 // Missing last message ID. |
| 98 EXPECT_FALSE(account_info.ParseFromString( |
| 99 "test@gmail.com&remove&&1305734521259935")); |
| 100 // Missing last message timestamp. |
| 101 EXPECT_FALSE(account_info.ParseFromString( |
| 102 "test@gmail.com&remove&last_message_id&")); |
| 103 // Last message timestamp not parseable. |
| 104 EXPECT_FALSE(account_info.ParseFromString( |
| 105 "test@gmail.com&remove&last_message_id&asdfjlk")); |
| 106 } |
| 107 |
| 108 } // namespace |
| 109 } // namespace gcm |
OLD | NEW |