Convert some gio tests to installed tests

This commit is contained in:
Matthias Clasen 2013-05-20 06:38:41 -04:00
parent f66016261a
commit 5e1f9173c3
16 changed files with 314 additions and 148 deletions

View File

@ -4,6 +4,8 @@ BUILT_SOURCES =
include $(top_srcdir)/Makefile.decl
insttestdir = $(pkglibexecdir)/installed-tests
SUBDIRS = gdbus-object-manager-example services
AM_CPPFLAGS = \
@ -28,7 +30,7 @@ LDADD = \
$(top_builddir)/gmodule/libgmodule-2.0.la \
$(top_builddir)/gio/libgio-2.0.la
TEST_PROGS += \
test_progs = \
io-stream \
memory-input-stream \
memory-output-stream \
@ -70,6 +72,8 @@ TEST_PROGS += \
credentials \
$(NULL)
TEST_PROGS += $(test_progs)
if HAVE_DBUS_DAEMON
TEST_PROGS += \
actions \
@ -289,84 +293,105 @@ gapplication_SOURCES = gapplication.c gdbus-sessionbus.h gdbus-sessionbus.c gdbu
gmenumodel_SOURCES = gmenumodel.c gdbus-sessionbus.h gdbus-sessionbus.c
TESTS_ENVIRONMENT = \
GLIB_MKENUMS=../../gobject/glib-mkenums \
GLIB_COMPILE_SCHEMAS=../glib-compile-schemas
schema_tests = \
schema-tests/array-default-not-in-choices.gschema.xml \
schema-tests/bad-choice.gschema.xml \
schema-tests/bad-key.gschema.xml \
schema-tests/bad-key2.gschema.xml \
schema-tests/bad-key3.gschema.xml \
schema-tests/bad-key4.gschema.xml \
schema-tests/bad-type.gschema.xml \
schema-tests/bare-alias.gschema.xml \
schema-tests/choice-alias.gschema.xml \
schema-tests/choice-bad.gschema.xml \
schema-tests/choice-badtype.gschema.xml \
schema-tests/choice-invalid-alias.gschema.xml \
schema-tests/choice-missing-value.gschema.xml \
schema-tests/choice-shadowed-alias.gschema.xml \
schema-tests/choice-upside-down.gschema.xml \
schema-tests/choice.gschema.xml \
schema-tests/choices-wrong-type.gschema.xml \
schema-tests/default-in-aliases.gschema.xml \
schema-tests/default-not-in-choices.gschema.xml \
schema-tests/default-out-of-range.gschema.xml \
schema-tests/empty-key.gschema.xml \
schema-tests/enum-with-aliases.gschema.xml \
schema-tests/enum-with-bad-default.gschema.xml \
schema-tests/enum-with-chained-alias.gschema.xml \
schema-tests/enum-with-choice.gschema.xml \
schema-tests/enum-with-invalid-alias.gschema.xml \
schema-tests/enum-with-repeated-alias.gschema.xml \
schema-tests/enum-with-repeated-nick.gschema.xml \
schema-tests/enum-with-repeated-value.gschema.xml \
schema-tests/enum-with-shadow-alias.gschema.xml \
schema-tests/enum.gschema.xml \
schema-tests/flags-aliased-default.gschema.xml \
schema-tests/flags-bad-default.gschema.xml \
schema-tests/flags-more-than-one-bit.gschema.xml \
schema-tests/flags-with-enum-attr.gschema.xml \
schema-tests/flags-with-enum-tag.gschema.xml \
schema-tests/extend-and-shadow-indirect.gschema.xml \
schema-tests/extend-and-shadow.gschema.xml \
schema-tests/extend-missing.gschema.xml \
schema-tests/extend-nonlist.gschema.xml \
schema-tests/extend-self.gschema.xml \
schema-tests/extend-wrong-list-indirect.gschema.xml \
schema-tests/extend-wrong-list.gschema.xml \
schema-tests/extending.gschema.xml \
schema-tests/from-docs.gschema.xml \
schema-tests/incomplete-list.gschema.xml \
schema-tests/inherit-gettext-domain.gschema.xml \
schema-tests/invalid-path.gschema.xml \
schema-tests/key-in-list-indirect.gschema.xml \
schema-tests/key-in-list.gschema.xml \
schema-tests/list-of-missing.gschema.xml \
schema-tests/missing-quotes.gschema.xml \
schema-tests/no-default.gschema.xml \
schema-tests/overflow.gschema.xml \
schema-tests/override-missing.gschema.xml \
schema-tests/override-range-error.gschema.xml \
schema-tests/override-then-key.gschema.xml \
schema-tests/override-twice.gschema.xml \
schema-tests/override-type-error.gschema.xml \
schema-tests/override.gschema.xml \
schema-tests/range-badtype.gschema.xml \
schema-tests/range-default-high.gschema.xml \
schema-tests/range-default-low.gschema.xml \
schema-tests/range-high-default.gschema.xml \
schema-tests/range-low-default.gschema.xml \
schema-tests/range-missing-max.gschema.xml \
schema-tests/range-missing-min.gschema.xml \
schema-tests/range-parse-error.gschema.xml \
schema-tests/range-wrong-type.gschema.xml \
schema-tests/range.gschema.xml \
schema-tests/wrong-category.gschema.xml
array-default-not-in-choices.gschema.xml \
bad-choice.gschema.xml \
bad-key.gschema.xml \
bad-key2.gschema.xml \
bad-key3.gschema.xml \
bad-key4.gschema.xml \
bad-type.gschema.xml \
bare-alias.gschema.xml \
choice-alias.gschema.xml \
choice-bad.gschema.xml \
choice-badtype.gschema.xml \
choice-invalid-alias.gschema.xml \
choice-missing-value.gschema.xml \
choice-shadowed-alias.gschema.xml \
choice-upside-down.gschema.xml \
choice.gschema.xml \
choices-wrong-type.gschema.xml \
default-in-aliases.gschema.xml \
default-not-in-choices.gschema.xml \
default-out-of-range.gschema.xml \
empty-key.gschema.xml \
enum-with-aliases.gschema.xml \
enum-with-bad-default.gschema.xml \
enum-with-chained-alias.gschema.xml \
enum-with-choice.gschema.xml \
enum-with-invalid-alias.gschema.xml \
enum-with-repeated-alias.gschema.xml \
enum-with-repeated-nick.gschema.xml \
enum-with-repeated-value.gschema.xml \
enum-with-shadow-alias.gschema.xml \
enum.gschema.xml \
flags-aliased-default.gschema.xml \
flags-bad-default.gschema.xml \
flags-more-than-one-bit.gschema.xml \
flags-with-enum-attr.gschema.xml \
flags-with-enum-tag.gschema.xml \
extend-and-shadow-indirect.gschema.xml \
extend-and-shadow.gschema.xml \
extend-missing.gschema.xml \
extend-nonlist.gschema.xml \
extend-self.gschema.xml \
extend-wrong-list-indirect.gschema.xml \
extend-wrong-list.gschema.xml \
extending.gschema.xml \
from-docs.gschema.xml \
incomplete-list.gschema.xml \
inherit-gettext-domain.gschema.xml \
invalid-path.gschema.xml \
key-in-list-indirect.gschema.xml \
key-in-list.gschema.xml \
list-of-missing.gschema.xml \
missing-quotes.gschema.xml \
no-default.gschema.xml \
overflow.gschema.xml \
override-missing.gschema.xml \
override-range-error.gschema.xml \
override-then-key.gschema.xml \
override-twice.gschema.xml \
override-type-error.gschema.xml \
override.gschema.xml \
range-badtype.gschema.xml \
range-default-high.gschema.xml \
range-default-low.gschema.xml \
range-high-default.gschema.xml \
range-low-default.gschema.xml \
range-missing-max.gschema.xml \
range-missing-min.gschema.xml \
range-parse-error.gschema.xml \
range-wrong-type.gschema.xml \
range.gschema.xml \
wrong-category.gschema.xml \
$(NULL)
schema_test_files = $(addprefix schema-tests/,$(schema_tests))
proxy_LDADD = $(LDADD) \
$(top_builddir)/gthread/libgthread-2.0.la
tls_certificate_SOURCES = tls-certificate.c gtesttlsbackend.c gtesttlsbackend.h
cert_tests = \
cert1.pem \
cert2.pem \
cert3.pem \
cert-key.pem \
cert-list.pem \
key8.pem \
key-cert.pem \
key.pem \
nothing.pem \
$(NULL)
cert_test_files = $(addprefix cert-tests/,$(cert_tests))
# -----------------------------------------------------------------------------
if OS_UNIX
@ -395,22 +420,14 @@ EXTRA_DIST += \
testenum.h \
enums.xml.template \
de.po \
$(schema_tests) \
$(schema_test_files) \
org.gtk.schemasourcecheck.gschema.xml \
appinfo-test.desktop \
appinfo-test2.desktop \
appinfo-test-gnome.desktop \
appinfo-test-notgnome.desktop \
test-codegen.xml \
cert1.pem \
cert2.pem \
cert3.pem \
key.pem \
key8.pem \
key-cert.pem \
cert-key.pem \
cert-list.pem \
nothing.pem \
$(cert_test_files) \
test.gresource.xml \
test1.txt \
test2.gresource.xml \
@ -446,10 +463,14 @@ plugin_resources.c: test4.gresource.xml Makefile $(shell $(glib_compile_resource
test.gresource: test.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test.gresource.xml)
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) $<
if BUILDOPT_INSTALL_TESTS
insttest_LTLIBRARIES = libresourceplugin.la
else
noinst_LTLIBRARIES = libresourceplugin.la
endif
libresourceplugin_la_SOURCES = resourceplugin.c plugin_resources.c
libresourceplugin_la_LDFLAGS = -avoid-version -module $(no_undefined) -rpath $(libdir)
libresourceplugin_la_LDFLAGS = -avoid-version -module $(no_undefined) -rpath $(insttestdir)
libresourceplugin_la_LIBADD = $(LDADD)
CLEANFILES = gdbus-test-codegen-generated.[ch] gdbus-test-codegen-generated-doc-*.xml test_resources2.[ch] plugin_resources.c
@ -467,3 +488,36 @@ DISTCLEANFILES = \
distclean-local:
rm -rf xdgdatahome xdgdatadir
test_files = \
contexts.c \
g-icon.c \
enums.xml.template \
testenum.h \
org.gtk.test.gschema.xml \
org.gtk.schemasourcecheck.gschema.xml \
test.gresource \
$(NULL)
if BUILDOPT_INSTALL_TESTS
insttest_PROGRAMS = $(test_progs)
schematestdir = $(insttestdir)/schema-tests
schematest_DATA = $(schema_test_files)
certtestdir = $(insttestdir)/cert-tests
certtest_DATA = $(cert_test_files)
testdatadir = $(insttestdir)
testdata_DATA = $(test_files)
testmetadir = $(datadir)/installed-tests/$(PACKAGE)
testmeta_DATA = $(test_progs:=.test)
%.test: % Makefile
$(AM_V_GEN) (echo '[Test]' > $@.tmp; \
echo 'Type=session' >> $@.tmp; \
echo 'Exec=env G_TEST_DATA=$(pkglibexecdir)/installed-tests $(pkglibexecdir)/installed-tests/$<' >> $@.tmp; \
mv $@.tmp $@)
endif

View File

@ -2,7 +2,9 @@
#include <stdlib.h>
#include <string.h>
#define TEST_FILE (SRCDIR "/Makefile.am")
static const gchar *datapath;
static const gchar *test_file;
char *test_file_buffer;
gsize test_file_size;
static char async_read_buffer[8192];
@ -105,7 +107,7 @@ test1_thread (gpointer user_data)
g_main_context_push_thread_default (context);
g_assert (g_main_context_get_thread_default () == context);
file = g_file_new_for_path (TEST_FILE);
file = g_file_new_for_path (test_file);
g_assert (g_file_supports_thread_contexts (file));
loop = g_main_loop_new (context, FALSE);
@ -146,7 +148,7 @@ test_context_independence (void)
g_main_context_push_thread_default (context);
g_assert (g_main_context_get_thread_default () == context);
file = g_file_new_for_path (TEST_FILE);
file = g_file_new_for_path (test_file);
g_assert (g_file_supports_thread_contexts (file));
/* Add a timeout to the main loop, to fail immediately if it gets run */
@ -185,9 +187,15 @@ main (int argc, char **argv)
GError *error = NULL;
int ret;
if (g_getenv ("G_TEST_DATA"))
datapath = g_getenv ("G_TEST_DATA");
else
datapath = SRCDIR;
g_test_init (&argc, &argv, NULL);
g_file_get_contents (TEST_FILE, &test_file_buffer,
test_file = g_strconcat (datapath, "/contexts.c", NULL);
g_file_get_contents (test_file, &test_file_buffer,
&test_file_size, &error);
g_assert_no_error (error);

View File

@ -27,6 +27,8 @@
#include <stdlib.h>
#include <string.h>
static const gchar *datapath;
static void
test_g_icon_to_string (void)
{
@ -465,8 +467,11 @@ test_file_icon (void)
GError *error;
GInputStream *stream;
gchar *str;
gchar *path;
file = g_file_new_for_path (SRCDIR "/g-icon.c");
path = g_strconcat (datapath, "/g-icon.c", NULL);
file = g_file_new_for_path (path);
icon = g_file_icon_new (file);
g_object_unref (file);
@ -484,12 +489,19 @@ test_file_icon (void)
g_object_unref (icon);
g_object_unref (icon2);
g_free (path);
}
int
main (int argc,
char *argv[])
{
if (g_getenv ("G_TEST_DATA"))
datapath = g_getenv ("G_TEST_DATA");
else
datapath = SRCDIR;
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/icons/to-string", test_g_icon_to_string);

View File

@ -5,6 +5,9 @@
#include <gio/gio.h>
#include <gstdio.h>
const gchar *datapath;
const gchar *glib_compile_schemas;
typedef struct {
const gchar *name;
const gchar *opt;
@ -16,9 +19,9 @@ test_schema_do_compile (gpointer data)
{
SchemaTest *test = (SchemaTest *) data;
gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
gchar *path = g_build_filename (SRCDIR, "schema-tests", filename, NULL);
gchar *path = g_build_filename (datapath, "schema-tests", filename, NULL);
gchar *argv[] = {
"../glib-compile-schemas",
(gchar*)glib_compile_schemas,
"--strict",
"--dry-run",
"--schema-file", path,
@ -139,6 +142,16 @@ main (int argc, char *argv[])
setlocale (LC_ALL, "");
if (g_getenv ("G_TEST_DATA"))
datapath = g_getenv ("G_TEST_DATA");
else
datapath = SRCDIR;
if (g_getenv ("GLIB_COMPILE_SCHEMAS"))
glib_compile_schemas = g_getenv ("GLIB_COMPILE_SCHEMAS");
else
glib_compile_schemas = "/usr/bin/glib-compile-schemas";
g_test_init (&argc, &argv, NULL);
for (i = 0; i < G_N_ELEMENTS (tests); ++i)

View File

@ -8,6 +8,7 @@
#include "testenum.h"
static const gchar *datapath;
static gboolean backend_set;
/* These tests rely on the schemas in org.gtk.test.gschema.xml
@ -2247,40 +2248,58 @@ main (int argc, char *argv[])
setlocale (LC_ALL, "");
if (g_getenv ("G_TEST_DATA"))
datapath = g_getenv ("G_TEST_DATA");
else
datapath = SRCDIR;
g_test_init (&argc, &argv, NULL);
if (!g_test_subprocess ())
{
const gchar *glib_mkenums;
const gchar *glib_compile_schemas;
gchar *cmdline;
backend_set = g_getenv ("GSETTINGS_BACKEND") != NULL;
g_setenv ("XDG_DATA_DIRS", ".", TRUE);
g_setenv ("XDG_DATA_DIRS", datapath, TRUE);
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
if (!backend_set)
g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
g_remove ("org.gtk.test.enums.xml");
g_assert (g_spawn_command_line_sync ("../../gobject/glib-mkenums "
"--template " SRCDIR "/enums.xml.template "
SRCDIR "/testenum.h",
&enums, NULL, &result, NULL));
if (g_getenv ("GLIB_MKENUMS"))
glib_mkenums = g_getenv ("GLIB_MKENUMS");
else
glib_mkenums = "glib-mkenums";
cmdline = g_strdup_printf ("%s --template %s/enums.xml.template %s/testenum.h", glib_mkenums, datapath, datapath);
g_assert (g_spawn_command_line_sync (cmdline, &enums, NULL, &result, NULL));
g_assert (result == 0);
g_assert (g_file_set_contents ("org.gtk.test.enums.xml", enums, -1, NULL));
g_free (enums);
g_remove ("gschemas.compiled");
g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=. "
"--schema-file=org.gtk.test.enums.xml "
"--schema-file=" SRCDIR "/org.gtk.test.gschema.xml",
NULL, NULL, &result, NULL));
g_assert (result == 0);
g_free (cmdline);
g_remove ("schema-source/gschemas.compiled");
g_mkdir ("schema-source", 0777);
g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=schema-source "
"--schema-file=" SRCDIR "/org.gtk.schemasourcecheck.gschema.xml",
NULL, NULL, &result, NULL));
if (g_getenv ("GLIB_COMPILE_SCHEMAS"))
glib_compile_schemas = g_getenv ("GLIB_COMPILE_SCHEMAS");
else
glib_compile_schemas = "glib-compile-schemas";
cmdline = g_strdup_printf ("%s --targetdir=. --schema-file=org.gtk.test.enums.xml --schema-file=%s/org.gtk.test.gschema.xml", glib_compile_schemas, datapath);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, &result, NULL));
g_assert (result == 0);
g_free (cmdline);
g_mkdir ("schema-source", 0777);
g_remove ("schema-source/gschemas.compiled");
cmdline = g_strdup_printf ("%s --targetdir=schema-source --schema-file=%s/org.gtk.schemasourcecheck.gschema.xml", glib_compile_schemas, datapath);
g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, &result, NULL));
g_assert (result == 0);
g_free (cmdline);
}
g_test_add_func ("/gsettings/basic", test_basic);

View File

@ -23,6 +23,8 @@
#include "gconstructor.h"
#include "test_resources2.h"
const gchar *datapath;
static void
test_resource (GResource *resource)
{
@ -143,15 +145,18 @@ test_resource_file (void)
{
GResource *resource;
GError *error = NULL;
gchar *path;
resource = g_resource_load ("not-there", &error);
g_assert (resource == NULL);
g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
g_clear_error (&error);
resource = g_resource_load ("test.gresource", &error);
path = g_build_filename (datapath, "test.gresource", NULL);
resource = g_resource_load (path, &error);
g_assert (resource != NULL);
g_assert_no_error (error);
g_free (path);
test_resource (resource);
g_resource_unref (resource);
@ -166,10 +171,12 @@ test_resource_data (void)
char *content;
gsize content_size;
GBytes *data;
gchar *path;
loaded_file = g_file_get_contents ("test.gresource", &content, &content_size,
NULL);
path = g_build_filename (datapath, "test.gresource", NULL);
loaded_file = g_file_get_contents (path, &content, &content_size, NULL);
g_assert (loaded_file);
g_free (path);
data = g_bytes_new_take (content, content_size);
resource = g_resource_new_from_data (data, &error);
@ -194,10 +201,13 @@ test_resource_registered (void)
char **children;
GInputStream *in;
char buffer[128];
gchar *path;
resource = g_resource_load ("test.gresource", &error);
path = g_build_filename (datapath, "test.gresource", NULL);
resource = g_resource_load (path, &error);
g_assert (resource != NULL);
g_assert_no_error (error);
g_free (path);
found = g_resources_get_info ("/test1.txt",
G_RESOURCE_LOOKUP_FLAGS_NONE,
@ -396,14 +406,11 @@ test_resource_module (void)
if (g_module_supported ())
{
char *dir, *path;
char *path;
dir = g_get_current_dir ();
path = g_strconcat (dir, G_DIR_SEPARATOR_S "libresourceplugin", NULL);
path = g_build_filename (datapath, "libresourceplugin", NULL);
module = g_io_module_new (path);
g_free (path);
g_free (dir);
error = NULL;
@ -456,11 +463,13 @@ test_uri_query_info (void)
GBytes *data;
GFile *file;
GFileInfo *info;
gchar *path;
const char *content_type;
loaded_file = g_file_get_contents ("test.gresource", &content, &content_size,
NULL);
path = g_build_filename (datapath, "test.gresource", NULL);
loaded_file = g_file_get_contents (path, &content, &content_size, NULL);
g_assert (loaded_file);
g_free (path);
data = g_bytes_new_take (content, content_size);
resource = g_resource_new_from_data (data, &error);
@ -507,10 +516,12 @@ test_uri_file (void)
gchar buf[1024];
gboolean ret;
gssize skipped;
gchar *path;
loaded_file = g_file_get_contents ("test.gresource", &content, &content_size,
NULL);
path = g_build_filename (datapath, "test.gresource", NULL);
loaded_file = g_file_get_contents (path, &content, &content_size, NULL);
g_assert (loaded_file);
g_free (path);
data = g_bytes_new_take (content, content_size);
resource = g_resource_new_from_data (data, &error);
@ -630,6 +641,11 @@ int
main (int argc,
char *argv[])
{
if (g_getenv ("G_TEST_DATA"))
datapath = g_getenv ("G_TEST_DATA");
else
datapath = SRCDIR;
g_test_init (&argc, &argv, NULL);
_g_test2_register_resource ();

View File

@ -26,6 +26,8 @@
#include "gtesttlsbackend.h"
gchar *datapath;
typedef struct
{
gchar *cert_pems[3];
@ -40,12 +42,15 @@ pem_parser (const Reference *ref)
gchar *pem;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
gchar *path;
GError *error = NULL;
/* Check PEM parsing in certificate, private key order. */
g_file_get_contents (SRCDIR "/cert-key.pem", &pem, NULL, &error);
path = g_build_filename (datapath, "cert-key.pem", NULL);
g_file_get_contents (path, &pem, NULL, &error);
g_assert_no_error (error);
g_assert (pem);
g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error);
@ -70,9 +75,11 @@ pem_parser (const Reference *ref)
g_free (pem);
/* Check PEM parsing in private key, certificate order */
g_file_get_contents (SRCDIR "/key-cert.pem", &pem, NULL, &error);
path = g_build_filename (datapath, "key-cert.pem", NULL);
g_file_get_contents (path, &pem, NULL, &error);
g_assert_no_error (error);
g_assert (pem);
g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error);
@ -92,9 +99,11 @@ pem_parser (const Reference *ref)
g_object_unref (cert);
/* Check certificate only PEM */
g_file_get_contents (SRCDIR "/cert1.pem", &pem, NULL, &error);
path = g_build_filename (datapath, "cert1.pem", NULL);
g_file_get_contents (path, &pem, NULL, &error);
g_assert_no_error (error);
g_assert (pem);
g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error);
@ -113,9 +122,11 @@ pem_parser (const Reference *ref)
g_object_unref (cert);
/* Check error with private key only PEM */
g_file_get_contents (SRCDIR "/key.pem", &pem, NULL, &error);
path = g_build_filename (datapath, "key.pem", NULL);
g_file_get_contents (path, &pem, NULL, &error);
g_assert_no_error (error);
g_assert (pem);
g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
@ -130,11 +141,14 @@ from_file (const Reference *ref)
GTlsCertificate *cert;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
gchar *path;
GError *error = NULL;
cert = g_tls_certificate_new_from_file (SRCDIR "/key-cert.pem", &error);
path = g_build_filename (datapath, "key-cert.pem", NULL);
cert = g_tls_certificate_new_from_file (path, &error);
g_assert_no_error (error);
g_assert (cert);
g_free (path);
g_object_get (cert,
"certificate-pem", &parsed_cert_pem,
@ -155,13 +169,16 @@ from_files (const Reference *ref)
GTlsCertificate *cert;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
gchar *path, *path2;
GError *error = NULL;
cert = g_tls_certificate_new_from_files (SRCDIR "/cert1.pem",
SRCDIR "/key.pem",
&error);
path = g_build_filename (datapath, "cert1.pem", NULL);
path2 = g_build_filename (datapath, "key.pem", NULL);
cert = g_tls_certificate_new_from_files (path, path2, &error);
g_assert_no_error (error);
g_assert (cert);
g_free (path);
g_free (path2);
g_object_get (cert,
"certificate-pem", &parsed_cert_pem,
@ -176,29 +193,32 @@ from_files (const Reference *ref)
g_object_unref (cert);
/* Missing private key */
cert = g_tls_certificate_new_from_files (SRCDIR "/cert1.pem",
SRCDIR "/cert2.pem",
&error);
path = g_build_filename (datapath, "cert1.pem", NULL);
path2 = g_build_filename (datapath, "cert2.pem", NULL);
cert = g_tls_certificate_new_from_files (path, path2, &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error);
g_assert (cert == NULL);
g_free (path);
g_free (path2);
/* Missing certificate */
cert = g_tls_certificate_new_from_files (SRCDIR "/key.pem",
SRCDIR "/key.pem",
&error);
path = g_build_filename (datapath, "key.pem", NULL);
cert = g_tls_certificate_new_from_files (path, path, &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error);
g_assert (cert == NULL);
g_free (path);
/* Using this method twice with a file containing both private key and
* certificate as a way to inforce private key presence is a fair use */
cert = g_tls_certificate_new_from_files (SRCDIR "/key-cert.pem",
SRCDIR "/key-cert.pem",
&error);
* certificate as a way to inforce private key presence is a fair use
*/
path = g_build_filename (datapath, "key-cert.pem", NULL);
cert = g_tls_certificate_new_from_files (path, path, &error);
g_assert_no_error (error);
g_assert (cert);
g_object_unref (cert);
g_free (path);
}
@ -208,13 +228,16 @@ from_files_pkcs8 (const Reference *ref)
GTlsCertificate *cert;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
gchar *path, *path2;
GError *error = NULL;
cert = g_tls_certificate_new_from_files (SRCDIR "/cert1.pem",
SRCDIR "/key8.pem",
&error);
path = g_build_filename (datapath, "cert1.pem", NULL);
path2 = g_build_filename (datapath, "key8.pem", NULL);
cert = g_tls_certificate_new_from_files (path, path2, &error);
g_assert_no_error (error);
g_assert (cert);
g_free (path);
g_free (path2);
g_object_get (cert,
"certificate-pem", &parsed_cert_pem,
@ -234,11 +257,14 @@ list_from_file (const Reference *ref)
{
GList *list, *l;
GError *error = NULL;
gchar *path;
int i;
list = g_tls_certificate_list_new_from_file (SRCDIR "/cert-list.pem", &error);
path = g_build_filename (datapath, "cert-list.pem", NULL);
list = g_tls_certificate_list_new_from_file (path, &error);
g_assert_no_error (error);
g_assert_cmpint (g_list_length (list), ==, 3);
g_free (path);
l = list;
for (i = 0; i < 3; i++)
@ -256,9 +282,11 @@ list_from_file (const Reference *ref)
g_list_free_full (list, g_object_unref);
/* Empty list is not an error */
list = g_tls_certificate_list_new_from_file (SRCDIR "/nothing.pem", &error);
path = g_build_filename (datapath, "nothing.pem", NULL);
list = g_tls_certificate_list_new_from_file (path, &error);
g_assert_no_error (error);
g_assert_cmpint (g_list_length (list), ==, 0);
g_free (path);
}
int
@ -268,27 +296,43 @@ main (int argc,
int rtv;
Reference ref;
GError *error = NULL;
gchar *path;
if (g_getenv ("G_TEST_DATA"))
datapath = g_build_filename (g_getenv ("G_TEST_DATA"), "cert-tests", NULL);
else
datapath = g_build_filename (SRCDIR, "cert-tests", NULL);
g_test_init (&argc, &argv, NULL);
_g_test_tls_backend_get_type ();
/* Load reference PEM */
g_file_get_contents (SRCDIR "/cert1.pem", &ref.cert_pems[0], NULL, &error);
path = g_build_filename (datapath, "cert1.pem", NULL);
g_file_get_contents (path, &ref.cert_pems[0], NULL, &error);
g_assert_no_error (error);
g_assert (ref.cert_pems[0]);
g_file_get_contents (SRCDIR "/cert2.pem", &ref.cert_pems[1], NULL, &error);
g_free (path);
path = g_build_filename (datapath, "cert2.pem", NULL);
g_file_get_contents (path, &ref.cert_pems[1], NULL, &error);
g_assert_no_error (error);
g_assert (ref.cert_pems[1]);
g_file_get_contents (SRCDIR "/cert3.pem", &ref.cert_pems[2], NULL, &error);
g_free (path);
path = g_build_filename (datapath, "cert3.pem", NULL);
g_file_get_contents (path, &ref.cert_pems[2], NULL, &error);
g_assert_no_error (error);
g_assert (ref.cert_pems[2]);
g_file_get_contents (SRCDIR "/key.pem", &ref.key_pem, NULL, &error);
g_free (path);
path = g_build_filename (datapath, "key.pem", NULL);
g_file_get_contents (path, &ref.key_pem, NULL, &error);
g_assert_no_error (error);
g_assert (ref.key_pem);
g_file_get_contents (SRCDIR "/key8.pem", &ref.key8_pem, NULL, &error);
g_free (path);
path = g_build_filename (datapath, "key8.pem", NULL);
g_file_get_contents (path, &ref.key8_pem, NULL, &error);
g_assert_no_error (error);
g_assert (ref.key8_pem);
g_free (path);
g_test_add_data_func ("/tls-certificate/pem-parser",
&ref, (GTestDataFunc)pem_parser);