|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Copyright (C) 2015 Red Hat, Inc.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
* version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
* Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
rpm-build |
0fba15 |
* Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "config.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "libglnx.h"
|
|
rpm-build |
0fba15 |
#include "ot-unix-utils.h"
|
|
rpm-build |
0fba15 |
#include <glib.h>
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
test_ot_util_path_split_validate (void)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
const char *paths[] = {"foo/bar", "test", "foo/bar:", "a/b/c/d/e/f/g/h/i/l/m/n/o/p", NULL};
|
|
rpm-build |
0fba15 |
int n_components[] = {2, 1, 2, 14, 0};
|
|
rpm-build |
0fba15 |
int i;
|
|
rpm-build |
0fba15 |
for (i = 0; paths[i]; i++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GError *error = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(GPtrArray) components = NULL;
|
|
rpm-build |
0fba15 |
if (! ot_util_path_split_validate (paths[i], &components, &error))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
int j;
|
|
rpm-build |
0fba15 |
g_assert_cmpint (components->len, ==, n_components[i]);
|
|
rpm-build |
0fba15 |
for (j = 0; j < components->len; j++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_assert (strcmp (components->pdata[i], ".."));
|
|
rpm-build |
0fba15 |
g_assert_null (strchr (components->pdata[i], '/'));
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
test_ot_util_filename_validate (void)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GError) error = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Check for valid inputs. */
|
|
rpm-build |
0fba15 |
g_assert (ot_util_filename_validate ("valid", &error));
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
g_assert (ot_util_filename_validate ("valid_file_name", &error));
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
g_assert (ot_util_filename_validate ("file.name", &error));
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
g_assert (ot_util_filename_validate ("foo..", &error));
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
g_assert (ot_util_filename_validate ("..bar", &error));
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
g_assert (ot_util_filename_validate ("baz:", &error));
|
|
rpm-build |
0fba15 |
g_assert_no_error (error);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Check for invalid inputs. */
|
|
rpm-build |
0fba15 |
g_assert_false (ot_util_filename_validate ("not/valid/file/name", &error));
|
|
rpm-build |
0fba15 |
g_clear_error (&error);
|
|
rpm-build |
0fba15 |
g_assert_false (ot_util_filename_validate (".", &error));
|
|
rpm-build |
0fba15 |
g_clear_error (&error);
|
|
rpm-build |
0fba15 |
g_assert_false (ot_util_filename_validate ("..", &error));
|
|
rpm-build |
0fba15 |
g_clear_error (&error);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
int main (int argc, char **argv)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_test_init (&argc, &argv, NULL);
|
|
rpm-build |
0fba15 |
g_test_add_func ("/ot_util_path_split_validate", test_ot_util_path_split_validate);
|
|
rpm-build |
0fba15 |
g_test_add_func ("/ot_util_filename_validate", test_ot_util_filename_validate);
|
|
rpm-build |
0fba15 |
return g_test_run();
|
|
rpm-build |
0fba15 |
}
|