1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*
* Copyright (C) 2021 Grilo Project
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <glib.h>
#include <glib-object.h>
#include <grilo.h>
/* Simple iteration to see that max and mix set in GrlOperationOptions is being
* respected. The values cannot be outside bounderies of what is registered for
* that metadata-key, e.g: GRL_METADATA_KEY_ORIENTATION has min: 0, max: 359 so
* negative numbers or >=360 or max < min are not allowed */
static void
range_filters_max_min_int(void)
{
static struct {
gint key_id;
gint min_registered;
gint max_registered;
gint min_test;
gint max_test;
gboolean result_registered;
gboolean expected_ret;
} int_keys[] = {
{ GRL_METADATA_KEY_ORIENTATION, 0, 359, 90, 180, FALSE, TRUE },
{ GRL_METADATA_KEY_ORIENTATION, 0, 359, -1, 999, TRUE, TRUE },
{ GRL_METADATA_KEY_ORIENTATION, 0, 359, 180, 90, FALSE, FALSE }
};
gint i;
for (i = 0; i < G_N_ELEMENTS (int_keys); i++) {
GrlOperationOptions *options = grl_operation_options_new (NULL);
gboolean ret;
GValue *min = NULL;
GValue *max = NULL;
ret = grl_operation_options_set_key_range_filter (options,
GRL_METADATA_KEY_ORIENTATION,
int_keys[i].min_test,
int_keys[i].max_test,
NULL);
g_assert_cmpint(ret, ==, int_keys[i].expected_ret);
if (ret) {
grl_operation_options_get_key_range_filter (options, GRL_METADATA_KEY_ORIENTATION, &min, &max);
if (int_keys[i].result_registered) {
g_assert_cmpint(g_value_get_int (min), ==, int_keys[i].min_registered);
g_assert_cmpint(g_value_get_int (max), ==, int_keys[i].max_registered);
} else {
g_assert_cmpint(g_value_get_int (min), ==, int_keys[i].min_test);
g_assert_cmpint(g_value_get_int (max), ==, int_keys[i].max_test);
}
}
}
}
static void
range_filters_max_min_null(void)
{
GrlOperationOptions *options = grl_operation_options_new (NULL);
gboolean ret;
GValue value = G_VALUE_INIT;
GValue *max, *min;
g_test_bug ("148");
/* Before */
grl_operation_options_get_key_range_filter (options,
GRL_METADATA_KEY_ORIENTATION,
&min,
&max);
/* TODO: this is actually a bug. Should get default min/max for this metadata-key 0/359.
* Seems that grilo stores the range in GParamSpec but does not set it in the HashTable
* GrlOperationsOptions look at. */
g_assert_null(min);
g_assert_null(max);
/* Test MIN */
g_value_init (&value, G_TYPE_INT);
g_value_set_int (&value, 90);
ret = grl_operation_options_set_key_range_filter_value (options,
GRL_METADATA_KEY_ORIENTATION,
&value,
NULL);
g_assert_true(ret);
grl_operation_options_get_key_range_filter (options, GRL_METADATA_KEY_ORIENTATION, &min, &max);
g_assert_cmpint(g_value_get_int (min), ==, 90);
// TODO: Same bug, as max was not set we receive NULL instead
g_assert_null(max);
g_value_unset(min);
/* Test MAX */
g_value_set_int (&value, 180);
ret = grl_operation_options_set_key_range_filter_value (options,
GRL_METADATA_KEY_ORIENTATION,
NULL,
&value);
g_assert_true(ret);
grl_operation_options_get_key_range_filter (options, GRL_METADATA_KEY_ORIENTATION, &min, &max);
/* TODO: This is another bug. When we set max above, the min should not be changed.
* g_assert_cmpint(g_value_get_int (min), ==, 90);
*/
g_assert_null(min);
g_assert_cmpint(g_value_get_int (max), ==, 180);
g_value_unset(max);
}
int
main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://gitlab.gnome.org/GNOME/grilo/issues/%s");
grl_init (&argc, &argv);
/* registry tests */
g_test_add_func ("/operation/range-filters/max-min/int", range_filters_max_min_int);
g_test_add_func ("/operation/range-filters/max-min/null", range_filters_max_min_null);
return g_test_run ();
}
|