]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Thu, 4 Nov 2021 05:35:07 +0000 (22:35 -0700)
committeralex <[email protected]>
Thu, 4 Nov 2021 05:35:07 +0000 (22:35 -0700)
test/unit/file.tests.c
test/unit/test_utils.h

index 7be295e7b4ae9f83c6b899c053d57ac58851943f..bb8aae4c801a76883ae1773cefa7cd8c6807f779 100644 (file)
@@ -4,6 +4,9 @@
 
 int main();
 static void file_hash_basic_test();
+static void file_hash_large_file_test();
+static void file_hash_large_piece_test();
+static void file_hash_random_file_test();
 static void file_init_basic_test();
 
 int main() {
@@ -11,6 +14,9 @@ int main() {
 
        file_init_basic_test();
        file_hash_basic_test();
+       file_hash_large_file_test();
+       file_hash_large_piece_test();
+       file_hash_random_file_test();
 
        clean_env();
 
@@ -61,6 +67,50 @@ static void file_hash_basic_test() {
        file_free(p);
 }
 
+static void file_hash_large_file_test() {
+       struct file *p;
+       FILE *fp;
+       unsigned char buf[16384];
+       unsigned char expected[crypto_hash_sha256_BYTES] = {0};
+
+       fp = fopen(TEST_FILE_1,"a");
+       assert(fp!=NULL);
+
+       for(size_t i=0;i<10000;i++) {
+               memset(buf,i%255,16384);
+               assert(16384==fwrite(buf,sizeof(char),16384,fp));
+       }
+
+       fclose(fp);
+
+       assert(file_init(&p,TEST_FILE_1)==1);
+       assert(file_hash(p,16384)==1);
+       assert(memcmp(p->root,expected,crypto_hash_sha256_BYTES)==0);
+       assert(10000==block_length(p->blocks));
+       assert((10000*16384+21)==p->size);
+
+       file_free(p);
+
+       reset_env();
+}
+
+static void file_hash_large_piece_test() {
+
+}
+
+static void file_hash_random_file_test() {
+       struct file *p;
+       
+       system("head -c 256MB </dev/urandom > " TEST_FILE_5);
+
+       assert(file_init(&p,TEST_FILE_5)==1);
+       assert(file_hash(p,16384)==1);
+       assert(1==block_length(p->blocks));
+       assert(24==p->size);
+
+       file_free(p);
+}
+
 static void file_init_basic_test() {
        struct file *p;
        unsigned char expected[crypto_hash_sha256_BYTES];
index e65884496d402dc49cbc418ecb2df22f948bb403..02932cc3b703998a96566df4b4ccd7ed218b957f 100644 (file)
@@ -19,6 +19,7 @@
 #define TEST_FILE_3_CONTENTS "sdlifjasdiofjasoidfjaois"
 #define TEST_FILE_4 PREFIX "/.test.meta"
 #define TEST_FILE_4_CONTENTS ";alsikdjf;lkasdjflk\n;asjdflk\n;ajsdklfjl;aksdfjla;kj"
+#define TEST_FILE_5 PREFIX "/random.test"
 
 void clean_env();
 void reset_env();