VirtualBox

Changeset 73979 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Aug 30, 2018 1:58:20 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124715
Message:

IPRT/json: Made the json parser report error info. Currently we're failing to parse negative numbers, added this to tstRTJson. bugref:9167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTJson.cpp

    r69111 r73979  
    7575        { "[ 100, 200 ]",  VINF_SUCCESS },
    7676        { "{ \"1\": 1 }",  VINF_SUCCESS },
    77         { "{ \"1\": 1, \"2\": 2 }", VINF_SUCCESS }
     77        { "{ \"1\": 1, \"2\": 2 }", VINF_SUCCESS },
     78        { "20", VINF_SUCCESS },
     79        { "-20", VINF_SUCCESS },
     80        { "{\"positive\":20}", VINF_SUCCESS },
     81        { "{\"negative\":-20}", VINF_SUCCESS },
    7882    };
    7983    for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++)
    8084    {
     85        RTERRINFOSTATIC ErrInfo;
    8186        RTJSONVAL hJsonVal = NIL_RTJSONVAL;
    82         int rc = RTJsonParseFromString(&hJsonVal, aTests[iTest].pszJson, NULL);
     87        int rc = RTJsonParseFromString(&hJsonVal, aTests[iTest].pszJson, RTErrInfoInitStatic(&ErrInfo));
    8388        if (rc != aTests[iTest].iRcResult)
    84             RTTestFailed(hTest, "RTJsonParseFromString() for \"%s\" failed, expected %Rrc got %Rrc\n",
    85                          aTests[iTest].pszJson, aTests[iTest].iRcResult, rc);
     89        {
     90            if (RTErrInfoIsSet(&ErrInfo.Core))
     91                RTTestFailed(hTest, "RTJsonParseFromString() for \"%s\" failed, expected %Rrc got %Rrc\n%s",
     92                             aTests[iTest].pszJson, aTests[iTest].iRcResult, rc, ErrInfo.Core.pszMsg);
     93            else
     94                RTTestFailed(hTest, "RTJsonParseFromString() for \"%s\" failed, expected %Rrc got %Rrc",
     95                             aTests[iTest].pszJson, aTests[iTest].iRcResult, rc);
     96        }
     97        else if (rc == VERR_JSON_MALFORMED && !RTErrInfoIsSet(&ErrInfo.Core))
     98            RTTestFailed(hTest, "RTJsonParseFromString() did not return error info for \"%s\" failed", aTests[iTest].pszJson);
    8699        if (RT_SUCCESS(rc))
    87100        {
     
    275288}
    276289
    277 int main()
     290int main(int argc, char **argv)
    278291{
    279292    RTTEST hTest;
    280     int rc = RTTestInitAndCreate("tstRTJson", &hTest);
     293    int rc = RTTestInitExAndCreate(argc, &argv, 0, "tstRTJson", &hTest);
    281294    if (rc)
    282295        return rc;
     
    285298    tstBasic(hTest);
    286299    tstCorrectness(hTest);
     300    for (int i = 1; i < argc; i++)
     301    {
     302        RTTestSubF(hTest, "file %Rbn", argv[i]);
     303        RTERRINFOSTATIC ErrInfo;
     304        RTJSONVAL       hFileValue = NIL_RTJSONVAL;
     305        rc = RTJsonParseFromFile(&hFileValue, argv[i], RTErrInfoInitStatic(&ErrInfo));
     306        if (RT_SUCCESS(rc))
     307            RTJsonValueRelease(hFileValue);
     308        else if (RTErrInfoIsSet(&ErrInfo.Core))
     309            RTTestFailed(hTest, "%Rrc - %s", rc, ErrInfo.Core.pszMsg);
     310        else
     311            RTTestFailed(hTest, "%Rrc", rc);
     312    }
    287313
    288314    /*
Note: See TracChangeset for help on using the changeset viewer.

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