Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief JSON<->UBF testing
0003  *
0004  * @file atmiclt24.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044 #include "test024.h"
0045 
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048 /*---------------------------Enums--------------------------------------*/
0049 /*---------------------------Typedefs-----------------------------------*/
0050 /*---------------------------Globals------------------------------------*/
0051 /*---------------------------Statics------------------------------------*/
0052 /*---------------------------Prototypes---------------------------------*/
0053 
0054 int main(int argc, char **argv)
0055 {
0056         int ret = EXSUCCEED;
0057         UBFH *p_fb;
0058         int i;
0059         
0060         char *json = "{\"T_SHORT_FLD\":1765,"
0061         "\"T_LONG_FLD\":[3333111,2],"
0062         "\"T_CHAR_FLD\":\"A\","
0063         "\"T_FLOAT_FLD\":1,"
0064         "\"T_DOUBLE_FLD\":[1111.220000,333,444],"
0065         "\"T_STRING_FLD\":\"HELLO WORLD\","
0066         "\"T_CARRAY_FLD\":\"AAECA0hFTExPIEJJTkFSWQQFAA==\"}";
0067         
0068         char jsonout[1024];
0069         
0070         for (i=0; i<10000; i++)
0071         {
0072             p_fb = (UBFH *)tpalloc("UBF", NULL, 4096);
0073             if (EXSUCCEED!=tpjsontoubf(p_fb, json))
0074             {
0075                 NDRX_LOG(log_error, "TESTERROR: failed to parse json!");
0076                 ret=EXFAIL;
0077                 goto out;
0078             }
0079 
0080             Bprint(p_fb);
0081 
0082             memset(jsonout, 0, sizeof(jsonout));
0083 
0084             if (EXSUCCEED!=tpubftojson(p_fb, jsonout, sizeof(jsonout)))
0085             {
0086                 NDRX_LOG(log_error, "TESTERROR: Failed to build json!!!!");
0087                 ret=EXFAIL;
0088                 goto out;
0089             }
0090             
0091             NDRX_LOG(log_info, "JSON built: [%s]", jsonout);
0092             
0093             if (0!=strcmp(json, jsonout))
0094             {
0095                 NDRX_LOG(log_error, "Original json differs from built! org: [%s], built: [%s]", 
0096                         json, jsonout);
0097                 ret=EXFAIL;
0098                 goto out;
0099             }
0100             
0101             tpfree((char *)p_fb);
0102             
0103         }
0104         
0105 out:
0106         return ret;
0107 }
0108 /* vim: set ts=4 sw=4 et smartindent: */