diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-21 12:00:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-21 12:00:05 +0000 |
commit | 7e655d5542a9912e14e779915acef2791cfa55c7 (patch) | |
tree | a2871d809accd9f6fcee2e4be26800833a27953c /src/fs/fs_test_lib.c | |
parent | 71db17bc50adc7c959838ca0bc9d5190c841e3c8 (diff) | |
download | gnunet-7e655d5542a9912e14e779915acef2791cfa55c7.tar.gz gnunet-7e655d5542a9912e14e779915acef2791cfa55c7.zip |
more testcases, allow location uris in fs_download
Diffstat (limited to 'src/fs/fs_test_lib.c')
-rw-r--r-- | src/fs/fs_test_lib.c | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c index dd646eafe..f91092c4e 100644 --- a/src/fs/fs_test_lib.c +++ b/src/fs/fs_test_lib.c | |||
@@ -27,6 +27,7 @@ | |||
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | */ | 28 | */ |
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "fs.h" | ||
30 | #include "fs_test_lib.h" | 31 | #include "fs_test_lib.h" |
31 | #include "gnunet_testing_lib.h" | 32 | #include "gnunet_testing_lib.h" |
32 | 33 | ||
@@ -106,6 +107,11 @@ struct GNUNET_FS_TestDaemon | |||
106 | struct GNUNET_FS_Uri *publish_uri; | 107 | struct GNUNET_FS_Uri *publish_uri; |
107 | 108 | ||
108 | /** | 109 | /** |
110 | * Name of the temporary file used, or NULL for none. | ||
111 | */ | ||
112 | char *publish_tmp_file; | ||
113 | |||
114 | /** | ||
109 | * Scheduler to use (for download_cont). | 115 | * Scheduler to use (for download_cont). |
110 | */ | 116 | */ |
111 | struct GNUNET_SCHEDULER_Handle *download_sched; | 117 | struct GNUNET_SCHEDULER_Handle *download_sched; |
@@ -562,6 +568,11 @@ GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched, | |||
562 | GNUNET_FS_stop (daemons[i]->fs); | 568 | GNUNET_FS_stop (daemons[i]->fs); |
563 | if (daemons[i]->cfg != NULL) | 569 | if (daemons[i]->cfg != NULL) |
564 | GNUNET_CONFIGURATION_destroy (daemons[i]->cfg); | 570 | GNUNET_CONFIGURATION_destroy (daemons[i]->cfg); |
571 | if (NULL != daemons[i]->publish_tmp_file) | ||
572 | { | ||
573 | GNUNET_DISK_directory_remove (daemons[i]->publish_tmp_file); | ||
574 | GNUNET_free (daemons[i]->publish_tmp_file); | ||
575 | } | ||
565 | GNUNET_free (daemons[i]); | 576 | GNUNET_free (daemons[i]); |
566 | daemons[i] = NULL; | 577 | daemons[i] = NULL; |
567 | } | 578 | } |
@@ -647,25 +658,71 @@ GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched, | |||
647 | GNUNET_FS_TEST_UriContinuation cont, | 658 | GNUNET_FS_TEST_UriContinuation cont, |
648 | void *cont_cls) | 659 | void *cont_cls) |
649 | { | 660 | { |
650 | GNUNET_assert (daemon->publish_cont == NULL); | ||
651 | struct GNUNET_FS_FileInformation *fi; | 661 | struct GNUNET_FS_FileInformation *fi; |
662 | struct GNUNET_DISK_FileHandle *fh; | ||
663 | char *emsg; | ||
664 | uint64_t off; | ||
665 | char buf[DBLOCK_SIZE]; | ||
666 | size_t bsize; | ||
652 | 667 | ||
668 | GNUNET_assert (daemon->publish_cont == NULL); | ||
653 | daemon->publish_cont = cont; | 669 | daemon->publish_cont = cont; |
654 | daemon->publish_cont_cls = cont_cls; | 670 | daemon->publish_cont_cls = cont_cls; |
655 | daemon->publish_seed = seed; | 671 | daemon->publish_seed = seed; |
656 | daemon->verbose = verbose; | 672 | daemon->verbose = verbose; |
657 | daemon->publish_sched = sched; | 673 | daemon->publish_sched = sched; |
658 | fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, | 674 | if (GNUNET_YES == do_index) |
659 | daemon, | 675 | { |
660 | size, | 676 | GNUNET_assert (daemon->publish_tmp_file == NULL); |
661 | &file_generator, | 677 | daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); |
662 | daemon, | 678 | GNUNET_assert (daemon->publish_tmp_file != NULL); |
663 | NULL, | 679 | fh = GNUNET_DISK_file_open (daemon->publish_tmp_file, |
664 | NULL, | 680 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, |
665 | do_index, | 681 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); |
666 | anonymity, | 682 | GNUNET_assert (NULL != fh); |
667 | 42 /* priority */, | 683 | off = 0; |
668 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS)); | 684 | while (off < size) |
685 | { | ||
686 | bsize = GNUNET_MIN (sizeof (buf), | ||
687 | size - off); | ||
688 | GNUNET_assert (bsize == | ||
689 | file_generator (daemon, | ||
690 | off, | ||
691 | bsize, | ||
692 | buf, | ||
693 | &emsg)); | ||
694 | GNUNET_assert (emsg == NULL); | ||
695 | GNUNET_assert (bsize == | ||
696 | GNUNET_DISK_file_write (fh, | ||
697 | buf, | ||
698 | bsize)); | ||
699 | off += bsize; | ||
700 | } | ||
701 | GNUNET_assert (GNUNET_OK == | ||
702 | GNUNET_DISK_file_close (fh)); | ||
703 | fi = GNUNET_FS_file_information_create_from_file (daemon->fs, | ||
704 | daemon, | ||
705 | daemon->publish_tmp_file, | ||
706 | NULL, NULL, | ||
707 | do_index, | ||
708 | anonymity, | ||
709 | 42 /* priority */, | ||
710 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS)); | ||
711 | } | ||
712 | else | ||
713 | { | ||
714 | fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, | ||
715 | daemon, | ||
716 | size, | ||
717 | &file_generator, | ||
718 | daemon, | ||
719 | NULL, | ||
720 | NULL, | ||
721 | do_index, | ||
722 | anonymity, | ||
723 | 42 /* priority */, | ||
724 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS)); | ||
725 | } | ||
669 | daemon->publish_context = GNUNET_FS_publish_start (daemon->fs, | 726 | daemon->publish_context = GNUNET_FS_publish_start (daemon->fs, |
670 | fi, | 727 | fi, |
671 | NULL, NULL, NULL, | 728 | NULL, NULL, NULL, |