OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/gdata/gdata_db.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_db.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "chrome/browser/chromeos/gdata/gdata_db_factory.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_db_factory.h" |
9 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 9 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // Tests GDataDB::NewIterator and GDataDBIter::GetNext. | 55 // Tests GDataDB::NewIterator and GDataDBIter::GetNext. |
56 // Creates an iterator with start at |parent|, and iterates comparing with | 56 // Creates an iterator with start at |parent|, and iterates comparing with |
57 // expected |filenames|. | 57 // expected |filenames|. |
58 void TestIter(const std::string& parent, | 58 void TestIter(const std::string& parent, |
59 const char* file_paths[], | 59 const char* file_paths[], |
60 size_t file_paths_size); | 60 size_t file_paths_size); |
61 | 61 |
62 scoped_ptr<TestingProfile> profile_; | 62 scoped_ptr<TestingProfile> profile_; |
63 scoped_ptr<GDataDB> gdata_db_; | 63 scoped_ptr<GDataDB> gdata_db_; |
64 std::set<GDataEntry*> entry_set_; | |
65 }; | 64 }; |
66 | 65 |
67 void GDataDBTest::SetUp() { | 66 void GDataDBTest::SetUp() { |
68 profile_.reset(new TestingProfile()); | 67 profile_.reset(new TestingProfile()); |
69 gdata_db_ = db_factory::CreateGDataDB( | 68 gdata_db_ = db_factory::CreateGDataDB( |
70 profile_->GetPath().Append("testdb")); | 69 profile_->GetPath().Append("testdb")); |
71 } | 70 } |
72 | 71 |
73 void GDataDBTest::TestGetNotFound(const GDataEntry& source) { | 72 void GDataDBTest::TestGetNotFound(const GDataEntry& source) { |
74 scoped_ptr<GDataEntry> entry; | 73 scoped_ptr<GDataEntry> entry; |
(...skipping 20 matching lines...) Expand all Loading... |
95 EXPECT_EQ(GDataDB::DB_OK, status); | 94 EXPECT_EQ(GDataDB::DB_OK, status); |
96 ASSERT_TRUE(entry.get()); | 95 ASSERT_TRUE(entry.get()); |
97 EXPECT_EQ(source.title(), entry->title()); | 96 EXPECT_EQ(source.title(), entry->title()); |
98 EXPECT_EQ(source.resource_id(), entry->resource_id()); | 97 EXPECT_EQ(source.resource_id(), entry->resource_id()); |
99 EXPECT_EQ(source.content_url(), entry->content_url()); | 98 EXPECT_EQ(source.content_url(), entry->content_url()); |
100 } | 99 } |
101 | 100 |
102 void GDataDBTest::InitDB() { | 101 void GDataDBTest::InitDB() { |
103 int sequence_id = 1; | 102 int sequence_id = 1; |
104 GDataRootDirectory root; | 103 GDataRootDirectory root; |
105 GDataDirectory* dir1 = AddDirectory(NULL, &root, sequence_id++); | 104 GDataDirectory* dir1 = AddDirectory(&root, &root, sequence_id++); |
106 GDataDirectory* dir2 = AddDirectory(NULL, &root, sequence_id++); | 105 GDataDirectory* dir2 = AddDirectory(&root, &root, sequence_id++); |
107 GDataDirectory* dir3 = AddDirectory(dir1, &root, sequence_id++); | 106 GDataDirectory* dir3 = AddDirectory(dir1, &root, sequence_id++); |
108 | 107 |
109 AddFile(dir1, &root, sequence_id++); | 108 AddFile(dir1, &root, sequence_id++); |
110 AddFile(dir1, &root, sequence_id++); | 109 AddFile(dir1, &root, sequence_id++); |
111 | 110 |
112 AddFile(dir2, &root, sequence_id++); | 111 AddFile(dir2, &root, sequence_id++); |
113 AddFile(dir2, &root, sequence_id++); | 112 AddFile(dir2, &root, sequence_id++); |
114 AddFile(dir2, &root, sequence_id++); | 113 AddFile(dir2, &root, sequence_id++); |
115 | 114 |
116 AddFile(dir3, &root, sequence_id++); | 115 AddFile(dir3, &root, sequence_id++); |
117 AddFile(dir3, &root, sequence_id++); | 116 AddFile(dir3, &root, sequence_id++); |
118 | |
119 STLDeleteElements(&entry_set_); | |
120 } | 117 } |
121 | 118 |
122 GDataDirectory* GDataDBTest::AddDirectory(GDataDirectory* parent, | 119 GDataDirectory* GDataDBTest::AddDirectory(GDataDirectory* parent, |
123 GDataRootDirectory* root, | 120 GDataRootDirectory* root, |
124 int sequence_id) { | 121 int sequence_id) { |
125 GDataDirectory* dir = new GDataDirectory(parent ? parent : root, root); | 122 GDataDirectory* dir = new GDataDirectory(parent, root); |
126 const std::string dir_name = "dir" + base::IntToString(sequence_id); | 123 const std::string dir_name = "dir" + base::IntToString(sequence_id); |
127 const std::string resource_id = std::string("dir_resource_id:") + | 124 const std::string resource_id = std::string("dir_resource_id:") + |
128 dir_name; | 125 dir_name; |
129 dir->set_title(dir_name); | 126 dir->set_title(dir_name); |
130 dir->set_file_name(dir_name); | |
131 dir->set_resource_id(resource_id); | 127 dir->set_resource_id(resource_id); |
| 128 parent->AddEntry(dir); |
| 129 |
132 GDataDB::Status status = gdata_db_->Put(*dir); | 130 GDataDB::Status status = gdata_db_->Put(*dir); |
133 EXPECT_EQ(GDataDB::DB_OK, status); | 131 EXPECT_EQ(GDataDB::DB_OK, status); |
134 DVLOG(1) << "AddDirectory " << dir->GetFilePath().value() | 132 DVLOG(1) << "AddDirectory " << dir->GetFilePath().value() |
135 << ", " << resource_id; | 133 << ", " << resource_id; |
136 entry_set_.insert(dir); | |
137 return dir; | 134 return dir; |
138 } | 135 } |
139 | 136 |
140 GDataFile* GDataDBTest::AddFile(GDataDirectory* parent, | 137 GDataFile* GDataDBTest::AddFile(GDataDirectory* parent, |
141 GDataRootDirectory* root, | 138 GDataRootDirectory* root, |
142 int sequence_id) { | 139 int sequence_id) { |
143 GDataFile* file = new GDataFile(parent, root); | 140 GDataFile* file = new GDataFile(parent, root); |
144 const std::string title = "file" + base::IntToString(sequence_id); | 141 const std::string title = "file" + base::IntToString(sequence_id); |
145 const std::string resource_id = std::string("file_resource_id:") + | 142 const std::string resource_id = std::string("file_resource_id:") + |
146 title; | 143 title; |
147 file->set_title(title); | 144 file->set_title(title); |
148 file->set_file_name(title); | |
149 file->set_resource_id(resource_id); | 145 file->set_resource_id(resource_id); |
| 146 parent->AddEntry(file); |
| 147 |
150 GDataDB::Status status = gdata_db_->Put(*file); | 148 GDataDB::Status status = gdata_db_->Put(*file); |
151 EXPECT_EQ(GDataDB::DB_OK, status); | 149 EXPECT_EQ(GDataDB::DB_OK, status); |
152 DVLOG(1) << "AddFile " << file->GetFilePath().value() | 150 DVLOG(1) << "AddFile " << file->GetFilePath().value() |
153 << ", " << resource_id; | 151 << ", " << resource_id; |
154 entry_set_.insert(file); | |
155 return file; | 152 return file; |
156 } | 153 } |
157 | 154 |
158 void GDataDBTest::TestIter(const std::string& parent, | 155 void GDataDBTest::TestIter(const std::string& parent, |
159 const char* file_paths[], | 156 const char* file_paths[], |
160 size_t file_paths_size) { | 157 size_t file_paths_size) { |
161 scoped_ptr<GDataDBIter> iter = gdata_db_->CreateIterator( | 158 scoped_ptr<GDataDBIter> iter = gdata_db_->CreateIterator( |
162 FilePath::FromUTF8Unsafe(parent)); | 159 FilePath::FromUTF8Unsafe(parent)); |
163 for (size_t i = 0; ; ++i) { | 160 for (size_t i = 0; ; ++i) { |
164 scoped_ptr<GDataEntry> entry; | 161 scoped_ptr<GDataEntry> entry; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 "drive/dir2/file6", | 268 "drive/dir2/file6", |
272 "drive/dir2/file7", | 269 "drive/dir2/file7", |
273 "drive/dir2/file8", | 270 "drive/dir2/file8", |
274 }; | 271 }; |
275 TestIter("", all_entries, arraysize(all_entries)); | 272 TestIter("", all_entries, arraysize(all_entries)); |
276 | 273 |
277 TestIter("dir4", NULL, 0); | 274 TestIter("dir4", NULL, 0); |
278 } | 275 } |
279 | 276 |
280 } // namespace gdata | 277 } // namespace gdata |
OLD | NEW |