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() {
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();
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];