summaryrefslogtreecommitdiff
path: root/src/tests/clutter/conform/timeline-progress.c
blob: fc4ce84211370a5333dad85e20a0e8f7445142df (plain)
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
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <glib.h>
#include <clutter/clutter.h>

#include "tests/clutter-test-utils.h"

static void
timeline_progress_step (void)
{
  ClutterActor *stage = clutter_test_get_stage ();
  ClutterTimeline *timeline;

  timeline = clutter_timeline_new_for_actor (stage, 1000);

  if (!g_test_quiet ())
    g_print ("mode: step(3, end)\n");

  clutter_timeline_rewind (timeline);
  clutter_timeline_set_step_progress (timeline, 3, CLUTTER_STEP_MODE_END);
  g_assert_cmpint (clutter_timeline_get_progress (timeline), ==, 0);

  clutter_timeline_advance (timeline, 1000 / 3 - 1);
  g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 0);

  clutter_timeline_advance (timeline, 1000 / 3 + 1);
  g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 333);

  clutter_timeline_advance (timeline, 1000 / 3 * 2 - 1);
  g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 333);

  clutter_timeline_advance (timeline, 1000 / 3 * 2 + 1);
  g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 666);

  clutter_timeline_rewind (timeline);
  clutter_timeline_set_progress_mode (timeline, CLUTTER_STEP_START);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 1);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_advance (timeline, 500);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_advance (timeline, 999);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_advance (timeline, 1000);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  if (!g_test_quiet ())
    g_print ("mode: step-start\n");

  clutter_timeline_rewind (timeline);
  clutter_timeline_set_progress_mode (timeline, CLUTTER_STEP_START);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 1);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_advance (timeline, 500);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_advance (timeline, 999);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_advance (timeline, 1000);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  if (!g_test_quiet ())
    g_print ("mode: step-end\n");

  clutter_timeline_rewind (timeline);
  clutter_timeline_set_progress_mode (timeline, CLUTTER_STEP_END);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 1);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 500);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 999);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 1000);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  g_object_unref (timeline);
}

static void
timeline_progress_mode (void)
{
  ClutterActor *stage = clutter_test_get_stage ();
  ClutterTimeline *timeline;

  timeline = clutter_timeline_new_for_actor (stage, 1000);

  g_assert (clutter_timeline_get_progress_mode (timeline) == CLUTTER_LINEAR);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  clutter_timeline_advance (timeline, 500);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.5);

  clutter_timeline_advance (timeline, 1000);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0);

  clutter_timeline_rewind (timeline);
  g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0);

  g_object_unref (timeline);
}

CLUTTER_TEST_SUITE (
  CLUTTER_TEST_UNIT ("/timeline/progress/step", timeline_progress_step);
  CLUTTER_TEST_UNIT ("/timeline/progress/mode", timeline_progress_mode)
)