Chromium Code Reviews| Index: mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
| diff --git a/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
| index c7b49c210f0aa20c02c77517bee0da0d0ff1bb67..2de83ea04494e2cba483033aa7fe6a0e4d5ae361 100644 |
| --- a/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
| +++ b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc |
| @@ -15,6 +15,7 @@ |
| #include <deque> |
| +#include "base/files/file_path.h" |
|
viettrungluu
2015/07/28 18:17:09
Could you please put this under the ifdef also?
qsr
2015/07/29 08:37:31
Done.
|
| #include "base/files/scoped_file.h" |
| #include "base/logging.h" |
| #include "mojo/edk/embedder/platform_channel_utils_posix.h" |
| @@ -25,6 +26,10 @@ |
| #include "mojo/public/cpp/system/macros.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#if defined(OS_ANDROID) |
|
viettrungluu
2015/07/28 18:17:10
You should explicitly include build/build_config.h
qsr
2015/07/29 08:37:31
Done.
|
| +#include "base/android/path_utils.h" |
| +#endif |
| + |
| namespace mojo { |
| namespace embedder { |
| namespace { |
| @@ -36,6 +41,21 @@ void WaitReadable(PlatformHandle h) { |
| CHECK_EQ(poll(&pfds, 1, -1), 1); |
| } |
| +FILE* NewTmpFile() { |
| +#if defined(OS_ANDROID) |
| + base::FilePath tmpdir; |
| + if (!base::android::GetCacheDirectory(&tmpdir)) |
| + return nullptr; |
| + std::string templ = tmpdir.Append("XXXXXXXX").value(); |
| + int fd = mkstemp(const_cast<char*>(templ.c_str())); |
| + if (fd == -1) |
| + return nullptr; |
| + return fdopen(fd, "w"); |
|
viettrungluu
2015/07/28 18:17:10
You should unlink() the file too.
viettrungluu
2015/07/28 18:17:10
This should be "wb+" according to the C standard (
qsr
2015/07/29 08:37:31
Done.
qsr
2015/07/29 08:37:31
Done.
|
| +#else |
| + return tmpfile(); |
| +#endif |
| +} |
| + |
| class PlatformChannelPairPosixTest : public testing::Test { |
| public: |
| PlatformChannelPairPosixTest() {} |
| @@ -144,7 +164,7 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) { |
| const char c = '0' + (i % 10); |
| ScopedPlatformHandleVectorPtr platform_handles(new PlatformHandleVector); |
| for (size_t j = 1; j <= i; j++) { |
| - base::ScopedFILE fp(tmpfile()); |
| + base::ScopedFILE fp(NewTmpFile()); |
| ASSERT_TRUE(fp); |
| ASSERT_EQ(j, fwrite(std::string(j, c).data(), 1, j, fp.get())); |
| platform_handles->push_back( |
| @@ -195,7 +215,7 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) { |
| const std::string file_contents("hello world"); |
| { |
| - base::ScopedFILE fp(tmpfile()); |
| + base::ScopedFILE fp(NewTmpFile()); |
| ASSERT_TRUE(fp); |
| ASSERT_EQ(file_contents.size(), |
| fwrite(file_contents.data(), 1, file_contents.size(), fp.get())); |