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 "chrome/common/media_galleries/pmp_test_helper.h" | 5 #include "chrome/common/media_galleries/pmp_test_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return total; | 52 return total; |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 PmpTestHelper::PmpTestHelper(const std::string& table_name) | 57 PmpTestHelper::PmpTestHelper(const std::string& table_name) |
58 : table_name_(table_name) { | 58 : table_name_(table_name) { |
59 } | 59 } |
60 | 60 |
61 bool PmpTestHelper::Init() { | 61 bool PmpTestHelper::Init() { |
62 if (!temp_dir_.CreateUniqueTempDir() || !temp_dir_.IsValid()) | 62 if (!root_dir_.CreateUniqueTempDir() || |
| 63 !root_dir_.IsValid() || |
| 64 !file_util::CreateDirectory(GetDatabaseDirPath()) || |
| 65 !file_util::CreateDirectory(GetTempDirPath())) { |
63 return false; | 66 return false; |
| 67 } |
64 | 68 |
65 base::FilePath indicator_path = temp_dir_.path().Append( | 69 base::FilePath indicator_path = GetTempDirPath().Append( |
66 base::FilePath::FromUTF8Unsafe(table_name_ + "_0")); | 70 base::FilePath::FromUTF8Unsafe(table_name_ + "_0")); |
67 | 71 |
68 return file_util::WriteFile(indicator_path, NULL, 0) == 0; | 72 return file_util::WriteFile(indicator_path, NULL, 0) == 0; |
69 } | 73 } |
70 | 74 |
| 75 base::FilePath PmpTestHelper::GetDatabaseDirPath() { |
| 76 DCHECK(root_dir_.IsValid()); |
| 77 return root_dir_.path().AppendASCII(kPicasaDatabaseDirName); |
| 78 } |
| 79 |
71 base::FilePath PmpTestHelper::GetTempDirPath() { | 80 base::FilePath PmpTestHelper::GetTempDirPath() { |
72 DCHECK(temp_dir_.IsValid()); | 81 DCHECK(root_dir_.IsValid()); |
73 return temp_dir_.path(); | 82 return root_dir_.path().AppendASCII(kPicasaTempDirName); |
74 } | 83 } |
75 | 84 |
76 template<class T> | 85 template<class T> |
77 bool PmpTestHelper::WriteColumnFileFromVector( | 86 bool PmpTestHelper::WriteColumnFileFromVector( |
78 const std::string& column_name, const PmpFieldType field_type, | 87 const std::string& column_name, const PmpFieldType field_type, |
79 const std::vector<T>& elements_vector) { | 88 const std::vector<T>& elements_vector) { |
80 DCHECK(temp_dir_.IsValid()); | |
81 | |
82 std::string file_name = table_name_ + "_" + column_name + "." + kPmpExtension; | 89 std::string file_name = table_name_ + "_" + column_name + "." + kPmpExtension; |
83 | 90 |
84 base::FilePath path = temp_dir_.path().Append( | 91 base::FilePath path = GetTempDirPath().AppendASCII(file_name); |
85 base::FilePath::FromUTF8Unsafe(file_name)); | |
86 | 92 |
87 std::vector<char> data = PmpTestHelper::MakeHeaderAndBody( | 93 std::vector<char> data = PmpTestHelper::MakeHeaderAndBody( |
88 field_type, elements_vector.size(), elements_vector); | 94 field_type, elements_vector.size(), elements_vector); |
89 | 95 |
90 size_t bytes_written = file_util::WriteFile(path, &data[0], data.size()); | 96 size_t bytes_written = file_util::WriteFile(path, &data[0], data.size()); |
91 return (bytes_written == data.size()); | 97 return (bytes_written == data.size()); |
92 } | 98 } |
93 | 99 |
94 // Explicit Instantiation for all the valid types. | 100 // Explicit Instantiation for all the valid types. |
95 template bool PmpTestHelper::WriteColumnFileFromVector<std::string>( | 101 template bool PmpTestHelper::WriteColumnFileFromVector<std::string>( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint32>( | 151 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint32>( |
146 const PmpFieldType, const uint32, const std::vector<uint32>&); | 152 const PmpFieldType, const uint32, const std::vector<uint32>&); |
147 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<double>( | 153 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<double>( |
148 const PmpFieldType, const uint32, const std::vector<double>&); | 154 const PmpFieldType, const uint32, const std::vector<double>&); |
149 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint8>( | 155 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint8>( |
150 const PmpFieldType, const uint32, const std::vector<uint8>&); | 156 const PmpFieldType, const uint32, const std::vector<uint8>&); |
151 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint64>( | 157 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint64>( |
152 const PmpFieldType, const uint32, const std::vector<uint64>&); | 158 const PmpFieldType, const uint32, const std::vector<uint64>&); |
153 | 159 |
154 } // namespace picasa | 160 } // namespace picasa |
OLD | NEW |