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

Unified Diff: mojo/common/test/test_utils_win.cc

Issue 273023003: Mojo: Add test utils to go between a ScopedPlatformHandle and a ScopedFILE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win Created 6 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 | « mojo/common/test/test_utils_posix.cc ('k') | mojo/embedder/platform_channel_pair_posix_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/test/test_utils_win.cc
diff --git a/mojo/common/test/test_utils_win.cc b/mojo/common/test/test_utils_win.cc
index aaabc01c00c5799dca75eda75b5743f5627b3e36..71efced5c7913189d8935a7e3626cf4652efdcc0 100644
--- a/mojo/common/test/test_utils_win.cc
+++ b/mojo/common/test/test_utils_win.cc
@@ -4,12 +4,14 @@
#include "mojo/common/test/test_utils.h"
+#include <fcntl.h>
+#include <io.h>
+#include <string.h>
#include <windows.h>
#include "base/base_paths.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
-#include "mojo/embedder/platform_handle.h"
namespace mojo {
namespace test {
@@ -79,6 +81,41 @@ bool NonBlockingRead(const embedder::PlatformHandle& handle,
return true;
}
+embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) {
+ CHECK(fp);
+
+ HANDLE rv = INVALID_HANDLE_VALUE;
+ PCHECK(DuplicateHandle(
+ GetCurrentProcess(),
+ reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))),
+ GetCurrentProcess(),
+ &rv,
+ 0,
+ TRUE,
+ DUPLICATE_SAME_ACCESS)) << "DuplicateHandle";
+ return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv));
+}
+
+base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h,
+ const char* mode) {
+ CHECK(h.is_valid());
+ // Microsoft's documentation for |_open_osfhandle()| only discusses these
+ // flags (and |_O_WTEXT|). Hmmm.
+ int flags = 0;
+ if (strchr(mode, 'a'))
+ flags |= _O_APPEND;
+ if (strchr(mode, 'r'))
+ flags |= _O_RDONLY;
+ if (strchr(mode, 't'))
+ flags |= _O_TEXT;
+ base::ScopedFILE rv(
+ _fdopen(_open_osfhandle(reinterpret_cast<intptr_t>(h.release().handle),
+ flags),
+ mode));
+ PCHECK(rv) << "_fdopen";
+ return rv.Pass();
+}
+
base::FilePath GetFilePathForJSResource(const std::string& path) {
std::string binding_path = "gen/" + path + ".js";
base::ReplaceChars(binding_path, "//", "\\", &binding_path);
« no previous file with comments | « mojo/common/test/test_utils_posix.cc ('k') | mojo/embedder/platform_channel_pair_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698