| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gcm/base/mcs_util.h" | 5 #include "google_apis/gcm/base/mcs_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 scoped_ptr<google::protobuf::MessageLite> protobuf = | 35 scoped_ptr<google::protobuf::MessageLite> protobuf = |
| 36 BuildProtobufFromTag(i); | 36 BuildProtobufFromTag(i); |
| 37 if (!protobuf.get()) // Not all tags have protobuf definitions. | 37 if (!protobuf.get()) // Not all tags have protobuf definitions. |
| 38 continue; | 38 continue; |
| 39 ASSERT_EQ((int)i, GetMCSProtoTag(*protobuf)) << "Type " << i; | 39 ASSERT_EQ((int)i, GetMCSProtoTag(*protobuf)) << "Type " << i; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Test getting and setting persistent ids. | 43 // Test getting and setting persistent ids. |
| 44 TEST(MCSUtilTest, PersistentIds) { | 44 TEST(MCSUtilTest, PersistentIds) { |
| 45 COMPILE_ASSERT(kNumProtoTypes == 16U, UpdatePersistentIds); | 45 static_assert(kNumProtoTypes == 16U, "Update Persistent Ids"); |
| 46 const int kTagsWithPersistentIds[] = { | 46 const int kTagsWithPersistentIds[] = { |
| 47 kIqStanzaTag, | 47 kIqStanzaTag, |
| 48 kDataMessageStanzaTag | 48 kDataMessageStanzaTag |
| 49 }; | 49 }; |
| 50 for (size_t i = 0; i < arraysize(kTagsWithPersistentIds); ++i) { | 50 for (size_t i = 0; i < arraysize(kTagsWithPersistentIds); ++i) { |
| 51 int tag = kTagsWithPersistentIds[i]; | 51 int tag = kTagsWithPersistentIds[i]; |
| 52 scoped_ptr<google::protobuf::MessageLite> protobuf = | 52 scoped_ptr<google::protobuf::MessageLite> protobuf = |
| 53 BuildProtobufFromTag(tag); | 53 BuildProtobufFromTag(tag); |
| 54 ASSERT_TRUE(protobuf.get()); | 54 ASSERT_TRUE(protobuf.get()); |
| 55 SetPersistentId(base::IntToString(tag), protobuf.get()); | 55 SetPersistentId(base::IntToString(tag), protobuf.get()); |
| 56 int get_val = 0; | 56 int get_val = 0; |
| 57 base::StringToInt(GetPersistentId(*protobuf), &get_val); | 57 base::StringToInt(GetPersistentId(*protobuf), &get_val); |
| 58 ASSERT_EQ(tag, get_val); | 58 ASSERT_EQ(tag, get_val); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Test getting and setting stream ids. | 62 // Test getting and setting stream ids. |
| 63 TEST(MCSUtilTest, StreamIds) { | 63 TEST(MCSUtilTest, StreamIds) { |
| 64 COMPILE_ASSERT(kNumProtoTypes == 16U, UpdateStreamIds); | 64 static_assert(kNumProtoTypes == 16U, "Update Stream Ids"); |
| 65 const int kTagsWithStreamIds[] = { | 65 const int kTagsWithStreamIds[] = { |
| 66 kIqStanzaTag, | 66 kIqStanzaTag, |
| 67 kDataMessageStanzaTag, | 67 kDataMessageStanzaTag, |
| 68 kHeartbeatPingTag, | 68 kHeartbeatPingTag, |
| 69 kHeartbeatAckTag, | 69 kHeartbeatAckTag, |
| 70 kLoginResponseTag, | 70 kLoginResponseTag, |
| 71 }; | 71 }; |
| 72 for (size_t i = 0; i < arraysize(kTagsWithStreamIds); ++i) { | 72 for (size_t i = 0; i < arraysize(kTagsWithStreamIds); ++i) { |
| 73 int tag = kTagsWithStreamIds[i]; | 73 int tag = kTagsWithStreamIds[i]; |
| 74 scoped_ptr<google::protobuf::MessageLite> protobuf = | 74 scoped_ptr<google::protobuf::MessageLite> protobuf = |
| 75 BuildProtobufFromTag(tag); | 75 BuildProtobufFromTag(tag); |
| 76 ASSERT_TRUE(protobuf.get()); | 76 ASSERT_TRUE(protobuf.get()); |
| 77 SetLastStreamIdReceived(tag, protobuf.get()); | 77 SetLastStreamIdReceived(tag, protobuf.get()); |
| 78 int get_id = GetLastStreamIdReceived(*protobuf); | 78 int get_id = GetLastStreamIdReceived(*protobuf); |
| 79 ASSERT_EQ(tag, get_id); | 79 ASSERT_EQ(tag, get_id); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace | 83 } // namespace |
| 84 } // namespace gcm | 84 } // namespace gcm |
| OLD | NEW |