示例#1
0
static void
test_resource (void)
{
  const gchar *path;
  GError *error = NULL;
  GdkPixbuf *pixbuf, *ref;

  path = g_test_get_filename (G_TEST_DIST, "icc-profile.png", NULL);
  ref = gdk_pixbuf_new_from_file (path, &error);
  g_assert_no_error (error);

  pixbuf = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile.png", &error);
  g_assert_no_error (error);
  g_assert (pixbuf_equal (pixbuf, ref));
  g_object_unref (pixbuf);
  
  pixbuf = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile.pixdata", &error);
  g_assert_no_error (error);
  g_assert (pixdata_equal (pixbuf, ref));
  g_object_unref (pixbuf);

  pixbuf = gdk_pixbuf_new_from_resource ("/no/such/resource", &error);
  g_assert (pixbuf == NULL);
  g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
  g_clear_error (&error);

  pixbuf = gdk_pixbuf_new_from_resource ("resource:///test/resource/icc-profile.png", &error);
  g_assert (pixbuf == NULL);
  g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
  g_clear_error (&error);

  g_object_unref (ref);
}
示例#2
0
static void
test_area_updated_anim (gconstpointer data)
{
    const char *filename;
    GIOChannel *channel;
    GdkPixbufLoader *loader;

    filename = g_test_get_filename (G_TEST_DIST, data, NULL);

    channel = g_io_channel_new_file (filename, "r", NULL);
    g_assert_nonnull (channel);
    g_io_channel_set_encoding(channel, NULL, NULL);
    /*create loader */
    loader = gdk_pixbuf_loader_new ();
    g_assert_nonnull (loader);

    g_signal_connect (loader, "area-prepared",
                      (GCallback) callback_area_prepared_anim, NULL);
    /* other callbacks will be registered inside callback_area_prepared_anim */

    /*read animation by portions of bytes */
#if 0
    while(loader_write_from_channel(loader, channel, 20) == 20);
#endif
    /* or read it at once */
    loader_write_from_channel (loader, channel, G_MAXSIZE);

    /* free resources */
    g_io_channel_unref (channel);
    gdk_pixbuf_loader_close (loader, NULL);
    g_object_unref (loader);
}
示例#3
0
static void
test_area_updated_ico (gconstpointer data)
{
    const char *filename;
    GIOChannel *channel;
    GdkPixbufLoader *loader;

    filename = g_test_get_filename (G_TEST_DIST, data, NULL);

    /* create channel */
    channel = g_io_channel_new_file(filename, "r", NULL);
    g_assert_nonnull (channel);
    g_io_channel_set_encoding (channel, NULL, NULL);
    /* create loader */
    loader = gdk_pixbuf_loader_new ();
    g_assert_nonnull (loader);

    g_signal_connect(loader, "area-prepared",
                    (GCallback) callback_area_prepared, NULL);
    /* callbacks for "area-updated" and "closed" signals will be connected
     * in callback_area_prepared() */

    /* read image byte by byte */
    while (loader_write_from_channel(loader, channel, 1) == 1);
    /* or read full image at once */
#if 0
    loader_write_from_channel(loader, channel, G_MAXSIZE);
#endif

    /* free resources */
    g_io_channel_unref (channel);

    gdk_pixbuf_loader_close (loader, NULL);
    g_object_unref (loader);
}
示例#4
0
static void
do_session_property_tests (void)
{
	gboolean use_system;
	GTlsDatabase *tlsdb;
	char *ca_file;
	SoupSession *session;

	debug_printf (1, "session properties\n");

	session = soup_session_async_new ();

	g_object_get (G_OBJECT (session),
		      "ssl-use-system-ca-file", &use_system,
		      "tls-database", &tlsdb,
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (!use_system, "ssl-use-system-ca-file defaults to TRUE");
	soup_test_assert (tlsdb == NULL, "tls-database set by default");
	soup_test_assert (ca_file == NULL, "ca-file set by default");

	g_object_set (G_OBJECT (session),
		      "ssl-use-system-ca-file", TRUE,
		      NULL);
	g_object_get (G_OBJECT (session),
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (ca_file == NULL, "setting ssl-use-system-ca-file set ssl-ca-file");

	g_object_set (G_OBJECT (session),
		      "ssl-ca-file",
		      g_test_get_filename (G_TEST_DIST, "test-cert.pem", NULL),
		      NULL);
	g_object_get (G_OBJECT (session),
		      "ssl-use-system-ca-file", &use_system,
		      "tls-database", &tlsdb,
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (ca_file == NULL, "setting ssl-ca-file did not fail");
	soup_test_assert (!use_system, "setting ssl-ca-file set ssl-use-system-ca-file");
	soup_test_assert (tlsdb == NULL, "setting ssl-ca-file set tls-database");

	g_object_set (G_OBJECT (session),
		      "tls-database", NULL,
		      NULL);
	g_object_get (G_OBJECT (session),
		      "ssl-use-system-ca-file", &use_system,
		      "tls-database", &tlsdb,
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (tlsdb == NULL, "setting tls-database NULL failed");
	soup_test_assert (!use_system, "setting tls-database NULL set ssl-use-system-ca-file");
	soup_test_assert (ca_file == NULL, "setting tls-database NULL set ssl-ca-file");

	soup_test_session_abort_unref (session);
}
static void
test_serialize (void)
{
  GError *error = NULL;
  GdkPixbuf *pixbuf;
  GdkPixbuf *pixbuf2;
  GVariant *data;
  GIcon *icon;
  GInputStream *stream;

  pixbuf = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "test-image.png", NULL), &error);
  g_assert_no_error (error);
  g_assert (pixbuf != NULL);

  /* turn it into a GVariant */
  data = g_icon_serialize (G_ICON (pixbuf));

  /* back to a GIcon, but this will be a GBytesIcon, not GdkPixbuf */
  icon = g_icon_deserialize (data);
  g_assert (G_IS_BYTES_ICON (icon));

  /* but since that is a GLoadableIcon, we can load it again */
  stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), 0, NULL, NULL, &error);
  g_assert_no_error (error);
  pixbuf2 = gdk_pixbuf_new_from_stream (stream, NULL, &error);
  g_assert_no_error (error);

  /* make sure that the pixels are the same.
   * our _serialize() uses png, so this should be perfect.
   */
  {
    guchar *pixels_a, *pixels_b;
    guint len_a, len_b;
    pixels_a = gdk_pixbuf_get_pixels_with_length (pixbuf, &len_a);
    pixels_b = gdk_pixbuf_get_pixels_with_length (pixbuf2, &len_b);
    g_assert (len_a == len_b);
    g_assert (memcmp (pixels_a, pixels_b, len_a) == 0);
  }

  g_object_unref (pixbuf2);
  g_object_unref (pixbuf);
  g_object_unref (stream);
  g_variant_unref (data);

}
示例#6
0
static void
test_resource_at_scale (void)
{
  const gchar *path;
  GError *error = NULL;
  GdkPixbuf *pixbuf, *ref;

  path = g_test_get_filename (G_TEST_DIST, "icc-profile.png", NULL);
  ref = gdk_pixbuf_new_from_file_at_scale (path, 40, 10, FALSE, &error);
  g_assert_no_error (error);

  pixbuf = gdk_pixbuf_new_from_resource_at_scale ("/test/resource/icc-profile.png", 40, 10, FALSE, &error);
  g_assert_no_error (error);
  g_assert (pixbuf_equal (pixbuf, ref));
  g_object_unref (pixbuf);
  
  g_object_unref (ref);
}
示例#7
0
static void check_xml(GVirConfigDomain *domain, const char *reference_file)
{
    const char *reference_path;
    GError *error = NULL;
    char *reference_xml;
    char *xml;

    reference_path = g_test_get_filename(G_TEST_DIST, "xml",
                                         reference_file, NULL);
    g_file_get_contents(reference_path, &reference_xml, NULL, &error);
    g_assert_no_error(error);
    /* I could not generate text files without a trailing \n with vim or
     * gedit, workaround this issue by removing trailing whitespace from
     * the reference file */
    g_strchomp(reference_xml);
    xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain));
    g_assert_cmpstr(xml, ==, reference_xml);
    g_free(xml);
    g_free(reference_xml);
}
示例#8
0
static void
test_boundaries (void)
{
  gchar *text;
  const gchar *filename;
#if GLIB_CHECK_VERSION(2, 37, 2)
  filename = g_test_get_filename (G_TEST_DIST, "boundaries.utf8", NULL);
#else
  filename = SRCDIR "/boundaries.utf8";
#endif

  g_print ("sample file: %s\n", filename);

  if (!g_file_get_contents (filename, &text, NULL, NULL))
    fail ("Couldn't open sample text file");

  check_invariants (text);

  g_free (text);

  printf ("testboundaries passed\n");
}
示例#9
0
static void
do_session_property_tests (void)
{
	gboolean use_system;
	GTlsDatabase *tlsdb;
	char *ca_file;
	SoupSession *session;
	GParamSpec *pspec;

	g_test_bug ("700518");

	G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
	session = soup_session_async_new ();
	G_GNUC_END_IGNORE_DEPRECATIONS;

	/* Temporarily undeprecate SOUP_SESSION_SSL_CA_FILE to avoid warnings. */
	pspec = g_object_class_find_property (g_type_class_peek (SOUP_TYPE_SESSION),
					      SOUP_SESSION_SSL_CA_FILE);
	pspec->flags &= ~G_PARAM_DEPRECATED;

	g_object_get (G_OBJECT (session),
		      "ssl-use-system-ca-file", &use_system,
		      "tls-database", &tlsdb,
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (!use_system, "ssl-use-system-ca-file defaults to TRUE");
	soup_test_assert (tlsdb == NULL, "tls-database set by default");
	soup_test_assert (ca_file == NULL, "ca-file set by default");

	g_object_set (G_OBJECT (session),
		      "ssl-use-system-ca-file", TRUE,
		      NULL);
	g_object_get (G_OBJECT (session),
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (ca_file == NULL, "setting ssl-use-system-ca-file set ssl-ca-file");

	g_object_set (G_OBJECT (session),
		      "ssl-ca-file",
		      g_test_get_filename (G_TEST_DIST, "test-cert.pem", NULL),
		      NULL);
	g_object_get (G_OBJECT (session),
		      "ssl-use-system-ca-file", &use_system,
		      "tls-database", &tlsdb,
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (ca_file == NULL, "setting ssl-ca-file did not fail");
	soup_test_assert (!use_system, "setting ssl-ca-file set ssl-use-system-ca-file");
	soup_test_assert (tlsdb == NULL, "setting ssl-ca-file set tls-database");

	g_object_set (G_OBJECT (session),
		      "tls-database", NULL,
		      NULL);
	g_object_get (G_OBJECT (session),
		      "ssl-use-system-ca-file", &use_system,
		      "tls-database", &tlsdb,
		      "ssl-ca-file", &ca_file,
		      NULL);
	soup_test_assert (tlsdb == NULL, "setting tls-database NULL failed");
	soup_test_assert (!use_system, "setting tls-database NULL set ssl-use-system-ca-file");
	soup_test_assert (ca_file == NULL, "setting tls-database NULL set ssl-ca-file");

	soup_test_session_abort_unref (session);

	/* Re-deprecate SOUP_SESSION_SSL_CA_FILE */
	pspec->flags |= G_PARAM_DEPRECATED;
}
示例#10
0
文件: autoptr.c 项目: Babelz/SaNi
static void
test_g_mapped_file (void)
{
  g_autoptr(GMappedFile) val = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "keyfiletest.ini", NULL), FALSE, NULL);
  g_assert (val != NULL);
}
示例#11
0
static void
test_validity (void)
{
  struct
    {
      const gchar *filename;  /* name of a file in the tests/thumbnails dir */
      guint64 mtime;  /* asserted mtime of @filename */
      guint64 size;  /* asserted size of @filename */
      gboolean expected_validity;  /* should thumbnail_verify() succeed? */
    }
  tests[] =
    {
      /*
       * Tests with well-formed PNG files.
       *
       * Note that these files have all been brutally truncated to a reasonable
       * size, so aren't actually valid PNG files. Their headers are valid,
       * however, and that's all we care about.
       */

      /* Test that validation succeeds against a valid PNG file with URI,
       * mtime and size which match the expected values. */
      { "valid.png", 1382429848, 93654, TRUE },
      /* Test that validation succeeds with URI and mtime, but no size in the
       * tEXt data. */
      { "valid-no-size.png", 1382429848, 93633, TRUE },
      /* Test that a missing file fails validation. */
      { "missing.png", 123456789, 12345, FALSE },
      /* Test that an existing file with no tEXt data fails validation. */
      { "no-text-data.png", 123 /* invalid */, 26378, FALSE },
      /* Test that a URI mismatch fails validation. */
      { "uri-mismatch.png" /* invalid */, 1382429848, 93654, FALSE },
      /* Test that an mtime mismatch fails validation. */
      { "valid.png", 123 /* invalid */, 93654, FALSE },
      /* Test that a valid URI and mtime, but a mismatched size, fails
       * validation. */
      { "valid.png", 1382429848, 123 /* invalid */, FALSE },
      /* Test that validation succeeds with an mtime of 0. */
      { "mtime-zero.png", 0, 93621, TRUE },
      /* Test that validation fails if the mtime is only a prefix match. */
      { "valid.png", 9848 /* invalid */, 93654, FALSE },

      /*
       * Tests with PNG files which have malicious or badly-formed headers.
       *
       * As above, the files have all been truncated to reduce their size.
       */

      /* Check a corrupted PNG header fails validation. */
      { "bad-header.png", 1382429848, 93654, FALSE },
      /* Check a PNG header by itself fails. */
      { "header-only.png", 1382429848, 8, FALSE },
      /* Check a PNG header and initial chunk size fails. */
      { "header-and-chunk-size.png", 1382429848, 20, FALSE },
      /* Check a huge chunk size fails. */
      { "huge-chunk-size.png", 1382429848, 93654, FALSE },
      /* Check that an empty key fails. */
      { "empty-key.png", 1382429848, 93654, FALSE },
      /* Check that an over-long value fails (even if nul-terminated). */
      { "overlong-value.png", 1382429848, 93660, FALSE },
    };
  guint i;

  /* Run all the tests. */
  for (i = 0; i < G_N_ELEMENTS (tests); i++)
    {
      GStatBuf stat_buf;
      const gchar *thumbnail_path;
      gchar *file_uri;
      gboolean result;

      thumbnail_path = g_test_get_filename (G_TEST_DIST, "thumbnails",
                                            tests[i].filename, NULL);
      file_uri = g_strconcat ("file:///tmp/", tests[i].filename, NULL);
      stat_buf.st_mtime = tests[i].mtime;
      stat_buf.st_size = tests[i].size;

      result = thumbnail_verify (thumbnail_path, file_uri, &stat_buf);

      g_free (file_uri);

      g_assert (result == tests[i].expected_validity);
    }
}