diff options
author | Stef Walter <stefw@gnome.org> | 2013-03-15 08:18:42 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-03-15 17:33:47 +0100 |
commit | 58e1e3764250fbda96c5ef7244e891a6be04d4cb (patch) | |
tree | 32bb771186cb672a5061abfc5236c44173642a45 /tools/tests/test-save.c | |
parent | 8fd55c8089c90b52f00e4ffad572d1b9da72e6ba (diff) |
extract: Allow p11_save_write() to automatically calculate length
Also if automatically calculating length, then ignore input
that is NULL, as something that shouldn't be written out.
This allows easier chaining of optional output, such as comments.
https://bugs.freedesktop.org/show_bug.cgi?id=62029
Diffstat (limited to 'tools/tests/test-save.c')
-rw-r--r-- | tools/tests/test-save.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/tests/test-save.c b/tools/tests/test-save.c index 41f4e08..88d1ecd 100644 --- a/tools/tests/test-save.c +++ b/tools/tests/test-save.c @@ -191,6 +191,54 @@ test_file_overwrite (CuTest *tc) } static void +test_file_auto_empty (CuTest *tc) +{ + p11_save_file *file; + char *filename; + bool ret; + + setup (tc); + + if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) + CuFail (tc, "asprintf() failed"); + + file = p11_save_open_file (filename, 0); + CuAssertPtrNotNull (tc, file); + + ret = p11_save_write_and_finish (file, NULL, -1); + CuAssertIntEquals (tc, true, ret); + free (filename); + + test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/empty-file"); + + teardown (tc); +} + +static void +test_file_auto_length (CuTest *tc) +{ + p11_save_file *file; + char *filename; + bool ret; + + setup (tc); + + if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) + CuFail (tc, "asprintf() failed"); + + file = p11_save_open_file (filename, 0); + CuAssertPtrNotNull (tc, file); + + ret = p11_save_write_and_finish (file, "The simple string is hairy", -1); + CuAssertIntEquals (tc, true, ret); + free (filename); + + test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/simple-string"); + + teardown (tc); +} + +static void test_write_with_null (CuTest *tc) { bool ret; @@ -496,6 +544,8 @@ main (void) SUITE_ADD_TEST (suite, test_file_exists); SUITE_ADD_TEST (suite, test_file_bad_directory); SUITE_ADD_TEST (suite, test_file_overwrite); + SUITE_ADD_TEST (suite, test_file_auto_empty); + SUITE_ADD_TEST (suite, test_file_auto_length); SUITE_ADD_TEST (suite, test_write_with_null); SUITE_ADD_TEST (suite, test_write_and_finish_with_null); SUITE_ADD_TEST (suite, test_file_abort); |