File: c-test-header.c

package info (click to toggle)
gimp 3.0.4-6.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 210,548 kB
  • sloc: ansic: 842,405; lisp: 10,761; python: 10,318; cpp: 7,238; perl: 4,355; sh: 1,043; xml: 963; yacc: 609; lex: 348; javascript: 150; makefile: 43
file content (132 lines) | stat: -rw-r--r-- 4,059 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
 *
 * Copyright (C) 2024 Jehan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <libgimp/gimp.h>

static GimpPDBStatusType  status   = GIMP_PDB_SUCCESS;
static GError            *error    = NULL;
static const gchar       *testname = NULL;

#define GIMP_TEST_RETURN \
gimp_test_cleanup: \
    return gimp_procedure_new_return_values (procedure, status, error);

#define GIMP_TEST_START(name) if (error) goto gimp_test_cleanup; testname = name; printf ("Starting test '%s': ", testname);

#define GIMP_TEST_END(test) \
  if (! (test)) \
    { \
      printf ("FAILED\n"); \
      error = g_error_new_literal (GIMP_PLUG_IN_ERROR, 0, testname); \
      status = GIMP_PDB_EXECUTION_ERROR; \
    } \
  else \
    { \
      printf ("OK\n"); \
    }

typedef struct _GimpCTest      GimpCTest;
typedef struct _GimpCTestClass GimpCTestClass;

struct _GimpCTest
{
  GimpPlugIn      parent_instance;
};

struct _GimpCTestClass
{
  GimpPlugInClass parent_class;
};


/* Declare local functions.
 */

#define GIMP_C_TEST_TYPE  (gimp_c_test_get_type ())
#define GIMP_C_TEST (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_C_TEST_TYPE, GimpCTest))

GType                   gimp_c_test_get_type         (void) G_GNUC_CONST;

static GList          * gimp_c_test_query_procedures (GimpPlugIn           *plug_in);
static GimpProcedure  * gimp_c_test_create_procedure (GimpPlugIn           *plug_in,
                                                      const gchar          *name);

static GimpValueArray * gimp_c_test_run              (GimpProcedure        *procedure,
                                                      GimpRunMode           run_mode,
                                                      GimpImage            *image,
                                                      GimpDrawable        **drawables,
                                                      GimpProcedureConfig  *config,
                                                      gpointer              run_data);


G_DEFINE_TYPE (GimpCTest, gimp_c_test, GIMP_TYPE_PLUG_IN)

GIMP_MAIN (GIMP_C_TEST_TYPE)


static void
gimp_c_test_class_init (GimpCTestClass *klass)
{
  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);

  plug_in_class->query_procedures = gimp_c_test_query_procedures;
  plug_in_class->create_procedure = gimp_c_test_create_procedure;
}

static void
gimp_c_test_init (GimpCTest *ctest)
{
}

static GList *
gimp_c_test_query_procedures (GimpPlugIn *plug_in)
{
  gchar *testname  = g_path_get_basename (__FILE__);
  gchar *dot;

  dot  = g_strrstr (testname, ".");
  *dot = '\0';

  return g_list_append (NULL, testname);
}

static GimpProcedure *
gimp_c_test_create_procedure (GimpPlugIn  *plug_in,
                       const gchar *name)
{
  GimpProcedure *procedure = NULL;
  gchar         *testname  = g_path_get_basename (__FILE__);
  gchar         *dot;

  dot  = g_strrstr (testname, ".");
  *dot = '\0';

  if (! strcmp (name, testname))
    {
      procedure = gimp_image_procedure_new (plug_in, name,
                                            GIMP_PDB_PROC_TYPE_PLUGIN,
                                            gimp_c_test_run, NULL, NULL);
      gimp_procedure_set_image_types (procedure, "*");
      gimp_procedure_set_sensitivity_mask(procedure, GIMP_PROCEDURE_SENSITIVE_ALWAYS);
    }

  g_free (testname);

  return procedure;
}