[gmime] Use more accessor methods in unit tests to increase coverage
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Use more accessor methods in unit tests to increase coverage
- Date: Thu, 9 Mar 2017 02:00:15 +0000 (UTC)
commit 3ca9d7cf813985d8bc069e93c787ae5a3de8448c
Author: Jeffrey Stedfast <fejj gnome org>
Date: Wed Mar 8 20:54:08 2017 -0500
Use more accessor methods in unit tests to increase coverage
tests/test-headers.c | 18 +++++++++++-------
tests/test-mbox.c | 20 +++++++++++++++-----
tests/test-mime.c | 12 +++++++-----
tests/test-pgp.c | 23 +++++++++++++++--------
tests/test-pgpmime.c | 2 +-
tests/test-pkcs7.c | 19 ++++++++-----------
tests/test-smime.c | 2 +-
tests/testsuite.c | 40 +++++++++++++++++++++++++++++++++-------
8 files changed, 91 insertions(+), 45 deletions(-)
---
diff --git a/tests/test-headers.c b/tests/test-headers.c
index bda2263..8c405a7 100644
--- a/tests/test-headers.c
+++ b/tests/test-headers.c
@@ -165,8 +165,10 @@ test_remove_at (void)
static void
test_header_sync (void)
{
+ GMimeContentDisposition *disposition;
InternetAddressList *list;
InternetAddress *addr, *ia;
+ GMimeContentType *type;
GMimeMessage *message;
GMimeObject *object;
const char *value;
@@ -186,28 +188,29 @@ test_header_sync (void)
throw (exception_new ("initial content-type header had unexpected value"));
/* now change the content-type's media type... */
- g_mime_content_type_set_media_type (object->content_type, "text");
+ type = g_mime_object_get_content_type (object);
+ g_mime_content_type_set_media_type (type, "text");
if (!(value = g_mime_object_get_header (object, "Content-Type")))
throw (exception_new ("content-type header was unexpectedly null after changing
type"));
if (strcmp ("text/octet-stream", value) != 0)
throw (exception_new ("content-type header had unexpected value after changing
type"));
/* now change the content-type's media subtype... */
- g_mime_content_type_set_media_subtype (object->content_type, "plain");
+ g_mime_content_type_set_media_subtype (type, "plain");
if (!(value = g_mime_object_get_header (object, "Content-Type")))
throw (exception_new ("content-type header was unexpectedly null after changing
subtype"));
if (strcmp ("text/plain", value) != 0)
throw (exception_new ("content-type header had unexpected value after changing
subtype"));
/* now change the content-type's parameters by setting a param */
- g_mime_content_type_set_parameter (object->content_type, "format", "flowed");
+ g_mime_content_type_set_parameter (type, "format", "flowed");
if (!(value = g_mime_object_get_header (object, "Content-Type")))
throw (exception_new ("content-type header was unexpectedly null after setting a
param"));
if (strcmp ("text/plain; format=flowed", value) != 0)
throw (exception_new ("content-type header had unexpected value after setting a
param"));
/* now change the content-type's parameters by setting a param list */
- g_mime_content_type_set_params (object->content_type, NULL);
+ g_mime_content_type_set_params (type, NULL);
if (!(value = g_mime_object_get_header (object, "Content-Type")))
throw (exception_new ("content-type header was unexpectedly null after setting
params"));
if (strcmp ("text/plain", value) != 0)
@@ -231,21 +234,22 @@ test_header_sync (void)
throw (exception_new ("initial content-disposition header had unexpected value"));
/* now change the content-disposition's disposition */
- g_mime_content_disposition_set_disposition (object->disposition, "inline");
+ disposition = g_mime_object_get_content_disposition (object);
+ g_mime_content_disposition_set_disposition (disposition, "inline");
if (!(value = g_mime_object_get_header (object, "Content-Disposition")))
throw (exception_new ("content-disposition header was unexpectedly null after
changing type"));
if (strcmp ("inline", value) != 0)
throw (exception_new ("content-disposition header had unexpected value after changing
type"));
/* now change the content-disposition's parameters by setting a param */
- g_mime_content_disposition_set_parameter (object->disposition, "filename", "hello.txt");
+ g_mime_content_disposition_set_parameter (disposition, "filename", "hello.txt");
if (!(value = g_mime_object_get_header (object, "Content-Disposition")))
throw (exception_new ("content-disposition header was unexpectedly null after setting
a param"));
if (strcmp ("inline; filename=hello.txt", value) != 0)
throw (exception_new ("content-disposition header had unexpected value after setting
a param"));
/* now change the content-disposition's parameters by setting a param list */
- g_mime_content_disposition_set_params (object->disposition, NULL);
+ g_mime_content_disposition_set_params (disposition, NULL);
if (!(value = g_mime_object_get_header (object, "Content-Disposition")))
throw (exception_new ("content-disposition header was unexpectedly null after setting
params"));
if (strcmp ("inline", value) != 0)
diff --git a/tests/test-mbox.c b/tests/test-mbox.c
index 7982b77..95f52ef 100644
--- a/tests/test-mbox.c
+++ b/tests/test-mbox.c
@@ -58,17 +58,21 @@ print_depth (GMimeStream *stream, int depth)
static void
print_mime_struct (GMimeStream *stream, GMimeObject *part, int depth)
{
- const GMimeContentType *type;
GMimeMultipart *multipart;
GMimeMessagePart *mpart;
+ GMimeContentType *type;
GMimeObject *subpart;
+ GMimeObject *body;
+ GMimeMessage *msg;
int i, n;
print_depth (stream, depth);
type = g_mime_object_get_content_type (part);
- g_mime_stream_printf (stream, "Content-Type: %s/%s\n", type->type, type->subtype);
+ g_mime_stream_printf (stream, "Content-Type: %s/%s\n",
+ g_mime_content_type_get_media_type (type),
+ g_mime_content_type_get_media_subtype (type));
if (GMIME_IS_MULTIPART (part)) {
multipart = (GMimeMultipart *) part;
@@ -80,9 +84,13 @@ print_mime_struct (GMimeStream *stream, GMimeObject *part, int depth)
}
} else if (GMIME_IS_MESSAGE_PART (part)) {
mpart = (GMimeMessagePart *) part;
+ msg = g_mime_message_part_get_message (mpart);
- if (mpart->message)
- print_mime_struct (stream, mpart->message->mime_part, depth + 1);
+ if (msg != NULL) {
+ body = g_mime_message_get_mime_part (msg);
+
+ print_mime_struct (stream, body, depth + 1);
+ }
}
}
@@ -94,6 +102,7 @@ test_parser (GMimeParser *parser, GMimeStream *mbox, GMimeStream *summary)
GMimeMessage *message;
char *marker, *buf;
const char *subject;
+ GMimeObject *body;
int tz_offset;
int nmsg = 0;
time_t date;
@@ -139,7 +148,8 @@ test_parser (GMimeParser *parser, GMimeStream *mbox, GMimeStream *summary)
g_mime_stream_printf (summary, "Date: %s\n", buf);
g_free (buf);
- print_mime_struct (summary, message->mime_part, 0);
+ body = g_mime_message_get_mime_part (message);
+ print_mime_struct (summary, body, 0);
g_mime_stream_write (summary, "\n", 1);
if (mbox) {
diff --git a/tests/test-mime.c b/tests/test-mime.c
index ac3b58b..d613268 100644
--- a/tests/test-mime.c
+++ b/tests/test-mime.c
@@ -533,6 +533,7 @@ static void
test_rfc2184 (GMimeParserOptions *options)
{
GMimeParam param, *params;
+ const char *value;
GString *str;
size_t n;
guint i;
@@ -560,7 +561,8 @@ test_rfc2184 (GMimeParserOptions *options)
if (params->next != NULL)
throw (exception_new ("parsed more than a single param?"));
- if (strcmp (rfc2184[i].input, params->value) != 0)
+ value = g_mime_param_get_value (params);
+ if (strcmp (rfc2184[i].input, value) != 0)
throw (exception_new ("parsed param value does not match"));
testsuite_check_passed ();
@@ -634,12 +636,12 @@ int main (int argc, char **argv)
testsuite_init (argc, argv);
testsuite_start ("addr-spec parser (strict)");
- options->rfc2047 = GMIME_RFC_COMPLIANCE_STRICT;
+ g_mime_parser_options_set_rfc2047_compliance_mode (options, GMIME_RFC_COMPLIANCE_STRICT);
test_addrspec (options, FALSE);
testsuite_end ();
testsuite_start ("addr-spec parser (loose)");
- options->rfc2047 = GMIME_RFC_COMPLIANCE_LOOSE;
+ g_mime_parser_options_set_rfc2047_compliance_mode (options, GMIME_RFC_COMPLIANCE_LOOSE);
test_addrspec (options, TRUE);
testsuite_end ();
@@ -648,12 +650,12 @@ int main (int argc, char **argv)
testsuite_end ();
testsuite_start ("rfc2047 encoding/decoding (strict)");
- options->rfc2047 = GMIME_RFC_COMPLIANCE_STRICT;
+ g_mime_parser_options_set_rfc2047_compliance_mode (options, GMIME_RFC_COMPLIANCE_STRICT);
test_rfc2047 (options, FALSE);
testsuite_end ();
testsuite_start ("rfc2047 encoding/decoding (loose)");
- options->rfc2047 = GMIME_RFC_COMPLIANCE_LOOSE;
+ g_mime_parser_options_set_rfc2047_compliance_mode (options, GMIME_RFC_COMPLIANCE_LOOSE);
test_rfc2047 (options, TRUE);
testsuite_end ();
diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index 030c101..b1beb3a 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -58,7 +58,7 @@ get_sig_status (GMimeSignatureList *signatures)
for (i = 0; i < g_mime_signature_list_length (signatures); i++) {
sig = g_mime_signature_list_get_signature (signatures, i);
- status |= sig->status;
+ status |= g_mime_signature_get_status (sig);
}
return status;
@@ -142,6 +142,7 @@ test_encrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GM
static void
test_decrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GMimeStream *ciphertext)
{
+ GMimeSignatureList *signatures;
GMimeSignatureStatus status;
GMimeDecryptResult *result;
Exception *ex = NULL;
@@ -158,13 +159,19 @@ test_decrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GM
throw (ex);
}
+ signatures = g_mime_decrypt_result_get_signatures (result);
+
if (sign) {
- status = get_sig_status (result->signatures);
-
- if ((status & GMIME_SIGNATURE_STATUS_RED) != 0)
- ex = exception_new ("expected GOOD signature");
+ if (signatures != NULL) {
+ status = get_sig_status (signatures);
+
+ if ((status & GMIME_SIGNATURE_STATUS_RED) != 0)
+ ex = exception_new ("expected GOOD signature");
+ } else {
+ ex = exception_new ("Failed to get signatures");
+ }
} else {
- if (result->signatures != NULL)
+ if (signatures != NULL)
ex = exception_new ("unexpected signature");
}
@@ -180,8 +187,8 @@ test_decrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GM
throw (ex);
}
- buf[0] = GMIME_STREAM_MEM (cleartext)->buffer;
- buf[1] = GMIME_STREAM_MEM (stream)->buffer;
+ buf[0] = g_mime_stream_mem_get_byte_array ((GMimeStreamMem *) cleartext);
+ buf[1] = g_mime_stream_mem_get_byte_array ((GMimeStreamMem *) stream);
if (buf[0]->len != buf[1]->len || memcmp (buf[0]->data, buf[1]->data, buf[0]->len) != 0)
ex = exception_new ("decrypted data does not match original cleartext");
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index 7cf43a5..31c4247 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -59,7 +59,7 @@ get_sig_status (GMimeSignatureList *signatures)
for (i = 0; i < g_mime_signature_list_length (signatures); i++) {
sig = g_mime_signature_list_get_signature (signatures, i);
- status |= sig->status;
+ status |= g_mime_signature_get_status (sig);
}
return status;
diff --git a/tests/test-pkcs7.c b/tests/test-pkcs7.c
index d330f9a..59f4724 100644
--- a/tests/test-pkcs7.c
+++ b/tests/test-pkcs7.c
@@ -62,7 +62,7 @@ get_sig_status (GMimeSignatureList *signatures)
for (i = 0; i < g_mime_signature_list_length (signatures); i++) {
sig = g_mime_signature_list_get_signature (signatures, i);
- status |= sig->status;
+ status |= g_mime_signature_get_status (sig);
}
return status;
@@ -191,9 +191,9 @@ test_encrypt (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciph
}
static void
-test_decrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GMimeStream *ciphertext)
+test_decrypt (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphertext)
{
- GMimeSignatureStatus status;
+ GMimeCertificateList *recipients;
GMimeDecryptResult *result;
Exception *ex = NULL;
GMimeStream *stream;
@@ -209,14 +209,11 @@ test_decrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GM
throw (ex);
}
- if (sign) {
- status = get_sig_status (result->signatures);
+ if (!(recipients = g_mime_decrypt_result_get_recipients (result))) {
+ g_object_unref (result);
+ g_object_unref (stream);
- if ((status & GMIME_SIGNATURE_STATUS_RED) != 0)
- ex = exception_new ("expected GOOD signature");
- } else {
- if (result->signatures)
- ex = exception_new ("unexpected signature");
+ throw (exception_new ("Failed to get recipients"));
}
g_object_unref (result);
@@ -436,7 +433,7 @@ int main (int argc, char **argv)
testsuite_check (what);
g_mime_stream_reset (istream);
g_mime_stream_reset (ostream);
- test_decrypt (ctx, FALSE, istream, ostream);
+ test_decrypt (ctx, istream, ostream);
testsuite_check_passed ();
} catch (ex) {
testsuite_check_failed ("%s failed: %s", what, ex->message);
diff --git a/tests/test-smime.c b/tests/test-smime.c
index f4afb3f..48e3b49 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -62,7 +62,7 @@ get_sig_status (GMimeSignatureList *signatures)
for (i = 0; i < g_mime_signature_list_length (signatures); i++) {
sig = g_mime_signature_list_get_signature (signatures, i);
- status |= sig->status;
+ status |= g_mime_signature_get_status (sig);
}
return status;
diff --git a/tests/testsuite.c b/tests/testsuite.c
index a437d41..2f170c6 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -423,14 +423,18 @@ testsuite_can_safely_override_session_key (const char *gpg)
int
testsuite_setup_gpghome (const char *gpg)
{
- char *command;
+ const char *files[] = { "./tmp/.gnupg/gpg.conf", "./tmp/.gnupg/gpgsm.conf",
"./tmp/.gnupg/gpg-agent.conf", "./tmp/.gnupg/dirmngr.conf", NULL };
+ const char debug[] = "log-file socket://%s/tmp/.gnupg/S.log\ndebug 1024\nverbose\n";
+ char *command, *cwd;
FILE *fp;
+ int i;
/* reset .gnupg config directory */
- if (system ("/bin/rm -rf ./tmp") != 0)
- return EXIT_FAILURE;
- if (system ("/bin/mkdir ./tmp") != 0)
- return EXIT_FAILURE;
+ //if (system ("/bin/rm -rf ./tmp") != 0)
+ // return EXIT_FAILURE;
+
+ //if (g_mkdir ("./tmp", 0755) != 0)
+ // return EXIT_FAILURE;
g_setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
@@ -439,6 +443,8 @@ testsuite_setup_gpghome (const char *gpg)
g_unsetenv ("DISPLAY");
g_unsetenv ("GPG_TTY");
+ return 0;
+
command = g_strdup_printf ("%s --list-keys > /dev/null 2>&1", gpg);
if (system (command) != 0) {
g_free (command);
@@ -471,14 +477,34 @@ testsuite_setup_gpghome (const char *gpg)
if (fclose (fp))
return EXIT_FAILURE;
+ cwd = g_get_current_dir ();
+
+ for (i = 0; files[i]; i++) {
+ if (!(fp = fopen (files[i], "a")))
+ return EXIT_FAILURE;
+
+ if (fprintf (fp, debug, cwd) == -1) {
+ g_free (cwd);
+ fclose (fp);
+ return EXIT_FAILURE;
+ }
+
+ if (fclose (fp)) {
+ g_free (cwd);
+ return EXIT_FAILURE;
+ }
+ }
+
+ g_free (cwd);
+
return EXIT_SUCCESS;
}
int
testsuite_destroy_gpghome (void)
{
- if (system ("/bin/rm -rf ./tmp") != 0)
- return EXIT_FAILURE;
+ //if (system ("/bin/rm -rf ./tmp") != 0)
+ // return EXIT_FAILURE;
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]