Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / cpp / test / null_storage_test.cc
1 // Copyright (C) 2014 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 <libaddressinput/null_storage.h>
16
17 #include <libaddressinput/callback.h>
18 #include <libaddressinput/storage.h>
19 #include <libaddressinput/util/basictypes.h>
20 #include <libaddressinput/util/scoped_ptr.h>
21
22 #include <cstddef>
23 #include <string>
24
25 #include <gtest/gtest.h>
26
27 namespace {
28
29 using i18n::addressinput::BuildCallback;
30 using i18n::addressinput::NullStorage;
31 using i18n::addressinput::scoped_ptr;
32 using i18n::addressinput::Storage;
33
34 class NullStorageTest : public testing::Test {
35  protected:
36   NullStorageTest()
37       : data_ready_(BuildCallback(this, &NullStorageTest::OnDataReady)) {}
38
39   NullStorage storage_;
40   bool success_;
41   std::string key_;
42   std::string data_;
43   const scoped_ptr<const Storage::Callback> data_ready_;
44
45   static const char kKey[];
46
47  private:
48   void OnDataReady(bool success, const std::string& key, std::string* data) {
49     ASSERT_FALSE(success && data == NULL);
50     success_ = success;
51     key_ = key;
52     if (data != NULL) {
53       data_ = *data;
54       delete data;
55     }
56   }
57
58   DISALLOW_COPY_AND_ASSIGN(NullStorageTest);
59 };
60
61 const char NullStorageTest::kKey[] = "foo";
62
63 TEST_F(NullStorageTest, Put) {
64   // The Put() method should not do anything, so this test only tests that the
65   // code compiles and that the call doesn't crash.
66   storage_.Put(kKey, new std::string("bar"));
67 }
68
69 TEST_F(NullStorageTest, Get) {
70   storage_.Get(kKey, *data_ready_);
71   EXPECT_FALSE(success_);
72   EXPECT_EQ(kKey, key_);
73   EXPECT_TRUE(data_.empty());
74 }
75
76 }  // namespace