Apache HTTPD
testfile.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_file_io.h"
18#include "apr_file_info.h"
19#include "apr_network_io.h"
20#include "apr_errno.h"
21#include "apr_general.h"
22#include "apr_poll.h"
23#include "apr_lib.h"
24#include "apr_strings.h"
25#include "apr_thread_proc.h"
26#include "testutil.h"
27
28#define DIRNAME "data"
29#define FILENAME DIRNAME "/file_datafile.txt"
30#define TESTSTR "This is the file data file."
31
32#define TESTREAD_BLKSIZE 1024
33#define APR_BUFFERSIZE 4096 /* This should match APR's buffer size. */
34
35
36
49
62
75
76static void link_existing(abts_case *tc, void *data)
77{
78 apr_status_t rv;
79
80 rv = apr_file_link("data/file_datafile.txt", "data/file_datafile2.txt");
81 apr_file_remove("data/file_datafile2.txt", p);
82 ABTS_ASSERT(tc, "Couldn't create hardlink to file", rv == APR_SUCCESS);
83}
84
85static void link_nonexisting(abts_case *tc, void *data)
86{
87 apr_status_t rv;
88
89 rv = apr_file_link("data/does_not_exist.txt", "data/fake.txt");
90 ABTS_ASSERT(tc, "", rv != APR_SUCCESS);
91}
92
93static void test_read(abts_case *tc, void *data)
94{
95 apr_status_t rv;
96 apr_size_t nbytes = 256;
97 char *str = apr_pcalloc(p, nbytes + 1);
99
103
104 APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv);
107 ABTS_SIZE_EQUAL(tc, strlen(TESTSTR), nbytes);
109
111}
112
113static void test_readzero(abts_case *tc, void *data)
114{
115 apr_status_t rv;
116 apr_size_t nbytes = 0;
117 char *str = NULL;
119
121 APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv);
122
125 ABTS_SIZE_EQUAL(tc, 0, nbytes);
126
128}
129
130static void test_filename(abts_case *tc, void *data)
131{
132 const char *str;
133 apr_status_t rv;
135
139 APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv);
140
144
146}
147
148static void test_fileclose(abts_case *tc, void *data)
149{
150 char str;
151 apr_status_t rv;
152 apr_size_t one = 1;
154
158 APR_ASSERT_SUCCESS(tc, "Opening test file " FILENAME, rv);
159
162 /* We just closed the file, so this should fail */
163 rv = apr_file_read(filetest, &str, &one);
165}
166
179
192
206
223
238
239static void test_seek(abts_case *tc, void *data)
240{
241 apr_status_t rv;
242 apr_off_t offset = 5;
243 apr_size_t nbytes = 256;
244 char *str = apr_pcalloc(p, nbytes + 1);
246
250 APR_ASSERT_SUCCESS(tc, "Open test file " FILENAME, rv);
251
254 ABTS_SIZE_EQUAL(tc, strlen(TESTSTR), nbytes);
256
257 memset(str, 0, nbytes + 1);
258
261
264 ABTS_SIZE_EQUAL(tc, strlen(TESTSTR) - 5, nbytes);
265 ABTS_STR_EQUAL(tc, TESTSTR + 5, str);
266
268
269 /* Test for regression of sign error bug with SEEK_END and
270 buffered files. */
274 APR_ASSERT_SUCCESS(tc, "Open test file " FILENAME, rv);
275
276 offset = -5;
279 ABTS_SIZE_EQUAL(tc, strlen(TESTSTR) - 5, nbytes);
280
281 memset(str, 0, nbytes + 1);
282 nbytes = 256;
285 ABTS_SIZE_EQUAL(tc, 5, nbytes);
286 ABTS_STR_EQUAL(tc, TESTSTR + strlen(TESTSTR) - 5, str);
287
289}
290
291static void test_userdata_set(abts_case *tc, void *data)
292{
293 apr_status_t rv;
295
300
301 rv = apr_file_data_set(filetest, "This is a test",
302 "test", apr_pool_cleanup_null);
305}
306
307static void test_userdata_get(abts_case *tc, void *data)
308{
309 apr_status_t rv;
310 void *udata;
311 char *teststr;
313
318
319 rv = apr_file_data_set(filetest, "This is a test",
320 "test", apr_pool_cleanup_null);
322
323 rv = apr_file_data_get(&udata, "test", filetest);
325 teststr = udata;
326 ABTS_STR_EQUAL(tc, "This is a test", teststr);
327
329}
330
331static void test_userdata_getnokey(abts_case *tc, void *data)
332{
333 apr_status_t rv;
334 void *teststr;
336
341
342 rv = apr_file_data_get(&teststr, "nokey", filetest);
346}
347
378static void test_getc(abts_case *tc, void *data)
379{
380 apr_file_t *f = NULL;
381 apr_status_t rv;
382 char ch;
383
386
387 apr_file_getc(&ch, f);
389 ABTS_INT_EQUAL(tc, (int)TESTSTR[0], (int)ch);
391}
392
393static void test_ungetc(abts_case *tc, void *data)
394{
395 apr_file_t *f = NULL;
396 apr_status_t rv;
397 char ch;
398
401
402 apr_file_getc(&ch, f);
404 ABTS_INT_EQUAL(tc, (int)TESTSTR[0], (int)ch);
405
406 apr_file_ungetc('X', f);
408
409 apr_file_getc(&ch, f);
411 ABTS_INT_EQUAL(tc, 'X', (int)ch);
412
414}
415
416static void test_gets(abts_case *tc, void *data)
417{
418 apr_file_t *f = NULL;
419 apr_status_t rv;
420 char *str = apr_palloc(p, 256);
421
424
425 rv = apr_file_gets(str, 256, f);
426 /* Only one line in the test file, so APR will encounter EOF on the first
427 * call to gets, but we should get APR_SUCCESS on this call and
428 * APR_EOF on the next.
429 */
432 rv = apr_file_gets(str, 256, f);
433 ABTS_INT_EQUAL(tc, APR_EOF, rv);
434 ABTS_STR_EQUAL(tc, "", str);
435 /* Calling gets after EOF should return EOF. */
436 rv = apr_file_gets(str, 256, f);
437 ABTS_INT_EQUAL(tc, APR_EOF, rv);
438 ABTS_STR_EQUAL(tc, "", str);
440}
441
442static void test_gets_buffered(abts_case *tc, void *data)
443{
444 apr_file_t *f = NULL;
445 apr_status_t rv;
446 char *str = apr_palloc(p, 256);
447
448 /* This will deadlock gets before the r524355 fix. */
451
452 rv = apr_file_gets(str, 256, f);
453 /* Only one line in the test file, so APR will encounter EOF on the first
454 * call to gets, but we should get APR_SUCCESS on this call and
455 * APR_EOF on the next.
456 */
459 rv = apr_file_gets(str, 256, f);
460 ABTS_INT_EQUAL(tc, APR_EOF, rv);
461 ABTS_STR_EQUAL(tc, "", str);
462 /* Calling gets after EOF should return EOF. */
463 rv = apr_file_gets(str, 256, f);
464 ABTS_INT_EQUAL(tc, APR_EOF, rv);
465 ABTS_STR_EQUAL(tc, "", str);
467}
468
469static void test_gets_empty(abts_case *tc, void *data)
470{
471 apr_status_t rv;
472 apr_file_t *f;
473 const char *fname = "data/testgets_empty.dat";
474 char buf[256];
475
477
480 APR_ASSERT_SUCCESS(tc, "open test file", rv);
482
484 APR_ASSERT_SUCCESS(tc, "re-open test file", rv);
485
486 rv = apr_file_gets(buf, sizeof(buf), f);
487 ABTS_INT_EQUAL(tc, APR_EOF, rv);
488 ABTS_STR_EQUAL(tc, "", buf);
489 /* Calling gets after EOF should return EOF. */
490 rv = apr_file_gets(buf, sizeof(buf), f);
491 ABTS_INT_EQUAL(tc, APR_EOF, rv);
492 ABTS_STR_EQUAL(tc, "", buf);
494}
495
496static void test_gets_multiline(abts_case *tc, void *data)
497{
498 apr_status_t rv;
499 apr_file_t *f;
500 const char *fname = "data/testgets_multiline.dat";
501 char buf[256];
502
504
507 APR_ASSERT_SUCCESS(tc, "open test file", rv);
508 rv = apr_file_puts("a\nb\n", f);
509 APR_ASSERT_SUCCESS(tc, "write test data", rv);
511
513 APR_ASSERT_SUCCESS(tc, "re-open test file", rv);
514
515 memset(buf, 0, sizeof(buf));
516 rv = apr_file_gets(buf, sizeof(buf), f);
517 APR_ASSERT_SUCCESS(tc, "read first line", rv);
518 ABTS_STR_EQUAL(tc, "a\n", buf);
519
520 memset(buf, 0, sizeof(buf));
521 rv = apr_file_gets(buf, sizeof(buf), f);
522 APR_ASSERT_SUCCESS(tc, "read second line", rv);
523 ABTS_STR_EQUAL(tc, "b\n", buf);
524
525 rv = apr_file_gets(buf, sizeof(buf), f);
526 ABTS_INT_EQUAL(tc, APR_EOF, rv);
527 ABTS_STR_EQUAL(tc, "", buf);
528 /* Calling gets after EOF should return EOF. */
529 rv = apr_file_gets(buf, sizeof(buf), f);
530 ABTS_INT_EQUAL(tc, APR_EOF, rv);
531 ABTS_STR_EQUAL(tc, "", buf);
533}
534
535static void test_gets_small_buf(abts_case *tc, void *data)
536{
537 apr_status_t rv;
538 apr_file_t *f;
539 const char *fname = "data/testgets_small_buf.dat";
540 char buf[2];
541
543
546 APR_ASSERT_SUCCESS(tc, "open test file", rv);
547 rv = apr_file_puts("ab\n", f);
549
551 APR_ASSERT_SUCCESS(tc, "re-open test file", rv);
552 /* Buffer is too small to hold the full line, test that gets properly
553 * returns the line content character by character.
554 */
555 memset(buf, 0, sizeof(buf));
556 rv = apr_file_gets(buf, sizeof(buf), f);
557 APR_ASSERT_SUCCESS(tc, "read first chunk", rv);
558 ABTS_STR_EQUAL(tc, "a", buf);
559
560 memset(buf, 0, sizeof(buf));
561 rv = apr_file_gets(buf, sizeof(buf), f);
562 APR_ASSERT_SUCCESS(tc, "read second chunk", rv);
563 ABTS_STR_EQUAL(tc, "b", buf);
564
565 memset(buf, 0, sizeof(buf));
566 rv = apr_file_gets(buf, sizeof(buf), f);
567 APR_ASSERT_SUCCESS(tc, "read third chunk", rv);
568 ABTS_STR_EQUAL(tc, "\n", buf);
569
570 rv = apr_file_gets(buf, sizeof(buf), f);
571 ABTS_INT_EQUAL(tc, APR_EOF, rv);
572 ABTS_STR_EQUAL(tc, "", buf);
573 /* Calling gets after EOF should return EOF. */
574 rv = apr_file_gets(buf, sizeof(buf), f);
575 ABTS_INT_EQUAL(tc, APR_EOF, rv);
576 ABTS_STR_EQUAL(tc, "", buf);
578}
579
580static void test_gets_ungetc(abts_case *tc, void *data)
581{
582 apr_status_t rv;
583 apr_file_t *f;
584 const char *fname = "data/testgets_ungetc.dat";
585 char buf[256];
586
588
591 APR_ASSERT_SUCCESS(tc, "open test file", rv);
592 rv = apr_file_puts("a\n", f);
593 APR_ASSERT_SUCCESS(tc, "write test data", rv);
595
597 APR_ASSERT_SUCCESS(tc, "re-open test file", rv);
598
599 rv = apr_file_ungetc('b', f);
600 APR_ASSERT_SUCCESS(tc, "call ungetc", rv);
601 memset(buf, 0, sizeof(buf));
602 rv = apr_file_gets(buf, sizeof(buf), f);
603 APR_ASSERT_SUCCESS(tc, "read line", rv);
604 ABTS_STR_EQUAL(tc, "ba\n", buf);
605
606 rv = apr_file_ungetc('\n', f);
607 APR_ASSERT_SUCCESS(tc, "call ungetc with EOL", rv);
608 memset(buf, 0, sizeof(buf));
609 rv = apr_file_gets(buf, sizeof(buf), f);
610 APR_ASSERT_SUCCESS(tc, "read line", rv);
611 ABTS_STR_EQUAL(tc, "\n", buf);
612
613 rv = apr_file_gets(buf, sizeof(buf), f);
614 ABTS_INT_EQUAL(tc, APR_EOF, rv);
615 ABTS_STR_EQUAL(tc, "", buf);
616 /* Calling gets after EOF should return EOF. */
617 rv = apr_file_gets(buf, sizeof(buf), f);
618 ABTS_INT_EQUAL(tc, APR_EOF, rv);
619 ABTS_STR_EQUAL(tc, "", buf);
621}
622
623static void test_gets_buffered_big(abts_case *tc, void *data)
624{
625 apr_status_t rv;
626 apr_file_t *f;
627 const char *fname = "data/testgets_buffered_big.dat";
628 char hugestr[APR_BUFFERSIZE + 2];
629 char buf[APR_BUFFERSIZE + 2];
630
632
635 APR_ASSERT_SUCCESS(tc, "open test file", rv);
636 /* Test an edge case with a buffered file and the line that exceeds
637 * the default buffer size by 1 (the line itself fits into the buffer,
638 * but the line + EOL does not).
639 */
640 memset(hugestr, 'a', sizeof(hugestr));
641 hugestr[sizeof(hugestr) - 2] = '\n';
642 hugestr[sizeof(hugestr) - 1] = '\0';
643 rv = apr_file_puts(hugestr, f);
644 APR_ASSERT_SUCCESS(tc, "write first line", rv);
645 rv = apr_file_puts("b\n", f);
646 APR_ASSERT_SUCCESS(tc, "write second line", rv);
648
651 APR_ASSERT_SUCCESS(tc, "re-open test file", rv);
652
653 memset(buf, 0, sizeof(buf));
654 rv = apr_file_gets(buf, sizeof(buf), f);
655 APR_ASSERT_SUCCESS(tc, "read first line", rv);
657
658 memset(buf, 0, sizeof(buf));
659 rv = apr_file_gets(buf, sizeof(buf), f);
660 APR_ASSERT_SUCCESS(tc, "read second line", rv);
661 ABTS_STR_EQUAL(tc, "b\n", buf);
662
663 rv = apr_file_gets(buf, sizeof(buf), f);
664 ABTS_INT_EQUAL(tc, APR_EOF, rv);
665 ABTS_STR_EQUAL(tc, "", buf);
666 /* Calling gets after EOF should return EOF. */
667 rv = apr_file_gets(buf, sizeof(buf), f);
668 ABTS_INT_EQUAL(tc, APR_EOF, rv);
669 ABTS_STR_EQUAL(tc, "", buf);
671}
672
673static void test_bigread(abts_case *tc, void *data)
674{
675 apr_file_t *f = NULL;
676 apr_status_t rv;
677 char buf[APR_BUFFERSIZE * 2];
679
680 /* Create a test file with known content.
681 */
682 rv = apr_file_open(&f, "data/created_file",
686
688 memset(buf, 0xFE, nbytes);
689
690 rv = apr_file_write(f, buf, &nbytes);
693
694 rv = apr_file_close(f);
696
697 f = NULL;
698 rv = apr_file_open(&f, "data/created_file", APR_FOPEN_READ, 0, p);
700
701 nbytes = sizeof buf;
702 rv = apr_file_read(f, buf, &nbytes);
705
706 rv = apr_file_close(f);
708
709 rv = apr_file_remove("data/created_file", p);
711}
712
713/* This is a horrible name for this function. We are testing APR, not how
714 * Apache uses APR. And, this function tests _way_ too much stuff.
715 */
716static void test_mod_neg(abts_case *tc, void *data)
717{
718 apr_status_t rv;
719 apr_file_t *f;
720 const char *s;
721 int i;
723 char buf[8192];
725 const char *fname = "data/modneg.dat";
726
727 rv = apr_file_open(&f, fname,
730
731 s = "body56789\n";
732 nbytes = strlen(s);
733 rv = apr_file_write(f, s, &nbytes);
735 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
736
737 for (i = 0; i < 7980; i++) {
738 s = "0";
739 nbytes = strlen(s);
740 rv = apr_file_write(f, s, &nbytes);
742 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
743 }
744
745 s = "end456789\n";
746 nbytes = strlen(s);
747 rv = apr_file_write(f, s, &nbytes);
749 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
750
751 for (i = 0; i < 10000; i++) {
752 s = "1";
753 nbytes = strlen(s);
754 rv = apr_file_write(f, s, &nbytes);
756 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
757 }
758
759 rv = apr_file_close(f);
761
762 rv = apr_file_open(&f, fname, APR_FOPEN_READ, 0, p);
764
765 rv = apr_file_gets(buf, 11, f);
767 ABTS_STR_EQUAL(tc, "body56789\n", buf);
768
769 cur = 0;
770 rv = apr_file_seek(f, APR_CUR, &cur);
772 ABTS_ASSERT(tc, "File Pointer Mismatch, expected 10", cur == 10);
773
774 nbytes = sizeof(buf);
775 rv = apr_file_read(f, buf, &nbytes);
777 ABTS_SIZE_EQUAL(tc, nbytes, sizeof(buf));
778
779 cur = -((apr_off_t)nbytes - 7980);
780 rv = apr_file_seek(f, APR_CUR, &cur);
782 ABTS_ASSERT(tc, "File Pointer Mismatch, expected 7990", cur == 7990);
783
784 rv = apr_file_gets(buf, 11, f);
786 ABTS_STR_EQUAL(tc, "end456789\n", buf);
787
788 rv = apr_file_close(f);
790
791 rv = apr_file_remove(fname, p);
793}
794
795/* Test that the contents of file FNAME are equal to data EXPECT of
796 * length EXPECTLEN. */
798 const char *fname,
799 const void *expect,
801{
802 void *actual = apr_palloc(p, expectlen);
803 apr_file_t *f;
804
805 APR_ASSERT_SUCCESS(tc, "open file",
807 0, p));
808 APR_ASSERT_SUCCESS(tc, "read from file",
810
811 ABTS_ASSERT(tc, "matched expected file contents",
812 memcmp(expect, actual, expectlen) == 0);
813
814 APR_ASSERT_SUCCESS(tc, "close file", apr_file_close(f));
815}
816
817#define LINE1 "this is a line of text\n"
818#define LINE2 "this is a second line of text\n"
819
820static void test_puts(abts_case *tc, void *data)
821{
822 apr_file_t *f;
823 const char *fname = "data/testputs.dat";
824
825 APR_ASSERT_SUCCESS(tc, "open file for writing",
828 APR_OS_DEFAULT, p));
829
830 APR_ASSERT_SUCCESS(tc, "write line to file",
832 APR_ASSERT_SUCCESS(tc, "write second line to file",
834
835 APR_ASSERT_SUCCESS(tc, "close for writing",
837
839}
840
841static void test_writev(abts_case *tc, void *data)
842{
843 apr_file_t *f;
845 struct iovec vec[5];
846 const char *fname = "data/testwritev.dat";
847
848 APR_ASSERT_SUCCESS(tc, "open file for writing",
851 APR_OS_DEFAULT, p));
852
853 vec[0].iov_base = LINE1;
854 vec[0].iov_len = strlen(LINE1);
855
856 APR_ASSERT_SUCCESS(tc, "writev of size 1 to file",
857 apr_file_writev(f, vec, 1, &nbytes));
858
859 file_contents_equal(tc, fname, LINE1, strlen(LINE1));
860
861 vec[0].iov_base = LINE1;
862 vec[0].iov_len = strlen(LINE1);
863 vec[1].iov_base = LINE2;
864 vec[1].iov_len = strlen(LINE2);
865 vec[2].iov_base = LINE1;
866 vec[2].iov_len = strlen(LINE1);
867 vec[3].iov_base = LINE1;
868 vec[3].iov_len = strlen(LINE1);
869 vec[4].iov_base = LINE2;
870 vec[4].iov_len = strlen(LINE2);
871
872 APR_ASSERT_SUCCESS(tc, "writev of size 5 to file",
873 apr_file_writev(f, vec, 5, &nbytes));
874
875 APR_ASSERT_SUCCESS(tc, "close for writing",
877
879 strlen(LINE1)*4 + strlen(LINE2)*2);
880
881}
882
883static void test_writev_full(abts_case *tc, void *data)
884{
885 apr_file_t *f;
887 struct iovec vec[5];
888 const char *fname = "data/testwritev_full.dat";
889
890 APR_ASSERT_SUCCESS(tc, "open file for writing",
893 APR_OS_DEFAULT, p));
894
895 vec[0].iov_base = LINE1;
896 vec[0].iov_len = strlen(LINE1);
897 vec[1].iov_base = LINE2;
898 vec[1].iov_len = strlen(LINE2);
899 vec[2].iov_base = LINE1;
900 vec[2].iov_len = strlen(LINE1);
901 vec[3].iov_base = LINE1;
902 vec[3].iov_len = strlen(LINE1);
903 vec[4].iov_base = LINE2;
904 vec[4].iov_len = strlen(LINE2);
905
906 APR_ASSERT_SUCCESS(tc, "writev_full of size 5 to file",
908
909 ABTS_SIZE_EQUAL(tc, strlen(LINE1)*3 + strlen(LINE2)*2, nbytes);
910
911 APR_ASSERT_SUCCESS(tc, "close for writing",
913
915 strlen(LINE1)*3 + strlen(LINE2)*2);
916
917}
918
919static void test_writev_buffered(abts_case *tc, void *data)
920{
921 apr_file_t *f;
923 struct iovec vec[2];
924 const char *fname = "data/testwritev_buffered.dat";
925
926 APR_ASSERT_SUCCESS(tc, "open file for writing",
930
931 nbytes = strlen(TESTSTR);
932 APR_ASSERT_SUCCESS(tc, "buffered write",
934
935 vec[0].iov_base = LINE1;
936 vec[0].iov_len = strlen(LINE1);
937 vec[1].iov_base = LINE2;
938 vec[1].iov_len = strlen(LINE2);
939
940 APR_ASSERT_SUCCESS(tc, "writev of size 2 to file",
941 apr_file_writev(f, vec, 2, &nbytes));
942
943 APR_ASSERT_SUCCESS(tc, "close for writing",
945
947 strlen(TESTSTR) + strlen(LINE1) + strlen(LINE2));
948}
949
951{
952 apr_file_t *f;
953 apr_status_t rv;
954 apr_off_t off = 0;
955 struct iovec vec[3];
956 apr_size_t nbytes = strlen(TESTSTR);
957 char *str = apr_pcalloc(p, nbytes+1);
958 const char *fname = "data/testwritev_buffered.dat";
959
960 APR_ASSERT_SUCCESS(tc, "open file for writing",
963 APR_OS_DEFAULT, p));
964
965 rv = apr_file_read(f, str, &nbytes);
968 APR_ASSERT_SUCCESS(tc, "buffered seek", apr_file_seek(f, APR_SET, &off));
969
970 vec[0].iov_base = LINE1;
971 vec[0].iov_len = strlen(LINE1);
972 vec[1].iov_base = LINE2;
973 vec[1].iov_len = strlen(LINE2);
974 vec[2].iov_base = TESTSTR;
975 vec[2].iov_len = strlen(TESTSTR);
976
977 APR_ASSERT_SUCCESS(tc, "writev of size 2 to file",
978 apr_file_writev(f, vec, 3, &nbytes));
979
980 APR_ASSERT_SUCCESS(tc, "close for writing",
982
984 strlen(LINE1) + strlen(LINE2) + strlen(TESTSTR));
985
986 APR_ASSERT_SUCCESS(tc, "remove file", apr_file_remove(fname, p));
987}
988
989static void test_truncate(abts_case *tc, void *data)
990{
991 apr_status_t rv;
992 apr_file_t *f;
993 const char *fname = "data/testtruncate.dat";
994 const char *s;
996 apr_finfo_t finfo;
997
999
1000 rv = apr_file_open(&f, fname,
1002 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1003
1004 s = "some data";
1005 nbytes = strlen(s);
1006 rv = apr_file_write(f, s, &nbytes);
1007 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1008 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
1009
1010 rv = apr_file_close(f);
1011 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1012
1013 rv = apr_file_open(&f, fname,
1015 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1016
1017 rv = apr_file_close(f);
1018 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1019
1020 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1021 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1022 ABTS_ASSERT(tc, "File size mismatch, expected 0 (empty)", finfo.size == 0);
1023
1024 rv = apr_file_remove(fname, p);
1025 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1026}
1027
1028static void test_file_trunc(abts_case *tc, void *data)
1029{
1030 apr_status_t rv;
1031 apr_file_t *f;
1032 const char *fname = "data/testtruncate.dat";
1033 const char *s;
1035 apr_finfo_t finfo;
1036
1038
1039 /* Test unbuffered */
1040 rv = apr_file_open(&f, fname,
1044 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1045
1046 s = "some data";
1047 nbytes = strlen(s);
1048 rv = apr_file_write(f, s, &nbytes);
1049 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1050 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
1051 rv = apr_file_trunc(f, 4);
1052 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1053 rv = apr_file_close(f);
1054 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1055 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1056 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1057 ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);
1058
1059 rv = apr_file_remove(fname, p);
1060 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1061 /* Test buffered */
1062 rv = apr_file_open(&f, fname,
1066 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1067
1068 nbytes = strlen(s);
1069 rv = apr_file_write(f, s, &nbytes);
1070 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1071 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
1072 rv = apr_file_trunc(f, 4);
1073 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1074 rv = apr_file_close(f);
1075 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1076 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1077 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1078 ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);
1079
1080 rv = apr_file_remove(fname, p);
1081 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1082}
1083
1084static void test_file_trunc2(abts_case *tc, void *data)
1085{
1086 apr_status_t rv;
1087 apr_file_t *f;
1088 const char *fname = "data/testtruncate.dat";
1089 const char *s;
1091 apr_finfo_t finfo;
1092 char c;
1093
1095
1096 rv = apr_file_open(&f, fname,
1100 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1101
1102 s = "some data";
1103 nbytes = strlen(s);
1104 rv = apr_file_write(f, s, &nbytes);
1105 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1106 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
1107 rv = apr_file_trunc(f, 4);
1108 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1109 /* Test apr_file_info_get(). */
1110 rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, f);
1111 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1112 ABTS_INT_EQUAL(tc, 4, (int)finfo.size);
1113 /* EOF is not reported until the next read. */
1114 rv = apr_file_eof(f);
1115 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1116 rv = apr_file_getc(&c, f);
1117 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1118 rv = apr_file_eof(f);
1119 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1120
1121 rv = apr_file_close(f);
1122 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1123 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1124 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1125 ABTS_INT_EQUAL(tc, 4, (int)finfo.size);
1126
1127 rv = apr_file_remove(fname, p);
1128 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1129}
1130
1132{
1133 apr_status_t rv;
1134 apr_file_t *f;
1135 const char *fname = "data/testtruncate_buffered_write.dat";
1136 const char *s;
1138 apr_finfo_t finfo;
1139 char c;
1140
1142
1143 rv = apr_file_open(&f, fname,
1147 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1148
1149 s = "some data";
1150 nbytes = strlen(s);
1151 rv = apr_file_write(f, s, &nbytes);
1152 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1153 ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
1154 rv = apr_file_trunc(f, 4);
1155 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1156 /* Test apr_file_info_get(). */
1157 rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, f);
1158 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1159 ABTS_INT_EQUAL(tc, 4, (int)finfo.size);
1160 /* EOF is not reported until the next read. */
1161 rv = apr_file_eof(f);
1162 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1163 rv = apr_file_getc(&c, f);
1164 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1165 rv = apr_file_eof(f);
1166 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1167
1168 rv = apr_file_close(f);
1169 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1170 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1171 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1172 ABTS_INT_EQUAL(tc, 4, (int)finfo.size);
1173
1174 rv = apr_file_remove(fname, p);
1175 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1176}
1177
1179{
1180 apr_status_t rv;
1181 apr_file_t *f;
1182 const char *fname = "data/testtruncate_buffered_write2.dat";
1183 apr_finfo_t finfo;
1184 char c;
1185
1187
1188 rv = apr_file_open(&f, fname,
1192 APR_ASSERT_SUCCESS(tc, "open test file", rv);
1193
1194 rv = apr_file_puts("abc", f);
1195 APR_ASSERT_SUCCESS(tc, "write first string", rv);
1196 rv = apr_file_flush(f);
1197 APR_ASSERT_SUCCESS(tc, "flush", rv);
1198 rv = apr_file_puts("def", f);
1199 APR_ASSERT_SUCCESS(tc, "write second string", rv);
1200 /* Truncate behind the write buffer. */
1201 rv = apr_file_trunc(f, 2);
1202 APR_ASSERT_SUCCESS(tc, "truncate the file", rv);
1203 /* Test apr_file_info_get(). */
1204 rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, f);
1205 APR_ASSERT_SUCCESS(tc, "get file info", rv);
1206 ABTS_INT_EQUAL(tc, 2, (int)finfo.size);
1207 /* EOF is not reported until the next read. */
1208 rv = apr_file_eof(f);
1209 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1210 rv = apr_file_getc(&c, f);
1211 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1212 rv = apr_file_eof(f);
1213 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1214
1216
1217 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1218 APR_ASSERT_SUCCESS(tc, "stat file", rv);
1219 ABTS_INT_EQUAL(tc, 2, (int)finfo.size);
1220
1222}
1223
1225{
1226 apr_status_t rv;
1227 apr_file_t *f;
1228 const char *fname = "data/testtruncate_buffered_read.dat";
1229 apr_finfo_t finfo;
1230 char c;
1231
1233
1234 rv = apr_file_open(&f, fname,
1237 APR_ASSERT_SUCCESS(tc, "open test file", rv);
1238
1239 rv = apr_file_puts("abc", f);
1240 APR_ASSERT_SUCCESS(tc, "write test data", rv);
1242
1243 rv = apr_file_open(&f, fname,
1246 APR_ASSERT_SUCCESS(tc, "re-open test file", rv);
1247
1248 /* Read to fill in the buffer. */
1249 rv = apr_file_getc(&c, f);
1250 APR_ASSERT_SUCCESS(tc, "read char", rv);
1251 /* Truncate the file. */
1252 rv = apr_file_trunc(f, 1);
1253 APR_ASSERT_SUCCESS(tc, "truncate the file", rv);
1254 /* Test apr_file_info_get(). */
1255 rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, f);
1256 APR_ASSERT_SUCCESS(tc, "get file info", rv);
1257 ABTS_INT_EQUAL(tc, 1, (int)finfo.size);
1258 /* EOF is not reported until the next read. */
1259 rv = apr_file_eof(f);
1260 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1261 rv = apr_file_getc(&c, f);
1262 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1263 rv = apr_file_eof(f);
1264 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1265
1267
1268 rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
1269 APR_ASSERT_SUCCESS(tc, "stat file", rv);
1270 ABTS_INT_EQUAL(tc, 1, (int)finfo.size);
1271
1273}
1274
1275static void test_bigfprintf(abts_case *tc, void *data)
1276{
1277 apr_file_t *f;
1278 const char *fname = "data/testbigfprintf.dat";
1279 char *to_write;
1280 int i;
1281
1283
1284 APR_ASSERT_SUCCESS(tc, "open test file",
1288
1289
1291
1292 for (i = 0; i < HUGE_STRING_LEN + 1; ++i)
1293 to_write[i] = 'A' + i%26;
1294
1296
1297 i = apr_file_printf(f, "%s", to_write);
1299
1301
1303
1304 free(to_write);
1305}
1306
1307static void test_fail_write_flush(abts_case *tc, void *data)
1308{
1309 apr_file_t *f;
1310 const char *fname = "data/testflush.dat";
1311 apr_status_t rv;
1312 char buf[APR_BUFFERSIZE];
1313 int n;
1314
1316
1317 APR_ASSERT_SUCCESS(tc, "open test file",
1321
1322 memset(buf, 'A', sizeof buf);
1323
1324 /* Try three writes. One of these should fail when it exceeds the
1325 * internal buffer and actually tries to write to the file, which
1326 * was opened read-only and hence should be unwritable. */
1327 for (n = 0, rv = APR_SUCCESS; n < 4 && rv == APR_SUCCESS; n++) {
1328 apr_size_t bytes = sizeof buf;
1329 rv = apr_file_write(f, buf, &bytes);
1330 }
1331
1332 ABTS_ASSERT(tc, "failed to write to read-only buffered fd",
1333 rv != APR_SUCCESS);
1334
1336}
1337
1338static void test_fail_read_flush(abts_case *tc, void *data)
1339{
1340 apr_file_t *f;
1341 const char *fname = "data/testflush.dat";
1342 apr_status_t rv;
1343 char buf[2];
1344
1346
1347 APR_ASSERT_SUCCESS(tc, "open test file",
1351
1352 /* this write should be buffered. */
1353 APR_ASSERT_SUCCESS(tc, "buffered write should succeed",
1354 apr_file_puts("hello", f));
1355
1356 /* Now, trying a read should fail since the write must be flushed,
1357 * and should fail with something other than EOF since the file is
1358 * opened read-only. */
1359 rv = apr_file_read_full(f, buf, 2, NULL);
1360
1361 ABTS_ASSERT(tc, "read should flush buffered write and fail",
1362 rv != APR_SUCCESS && rv != APR_EOF);
1363
1364 /* Likewise for gets */
1365 rv = apr_file_gets(buf, 2, f);
1366
1367 ABTS_ASSERT(tc, "gets should flush buffered write and fail",
1368 rv != APR_SUCCESS && rv != APR_EOF);
1369
1370 /* Likewise for seek. */
1371 {
1372 apr_off_t offset = 0;
1373
1374 rv = apr_file_seek(f, APR_SET, &offset);
1375 }
1376
1377 ABTS_ASSERT(tc, "seek should flush buffered write and fail",
1378 rv != APR_SUCCESS && rv != APR_EOF);
1379
1381}
1382
1383static void test_xthread(abts_case *tc, void *data)
1384{
1385 apr_file_t *f;
1386 const char *fname = "data/testxthread.dat";
1387 apr_status_t rv;
1389 char buf[128] = { 0 };
1390
1391 /* Test for bug 38438, opening file with append + xthread and seeking to
1392 the end of the file resulted in writes going to the beginning not the
1393 end. */
1394
1396
1397 APR_ASSERT_SUCCESS(tc, "open test file",
1400
1401 APR_ASSERT_SUCCESS(tc, "write should succeed",
1402 apr_file_puts("hello", f));
1403
1405
1406 APR_ASSERT_SUCCESS(tc, "open test file",
1409
1410 /* Seek to the end. */
1411 {
1412 apr_off_t offset = 0;
1413
1414 rv = apr_file_seek(f, APR_END, &offset);
1415 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1416 }
1417
1418 APR_ASSERT_SUCCESS(tc, "more writes should succeed",
1419 apr_file_puts("world", f));
1420
1421 /* Back to the beginning. */
1422 {
1423 apr_off_t offset = 0;
1424
1425 rv = apr_file_seek(f, APR_SET, &offset);
1426 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1427 }
1428
1429 apr_file_read_full(f, buf, sizeof(buf), NULL);
1430
1431 ABTS_STR_EQUAL(tc, "helloworld", buf);
1432
1434}
1435
1436static void test_datasync_on_file(abts_case *tc, void *data)
1437{
1438 apr_status_t rv;
1439 apr_file_t *f;
1440 const char *fname = DIRNAME "/testtest_datasync.dat";
1442
1444
1447 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1448 rv = apr_file_write_full(f, "abcdef", 6, &bytes_written);
1449 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1450 rv = apr_file_datasync(f);
1451 APR_ASSERT_SUCCESS(tc, "sync file contents", rv);
1453
1455}
1456
1458{
1459 apr_status_t rv;
1460 apr_file_t *f;
1462
1463 rv = apr_file_open_stdout(&f, p);
1464 APR_ASSERT_SUCCESS(tc, "open stdout", rv);
1465 rv = apr_file_write_full(f, "abcdef\b\b\b\b\b\b\b", 12, &bytes_written);
1466 APR_ASSERT_SUCCESS(tc, "write to stdout", rv);
1467 rv = apr_file_datasync(f);
1468 if (rv != APR_SUCCESS) {
1469#if defined(__APPLE__)
1470 ABTS_INT_EQUAL(tc, ENOTSUP, rv);
1471#else
1472 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
1473#endif
1474 }
1475}
1476
1477#if APR_HAS_THREADS
1478typedef struct thread_file_append_ctx_t {
1480 const char *fname;
1482 char val;
1483 int num_writes;
1484 char *errmsg;
1486
1488{
1490 apr_status_t rv;
1491 apr_file_t *f;
1492 int i;
1493 char *writebuf;
1494 char *readbuf;
1495
1496 rv = apr_file_open(&f, ctx->fname,
1498 APR_FPROT_OS_DEFAULT, ctx->pool);
1499 if (rv) {
1500 apr_thread_exit(thd, rv);
1501 return NULL;
1502 }
1503
1504 writebuf = apr_palloc(ctx->pool, ctx->chunksize);
1505 memset(writebuf, ctx->val, ctx->chunksize);
1506 readbuf = apr_palloc(ctx->pool, ctx->chunksize);
1507
1508 for (i = 0; i < ctx->num_writes; i++) {
1512
1513 rv = apr_file_write_full(f, writebuf, ctx->chunksize, &bytes_written);
1514 if (rv) {
1515 apr_thread_exit(thd, rv);
1516 return NULL;
1517 }
1518 /* After writing the data, seek back from the current offset and
1519 * verify what we just wrote. */
1520 offset = -((apr_off_t)ctx->chunksize);
1521 rv = apr_file_seek(f, APR_CUR, &offset);
1522 if (rv) {
1523 apr_thread_exit(thd, rv);
1524 return NULL;
1525 }
1526 rv = apr_file_read_full(f, readbuf, ctx->chunksize, &bytes_read);
1527 if (rv) {
1528 apr_thread_exit(thd, rv);
1529 return NULL;
1530 }
1531 if (memcmp(readbuf, writebuf, ctx->chunksize) != 0) {
1532 ctx->errmsg = apr_psprintf(
1533 ctx->pool,
1534 "Unexpected data at file offset %" APR_OFF_T_FMT,
1535 offset);
1537 return NULL;
1538 }
1539 }
1540
1543
1544 return NULL;
1545}
1546#endif /* APR_HAS_THREADS */
1547
1548static void test_atomic_append(abts_case *tc, void *data)
1549{
1550#if APR_HAS_THREADS
1551 apr_status_t rv;
1553 apr_file_t *f;
1554 const char *fname = "data/testatomic_append.dat";
1555 unsigned int seed;
1560
1562
1565 APR_ASSERT_SUCCESS(tc, "create file", rv);
1567
1568 seed = (unsigned int)apr_time_now();
1569 abts_log_message("Random seed for test_atomic_append() is %u", seed);
1570 srand(seed);
1571
1572 /* Create two threads appending data to the same file. */
1573 apr_pool_create(&ctx1.pool, p);
1574 ctx1.fname = fname;
1575 ctx1.chunksize = 1 + rand() % 8192;
1576 ctx1.val = 'A';
1577 ctx1.num_writes = 1000;
1579 APR_ASSERT_SUCCESS(tc, "create thread", rv);
1580
1581 apr_pool_create(&ctx2.pool, p);
1582 ctx2.fname = fname;
1583 ctx2.chunksize = 1 + rand() % 8192;
1584 ctx2.val = 'B';
1585 ctx2.num_writes = 1000;
1587 APR_ASSERT_SUCCESS(tc, "create thread", rv);
1588
1590 APR_ASSERT_SUCCESS(tc, "join thread", rv);
1591 APR_ASSERT_SUCCESS(tc, "no thread errors", thread_rv);
1592 if (ctx1.errmsg) {
1593 ABTS_FAIL(tc, ctx1.errmsg);
1594 }
1596 APR_ASSERT_SUCCESS(tc, "join thread", rv);
1597 APR_ASSERT_SUCCESS(tc, "no thread errors", thread_rv);
1598 if (ctx2.errmsg) {
1599 ABTS_FAIL(tc, ctx2.errmsg);
1600 }
1601
1603#else
1604 ABTS_SKIP(tc, data, "This test requires APR thread support.");
1605#endif /* APR_HAS_THREADS */
1606}
1607
1608static void test_append_locked(abts_case *tc, void *data)
1609{
1610 apr_status_t rv;
1611 apr_file_t *f;
1612 const char *fname = "data/testappend_locked.dat";
1615 char buf[64] = {0};
1616
1618
1619 rv = apr_file_open(&f, fname,
1622 APR_ASSERT_SUCCESS(tc, "create file", rv);
1623
1625 APR_ASSERT_SUCCESS(tc, "lock file", rv);
1626
1627 /* PR50058: Appending to a locked file should not deadlock. */
1628 rv = apr_file_write_full(f, "abc", 3, &bytes_written);
1629 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1630
1633
1635 APR_ASSERT_SUCCESS(tc, "open file", rv);
1636
1637 rv = apr_file_read_full(f, buf, sizeof(buf), &bytes_read);
1638 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1639 ABTS_INT_EQUAL(tc, 3, (int)bytes_read);
1640 ABTS_STR_EQUAL(tc, "abc", buf);
1641
1644}
1645
1647{
1648 apr_status_t rv;
1649 apr_file_t *f;
1650 const char *fname = "data/testlarge_write_buffered.dat";
1654 char *buf;
1655 char *buf2;
1656
1658
1659 rv = apr_file_open(&f, fname,
1662 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1663
1664 /* Test a single large write. */
1665 len = 80000;
1666 buf = apr_palloc(p, len);
1667 memset(buf, 'a', len);
1669 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1670 ABTS_INT_EQUAL(tc, (int)len, (int)bytes_written);
1672
1675 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1676
1677 buf2 = apr_palloc(p, len + 1);
1678 rv = apr_file_read_full(f, buf2, len + 1, &bytes_read);
1679 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1680 ABTS_INT_EQUAL(tc, (int)len, (int)bytes_read);
1681 ABTS_TRUE(tc, memcmp(buf, buf2, len) == 0);
1683
1685}
1686
1688{
1689 apr_status_t rv;
1690 apr_file_t *f;
1691 const char *fname = "data/testtwo_large_writes_buffered.dat";
1695 char *buf;
1696 char *buf2;
1697
1699
1700 rv = apr_file_open(&f, fname,
1703 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1704
1705 /* Test two consecutive large writes. */
1706 len = 80000;
1707 buf = apr_palloc(p, len);
1708 memset(buf, 'a', len);
1709
1711 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1712 ABTS_INT_EQUAL(tc, (int)(len / 2), (int)bytes_written);
1713
1715 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1716 ABTS_INT_EQUAL(tc, (int)(len / 2), (int)bytes_written);
1717
1719
1722 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1723
1724 buf2 = apr_palloc(p, len + 1);
1725 rv = apr_file_read_full(f, buf2, len + 1, &bytes_read);
1726 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1727 ABTS_INT_EQUAL(tc, (int) len, (int)bytes_read);
1728 ABTS_TRUE(tc, memcmp(buf, buf2, len) == 0);
1730
1732}
1733
1735{
1736 apr_status_t rv;
1737 apr_file_t *f;
1738 const char *fname = "data/testtwo_large_writes_buffered.dat";
1742 char *buf;
1743 char *buf2;
1744
1746
1747 rv = apr_file_open(&f, fname,
1750 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1751
1752 /* Test small write followed by a large write. */
1753 len = 80000;
1754 buf = apr_palloc(p, len);
1755 memset(buf, 'a', len);
1756
1758 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1759 ABTS_INT_EQUAL(tc, 5, (int)bytes_written);
1760
1762 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1763 ABTS_INT_EQUAL(tc, (int)(len - 5), (int)bytes_written);
1764
1766
1769 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1770
1771 buf2 = apr_palloc(p, len + 1);
1772 rv = apr_file_read_full(f, buf2, len + 1, &bytes_read);
1773 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1774 ABTS_INT_EQUAL(tc, (int) len, (int)bytes_read);
1775 ABTS_TRUE(tc, memcmp(buf, buf2, len) == 0);
1777
1779}
1780
1782{
1783 apr_status_t rv;
1784 apr_file_t *f;
1785 const char *fname = "data/testwrite_buffered_spanning_over_bufsize.dat";
1789 char *buf;
1790 char *buf2;
1791
1793
1794 rv = apr_file_open(&f, fname,
1797 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1798
1799 /* Test three writes than span over the default buffer size. */
1800 len = APR_BUFFERSIZE + 1;
1801 buf = apr_palloc(p, len);
1802 memset(buf, 'a', len);
1803
1805 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1807
1809 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1810 ABTS_INT_EQUAL(tc, 2, (int)bytes_written);
1811
1813
1816 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1817
1818 buf2 = apr_palloc(p, len + 1);
1819 rv = apr_file_read_full(f, buf2, len + 1, &bytes_read);
1820 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1821 ABTS_INT_EQUAL(tc, (int)len, (int)bytes_read);
1822 ABTS_TRUE(tc, memcmp(buf, buf2, len) == 0);
1824
1826}
1827
1829{
1830 apr_status_t rv;
1831 apr_file_t *f;
1832 const char *fname = "data/testempty_read_buffered.dat";
1835 char buf[64];
1836
1838
1841 APR_ASSERT_SUCCESS(tc, "create empty test file", rv);
1843
1846 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1847
1848 /* Test an empty read. */
1849 len = 1;
1851 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1852 ABTS_INT_EQUAL(tc, 0, (int)bytes_read);
1853 rv = apr_file_eof(f);
1854 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1856
1858}
1859
1861{
1862 apr_status_t rv;
1863 apr_file_t *f;
1864 const char *fname = "data/testlarge_read_buffered.dat";
1868 char *buf;
1869 char *buf2;
1870
1872
1875 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1876 len = 80000;
1877 buf = apr_palloc(p, len);
1878 memset(buf, 'a', len);
1880 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1882
1885 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1886
1887 /* Test a single large read. */
1888 buf2 = apr_palloc(p, len);
1890 APR_ASSERT_SUCCESS(tc, "read from file", rv);
1891 ABTS_INT_EQUAL(tc, (int)len, (int)bytes_read);
1892 ABTS_TRUE(tc, memcmp(buf, buf2, bytes_read) == 0);
1893 rv = apr_file_eof(f);
1894 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1895
1896 /* Test that we receive an EOF. */
1897 len = 1;
1899 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1900 ABTS_INT_EQUAL(tc, 0, (int)bytes_read);
1901 rv = apr_file_eof(f);
1902 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1904
1906}
1907
1909{
1910 apr_status_t rv;
1911 apr_file_t *f;
1912 const char *fname = "data/testtwo_large_reads_buffered.dat";
1916 char *buf;
1917 char *buf2;
1918
1920
1923 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1924 len = 80000;
1925 buf = apr_palloc(p, len);
1926 memset(buf, 'a', len);
1928 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1930
1933 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1934
1935 /* Test two consecutive large reads. */
1936 buf2 = apr_palloc(p, len);
1937 memset(buf2, 0, len);
1938 rv = apr_file_read_full(f, buf2, len / 2, &bytes_read);
1939 APR_ASSERT_SUCCESS(tc, "read from file", rv);
1940 ABTS_INT_EQUAL(tc, (int)(len / 2), (int)bytes_read);
1941 ABTS_TRUE(tc, memcmp(buf, buf2, bytes_read) == 0);
1942 rv = apr_file_eof(f);
1943 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1944
1945 memset(buf2, 0, len);
1946 rv = apr_file_read_full(f, buf2, len / 2, &bytes_read);
1947 APR_ASSERT_SUCCESS(tc, "read from file", rv);
1948 ABTS_INT_EQUAL(tc, (int)(len / 2), (int)bytes_read);
1949 ABTS_TRUE(tc, memcmp(buf + len / 2, buf2, bytes_read) == 0);
1950 rv = apr_file_eof(f);
1951 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1952
1953 /* Test that we receive an EOF. */
1954 len = 1;
1956 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1957 ABTS_INT_EQUAL(tc, 0, (int)bytes_read);
1958 rv = apr_file_eof(f);
1959 ABTS_INT_EQUAL(tc, APR_EOF, rv);
1961
1963}
1964
1966{
1967 apr_status_t rv;
1968 apr_file_t *f;
1969 const char *fname = "data/testtwo_large_reads_buffered.dat";
1973 char *buf;
1974 char *buf2;
1975
1977
1980 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
1981 len = 80000;
1982 buf = apr_palloc(p, len);
1983 memset(buf, 'a', len);
1985 APR_ASSERT_SUCCESS(tc, "write to file", rv);
1987
1990 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
1991
1992 /* Test small read followed by a large read. */
1993 buf2 = apr_palloc(p, len);
1994 memset(buf2, 0, len);
1995 rv = apr_file_read_full(f, buf2, 5, &bytes_read);
1996 APR_ASSERT_SUCCESS(tc, "read from file", rv);
1997 ABTS_INT_EQUAL(tc, 5, (int)bytes_read);
1998 ABTS_TRUE(tc, memcmp(buf, buf2, bytes_read) == 0);
1999 rv = apr_file_eof(f);
2000 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
2001
2002 memset(buf2, 0, len);
2003 rv = apr_file_read_full(f, buf2, len - 5, &bytes_read);
2004 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2005 ABTS_INT_EQUAL(tc, (int)(len - 5), (int)bytes_read);
2006 ABTS_TRUE(tc, memcmp(buf + 5, buf2, bytes_read) == 0);
2007 rv = apr_file_eof(f);
2008 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
2009
2010 /* Test that we receive an EOF. */
2011 len = 1;
2013 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2014 ABTS_INT_EQUAL(tc, 0, (int)bytes_read);
2015 rv = apr_file_eof(f);
2016 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2018
2020}
2021
2023{
2024 apr_status_t rv;
2025 apr_file_t *f;
2026 const char *fname = "data/testread_buffered_spanning_over_bufsize.dat";
2030 char *buf;
2031 char *buf2;
2032
2034
2037 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
2038 len = APR_BUFFERSIZE + 1;
2039 buf = apr_palloc(p, len);
2040 memset(buf, 'a', len);
2042 APR_ASSERT_SUCCESS(tc, "write to file", rv);
2044
2047 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
2048
2049 /* Test reads than span over the default buffer size. */
2050 buf2 = apr_palloc(p, len);
2051 memset(buf2, 0, len);
2053 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2055 ABTS_TRUE(tc, memcmp(buf, buf2, bytes_read) == 0);
2056 rv = apr_file_eof(f);
2057 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
2058
2059 memset(buf2, 0, len);
2060 rv = apr_file_read_full(f, buf2, 2, &bytes_read);
2061 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2062 ABTS_INT_EQUAL(tc, 2, (int)bytes_read);
2063 ABTS_TRUE(tc, memcmp(buf, buf2, bytes_read) == 0);
2064 rv = apr_file_eof(f);
2065 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
2066
2067 /* Test that we receive an EOF. */
2068 len = 1;
2070 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2071 ABTS_INT_EQUAL(tc, 0, (int)bytes_read);
2072 rv = apr_file_eof(f);
2073 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2075
2077}
2078
2080{
2081 apr_status_t rv;
2082 apr_file_t *f;
2083 const char *fname = "data/testsingle_byte_reads_buffered.dat";
2087 char *buf;
2088 apr_size_t total;
2089
2091
2094 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
2095 len = 40000;
2096 buf = apr_palloc(p, len);
2097 memset(buf, 'a', len);
2099 APR_ASSERT_SUCCESS(tc, "write to file", rv);
2101
2104 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
2105
2106 total = 0;
2107 while (1) {
2108 memset(buf, 0, len);
2109 rv = apr_file_read_full(f, buf, 1, &bytes_read);
2110 if (rv == APR_EOF) {
2111 break;
2112 }
2113 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2114 ABTS_INT_EQUAL(tc, 1, (int)bytes_read);
2115 ABTS_INT_EQUAL(tc, 'a', buf[0]);
2116 total += bytes_read;
2117 }
2118 ABTS_INT_EQUAL(tc, (int)len, (int)total);
2119
2120 rv = apr_file_eof(f);
2121 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2123
2125}
2126
2128{
2129 apr_status_t rv;
2130 apr_file_t *f;
2131 const char *fname = "data/testtest_read_buffered_seek.dat";
2135 char buf[64];
2136 apr_off_t off;
2137
2139
2142 APR_ASSERT_SUCCESS(tc, "open test file for writing", rv);
2143 rv = apr_file_write_full(f, "abcdef", 6, &bytes_written);
2144 APR_ASSERT_SUCCESS(tc, "write to file", rv);
2146
2149 APR_ASSERT_SUCCESS(tc, "open test file for reading", rv);
2150
2151 /* Read one byte. */
2152 memset(buf, 0, sizeof(buf));
2153 rv = apr_file_read_full(f, buf, 1, &bytes_read);
2154 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2155 ABTS_INT_EQUAL(tc, 1, (int)bytes_read);
2156 ABTS_INT_EQUAL(tc, 'a', buf[0]);
2157
2158 /* Seek into the middle of the file. */
2159 off = 3;
2160 rv = apr_file_seek(f, APR_SET, &off);
2161 APR_ASSERT_SUCCESS(tc, "change file read offset", rv);
2162 ABTS_INT_EQUAL(tc, 3, (int)off);
2163
2164 /* Read three bytes. */
2165 memset(buf, 0, sizeof(buf));
2166 rv = apr_file_read_full(f, buf, 3, &bytes_read);
2167 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2168 ABTS_INT_EQUAL(tc, 3, (int)bytes_read);
2169 ABTS_TRUE(tc, memcmp(buf, "def", bytes_read) == 0);
2170
2171 rv = apr_file_eof(f);
2172 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
2173
2174 /* Test that we receive an EOF. */
2175 len = 1;
2177 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2178 ABTS_INT_EQUAL(tc, 0, (int)bytes_read);
2179 rv = apr_file_eof(f);
2180 ABTS_INT_EQUAL(tc, APR_EOF, rv);
2182
2184}
2185
2186static void test_append_buffered(abts_case *tc, void *data)
2187{
2188 apr_status_t rv;
2189 apr_file_t *f;
2190 const char *fname = "data/testappend_buffered.dat";
2192 char buf[64];
2193
2195
2196 /* Create file with contents. */
2199 APR_ASSERT_SUCCESS(tc, "create file", rv);
2200
2201 rv = apr_file_write_full(f, "abc", 3, &bytes_written);
2202 APR_ASSERT_SUCCESS(tc, "write to file", rv);
2204
2205 /* Re-open it with APR_FOPEN_APPEND and APR_FOPEN_BUFFERED. */
2206 rv = apr_file_open(&f, fname,
2210 APR_ASSERT_SUCCESS(tc, "open file", rv);
2211
2212 /* Append to the file. */
2213 rv = apr_file_write_full(f, "def", 3, &bytes_written);
2214 APR_ASSERT_SUCCESS(tc, "write to file", rv);
2216
2219 APR_ASSERT_SUCCESS(tc, "open file", rv);
2220
2221 /* Test the file contents. */
2222 rv = apr_file_gets(buf, sizeof(buf), f);
2223 APR_ASSERT_SUCCESS(tc, "read from file", rv);
2224 ABTS_STR_EQUAL(tc, "abcdef", buf);
2225
2228}
2229
2231{
2232 suite = ADD_SUITE(suite)
2233
2240 abts_run_test(suite, test_read, NULL);
2242 abts_run_test(suite, test_seek, NULL);
2248 abts_run_test(suite, test_write, NULL);
2252 abts_run_test(suite, test_getc, NULL);
2254 abts_run_test(suite, test_gets, NULL);
2261 abts_run_test(suite, test_puts, NULL);
2295
2296 return suite;
2297}
2298
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
void abts_log_message(const char *fmt,...)
Definition abts.c:270
#define ABTS_SIZE_EQUAL(a, b, c)
Definition abts.h:121
#define ABTS_PTR_EQUAL(a, b, c)
Definition abts.h:126
#define ABTS_TRUE(a, b)
Definition abts.h:127
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_SKIP(tc, data, msg)
Definition abts.h:135
#define ABTS_ASSERT(a, b, c)
Definition abts.h:130
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
#define ABTS_FAIL(a, b)
Definition abts.h:128
#define APR_ASSERT_SUCCESS(tc, ctxt, rv)
Definition testutil.h:58
APR Error Codes.
APR File Information.
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Network library.
APR Poll interface.
APR Strings library.
APR Thread and Process Library.
#define HUGE_STRING_LEN
Definition httpd.h:303
const unsigned char * buf
Definition util_md5.h:50
#define APR_EOF
Definition apr_errno.h:461
#define APR_EINVAL
Definition apr_errno.h:711
#define APR_STATUS_IS_EEXIST(s)
Definition apr_errno.h:1233
#define APR_STATUS_IS_EACCES(s)
Definition apr_errno.h:1231
#define APR_STATUS_IS_EBADF(s)
Definition apr_errno.h:1264
#define APR_STATUS_IS_ENOENT(s)
Definition apr_errno.h:1246
apr_file_t * f
apr_brigade_flush void * ctx
const char apr_ssize_t int flags
Definition apr_encode.h:168
apr_size_t size
apr_uint32_t val
Definition apr_atomic.h:66
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
char apr_size_t bufsize
Definition apr_errno.h:53
int apr_status_t
Definition apr_errno.h:44
apr_file_t * thefile
void apr_size_t * nbytes
const struct iovec * vec
apr_seek_where_t apr_off_t * offset
void apr_size_t apr_size_t * bytes_read
void * data
const void apr_size_t apr_size_t * bytes_written
char * buffer
#define APR_FLOCK_EXCLUSIVE
#define APR_FOPEN_TRUNCATE
Definition apr_file_io.h:58
#define APR_FOPEN_XTHREAD
Definition apr_file_io.h:67
#define APR_FOPEN_APPEND
Definition apr_file_io.h:57
#define APR_FOPEN_EXCL
Definition apr_file_io.h:63
#define APR_FOPEN_BUFFERED
Definition apr_file_io.h:65
#define APR_FOPEN_WRITE
Definition apr_file_io.h:55
#define APR_FOPEN_READ
Definition apr_file_io.h:54
#define APR_FOPEN_CREATE
Definition apr_file_io.h:56
#define APR_GREAD
#define APR_UWRITE
#define APR_FPROT_UWRITE
#define APR_UREAD
#define APR_OS_DEFAULT
#define APR_FPROT_UREAD
#define APR_FPROT_OS_DEFAULT
#define APR_SET
#define APR_END
#define APR_CUR
const char * fname
#define APR_FINFO_SIZE
apr_vformatter_buff_t * c
Definition apr_lib.h:175
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const void apr_size_t bytes
Definition apr_random.h:91
const char * s
Definition apr_strings.h:95
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_status_t apr_file_lock(apr_file_t *thefile, int type)
Definition flock.c:21
apr_status_t apr_file_unlock(apr_file_t *thefile)
Definition flock.c:33
apr_status_t apr_thread_exit(apr_thread_t *thd, apr_status_t retval)
Definition thread.c:157
apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd)
Definition thread.c:166
apr_status_t apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr, apr_thread_start_t func, void *data, apr_pool_t *pool)
Definition thread.c:73
apr_off_t size
static void test_readzero(abts_case *tc, void *data)
Definition testfile.c:113
static void test_buffer_set_get(abts_case *tc, void *data)
Definition testfile.c:348
static void file_contents_equal(abts_case *tc, const char *fname, const void *expect, apr_size_t expectlen)
Definition testfile.c:797
static void test_seek(abts_case *tc, void *data)
Definition testfile.c:239
#define DIRNAME
Definition testfile.c:28
static void test_atomic_append(abts_case *tc, void *data)
Definition testfile.c:1548
static void test_fail_read_flush(abts_case *tc, void *data)
Definition testfile.c:1338
static void test_single_byte_reads_buffered(abts_case *tc, void *data)
Definition testfile.c:2079
static void test_file_trunc_buffered_write2(abts_case *tc, void *data)
Definition testfile.c:1178
#define LINE2
Definition testfile.c:818
static void test_ungetc(abts_case *tc, void *data)
Definition testfile.c:393
static void test_file_trunc_buffered_read(abts_case *tc, void *data)
Definition testfile.c:1224
abts_suite * testfile(abts_suite *suite)
Definition testfile.c:2230
static void test_mod_neg(abts_case *tc, void *data)
Definition testfile.c:716
static void test_xthread(abts_case *tc, void *data)
Definition testfile.c:1383
static void test_fail_write_flush(abts_case *tc, void *data)
Definition testfile.c:1307
static void test_small_and_large_reads_buffered(abts_case *tc, void *data)
Definition testfile.c:1965
static void test_two_large_reads_buffered(abts_case *tc, void *data)
Definition testfile.c:1908
static void test_puts(abts_case *tc, void *data)
Definition testfile.c:820
static void test_open_write(abts_case *tc, void *data)
Definition testfile.c:180
#define LINE1
Definition testfile.c:817
#define TESTSTR
Definition testfile.c:30
static void test_open_excl(abts_case *tc, void *data)
Definition testfile.c:50
static void test_gets_buffered_big(abts_case *tc, void *data)
Definition testfile.c:623
static void test_open_writecreate(abts_case *tc, void *data)
Definition testfile.c:193
static void test_datasync_on_file(abts_case *tc, void *data)
Definition testfile.c:1436
static void test_datasync_on_stream(abts_case *tc, void *data)
Definition testfile.c:1457
static void test_append_buffered(abts_case *tc, void *data)
Definition testfile.c:2186
static void test_bigread(abts_case *tc, void *data)
Definition testfile.c:673
#define APR_BUFFERSIZE
Definition testfile.c:33
static void test_writev_buffered_seek(abts_case *tc, void *data)
Definition testfile.c:950
static void test_truncate(abts_case *tc, void *data)
Definition testfile.c:989
static void test_append_locked(abts_case *tc, void *data)
Definition testfile.c:1608
static void test_gets(abts_case *tc, void *data)
Definition testfile.c:416
static void test_read_buffered_spanning_over_bufsize(abts_case *tc, void *data)
Definition testfile.c:2022
static void test_read_buffered_seek(abts_case *tc, void *data)
Definition testfile.c:2127
static void test_fileclose(abts_case *tc, void *data)
Definition testfile.c:148
static void test_gets_ungetc(abts_case *tc, void *data)
Definition testfile.c:580
static void test_gets_empty(abts_case *tc, void *data)
Definition testfile.c:469
#define FILENAME
Definition testfile.c:29
static void test_userdata_getnokey(abts_case *tc, void *data)
Definition testfile.c:331
static void test_file_trunc2(abts_case *tc, void *data)
Definition testfile.c:1084
static void test_open_readwrite(abts_case *tc, void *data)
Definition testfile.c:224
static void test_writev_full(abts_case *tc, void *data)
Definition testfile.c:883
static void link_nonexisting(abts_case *tc, void *data)
Definition testfile.c:85
static void test_gets_small_buf(abts_case *tc, void *data)
Definition testfile.c:535
static void test_file_trunc_buffered_write(abts_case *tc, void *data)
Definition testfile.c:1131
static void test_write_buffered_spanning_over_bufsize(abts_case *tc, void *data)
Definition testfile.c:1781
static void test_getc(abts_case *tc, void *data)
Definition testfile.c:378
static void test_userdata_get(abts_case *tc, void *data)
Definition testfile.c:307
static void test_empty_read_buffered(abts_case *tc, void *data)
Definition testfile.c:1828
static void test_open_read(abts_case *tc, void *data)
Definition testfile.c:63
static void link_existing(abts_case *tc, void *data)
Definition testfile.c:76
static void test_two_large_writes_buffered(abts_case *tc, void *data)
Definition testfile.c:1687
static void test_userdata_set(abts_case *tc, void *data)
Definition testfile.c:291
static void test_small_and_large_writes_buffered(abts_case *tc, void *data)
Definition testfile.c:1734
static void test_large_read_buffered(abts_case *tc, void *data)
Definition testfile.c:1860
static void test_filename(abts_case *tc, void *data)
Definition testfile.c:130
static void test_gets_buffered(abts_case *tc, void *data)
Definition testfile.c:442
static void test_file_trunc(abts_case *tc, void *data)
Definition testfile.c:1028
static void test_write(abts_case *tc, void *data)
Definition testfile.c:207
static void test_file_remove(abts_case *tc, void *data)
Definition testfile.c:167
static void test_writev_buffered(abts_case *tc, void *data)
Definition testfile.c:919
static void test_bigfprintf(abts_case *tc, void *data)
Definition testfile.c:1275
static void test_large_write_buffered(abts_case *tc, void *data)
Definition testfile.c:1646
static void test_open_noreadwrite(abts_case *tc, void *data)
Definition testfile.c:37
static void test_writev(abts_case *tc, void *data)
Definition testfile.c:841
static void test_gets_multiline(abts_case *tc, void *data)
Definition testfile.c:496
static void test_read(abts_case *tc, void *data)
Definition testfile.c:93
abts_suite * teststr(abts_suite *suite)
Definition teststr.c:411
static apr_table_t * t1
Definition testtable.c:34
apr_status_t apr_file_trunc(apr_file_t *fp, apr_off_t offset)
Definition seek.c:99
#define str
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray