Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: third_party/libaddressinput/chromium/cpp/test/wrapper_test.cc

Issue 144353002: [rac] Use stale libaddressinput data if download fails (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (C) 2013 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "wrapper.h"
16
17 #include <cstddef>
18 #include <ctime>
19 #include <string>
20
21 #include <gtest/gtest.h>
22
23 #include "time_to_string.h"
24
25 namespace {
26
27 using i18n::addressinput::TimeToString;
28 using i18n::addressinput::Wrapper;
29
30 static const char kData[] = "{'foo': 'bar'}";
31 static const char kChecksum[] = "dd63dafcbd4d5b28badfcaf86fb6fcdb";
32
33 TEST(WrapperTest, UnwrappedDataSameAsOriginal) {
34 std::string data = Wrapper::Wrap(kData);
35 EXPECT_NE(kData, data);
36 double age_in_seconds = 0.0;
37 EXPECT_TRUE(Wrapper::Unwrap(&data, &age_in_seconds));
38 EXPECT_EQ(kData, data);
39 }
40
41 TEST(WrapperTest, OldTimestampReturnsTrue) {
42 std::string negative_timestamp = std::string("timestamp=0\nchecksum=") +
43 kChecksum + "\n" + kData;
44 double age_in_seconds = 0.0;
45 EXPECT_TRUE(Wrapper::Unwrap(&negative_timestamp, &age_in_seconds));
46 }
47
48 TEST(WrapperTest, WrongChecksumReturnsFalse) {
49 std::string wrong_checksum = std::string("timestamp=123\nchecksum=123\n") +
50 kData;
51 double age_in_seconds = 0.0;
52 EXPECT_FALSE(Wrapper::Unwrap(&wrong_checksum, &age_in_seconds));
53 }
54
55 TEST(WrapperTest, NoDataReturnsFalse) {
56 std::string no_data = "timestamp=123";
57 double age_in_seconds = 0.0;
58 EXPECT_FALSE(Wrapper::Unwrap(&no_data, &age_in_seconds));
59 no_data = std::string("timestamp=123\nchecksum=") + kChecksum;
60 EXPECT_FALSE(Wrapper::Unwrap(&no_data, &age_in_seconds));
61 }
62
63 TEST(WrapperTest, NegativeTimestampReturnsFalse) {
64 std::string negative_timestamp = std::string("timestamp=-1\nchecksum=") +
65 kChecksum + "\n" + kData;
66 double age_in_seconds = 0.0;
67 EXPECT_FALSE(Wrapper::Unwrap(&negative_timestamp, &age_in_seconds));
68 }
69
70 TEST(WrapperTest, FutureTimestampReturnsFalse) {
71 std::string future_timestamp = "timestamp=" +
72 TimeToString(time(NULL) + 10000) + "\nchecksum=" + kChecksum + "\n" +
73 kData;
74 double age_in_seconds = 0.0;
75 EXPECT_FALSE(Wrapper::Unwrap(&future_timestamp, &age_in_seconds));
76 }
77
78 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698