Menu

[r1129]: / advanced / src / test / test.c  Maximize  Restore  History

Download this file

745 lines (600 with data), 22.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/* Copyright information is at the end of the file. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include "casprintf.h"
#include "xmlrpc_config.h"
#include "xmlrpc-c/base.h"
#include "xmlrpc-c/server.h"
#include "test.h"
#include "value.h"
#include "serialize.h"
#include "parse_xml.h"
#include "cgi.h"
#include "xml_data.h"
#include "client.h"
#include "abyss.h"
#include "server_abyss.h"
#include "method_registry.h"
/*=========================================================================
** Test Harness
**=========================================================================
** This is a super light-weight test harness. It's vaguely inspired by
** Kent Beck's book on eXtreme Programming (XP)--the output is succinct,
** new tests can be coded quickly, and the whole thing runs in a few
** second's time.
**
** To run the tests, type './rpctest'.
** To check for memory leaks, install RedHat's 'memprof' utility, and
** type 'memprof rpctest'.
**
** If you add new tests to this file, please deallocate any data
** structures you use in the appropriate fashion. This allows us to test
** various destructor code for memory leaks.
*/
int total_tests = 0;
int total_failures = 0;
/*=========================================================================
** Test Data
**=========================================================================
** Some common test data which need to be allocated at a fixed address,
** or which are inconvenient to allocate inline.
*/
static char* test_string_1 = "foo";
static char* test_string_2 = "bar";
static int test_int_array_1[5] = {1, 2, 3, 4, 5};
static int test_int_array_2[3] = {6, 7, 8};
static int test_int_array_3[8] = {1, 2, 3, 4, 5, 6, 7, 8};
/*=========================================================================
** Test Suites
**=========================================================================
*/
static void test_env(void)
{
xmlrpc_env env, env2;
char *s;
/* Test xmlrpc_env_init. */
xmlrpc_env_init(&env);
TEST(!env.fault_occurred);
TEST(env.fault_code == 0);
TEST(env.fault_string == NULL);
/* Test xmlrpc_set_fault. */
xmlrpc_env_set_fault(&env, 1, test_string_1);
TEST(env.fault_occurred);
TEST(env.fault_code == 1);
TEST(env.fault_string != test_string_1);
TEST(strcmp(env.fault_string, test_string_1) == 0);
/* Change an existing fault. */
xmlrpc_env_set_fault(&env, 2, test_string_2);
TEST(env.fault_occurred);
TEST(env.fault_code == 2);
TEST(strcmp(env.fault_string, test_string_2) == 0);
/* Set a fault with a format string. */
xmlrpc_env_set_fault_formatted(&env, 3, "a%s%d", "bar", 9);
TEST(env.fault_occurred);
TEST(env.fault_code == 3);
TEST(strcmp(env.fault_string, "abar9") == 0);
/* Set a fault with an oversized string. */
s = "12345678901234567890123456789012345678901234567890";
xmlrpc_env_set_fault_formatted(&env, 4, "%s%s%s%s%s%s", s, s, s, s, s, s);
TEST(env.fault_occurred);
TEST(env.fault_code == 4);
TEST(strlen(env.fault_string) == 255);
/* Test cleanup code (with help from memprof). */
xmlrpc_env_clean(&env);
/* Test cleanup code on in absence of xmlrpc_env_set_fault. */
xmlrpc_env_init(&env2);
xmlrpc_env_clean(&env2);
}
static void test_mem_block (void)
{
xmlrpc_env env;
xmlrpc_mem_block* block;
xmlrpc_mem_block* typed_heap_block;
xmlrpc_mem_block typed_auto_block;
void** typed_contents;
xmlrpc_env_init(&env);
/* Allocate a zero-size block. */
block = xmlrpc_mem_block_new(&env, 0);
TEST_NO_FAULT(&env);
TEST(block != NULL);
TEST(xmlrpc_mem_block_size(block) == 0);
/* Grow the block a little bit. */
xmlrpc_mem_block_resize(&env, block, strlen(test_string_1) + 1);
TEST_NO_FAULT(&env);
TEST(xmlrpc_mem_block_size(block) == strlen(test_string_1) + 1);
/* Insert a string into the block, and resize it by large amount.
** We want to cause a reallocation and copy of the block contents. */
strcpy(xmlrpc_mem_block_contents(block), test_string_1);
xmlrpc_mem_block_resize(&env, block, 10000);
TEST_NO_FAULT(&env);
TEST(xmlrpc_mem_block_size(block) == 10000);
TEST(strcmp(xmlrpc_mem_block_contents(block), test_string_1) == 0);
/* Test cleanup code (with help from memprof). */
xmlrpc_mem_block_free(block);
/* Allocate a bigger block. */
block = xmlrpc_mem_block_new(&env, 128);
TEST_NO_FAULT(&env);
TEST(block != NULL);
TEST(xmlrpc_mem_block_size(block) == 128);
/* Test cleanup code (with help from memprof). */
xmlrpc_mem_block_free(block);
/* Allocate a "typed" memory block. */
typed_heap_block = XMLRPC_TYPED_MEM_BLOCK_NEW(void*, &env, 20);
TEST_NO_FAULT(&env);
TEST(typed_heap_block != NULL);
TEST(XMLRPC_TYPED_MEM_BLOCK_SIZE(void*, typed_heap_block) == 20);
typed_contents = XMLRPC_TYPED_MEM_BLOCK_CONTENTS(void*, typed_heap_block);
TEST(typed_contents != NULL);
/* Resize a typed memory block. */
XMLRPC_TYPED_MEM_BLOCK_RESIZE(void*, &env, typed_heap_block, 100);
TEST_NO_FAULT(&env);
TEST(XMLRPC_TYPED_MEM_BLOCK_SIZE(void*, typed_heap_block) == 100);
/* Test cleanup code (with help from memprof). */
XMLRPC_TYPED_MEM_BLOCK_FREE(void*, typed_heap_block);
/* Test _INIT and _CLEAN for stack-based memory blocks. */
XMLRPC_TYPED_MEM_BLOCK_INIT(void*, &env, &typed_auto_block, 30);
TEST(XMLRPC_TYPED_MEM_BLOCK_SIZE(void*, &typed_auto_block) == 30);
XMLRPC_TYPED_MEM_BLOCK_CLEAN(void*, &typed_auto_block);
/* Test xmlrpc_mem_block_append. */
block = XMLRPC_TYPED_MEM_BLOCK_NEW(int, &env, 5);
TEST_NO_FAULT(&env);
memcpy(XMLRPC_TYPED_MEM_BLOCK_CONTENTS(int, block),
test_int_array_1, sizeof(test_int_array_1));
XMLRPC_TYPED_MEM_BLOCK_APPEND(int, &env, block, test_int_array_2, 3);
TEST(XMLRPC_TYPED_MEM_BLOCK_SIZE(int, block) == 8);
TEST(memcmp(XMLRPC_TYPED_MEM_BLOCK_CONTENTS(int, block),
test_int_array_3, sizeof(test_int_array_3)) == 0);
XMLRPC_TYPED_MEM_BLOCK_FREE(int, block);
xmlrpc_env_clean(&env);
}
static char *(base64_triplets[]) = {
"", "", "\r\n",
"a", "YQ==", "YQ==\r\n",
"aa", "YWE=", "YWE=\r\n",
"aaa", "YWFh", "YWFh\r\n",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY"
"2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=",
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY"
"2Rl\r\n"
"ZmdoaWprbG1ub3BxcnN0dXZ3eHl6QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=\r\n",
NULL};
static void
test_base64_conversion(void) {
xmlrpc_env env;
char ** triplet;
xmlrpc_env_init(&env);
for (triplet = base64_triplets; *triplet != NULL; triplet += 3) {
char * bin_data;
char * nocrlf_ascii_data;
char * ascii_data;
xmlrpc_mem_block * output;
bin_data = *triplet;
nocrlf_ascii_data = *(triplet + 1);
ascii_data = *(triplet + 2);
/* Test our encoding routine. */
output = xmlrpc_base64_encode(&env,
(unsigned char*) bin_data,
strlen(bin_data));
TEST_NO_FAULT(&env);
TEST(output != NULL);
TEST(xmlrpc_mem_block_size(output) == strlen(ascii_data));
TEST(memcmp(xmlrpc_mem_block_contents(output), ascii_data,
strlen(ascii_data)) == 0);
xmlrpc_mem_block_free(output);
/* Test our newline-free encoding routine. */
output =
xmlrpc_base64_encode_without_newlines(&env,
(unsigned char*) bin_data,
strlen(bin_data));
TEST_NO_FAULT(&env);
TEST(output != NULL);
TEST(xmlrpc_mem_block_size(output) == strlen(nocrlf_ascii_data));
TEST(memcmp(xmlrpc_mem_block_contents(output), nocrlf_ascii_data,
strlen(nocrlf_ascii_data)) == 0);
xmlrpc_mem_block_free(output);
/* Test our decoding routine. */
output = xmlrpc_base64_decode(&env, ascii_data, strlen(ascii_data));
TEST_NO_FAULT(&env);
TEST(output != NULL);
TEST(xmlrpc_mem_block_size(output) == strlen(bin_data));
TEST(memcmp(xmlrpc_mem_block_contents(output), bin_data,
strlen(bin_data)) == 0);
xmlrpc_mem_block_free(output);
}
/* Now for something broken... */
{
xmlrpc_env env2;
xmlrpc_mem_block * output;
xmlrpc_env_init(&env2);
output = xmlrpc_base64_decode(&env2, "====", 4);
TEST(output == NULL);
TEST_FAULT(&env2, XMLRPC_PARSE_ERROR);
xmlrpc_env_clean(&env2);
}
/* Now for something broken in a really sneaky way... */
{
xmlrpc_env env2;
xmlrpc_mem_block * output;
xmlrpc_env_init(&env2);
output = xmlrpc_base64_decode(&env2, "a==", 4);
TEST(output == NULL);
TEST_FAULT(&env2, XMLRPC_PARSE_ERROR);
xmlrpc_env_clean(&env2);
}
xmlrpc_env_clean(&env);
}
static void test_bounds_checks (void)
{
xmlrpc_env env;
xmlrpc_value *array;
int i1, i2, i3, i4;
/* Get an array to work with. */
xmlrpc_env_init(&env);
array = xmlrpc_build_value(&env, "(iii)", 100, 200, 300);
TEST_NO_FAULT(&env);
xmlrpc_env_clean(&env);
/* Test xmlrpc_decompose_value with too few values. */
xmlrpc_env_init(&env);
xmlrpc_decompose_value(&env, array, "(iiii)", &i1, &i2, &i3, &i4);
TEST_FAULT(&env, XMLRPC_INDEX_ERROR);
xmlrpc_env_clean(&env);
/* Test xmlrpc_decompose_value with too many values. */
xmlrpc_env_init(&env);
xmlrpc_decompose_value(&env, array, "(ii)", &i1, &i2, &i3, &i4);
TEST_FAULT(&env, XMLRPC_INDEX_ERROR);
xmlrpc_env_clean(&env);
/* Dispose of our array. */
xmlrpc_DECREF(array);
}
static void test_nesting_limit (void)
{
xmlrpc_env env;
xmlrpc_value *val;
xmlrpc_env_init(&env);
/* Test with an adequate limit for a result value which is an
array which contains an element which is a struct, whose values
are simple: 3.
*/
xmlrpc_limit_set(XMLRPC_NESTING_LIMIT_ID, 3);
val = xmlrpc_parse_response(&env,
good_response_xml, strlen(good_response_xml));
TEST_NO_FAULT(&env);
TEST(val != NULL);
xmlrpc_DECREF(val);
/* Test with an inadequate limit. */
xmlrpc_limit_set(XMLRPC_NESTING_LIMIT_ID, 2);
val = xmlrpc_parse_response(&env,
good_response_xml, strlen(good_response_xml));
TEST_FAULT(&env, XMLRPC_PARSE_ERROR); /* BREAKME - Will change. */
TEST(val == NULL);
/* Reset the default limit. */
xmlrpc_limit_set(XMLRPC_NESTING_LIMIT_ID, XMLRPC_NESTING_LIMIT_DEFAULT);
TEST(xmlrpc_limit_get(XMLRPC_NESTING_LIMIT_ID)
== XMLRPC_NESTING_LIMIT_DEFAULT);
xmlrpc_env_clean(&env);
}
static void
test_xml_size_limit(void) {
xmlrpc_env env;
const char * methodName;
xmlrpc_value * paramsP;
/* NOTE - This test suite only verifies the last-ditch size-checking
code. There should also be matching code in all server (and
preferably all client) modules as well.
*/
/* Set our XML size limit to something ridiculous. */
xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 6);
/* Attempt to parse a call. */
xmlrpc_env_init(&env);
xmlrpc_parse_call(&env, serialized_call, strlen(serialized_call),
&methodName, &paramsP);
TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
xmlrpc_env_clean(&env);
{
xmlrpc_value * resultP;
int faultCode;
const char * faultString;
/* Attempt to parse a response. */
xmlrpc_env_init(&env);
xmlrpc_parse_response2(&env,
good_response_xml, strlen(good_response_xml),
&resultP, &faultCode, &faultString);
TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
xmlrpc_env_clean(&env);
}
/* Reset the default limit. */
xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, XMLRPC_XML_SIZE_LIMIT_DEFAULT);
}
/*=========================================================================
** test_sample_files
**=========================================================================
** Read in a bunch of sample test files and make sure we get plausible
** results.
**
** We use these files to test strange-but-legal encodings, illegal-but-
** supported encodings, etc.
*/
#define TESTDATA_DIR "data"
static char *good_requests[] = {
TESTDATA_DIR DIRECTORY_SEPARATOR "req_out_of_order.xml",
TESTDATA_DIR DIRECTORY_SEPARATOR "req_no_params.xml",
TESTDATA_DIR DIRECTORY_SEPARATOR "req_value_name.xml",
NULL
};
#define MAX_SAMPLE_FILE_LEN (16 * 1024)
static char file_buff [MAX_SAMPLE_FILE_LEN];
static void
read_file (char *path, char **out_data, size_t *out_size)
{
FILE *f;
size_t bytes_read;
/* Open the file. */
f = fopen(path, "r");
if (f == NULL) {
/* Since this error is fairly likely to happen, give an
** informative error message... */
fflush(stdout);
fprintf(stderr, "Could not open file '%s'. errno=%d (%s)\n",
path, errno, strerror(errno));
abort();
}
/* Read in one buffer full of data, and make sure that everything
** fit. (We perform a lazy error/no-eof/zero-length-file test using
** bytes_read.) */
bytes_read = fread(file_buff, sizeof(char), MAX_SAMPLE_FILE_LEN, f);
TEST(0 < bytes_read && bytes_read < MAX_SAMPLE_FILE_LEN);
/* Close the file and return our data. */
fclose(f);
*out_data = file_buff;
*out_size = bytes_read;
}
static void test_sample_files (void)
{
xmlrpc_env env;
char **paths, *path;
char *data;
size_t data_len;
const char *method_name;
xmlrpc_value *params;
xmlrpc_env_init(&env);
/* Test our good requests. */
for (paths = good_requests; *paths != NULL; paths++) {
path = *paths;
read_file(path, &data, &data_len);
xmlrpc_parse_call(&env, data, data_len, &method_name, &params);
TEST_NO_FAULT(&env);
strfree(method_name);
xmlrpc_DECREF(params);
}
xmlrpc_env_clean(&env);
}
/*=========================================================================
** test_utf8_coding
**=========================================================================
** We need to test our UTF-8 decoder thoroughly. Most of these test
** cases are taken from the UTF-8-test.txt file by Markus Kuhn
** <mkuhn@acm.org>:
** http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
*/
#if HAVE_UNICODE_WCHAR
typedef struct {
char *utf8;
wchar_t wcs[16];
} utf8_and_wcs;
static utf8_and_wcs good_utf8[] = {
/* Greek 'kosme'. */
{"\316\272\341\275\271\317\203\316\274\316\265",
{0x03BA, 0x1F79, 0x03C3, 0x03BC, 0x03B5, 0}},
/* First sequences of a given length. */
/* '\000' is not a legal C string. */
{"\302\200", {0x0080, 0}},
{"\340\240\200", {0x0800, 0}},
/* Last sequences of a given length. */
{"\177", {0x007F, 0}},
{"\337\277", {0x07FF, 0}},
/* 0xFFFF is not a legal Unicode character. */
/* Other boundry conditions. */
{"\001", {0x0001, 0}},
{"\355\237\277", {0xD7FF, 0}},
{"\356\200\200", {0xE000, 0}},
{"\357\277\275", {0xFFFD, 0}},
/* Other random test cases. */
{"", {0}},
{"abc", {0x0061, 0x0062, 0x0063, 0}},
{"[\302\251]", {0x005B, 0x00A9, 0x005D, 0}},
{NULL, {0}}
};
static char *(bad_utf8[]) = {
/* Continuation bytes. */
"\200", "\277",
/* Lonely start characters. */
"\300", "\300x", "\300xx",
"\340", "\340x", "\340xx", "\340xxx",
/* Last byte missing. */
"\340\200", "\340\200x", "\340\200xx",
"\357\277", "\357\277x", "\357\277xx",
/* Illegal bytes. */
"\376", "\377",
/* Overlong '/'. */
"\300\257", "\340\200\257",
/* Overlong ASCII NUL. */
"\300\200", "\340\200\200",
/* Maximum overlong sequences. */
"\301\277", "\340\237\277",
/* Illegal code positions. */
"\357\277\276", /* U+FFFE */
"\357\277\277", /* U+FFFF */
/* UTF-16 surrogates (unpaired and paired). */
"\355\240\200",
"\355\277\277",
"\355\240\200\355\260\200",
"\355\257\277\355\277\277",
/* Valid UCS-4 characters (we don't handle these yet).
** On systems with UCS-4 or UTF-16 wchar_t values, we
** may eventually handle these in some fashion. */
"\360\220\200\200",
"\370\210\200\200\200",
"\374\204\200\200\200\200",
NULL
};
#endif /* HAVE_UNICODE_WCHAR */
/* This routine is missing on certain platforms. This implementation
** *appears* to be correct. */
#if 0
#ifndef HAVE_WCSNCMP
int wcsncmp(wchar_t *wcs1, wchar_t* wcs2, size_t len)
{
size_t i;
/* XXX - 'unsigned long' should be 'uwchar_t'. */
unsigned long c1, c2;
for (i=0; i < len; i++) {
c1 = wcs1[i];
c2 = wcs2[i];
/* This clever comparison borrowed from the GNU C Library. */
if (c1 == 0 || c1 != c2)
return c1 - c2;
}
return 0;
}
#endif /* HAVE_WCSNCMP */
#endif
static void
test_utf8_coding(void) {
#if HAVE_UNICODE_WCHAR
xmlrpc_env env, env2;
utf8_and_wcs *good_data;
char **bad_data;
char *utf8;
wchar_t *wcs;
xmlrpc_mem_block *output;
xmlrpc_env_init(&env);
/* Test each of our valid UTF-8 sequences. */
for (good_data = good_utf8; good_data->utf8 != NULL; good_data++) {
utf8 = good_data->utf8;
wcs = good_data->wcs;
/* Attempt to validate the UTF-8 string. */
xmlrpc_validate_utf8(&env, utf8, strlen(utf8));
TEST_NO_FAULT(&env);
/* Attempt to decode the UTF-8 string. */
output = xmlrpc_utf8_to_wcs(&env, utf8, strlen(utf8));
TEST_NO_FAULT(&env);
TEST(output != NULL);
TEST(wcslen(wcs) == XMLRPC_TYPED_MEM_BLOCK_SIZE(wchar_t, output));
TEST(0 ==
wcsncmp(wcs, XMLRPC_TYPED_MEM_BLOCK_CONTENTS(wchar_t, output),
wcslen(wcs)));
xmlrpc_mem_block_free(output);
/* Test the UTF-8 encoder, too. */
output = xmlrpc_wcs_to_utf8(&env, wcs, wcslen(wcs));
TEST_NO_FAULT(&env);
TEST(output != NULL);
TEST(strlen(utf8) == XMLRPC_TYPED_MEM_BLOCK_SIZE(char, output));
TEST(0 ==
strncmp(utf8, XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, output),
strlen(utf8)));
xmlrpc_mem_block_free(output);
}
/* Test each of our illegal UTF-8 sequences. */
for (bad_data = bad_utf8; *bad_data != NULL; bad_data++) {
utf8 = *bad_data;
/* Attempt to validate the UTF-8 string. */
xmlrpc_env_init(&env2);
xmlrpc_validate_utf8(&env2, utf8, strlen(utf8));
TEST_FAULT(&env2, XMLRPC_INVALID_UTF8_ERROR);
/* printf("Fault: %s\n", env2.fault_string); --Hand-checked */
xmlrpc_env_clean(&env2);
/* Attempt to decode the UTF-8 string. */
xmlrpc_env_init(&env2);
output = xmlrpc_utf8_to_wcs(&env2, utf8, strlen(utf8));
TEST_FAULT(&env2, XMLRPC_INVALID_UTF8_ERROR);
TEST(output == NULL);
xmlrpc_env_clean(&env2);
}
xmlrpc_env_clean(&env);
#endif /* HAVE_UNICODE_WCHAR */
}
static void
test_server_cgi_maybe(void) {
#ifndef WIN32
test_server_cgi();
#endif
}
static void
test_client_maybe(void) {
#ifndef WIN32 /* Must get Windows Curl transport working for this to work */
test_client();
#endif
}
int
main(int argc,
char ** argv ATTR_UNUSED) {
int retval;
if (argc-1 > 0) {
fprintf(stderr, "There are no arguments.\n");
retval = 1;
} else {
test_env();
test_mem_block();
test_base64_conversion();
printf("\n");
test_value();
test_bounds_checks();
printf("\n");
test_serialize();
test_parse_xml();
test_method_registry();
test_nesting_limit();
test_xml_size_limit();
test_sample_files();
printf("\n");
test_server_cgi_maybe();
test_abyss();
test_server_abyss();
test_utf8_coding();
printf("\n");
test_client_maybe();
printf("\n");
/* Summarize our test run. */
printf("Ran %d tests, %d failed, %.1f%% passed\n",
total_tests, total_failures,
100.0 - (100.0 * total_failures) / total_tests);
/* Print the final result. */
if (total_failures == 0) {
printf("OK\n");
retval = 0;
} else {
retval = 1;
printf("FAILED\n");
}
}
return retval;
}
/* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE. */
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.