VirtualBox

Changeset 18847 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Apr 8, 2009 4:22:27 PM (16 years ago)
Author:
vboxsync
Message:

RTTest: Added alternative API that's easier to use.

Location:
trunk/src/VBox/Runtime
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r18750 r18847  
    291291        r3/stream.cpp \
    292292        r3/test.cpp \
     293        r3/testi.cpp \
    293294        r3/tcp.cpp
    294295
  • trunk/src/VBox/Runtime/r3/test.cpp

    r18569 r18847  
    825825}
    826826
    827 
    828 /**
    829  * Increments the error counter.
    830  *
    831  * @returns IPRT status code.
    832  * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
    833  *                      associated with the calling thread.
    834  */
    835 RTR3DECL(int) RTTestErrorInc(RTTEST hTest)
    836 {
    837     PRTTESTINT pTest = hTest;
    838     RTTEST_GET_VALID_RETURN(pTest);
    839 
    840     ASMAtomicIncU32(&pTest->cErrors);
    841 
    842     return VINF_SUCCESS;
    843 }
    844 
    845 
    846 /**
    847  * Increments the error counter and prints a failure message.
     827/**
     828 * Prints an extended PASSED message, optional.
     829 *
     830 * This does not conclude the sub-test, it could be used to report the passing
     831 * of a sub-sub-to-the-power-of-N-test.
    848832 *
    849833 * @returns IPRT status code.
     
    853837 * @param   va          The arguments.
    854838 */
    855 RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va)
     839RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va)
    856840{
    857841    PRTTESTINT pTest = hTest;
    858842    RTTEST_GET_VALID_RETURN_RC(pTest, -1);
    859843
    860     RTTestErrorInc(pTest);
    861 
    862844    int cch = 0;
    863     if (pTest->enmMaxLevel >= RTTESTLVL_FAILURE)
     845    if (pTest->enmMaxLevel >= RTTESTLVL_INFO)
    864846    {
    865847        va_list va2;
     
    878860
    879861/**
     862 * Prints an extended PASSED message, optional.
     863 *
     864 * This does not conclude the sub-test, it could be used to report the passing
     865 * of a sub-sub-to-the-power-of-N-test.
     866 *
     867 * @returns IPRT status code.
     868 * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
     869 *                      associated with the calling thread.
     870 * @param   pszFormat   The message. No trailing newline.
     871 * @param   ...         The arguments.
     872 */
     873RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...)
     874{
     875    va_list va;
     876
     877    va_start(va, pszFormat);
     878    int cch = RTTestPassedV(hTest, pszFormat, va);
     879    va_end(va);
     880
     881    return cch;
     882}
     883
     884
     885/**
     886 * Increments the error counter.
     887 *
     888 * @returns IPRT status code.
     889 * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
     890 *                      associated with the calling thread.
     891 */
     892RTR3DECL(int) RTTestErrorInc(RTTEST hTest)
     893{
     894    PRTTESTINT pTest = hTest;
     895    RTTEST_GET_VALID_RETURN(pTest);
     896
     897    ASMAtomicIncU32(&pTest->cErrors);
     898
     899    return VINF_SUCCESS;
     900}
     901
     902
     903/**
     904 * Increments the error counter and prints a failure message.
     905 *
     906 * @returns IPRT status code.
     907 * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
     908 *                      associated with the calling thread.
     909 * @param   pszFormat   The message. No trailing newline.
     910 * @param   va          The arguments.
     911 */
     912RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va)
     913{
     914    PRTTESTINT pTest = hTest;
     915    RTTEST_GET_VALID_RETURN_RC(pTest, -1);
     916
     917    RTTestErrorInc(pTest);
     918
     919    int cch = 0;
     920    if (pTest->enmMaxLevel >= RTTESTLVL_FAILURE)
     921    {
     922        va_list va2;
     923        va_copy(va2, va);
     924
     925        RTCritSectEnter(&pTest->OutputLock);
     926        cch += rtTestPrintf(pTest, "%N\n", pszFormat, &va2);
     927        RTCritSectLeave(&pTest->OutputLock);
     928
     929        va_end(va2);
     930    }
     931
     932    return cch;
     933}
     934
     935
     936/**
    880937 * Increments the error counter and prints a failure message.
    881938 *
     
    899956
    900957/**
    901  * Prints an extended PASSED message, optional.
    902  *
    903  * This does not conclude the sub-test, it could be used to report the passing
    904  * of a sub-sub-to-the-power-of-N-test.
    905  *
    906  * @returns IPRT status code.
    907  * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
    908  *                      associated with the calling thread.
    909  * @param   pszFormat   The message. No trailing newline.
    910  * @param   va          The arguments.
    911  */
    912 RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va)
    913 {
    914     PRTTESTINT pTest = hTest;
    915     RTTEST_GET_VALID_RETURN_RC(pTest, -1);
    916 
    917     int cch = 0;
    918     if (pTest->enmMaxLevel >= RTTESTLVL_INFO)
    919     {
    920         va_list va2;
    921         va_copy(va2, va);
    922 
    923         RTCritSectEnter(&pTest->OutputLock);
    924         cch += rtTestPrintf(pTest, "%N\n", pszFormat, &va2);
    925         RTCritSectLeave(&pTest->OutputLock);
    926 
    927         va_end(va2);
    928     }
    929 
    930     return cch;
    931 }
    932 
    933 
    934 /**
    935  * Prints an extended PASSED message, optional.
    936  *
    937  * This does not conclude the sub-test, it could be used to report the passing
    938  * of a sub-sub-to-the-power-of-N-test.
    939  *
    940  * @returns IPRT status code.
    941  * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
    942  *                      associated with the calling thread.
    943  * @param   pszFormat   The message. No trailing newline.
    944  * @param   ...         The arguments.
    945  */
    946 RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...)
     958 * Same as RTTestPrintfV with RTTESTLVL_FAILURE.
     959 *
     960 * @returns Number of chars printed.
     961 * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
     962 *                      associated with the calling thread.
     963 * @param   enmLevel    Message importance level.
     964 * @param   pszFormat   The message.
     965 * @param   va          Arguments.
     966 */
     967RTR3DECL(int) RTTestFailureDetailsV(RTTEST hTest, const char *pszFormat, va_list va)
     968{
     969    return RTTestPrintfV(hTest, RTTESTLVL_FAILURE, pszFormat, va);
     970}
     971
     972
     973/**
     974 * Same as RTTestPrintf with RTTESTLVL_FAILURE.
     975 *
     976 * @returns Number of chars printed.
     977 * @param   hTest       The test handle. If NIL_RTTEST we'll use the one
     978 *                      associated with the calling thread.
     979 * @param   enmLevel    Message importance level.
     980 * @param   pszFormat   The message.
     981 * @param   ...         Arguments.
     982 */
     983RTR3DECL(int) RTTestFailureDetails(RTTEST hTest, const char *pszFormat, ...)
    947984{
    948985    va_list va;
    949 
    950986    va_start(va, pszFormat);
    951     int cch = RTTestPassedV(hTest, pszFormat, va);
     987    int cch = RTTestFailureDetailsV(hTest, pszFormat, va);
    952988    va_end(va);
    953 
    954     return cch;
    955 }
    956 
     989    return cch;
     990}
     991
  • trunk/src/VBox/Runtime/testcase/tstUtf8.cpp

    r18587 r18847  
    8080    rc = RTStrToUtf16(s_szBadString1, &pwsz);
    8181    RTTEST_CHECK_MSG(hTest, rc == VERR_NO_TRANSLATION || rc == VERR_INVALID_UTF8_ENCODING,
    82                      (hTest, RTTESTLVL_FAILURE, "Conversion of first bad UTF-8 string to UTF-16 apparantly succeeded. It shouldn't. rc=%Rrc\n", rc));
     82                     (hTest, "Conversion of first bad UTF-8 string to UTF-16 apparantly succeeded. It shouldn't. rc=%Rrc\n", rc));
    8383    rc = RTStrToUtf16(s_szBadString2, &pwsz);
    8484    RTTEST_CHECK_MSG(hTest, rc == VERR_NO_TRANSLATION || rc == VERR_INVALID_UTF8_ENCODING,
    85                      (hTest, RTTESTLVL_FAILURE, "Conversion of second bad UTF-8 strings to UTF-16 apparantly succeeded. It shouldn't. rc=%Rrc\n", rc));
     85                     (hTest, "Conversion of second bad UTF-8 strings to UTF-16 apparantly succeeded. It shouldn't. rc=%Rrc\n", rc));
    8686
    8787    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette