summaryrefslogtreecommitdiff
path: root/tests/core
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-04-04 15:06:44 -0700
committerGitHub <noreply@github.com>2019-04-04 15:06:44 -0700
commitaeea1c463941806a0176859c06c0e2e9716efcb0 (patch)
tree66b216a1967068230777a0d5867a46e4e510ddca /tests/core
parent80db20430ec103cc8b3ca1734770e50c84c626ab (diff)
parentfb7614c0f3dfc95a0b78948c5878628e12750082 (diff)
downloadlibgit2-aeea1c463941806a0176859c06c0e2e9716efcb0.tar.gz
Merge pull request #4874 from tiennou/test/4615
Test that largefiles can be read through the tree API
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/posix.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 172462073..529ee37f7 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -27,6 +27,11 @@ void test_core_posix__initialize(void)
#endif
}
+void test_core_posix__cleanup(void)
+{
+ p_unlink("fallocate_test");
+}
+
static bool supports_ipv6(void)
{
#ifdef GIT_WIN32
@@ -190,3 +195,39 @@ void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
cl_must_pass(error);
}
}
+
+void test_core_posix__fallocate(void)
+{
+ int fd;
+ struct stat st;
+
+ /* fallocate a new file succeeds */
+ cl_must_pass(fd = p_open("fallocate_test", O_RDWR|O_CREAT, 0666));
+ cl_must_pass(p_fallocate(fd, 0, 42));
+ cl_must_pass(p_fstat(fd, &st));
+ cl_assert_equal_i(42, st.st_size);
+ p_close(fd);
+
+ /* fallocate an existing file succeeds */
+ cl_must_pass(fd = p_open("fallocate_test", O_RDWR, 0666));
+ cl_must_pass(p_fallocate(fd, 90, 9));
+ cl_must_pass(p_fstat(fd, &st));
+ cl_assert_equal_i(99, st.st_size);
+ p_close(fd);
+
+ /* fallocate doesn't shrink */
+ cl_must_pass(fd = p_open("fallocate_test", O_RDWR, 0666));
+ cl_must_pass(p_fallocate(fd, 0, 14));
+ cl_must_pass(p_fstat(fd, &st));
+ cl_assert_equal_i(99, st.st_size);
+ p_close(fd);
+
+ /* fallocate doesn't move the cursor */
+ cl_must_pass(fd = p_open("fallocate_test", O_RDWR, 0666));
+ cl_must_pass(p_fallocate(fd, 0, 100));
+ cl_assert_equal_i(0, p_lseek(fd, 0, SEEK_CUR));
+ cl_must_pass(p_lseek(fd, 42, SEEK_SET));
+ cl_must_pass(p_fallocate(fd, 0, 200));
+ cl_assert_equal_i(42, p_lseek(fd, 0, SEEK_CUR));
+ p_close(fd);
+}