This source file includes following definitions.
- SetUp
 
- TearDown
 
- TEST_F
 
#include "mojo/embedder/platform_channel_pair.h"
#include <errno.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "base/logging.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "mojo/embedder/scoped_platform_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace embedder {
namespace {
class PlatformChannelPairPosixTest : public testing::Test {
 public:
  PlatformChannelPairPosixTest() {}
  virtual ~PlatformChannelPairPosixTest() {}
  virtual void SetUp() OVERRIDE {
    
    struct sigaction action = {};
    action.sa_handler = SIG_DFL;
    ASSERT_EQ(0, sigaction(SIGPIPE, &action, &old_action_));
  }
  virtual void TearDown() OVERRIDE {
    
    ASSERT_EQ(0, sigaction(SIGPIPE, &old_action_, NULL));
  }
 private:
  struct sigaction old_action_;
  DISALLOW_COPY_AND_ASSIGN(PlatformChannelPairPosixTest);
};
TEST_F(PlatformChannelPairPosixTest, NoSigPipe) {
  PlatformChannelPair channel_pair;
  ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass();
  ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass();
  
  static const char kHello[] = "hello";
  EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
            write(client_handle.get().fd, kHello, sizeof(kHello)));
  
  client_handle.reset();
  
  char buffer[100] = {};
  EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
            read(server_handle.get().fd, buffer, sizeof(buffer)));
  EXPECT_STREQ(kHello, buffer);
  
  ssize_t result = read(server_handle.get().fd, buffer, sizeof(buffer));
  
  EXPECT_TRUE(result == 0 || result == -1);
  if (result == -1)
    PLOG(WARNING) << "read (expected 0 for EOF)";
  
  
  
  
#if defined(OS_MACOSX)
  result = write(server_handle.get().fd, kHello, sizeof(kHello));
#else
  result = send(server_handle.get().fd, kHello, sizeof(kHello), MSG_NOSIGNAL);
#endif
  EXPECT_EQ(-1, result);
  if (errno != EPIPE)
    PLOG(WARNING) << "write (expected EPIPE)";
}
}  
}  
}