File: testing.c

package info (click to toggle)
libpeas2 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: ansic: 8,018; cpp: 319; python: 178; javascript: 52; xml: 47; sh: 21; makefile: 17
file content (115 lines) | stat: -rw-r--r-- 3,766 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
/*
 * testing.c
 * This file is part of libpeas
 *
 * Copyright (C) 2010 - Garrett Regier
 *
 * libpeas is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libpeas is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include <stdlib.h>

#include <glib.h>

#if GLIB_CHECK_VERSION(2, 85, 0)
# include <girepository/girepository.h>
#else
# include <girepository.h>
#endif

#include <testing-util.h>

#include "testing.h"

void
testing_init (int    *argc,
              char ***argv)
{
  GError *error = NULL;
  static gboolean initialized = FALSE;
  GIRepository *repository;

  if (initialized)
    return;

  testing_util_envars ();

  g_test_init (argc, argv, NULL);

  /* Must be after g_test_init() changes the log settings*/
  testing_util_init ();

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
#if GLIB_CHECK_VERSION(2, 85, 0)
  repository = gi_repository_dup_default ();
  gi_repository_require_private (repository,
#else
  repository = g_object_ref (g_irepository_get_default ());
  g_irepository_require_private (repository,
#endif
                                 BUILDDIR "/tests/libpeas/introspection",
                                 "Introspection", API_VERSION_S, 0, &error);
  g_assert_no_error (error);
  g_clear_object (&repository);

  initialized = TRUE;
}

PeasEngine *
testing_engine_new_full (gboolean nonglobal_loaders)
{
  PeasEngine *engine;

  testing_util_push_log_hook ("*Bad plugin file *invalid.plugin*");
  testing_util_push_log_hook ("*Error loading *invalid.plugin*");

  testing_util_push_log_hook ("*Could not find 'Module' in "
                              "*info-missing-module.plugin*");
  testing_util_push_log_hook ("*Error loading *info-missing-module.plugin*");

  testing_util_push_log_hook ("*Could not find 'Name' in "
                              "*info-missing-name.plugin*");
  testing_util_push_log_hook ("*Error loading *info-missing-name.plugin*");

  testing_util_push_log_hook ("*Unkown 'Loader' in "
                              "*unkown-loader.plugin* does-not-exist");
  testing_util_push_log_hook ("*Error loading *unkown-loader.plugin*");

  testing_util_push_log_hook ("Bad plugin file '"
                              BUILDDIR "*" G_DIR_SEPARATOR_S "embedded*.plugin': "
                              "embedded plugins must be a resource");
  testing_util_push_log_hook ("Error loading '"
                              BUILDDIR "*" G_DIR_SEPARATOR_S "embedded*.plugin'*");

  testing_util_push_log_hook ("Bad plugin file '"
                              BUILDDIR "*embedded-invalid-loader.plugin': "
                              "embedded plugins must use the C plugin loader");

  /* Must be after pushing log hooks */
  engine = testing_util_engine_new_full (nonglobal_loaders);

  peas_engine_add_search_path (engine,
                               "resource:///org/gnome/libpeas/"
                               "tests/plugins", NULL);
  peas_engine_add_search_path (engine,
                               BUILDDIR "/tests/libpeas/plugins",
                               SRCDIR   "/tests/libpeas/plugins");

  return engine;
}