File: test-wget-1.c

package info (click to toggle)
wget2 1.99.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,468 kB
  • sloc: ansic: 88,607; sh: 10,241; makefile: 501; xml: 182; sed: 16
file content (688 lines) | stat: -rw-r--r-- 18,191 bytes parent folder | download
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
/*
 * Copyright(c) 2013 Tim Ruehsen
 * Copyright(c) 2015-2018 Free Software Foundation, Inc.
 *
 * This file is part of libwget.
 *
 * Libwget is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Libwget is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libwget.  If not, see <https://www.gnu.org/licenses/>.
 *
 *
 * Testing Wget
 *
 * Changelog
 * 10.03.2013  Tim Ruehsen  created
 *
 */

#include <config.h>

#include <stdlib.h> // exit()
#include <string.h> // strlen()
#include "libtest.h"

static const char *mainpage = "\
<html>\n\
<head>\n\
  <title>Main Page</title>\n\
</head>\n\
<body>\n\
  <p>\n\
    Some text and a link to a <a href=\"http://localhost:{{port}}/secondpage.html\">second page</a>.\n\
    Also, a <a href=\"http://localhost:{{port}}/nonexistent\">broken link</a>.\n\
  </p>\n\
</body>\n\
</html>\n";

static const char *secondpage = "\
<html>\n\
<head>\n\
  <title>Main Page</title>\n\
</head>\n\
<body>\n\
  <p>\n\
    Some text and a link to a <a href=\"http://localhost:{{port}}/thirdpage.html\">third page</a>.\n\
    Also, a <a href=\"http://localhost:{{port}}/nonexistent\">broken link</a>.\n\
  </p>\n\
</body>\n\
</html>\n";

static const char *thirdpage = "\
<html>\n\
<head>\n\
  <title>Main Page</title>\n\
</head>\n\
<body>\n\
  <p>\n\
    Some text and a link to a <a href=\"http://localhost:{{port}}/dummy.txt\">dummy text</a>.\n\
    Also, a <a href=\"http://localhost:{{port}}/againnonexistent\">broken link</a>.\n\
  </p>\n\
</body>\n\
</html>\n";

static const char *dummypage = "\
<html>\n\
<head>\n\
  <title>Main Page</title>\n\
</head>\n\
<body>\n\
  <p>\n\
    Don't care.\n\
  </p>\n\
</body>\n\
</html>\n";

static const char *errorpage = "\
<html>\n\
<head>\n\
  <title>Main Page</title>\n\
</head>\n\
<body>\n\
  <p>\n\
    Error.\n\
  </p>\n\
</body>\n\
</html>\n";

int main(void)
{
	wget_test_url_t urls[]={
		{	.name = "/index.html",
			.code = "200 Dontcare",
			.body = mainpage,
			.headers = {
				"Content-Type: text/html",
			}
		},
		{	.name = "/secondpage.html",
			.code = "200 Dontcare",
			.body = secondpage,
			.headers = {
				"Content-Type: text/html",
			}
		},
		{	.name = "/thirdpage.html",
			.code = "200 Dontcare",
			.body = thirdpage,
			.headers = {
				"Content-Type: text/html",
			}
		},
		{	.name = "/dummy.txt",
			.code = "200 Dontcare",
			.body = "Don't care.",
			.headers = {
				"Content-Type: text/plain",
			},
		},
		{	.name = "/dummy.html",
			.code = "200 Dontcare",
			.body = dummypage,
			.headers = {
				"Content-Type: text/plain",
            "Content-Disposition: attachment; filename=\"filename.html\"",
			}
		},
		{	.name = "/dummy2.html",
			.code = "200 Dontcare",
			.body = dummypage,
			.headers = {
				"Content-Type: text/plain",
            "Content-Disposition: attachment; filename*=UTF-8''%66ile_fran%c3%A7ais.html",
			}
		},
		{	.name = "/error.html",
			.code = "404 Not exist",
			.body = errorpage,
			.headers = {
				"Content-Type: text/html",
			}
		}
	};

	// functions won't come back if an error occurs
	wget_test_start_server(
		WGET_TEST_RESPONSE_URLS, &urls, countof(urls),
		WGET_TEST_FEATURE_MHD,
		0);

	// some tests are not working on file systems that mangle filenames to lower- or uppercase
	int fs_flags = wget_test_check_file_system();

	// test-noop
	wget_test(
		WGET_TEST_REQUEST_URL, "index.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{ "index.html", urls[0].body },
			{	NULL } },
		0);

	// test-nonexistent-quiet
	wget_test(
		WGET_TEST_OPTIONS, "--quiet",
		WGET_TEST_REQUEST_URL, "nonexistent",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		0);

	// test-stdouterr
#ifdef __linux__
	if (access("/dev/full", W_OK)) {
		// TODO: Find better file to use for other operating systems.
		wget_test(
			WGET_TEST_OPTIONS, "-c -O /dev/full",
			WGET_TEST_REQUEST_URL, "dummy.txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 3,
			0);
	}
#endif

	// test--spider
	wget_test(
		WGET_TEST_OPTIONS, "--spider",
		WGET_TEST_REQUEST_URL, "index.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		0);

	// test--spider-fail
	wget_test(
		WGET_TEST_OPTIONS, "--spider",
		WGET_TEST_REQUEST_URL, "nonexistent",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		0);

	// test--spider-r--no-content-disposition-trivial
	wget_test(
		WGET_TEST_OPTIONS, "--spider -r --no-content-disposition",
		WGET_TEST_REQUEST_URL, "",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		0);

	// test--no-content-disposition-trivial
	wget_test(
		WGET_TEST_OPTIONS, "--no-content-disposition",
		WGET_TEST_REQUEST_URL, "index.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{ "index.html", urls[0].body },
			{	NULL } },
		0);

	urls[1].headers[1] = "Content-Disposition: attachment; filename=\"filename.html\"";

	// test--no-content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "--no-content-disposition",
		WGET_TEST_REQUEST_URL, "index.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{ "index.html", urls[0].body },
			{	NULL } },
		0);

	// test--spider-r--no-content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "--spider -r --no-content-disposition",
		WGET_TEST_REQUEST_URL, "",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		0);

	urls[1].headers[1] = NULL;

	// test--HTTP-content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "-e contentdisposition=on",
		WGET_TEST_REQUEST_URL, "dummy.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"filename.html", dummypage },
			{	NULL } },
		0);

	// test--HTTP-content-disposition-1
	wget_test(
		WGET_TEST_OPTIONS, "-e contentdisposition=on",
		WGET_TEST_REQUEST_URL, "dummy.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{	"filename.html", "dontcare" },
			{	"filename.html.1", "dontcare" },
			{	NULL } },
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"filename.html", "dontcare" },
			{	"filename.html.1", "dontcare" },
			{	"filename.html.2", dummypage },
			{	NULL } },
		0);

	// test--HTTP-content-disposition-2
	wget_test(
		WGET_TEST_OPTIONS, "--no-content-disposition",
		WGET_TEST_REQUEST_URL, "dummy.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{	"filename.html", "dontcare" },
			{	"filename.html.1", "dontcare" },
			{	NULL } },
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"filename.html", "dontcare" },
			{	"filename.html.1", "dontcare" },
			{	"dummy.html", dummypage },
			{	NULL } },
		0);

	// test--HTTP-content-disposition-RFC6266
#define ccedilla_u8 "\xC3\xA7"
	wget_test(
		WGET_TEST_OPTIONS, "-e contentdisposition=on --local-encoding=utf-8",
		WGET_TEST_REQUEST_URL, "dummy2.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{	"filename.html", "dontcare" },
			{	"filename.html.1", "dontcare" },
			{	NULL } },
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"filename.html", "dontcare" },
			{	"filename.html.1", "dontcare" },
			{	"file_fran" ccedilla_u8 "ais.html", dummypage },
			{	NULL } },
		0);

	urls[3].headers[1] = "Last-Modified: Sat, 09 Oct 2004 08:30:00 GMT";

	// test-N--no-content-disposition-trivial
	wget_test(
		WGET_TEST_OPTIONS, "-N --no-content-disposition",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body, 1097310600 },
			{	NULL } },
		0);

	urls[3].headers[2] = "Content-Disposition: attachment; filename=\"filename.txt\"";

	// test-N--no-content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "-N --no-content-disposition",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body, 1097310600 },
			{	NULL } },
		0);

	// test-N-HTTP--content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "-N --content-disposition",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"filename.txt", urls[3].body, 1097310600 },
			{	NULL } },
		0);

	urls[3].headers[2] = NULL;

	{
		// server sends same length content with slightly different content
		char modified[strlen(urls[3].body) + 1];

		memcpy(modified, urls[3].body, sizeof(modified));
		modified[3] = 'x';

		urls[3].modified = 1097310600;

		// test-N-current
		wget_test(
			WGET_TEST_OPTIONS, "-N",
			WGET_TEST_REQUEST_URL, "dummy.txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", modified, 1097310600 },
				{	NULL } },
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", modified, 1097310600 },
				{	NULL } },
			0);

		// test-N-old
		wget_test(
			WGET_TEST_OPTIONS, "-N",
			WGET_TEST_REQUEST_URL, "dummy.txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", modified, 1097310000 }, // earlier timestamp
				{	NULL } },
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", urls[3].body, 1097310600 },
				{	NULL } },
			0);

/*
		// test-N-smaller
		// This test just works with a HEAD request. But Wget uses If-Modified-Since.
		const char *old_body = urls[3].body;
		modified[strlen(modified)-2] = 0;
		urls[3].body = modified;
		wget_test(
			WGET_TEST_OPTIONS, "-N",
			WGET_TEST_REQUEST_URL, "dummy.txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", old_body, 1097310600 },
				{	NULL } },
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", modified, 1097310600 },
				{	NULL } },
			0);
		urls[3].body = old_body; // restore body
*/
	}

	// test-N
	wget_test(
		WGET_TEST_OPTIONS, "-N",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body, 0},
			{	NULL } },
		0);

	urls[3].headers[1] = NULL;

/*
	// test-N-no-info
	// This test just works with a HEAD request. But Wget uses If-Modified-Since.
	wget_test(
		WGET_TEST_OPTIONS, "-N",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", "anycontent", 1097310600 },
			{	NULL } },
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body, 0},
			{	NULL } },
		0);
*/

	urls[1].headers[1] = "Content-Disposition: attachment; filename=\"filename.html\"";

	// test-O--no-content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "-O out --no-content-disposition",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"out", urls[3].body },
			{	NULL } },
		0);

	// test-O-HTTP-content-disposition
	wget_test(
		WGET_TEST_OPTIONS, "-O out",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"out", urls[3].body },
			{	NULL } },
		0);


	urls[3].headers[1] = NULL;

	// test-O-nc
	wget_test(
		WGET_TEST_OPTIONS, "-nc -O out",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"out", urls[3].body },
			{	NULL } },
		0);

	// test-O-nonexisting
	wget_test(
		WGET_TEST_OPTIONS, "-O out",
		WGET_TEST_REQUEST_URL, "nonexistent",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			// {	"out", "" }, // Wget would create an empty file here, but Wget not
			{	NULL } },
		0);

	// test-O
	wget_test(
		WGET_TEST_OPTIONS, "-O out",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"out", urls[3].body },
			{	NULL } },
		0);

	if ((fs_flags & WGET_TEST_FS_CASEMATTERS) == 0) {
		urls[3].name="/DuMmy.Txt";

		// test-restrict-lowercase
		wget_test(
			WGET_TEST_OPTIONS, "--restrict-file-names=lowercase",
			WGET_TEST_REQUEST_URL, "DuMmy.Txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", urls[3].body },
				{	NULL } },
			0);

		// test-restrict-uppercase
		wget_test(
			WGET_TEST_OPTIONS, "--restrict-file-names=uppercase",
			WGET_TEST_REQUEST_URL, "DuMmy.Txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"DUMMY.TXT", urls[3].body },
				{	NULL } },
			0);

		urls[3].name="/dummy.txt";
	}

	// test-c-full
	wget_test(
		WGET_TEST_OPTIONS, "-c",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	{
		// server sends same length content with slightly different content
		char *partial = wget_strmemdup(urls[3].body, strlen(urls[3].body)-2);

		// test-c-partial
		wget_test(
			WGET_TEST_OPTIONS, "-c",
			WGET_TEST_REQUEST_URL, "dummy.txt",
//			WGET_TEST_KEEP_TMPFILES, 1,
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", partial },
				{	NULL } },
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", urls[3].body },
				{	NULL } },
			0);

		wget_test(
			WGET_TEST_OPTIONS, "--header Range:bytes=9-",
			WGET_TEST_REQUEST_URL, "dummy.txt",
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", partial },
				{	NULL } },
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", urls[3].body },
				{	NULL } },
			0);

		wget_xfree(partial);
	}


/*
 * this test needs a broken server ... I don't have one right now.
	{
		// server sends same length content with slightly different content
		char *partial = wget_strmemdup(urls[3].body, strlen(urls[3].body)-2);
		const char *old_body = urls[3].body;
		urls[3].body = "";

		// test-c-shorter
		wget_test(
			WGET_TEST_OPTIONS, "-c",
			WGET_TEST_REQUEST_URL, "dummy.txt",
//			WGET_TEST_KEEP_TMPFILES, 1,
			WGET_TEST_EXPECTED_ERROR_CODE, 0,
			WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", partial },
				{	NULL } },
			WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
				{	"dummy.txt", urls[3].body },
				{	NULL } },
			0);

		urls[3].body = old_body;
		wget_xfree(partial);
	}
*/
	// test-c
	wget_test(
		WGET_TEST_OPTIONS, "-c",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		// no existing file
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	// test-O--continue-existing
	wget_test(
		WGET_TEST_OPTIONS, "-O newindex.html -c",
		WGET_TEST_REQUEST_URL, "index.html",
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{ urls[0].name + 1, urls[0].body },
			{	NULL } },
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{ urls[0].name + 1, urls[0].body },
			{ "newindex.html", urls[0].body },
			{	NULL } },
		0);

	// test --chunk-size, new file
	wget_test(
		WGET_TEST_OPTIONS, "--chunk-size=3",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		// no existing file
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	// test --chunk-size, new file, without Content-Length header
	wget_test(
		WGET_TEST_OPTIONS, "--chunk-size=3",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_SERVER_SEND_CONTENT_LENGTH, 0, // server does not send Content-Length
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		// no existing file
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	// test --chunk-size, new file, with chunk size > Content-Length
	wget_test(
		WGET_TEST_OPTIONS, "--chunk-size=1000",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		// no existing file
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	// test -c --chunk-size, new file
	wget_test(
		WGET_TEST_OPTIONS, "--chunk-size=3 -c",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		// no existing file
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	// test -c --chunk-size, existing file
	wget_test(
		WGET_TEST_OPTIONS, "--chunk-size=3 -c",
		WGET_TEST_REQUEST_URL, "dummy.txt",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXISTING_FILES, &(wget_test_file_t []) {
			{ "dummy.txt",  urls[3].body },
			{	NULL } },
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"dummy.txt", urls[3].body },
			{	NULL } },
		0);

	// test--https-only
	wget_test(
		WGET_TEST_OPTIONS, "--https-only -r -nH",
		WGET_TEST_REQUEST_URL, "index.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 0,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	"index.html", urls[0].body },
			{	NULL } },
		0);

	// test --content-on-error
	wget_test(
		WGET_TEST_OPTIONS, "--content-on-error",
		WGET_TEST_REQUEST_URL, "error.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	urls[6].name + 1, urls[6].body },
			{	NULL } },
		0);

	// test not saving file on error
	wget_test(
		WGET_TEST_OPTIONS, "",
		WGET_TEST_REQUEST_URL, "error.html",
		WGET_TEST_EXPECTED_ERROR_CODE, 8,
		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
			{	NULL } },
		0);

	exit(0);
}