Index: google_apis/gcm/engine/account_info_unittest.cc |
diff --git a/google_apis/gcm/engine/account_info_unittest.cc b/google_apis/gcm/engine/account_info_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0d8c7d3cb44e453ea4bdbc1e07df04e9e8fe618a |
--- /dev/null |
+++ b/google_apis/gcm/engine/account_info_unittest.cc |
@@ -0,0 +1,83 @@ |
+// Copyright 2014 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 <string> |
+ |
+#include "google_apis/gcm/engine/account_info.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace gcm { |
+ |
+namespace { |
+ |
+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.
|
+ public: |
+ AccountInfoTest(); |
+ virtual ~AccountInfoTest(); |
+}; |
+ |
+AccountInfoTest::AccountInfoTest() { |
+} |
+ |
+AccountInfoTest::~AccountInfoTest() { |
+} |
+ |
+TEST_F(AccountInfoTest, SerializeAccountInfo) { |
+ AccountInfo account_info; |
+ account_info.account_id = "acc_id"; |
+ account_info.email = "test@example.com"; |
+ account_info.last_message_id = "last_message_id_1"; |
+ account_info.last_message_type = AccountInfo::MSG_ADD; |
+ account_info.last_message_timestamp = base::Time::FromInternalValue( |
+ 1305797421259935LL); // Arbitrary timestamp. |
+ |
+ EXPECT_EQ("test@example.com&add&last_message_id_1&1305797421259935", |
+ account_info.SerializeAsString()); |
+ |
+ account_info.account_id = "acc_id2"; |
+ account_info.email = "test@gmail.com"; |
+ account_info.last_message_id = "last_message_id_2"; |
+ account_info.last_message_type = AccountInfo::MSG_REMOVE; |
+ account_info.last_message_timestamp = |
+ base::Time::FromInternalValue(1305734521259935LL); // Other timestamp. |
+ |
+ EXPECT_EQ("test@gmail.com&remove&last_message_id_2&1305734521259935", |
+ account_info.SerializeAsString()); |
+ |
+ account_info.last_message_type = AccountInfo::MSG_NONE; |
+ |
+ EXPECT_EQ("test@gmail.com&none", account_info.SerializeAsString()); |
+} |
+ |
+TEST_F(AccountInfoTest, DeserializeAccountInfo) { |
+ AccountInfo account_info; |
+ account_info.account_id = "acc_id"; |
+ EXPECT_TRUE(account_info.ParseFromString( |
+ "test@example.com&add&last_message_id_1&1305797421259935")); |
+ EXPECT_EQ("acc_id", account_info.account_id); |
+ EXPECT_EQ("test@example.com", account_info.email); |
+ EXPECT_EQ(AccountInfo::MSG_ADD, account_info.last_message_type); |
+ EXPECT_EQ("last_message_id_1", account_info.last_message_id); |
+ EXPECT_EQ(base::Time::FromInternalValue(1305797421259935LL), |
+ account_info.last_message_timestamp); |
+ |
+ EXPECT_TRUE(account_info.ParseFromString( |
+ "test@gmail.com&remove&last_message_id_2&1305734521259935")); |
+ EXPECT_EQ("acc_id", account_info.account_id); |
+ EXPECT_EQ("test@gmail.com", account_info.email); |
+ EXPECT_EQ(AccountInfo::MSG_REMOVE, account_info.last_message_type); |
+ EXPECT_EQ("last_message_id_2", account_info.last_message_id); |
+ EXPECT_EQ(base::Time::FromInternalValue(1305734521259935LL), |
+ account_info.last_message_timestamp); |
+ |
+ EXPECT_TRUE(account_info.ParseFromString("test@gmail.com&none")); |
+ EXPECT_EQ("acc_id", account_info.account_id); |
+ EXPECT_EQ("test@gmail.com", account_info.email); |
+ EXPECT_EQ(AccountInfo::MSG_NONE, account_info.last_message_type); |
+ EXPECT_EQ("", account_info.last_message_id); |
+ EXPECT_EQ(base::Time(), account_info.last_message_timestamp); |
+} |
+ |
Nicolas Zea
2014/07/28 18:10:10
maybe add some parsing failure cases?
fgorski
2014/07/29 16:24:02
Done.
|
+} // namespace |
+} // namespace gcm |