1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef MOJO_COMMON_TEST_TEST_UTILS_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define MOJO_COMMON_TEST_TEST_UTILS_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <stddef.h>
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include <stdio.h>
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include <string>
125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/files/file_path.h"
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/files/scoped_file.h"
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "mojo/embedder/platform_handle.h"
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "mojo/embedder/scoped_platform_handle.h"
175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace mojo {
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace test {
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// On success, |bytes_written| is updated to the number of bytes written;
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// otherwise it is untouched.
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool BlockingWrite(const embedder::PlatformHandle& handle,
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   const void* buffer,
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   size_t bytes_to_write,
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   size_t* bytes_written);
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// On success, |bytes_read| is updated to the number of bytes read; otherwise it
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// is untouched.
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool BlockingRead(const embedder::PlatformHandle& handle,
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                  void* buffer,
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                  size_t buffer_size,
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                  size_t* bytes_read);
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// If the read is done successfully or would block, the function returns true
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// and updates |bytes_read| to the number of bytes read (0 if the read would
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// block); otherwise it returns false and leaves |bytes_read| untouched.
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// |handle| must already be in non-blocking mode.
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool NonBlockingRead(const embedder::PlatformHandle& handle,
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                     void* buffer,
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                     size_t buffer_size,
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                     size_t* bytes_read);
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Gets a (scoped) |PlatformHandle| from the given (scoped) |FILE|.
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp);
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Gets a (scoped) |FILE| from a (scoped) |PlatformHandle|.
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h,
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                        const char* mode);
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Returns the path to the mojom js bindings file.
525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liubase::FilePath GetFilePathForJSResource(const std::string& path);
535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace test
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace mojo
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // MOJO_COMMON_TEST_TEST_UTILS_H_
58