lib

morphux C utility library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/lib

commit e8af86eb3f7db311003da457cf0f8adaefbe2c75
parent 3226f42898495945398ff4776ace632a886a7b4d
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Thu, 15 Jun 2017 18:50:05 +0200

Add(Mock): Add mock on fchmod function

Diffstat:
Minc/fail_test.h | 2++
Msrc/test.c | 4++++
Mtests/test_tests.c | 13+++++++++++++
3 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/inc/fail_test.h b/inc/fail_test.h @@ -33,6 +33,7 @@ # define mkdir(path, mode) fl_mkdir(path, mode) # define fork fl_fork # define chdir fl_chdir +# define fchmod fl_fchmod # define MOCK_SET_DECL(fn_name, type, ...) \ void set_##fn_name##_fail(int val); \ @@ -51,6 +52,7 @@ MOCK_SET_DECL(strcat, char *, char *, const char *); MOCK_SET_DECL(mkdir, int, const char *, mode_t); MOCK_SET_DECL(fork, pid_t); MOCK_SET_DECL(chdir, int, const char *); +MOCK_SET_DECL(fchmod, int, int, mode_t); # endif /* M_FAIL_TEST_H */ #endif /* COMPILE_WITH_TEST */ diff --git a/src/test.c b/src/test.c @@ -96,4 +96,8 @@ MOCK_SET_IMP(chdir, int, -1, const char *path) { MOCK_REAL_CALL(chdir, path); } +MOCK_SET_IMP(fchmod, int, -1, int fd, mode_t mode) { + MOCK_REAL_CALL(fchmod, fd, mode); +} + #endif /* COMPILE_WITH_TEST */ diff --git a/tests/test_tests.c b/tests/test_tests.c @@ -277,6 +277,18 @@ TEST(test_fail_chdir) { return TEST_SUCCESS; } +TEST(test_fail_fchmod) { + int fd = open("/tmp/truc_12345", O_CREAT | O_RDONLY, 0666); + + TEST_ASSERT(fd != -1, "Could not create file"); + TEST_ASSERT(fchmod(fd, 0777) != -1, "Should have suceed"); + set_fchmod_fail(1); + TEST_ASSERT(fchmod(fd, 0777) != -1, "Should have suceed"); + TEST_ASSERT(fchmod(fd, 0777) == -1, "Should have failed"); + unlink("/tmp/truc_12345"); + return TEST_SUCCESS; +} + TEST(test_fail_cleanup) { unlink(TMP_FD_FN); return TEST_SUCCESS; @@ -302,4 +314,5 @@ void register_tests_tests(void) { reg_test("fake_functions", test_fail_mkdir); reg_test("fake_functions", test_fail_fork); reg_test("fake_functions", test_fail_chdir); + reg_test("fake_functions", test_fail_fchmod); }