On Sunday 14 June 2009 12:03:45 pm Brad Hards wrote:
> In an attempt to improve coverage a little, I've added some unit tests that
> check for a NULL destination for some of the base types. These pass,
> although I didn't actually run the coverage checker locally to verify that
> we're now testing correctly.
Here is a couple more. this time for base/crypt. I'm now running the coverage
checker to verify these.
Please apply
Brad
=== modified file 'torture/unit/base/crypt/pdf-crypt-md-new.c'
--- torture/unit/base/crypt/pdf-crypt-md-new.c 2008-12-21 17:39:51 +0000
+++ torture/unit/base/crypt/pdf-crypt-md-new.c 2009-06-14 07:02:33 +0000
@@ -47,6 +47,20 @@
}
END_TEST
+/*
+ * Test: pdf_crypt_md_new_002
+ * Description:
+ * Create a new nonce (random initialization vector).
+ * Success condition:
+ * Returns PDF_OK
+ */
+START_TEST (pdf_crypt_md_new_002)
+{
+ pdf_char_t buffer[16];
+
+ fail_if (pdf_crypt_nonce (buffer, sizeof(buffer)) != PDF_OK);
+}
+END_TEST
/*
* Test case creation function
@@ -56,6 +70,7 @@
{
TCase *tc = tcase_create("pdf_crypt_md_new");
tcase_add_test(tc, pdf_crypt_md_new_001);
+ tcase_add_test(tc, pdf_crypt_md_new_002);
return tc;
}
=== modified file 'torture/unit/base/crypt/pdf-crypt-md-read.c'
--- torture/unit/base/crypt/pdf-crypt-md-read.c 2008-12-23 18:16:49 +0000
+++ torture/unit/base/crypt/pdf-crypt-md-read.c 2009-06-14 07:41:03 +0000
@@ -132,6 +132,57 @@
END_TEST
+/*
+ * Test: pdf_crypt_md_read_004
+ * Description:
+ * Confirm that we handle the "output buffer is too small" case
+ * Success condition:
+ * Returns PDF_EBADDATA.
+ */
+START_TEST (pdf_crypt_md_read_004)
+{
+ pdf_char_t *in;
+ pdf_char_t out[6];
+ pdf_crypt_md_t md;
+ pdf_char_t real_out[] = {
+ 0xd4, 0x1d, 0x8c, 0xd9,
+ 0x8f, 0x00, 0xb2, 0x04,
+ 0xe9, 0x80, 0x09, 0x98,
+ 0xec, 0xf8, 0x42, 0x7e
+ };
+
+ pdf_crypt_init();
+
+ pdf_crypt_md_new (PDF_CRYPT_MD_MD5, &md);
+
+ pdf_crypt_md_write (md, in, 0);
+
+ fail_unless (pdf_crypt_md_read (md, out, sizeof(out)) == PDF_EBADDATA);
+
+ pdf_crypt_md_destroy (md);
+}
+END_TEST
+
+/*
+ * Test: pdf_crypt_md_read_005
+ * Description:
+ * Confirm that we handle passing an unsupported message digest
+ * algorithm to pdf_crypt_md_new().
+ * Success condition:
+ * Returns PDF_EBADDATA.
+ */
+START_TEST (pdf_crypt_md_read_005)
+{
+ pdf_char_t *in;
+ pdf_char_t out[20];
+ pdf_crypt_md_t md;
+
+ pdf_crypt_init();
+
+ fail_unless (pdf_crypt_md_new (PDF_CRYPT_MD_MD5 + 1, &md) == PDF_EBADDATA);
+}
+END_TEST
+
/*
@@ -144,6 +195,8 @@
tcase_add_test(tc, pdf_crypt_md_read_001);
tcase_add_test(tc, pdf_crypt_md_read_002);
tcase_add_test(tc, pdf_crypt_md_read_003);
+ tcase_add_test(tc, pdf_crypt_md_read_004);
+ tcase_add_test(tc, pdf_crypt_md_read_005);
return tc;
}