OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/fileapi/test_file_set.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/file_util.h" | |
10 #include "base/logging.h" | |
11 #include "base/platform_file.h" | |
12 #include "base/rand_util.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace fileapi { | |
16 | |
17 namespace test { | |
18 | |
19 const TestCaseRecord kRegularTestCases[] = { | |
20 {true, FILE_PATH_LITERAL("dir a"), 0}, | |
21 {true, FILE_PATH_LITERAL("dir a/dir A"), 0}, | |
22 {true, FILE_PATH_LITERAL("dir a/dir d"), 0}, | |
23 {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0}, | |
24 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir f"), 0}, | |
25 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g"), 0}, | |
26 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0}, | |
27 {true, FILE_PATH_LITERAL("dir b"), 0}, | |
28 {true, FILE_PATH_LITERAL("dir b/dir a"), 0}, | |
29 {true, FILE_PATH_LITERAL("dir c"), 0}, | |
30 {false, FILE_PATH_LITERAL("file 0"), 38}, | |
31 {false, FILE_PATH_LITERAL("file 2"), 60}, | |
32 {false, FILE_PATH_LITERAL("file 3"), 0}, | |
33 {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, | |
34 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, | |
35 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, | |
36 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, | |
37 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, | |
38 }; | |
39 | |
40 const size_t kRegularTestCaseSize = arraysize(kRegularTestCases); | |
41 | |
42 void SetUpOneTestCase(const base::FilePath& root_path, | |
43 const TestCaseRecord& test_case) { | |
44 base::FilePath path = root_path.Append(test_case.path); | |
45 if (test_case.is_directory) { | |
46 ASSERT_TRUE(file_util::CreateDirectory(path)); | |
47 return; | |
48 } | |
49 base::PlatformFileError error_code; | |
50 bool created = false; | |
51 int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS | | |
52 base::PLATFORM_FILE_WRITE; | |
53 base::PlatformFile file_handle = | |
54 base::CreatePlatformFile(path, file_flags, &created, &error_code); | |
55 EXPECT_TRUE(created); | |
56 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); | |
57 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | |
58 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | |
59 if (test_case.data_file_size > 0U) { | |
60 std::string content = base::RandBytesAsString(test_case.data_file_size); | |
61 ASSERT_EQ(static_cast<int>(content.size()), | |
62 file_util::WriteFile(path, content.data(), content.size())); | |
63 } | |
64 } | |
65 | |
66 | |
67 void SetUpRegularTestCases(const base::FilePath& root_path) { | |
68 for (size_t i = 0; i < arraysize(kRegularTestCases); ++i) { | |
69 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i); | |
70 SetUpOneTestCase(root_path, kRegularTestCases[i]); | |
71 } | |
72 } | |
73 | |
74 } // namespace test | |
75 | |
76 } // namespace fileapi | |
OLD | NEW |