Skip to content

Commit

Permalink
test: UTs related to deleted functions are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvendramini committed Aug 13, 2024
1 parent 7a253cc commit 22004cd
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 1,823 deletions.
193 changes: 0 additions & 193 deletions src/common/file_op/tests/unit/tests/test_file_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,190 +239,6 @@ void test_w_is_compressed_bz2_file_uncompressed(void **state) {
assert_int_equal(ret, 0);
}

// w_uncompress_bz2_gz_file

#ifdef TEST_SERVER

void test_w_uncompress_bz2_gz_file_bz2(void **state) {

char * path = "/test/file.bz2";
char * dest = "/test/file";
int ret;

expect_string(__wrap_fopen, path, "/test/file.bz2");
expect_string(__wrap_fopen, mode, "rb");
will_return(__wrap_fopen, 1);

will_return(__wrap_fread, "BZh");
will_return(__wrap_fread, 3);

expect_string(__wrap_bzip2_uncompress, filebz2, "/test/file.bz2");
expect_string(__wrap_bzip2_uncompress, file, "/test/file");
will_return(__wrap_bzip2_uncompress, 0);

expect_string(__wrap_fopen, path, "/test/file.bz2");
expect_string(__wrap_fopen, mode, "rb");
will_return(__wrap_fopen, 0);

expect_string(__wrap__mdebug1, formatted_msg, "The file '/test/file.bz2' was successfully uncompressed into '/test/file'");

expect_value(__wrap_fclose, _File, 1);
will_return(__wrap_fclose, 0);

ret = w_uncompress_bz2_gz_file(path, dest);
assert_int_equal(ret, 0);
}

void test_MergeAppendFile_open_fail(void **state) {

FILE * finalfp = (FILE *)5;
char * file = "test.txt";
int path_offset = -1;
int ret;

expect_string(__wrap_fopen, path, file);
expect_string(__wrap_fopen, mode, "r");
will_return(__wrap_fopen, NULL);

expect_string(__wrap__merror, formatted_msg, "Unable to open file: 'test.txt' due to [(0)-(Success)].");

ret = MergeAppendFile(finalfp, file, path_offset);
assert_int_equal(ret, 0);
}

void test_MergeAppendFile_fseek_fail(void **state) {

FILE * finalfp = (FILE *)5;
char * file = "test.txt";
int path_offset = -1;
int ret;

expect_string(__wrap_fopen, path, file);
expect_string(__wrap_fopen, mode, "r");
will_return(__wrap_fopen, 6);

will_return(__wrap_fseek, 1);

expect_string(__wrap__merror, formatted_msg, "Unable to set EOF offset in file: 'test.txt', due to [(0)-(Success)].");

expect_value(__wrap_fclose, _File, 6);
will_return(__wrap_fclose, 1);

ret = MergeAppendFile(finalfp, file, path_offset);
assert_int_equal(ret, 0);
}

void test_MergeAppendFile_fseek2_fail(void **state) {

FILE * finalfp = (FILE *)5;
char * file = "/test/shared/default/test.txt";
int path_offset = -1;
int ret;

expect_string(__wrap_fopen, path, file);
expect_string(__wrap_fopen, mode, "r");
will_return(__wrap_fopen, 6);

will_return(__wrap_fseek, 0);

will_return(__wrap_ftell, 0);
expect_string(__wrap__mwarn, formatted_msg, "File '/test/shared/default/test.txt' is empty.");

expect_value(__wrap_fprintf, __stream, finalfp);
expect_string(__wrap_fprintf, formatted_msg, "!0 test.txt\n");
will_return(__wrap_fprintf, 0);

will_return(__wrap_fseek, -2);

expect_string(__wrap__merror, formatted_msg, "Unable to set the offset in file: '/test/shared/default/test.txt', due to [(0)-(Success)].");

expect_value(__wrap_fclose, _File, 6);
will_return(__wrap_fclose, 1);

ret = MergeAppendFile(finalfp, file, path_offset);
assert_int_equal(ret, 0);
}

void test_MergeAppendFile_diff_ftell(void **state) {

FILE * finalfp = (FILE *)5;
char * file = "/test/shared/default/test.txt";
int path_offset = 0;
int ret;

expect_string(__wrap_fopen, path, file);
expect_string(__wrap_fopen, mode, "r");
will_return(__wrap_fopen, 6);

will_return(__wrap_fseek, 0);

will_return(__wrap_ftell, 25);

expect_value(__wrap_fprintf, __stream, finalfp);
expect_string(__wrap_fprintf, formatted_msg, "!25 /test/shared/default/test.txt\n");
will_return(__wrap_fprintf, 0);

will_return(__wrap_fseek, 0);

will_return(__wrap_fread, "test.txt");
will_return(__wrap_fread, 1);

will_return(__wrap_fwrite, 0);

will_return(__wrap_fread, "test.txt");
will_return(__wrap_fread, 0);

will_return(__wrap_ftell, 33);

expect_value(__wrap_fclose, _File, 6);
will_return(__wrap_fclose, 1);

expect_string(__wrap__merror, formatted_msg, "File '/test/shared/default/test.txt' was modified after getting its size.");

ret = MergeAppendFile(finalfp, file, path_offset);
assert_int_equal(ret, 0);
}

void test_MergeAppendFile_success(void **state) {

FILE * finalfp = (FILE *)5;
char * file = "/test/shared/default/test.txt";
int path_offset = 0;
int ret;

expect_string(__wrap_fopen, path, file);
expect_string(__wrap_fopen, mode, "r");
will_return(__wrap_fopen, 6);

will_return(__wrap_fseek, 0);

will_return(__wrap_ftell, 25);

expect_value(__wrap_fprintf, __stream, finalfp);
expect_string(__wrap_fprintf, formatted_msg, "!25 /test/shared/default/test.txt\n");
will_return(__wrap_fprintf, 0);

will_return(__wrap_fseek, 0);

will_return(__wrap_fread, "test.txt");
will_return(__wrap_fread, 1);

will_return(__wrap_fwrite, 0);

will_return(__wrap_fread, "test.txt");
will_return(__wrap_fread, 0);

will_return(__wrap_ftell, 25);

expect_value(__wrap_fclose, _File, 6);
will_return(__wrap_fclose, 1);

ret = MergeAppendFile(finalfp, file, path_offset);
assert_int_equal(ret, 1);
}

#endif

// w_compress_gzfile

void test_w_compress_gzfile_wfopen_fail(void **state){
Expand Down Expand Up @@ -1120,15 +936,6 @@ int main(void) {
cmocka_unit_test(test_w_is_compressed_gz_file_uncompressed),
cmocka_unit_test(test_w_is_compressed_bz2_file_compressed),
cmocka_unit_test(test_w_is_compressed_bz2_file_uncompressed),
#ifdef TEST_SERVER
cmocka_unit_test(test_w_uncompress_bz2_gz_file_bz2),
// MergeAppendFile
cmocka_unit_test(test_MergeAppendFile_open_fail),
cmocka_unit_test(test_MergeAppendFile_fseek_fail),
cmocka_unit_test(test_MergeAppendFile_fseek2_fail),
cmocka_unit_test(test_MergeAppendFile_diff_ftell),
cmocka_unit_test(test_MergeAppendFile_success),
#endif
// w_compress_gzfile
cmocka_unit_test(test_w_compress_gzfile_wfopen_fail),
cmocka_unit_test(test_w_compress_gzfile_gzopen_fail),
Expand Down
Loading

0 comments on commit 22004cd

Please sign in to comment.