| 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 #include "files/public/c/tests/test_utils.h" | |
| 6 | |
| 7 #include <errno.h> | |
| 8 | |
| 9 #include "files/public/c/tests/mock_errno_impl.h" | |
| 10 #include "files/public/c/tests/mojio_impl_test_base.h" | |
| 11 #include "files/public/c/tests/test_utils.h" | |
| 12 | |
| 13 namespace mojio { | |
| 14 namespace test { | |
| 15 namespace { | |
| 16 | |
| 17 using TestUtilsTest = mojio::test::MojioImplTestBase; | |
| 18 | |
| 19 TEST_F(TestUtilsTest, MakeDirAt) { | |
| 20 EXPECT_EQ(-1, GetFileSize(&directory(), "my_file")); | |
| 21 EXPECT_EQ(-1, GetFileSize(&directory(), "my_dir/my_file")); | |
| 22 | |
| 23 MakeDirAt(&directory(), "my_dir"); | |
| 24 | |
| 25 EXPECT_EQ(-1, GetFileSize(&directory(), "my_file")); | |
| 26 EXPECT_EQ(-1, GetFileSize(&directory(), "my_dir/my_file")); | |
| 27 | |
| 28 CreateTestFileAt(&directory(), "my_dir/my_file", 123); | |
| 29 | |
| 30 EXPECT_EQ(-1, GetFileSize(&directory(), "my_file")); | |
| 31 EXPECT_EQ(123, GetFileSize(&directory(), "my_dir/my_file")); | |
| 32 } | |
| 33 | |
| 34 TEST_F(TestUtilsTest, OpenFileAt) { | |
| 35 EXPECT_FALSE( | |
| 36 OpenFileAt(&directory(), "nonexistent", mojo::files::kOpenFlagWrite)); | |
| 37 EXPECT_TRUE( | |
| 38 OpenFileAt(&directory(), "created", | |
| 39 mojo::files::kOpenFlagWrite | mojo::files::kOpenFlagCreate)); | |
| 40 EXPECT_TRUE(OpenFileAt(&directory(), "created", mojo::files::kOpenFlagRead)); | |
| 41 } | |
| 42 | |
| 43 TEST_F(TestUtilsTest, CreateTestFileAtGetFileSizeGetFileContents) { | |
| 44 CreateTestFileAt(&directory(), "file_0", 0); | |
| 45 CreateTestFileAt(&directory(), "file_123", 123); | |
| 46 CreateTestFileAt(&directory(), "file_456", 456); | |
| 47 | |
| 48 EXPECT_EQ(0, GetFileSize(&directory(), "file_0")); | |
| 49 EXPECT_EQ(123, GetFileSize(&directory(), "file_123")); | |
| 50 EXPECT_EQ(456, GetFileSize(&directory(), "file_456")); | |
| 51 EXPECT_EQ(-1, GetFileSize(&directory(), "nonexistent")); | |
| 52 | |
| 53 EXPECT_EQ(std::string(), GetFileContents(&directory(), "file_0")); | |
| 54 | |
| 55 std::string s_123(123, '\0'); | |
| 56 for (size_t i = 0; i < 123; i++) { | |
| 57 unsigned char c = static_cast<unsigned char>(i); | |
| 58 s_123[i] = *reinterpret_cast<char*>(&c); | |
| 59 } | |
| 60 EXPECT_EQ(s_123, GetFileContents(&directory(), "file_123")); | |
| 61 | |
| 62 std::string s_456(456, '\0'); | |
| 63 for (size_t i = 0; i < 456; i++) { | |
| 64 unsigned char c = static_cast<unsigned char>(i); | |
| 65 s_456[i] = *reinterpret_cast<char*>(&c); | |
| 66 } | |
| 67 EXPECT_EQ(s_456, GetFileContents(&directory(), "file_456")); | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 } // namespace test | |
| 72 } // namespace mojio | |
| OLD | NEW |