Chromium Code Reviews| 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 class AccountInfoTest : public testing::Test { | |
|
Nicolas Zea
2014/07/28 18:10:10
nit: instead of having a dummy class like this, yo
fgorski
2014/07/29 16:24:02
Done.
| |
| 15 public: | |
| 16 AccountInfoTest(); | |
| 17 virtual ~AccountInfoTest(); | |
| 18 }; | |
| 19 | |
| 20 AccountInfoTest::AccountInfoTest() { | |
| 21 } | |
| 22 | |
| 23 AccountInfoTest::~AccountInfoTest() { | |
| 24 } | |
| 25 | |
| 26 TEST_F(AccountInfoTest, SerializeAccountInfo) { | |
| 27 AccountInfo account_info; | |
| 28 account_info.account_id = "acc_id"; | |
| 29 account_info.email = "test@example.com"; | |
| 30 account_info.last_message_id = "last_message_id_1"; | |
| 31 account_info.last_message_type = AccountInfo::MSG_ADD; | |
| 32 account_info.last_message_timestamp = base::Time::FromInternalValue( | |
| 33 1305797421259935LL); // Arbitrary timestamp. | |
| 34 | |
| 35 EXPECT_EQ("test@example.com&add&last_message_id_1&1305797421259935", | |
| 36 account_info.SerializeAsString()); | |
| 37 | |
| 38 account_info.account_id = "acc_id2"; | |
| 39 account_info.email = "test@gmail.com"; | |
| 40 account_info.last_message_id = "last_message_id_2"; | |
| 41 account_info.last_message_type = AccountInfo::MSG_REMOVE; | |
| 42 account_info.last_message_timestamp = | |
| 43 base::Time::FromInternalValue(1305734521259935LL); // Other timestamp. | |
| 44 | |
| 45 EXPECT_EQ("test@gmail.com&remove&last_message_id_2&1305734521259935", | |
| 46 account_info.SerializeAsString()); | |
| 47 | |
| 48 account_info.last_message_type = AccountInfo::MSG_NONE; | |
| 49 | |
| 50 EXPECT_EQ("test@gmail.com&none", account_info.SerializeAsString()); | |
| 51 } | |
| 52 | |
| 53 TEST_F(AccountInfoTest, DeserializeAccountInfo) { | |
| 54 AccountInfo account_info; | |
| 55 account_info.account_id = "acc_id"; | |
| 56 EXPECT_TRUE(account_info.ParseFromString( | |
| 57 "test@example.com&add&last_message_id_1&1305797421259935")); | |
| 58 EXPECT_EQ("acc_id", account_info.account_id); | |
| 59 EXPECT_EQ("test@example.com", account_info.email); | |
| 60 EXPECT_EQ(AccountInfo::MSG_ADD, account_info.last_message_type); | |
| 61 EXPECT_EQ("last_message_id_1", account_info.last_message_id); | |
| 62 EXPECT_EQ(base::Time::FromInternalValue(1305797421259935LL), | |
| 63 account_info.last_message_timestamp); | |
| 64 | |
| 65 EXPECT_TRUE(account_info.ParseFromString( | |
| 66 "test@gmail.com&remove&last_message_id_2&1305734521259935")); | |
| 67 EXPECT_EQ("acc_id", account_info.account_id); | |
| 68 EXPECT_EQ("test@gmail.com", account_info.email); | |
| 69 EXPECT_EQ(AccountInfo::MSG_REMOVE, account_info.last_message_type); | |
| 70 EXPECT_EQ("last_message_id_2", account_info.last_message_id); | |
| 71 EXPECT_EQ(base::Time::FromInternalValue(1305734521259935LL), | |
| 72 account_info.last_message_timestamp); | |
| 73 | |
| 74 EXPECT_TRUE(account_info.ParseFromString("test@gmail.com&none")); | |
| 75 EXPECT_EQ("acc_id", account_info.account_id); | |
| 76 EXPECT_EQ("test@gmail.com", account_info.email); | |
| 77 EXPECT_EQ(AccountInfo::MSG_NONE, account_info.last_message_type); | |
| 78 EXPECT_EQ("", account_info.last_message_id); | |
| 79 EXPECT_EQ(base::Time(), account_info.last_message_timestamp); | |
| 80 } | |
| 81 | |
|
Nicolas Zea
2014/07/28 18:10:10
maybe add some parsing failure cases?
fgorski
2014/07/29 16:24:02
Done.
| |
| 82 } // namespace | |
| 83 } // namespace gcm | |
| OLD | NEW |