VirtualBox

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


Ignore:
Timestamp:
Sep 9, 2018 2:12:40 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/rest: Added testcases for RTCRestBool and RTCRestIntXY. bugref:9167

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp

    r74149 r74161  
    207207int RTCRestBool::deserializeFromJson(RTCRestJsonCursor const &a_rCursor)
    208208{
     209    m_fValue = false;
     210    m_fNullIndicator = false;
     211
    209212    RTJSONVALTYPE enmType = RTJsonValueGetType(a_rCursor.m_hValue);
    210213
     
    212215    {
    213216        m_fValue = true;
    214         m_fNullIndicator = false;
    215217        return VINF_SUCCESS;
    216218    }
    217219
    218220    if (enmType == RTJSONVALTYPE_FALSE)
    219     {
    220         m_fValue = false;
    221         m_fNullIndicator = false;
    222         return VINF_SUCCESS;
    223     }
     221        return VINF_SUCCESS;
    224222
    225223    if (enmType == RTJSONVALTYPE_NULL)
    226224    {
    227         m_fValue = false;
    228225        m_fNullIndicator = true;
    229226        return VINF_SUCCESS;
    230227    }
    231228
    232     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for boolean",
     229    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_BOOL, "wrong JSON type %s for boolean",
    233230                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    234231}
     
    279276    }
    280277    else
    281         return RTErrInfoSetF(a_pErrInfo, VERR_INVALID_PARAMETER, "%s: unable to parse '%s' as bool", a_pszName, a_rValue.c_str());
     278        return RTErrInfoSetF(a_pErrInfo, VERR_REST_UNABLE_TO_PARSE_STRING_AS_BOOL,
     279                             "%s: unable to parse '%s' as bool", a_pszName, a_rValue.c_str());
    282280    return VINF_SUCCESS;
    283281}
     
    405403        m_iValue = 1;
    406404
    407     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for 64-bit integer",
     405    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_INTEGER, "wrong JSON type %s for 64-bit integer",
    408406                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    409407}
     
    432430    m_fNullIndicator = false;
    433431
    434     int rc = RTStrToInt64Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue);
     432/** @todo RTStrStripL and RTStrToInt64Full has a different idea what consitutes spaces... */
     433    int rc = RTStrToInt64Full(RTStrStripL(a_rValue.c_str()), 0, &m_iValue);
    435434    if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES)
    436435        return VINF_SUCCESS;
     
    574573        m_iValue = 1;
    575574
    576     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for 32-bit integer",
     575    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_INTEGER, "wrong JSON type %s for 32-bit integer",
    577576                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    578577}
     
    601600    m_fNullIndicator = false;
    602601
    603     int rc = RTStrToInt32Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue);
     602/** @todo RTStrStripL and RTStrToInt32Full has a different idea what consitutes spaces... */
     603    int rc = RTStrToInt32Full(RTStrStripL(a_rValue.c_str()), 0, &m_iValue);
    604604    if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES)
    605605        return VINF_SUCCESS;
     
    743743        m_iValue = 1;
    744744
    745     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for 16-bit integer",
     745    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_INTEGER, "wrong JSON type %s for 16-bit integer",
    746746                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    747747}
     
    770770    m_fNullIndicator = false;
    771771
    772     int rc = RTStrToInt16Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue);
     772/** @todo RTStrStripL and RTStrToInt16Full has a different idea what consitutes spaces... */
     773    int rc = RTStrToInt16Full(RTStrStripL(a_rValue.c_str()), 0, &m_iValue);
    773774    if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES)
    774775        return VINF_SUCCESS;
     
    930931        m_rdValue = 1.0;
    931932
    932     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for a double",
     933    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_DOUBLE, "wrong JSON type %s for a double",
    933934                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    934935}
     
    11181119    }
    11191120
    1120     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for string",
     1121    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_STRING, "wrong JSON type %s for string",
    11211122                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    11221123}
     
    12641265    }
    12651266
    1266     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type for date: %s",
     1267    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_DATE, "wrong JSON type for date: %s",
    12671268                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    12681269}
     
    16761677    }
    16771678
    1678     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for string/enum",
     1679    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_REST_WRONG_JSON_TYPE_FOR_STRING, "wrong JSON type %s for string/enum",
    16791680                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    16801681}
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r74094 r74161  
    5656        tstRTCrX509-1 \
    5757        tstRTCType \
     58        tstRTCRest-1 \
    5859        tstRTDigest \
    5960        tstRTDigest-2 \
     
    308309tstRTCType_SOURCES = tstRTCType.cpp
    309310
     311tstRTCRest-1_TEMPLATE = VBOXR3TSTEXE
     312tstRTCRest-1_SOURCES = tstRTCRest-1.cpp
     313
    310314tstRTDigest_TEMPLATE = VBOXR3TSTEXE
    311315tstRTDigest_SOURCES = tstRTDigest.cpp
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