File: test-animation-target.c

package info (click to toggle)
libadwaita-1 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 12,252 kB
  • sloc: ansic: 86,011; xml: 189; python: 60; sh: 30; makefile: 23; javascript: 9
file content (71 lines) | stat: -rw-r--r-- 2,231 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) 2022 George Barrett <bob@bob131.so>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <adwaita.h>

static void
test_adw_property_animation_target_construct (void)
{
  GObject *widget = g_object_ref_sink (G_OBJECT (gtk_button_new ()));
  AdwPropertyAnimationTarget *named_target, *pspec_target;
  GParamSpec *target_pspec;

  named_target =
    ADW_PROPERTY_ANIMATION_TARGET (adw_property_animation_target_new (widget, "opacity"));

  target_pspec = adw_property_animation_target_get_pspec (named_target);
  g_assert_nonnull (target_pspec);
  g_assert_cmpstr (target_pspec->name, ==, "opacity");

  pspec_target =
    ADW_PROPERTY_ANIMATION_TARGET (adw_property_animation_target_new_for_pspec (widget, target_pspec));

  g_assert_true (adw_property_animation_target_get_pspec (pspec_target) == target_pspec);

  target_pspec = adw_property_animation_target_get_pspec (named_target);
  g_assert_nonnull (target_pspec);
  g_assert_cmpstr (target_pspec->name, ==, "opacity");

  g_assert_finalize_object (named_target);
  g_assert_finalize_object (pspec_target);
  g_assert_finalize_object (widget);
}

static void
test_adw_property_animation_target_basic (void)
{
  GtkWidget *widget = g_object_ref_sink (gtk_button_new ());
  AdwAnimationTarget *target =
    adw_property_animation_target_new (G_OBJECT (widget), "opacity");
  AdwAnimation *animation =
    adw_timed_animation_new (widget, 1, 0, 100, g_object_ref (target));

  g_assert_true (G_APPROX_VALUE (gtk_widget_get_opacity (widget), 1, DBL_EPSILON));

  adw_animation_play (animation);

  /* Since the widget is not mapped, the animation will immediately finish */
  g_assert_true (G_APPROX_VALUE (gtk_widget_get_opacity (widget), 0, DBL_EPSILON));

  g_assert_finalize_object (animation);
  g_assert_finalize_object (target);
  g_assert_finalize_object (widget);
}

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

  g_test_add_func("/Adwaita/PropertyAnimationTarget/construct",
                  test_adw_property_animation_target_construct);
  g_test_add_func("/Adwaita/PropertyAnimationTarget/basic",
                  test_adw_property_animation_target_basic);

  return g_test_run();
}