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 <unistd.h>
0038 #include <cgreen/cgreen.h>
0039 #include <ubf.h>
0040 #include <ndrstandard.h>
0041 #include <string.h>
0042 #include "test.fd.h"
0043
0044 #include "ndebug.h"
0045 #include "xatmi.h"
0046 #include <fdatatype.h>
0047 #include <typed_buf.h>
0048
0049 extern TestSuite *atmiunit0_mbuf(void);
0050 extern TestSuite *atmiunit0_exproto(void);
0051
0052
0053
0054
0055 exprivate void basic_setup(void)
0056 {
0057
0058 }
0059
0060 exprivate void basic_teardown(void)
0061 {
0062
0063 }
0064
0065
0066
0067
0068 Ensure(test_recursfree)
0069 {
0070 UBFH *p_ub1;
0071 UBFH *p_ub2;
0072 UBFH *p_ub3;
0073 UBFH *p_ub4;
0074 ndrx_growlist_t list;
0075
0076 ndrx_buffer_list(&list);
0077
0078 assert_equal(list.maxindexused, -1);
0079
0080 p_ub1=(UBFH *)tpalloc("UBF", NULL, 1024);
0081 assert_not_equal(p_ub1, NULL);
0082
0083 p_ub2=(UBFH *)tpalloc("UBF", NULL, 1024);
0084 assert_not_equal(p_ub2, NULL);
0085
0086 p_ub3=(UBFH *)tpalloc("UBF", NULL, 1024);
0087 assert_not_equal(p_ub3, NULL);
0088
0089 p_ub4=(UBFH *)tpalloc("UBF", NULL, 1024);
0090 assert_not_equal(p_ub4, NULL);
0091
0092
0093 assert_equal(Bchg(p_ub2, T_PTR_FLD, 0, (char *)&p_ub4, 0), EXSUCCEED);
0094 assert_equal(Bchg(p_ub2, T_STRING_FLD, 0, "HELLO WORLD", 0), EXSUCCEED);
0095 assert_equal(tpsetcallinfo((char *)p_ub1, p_ub2, 0), 0);
0096
0097 assert_equal(Bchg(p_ub2, T_PTR_FLD, 0, (char *)&p_ub3, 0), EXSUCCEED);
0098
0099 assert_equal(Bchg(p_ub3, T_STRING_FLD, 0, "HELLO WORLD 2", 0), EXSUCCEED);
0100 assert_equal(Bchg(p_ub1, T_PTR_FLD, 0, (char *)&p_ub2, 0), EXSUCCEED);
0101 assert_equal(Bchg(p_ub1, T_PTR_FLD, 1, (char *)&p_ub2, 0), EXSUCCEED);
0102 assert_equal(Bchg(p_ub1, T_UBF_FLD, 1, (char *)p_ub2, 0), EXSUCCEED);
0103
0104 ndrx_buffer_list(&list);
0105
0106 assert_equal(list.maxindexused, 4);
0107
0108 tpfree((char *)p_ub1);
0109
0110 ndrx_buffer_list(&list);
0111 assert_equal(list.maxindexused, -1);
0112 }
0113
0114
0115
0116
0117 Ensure(test_tpcallinfo)
0118 {
0119 char *call_buf;
0120 UBFH *p_meta_ubf;
0121 UBFH *p_other_buf;
0122 char tmp[100];
0123 char tmp2[1024];
0124 BFLDLEN len;
0125 assert_equal(tpinit(NULL), EXSUCCEED);
0126
0127
0128 call_buf=tpalloc("STRING", NULL, 1024);
0129 assert_not_equal(call_buf, NULL);
0130
0131 p_meta_ubf=(UBFH *)tpalloc("UBF", NULL, 1024);
0132 assert_not_equal(p_meta_ubf, NULL);
0133
0134 p_other_buf=(UBFH *)tpalloc("STRING", NULL, 100);
0135 assert_not_equal(p_other_buf, NULL);
0136
0137
0138 assert_equal(Bchg(p_meta_ubf, T_STRING_FLD, 0, "HELLO", 0), EXSUCCEED);
0139 assert_equal(Bchg(p_meta_ubf, T_STRING_FLD, 5, "WORLD", 0), EXSUCCEED);
0140
0141 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, 0), EXFAIL);
0142 assert_equal(tperrno, TPESYSTEM);
0143
0144
0145 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, TPCI_NOEOFERR), 0);
0146 assert_equal(tperrno, 0);
0147
0148 assert_equal(tpsetcallinfo(call_buf, p_meta_ubf, 0), EXSUCCEED);
0149
0150
0151 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, 0), EXSUCCEED);
0152 len=sizeof(tmp);
0153 assert_equal(Bget(p_other_buf, T_STRING_FLD, 0, tmp, &len), EXSUCCEED);
0154 assert_string_equal(tmp, "HELLO");
0155
0156 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, TPCI_NOEOFERR), EXTRUE);
0157 len=sizeof(tmp);
0158 assert_equal(Bget(p_other_buf, T_STRING_FLD, 0, tmp, &len), EXSUCCEED);
0159 assert_string_equal(tmp, "HELLO");
0160
0161 len=sizeof(tmp);
0162 assert_equal(Bget(p_other_buf, T_STRING_FLD, 5, tmp, &len), EXSUCCEED);
0163 assert_string_equal(tmp, "WORLD");
0164
0165
0166 tpfree((char *)p_other_buf);
0167 p_other_buf = NULL;
0168
0169 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, 0), EXSUCCEED);
0170
0171 len=sizeof(tmp);
0172 assert_equal(Bget(p_other_buf, T_STRING_FLD, 0, tmp, &len), EXSUCCEED);
0173 assert_string_equal(tmp, "HELLO");
0174
0175 len=sizeof(tmp);
0176 assert_equal(Bget(p_other_buf, T_STRING_FLD, 5, tmp, &len), EXSUCCEED);
0177 assert_string_equal(tmp, "WORLD");
0178
0179
0180 tpfree((char *)p_other_buf);
0181
0182
0183 assert_equal(Binit(p_meta_ubf, Bsizeof(p_meta_ubf)), EXSUCCEED);
0184 len=sizeof(tmp);
0185 assert_equal(Bget(p_meta_ubf, T_STRING_FLD, 0, tmp, &len), EXFAIL);
0186
0187 assert_equal(tpgetcallinfo(call_buf, &p_meta_ubf, 0), EXSUCCEED);
0188
0189 len=sizeof(tmp);
0190 assert_equal(Bget(p_meta_ubf, T_STRING_FLD, 0, tmp, &len), EXSUCCEED);
0191 assert_string_equal(tmp, "HELLO");
0192
0193 len=sizeof(tmp);
0194 assert_equal(Bget(p_meta_ubf, T_STRING_FLD, 5, tmp, &len), EXSUCCEED);
0195 assert_string_equal(tmp, "WORLD");
0196
0197
0198
0199
0200 p_other_buf=(UBFH *)tmp2;
0201 Binit(p_other_buf, sizeof(tmp2));
0202 assert_equal(Bchg(p_other_buf, T_STRING_10_FLD, 0, "10 test", 0), EXSUCCEED);
0203
0204 assert_equal(tpsetcallinfo(call_buf, p_other_buf, 0), EXSUCCEED);
0205
0206 Binit(p_other_buf, sizeof(tmp2));
0207
0208
0209 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, 0), EXFAIL);
0210 assert_equal(tperrno, TPEINVAL);
0211
0212
0213 p_other_buf=NULL;
0214 assert_equal(tpgetcallinfo(call_buf, &p_other_buf, 0), EXSUCCEED);
0215 assert_equal(Bget(p_other_buf, T_STRING_10_FLD, 0, tmp, 0), EXSUCCEED);
0216 assert_string_equal(tmp, "10 test");
0217
0218
0219 tpfree((char *)p_other_buf);
0220
0221
0222 NDRX_LOG(log_info, "Testing errors...");
0223
0224 assert_equal(tpsetcallinfo(NULL, p_meta_ubf, 0), EXFAIL);
0225 assert_equal(tperrno, TPEINVAL);
0226
0227 assert_equal(tpgetcallinfo(NULL, &p_meta_ubf, 0), EXFAIL);
0228 assert_equal(tperrno, TPEINVAL);
0229
0230
0231 assert_equal(tpsetcallinfo(call_buf, p_meta_ubf, 999), EXFAIL);
0232 assert_equal(tperrno, TPEINVAL);
0233
0234 assert_equal(tpgetcallinfo(call_buf, &p_meta_ubf, 999), EXFAIL);
0235 assert_equal(tperrno, TPEINVAL);
0236
0237 assert_equal(tpgetcallinfo(call_buf, &p_meta_ubf, 999|TPCI_NOEOFERR), EXFAIL);
0238 assert_equal(tperrno, TPEINVAL);
0239
0240
0241 assert_equal(tpgetcallinfo(call_buf, NULL, 0), EXFAIL);
0242 assert_equal(tperrno, TPEINVAL);
0243
0244 assert_equal(tpsetcallinfo(call_buf, NULL, 0), EXFAIL);
0245 assert_equal(tperrno, TPEINVAL);
0246
0247 tpfree(call_buf);
0248 tpfree((char *)p_meta_ubf);
0249
0250 assert_equal(tpterm(), EXSUCCEED);
0251 }
0252
0253
0254
0255
0256
0257 TestSuite *atmiunit0_base(void)
0258 {
0259 TestSuite *suite = create_test_suite();
0260
0261 add_test(suite, test_tpcallinfo);
0262 add_test(suite, test_recursfree);
0263
0264 return suite;
0265 }
0266
0267
0268
0269
0270 int main(int argc, char** argv)
0271 {
0272 TestSuite *suite = create_test_suite();
0273 int ret;
0274
0275 add_suite(suite, atmiunit0_exproto());
0276 add_suite(suite, atmiunit0_base());
0277 add_suite(suite, atmiunit0_mbuf());
0278
0279 if (argc > 1)
0280 {
0281 ret=run_single_test(suite,argv[1],create_text_reporter());
0282 }
0283 else
0284 {
0285 ret=run_test_suite(suite, create_text_reporter());
0286 }
0287
0288 destroy_test_suite(suite);
0289
0290 return ret;
0291 }
0292
0293