VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTJson.cpp@ 61718

Last change on this file since 61718 was 61718, checked in by vboxsync, 8 years ago

properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: tstRTJson.cpp 61718 2016-06-15 13:27:56Z vboxsync $ */
2/** @file
3 * IPRT Testcase - JSON API.
4 */
5
6/*
7 * Copyright (C) 2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/json.h>
32
33#include <iprt/test.h>
34
35
36int main()
37{
38 RTTEST hTest;
39 int rc = RTTestInitAndCreate("tstRTJson", &hTest);
40 if (rc)
41 return rc;
42 RTTestBanner(hTest);
43
44 RTTestSub(hTest, "RTJsonParseFromString");
45 static struct
46 {
47 const char *pszJson;
48 int iRcResult;
49 } const aTests[] =
50 {
51 { "", VERR_JSON_MALFORMED },
52 { ",", VERR_JSON_MALFORMED },
53 { ":", VERR_JSON_MALFORMED },
54 { "null", VINF_SUCCESS },
55 { "true", VINF_SUCCESS },
56 { "false", VINF_SUCCESS },
57 { "100", VINF_SUCCESS },
58 { "\"test\"", VINF_SUCCESS },
59 { "{ }", VINF_SUCCESS },
60 { "[ ]", VINF_SUCCESS },
61 };
62 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++)
63 {
64 RTJSONVAL hJsonVal = NIL_RTJSONVAL;
65 rc = RTJsonParseFromString(&hJsonVal, aTests[iTest].pszJson, NULL);
66 if (rc != aTests[iTest].iRcResult)
67 RTTestIFailed("RTJsonParseFromString() failed, expected %Rrc got %Rrc\n",
68 aTests[iTest].iRcResult, rc);
69 if (RT_SUCCESS(rc))
70 {
71 if (hJsonVal != NIL_RTJSONVAL)
72 RTJsonValueRelease(hJsonVal);
73 else
74 RTTestIFailed("RTJsonParseFromString() returned success but no value\n");
75 }
76 else if (hJsonVal != NIL_RTJSONVAL)
77 RTTestIFailed("RTJsonParseFromString() failed but a JSON value was returned\n");
78 }
79
80 /*
81 * Summary.
82 */
83 return RTTestSummaryAndDestroy(hTest);
84}
85
Note: See TracBrowser for help on using the repository browser.

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