コード例 #1
0
ファイル: test_layerapi2.c プロジェクト: frdcms/mfext
void test_lines_to_gslist()
{
    gchar *content = read_file_in_directory("./tests", "lines");
    GSList *list = lines_to_gslist(content);
    GSList *list_iterator;
    g_free(content);
    gchar *data = (gchar*) list->data;
    g_assert_cmpstr(data, ==, "foo");
    list_iterator = list->next;
    data = (gchar*) list_iterator->data;
    g_assert_cmpstr(data, ==, "bar");
    list_iterator = list_iterator->next;
    data = (gchar*) list_iterator->data;
    g_assert_cmpstr(data, ==, "foo2");
    list_iterator = list_iterator->next;
    g_assert_null(list_iterator);
    g_slist_free_full(list, g_free);
}
コード例 #2
0
ファイル: test_layerapi2.c プロジェクト: frdcms/mfext
void test_field_prepend_special()
{
    gchar *res1 = field_prepend("", "foo", ":");
    g_assert_cmpstr(res1, ==, "foo");
    g_free(res1);
    gchar *res2 = field_prepend(NULL, "foo", ":");
    g_assert_cmpstr(res2, ==, "foo");
    g_free(res2);
    gchar *res3 = field_prepend("foo:bar", "", ":");
    g_assert_cmpstr(res3, ==, "foo:bar");
    g_free(res3);
    gchar *res4 = field_prepend("foo:bar", NULL, ":");
    g_assert_cmpstr(res4, ==, "foo:bar");
    g_free(res4);
    gchar *res5 = field_prepend(NULL, NULL, ":");
    g_assert_null(res5);
    g_free(res5);
}
コード例 #3
0
ファイル: test-blockjob.c プロジェクト: JunaidLoonat/qemu
static BlockJob *do_test_id(BlockBackend *blk, const char *id,
                            bool should_succeed)
{
    BlockJob *job;
    Error *errp = NULL;

    job = block_job_create(id, &test_block_job_driver, blk_bs(blk),
                           0, BLK_PERM_ALL, 0, BLOCK_JOB_DEFAULT, block_job_cb,
                           NULL, &errp);
    if (should_succeed) {
        g_assert_null(errp);
        g_assert_nonnull(job);
        if (id) {
            g_assert_cmpstr(job->id, ==, id);
        } else {
            g_assert_cmpstr(job->id, ==, blk_name(blk));
        }
    } else {
コード例 #4
0
ファイル: test_layerapi2.c プロジェクト: frdcms/mfext
void test_field_remove_special()
{
    gchar *res1 = field_remove("", "foo", ":", FALSE);
    g_assert_cmpstr(res1, ==, "");
    g_free(res1);
    gchar *res2 = field_remove(NULL, "foo", ":", FALSE);
    g_assert_cmpstr(res2, ==, NULL);
    g_free(res2);
    gchar *res3 = field_remove("foo:bar", "", ":", FALSE);
    g_assert_cmpstr(res3, ==, "foo:bar");
    g_free(res3);
    gchar *res4 = field_remove("foo:bar", NULL, ":", FALSE);
    g_assert_cmpstr(res4, ==, "foo:bar");
    g_free(res4);
    gchar *res5 = field_remove(NULL, NULL, ":", FALSE);
    g_assert_null(res5);
    g_free(res5);
}
コード例 #5
0
ファイル: test-connection.c プロジェクト: vicamo/libgaril
static void
check_stream_address_flags (GarilConnection *connection,
                            GIOStream       *expected_stream,
                            GSocketAddress  *expected_address)
{
  GIOStream *stream = garil_connection_get_stream (connection);
  g_assert_true (G_IS_IO_STREAM (stream));
  if (expected_stream != NULL)
    g_assert_true (stream == expected_stream);

  GSocketAddress *address = garil_connection_get_address (connection);
  if (expected_address != NULL)
    g_assert_true (address == expected_address);
  else
    g_assert_null (address);

  GarilConnectionFlags flags = garil_connection_get_flags (connection);
  g_assert_true (flags == GARIL_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING);
}
コード例 #6
0
ファイル: test-connection.c プロジェクト: vicamo/libgaril
static void
check_new (GAsyncResult    *res,
           GError         **expected_error,
           GIOStream       *expected_stream,
           GSocketAddress  *expected_address)
{
  GarilConnection *connection =
    garil_connection_new_finish (res, expected_error);
  if (expected_error != NULL) {
    g_assert_null (connection);
    g_assert_nonnull (*expected_error);
    return;
  }

  g_assert_true (GARIL_IS_CONNECTION (connection));

  check_stream_address_flags (connection, expected_stream, expected_address);

  g_object_unref (connection);
}
コード例 #7
0
static void test_parse_mountinfo_entry__snapd_mnt()
{
	const char *line =
	    "256 104 0:3 mnt:[4026532509] /run/snapd/ns/hello-world.mnt rw - nsfs nsfs rw";
	struct mountinfo_entry *entry = parse_mountinfo_entry(line);
	g_assert_nonnull(entry);
	g_test_queue_destroy((GDestroyNotify) free_mountinfo_entry, entry);
	g_assert_cmpint(entry->mount_id, ==, 256);
	g_assert_cmpint(entry->parent_id, ==, 104);
	g_assert_cmpint(entry->dev_major, ==, 0);
	g_assert_cmpint(entry->dev_minor, ==, 3);
	g_assert_cmpstr(entry->root, ==, "mnt:[4026532509]");
	g_assert_cmpstr(entry->mount_dir, ==, "/run/snapd/ns/hello-world.mnt");
	g_assert_cmpstr(entry->mount_opts, ==, "rw");
	g_assert_cmpstr(entry->optional_fields, ==, "");
	g_assert_cmpstr(entry->fs_type, ==, "nsfs");
	g_assert_cmpstr(entry->mount_source, ==, "nsfs");
	g_assert_cmpstr(entry->super_opts, ==, "rw");
	g_assert_null(entry->next);
}
コード例 #8
0
static void test_parse_mountinfo_entry__no_tags()
{
	const char *line =
	    "1 2 3:4 root mount-dir mount-opts - fs-type mount-source super-opts";
	struct mountinfo_entry *entry = parse_mountinfo_entry(line);
	g_assert_nonnull(entry);
	g_test_queue_destroy((GDestroyNotify) free_mountinfo_entry, entry);
	g_assert_cmpint(entry->mount_id, ==, 1);
	g_assert_cmpint(entry->parent_id, ==, 2);
	g_assert_cmpint(entry->dev_major, ==, 3);
	g_assert_cmpint(entry->dev_minor, ==, 4);
	g_assert_cmpstr(entry->root, ==, "root");
	g_assert_cmpstr(entry->mount_dir, ==, "mount-dir");
	g_assert_cmpstr(entry->mount_opts, ==, "mount-opts");
	g_assert_cmpstr(entry->optional_fields, ==, "");
	g_assert_cmpstr(entry->fs_type, ==, "fs-type");
	g_assert_cmpstr(entry->mount_source, ==, "mount-source");
	g_assert_cmpstr(entry->super_opts, ==, "super-opts");
	g_assert_null(entry->next);
}
コード例 #9
0
ファイル: no-ssl-test.c プロジェクト: Distrotech/libsoup
static void
do_ssl_test_for_session (SoupSession *session, SoupURI *uri)
{
	SoupMessage *msg;
	GTlsCertificate *cert = NULL;
	GTlsCertificateFlags flags;
	gboolean is_https;

	msg = soup_message_new_from_uri ("GET", uri);
	soup_session_send_message (session, msg);
	soup_test_assert_message_status (msg, SOUP_STATUS_SSL_FAILED);

	is_https = soup_message_get_https_status (msg, &cert, &flags);
	soup_test_assert (!is_https, "get_http_status() returned TRUE? (flags %x)", flags);

	g_assert_null (cert);
	g_assert_false (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED);

	g_object_unref (msg);
}
コード例 #10
0
// Parse the /run/snapd/ns bind mount (over itself)
// Note that /run is itself a tmpfs mount point.
static void test_parse_mountinfo_entry__snapd_ns()
{
	const char *line =
	    "104 23 0:19 /snapd/ns /run/snapd/ns rw,nosuid,noexec,relatime - tmpfs tmpfs rw,size=99840k,mode=755";
	struct mountinfo_entry *entry = parse_mountinfo_entry(line);
	g_assert_nonnull(entry);
	g_test_queue_destroy((GDestroyNotify) free_mountinfo_entry, entry);
	g_assert_cmpint(entry->mount_id, ==, 104);
	g_assert_cmpint(entry->parent_id, ==, 23);
	g_assert_cmpint(entry->dev_major, ==, 0);
	g_assert_cmpint(entry->dev_minor, ==, 19);
	g_assert_cmpstr(entry->root, ==, "/snapd/ns");
	g_assert_cmpstr(entry->mount_dir, ==, "/run/snapd/ns");
	g_assert_cmpstr(entry->mount_opts, ==, "rw,nosuid,noexec,relatime");
	g_assert_cmpstr(entry->optional_fields, ==, "");
	g_assert_cmpstr(entry->fs_type, ==, "tmpfs");
	g_assert_cmpstr(entry->mount_source, ==, "tmpfs");
	g_assert_cmpstr(entry->super_opts, ==, "rw,size=99840k,mode=755");
	g_assert_null(entry->next);
}
コード例 #11
0
ファイル: check-qom-proplist.c プロジェクト: CTU-IIG/qemu
static void test_dummy_createcmdl(void)
{
    QemuOpts *opts;
    DummyObject *dobj;
    Error *err = NULL;
    const char *params = TYPE_DUMMY \
                         ",id=dev0," \
                         "bv=yes,sv=Hiss hiss hiss,av=platypus";

    qemu_add_opts(&qemu_object_opts);
    opts = qemu_opts_parse(&qemu_object_opts, params, true, &err);
    g_assert(err == NULL);
    g_assert(opts);

    dobj = DUMMY_OBJECT(user_creatable_add_opts(opts, &err));
    g_assert(err == NULL);
    g_assert(dobj);
    g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss");
    g_assert(dobj->bv == true);
    g_assert(dobj->av == DUMMY_PLATYPUS);

    user_creatable_del("dev0", &err);
    g_assert(err == NULL);
    error_free(err);

    object_unref(OBJECT(dobj));

    /*
     * cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry
     * corresponding to the Object's ID to be added to the QemuOptsList
     * for objects. To avoid having this entry conflict with future
     * Objects using the same ID (which can happen in cases where
     * qemu_opts_parse() is used to parse the object params, such as
     * with hmp_object_add() at the time of this comment), we need to
     * check for this in user_creatable_del() and remove the QemuOpts if
     * it is present.
     *
     * The below check ensures this works as expected.
     */
    g_assert_null(qemu_opts_find(&qemu_object_opts, "dev0"));
}
コード例 #12
0
static void test_parse_mountinfo_entry__sysfs()
{
	const char *line =
	    "19 25 0:18 / /sys rw,nosuid,nodev,noexec,relatime shared:7 - sysfs sysfs rw";
	struct mountinfo_entry *entry = parse_mountinfo_entry(line);
	g_assert_nonnull(entry);
	g_test_queue_destroy((GDestroyNotify) free_mountinfo_entry, entry);
	g_assert_cmpint(entry->mount_id, ==, 19);
	g_assert_cmpint(entry->parent_id, ==, 25);
	g_assert_cmpint(entry->dev_major, ==, 0);
	g_assert_cmpint(entry->dev_minor, ==, 18);
	g_assert_cmpstr(entry->root, ==, "/");
	g_assert_cmpstr(entry->mount_dir, ==, "/sys");
	g_assert_cmpstr(entry->mount_opts, ==,
			"rw,nosuid,nodev,noexec,relatime");
	g_assert_cmpstr(entry->optional_fields, ==, "shared:7");
	g_assert_cmpstr(entry->fs_type, ==, "sysfs");
	g_assert_cmpstr(entry->mount_source, ==, "sysfs");
	g_assert_cmpstr(entry->super_opts, ==, "rw");
	g_assert_null(entry->next);
}
コード例 #13
0
ファイル: test_dir.c プロジェクト: GuillaumeDelaporte/oio-sds
static void
_test_reference_cycle_round (void)
{
	GError *err = NULL;

	struct oio_url_s *url = oio_url_empty ();
	_random_url (url);

	struct oio_directory_s *dir = oio_directory__create_proxy (ns);
	g_assert_nonnull (dir);

	/* link with no reference */
	gchar **srvtab = NULL;
	err = oio_directory__link (dir, url, NAME_SRVTYPE_META2, FALSE, &srvtab);
	g_assert_error (err, GQ(), CODE_USER_NOTFOUND);
	g_assert_null (srvtab);
	g_clear_error (&err);

	/* create */
	err = oio_directory__create (dir, url);
	g_assert_no_error (err);

	/* link with a reference */
	err = oio_directory__link (dir, url, NAME_SRVTYPE_META2, FALSE, &srvtab);
	g_assert_no_error (err);
	g_assert_nonnull (srvtab);
	g_strfreev (srvtab);

	/* list */
	gchar **dirtab = NULL;
	err = oio_directory__list (dir, url, NAME_SRVTYPE_META2, &dirtab, &srvtab);
	g_assert_no_error (err);
	g_assert_nonnull (dirtab);
	g_assert_nonnull (srvtab);
	g_strfreev (dirtab);
	g_strfreev (srvtab);

	oio_url_pclean (&url);
	oio_directory__destroy (dir);
}
コード例 #14
0
static void
gst_ah_sensor_sensor_sizes_init (void)
{
  gint i;
  static struct
  {
    gint type;
    gsize size;
  } types[] = {
    {AHS_SENSOR_TYPE_ACCELEROMETER, sizeof (GstAHSAccelerometerValues)},
    {AHS_SENSOR_TYPE_AMBIENT_TEMPERATURE, sizeof (GstAHSAmbientTemperatureValues)},
    {AHS_SENSOR_TYPE_GAME_ROTATION_VECTOR, sizeof (GstAHSGameRotationVectorValues)},
    {AHS_SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR, sizeof (GstAHSGeomagneticRotationVectorValues)},
    {AHS_SENSOR_TYPE_GRAVITY, sizeof (GstAHSGravityValues)},
    {AHS_SENSOR_TYPE_GYROSCOPE, sizeof (GstAHSGyroscopeValues)},
    {AHS_SENSOR_TYPE_GYROSCOPE_UNCALIBRATED, sizeof (GstAHSGyroscopeUncalibratedValues)},
    {AHS_SENSOR_TYPE_HEART_RATE, sizeof (GstAHSHeartRateValues)},
    {AHS_SENSOR_TYPE_LIGHT, sizeof (GstAHSLightValues)},
    {AHS_SENSOR_TYPE_LINEAR_ACCELERATION, sizeof (GstAHSLinearAccelerationValues)},
    {AHS_SENSOR_TYPE_MAGNETIC_FIELD, sizeof (GstAHSMagneticFieldValues)},
    {AHS_SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, sizeof (GstAHSMagneticFieldUncalibratedValues)},
    {AHS_SENSOR_TYPE_ORIENTATION, sizeof (GstAHSOrientationValues)},
    {AHS_SENSOR_TYPE_PRESSURE, sizeof (GstAHSPressureValues)},
    {AHS_SENSOR_TYPE_PROXIMITY, sizeof (GstAHSProximityValues)},
    {AHS_SENSOR_TYPE_RELATIVE_HUMIDITY, sizeof (GstAHSRelativeHumidityValues)},
    {AHS_SENSOR_TYPE_ROTATION_VECTOR, sizeof (GstAHSRotationVectorValues)},
    {AHS_SENSOR_TYPE_STEP_COUNTER, sizeof (GstAHSStepCounterValues)},
    {AHS_SENSOR_TYPE_STEP_DETECTOR, sizeof (GstAHSStepDetectorValues)},
  };

  g_assert_null (sensor_sizes);

  sensor_sizes = g_hash_table_new (g_int_hash, g_int_equal);
  for (i = 0; i < G_N_ELEMENTS (types); i++)
    g_hash_table_insert (sensor_sizes, &types[i].type, &types[i].size);
}
コード例 #15
0
static void
test_resolve_metrolyrics_bad_request (void)
{
  GrlSource *source;
  guint i;

  struct {
    gchar *title;
    gchar *artist;
    gchar *lyrics_file;
  } audios[] = {
   { "GNOME", "grilo framework", NULL },
  };

  source = test_lua_factory_get_source (METROLYRICS_ID, METROLYRICS_OPS);

  for (i = 0; i < G_N_ELEMENTS (audios); i++) {
    gchar *lyrics;

    g_test_expect_message("Grilo", G_LOG_LEVEL_WARNING, "*Can't fetch element*");
    lyrics = get_lyrics (source, audios[i].artist, audios[i].title);
    g_assert_null (lyrics);
  }
}
コード例 #16
0
static void
photos_thumbnailer_generate_thumbnail_process (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  g_autoptr (GFile) thumbnail_file = NULL;
  g_autoptr (GTask) task = G_TASK (user_data);
  GeglNode *pipeline_node;
  GeglProcessor *processor = GEGL_PROCESSOR (source_object);
  PhotosThumbnailerGenerateData *data;
  g_autofree gchar *thumbnail_dir = NULL;
  gdouble zoom = 0.0;
  gint pixbuf_height;
  gint pixbuf_width;
  gint pixbuf_zoomed_height;
  gint pixbuf_zoomed_width;

  cancellable = g_task_get_cancellable (task);
  data = g_task_get_task_data (task);

  {
    g_autoptr (GError) error = NULL;

    if (!photos_gegl_processor_process_finish (processor, res, &error))
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_assert_null (data->pixbuf_thumbnail);

  pipeline_node = photos_pipeline_get_graph (data->pipeline);
  data->pixbuf_thumbnail = photos_gegl_create_pixbuf_from_node (pipeline_node);
  pixbuf_height = gdk_pixbuf_get_height (data->pixbuf_thumbnail);
  pixbuf_width = gdk_pixbuf_get_width (data->pixbuf_thumbnail);

  if (pixbuf_height > pixbuf_width && pixbuf_height > data->thumbnail_size)
    {
      zoom = (gdouble) data->thumbnail_size / (gdouble) pixbuf_height;
      pixbuf_zoomed_height = data->thumbnail_size;
      pixbuf_zoomed_width = (gint) (zoom * (gdouble) pixbuf_width + 0.5);
    }
  else if (pixbuf_height <= pixbuf_width && pixbuf_width > data->thumbnail_size)
    {
      zoom = (gdouble) data->thumbnail_size / (gdouble) pixbuf_width;
      pixbuf_zoomed_height = (gint) (zoom * (gdouble) pixbuf_height + 0.5);
      pixbuf_zoomed_width = data->thumbnail_size;
    }

  if (zoom > 0.0)
    {
      g_autoptr (GdkPixbuf) pixbuf_scaled = NULL;

      photos_debug (PHOTOS_DEBUG_THUMBNAILER,
                    "Scaling thumbnail to %d×%d",
                    pixbuf_zoomed_width,
                    pixbuf_zoomed_height);

      pixbuf_scaled = gdk_pixbuf_scale_simple (data->pixbuf_thumbnail,
                                               pixbuf_zoomed_width,
                                               pixbuf_zoomed_height,
                                               GDK_INTERP_BILINEAR);

      g_set_object (&data->pixbuf_thumbnail, pixbuf_scaled);
    }

  thumbnail_dir = g_path_get_dirname (data->thumbnail_path);
  g_mkdir_with_parents (thumbnail_dir, 0700);

  thumbnail_file = g_file_new_for_path (data->thumbnail_path);

  photos_debug (PHOTOS_DEBUG_THUMBNAILER, "Saving thumbnail to %s", data->thumbnail_path);
  g_file_replace_async (thumbnail_file,
                        NULL,
                        FALSE,
                        G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION,
                        G_PRIORITY_DEFAULT,
                        cancellable,
                        photos_thumbnailer_generate_thumbnail_replace,
                        g_object_ref (task));

 out:
  return;
}
コード例 #17
0
ファイル: test-container.c プロジェクト: bert/adg
static void
_adg_property_child(void)
{
    AdgContainer *container;
    AdgEntity *valid_entity, *invalid_entity;
    GSList *children;

    container = adg_container_new();
    valid_entity = ADG_ENTITY(adg_logo_new());
    invalid_entity = adg_test_invalid_pointer();

    /* Keep alive the entity between all the tests */
    g_object_ref(valid_entity);

    /* Using the public APIs */
    adg_container_add(container, NULL);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_container_add(container, invalid_entity);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_container_add(container, valid_entity);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_true(children->data == valid_entity);
    g_slist_free(children);

    adg_container_remove(container, invalid_entity);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_true(children->data == valid_entity);
    g_slist_free(children);

    adg_container_remove(container, valid_entity);
    children = adg_container_children(container);
    g_assert_null(children);

    /* Using GObject property methods */
    g_object_set(container, "child", NULL, NULL);
    children = adg_container_children(container);
    g_assert_null(children);

    g_object_set(container, "child", invalid_entity, NULL);
    children = adg_container_children(container);
    g_assert_null(children);

    g_object_set(container, "child", valid_entity, NULL);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_true(children->data == valid_entity);
    g_slist_free(children);

    adg_container_remove(container, valid_entity);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_entity_destroy(ADG_ENTITY(container));
    adg_entity_destroy(valid_entity);
}
コード例 #18
0
void testHandleNotCreatedMode(handleFixture *fixture, gconstpointer ignored) {
    (void)ignored;
    g_assert_null(fixture->handle);
}
コード例 #19
0
void testHandleNotCreatedVersion(handleFixture *fixture, gconstpointer ignored) {
    // This test has to be run with setupUnsupportedApiVersion
    (void)ignored;
    g_assert_null(fixture->handle);
}
コード例 #20
0
ファイル: snap-test.c プロジェクト: matiasb/snappy
static void test_sc_snap_name_validate()
{
	struct sc_error *err = NULL;

	// Smoke test, a valid snap name
	sc_snap_name_validate("hello-world", &err);
	g_assert_null(err);

	// Smoke test: invalid character 
	sc_snap_name_validate("hello world", &err);
	g_assert_nonnull(err);
	g_assert_true(sc_error_match
		      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
	g_assert_cmpstr(sc_error_msg(err), ==,
			"snap name must use lower case letters, digits or dashes");
	sc_error_free(err);

	// Smoke test: no letters
	sc_snap_name_validate("", &err);
	g_assert_nonnull(err);
	g_assert_true(sc_error_match
		      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
	g_assert_cmpstr(sc_error_msg(err), ==,
			"snap name must contain at least one letter");
	sc_error_free(err);

	// Smoke test: leading dash
	sc_snap_name_validate("-foo", &err);
	g_assert_nonnull(err);
	g_assert_true(sc_error_match
		      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
	g_assert_cmpstr(sc_error_msg(err), ==,
			"snap name cannot start with a dash");
	sc_error_free(err);

	// Smoke test: trailing dash
	sc_snap_name_validate("foo-", &err);
	g_assert_nonnull(err);
	g_assert_true(sc_error_match
		      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
	g_assert_cmpstr(sc_error_msg(err), ==,
			"snap name cannot end with a dash");
	sc_error_free(err);

	// Smoke test: double dash
	sc_snap_name_validate("f--oo", &err);
	g_assert_nonnull(err);
	g_assert_true(sc_error_match
		      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
	g_assert_cmpstr(sc_error_msg(err), ==,
			"snap name cannot contain two consecutive dashes");
	sc_error_free(err);

	// Smoke test: NULL name is not valid
	sc_snap_name_validate(NULL, &err);
	g_assert_nonnull(err);
	g_assert_true(sc_error_match
		      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
	g_assert_cmpstr(sc_error_msg(err), ==, "snap name cannot be NULL");
	sc_error_free(err);

	const char *valid_names[] = {
		"a", "aa", "aaa", "aaaa",
		"a-a", "aa-a", "a-aa", "a-b-c",
		"a0", "a-0", "a-0a",
		"01game", "1-or-2"
	};
	for (int i = 0; i < sizeof valid_names / sizeof *valid_names; ++i) {
		g_test_message("checking valid snap name: %s", valid_names[i]);
		sc_snap_name_validate(valid_names[i], &err);
		g_assert_null(err);
	}
	const char *invalid_names[] = {
		// name cannot be empty
		"",
		// dashes alone are not a name
		"-", "--",
		// double dashes in a name are not allowed
		"a--a",
		// name should not end with a dash
		"a-",
		// name cannot have any spaces in it
		"a ", " a", "a a",
		// a number alone is not a name
		"0", "123",
		// identifier must be plain ASCII
		"日本語", "한글", "ру́сский язы́к",
	};
	for (int i = 0; i < sizeof invalid_names / sizeof *invalid_names; ++i) {
		g_test_message("checking invalid snap name: >%s<",
			       invalid_names[i]);
		sc_snap_name_validate(invalid_names[i], &err);
		g_assert_nonnull(err);
		g_assert_true(sc_error_match
			      (err, SC_SNAP_DOMAIN, SC_SNAP_INVALID_NAME));
		sc_error_free(err);
	}
	// Regression test: 12to8 and 123test
	sc_snap_name_validate("12to8", &err);
	g_assert_null(err);
	sc_snap_name_validate("123test", &err);
	g_assert_null(err);

}
コード例 #21
0
static void test_foobar_null()
{
    const char *type = guess_content_type("foo.wombat");
    g_assert_null(type);
}
コード例 #22
0
static void
photos_thumbnailer_generate_thumbnail_pipeline (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  g_autoptr (GTask) task = G_TASK (user_data);
  g_autoptr (PhotosPipeline) pipeline = NULL;
  PhotosThumbnailerGenerateData *data;
  gboolean has_crop;
  g_autofree gchar *path = NULL;
  g_autofree gchar *uri = NULL;
  gdouble height;
  gdouble width;
  gdouble x;
  gdouble y;
  gint load_height;
  gint load_width;

  cancellable = g_task_get_cancellable (task);
  data = g_task_get_task_data (task);

  {
    g_autoptr (GError) error = NULL;

    pipeline = photos_pipeline_new_finish (res, &error);
    if (error != NULL)
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_assert_null (data->pipeline);
  data->pipeline = g_object_ref (pipeline);

  uri = g_file_get_uri (data->file);

  has_crop = photos_pipeline_get (pipeline,
                                  "gegl:crop",
                                  "height", &height,
                                  "width", &width,
                                  "x", &x,
                                  "y", &y,
                                  NULL);
  if (has_crop)
    {
      if (height < 0.0 || width < 0.0 || x < 0.0 || y < 0.0)
        {
          g_warning ("Unable to crop the thumbnail for %s: Invalid parameters", uri);

          photos_pipeline_remove (pipeline, "gegl:crop");
          has_crop = FALSE;
        }
    }

  if (has_crop
      || (0 < data->original_height
          && data->original_height < data->thumbnail_size
          && 0 < data->original_width
          && data->original_width < data->thumbnail_size))
    {
      load_height = (gint) data->original_height;
      load_width = (gint) data->original_width;
    }
  else
    {
      load_height = data->thumbnail_size;
      load_width = data->thumbnail_size;
    }

  path = g_file_get_path (data->file);
  if (!g_file_is_native (data->file))
    photos_debug (PHOTOS_DEBUG_NETWORK, "Downloading %s (%s)", uri, path);

  photos_debug (PHOTOS_DEBUG_THUMBNAILER, "Loading %s at %d×%d", uri, load_width, load_height);
  photos_pixbuf_new_from_file_at_size_async (path,
                                             load_width,
                                             load_height,
                                             cancellable,
                                             photos_thumbnailer_generate_thumbnail_pixbuf,
                                             g_object_ref (task));

 out:
  return;
}
コード例 #23
0
ファイル: test-read-xmsa.c プロジェクト: tschoonj/xmimsim
int main(int argc, char *argv[]) {
	xmi_archive *archive = NULL;
	xmi_archive *archive_copy = NULL;
	int i,j;

	//init test
	g_assert(test_init() == 1);

	//download file
	g_assert(test_download_file(TEST_XMSA_URL_1) == 1);

	//read the file
	g_assert_nonnull(archive = xmi_archive_read_from_xml_file(TEST_XMSA_1, NULL));

	//some testing of the input and output
	for (i = 0 ; i <= archive->nsteps1 ; i++) {
		for (j = 0 ; j <= archive->nsteps2 ; j++) {
			xmi_output *output_copy = NULL;
			xmi_output_copy(archive->output[i][j], &output_copy);
			g_assert(xmi_input_validate(output_copy->input) == 0);
			g_assert(xmi_input_compare(archive->input[i][j], output_copy->input) == 0);
			xmi_output_free(output_copy);
		}
	}

	//make a copy
	xmi_archive_copy(archive, &archive_copy);
	g_assert_true(xmi_archive_equals(archive, archive_copy));
	xmi_archive_free(archive);
	xmi_archive_free(archive_copy);

	//download file
	g_assert(test_download_file(TEST_XMSA_URL_2) == 1);

	//read the file
	g_assert_nonnull(archive = xmi_archive_read_from_xml_file(TEST_XMSA_2, NULL));

	//some testing of the input and output
	for (i = 0 ; i <= archive->nsteps1 ; i++) {
		for (j = 0 ; j <= archive->nsteps2 ; j++) {
			xmi_output *output_copy = NULL;
			xmi_output_copy(archive->output[i][j], &output_copy);
			g_assert(xmi_input_validate(output_copy->input) == 0);
			g_assert(xmi_input_compare(archive->input[i][j], output_copy->input) == 0);
			xmi_output_free(output_copy);
		}
	}

	//make a copy
	xmi_archive_copy(archive, &archive_copy);
	g_assert_true(xmi_archive_equals(archive, archive_copy));
	xmi_archive_free(archive);
	xmi_archive_free(archive_copy);

	// now some tests that are supposed to fail
	GError *error = NULL;
	g_assert_null(archive = xmi_archive_read_from_xml_file("non-existent-file.xmsa", &error));
	g_assert_true(g_error_matches(error, XMI_MSIM_ERROR, XMI_MSIM_ERROR_XML));
	fprintf(stdout, "message: %s\n", error->message);
	g_clear_error(&error);

	// bad xpath1 test: enable when implemented
	/*g_assert(replace_xml_tag(TEST_XMSA_1, TEST_XMSA_COPY_1, "/xmimsim-archive/xpath1", "hsdhodhoosda") == 1);
	g_assert(xmi_read_archive_xml(TEST_XMSA_COPY_1, &archive, &error) == 0);
	g_assert_true(g_error_matches(error, XMI_MSIM_ERROR, XMI_MSIM_ERROR_XML));
	fprintf(stdout, "message: %s\n", error->message);
	g_clear_error(&error);
	unlink(TEST_XMSA_COPY_1);*/

	g_assert(remove_xml_tags(TEST_XMSA_1, TEST_XMSA_COPY_1, "/xmimsim-archive/end_value1") == 1);
	g_assert_null(archive = xmi_archive_read_from_xml_file(TEST_XMSA_COPY_1, &error));
	g_assert_true(g_error_matches(error, XMI_MSIM_ERROR, XMI_MSIM_ERROR_XML));
	fprintf(stdout, "message: %s\n", error->message);
	g_clear_error(&error);
	unlink(TEST_XMSA_COPY_1);
	return 0;
}
コード例 #24
0
static void
_adg_behavior_named_pair(void)
{
    CpmlPair p1 = { 123, 456 };
    AdgPoint *explicit_point, *explicit_point2, *model_point;
    AdgModel *model;
    CpmlPair *pair;

    explicit_point = adg_point_new();
    g_assert_nonnull(explicit_point);
    adg_point_set_pair(explicit_point, &p1);

    explicit_point2 = adg_point_new();
    g_assert_nonnull(explicit_point2);
    adg_point_set_pair_explicit(explicit_point2, p1.x, p1.y);

    /* Checking comparison APIs */
    g_assert_true(adg_point_equal(explicit_point, explicit_point2));
    adg_point_set_pair_explicit(explicit_point2, 78, 90);
    g_assert_false(adg_point_equal(explicit_point, explicit_point2));
    pair = (CpmlPair *) explicit_point2;
    adg_assert_isapprox(pair->x, 78);
    adg_assert_isapprox(pair->y, 90);

    pair = adg_point_get_pair(explicit_point);
    g_assert_true(cpml_pair_equal(pair, &p1));
    g_free(pair);

    model = ADG_MODEL(adg_path_new());
    g_assert_nonnull(model);
    adg_model_set_named_pair(model, "named-pair", &p1);

    model_point = adg_point_new();
    g_assert_nonnull(model_point);
    adg_point_set_pair_from_model(model_point, model, "named-pair");

    pair = adg_point_get_pair(model_point);
    g_assert_true(cpml_pair_equal(pair, &p1));
    g_free(pair);

    /* Ensure ADG does not consider an explicit point equals to
     * a point bound to a named pair with the same coordinates */
    g_assert_false(adg_point_equal(explicit_point, model_point));

    /* Check for lazy evaluation of named pairs */
    adg_point_set_pair_from_model(model_point, model, "unexistent-pair");
    pair = (CpmlPair *) model_point;
    adg_assert_isapprox(pair->x, p1.x);
    adg_assert_isapprox(pair->y, p1.y);

    /* Check behavior on undefined named pair */
    g_assert_false(adg_point_update(model_point));
    g_assert_null(adg_point_get_pair(model_point));

    adg_point_set_pair_from_model(model_point, model, "named-pair");
    g_assert_true(adg_point_update(model_point));

    /* Check for case sensitiveness */
    adg_point_set_pair_from_model(model_point, model, "Named-Pair");
    g_assert_null(adg_point_get_pair(model_point));
    g_assert_false(adg_point_update(model_point));

    /* Check if adg_point_get_pair() triggers an adg_point_update() */
    adg_point_set_pair_from_model(model_point, model, "named-pair");
    pair = adg_point_get_pair(model_point);
    g_assert_true(cpml_pair_equal(pair, &p1));
    g_free(pair);

    adg_point_destroy(explicit_point);
    adg_point_destroy(model_point);
    g_object_unref(model);
}
コード例 #25
0
static void test_parse_mountinfo_entry__garbage()
{
	const char *line = "256 104 0:3";
	struct mountinfo_entry *entry = parse_mountinfo_entry(line);
	g_assert_null(entry);
}
コード例 #26
0
ファイル: test-gtk-utils.c プロジェクト: ntd/adg
static void
_adg_method_widget_get_window(void)
{
    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_assert_null(gtk_widget_get_window(window));
}
コード例 #27
0
ファイル: test-adim.c プロジェクト: bert/adg
static void
_adg_property_org1(void)
{
    AdgADim *adim;
    AdgModel *model;
    AdgPoint *origin, *explicit_point, *model_point;
    AdgPoint *org1;

    adim = adg_adim_new();
    model = ADG_MODEL(adg_path_new());
    origin = adg_point_new();
    explicit_point = adg_point_new();
    model_point = adg_point_new();

    adg_point_set_pair_explicit(origin, 0, 0);
    adg_point_set_pair_explicit(explicit_point, 123, 321);
    adg_model_set_named_pair(model, "named-pair", (CpmlPair *) explicit_point);
    adg_point_set_pair_from_model(model_point, model, "named-pair");

    /* Ensure ADG does not consider an explicit point equals to
     * a point bound to a named pair with the same coordinates */
    g_assert_false(adg_point_equal(explicit_point, model_point));

    org1 = adg_adim_get_org1(adim);
    g_assert_null(org1);

    /* Using the public APIs */
    adg_adim_set_org1_explicit(adim, 0, 0);
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, origin));

    adg_adim_set_org1(adim, NULL);
    org1 = adg_adim_get_org1(adim);
    g_assert_null(org1);

    adg_adim_set_org1(adim, explicit_point);
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, explicit_point));

    adg_adim_set_org1_from_model(adim, model, "dummy");
    org1 = adg_adim_get_org1(adim);
    g_assert_nonnull(org1);

    adg_adim_set_org1_from_model(adim, model, "named-pair");
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, model_point));

    /* Using GObject property methods */
    g_object_set(adim, "org1", origin, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, origin));
    adg_point_destroy(org1);

    g_object_set(adim, "org1", NULL, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_null(org1);

    g_object_set(adim, "org1", explicit_point, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, explicit_point));
    adg_point_destroy(org1);

    adg_adim_set_org1_from_model(adim, model, "dummy");
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_nonnull(org1);
    adg_point_destroy(org1);

    g_object_set(adim, "org1", model_point, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, model_point));
    adg_point_destroy(org1);

    adg_point_destroy(origin);
    adg_point_destroy(explicit_point);
    adg_point_destroy(model_point);
    adg_entity_destroy(ADG_ENTITY(adim));
    g_object_unref(model);
}