OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SERVICES_FILES_C_TESTS_TEST_UTILS_H_ | |
6 #define SERVICES_FILES_C_TESTS_TEST_UTILS_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <string> | |
12 | |
13 #include "files/public/interfaces/directory.mojom.h" | |
14 #include "files/public/interfaces/file.mojom.h" | |
15 | |
16 namespace mojio { | |
17 namespace test { | |
18 | |
19 // Makes a directory at the given path under the given root directory. | |
20 // (Check-fails on any failure.) | |
21 void MakeDirAt(mojo::files::DirectoryPtr* root, const char* path); | |
22 | |
23 // Opens a file at the given path under the given root directory using the given | |
24 // flags (|mojo::files::kOpenFlag...|). Returns a null |FilePtr| on failure | |
25 // (e.g., if the file doesn't exist and |open_flags| doesn't indicate that it | |
26 // should be created). | |
27 mojo::files::FilePtr OpenFileAt(mojo::files::DirectoryPtr* root, | |
28 const char* path, | |
29 uint32_t open_flags); | |
30 | |
31 // Creates a test file at the given path under the given root directory; the | |
32 // file will be of the given size, with the i-th byte being i mod 256. | |
33 // (Check-fails on any failure.) | |
34 void CreateTestFileAt(mojo::files::DirectoryPtr* root, | |
35 const char* path, | |
36 size_t size); | |
37 | |
38 // Gets the size of the file at the given path under the given root directory. | |
39 // Returns -1 if the file doesn't exist (or can't be opened for some reason), so | |
40 // this may be used to check for a file's existence. | |
41 int64_t GetFileSize(mojo::files::DirectoryPtr* root, const char* path); | |
42 | |
43 // Gets the contents of the file (up to 1 MiB) at the given path under the given | |
44 // root directory. (Check-fails on any failure.) | |
45 std::string GetFileContents(mojo::files::DirectoryPtr* root, const char* path); | |
46 | |
47 } // namespace test | |
48 } // namespace mojio | |
49 | |
50 #endif // SERVICES_FILES_C_TESTS_TEST_UTILS_H_ | |
OLD | NEW |