Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Growlist testing from Enduro/X Standard Library
0003  *
0004  * @file test_nstd_growlist.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 
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <cgreen/cgreen.h>
0038 #include <ubf.h>
0039 #include <ndrstandard.h>
0040 #include <string.h>
0041 #include <ndebug.h>
0042 #include <exbase64.h>
0043 #include "test.fd.h"
0044 #include "ubfunit1.h"
0045 #include "xatmi.h"
0046 #include <nstdutil.h>
0047 
0048 /**
0049  * Test string buffer mode
0050  */
0051 Ensure(test_nstd_growlist_strbuf)
0052 {
0053     ndrx_growlist_t list;
0054     ndrx_growlist_init(&list, 2, sizeof(char));
0055     
0056     assert_equal(EXSUCCEED, ndrx_growlist_append_many(&list, "HELLO WORLD", 11));
0057     /* add EOS: */
0058     assert_equal(EXSUCCEED, ndrx_growlist_append_many(&list, "", 1));
0059 
0060     assert_string_equal(list.mem, "HELLO WORLD");
0061     assert_equal(list.maxindexused, 11);
0062     
0063     /* add some more stuff..., include EOS */
0064     assert_equal(EXSUCCEED, ndrx_growlist_add_many(&list, " FROM MARS1", 11, 12));
0065     assert_string_equal(list.mem, "HELLO WORLD FROM MARS1");
0066     assert_equal(list.maxindexused, 22);
0067     
0068     ndrx_growlist_free(&list);
0069 
0070 }
0071     
0072 /**
0073  * Basic grow list testing
0074  */
0075 Ensure(test_nstd_growlist)
0076 {
0077     ndrx_growlist_t list;
0078     long i;
0079     long *data;
0080     
0081     ndrx_growlist_init(&list, 11, sizeof(void *));
0082     
0083     for (i=0; i<100; i++)
0084     {
0085         assert_equal(EXSUCCEED, ndrx_growlist_add(&list, (void *)&i, i));
0086     }
0087     
0088     for (i=0; i<100; i++)
0089     {
0090         data = (long*)((char *)(list.mem) + i * sizeof(void *));
0091         
0092         assert_equal( i, *data);
0093     }
0094     
0095     assert_equal(list.maxindexused, 99);
0096     
0097     i = 777;
0098     assert_equal(EXSUCCEED, ndrx_growlist_add(&list, (void *)&i, 999));
0099     
0100     assert_equal(list.maxindexused, 999);
0101     
0102     data = (long*)((char *)(list.mem) + 999 * sizeof(void *));
0103         
0104     assert_equal( i, *data);
0105     
0106     i=1001;
0107     assert_equal(EXSUCCEED, ndrx_growlist_append(&list, (void *)&i));
0108     
0109     assert_equal(*NDRX_GROWLIST_ACCESS(&list, 1000, long), (long)1001);
0110     
0111     data = (long*)((char *)(list.mem) + 1000 * list.size);
0112         
0113     assert_equal( i, *data);
0114     
0115     
0116     ndrx_growlist_free(&list);
0117     
0118 }
0119 
0120 /**
0121  * Grow list testing
0122  * @return
0123  */
0124 TestSuite *ubf_nstd_growlist(void)
0125 {
0126     TestSuite *suite = create_test_suite();
0127 
0128     add_test(suite, test_nstd_growlist);
0129     add_test(suite, test_nstd_growlist_strbuf);
0130     return suite;
0131 }
0132 /* vim: set ts=4 sw=4 et smartindent: */