From d4fb115bda4a870ad0b28c6fec34814ff07ad115 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Mon, 22 Oct 2001 14:19:25 +0000 Subject: [PATCH] 2001-10-22 Marcus Brinkmann * t-data.c (write_test): New function. (main): Invoke write_test for all rounds except TEST_OUT_CB. --- tests/ChangeLog | 5 +++++ tests/t-data.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index a90637ff..53b9c516 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2001-10-22 Marcus Brinkmann + + * t-data.c (write_test): New function. + (main): Invoke write_test for all rounds except TEST_OUT_CB. + 2001-10-22 Marcus Brinkmann * Makefile.am (INCLUDES): Remove spurious duplicate to silence diff --git a/tests/t-data.c b/tests/t-data.c index f7d6e4cc..47a8926b 100644 --- a/tests/t-data.c +++ b/tests/t-data.c @@ -71,13 +71,14 @@ typedef enum } round_t; const char *text = "Just GNU it!\n"; +const char *text2 = "Just GNU it!\nJust GNU it!\n"; int read_cb (void *cb_value, char *buffer, size_t count, size_t *nread) { static int off = 0; - round_t round = *((round_t *) cb_value); int amount = strlen (text) - off; + /* round_t round = *((round_t *) cb_value); */ if (!buffer && !count && !nread) { @@ -152,6 +153,44 @@ read_test (round_t round, GpgmeData data) read_once_test (round, data); } +void +write_test (round_t round, GpgmeData data) +{ + GpgmeError err; + char buffer[1024]; + int read; + + err = gpgme_data_write (data, text, strlen (text)); + fail_if_err (err); + + read_once_test (round, data); + err = gpgme_data_rewind (data); + fail_if_err (err); + + if (round == TEST_INOUT_NONE) + read_once_test (round, data); + else + { + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + fail_if_err (err); + + if (read != strlen (text2) || strncmp (buffer, text2, strlen (text2))) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read returned wrong data\n", + __FILE__, __LINE__, round); + exit (1); + } + + err = gpgme_data_read (data, buffer, sizeof (buffer), &read); + if (err != GPGME_EOF) + { + fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n", + __FILE__, __LINE__, round); + exit (1); + } + } +} + int main (int argc, char **argv ) { @@ -276,7 +315,8 @@ main (int argc, char **argv ) exit (1); } read_test (round, data); - + if (round != TEST_OUT_CB) + write_test (round, data); gpgme_data_release (data); } return 0;