static void test_posix_dup() 
{ 
    int pfd[2]; 

    BOOST_REQUIRE(::pipe(pfd) != -1); 
    bpd::file_handle rend(pfd[0]); 
    bpd::file_handle wend(pfd[1]); 

    BOOST_REQUIRE(rend.get() != 10); 
    BOOST_REQUIRE(wend.get() != 10); 
    bpd::file_handle fh1 = bpd::file_handle::posix_dup(wend.get(), 10); 
    BOOST_REQUIRE_EQUAL(fh1.get(), 10); 

    BOOST_REQUIRE(::write(wend.get(), "test-posix-dup", 14) != -1); 
    char buf1[15]; 
    BOOST_REQUIRE_EQUAL(::read(rend.get(), buf1, sizeof(buf1)), 14); 
    buf1[14] = '\0'; 
    BOOST_REQUIRE(std::strcmp(buf1, "test-posix-dup") == 0); 

    BOOST_REQUIRE(::write(fh1.get(), "test-posix-dup", 14) != -1); 
    char buf2[15]; 
    BOOST_REQUIRE_EQUAL(::read(rend.get(), buf2, sizeof(buf2)), 14); 
    buf2[14] = '\0'; 
    BOOST_REQUIRE(std::strcmp(buf2, "test-posix-dup") == 0); 
} 
示例#2
0
QStringList WritingSystems::getLangs(qulonglong ws) const
{
    QMap<QString, qulonglong>::ConstIterator wit(itsMap.begin()),
                                             wend(itsMap.end());
    QStringList                              systems;

    for(; wit!=wend; ++wit)
        if(ws&wit.value())
            systems+=wit.key();
    return systems;
}
static void test_it() 
{ 
    bpd::pipe p; 
    bp::pistream rend(p.rend()); 
    bpd::systembuf wbuf(p.wend().get()); 
    std::ostream wend(&wbuf); 

    // This assumes that the pipe's buffer is big enough to accept 
    // the data written without blocking! 
    wend << "1Test 1message" << std::endl; 
    std::string tmp; 
    rend >> tmp; 
    BOOST_CHECK_EQUAL(tmp, "1Test"); 
    rend >> tmp; 
    BOOST_CHECK_EQUAL(tmp, "1message"); 
} 
static void test_win32_dup() 
{ 
    HANDLE in, out; 
    SECURITY_ATTRIBUTES sa; 
    ZeroMemory(&sa, sizeof(sa)); 
    sa.nLength = sizeof(sa); 
    sa.lpSecurityDescriptor = NULL; 
    sa.bInheritHandle = FALSE; 
    BOOST_REQUIRE(::CreatePipe(&in, &out, &sa, 0) != 0); 
    bpd::file_handle rend(in); 
    bpd::file_handle wend(out); 

    DWORD flags, rcnt; 
    char buf[15]; 

    bpd::file_handle out2 = bpd::file_handle::win32_dup(wend.get(), false); 
    BOOST_REQUIRE(::GetHandleInformation(out2.get(), &flags) != 0); 
    BOOST_REQUIRE(!(flags & HANDLE_FLAG_INHERIT)); 

    bpd::file_handle out3 = bpd::file_handle::win32_dup(wend.get(), true); 
    BOOST_REQUIRE(::GetHandleInformation(out3.get(), &flags) != 0); 
    BOOST_REQUIRE(flags & HANDLE_FLAG_INHERIT); 

    BOOST_REQUIRE(::WriteFile(wend.get(), "test-win32-dup", 14, &rcnt, 
        NULL) != 0); 
    BOOST_REQUIRE_EQUAL(rcnt, 14); 
    BOOST_REQUIRE(::ReadFile(rend.get(), buf, sizeof(buf), &rcnt, NULL) != 0); 
    BOOST_REQUIRE_EQUAL(rcnt, 14); 
    buf[14] = '\0'; 
    BOOST_REQUIRE(std::strcmp(buf, "test-win32-dup") == 0); 

    BOOST_REQUIRE(::WriteFile(out2.get(), "test-win32-dup", 14, &rcnt, 
        NULL) != 0); 
    BOOST_REQUIRE_EQUAL(rcnt, 14); 
    BOOST_REQUIRE(::ReadFile(rend.get(), buf, sizeof(buf), &rcnt, NULL) != 0); 
    BOOST_REQUIRE_EQUAL(rcnt, 14); 
    buf[14] = '\0'; 
    BOOST_REQUIRE(std::strcmp(buf, "test-win32-dup") == 0); 

    BOOST_REQUIRE(::WriteFile(out3.get(), "test-win32-dup", 14, &rcnt, 
        NULL) != 0); 
    BOOST_REQUIRE_EQUAL(rcnt, 14); 
    BOOST_REQUIRE(::ReadFile(rend.get(), buf, sizeof(buf), &rcnt, NULL) != 0); 
    BOOST_REQUIRE_EQUAL(rcnt, 14); 
    buf[14] = '\0'; 
    BOOST_REQUIRE(std::strcmp(buf, "test-win32-dup") == 0); 
} 
static void test_posix_remap() 
{ 
    int pfd[2]; 

    BOOST_REQUIRE(::pipe(pfd) != -1); 
    bpd::file_handle rend(pfd[0]); 
    bpd::file_handle wend(pfd[1]); 

    BOOST_REQUIRE(rend.get() != 10); 
    BOOST_REQUIRE(wend.get() != 10); 
    wend.posix_remap(10); 
    BOOST_REQUIRE_EQUAL(wend.get(), 10); 
    BOOST_REQUIRE(::write(wend.get(), "test-posix-remap", 16) != -1); 

    char buf[17]; 
    BOOST_REQUIRE_EQUAL(::read(rend.get(), buf, sizeof(buf)), 16); 
    buf[16] = '\0'; 
    BOOST_REQUIRE(std::strcmp(buf, "test-posix-remap") == 0); 
} 
static void test_win32_set_inheritable() 
{ 
    HANDLE in, out; 
    SECURITY_ATTRIBUTES sa; 
    ZeroMemory(&sa, sizeof(sa)); 
    sa.nLength = sizeof(sa); 
    sa.lpSecurityDescriptor = NULL; 
    sa.bInheritHandle = FALSE; 
    BOOST_REQUIRE(::CreatePipe(&in, &out, &sa, 0) != 0); 
    bpd::file_handle rend(in); 
    bpd::file_handle wend(out); 

    DWORD flags; 

    bpd::file_handle out2 = bpd::file_handle::win32_dup(wend.get(), false); 
    BOOST_REQUIRE(::GetHandleInformation(out2.get(), &flags) != 0); 
    BOOST_REQUIRE(!(flags & HANDLE_FLAG_INHERIT)); 

    bpd::file_handle out3 = bpd::file_handle::win32_dup(wend.get(), true); 
    BOOST_REQUIRE(::GetHandleInformation(out3.get(), &flags) != 0); 
    BOOST_REQUIRE(flags & HANDLE_FLAG_INHERIT); 
}