Commit 3f1888da authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

fixed filesize test

Use a guint64 to store the size to avoid an overflow for big
files.
parent ccfcfdd0
......@@ -48,7 +48,7 @@ GthMetadataInfo comments_metadata_info[] = {
};
static gint64
static int
get_comment_for_test (GthTest *test,
GthFileData *file,
gconstpointer *data,
......@@ -59,7 +59,7 @@ get_comment_for_test (GthTest *test,
}
static gint64
static int
get_place_for_test (GthTest *test,
GthFileData *file,
gconstpointer *data,
......
......@@ -30,7 +30,7 @@
#include "gth-time.h"
static gint64
static int
is_file_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -40,7 +40,7 @@ is_file_test (GthTest *test,
}
static gint64
static int
is_image_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -55,7 +55,7 @@ is_image_test (GthTest *test,
}
static gint64
static int
is_jpeg_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -70,7 +70,7 @@ is_jpeg_test (GthTest *test,
}
static gint64
static int
is_raw_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -85,7 +85,7 @@ is_raw_test (GthTest *test,
}
static gint64
static int
is_video_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -100,7 +100,7 @@ is_video_test (GthTest *test,
}
static gint64
static int
is_audio_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -115,7 +115,7 @@ is_audio_test (GthTest *test,
}
static gint64
static int
is_media_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -134,7 +134,7 @@ is_media_test (GthTest *test,
}
static gint64
static int
is_text_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -151,7 +151,7 @@ is_text_test (GthTest *test,
}
static gint64
static int
get_filename_for_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -162,17 +162,19 @@ get_filename_for_test (GthTest *test,
}
static gint64
static int
get_filesize_for_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
GDestroyNotify *data_destroy_func)
{
return g_file_info_get_size (file_data->info);
guint64 *size = (guint64 *) data;
*size = g_file_info_get_size (file_data->info);
return 0;
}
static gint64
static int
get_modified_date_for_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -195,7 +197,7 @@ get_modified_date_for_test (GthTest *test,
}
static gint64
static int
get_original_date_for_test (GthTest *test,
GthFileData *file_data,
gconstpointer *data,
......@@ -219,7 +221,7 @@ get_original_date_for_test (GthTest *test,
}
static gint64
static int
get_embedded_title_for_test (GthTest *test,
GthFileData *file,
gconstpointer *data,
......@@ -237,7 +239,7 @@ get_embedded_title_for_test (GthTest *test,
}
static gint64
static int
get_embedded_description_for_test (GthTest *test,
GthFileData *file,
gconstpointer *data,
......@@ -255,7 +257,7 @@ get_embedded_description_for_test (GthTest *test,
}
static gint64
static int
get_embedded_rating_for_test (GthTest *test,
GthFileData *file,
gconstpointer *data,
......
......@@ -86,6 +86,7 @@ enum {
PROP_DATA_TYPE,
PROP_DATA_AS_STRING,
PROP_DATA_AS_INT,
PROP_DATA_AS_SIZE,
PROP_DATA_AS_DOUBLE,
PROP_DATA_AS_DATE,
PROP_GET_DATA,
......@@ -99,10 +100,11 @@ enum {
struct _GthTestSimplePrivate {
GthTestDataType data_type;
union {
char *s;
gint64 i;
GDate *date;
gdouble f;
char *s;
int i;
guint64 size;
GDate *date;
gdouble f;
} data;
GthTestGetData get_data;
GthTestOp op;
......@@ -406,11 +408,11 @@ create_control_for_size (GthTestSimple *test)
for (i = 0; i < G_N_ELEMENTS (size_data); i++) {
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (test->priv->size_combo_box),
_(size_data[i].name));
if (! size_set && ((i == G_N_ELEMENTS (size_data) - 1) || (test->priv->data.i < size_data[i + 1].size))) {
if (! size_set && ((i == G_N_ELEMENTS (size_data) - 1) || (test->priv->data.size < size_data[i + 1].size))) {
char *value;
size_idx = i;
value = g_strdup_printf ("%.2f", (double) test->priv->data.i / size_data[i].size);
value = g_strdup_printf ("%.2f", (double) test->priv->data.size / size_data[i].size);
gtk_entry_set_text (GTK_ENTRY (test->priv->text_entry), value);
g_free (value);
size_set = TRUE;
......@@ -702,6 +704,33 @@ test_integer (GthTestSimple *test,
}
static gboolean
test_size (GthTestSimple *test,
guint64 value)
{
gboolean result = FALSE;
switch (test->priv->op) {
case GTH_TEST_OP_EQUAL:
result = (value == test->priv->data.size);
break;
case GTH_TEST_OP_LOWER:
result = (value < test->priv->data.size);
break;
case GTH_TEST_OP_GREATER:
result = (value > test->priv->data.size);
break;
default:
break;
}
return result;
}
static gboolean
test_double (GthTestSimple *test,
gdouble value)
......@@ -781,6 +810,18 @@ _gth_test_simple_get_int (GthTestSimple *test,
}
static guint64
_gth_test_simple_get_size (GthTestSimple *test,
GthFileData *file)
{
guint64 value;
test->priv->get_data (GTH_TEST (test), file, (gpointer)&value, NULL);
return value;
}
static gdouble
_gth_test_simple_get_double (GthTestSimple *test,
GthFileData *file)
......@@ -810,10 +851,13 @@ gth_test_simple_real_match (GthTest *test,
break;
case GTH_TEST_DATA_TYPE_INT:
case GTH_TEST_DATA_TYPE_SIZE:
result = test_integer (test_simple, _gth_test_simple_get_int (test_simple, file));
break;
case GTH_TEST_DATA_TYPE_SIZE:
result = test_size (test_simple, _gth_test_simple_get_size (test_simple, file));
break;
case GTH_TEST_DATA_TYPE_DOUBLE:
result = test_double (test_simple, _gth_test_simple_get_double (test_simple, file));
break;
......@@ -833,7 +877,7 @@ gth_test_simple_real_match (GthTest *test,
break;
}
if (test_simple->priv->negative)
if (test_simple->priv->negative)
result = ! result;
return result ? GTH_MATCH_YES : GTH_MATCH_NO;
......@@ -864,12 +908,22 @@ gth_test_simple_real_create_element (DomDomizable *base,
break;
case GTH_TEST_DATA_TYPE_INT:
dom_element_set_attribute (element, "op", _g_enum_type_get_value (GTH_TYPE_TEST_OP, self->priv->op)->value_nick);
if (self->priv->op != GTH_TEST_OP_NONE) {
if (self->priv->negative)
dom_element_set_attribute (element, "negative", self->priv->negative ? "true" : "false");
value = g_strdup_printf ("%d", self->priv->data.i);
dom_element_set_attribute (element, "value", value);
g_free (value);
}
break;
case GTH_TEST_DATA_TYPE_SIZE:
dom_element_set_attribute (element, "op", _g_enum_type_get_value (GTH_TYPE_TEST_OP, self->priv->op)->value_nick);
if (self->priv->op != GTH_TEST_OP_NONE) {
if (self->priv->negative)
dom_element_set_attribute (element, "negative", self->priv->negative ? "true" : "false");
value = g_strdup_printf ("%" G_GINT64_FORMAT, self->priv->data.i);
value = g_strdup_printf ("%" G_GUINT64_FORMAT, self->priv->data.size);
dom_element_set_attribute (element, "value", value);
g_free (value);
}
......@@ -1025,7 +1079,7 @@ update_from_control_for_size (GthTestSimple *self,
size = value * size_data[gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->size_combo_box))].size;
gth_test_simple_set_data_as_size (self, size);
if ((self->priv->data.i == 0) && (self->priv->op == GTH_TEST_OP_LOWER)) {
if ((self->priv->data.size == 0) && (self->priv->op == GTH_TEST_OP_LOWER)) {
if (error != NULL)
*error = g_error_new (GTH_TEST_ERROR, 0, _("The test definition is incomplete"));
return FALSE;
......@@ -1176,7 +1230,7 @@ gth_test_simple_real_duplicate (GthDuplicable *duplicable)
break;
case GTH_TEST_DATA_TYPE_SIZE:
gth_test_simple_set_data_as_size (new_test, test->priv->data.i);
gth_test_simple_set_data_as_size (new_test, test->priv->data.size);
break;
case GTH_TEST_DATA_TYPE_STRING:
......@@ -1223,6 +1277,11 @@ gth_test_simple_set_property (GObject *object,
test->priv->data.i = g_value_get_int (value);
break;
case PROP_DATA_AS_SIZE:
_gth_test_simple_free_data (test);
test->priv->data.size = g_value_get_uint64 (value);
break;
case PROP_DATA_AS_DOUBLE:
_gth_test_simple_free_data (test);
test->priv->data.f = g_value_get_double (value);
......@@ -1282,6 +1341,10 @@ gth_test_simple_get_property (GObject *object,
g_value_set_int (value, test->priv->data.i);
break;
case PROP_DATA_AS_SIZE:
g_value_set_uint64 (value, test->priv->data.size);
break;
case PROP_DATA_AS_DOUBLE:
g_value_set_double (value, test->priv->data.f);
break;
......@@ -1360,6 +1423,15 @@ gth_test_simple_class_init (GthTestSimpleClass *class)
G_MAXINT,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_DATA_AS_SIZE,
g_param_spec_uint64 ("data-as-size",
"Data as size",
"The data value as an unsigned long integer",
0,
G_MAXUINT64,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_DATA_AS_DOUBLE,
g_param_spec_double ("data-as-double",
......@@ -1493,7 +1565,7 @@ gth_test_simple_set_data_as_size (GthTestSimple *test,
{
_gth_test_simple_free_data (test);
test->priv->data_type = GTH_TEST_DATA_TYPE_SIZE;
test->priv->data.i = i;
test->priv->data.size = i;
}
......
......@@ -40,10 +40,10 @@ typedef struct _GthTestSimple GthTestSimple;
typedef struct _GthTestSimplePrivate GthTestSimplePrivate;
typedef struct _GthTestSimpleClass GthTestSimpleClass;
typedef gint64 (*GthTestGetData) (GthTest *test,
GthFileData *file,
gpointer *data,
GDestroyNotify *data_destroy_func);
typedef int (*GthTestGetData) (GthTest *test,
GthFileData *file,
gpointer *data,
GDestroyNotify *data_destroy_func);
typedef enum {
GTH_TEST_DATA_TYPE_NONE,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment