0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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
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
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
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
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
0122
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