File: test-screenshot-manager.c

package info (click to toggle)
phosh 0.51.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 9,620 kB
  • sloc: ansic: 81,727; xml: 3,903; python: 502; sh: 456; makefile: 34; lisp: 22; javascript: 6
file content (93 lines) | stat: -rw-r--r-- 3,376 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (C) 2021 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "phosh-screenshot-dbus.h"
#include "shell-priv.h"

#include "testlib-full-shell.h"

#define BUS_NAME "org.gnome.Shell.Screenshot"
#define OBJECT_PATH "/org/gnome/Shell/Screenshot"

#define POP_TIMEOUT 50000000

static void
test_phosh_screenshot_png (PhoshTestFullShellFixture *fixture, gconstpointer unused)
{
  g_autoptr (GError) err = NULL;
  g_autoptr (PhoshDBusScreenshot) proxy = NULL;
  g_autofree char *used_name = NULL;
  g_autofree char *dirname = NULL;
  g_autofree char *filename = NULL;
  g_autofree char *path = NULL;
  gboolean success1, success2;

  dirname = g_build_filename (TEST_OUTPUT_DIR, __func__, NULL);
  filename = g_strdup_printf ("screenshot-%d.png", g_test_rand_int ());
  path = g_build_filename (dirname, filename, NULL);
  g_assert_cmpint (g_mkdir_with_parents (dirname, 0755), ==, 0);

  /* Wait until comp/shell are up */
  g_assert_nonnull (g_async_queue_timeout_pop (fixture->queue, POP_TIMEOUT));

  proxy = phosh_dbus_screenshot_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                        G_DBUS_PROXY_FLAGS_NONE,
                                                        BUS_NAME,
                                                        OBJECT_PATH,
                                                        NULL,
                                                        &err);
  g_assert_no_error (err);
  g_assert_true (PHOSH_DBUS_IS_SCREENSHOT_PROXY (proxy));

  success1 = phosh_dbus_screenshot_call_screenshot_sync (proxy,
                                                         FALSE,
                                                         TRUE,
                                                         path,
                                                         &success2,
                                                         &used_name,
                                                         NULL,
                                                         &err);

  g_assert_no_error (err);
  g_assert_true (success1);
  g_assert_true (success2);
  g_assert_cmpstr (used_name, ==, path);
  g_test_message ("Screenshot at %s", used_name);
  g_assert_true (g_file_test (used_name, G_FILE_TEST_EXISTS));

  success1 = phosh_dbus_screenshot_call_screenshot_sync (proxy,
                                                         FALSE,
                                                         TRUE,
                                                         path,
                                                         &success2,
                                                         &used_name,
                                                         NULL,
                                                         &err);

  g_assert_no_error (err);
  g_assert_true (success1);
  /* 2nd screenshot with identical file name fails */
  g_assert_false (success2);

  g_assert_cmpint (unlink (path), ==, 0);
}


int
main (int argc, char *argv[])
{
  g_autoptr (PhoshTestFullShellFixtureCfg) cfg = NULL;

  g_test_init (&argc, &argv, NULL);

  cfg = phosh_test_full_shell_fixture_cfg_new ("phosh-screenshot-manager");

  PHOSH_FULL_SHELL_TEST_ADD ("/phosh/dbus/screenshot-manager/png", cfg, test_phosh_screenshot_png);

  return g_test_run ();
}