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
|
#include <stdbool.h>
#include <sys/stat.h>
#include "minunit.h"
#include "rbtree.c"
#include "opt.c"
#include "util.c"
#include "debug.c"
#include "csum.c"
#include "threads.c"
#include "btrfs-util.c"
#include "file_scan.c"
#include "filerec.c"
#include "dbfile.c"
#include "hash-tree.c"
#include "results-tree.c"
#include "list_sort.c"
#include "find_dupes.c"
#include "memstats.c"
#include "fiemap.c"
#include "progress.c"
unsigned int blocksize = DEFAULT_BLOCKSIZE;
static char *exec_path;
MU_TEST(test_is_block_zeroed) {
blocksize = 100;
char block[100] = {0,};
// Actual zeroed block
mu_check(is_block_zeroed(&block) == true);
// Block has the same content, but not zeroed
memset(block, 1, 100);
mu_check(is_block_zeroed(&block) == false);
// Block do not have the same content
block[50] = 50;
mu_check(is_block_zeroed(NULL) == false);
}
MU_TEST(test_block_len) {
struct file_block block;
struct filerec file;
block.b_file = &file;
// First block of the file
file.size = 10 * 1024 * 1024;
block.b_loff = 0;
mu_check(block_len(&block) == blocksize);
// block in the middle of the file, unaligned
block.b_loff = 1;
mu_check(block_len(&block) == blocksize);
// block in the middle of the file, aligned
block.b_loff = blocksize * 10;
mu_check(block_len(&block) == blocksize);
// block at the end of the file, which is aligned
file.size = blocksize * 10;
block.b_loff = blocksize * 9;
mu_check(block_len(&block) == blocksize);
// block at the end of the file, which is unaligned
unsigned int extra = 10;
file.size = blocksize * 10 + extra;
block.b_loff = blocksize * 10;
mu_check(block_len(&block) == extra);
// loff is passed filesize
file.size = blocksize * 10 + extra;
block.b_loff = blocksize * 15;
mu_check(block_len(&block) == 0);
}
MU_TEST(test_is_file_renamed) {
char *new_path = "/tmp/somefile";
char *path_in_db = "/tmp/somefile";
mu_check(is_file_renamed(path_in_db, new_path) == false);
path_in_db = "/tmp/anotherfile";
mu_check(is_file_renamed(path_in_db, new_path) == true);
/*
* Diffents path but the old one still exists.
* We use our own file to simulate a hard link
*/
mu_check(is_file_renamed(exec_path, new_path) == false);
}
MU_TEST_SUITE(test_suite) {
MU_RUN_TEST(test_is_block_zeroed);
MU_RUN_TEST(test_block_len);
MU_RUN_TEST(test_is_file_renamed);
}
int main(int argc [[maybe_unused]], char *argv[]) {
exec_path = argv[0];
MU_RUN_SUITE(test_suite);
MU_REPORT();
return MU_EXIT_CODE;
}
|