tests: add g_file_get_size() tests for files larger than 2GiB
This commit is contained in:
parent
c24b6d95dd
commit
a57d8491c0
@ -44,7 +44,7 @@ START_TEST(test_g_file_get_size__1GiB)
|
||||
"dd if=/dev/zero of=%s bs=%u seek=%u count=1",
|
||||
file,
|
||||
block_size,
|
||||
block_count -1);
|
||||
block_count - 1);
|
||||
|
||||
system_rv = system(cmd);
|
||||
size = g_file_get_size(file);
|
||||
@ -73,7 +73,65 @@ START_TEST(test_g_file_get_size__just_less_than_2GiB)
|
||||
"dd if=/dev/zero of=%s bs=%u seek=%u count=1",
|
||||
file,
|
||||
block_size,
|
||||
block_count -1);
|
||||
block_count - 1);
|
||||
|
||||
system_rv = system(cmd);
|
||||
size = g_file_get_size(file);
|
||||
g_file_delete(file);
|
||||
ck_assert_int_eq(system_rv, 0);
|
||||
ck_assert_int_eq(size, expected_size);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_g_file_get_size__2GiB)
|
||||
{
|
||||
const char *file = "./file_2GiB.dat";
|
||||
unsigned int block_size = 4096;
|
||||
unsigned int block_count = 524288;
|
||||
/* C90 5.2.4.2.1 guarantees long long is at least 64 bits */
|
||||
const long long expected_size =
|
||||
(long long)block_size * block_count;
|
||||
long long size;
|
||||
int system_rv;
|
||||
|
||||
char cmd[256];
|
||||
|
||||
/* Create a sparse file of the expected size with one block of data
|
||||
* at the end */
|
||||
g_snprintf(cmd, sizeof(cmd),
|
||||
"dd if=/dev/zero of=%s bs=%u seek=%u count=1",
|
||||
file,
|
||||
block_size,
|
||||
block_count - 1);
|
||||
|
||||
system_rv = system(cmd);
|
||||
size = g_file_get_size(file);
|
||||
g_file_delete(file);
|
||||
ck_assert_int_eq(system_rv, 0);
|
||||
ck_assert_int_eq(size, expected_size);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_g_file_get_size__5GiB)
|
||||
{
|
||||
const char *file = "./file_5GiB.dat";
|
||||
unsigned int block_size = 4096;
|
||||
unsigned int block_count = 1310720;
|
||||
/* C90 5.2.4.2.1 guarantees long long is at least 64 bits */
|
||||
const long long expected_size =
|
||||
(long long)block_size * block_count;
|
||||
long long size;
|
||||
int system_rv;
|
||||
|
||||
char cmd[256];
|
||||
|
||||
/* Create a sparse file of the expected size with one block of data
|
||||
* at the end */
|
||||
g_snprintf(cmd, sizeof(cmd),
|
||||
"dd if=/dev/zero of=%s bs=%u seek=%u count=1",
|
||||
file,
|
||||
block_size,
|
||||
block_count - 1);
|
||||
|
||||
system_rv = system(cmd);
|
||||
size = g_file_get_size(file);
|
||||
@ -97,6 +155,8 @@ make_suite_test_os_calls(void)
|
||||
tcase_add_test(tc_os_calls, test_g_file_get_size__returns_file_size);
|
||||
tcase_add_test(tc_os_calls, test_g_file_get_size__1GiB);
|
||||
tcase_add_test(tc_os_calls, test_g_file_get_size__just_less_than_2GiB);
|
||||
tcase_add_test(tc_os_calls, test_g_file_get_size__2GiB);
|
||||
tcase_add_test(tc_os_calls, test_g_file_get_size__5GiB);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user