コード例 #1
0
ファイル: test-utils.c プロジェクト: Distrotech/librsvg
void
test_utils_add_test_for_all_files (const gchar   *prefix,
                                   GFile         *base,
                                   GFile         *file,
                                   GTestDataFunc  test_func,
                                   AddTestFunc    add_test_func)
{
  GFileEnumerator *enumerator;
  GFileInfo *info;
  GList *l, *files;
  GError *error = NULL;


  if (g_file_query_file_type (file, 0, NULL) != G_FILE_TYPE_DIRECTORY)
    {
      gchar *test_path;
      gchar *relative_path;

      if (base)
        relative_path = g_file_get_relative_path (base, file);
      else
        relative_path = g_file_get_path (file);

      test_path = g_strconcat (prefix, "/", relative_path, NULL);
      
      g_test_add_data_func_full (test_path, g_object_ref (file), test_func, g_object_unref);
      return;
    }


  enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
  g_assert_no_error (error);
  files = NULL;

  while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
    {
      GFile *next_file = g_file_get_child (file, g_file_info_get_name (info));

      if (add_test_func == NULL || add_test_func (next_file))
        {
          files = g_list_prepend (files, g_object_ref (next_file));
        }

      g_object_unref (next_file);
      g_object_unref (info);
    }
  
  g_assert_no_error (error);
  g_object_unref (enumerator);

  files = g_list_sort (files, compare_files);

  for (l = files; l; l = l->next)
    {
      test_utils_add_test_for_all_files (prefix, base, l->data, test_func, add_test_func);
    }

  g_list_free_full (files, g_object_unref);
}
コード例 #2
0
ファイル: crankbasetest.c プロジェクト: WSID/crank-system
/**
 * crank_test_add_func_timeout: (skip)
 * @path: A Test path.
 * @func: A testing function, supposed to be done in time.
 * @time: Time in microseconds.
 *
 * Adds a test case that checks given test done in time.
 *
 * If given function does not end in time, then the test is considered to be failed.
 */
void
crank_test_add_func_timeout (const gchar  *path,
                             GTestFunc     func,
                             const guint64 time)
{
  CrankTestMetaTimeout *meta = g_new (CrankTestMetaTimeout, 1);

  meta->func = func;
  meta->time = time;

  g_test_add_data_func_full (path, meta, crank_test_meta_timeout, g_free);
}
コード例 #3
0
ファイル: crankbasetest.c プロジェクト: WSID/crank-system
/**
 * crank_test_add_func_expected_fail: (skip)
 * @path: A Test path.
 * @func: A testing function, supposed to fail.
 *
 * Adds a test case that checks given test fails.
 *
 * If given function does not fail, then the test is considered to be failed.
 */
void
crank_test_add_func_expected_fail (const gchar *path,
                                   GTestFunc    func)
{
  gchar *func_path = g_strdup_printf ("/_crank/subprocess/efail%s", path);

  g_test_add_func (func_path, func);
  g_test_add_data_func_full (path,
                             func_path,
                             crank_test_meta_expected_fail,
                             g_free);
}
コード例 #4
0
ファイル: test-layout.c プロジェクト: LastRitter/pango
int
main (int argc, char *argv[])
{
  GDir *dir;
  GError *error = NULL;
  const gchar *name;
  gchar *path;

  g_setenv ("LC_ALL", "C", TRUE);
  setlocale (LC_ALL, "");

  g_test_init (&argc, &argv, NULL);

  context = pango_font_map_create_context (pango_cairo_font_map_get_default ());

  /* allow to easily generate expected output for new test cases */
  if (argc > 1)
    {
      GString *string;

      string = g_string_sized_new (0);
      test_file (argv[1], string);
      g_print ("%s", string->str);

      return 0;
    }

  path = g_test_build_filename (G_TEST_DIST, "layouts", NULL);
  dir = g_dir_open (path, 0, &error);
  g_free (path);
  g_assert_no_error (error);
  while ((name = g_dir_read_name (dir)) != NULL)
    {
      if (!strstr (name, "markup"))
        continue;

      path = g_strdup_printf ("/layout/%s", name);
      g_test_add_data_func_full (path, g_test_build_filename (G_TEST_DIST, "layouts", name, NULL),
                                 test_layout, g_free);
      g_free (path);
    }
  g_dir_close (dir);

  return g_test_run ();
}
コード例 #5
0
/**
 * clutter_test_add_data_full:
 * @test_path: unique path for identifying the test
 * @test_func: (scope notified): function containing the test
 * @test_data: (closure): data to pass to the test function
 * @test_notify: function called when the test function ends
 *
 * Adds a test unit to the Clutter test environment.
 *
 * See also: g_test_add_data_func_full()
 *
 * Since: 1.18
 */
void
clutter_test_add_data_full (const char     *test_path,
                            GTestDataFunc   test_func,
                            gpointer        test_data,
                            GDestroyNotify  test_notify)
{
  ClutterTestData *data;

  g_return_if_fail (test_path != NULL);
  g_return_if_fail (test_func != NULL);

  g_assert (test_environ != NULL);

  data = g_new (ClutterTestData, 1);
  data->test_func = test_func;
  data->test_data = test_data;
  data->test_notify = test_notify;

  g_test_add_data_func_full (test_path, data,
                             clutter_test_func_wrapper,
                             g_free);
}
コード例 #6
0
ファイル: invalid.c プロジェクト: mspanc/json-glib
int
main (int   argc,
      char *argv[])
{
  int i;

  g_test_init (&argc, &argv, NULL);

  for (i = 0; i < n_test_invalid; i++)
    {
      char *test_path = g_strconcat ("/invalid/json/", test_invalid[i].path, NULL);

      g_test_add_data_func_full (test_path,
                                 (gpointer) test_invalid[i].json,
                                 test_invalid[i].func,
                                 NULL);

      g_free (test_path);
    }

  return g_test_run ();
}