tstRTPipe.cpp revision bd51228d218e2f43d2d5d7f0559901dfaac31c9c
/* $Id$ */
/** @file
* IPRT Testcase - RTPipe.
*/
/*
* Copyright (C) 2010 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
static void tstRTPipe3(void)
{
RTTestISub("Full write buffer");
int rc = VINF_SUCCESS;
for (;;)
{
break;
if (rc != VINF_SUCCESS)
break;
}
if (rc == VINF_TRY_AGAIN)
{
RTTESTI_CHECK_RC(RTPipeRead(hPipeR, s_abBuf, RT_MIN(sizeof(s_abBuf), cbTotal) / 2, &cbRead), VINF_SUCCESS);
}
}
static void tstRTPipe2(void)
{
RTTestISub("Negative");
}
static void tstRTPipe1(void)
{
RTTestISub("Basics");
hPipeR = NIL_RTPIPE;
hPipeW = NIL_RTPIPE;
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, RTPIPE_C_INHERIT_READ | RTPIPE_C_INHERIT_WRITE), VINF_SUCCESS);
RTTESTI_CHECK_RETV(cbRead == 0);
RTTESTI_CHECK_RETV(cbRead == 0);
RTTESTI_CHECK_RETV(cbRead == 0);
RTTESTI_CHECK_RETV(cbWritten == 0);
/* We can write a number of bytes without blocking (see PIPE_BUF on
POSIX systems). */
RTTestISub("VERR_BROKEN_PIPE");
RTTESTI_CHECK(cbWritten == 0);
RTTESTI_CHECK(cbRead == 0);
RTTESTI_CHECK(cbRead == 0);
RTTESTI_CHECK(cbRead == 0);
RTTestISub("Blocking");
RTTESTI_CHECK(cbRead == 0);
RTTESTI_CHECK(cbRead == 0);
RTTESTI_CHECK(cbWritten == 0);
RTTESTI_CHECK(cbWritten == 0);
}
int main()
{
if (rc)
return rc;
/*
* The tests.
*/
tstRTPipe1();
if (RTTestErrorCount(hTest) == 0)
{
bool fMayPanic = RTAssertMayPanic();
bool fQuiet = RTAssertAreQuiet();
RTAssertSetMayPanic(false);
RTAssertSetQuiet(true);
tstRTPipe2();
tstRTPipe3();
}
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}