Esempio n. 1
0
  void test_connect_pipe() {
    IO* lhs = IO::allocate(state, G(io));
    IO* rhs = IO::allocate(state, G(io));

    TS_ASSERT(IO::connect_pipe(state, lhs, rhs)->true_p());
    TS_ASSERT_EQUALS(Fixnum::from(0), lhs->lineno());
    TS_ASSERT_EQUALS(Fixnum::from(0), rhs->lineno());
    TS_ASSERT(kind_of<IOBuffer>(lhs->ibuffer()));
    TS_ASSERT(kind_of<IOBuffer>(rhs->ibuffer()));
    TS_ASSERT_EQUALS(Fixnum::from(O_RDONLY), lhs->mode());
    TS_ASSERT_EQUALS(Fixnum::from(O_WRONLY), rhs->mode());

    rhs->write(state, String::create(state, "hello"), 0);
    Object* obj = lhs->blocking_read(state, Fixnum::from(5));
    TS_ASSERT(kind_of<String>(obj));

    String* str = try_as<String>(obj);
    TS_ASSERT_EQUALS(std::string("hello"), str->c_str(state));

    lhs->close(state);
    rhs->close(state);
  }