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

Unified Diff: mojo/edk/embedder/platform_channel_pair_posix_unittest.cc

Issue 1261903002: Fix system unit tests on Android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Folllow review Created 5 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0b20f4b57b5188ae692b9cca9834e7d1732f667f 100644
--- a/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc
+++ b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc
@@ -17,6 +17,7 @@
#include "base/files/scoped_file.h"
#include "base/logging.h"
+#include "build/build_config.h"
#include "mojo/edk/embedder/platform_channel_utils_posix.h"
#include "mojo/edk/embedder/platform_handle.h"
#include "mojo/edk/embedder/platform_handle_vector.h"
@@ -25,6 +26,11 @@
#include "mojo/public/cpp/system/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_ANDROID)
+#include "base/android/path_utils.h"
+#include "base/files/file_path.h"
+#endif
+
namespace mojo {
namespace embedder {
namespace {
@@ -36,6 +42,22 @@ 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;
+ CHECK(unlink(templ.c_str()) == 0);
+ return fdopen(fd, "w+");
+#else
+ return tmpfile();
+#endif
+}
+
class PlatformChannelPairPosixTest : public testing::Test {
public:
PlatformChannelPairPosixTest() {}
@@ -144,7 +166,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 +217,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()));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698