Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1039)

Unified Diff: services/files/c/tests/test_utils.cc

Issue 1133933002: Move //services/files/c -> //mojo/services/files/public/c. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove data dep Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/files/c/tests/test_utils.h ('k') | services/files/c/tests/test_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/files/c/tests/test_utils.cc
diff --git a/services/files/c/tests/test_utils.cc b/services/files/c/tests/test_utils.cc
deleted file mode 100644
index 47a088410f0bc3aefb283cc93e6bb96863422cbb..0000000000000000000000000000000000000000
--- a/services/files/c/tests/test_utils.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "services/files/c/tests/test_utils.h"
-
-#include "mojo/public/cpp/environment/logging.h"
-#include "mojo/services/files/public/interfaces/file.mojom.h"
-#include "mojo/services/files/public/interfaces/types.mojom.h"
-#include "services/files/c/lib/template_util.h"
-
-namespace mojio {
-namespace test {
-
-void MakeDirAt(mojo::files::DirectoryPtr* root, const char* path) {
- MOJO_CHECK(root);
- MOJO_CHECK(path);
- mojo::files::DirectoryPtr& dir = *root;
-
- mojo::files::Error error = mojo::files::ERROR_INTERNAL;
- dir->OpenDirectory(path, nullptr,
- mojo::files::kOpenFlagRead | mojo::files::kOpenFlagWrite |
- mojo::files::kOpenFlagCreate,
- Capture(&error));
- MOJO_CHECK(dir.WaitForIncomingMethodCall());
- MOJO_CHECK(error == mojo::files::ERROR_OK);
-}
-
-mojo::files::FilePtr OpenFileAt(mojo::files::DirectoryPtr* root,
- const char* path,
- uint32_t open_flags) {
- MOJO_CHECK(root);
- MOJO_CHECK(path);
- mojo::files::DirectoryPtr& dir = *root;
-
- mojo::files::FilePtr file;
- mojo::files::Error error = mojo::files::ERROR_INTERNAL;
- dir->OpenFile(path, mojo::GetProxy(&file), open_flags, Capture(&error));
- MOJO_CHECK(dir.WaitForIncomingMethodCall());
- if (error != mojo::files::ERROR_OK)
- return nullptr;
-
- return file.Pass();
-}
-
-void CreateTestFileAt(mojo::files::DirectoryPtr* root,
- const char* path,
- size_t size) {
- mojo::files::FilePtr file = OpenFileAt(
- root, path, mojo::files::kOpenFlagWrite | mojo::files::kOpenFlagCreate |
- mojo::files::kOpenFlagExclusive);
- MOJO_CHECK(file);
-
- if (!size)
- return;
-
- std::vector<uint8_t> bytes_to_write(size);
- for (size_t i = 0; i < size; i++)
- bytes_to_write[i] = static_cast<uint8_t>(i);
- mojo::files::Error error = mojo::files::ERROR_INTERNAL;
- uint32_t num_bytes_written = 0;
- file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0,
- mojo::files::WHENCE_FROM_CURRENT,
- Capture(&error, &num_bytes_written));
- MOJO_CHECK(file.WaitForIncomingMethodCall());
- MOJO_CHECK(error == mojo::files::ERROR_OK);
- MOJO_CHECK(num_bytes_written == bytes_to_write.size());
-}
-
-int64_t GetFileSize(mojo::files::DirectoryPtr* root, const char* path) {
- mojo::files::FilePtr file =
- OpenFileAt(root, path, mojo::files::kOpenFlagRead);
- if (!file)
- return -1;
-
- // Seek to the end to get the file size (we could also stat).
- mojo::files::Error error = mojo::files::ERROR_INTERNAL;
- int64_t position = -1;
- file->Seek(0, mojo::files::WHENCE_FROM_END, Capture(&error, &position));
- MOJO_CHECK(file.WaitForIncomingMethodCall());
- MOJO_CHECK(error == mojo::files::ERROR_OK);
- MOJO_CHECK(position >= 0);
- return position;
-}
-
-std::string GetFileContents(mojo::files::DirectoryPtr* root, const char* path) {
- mojo::files::FilePtr file =
- OpenFileAt(root, path, mojo::files::kOpenFlagRead);
- MOJO_CHECK(file);
-
- mojo::Array<uint8_t> bytes_read;
- mojo::files::Error error = mojo::files::ERROR_INTERNAL;
- file->Read(1024 * 1024, 0, mojo::files::WHENCE_FROM_START,
- Capture(&error, &bytes_read));
- MOJO_CHECK(file.WaitForIncomingMethodCall());
- if (!bytes_read.size())
- return std::string();
- return std::string(reinterpret_cast<const char*>(&bytes_read[0]),
- bytes_read.size());
-}
-
-} // namespace test
-} // namespace mojio
« no previous file with comments | « services/files/c/tests/test_utils.h ('k') | services/files/c/tests/test_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698