Commit 1e906054 authored by Philip Withnall's avatar Philip Withnall
Browse files

Merge branch '1307-tarball-dist' into 'master'

Remove some files not included in tarballs

Closes #1307

See merge request GNOME/glib!58
parents 95ebaa26 27ec1469
#include <gio/gio.h>
#define GETTEXT_PACKAGE "gio-ls"
#define N_(s) (s)
#define _(s) (s)
enum
{
SHOW_ALL,
SHOW_LONG
};
static void print_path (const gchar* path, guint32 flags);
static gboolean show_all = FALSE;
static gboolean show_long = FALSE;
int
main (int argc, char *argv[])
{
GOptionContext *context = NULL;
static GOptionEntry options[] =
{
{"all", 'a', 0, G_OPTION_ARG_NONE, &show_all,
N_("do not hide entries"), NULL },
{"long", 'l', 0, G_OPTION_ARG_NONE, &show_long,
N_("use a long listing format"), NULL },
{ NULL }
};
GError *error = NULL;
int i;
context = g_option_context_new(_("[FILE...]"));
g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_print ("%s", error->message);
g_error_free (error);
}
else
{
for (i = 1; i < argc; i++)
{
print_path (argv[i], (show_all ? SHOW_ALL : 0) | (show_long ? SHOW_LONG : 0));
}
}
g_option_context_free(context);
return 0;
}
static void
print_path (const gchar* path,
guint32 flags)
{
GFile *top;
const gchar *short_attrs = G_FILE_ATTRIBUTE_STANDARD_NAME;
const gchar *long_attrs = G_FILE_ATTRIBUTE_OWNER_USER "," G_FILE_ATTRIBUTE_OWNER_GROUP "," \
"access:*,std:*";
const gchar *attrs;
if (flags & SHOW_LONG)
attrs = long_attrs;
else
attrs = short_attrs;
top = g_file_new_for_path (path);
if (top)
{
GFileInfo *info;
GError *error = NULL;
GFileEnumerator *enumerator = g_file_enumerate_children (top, attrs,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
if (error)
{
g_print ("%s", error->message);
g_error_free (error);
}
if (!enumerator)
return;
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
{
const gchar *name = g_file_info_get_name (info);
if (flags & SHOW_LONG)
{
const gchar *val;
g_print ("%c%c%c%c ",
g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY ? 'd' : '-',
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) ? 'r' : '-',
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) ? 'w' : '-',
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) ? 'x' : '-');
val = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER);
g_print ("\t%15s", val ? val : "?user?");
val = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
g_print ("\t%15s", val ? val : "?group?");
}
g_print ("\t%s\n", name ? name : "?noname?");
g_object_unref (info);
}
g_object_unref (top);
}
}
/* GObject - GLib Type, Object, Parameter and Signal Library
* Copyright (C) 2001, 2003 Red Hat, Inc.
*
* 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; either
* 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, see <http://www.gnu.org/licenses/>.
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestIfaceCheck"
#undef G_DISABLE_ASSERT
#undef G_DISABLE_CHECKS
#undef G_DISABLE_CAST_CHECKS
#include <string.h>
#include <glib-object.h>
#include "testcommon.h"
/* This test tests g_type_add_interface_check_func(), which allows
* installing a post-initialization check function.
*/
#define TEST_TYPE_IFACE (test_iface_get_type ())
#define TEST_IFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE, TestIfaceClass))
typedef struct _TestIfaceClass TestIfaceClass;
struct _TestIfaceClass
{
GTypeInterface base_iface;
GString *history;
};
static void
test_iface_base_init (TestIfaceClass *iface)
{
iface->history = g_string_new (iface->history ? iface->history->str : NULL);
}
static DEFINE_IFACE(TestIface, test_iface, test_iface_base_init, NULL)
/*
* TestObject1
*/
#define TEST_TYPE_OBJECT1 (test_object1_get_type ())
typedef struct _GObject TestObject1;
typedef struct _GObjectClass TestObject1Class;
static DEFINE_TYPE_FULL (TestObject1, test_object1,
NULL, NULL, NULL,
G_TYPE_OBJECT,
INTERFACE (NULL, TEST_TYPE_IFACE))
/*
* TestObject2
*/
#define TEST_TYPE_OBJECT2 (test_object2_get_type ())
typedef struct _GObject TestObject2;
typedef struct _GObjectClass TestObject2Class;
static DEFINE_TYPE_FULL (TestObject2, test_object2,
NULL, NULL, NULL,
G_TYPE_OBJECT,
INTERFACE (NULL, TEST_TYPE_IFACE))
/*
* TestObject3
*/
#define TEST_TYPE_OBJECT3 (test_object3_get_type ())
typedef struct _GObject TestObject3;
typedef struct _GObjectClass TestObject3Class;
static DEFINE_TYPE_FULL (TestObject3, test_object3,
NULL, NULL, NULL,
G_TYPE_OBJECT,
INTERFACE (NULL, TEST_TYPE_IFACE))
/*
* TestObject4
*/
#define TEST_TYPE_OBJECT4 (test_object4_get_type ())
typedef struct _GObject TestObject4;
typedef struct _GObjectClass TestObject4Class;
static DEFINE_TYPE_FULL (TestObject4, test_object4,
NULL, NULL, NULL,
G_TYPE_OBJECT, {})
static void
check_func (gpointer check_data,
gpointer g_iface)
{
TestIfaceClass *iface = g_iface;
g_string_append (iface->history, check_data);
}
int
main (int argc,
char *argv[])
{
TestIfaceClass *iface;
GObject *object;
char *string1 = "A";
char *string2 = "B";
/* Basic check of interfaces added before class_init time
*/
g_type_add_interface_check (string1, check_func);
object = g_object_new (TEST_TYPE_OBJECT1, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "A") == 0);
g_object_unref (object);
/* Add a second check function
*/
g_type_add_interface_check (string2, check_func);
object = g_object_new (TEST_TYPE_OBJECT2, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "AB") == 0);
g_object_unref (object);
/* Remove the first check function
*/
g_type_remove_interface_check (string1, check_func);
object = g_object_new (TEST_TYPE_OBJECT3, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "B") == 0);
g_object_unref (object);
/* Test interfaces added after class_init time
*/
g_type_class_ref (TEST_TYPE_OBJECT4);
{
GInterfaceInfo const iface = {
NULL, NULL, NULL
};
g_type_add_interface_static (TEST_TYPE_OBJECT4, TEST_TYPE_IFACE, &iface);
}
object = g_object_new (TEST_TYPE_OBJECT4, NULL);
iface = TEST_IFACE_GET_CLASS (object);
g_assert (strcmp (iface->history->str, "B") == 0);
g_object_unref (object);
return 0;
}
/* GObject - GLib Type, Object, Parameter and Signal Library
* Copyright (C) 2001, 2003 Red Hat, Inc.
*
* 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; either
* 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, see <http://www.gnu.org/licenses/>.
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestIfaceInherit"
#undef G_DISABLE_ASSERT
#undef G_DISABLE_CHECKS
#undef G_DISABLE_CAST_CHECKS
#include <glib-object.h>
#include "testcommon.h"
#include "testmodule.h"
/* This test tests inheritance of interface. We two object
* class BaseObject and DerivedObject we add an interface
* to BaseObject:
*
* I1) Before DerivedObject is registered
* I2) After DerivedObject is registered, but before
* DerivedObject is class initialized
* I3) During DerivedObject's class_init
* I4) After DerivedObject's class init
*
* We also do some tests of overriding.
*
* I5) We add an interface to BaseObject, then add the same
* interface to DerivedObject. (Note that this is only legal
* before DerivedObject's class_init; the results of
* g_type_interface_peek() are not allowed to change from one
* non-NULL vtable to another non-NULL vtable)
*/
/*
* BaseObject, a parent class for DerivedObject
*/
#define BASE_TYPE_OBJECT (base_object_get_type ())
typedef struct _BaseObject BaseObject;
typedef struct _BaseObjectClass BaseObjectClass;
struct _BaseObject
{
GObject parent_instance;
};
struct _BaseObjectClass
{
GObjectClass parent_class;
};
static GType base_object_get_type (void);
static GType derived_object_get_type (void);
/*
* DerivedObject, the child class of DerivedObject
*/
#define DERIVED_TYPE_OBJECT (derived_object_get_type ())
typedef struct _DerivedObject DerivedObject;
typedef struct _DerivedObjectClass DerivedObjectClass;
struct _DerivedObject
{
BaseObject parent_instance;
};
struct _DerivedObjectClass
{
BaseObjectClass parent_class;
};
/*
* The interfaces
*/
typedef struct _TestIfaceClass TestIfaceClass;
typedef struct _TestIfaceClass TestIface1Class;
typedef struct _TestIfaceClass TestIface2Class;
typedef struct _TestIfaceClass TestIface3Class;
typedef struct _TestIfaceClass TestIface4Class;
typedef struct _TestIfaceClass TestIface5Class;
struct _TestIfaceClass
{
GTypeInterface base_iface;
guint val;
};
static GType test_iface1_get_type (void);
static GType test_iface2_get_type (void);
static GType test_iface3_get_type (void);
static GType test_iface4_get_type (void);
static GType test_iface5_get_type (void);
#define TEST_TYPE_IFACE1 (test_iface1_get_type ())
#define TEST_TYPE_IFACE2 (test_iface2_get_type ())
#define TEST_TYPE_IFACE3 (test_iface3_get_type ())
#define TEST_TYPE_IFACE4 (test_iface4_get_type ())
#define TEST_TYPE_IFACE5 (test_iface5_get_type ())
static DEFINE_IFACE (TestIface1, test_iface1, NULL, NULL)
static DEFINE_IFACE (TestIface2, test_iface2, NULL, NULL)
static DEFINE_IFACE (TestIface3, test_iface3, NULL, NULL)
static DEFINE_IFACE (TestIface4, test_iface4, NULL, NULL)
static DEFINE_IFACE (TestIface5, test_iface5, NULL, NULL)
static void
add_interface (GType object_type,
GType iface_type,
GInterfaceInitFunc init_func)
{
GInterfaceInfo iface_info = { NULL, NULL, NULL };
iface_info.interface_init = init_func;
g_type_add_interface_static (object_type, iface_type, &iface_info);
}
static void
init_base_interface (TestIfaceClass *iface)
{
iface->val = 21;
}
static void
add_base_interface (GType object_type,
GType iface_type)
{
add_interface (object_type, iface_type,
(GInterfaceInitFunc)init_base_interface);
}
static gboolean
interface_is_base (GType object_type,
GType iface_type)
{
gpointer g_class = g_type_class_peek (object_type);
TestIfaceClass *iface = g_type_interface_peek (g_class, iface_type);
return iface && iface->val == 21;
}
static void
init_derived_interface (TestIfaceClass *iface)
{
iface->val = 42;
}
static void
add_derived_interface (GType object_type,
GType iface_type)
{
add_interface (object_type, iface_type,
(GInterfaceInitFunc)init_derived_interface);
}
static gboolean
interface_is_derived (GType object_type,
GType iface_type)
{
gpointer g_class = g_type_class_peek (object_type);
TestIfaceClass *iface = g_type_interface_peek (g_class, iface_type);
return iface && iface->val == 42;
}
static void
derived_object_class_init (BaseObjectClass *class)
{
add_base_interface (BASE_TYPE_OBJECT, TEST_TYPE_IFACE3);
}
static DEFINE_TYPE(BaseObject, base_object,
NULL, NULL, NULL,
G_TYPE_OBJECT)
static DEFINE_TYPE(DerivedObject, derived_object,
derived_object_class_init, NULL, NULL,
BASE_TYPE_OBJECT)
int
main (int argc,
char *argv[])
{
g_log_set_always_fatal (g_log_set_always_fatal (G_LOG_FATAL_MASK) |
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_CRITICAL);
/* Register BaseObject */
BASE_TYPE_OBJECT;
add_base_interface (BASE_TYPE_OBJECT, TEST_TYPE_IFACE5);
/* Class init BaseObject */
g_type_class_ref (BASE_TYPE_OBJECT);
add_base_interface (BASE_TYPE_OBJECT, TEST_TYPE_IFACE1);
/* Register DerivedObject */
DERIVED_TYPE_OBJECT;
add_base_interface (BASE_TYPE_OBJECT, TEST_TYPE_IFACE2);
add_derived_interface (DERIVED_TYPE_OBJECT, TEST_TYPE_IFACE5);
/* Class init DerivedObject */
g_type_class_ref (DERIVED_TYPE_OBJECT);
add_base_interface (BASE_TYPE_OBJECT, TEST_TYPE_IFACE4);
/* Check that all the non-overridden interfaces were properly inherited
*/
g_assert (interface_is_base (DERIVED_TYPE_OBJECT, TEST_TYPE_IFACE1));
g_assert (interface_is_base (DERIVED_TYPE_OBJECT, TEST_TYPE_IFACE2));
g_assert (interface_is_base (DERIVED_TYPE_OBJECT, TEST_TYPE_IFACE3));
g_assert (interface_is_base (DERIVED_TYPE_OBJECT, TEST_TYPE_IFACE4));
/* Check that all the overridden interfaces were properly overridden
*/
g_assert (interface_is_derived (DERIVED_TYPE_OBJECT, TEST_TYPE_IFACE5));
return 0;
}
/* GObject - GLib Type, Object, Parameter and Signal Library
* Copyright (C) 2001, 2003 Red Hat, Inc.
*
* 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; either
* 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, see <http://www.gnu.org/licenses/>.
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "TestIfaceInit"
#undef G_DISABLE_ASSERT
#undef G_DISABLE_CHECKS
#undef G_DISABLE_CAST_CHECKS
#include <glib-object.h>
#include "testcommon.h"
/* What this test tests is the ability to add interfaces dynamically; in
* particular adding interfaces to a class while that class is being
* initialized.
*
* The test defines 5 interfaces:
*
* - TestIface1 is added before the class is initialized
* - TestIface2 is added in base_object_base_init()
* - TestIface3 is added in test_iface1_base_init()
* - TestIface4 is added in test_object_class_init()
* - TestIface5 is added in test_object_test_iface1_init()
* - TestIface6 is added after the class is initialized
*/
/* All 6 interfaces actually share the same class structure, though
* we use separate typedefs
*/
typedef struct _TestIfaceClass TestIfaceClass;
struct _TestIfaceClass
{
GTypeInterface base_iface;
guint val;
guint base_val;
guint default_val;
};
#define TEST_TYPE_IFACE1 (test_iface1_get_type ())
#define TEST_IFACE1_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE1, TestIface1Class))
typedef struct _TestIface1 TestIface1;
typedef struct _TestIfaceClass TestIface1Class;
static void test_iface1_base_init (TestIface1Class *iface);
static void test_iface1_default_init (TestIface1Class *iface, gpointer class_data);
static DEFINE_IFACE(TestIface1, test_iface1, test_iface1_base_init, test_iface1_default_init)
#define TEST_TYPE_IFACE2 (test_iface2_get_type ())
#define TEST_IFACE2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE2, TestIface2Class))
typedef struct _TestIface2 TestIface2;
typedef struct _TestIfaceClass TestIface2Class;
static void test_iface2_base_init (TestIface2Class *iface);
static DEFINE_IFACE(TestIface2, test_iface2, test_iface2_base_init, NULL)
#define TEST_TYPE_IFACE3 (test_iface3_get_type ())
#define TEST_IFACE3_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE3, TestIface3Class))
typedef struct _TestIface3 TestIface3;
typedef struct _TestIfaceClass TestIface3Class;
static void test_iface3_base_init (TestIface3Class *iface);
static DEFINE_IFACE(TestIface3, test_iface3, test_iface3_base_init, NULL)
#define TEST_TYPE_IFACE4 (test_iface4_get_type ())
#define TEST_IFACE4_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE4, TestIface4Class))
typedef struct _TestIface4 TestIface4;
typedef struct _TestIfaceClass TestIface4Class;
static void test_iface4_base_init (TestIface4Class *iface);
static DEFINE_IFACE(TestIface4, test_iface4, test_iface4_base_init, NULL)
#define TEST_TYPE_IFACE5 (test_iface5_get_type ())
#define TEST_IFACE5_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE5, TestIface5Class))
typedef struct _TestIface5 TestIface5;
typedef struct _TestIfaceClass TestIface5Class;
static void test_iface5_base_init (TestIface5Class *iface);
static DEFINE_IFACE(TestIface5, test_iface5, test_iface5_base_init, NULL)
#define TEST_TYPE_IFACE6 (test_iface6_get_type ())
#define TEST_IFACE6_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE6, TestIface6Class))
typedef struct _TestIface6 TestIface6;
typedef struct _TestIfaceClass TestIface6Class;
static void test_iface6_base_init (TestIface6Class *iface);
static DEFINE_IFACE(TestIface6, test_iface6, test_iface6_base_init, NULL)
/*
* BaseObject, a parent class for TestObject
*/
#define BASE_TYPE_OBJECT (base_object_get_type ())
typedef struct _BaseObject BaseObject;
typedef struct _BaseObjectClass BaseObjectClass;
struct _BaseObject
{
GObject parent_instance;
};
struct _BaseObjectClass