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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
9 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
12 | 16 |
13 namespace gcm { | 17 namespace gcm { |
14 namespace { | 18 namespace { |
15 | 19 |
16 const uint64 kAuthId = 4421448356646222460; | 20 const uint64_t kAuthId = 4421448356646222460; |
17 const uint64 kAuthToken = 12345; | 21 const uint64_t kAuthToken = 12345; |
18 | 22 |
19 // Build a login request protobuf. | 23 // Build a login request protobuf. |
20 TEST(MCSUtilTest, BuildLoginRequest) { | 24 TEST(MCSUtilTest, BuildLoginRequest) { |
21 scoped_ptr<mcs_proto::LoginRequest> login_request = | 25 scoped_ptr<mcs_proto::LoginRequest> login_request = |
22 BuildLoginRequest(kAuthId, kAuthToken, "1.0"); | 26 BuildLoginRequest(kAuthId, kAuthToken, "1.0"); |
23 ASSERT_EQ("chrome-1.0", login_request->id()); | 27 ASSERT_EQ("chrome-1.0", login_request->id()); |
24 ASSERT_EQ(base::Uint64ToString(kAuthToken), login_request->auth_token()); | 28 ASSERT_EQ(base::Uint64ToString(kAuthToken), login_request->auth_token()); |
25 ASSERT_EQ(base::Uint64ToString(kAuthId), login_request->user()); | 29 ASSERT_EQ(base::Uint64ToString(kAuthId), login_request->user()); |
26 ASSERT_EQ("android-3d5c23dac2a1fa7c", login_request->device_id()); | 30 ASSERT_EQ("android-3d5c23dac2a1fa7c", login_request->device_id()); |
27 ASSERT_EQ("new_vc", login_request->setting(0).name()); | 31 ASSERT_EQ("new_vc", login_request->setting(0).name()); |
28 ASSERT_EQ("1", login_request->setting(0).value()); | 32 ASSERT_EQ("1", login_request->setting(0).value()); |
29 // TODO(zea): test the other fields once they have valid values. | 33 // TODO(zea): test the other fields once they have valid values. |
30 } | 34 } |
31 | 35 |
32 // Test building a protobuf and extracting the tag from a protobuf. | 36 // Test building a protobuf and extracting the tag from a protobuf. |
33 TEST(MCSUtilTest, ProtobufToTag) { | 37 TEST(MCSUtilTest, ProtobufToTag) { |
34 for (uint8 i = 0; i < kNumProtoTypes; ++i) { | 38 for (uint8_t i = 0; i < kNumProtoTypes; ++i) { |
35 scoped_ptr<google::protobuf::MessageLite> protobuf = | 39 scoped_ptr<google::protobuf::MessageLite> protobuf = |
36 BuildProtobufFromTag(i); | 40 BuildProtobufFromTag(i); |
37 if (!protobuf.get()) // Not all tags have protobuf definitions. | 41 if (!protobuf.get()) // Not all tags have protobuf definitions. |
38 continue; | 42 continue; |
39 ASSERT_EQ(i, GetMCSProtoTag(*protobuf)) << "Type " << i; | 43 ASSERT_EQ(i, GetMCSProtoTag(*protobuf)) << "Type " << i; |
40 } | 44 } |
41 } | 45 } |
42 | 46 |
43 // Test getting and setting persistent ids. | 47 // Test getting and setting persistent ids. |
44 TEST(MCSUtilTest, PersistentIds) { | 48 TEST(MCSUtilTest, PersistentIds) { |
(...skipping 30 matching lines...) Expand all Loading... |
75 BuildProtobufFromTag(tag); | 79 BuildProtobufFromTag(tag); |
76 ASSERT_TRUE(protobuf.get()); | 80 ASSERT_TRUE(protobuf.get()); |
77 SetLastStreamIdReceived(tag, protobuf.get()); | 81 SetLastStreamIdReceived(tag, protobuf.get()); |
78 int get_id = GetLastStreamIdReceived(*protobuf); | 82 int get_id = GetLastStreamIdReceived(*protobuf); |
79 ASSERT_EQ(tag, get_id); | 83 ASSERT_EQ(tag, get_id); |
80 } | 84 } |
81 } | 85 } |
82 | 86 |
83 } // namespace | 87 } // namespace |
84 } // namespace gcm | 88 } // namespace gcm |
OLD | NEW |