Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mms-lib] Added test for handling broken JPEGs
  • Loading branch information
monich committed Apr 15, 2014
1 parent 17a2f1c commit 4137924
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions mms-lib/test/resize/data/junk.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 19 additions & 6 deletions mms-lib/test/resize/test_resize.c
Expand Up @@ -14,6 +14,7 @@

#include "mms_attachment.h"
#include "mms_lib_util.h"
#include "mms_lib_log.h"
#include "mms_log.h"

#include <libexif/exif-content.h>
Expand Down Expand Up @@ -124,7 +125,8 @@ static const TestDesc resize_tests[] = {
},{
"Jpeg_Landscape2",
"data/0002.jpg",
&test_auto_jpeg, 2,
&test_auto_jpeg,
2,
2000000,
{1088, 613}
},{
Expand All @@ -134,6 +136,13 @@ static const TestDesc resize_tests[] = {
3,
3000000,
{816, 460}
},{
"Jpeg_Broken",
"data/junk.jpg",
&test_jpeg,
1,
1000000,
{0, 0} /* Expect failure */
},{
"Png_1",
"data/0003.png",
Expand Down Expand Up @@ -376,7 +385,7 @@ test_run_one(
ok = FALSE;
}
}
if (ok) {
if (ok && test->size.width && test->size.height) {
TestSize size;
if (test->type->filesize(at->file_name, &size)) {
if (size.width == test->size.width &&
Expand All @@ -393,6 +402,8 @@ test_run_one(
test->size.width, test->size.height);
}
}
} else if (!ok && !test->size.width && !test->size.height) {
ret = RET_OK;
}
mms_attachment_unref(at);
} else {
Expand Down Expand Up @@ -455,7 +466,6 @@ int main(int argc, char* argv[])
options = g_option_context_new("[TEST] - Resizing test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, NULL) && argc < 3) {

const char* test = (argc == 2) ? argv[1] : NULL;
MMSConfig config;
mms_lib_default_config(&config);
Expand All @@ -464,9 +474,12 @@ int main(int argc, char* argv[])

mms_log_stdout_timestamp = FALSE;
mms_log_default.name = "test_resize";
mms_log_default.level = verbose ?
MMS_LOGLEVEL_VERBOSE :
MMS_LOGLEVEL_INFO;
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
mms_log_default.level = MMS_LOGLEVEL_INFO;
mms_attachment_log.level = MMS_LOGLEVEL_ERR;
}
ret = test_run(&config, test);
}
g_option_context_free(options);
Expand Down

0 comments on commit 4137924

Please sign in to comment.