File: test-timed-animation.c

package info (click to toggle)
phoc 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,152 kB
  • sloc: ansic: 108,724; xml: 3,963; sh: 138; makefile: 33; javascript: 5
file content (165 lines) | stat: -rw-r--r-- 4,123 bytes parent folder | download
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright (C) 2023 Phosh.mobi e.V.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "anim/timed-animation.h"


#define PHOC_TYPE_TEST_OBJ (phoc_test_obj_get_type ())
G_DECLARE_FINAL_TYPE (PhocTestObj, phoc_test_obj, PHOC, TEST_OBJ, GObject)

enum {
  PROP_0,
  PROP_I,
  PROP_F,
  PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];

struct _PhocTestObj {
  GObject parent;

  int     prop_i;
  float   prop_f;
};
G_DEFINE_TYPE (PhocTestObj, phoc_test_obj, G_TYPE_OBJECT)


static void
phoc_test_obj_set_property (GObject      *object,
                            guint         property_id,
                            const GValue *value,
                            GParamSpec   *pspec)
{
  PhocTestObj *self = PHOC_TEST_OBJ (object);

  switch (property_id) {
  case PROP_I:
    self->prop_i = g_value_get_int (value);
    break;
  case PROP_F:
    self->prop_f = g_value_get_float (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
phoc_test_obj_get_property (GObject    *object,
                            guint       property_id,
                            GValue     *value,
                            GParamSpec *pspec)
{
  PhocTestObj *self = PHOC_TEST_OBJ (object);

  switch (property_id) {
  case PROP_I:
    g_value_set_int (value, self->prop_i);
    break;
  case PROP_F:
    g_value_set_float (value, self->prop_f);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
phoc_test_obj_class_init (PhocTestObjClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->get_property = phoc_test_obj_get_property;
  object_class->set_property = phoc_test_obj_set_property;

  props[PROP_I] =
    g_param_spec_int ("prop-i", "", "",
                      0,
                      1000,
                      0,
                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_F] =
    g_param_spec_float ("prop-f", "", "",
                        -1000.0,
                        1000.0,
                        0.0,
                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}


static void
phoc_test_obj_init (PhocTestObj *self)
{
}


static PhocTestObj *
phoc_test_obj_new (void)
{
  return PHOC_TEST_OBJ (g_object_new (PHOC_TYPE_TEST_OBJ, NULL));
}


static void
test_phoc_timed_animation_simple (void)
{
  PhocTimedAnimation *anim = phoc_timed_animation_new ();

  g_assert_cmpint (phoc_timed_animation_get_duration (anim), ==, 0);
  g_assert_cmpint (phoc_timed_animation_get_state (anim), ==,
                   PHOC_TIMED_ANIMATION_IDLE);
  g_assert_false (phoc_timed_animation_get_dispose_on_done (anim));

  g_assert_finalize_object (anim);
}


static void
test_phoc_timed_animation_dispose_on_done (void)
{
  PhocTimedAnimation *anim = NULL;
  PhocTestObj *obj = phoc_test_obj_new ();
  PhocPropertyEaser *easer = phoc_property_easer_new (G_OBJECT (obj));

  anim = g_object_new (PHOC_TYPE_TIMED_ANIMATION,
                       "dispose-on-done", TRUE,
                       "property-easer", easer,
                       NULL);
  phoc_property_easer_set_props (easer, "prop-f", NULL);

  g_assert_cmpint (phoc_timed_animation_get_duration (anim), ==, 0);
  g_assert_cmpint (phoc_timed_animation_get_state (anim), ==,
                   PHOC_TIMED_ANIMATION_IDLE);
  g_assert_true (phoc_timed_animation_get_dispose_on_done (anim));

  phoc_timed_animation_skip (anim);

  /* anim holds a ref on easer and obj so dispose first */
  g_assert_finalize_object (anim);
  g_assert_finalize_object (easer);
  g_assert_finalize_object (obj);
}


int
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/phoc/timed-animation/simple", test_phoc_timed_animation_simple);
  g_test_add_func ("/phoc/timed-animation/dispose_on_done",
                   test_phoc_timed_animation_dispose_on_done);

  return g_test_run ();
}