File: test-unit.c

package info (click to toggle)
gimp 3.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 210,076 kB
  • sloc: ansic: 842,287; 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 (97 lines) | stat: -rw-r--r-- 3,163 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
#define N_DEFAULT_USER_UNITS 6

typedef struct
{
  gdouble   factor;
  gint      digits;
  gchar    *name;
  gchar    *symbol;
  gchar    *abbreviation;
} GimpUnitDef;

static const GimpUnitDef _gimp_unit_defs[GIMP_UNIT_END] =
{
  /* pseudo unit */
  { 0.0,  0, "pixels",      "px", "px", },

  /* standard units */
  { 1.0,  2, "inches",      "''", "in", },

  { 25.4, 1, "millimeters", "mm", "mm", },

  /* professional units */
  { 72.0, 0, "points",      "pt", "pt", },

  { 6.0,  1, "picas",       "pc", "pc", },
};

static GimpValueArray *
gimp_c_test_run (GimpProcedure        *procedure,
                 GimpRunMode           run_mode,
                 GimpImage            *image,
                 GimpDrawable        **drawables,
                 GimpProcedureConfig  *config,
                 gpointer              run_data)
{
  GimpUnit *unit;
  GimpUnit *unit2;
  gint      n_user_units = 0;
  gint      i;

  GIMP_TEST_START("gimp_unit_inch()");
  unit = gimp_unit_inch ();
  GIMP_TEST_END(GIMP_IS_UNIT (unit));

  GIMP_TEST_START("gimp_unit_inch() always returns an unique object");
  unit2 = gimp_unit_inch ();
  GIMP_TEST_END(GIMP_IS_UNIT (unit2) && unit == unit2);

  for (i = 0; i < GIMP_UNIT_END; i++)
    {
      gchar *test_name = g_strdup_printf ("Testing built-in unit %d", i);

      GIMP_TEST_START(test_name);
      g_free (test_name);

      unit = gimp_unit_get_by_id (i);

      GIMP_TEST_END(GIMP_IS_UNIT (unit) &&
                    g_strcmp0 (gimp_unit_get_name (unit), _gimp_unit_defs[i].name) == 0                 &&
                    g_strcmp0 (gimp_unit_get_symbol (unit), _gimp_unit_defs[i].symbol) == 0             &&
                    g_strcmp0 (gimp_unit_get_abbreviation (unit), _gimp_unit_defs[i].abbreviation) == 0 &&
                    gimp_unit_get_factor (unit) == _gimp_unit_defs[i].factor                            &&
                    gimp_unit_get_digits (unit)  == _gimp_unit_defs[i].digits);

      if (i == GIMP_UNIT_INCH)
        {
          GIMP_TEST_START("gimp_unit_inch() is the same as gimp_unit_get_by_id (GIMP_UNIT_INCH)");
          GIMP_TEST_END(unit == unit2);
        }
    }

  GIMP_TEST_START("Counting default user units");
  unit = gimp_unit_get_by_id (GIMP_UNIT_END);
  while (GIMP_IS_UNIT (unit))
    unit = gimp_unit_get_by_id (GIMP_UNIT_END + ++n_user_units);
  /* A bare config contains 6 defaults units in /etc/. */
  GIMP_TEST_END(n_user_units == N_DEFAULT_USER_UNITS);

  GIMP_TEST_START("gimp_unit_new()");
  unit2 = gimp_unit_new ("name", 2.0, 1, "symbol", "abbreviation");
  GIMP_TEST_END(GIMP_IS_UNIT (unit2));

  GIMP_TEST_START("Verifying the new user unit's ID");
  GIMP_TEST_END(gimp_unit_get_id (unit2) == GIMP_UNIT_END + n_user_units);

  GIMP_TEST_START("Verifying the new user unit's unicity");
  GIMP_TEST_END(unit2 == gimp_unit_get_by_id (GIMP_UNIT_END + n_user_units));

  GIMP_TEST_START("Counting again user units");
  unit = gimp_unit_get_by_id(GIMP_UNIT_END);
  n_user_units = 0;
  while (GIMP_IS_UNIT (unit))
    unit = gimp_unit_get_by_id (GIMP_UNIT_END + ++n_user_units);
  GIMP_TEST_END(n_user_units == N_DEFAULT_USER_UNITS + 1);

  GIMP_TEST_RETURN
}