| Index: third_party/libaddressinput/chromium/cpp/test/wrapper_test.cc
|
| diff --git a/third_party/libaddressinput/chromium/cpp/test/wrapper_test.cc b/third_party/libaddressinput/chromium/cpp/test/wrapper_test.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b9638a089966832e78a852a0786a44b2f4656940
|
| --- /dev/null
|
| +++ b/third_party/libaddressinput/chromium/cpp/test/wrapper_test.cc
|
| @@ -0,0 +1,78 @@
|
| +// Copyright (C) 2013 Google Inc.
|
| +//
|
| +// Licensed under the Apache License, Version 2.0 (the "License");
|
| +// you may not use this file except in compliance with the License.
|
| +// You may obtain a copy of the License at
|
| +//
|
| +// http://www.apache.org/licenses/LICENSE-2.0
|
| +//
|
| +// Unless required by applicable law or agreed to in writing, software
|
| +// distributed under the License is distributed on an "AS IS" BASIS,
|
| +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| +// See the License for the specific language governing permissions and
|
| +// limitations under the License.
|
| +
|
| +#include "wrapper.h"
|
| +
|
| +#include <cstddef>
|
| +#include <ctime>
|
| +#include <string>
|
| +
|
| +#include <gtest/gtest.h>
|
| +
|
| +#include "time_to_string.h"
|
| +
|
| +namespace {
|
| +
|
| +using i18n::addressinput::TimeToString;
|
| +using i18n::addressinput::Wrapper;
|
| +
|
| +static const char kData[] = "{'foo': 'bar'}";
|
| +static const char kChecksum[] = "dd63dafcbd4d5b28badfcaf86fb6fcdb";
|
| +
|
| +TEST(WrapperTest, UnwrappedDataSameAsOriginal) {
|
| + std::string data = Wrapper::Wrap(kData);
|
| + EXPECT_NE(kData, data);
|
| + double age_in_seconds = 0.0;
|
| + EXPECT_TRUE(Wrapper::Unwrap(&data, &age_in_seconds));
|
| + EXPECT_EQ(kData, data);
|
| +}
|
| +
|
| +TEST(WrapperTest, OldTimestampReturnsTrue) {
|
| + std::string negative_timestamp = std::string("timestamp=0\nchecksum=") +
|
| + kChecksum + "\n" + kData;
|
| + double age_in_seconds = 0.0;
|
| + EXPECT_TRUE(Wrapper::Unwrap(&negative_timestamp, &age_in_seconds));
|
| +}
|
| +
|
| +TEST(WrapperTest, WrongChecksumReturnsFalse) {
|
| + std::string wrong_checksum = std::string("timestamp=123\nchecksum=123\n") +
|
| + kData;
|
| + double age_in_seconds = 0.0;
|
| + EXPECT_FALSE(Wrapper::Unwrap(&wrong_checksum, &age_in_seconds));
|
| +}
|
| +
|
| +TEST(WrapperTest, NoDataReturnsFalse) {
|
| + std::string no_data = "timestamp=123";
|
| + double age_in_seconds = 0.0;
|
| + EXPECT_FALSE(Wrapper::Unwrap(&no_data, &age_in_seconds));
|
| + no_data = std::string("timestamp=123\nchecksum=") + kChecksum;
|
| + EXPECT_FALSE(Wrapper::Unwrap(&no_data, &age_in_seconds));
|
| +}
|
| +
|
| +TEST(WrapperTest, NegativeTimestampReturnsFalse) {
|
| + std::string negative_timestamp = std::string("timestamp=-1\nchecksum=") +
|
| + kChecksum + "\n" + kData;
|
| + double age_in_seconds = 0.0;
|
| + EXPECT_FALSE(Wrapper::Unwrap(&negative_timestamp, &age_in_seconds));
|
| +}
|
| +
|
| +TEST(WrapperTest, FutureTimestampReturnsFalse) {
|
| + std::string future_timestamp = "timestamp=" +
|
| + TimeToString(time(NULL) + 10000) + "\nchecksum=" + kChecksum + "\n" +
|
| + kData;
|
| + double age_in_seconds = 0.0;
|
| + EXPECT_FALSE(Wrapper::Unwrap(&future_timestamp, &age_in_seconds));
|
| +}
|
| +
|
| +} // namespace
|
|
|