[retro-gtk/wip/aplazas/tests] Add tests



commit 2ed9fce24c8a1c16b3fc7462e7c199a48ab96c24
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue May 9 11:07:31 2017 +0200

    Add tests

 .editorconfig                                 |   36 ++++++
 Makefile.am                                   |    2 +-
 configure.ac                                  |    6 +
 retro-gtk/retro-environment.c                 |    4 +-
 tests/Makefile.am                             |    5 +
 tests/data/Makefile.am                        |    8 ++
 tests/data/elix-nu/README                     |    6 +
 tests/data/elix-nu/elix-nu-pal.sfc            |  Bin 0 -> 4194304 bytes
 tests/libretro-bsnes-tests/test1.test         |    2 +
 tests/libretro-cores/bsnes_balanced.libretro  |   11 ++
 tests/libretro-cores/libretro-bsnes.json      |   30 +++++
 tests/libretro-cores/libretro-samples.json    |   23 ++++
 tests/libretro-cores/samples-Makefile         |   13 ++
 tests/org.gnome.RetroGtkTests.json            |   51 ++++++++
 tests/retro-gtk-tests                         |    5 +
 tests/retro-tester/Makefile.am                |   69 +++++++++++
 tests/retro-tester/retro-tester-window.c      |   59 +++++++++
 tests/retro-tester/retro-tester-window.h      |   19 +++
 tests/retro-tester/retro-tester-window.ui     |   15 +++
 tests/retro-tester/retro-tester.c             |  161 +++++++++++++++++++++++++
 tests/retro-tester/retro-tester.gresource.xml |    7 +
 21 files changed, 529 insertions(+), 3 deletions(-)
---
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..5c9f919
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,36 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+
+[*.vala]
+indent_size = 4
+tab_size = 4
+indent_style = tab
+
+[*.{c,h}]
+indent_size = 2
+tab_size = 2
+indent_style = space
+
+[*.{ui,xml,modules}]
+indent_size = 2
+tab_size = 2
+indent_style = space
+
+[*.py]
+indent_size = 4
+tab_size = 4
+indent_style = space
+
+[*.{ac,am,mk}]
+indent_size = 8
+tab_size = 8
+indent_style = tab
+
+[*.sh]
+indent_size = 8
+tab_size = 8
+indent_style = space
diff --git a/Makefile.am b/Makefile.am
index 02b3f72..296bc4f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 NULL =
 
-SUBDIRS = retro-gtk po
+SUBDIRS = retro-gtk tests po
 
 dist_doc_DATA = \
        README \
diff --git a/configure.ac b/configure.ac
index d40e67e..4fc49d3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,6 +14,9 @@ AM_PROG_AR
 
 AM_PROG_VALAC
 
+# GResource
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
 GOBJECT_INTROSPECTION_CHECK([0.6.7])
 
 dnl ***************************************************************************
@@ -50,4 +53,7 @@ AC_OUTPUT([
 Makefile
 retro-gtk/retro-gtk-0.10.pc
 retro-gtk/Makefile
+tests/Makefile
+tests/data/Makefile
+tests/retro-tester/Makefile
 po/Makefile.in])
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 40099f6..b16b315 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -366,7 +366,7 @@ static void on_input_poll () {
        input = retro_core_get_input_interface (self);
 
        if (input == NULL)
-               g_return_if_reached ();
+               return 0;
 
        retro_input_poll (input);
 }
@@ -383,7 +383,7 @@ static gint16 on_input_state (guint port, guint device, guint index, guint id) {
        input = retro_core_get_input_interface (self);
 
        if (input == NULL)
-               g_return_val_if_reached (0);
+               return 0;
 
        return retro_input_get_state (input, port, device, index, id);
 }
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..858c71b
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,5 @@
+SUBDIRS = data retro-tester
+
+dist_bin_SCRIPTS = retro-gtk-tests
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
new file mode 100644
index 0000000..4f81afa
--- /dev/null
+++ b/tests/data/Makefile.am
@@ -0,0 +1,8 @@
+gamesdir = $(datadir)/retro-gtk/tests/games
+games_DATA = \
+       elix-nu/elix-nu-pal.sfc \
+       $(NULL)
+
+EXTRA_DIST = $(games_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/data/elix-nu/README b/tests/data/elix-nu/README
new file mode 100644
index 0000000..fce760d
--- /dev/null
+++ b/tests/data/elix-nu/README
@@ -0,0 +1,6 @@
+Nu by Elix
+
+As far as we know this is available in the public domain, please contact us if
+we are wrong.
+
+Source: http://www.pouet.net/prod.php?which=62927
diff --git a/tests/data/elix-nu/elix-nu-pal.sfc b/tests/data/elix-nu/elix-nu-pal.sfc
new file mode 100644
index 0000000..56edc9b
Binary files /dev/null and b/tests/data/elix-nu/elix-nu-pal.sfc differ
diff --git a/tests/libretro-bsnes-tests/test1.test b/tests/libretro-bsnes-tests/test1.test
new file mode 100644
index 0000000..d4193c7
--- /dev/null
+++ b/tests/libretro-bsnes-tests/test1.test
@@ -0,0 +1,2 @@
+load /usr/games/elix-nu/elix-nu-pal.sfc
+
diff --git a/tests/libretro-cores/bsnes_balanced.libretro b/tests/libretro-cores/bsnes_balanced.libretro
new file mode 100644
index 0000000..b105c53
--- /dev/null
+++ b/tests/libretro-cores/bsnes_balanced.libretro
@@ -0,0 +1,11 @@
+[Libretro]
+Type=Emulator
+Version=1.0
+Name=bsnes Balanced
+Module=bsnes_balanced_libretro.so
+LibretroVersion=1
+Authors=byuu;
+License=GPL-3.0;
+
+[Platform:SuperNintendoEntertainmentSystem]
+MimeType=application/vnd.nintendo.snes.rom;
diff --git a/tests/libretro-cores/libretro-bsnes.json b/tests/libretro-cores/libretro-bsnes.json
new file mode 100644
index 0000000..d89e384
--- /dev/null
+++ b/tests/libretro-cores/libretro-bsnes.json
@@ -0,0 +1,30 @@
+        {
+            "name": "libretro-bsnes",
+            "no-autogen": true,
+            "make-args": [
+                "prefix=/app",
+                "core_installdir=/app/lib/libretro",
+                "profile=balanced"
+            ],
+            "make-install-args": [
+                "prefix=/app",
+                "core_installdir=/app/lib/libretro",
+                "profile=balanced"
+            ],
+            "post-install": [
+                /* TODO: Send that upstream */
+                "mkdir -p /app/lib/libretro/",
+                "install -m644 -p bsnes_balanced.libretro /app/lib/libretro/"
+            ],
+            "sources": [
+                {
+                    "type": "git",
+                    "url": "https://github.com/libretro/bsnes-libretro.git";,
+                    "branch": "libretro"
+                },
+                {
+                    "type": "file",
+                    "path": "libretro-cores/bsnes_balanced.libretro"
+                }
+            ]
+        }
diff --git a/tests/libretro-cores/libretro-samples.json b/tests/libretro-cores/libretro-samples.json
new file mode 100644
index 0000000..8efe460
--- /dev/null
+++ b/tests/libretro-cores/libretro-samples.json
@@ -0,0 +1,23 @@
+        {
+            "name": "libretro-samples",
+            "no-autogen": true,
+            "make-args": [
+                "--makefile=Makefile",
+                "prefix=/app"
+            ],
+            "make-install-args": [
+                "--makefile=Makefile",
+                "prefix=/app"
+            ],
+            "sources": [
+                {
+                    "type": "git",
+                    "url": "https://github.com/libretro/libretro-samples.git";
+                },
+                {
+                    "type": "file",
+                    "path": "libretro-cores/samples-Makefile",
+                    "dest-filename": "Makefile"
+                }
+            ]
+        }
diff --git a/tests/libretro-cores/samples-Makefile b/tests/libretro-cores/samples-Makefile
new file mode 100644
index 0000000..d06f421
--- /dev/null
+++ b/tests/libretro-cores/samples-Makefile
@@ -0,0 +1,13 @@
+NULL=
+
+CORES= \
+       tests/test/test_libretro.so \
+       $(NULL)
+
+all: tests/test/test_libretro.so
+
+tests/test/test_libretro.so:
+       make -C $(@D)
+
+install: $(CORES)
+       install -Dp -m755 tests/test/test_libretro.so $(DESTDIR)$(prefix)/lib/libretro/test_libretro.so
diff --git a/tests/org.gnome.RetroGtkTests.json b/tests/org.gnome.RetroGtkTests.json
new file mode 100644
index 0000000..80f9c13
--- /dev/null
+++ b/tests/org.gnome.RetroGtkTests.json
@@ -0,0 +1,51 @@
+{
+    "app-id": "org.gnome.RetroGtkDemo",
+    "runtime": "org.gnome.Platform",
+    "runtime-version": "master",
+    "sdk": "org.gnome.Sdk",
+    "command": "retro-gtk-tests",
+    "tags": ["nightly"],
+    "desktop-file-name-prefix": "(Nightly) ",
+    "finish-args": [
+        /* X11 + XShm access */
+        "--share=ipc", "--socket=x11",
+        /* Wayland access */
+        "--socket=wayland",
+        /* PulseAudio access */
+        "--device=dri", "--socket=pulseaudio",
+        /* Needed to find the ROMs */
+        "--filesystem=home:ro"
+    ],
+    "build-options" : {
+        "cflags": "-O2 -g",
+        "cxxflags": "-O2 -g"
+    },
+    "cleanup": ["/include", "/lib/pkgconfig",
+                "/share/pkgconfig", "/share/aclocal",
+                "/man", "/share/man", "/share/gtk-doc",
+                "*.la", "*.a",
+                "/lib/girepository-1.0",
+                "/share/dbus-1", "/share/doc", "/share/gir-1.0"
+    ],
+    "modules": [
+        /* Emulator cores for libretro
+
+           We build them first, because some of them are very big, and they
+           change more rarely than the rest of the modules. */
+        "libretro-cores/libretro-bsnes.json",
+        "libretro-cores/libretro-samples.json",
+        /* End libretro cores */
+        {
+            "name": "retro-gtk",
+            "config-opts": [
+                "--disable-static"
+            ],
+            "sources": [
+                {
+                    "type": "git",
+                    "url": "https://git.gnome.org/browse/retro-gtk";
+                }
+            ]
+        }
+    ]
+}
diff --git a/tests/retro-gtk-tests b/tests/retro-gtk-tests
new file mode 100644
index 0000000..fc84549
--- /dev/null
+++ b/tests/retro-gtk-tests
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+retro-tester /app/lib/libretro/test_libretro.so
+#retro-tester /app/lib/libretro/bsnes_balanced_libretro.so \
+#             /app/share/retro-gtk/tests/games/elix-nu-pal.sfc
diff --git a/tests/retro-tester/Makefile.am b/tests/retro-tester/Makefile.am
new file mode 100644
index 0000000..0fd1b73
--- /dev/null
+++ b/tests/retro-tester/Makefile.am
@@ -0,0 +1,69 @@
+NULL =
+
+bin_PROGRAMS = retro-tester
+
+BUILT_SOURCES = \
+       retro-tester-resources.c \
+       retro-tester-resources.h \
+       $(NULL)
+
+retro_tester_SOURCES = \
+       retro-tester.c \
+       retro-tester-window.c \
+       $(BUILT_SOURCES) \
+       $(NULL)
+
+retro_tester_CFLAGS = \
+       $(RETRO_GTK_CFLAGS) \
+       $(GAMEPADS_CFLAGS) \
+       $(UDEV_CFLAGS) \
+       -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+       -DGAMES_PLUGINS_DIR=\"$(libdir)/gnome-games/plugins\" \
+       $(NULL)
+
+retro_tester_CPPFLAGS = \
+       -I$(top_srcdir) \
+       -I$(top_builddir)/retro-gtk \
+       -I$(top_srcdir)/retro-gtk \
+       -DRETRO_GTK_USE_UNSTABLE_API \
+       $(NULL)
+
+retro_tester_DEPENDENCIES = \
+       $(top_builddir)/retro-gtk/libretro-gtk.la \
+       $(NULL)
+
+retro_tester_LDADD = \
+       $(RETRO_GTK_LIBS) \
+       $(top_builddir)/retro-gtk/libretro-gtk.la \
+       $(NULL)
+
+gresource = $(srcdir)/retro-tester.gresource.xml
+
+resource_files = $(shell \
+       $(GLIB_COMPILE_RESOURCES) \
+       --sourcedir=$(srcdir) \
+       --generate-dependencies \
+       $(gresource))
+
+retro-tester-resources.c: $(gresource) $(resource_files)
+       $(AM_V_GEN) \
+       $(GLIB_COMPILE_RESOURCES) \
+               --target=$@ \
+               --sourcedir=$(srcdir) \
+               --generate-source \
+               --c-name retro_tester \
+               $<
+
+retro-tester-resources.h: $(gresource) $(resource_files)
+       $(AM_V_GEN) \
+       $(GLIB_COMPILE_RESOURCES) \
+               --target=$@ \
+               --sourcedir=$(srcdir) \
+               --generate-header \
+               --c-name retro_tester \
+               $<
+
+CLEANFILES = $(BUILT_SOURCES)
+EXTRA_DIST = $(resource_files) $(gresource)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/retro-tester/retro-tester-window.c b/tests/retro-tester/retro-tester-window.c
new file mode 100644
index 0000000..18cec27
--- /dev/null
+++ b/tests/retro-tester/retro-tester-window.c
@@ -0,0 +1,59 @@
+// This file is part of retro-gtk. License: GPLv3
+
+#include "retro-tester-window.h"
+
+struct _RetroTesterWindow
+{
+  GtkApplicationWindow parent_instance;
+
+  GtkBuilder *builder;
+  RetroCairoDisplay *display;
+  RetroMainLoop *loop;
+};
+
+G_DEFINE_TYPE (RetroTesterWindow, retro_tester_window, GTK_TYPE_APPLICATION_WINDOW)
+
+#define UI_RESOURCE "/org/gnome/retro-gtk/tester/retro-tester-window.ui"
+
+RetroTesterWindow *
+retro_tester_window_new (RetroCore *core)
+{
+  RetroTesterWindow *self;
+
+  g_return_val_if_fail (core != NULL, NULL);
+
+  self = g_object_new (RETRO_TYPE_TESTER_WINDOW, NULL);
+
+  retro_cairo_display_set_core (self->display, core);
+
+  self->loop = retro_main_loop_new (core);
+  retro_main_loop_start (self->loop);
+
+  return self;
+}
+
+static void
+retro_tester_window_finalize (GObject *object)
+{
+  RetroTesterWindow *self = RETRO_TESTER_WINDOW (object);
+
+  G_OBJECT_CLASS (retro_tester_window_parent_class)->finalize (object);
+}
+
+static void
+retro_tester_window_class_init (RetroTesterWindowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = retro_tester_window_finalize;
+
+  gtk_widget_class_set_template_from_resource (widget_class, UI_RESOURCE);
+  gtk_widget_class_bind_template_child (widget_class, RetroTesterWindow, display);
+}
+
+static void
+retro_tester_window_init (RetroTesterWindow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/tests/retro-tester/retro-tester-window.h b/tests/retro-tester/retro-tester-window.h
new file mode 100644
index 0000000..cbeb181
--- /dev/null
+++ b/tests/retro-tester/retro-tester-window.h
@@ -0,0 +1,19 @@
+// This file is part of retro-gtk. License: GPLv3
+
+#ifndef RETRO_TESTER_WINDOW_H
+#define RETRO_TESTER_WINDOW_H
+
+#include <retro-gtk/retro-gtk.h>
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_TESTER_WINDOW (retro_tester_window_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroTesterWindow, retro_tester_window, RETRO, TESTER_WINDOW, GtkApplicationWindow)
+
+RetroTesterWindow *retro_tester_window_new (RetroCore *core);
+
+G_END_DECLS
+
+#endif /* RETRO_TESTER_WINDOW_H */
+
diff --git a/tests/retro-tester/retro-tester-window.ui b/tests/retro-tester/retro-tester-window.ui
new file mode 100644
index 0000000..2790d8e
--- /dev/null
+++ b/tests/retro-tester/retro-tester-window.ui
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="RetroTesterWindow" parent="GtkApplicationWindow">
+    <property name="can_focus">False</property>
+    <property name="default_width">640</property>
+    <property name="default_height">480</property>
+    <property name="show_menubar">False</property>
+    <child>
+      <object class="RetroCairoDisplay" id="display">
+        <property name="visible">True</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/tests/retro-tester/retro-tester.c b/tests/retro-tester/retro-tester.c
new file mode 100644
index 0000000..0ffa3d6
--- /dev/null
+++ b/tests/retro-tester/retro-tester.c
@@ -0,0 +1,161 @@
+// This file is part of retro-gtk. License: GPLv3
+
+#include <gtk/gtk.h>
+#include <retro-gtk/retro-gtk.h>
+#include "retro-tester-window.h"
+
+#define RETRO_TYPE_TESTER_APPLICATION (retro_tester_application_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroTesterApplication, retro_tester_application, RETRO, TESTER_APPLICATION, 
GtkApplication)
+
+struct _RetroTesterApplication
+{
+  GtkApplication parent_instance;
+
+  RetroCore *core;
+};
+
+G_DEFINE_TYPE (RetroTesterApplication, retro_tester_application, GTK_TYPE_APPLICATION)
+
+static void
+retro_tester_open (GApplication  *application,
+                   GFile        **files,
+                   gint           n_files,
+                   const gchar   *hint)
+{
+  RetroTesterApplication *self;
+  char *module_path;
+  gchar *game_path;
+  RetroSystemInfo system_info = { 0 };
+  RetroGameInfo game_info = { 0 };
+  GError *error = NULL;
+
+  self = RETRO_TESTER_APPLICATION (application);
+
+  if (n_files < 1)
+    return;
+
+  if (!g_file_query_exists (files[0], NULL))
+    return;
+
+  module_path = g_file_get_path (files[0]);
+  self->core = retro_core_new (module_path);
+  g_free (module_path);
+
+  if (self->core == NULL)
+    return;
+
+  g_signal_emit_by_name (self->core, "init");
+
+  if (n_files == 1) {
+    g_application_activate (application);
+
+    return;
+  }
+
+  if (!g_file_query_exists (files[1], NULL))
+    return;
+
+  retro_core_get_system_info (self->core, &system_info);
+
+  if (system_info.need_fullpath) {
+    game_path = g_file_get_path (files[1]);
+    retro_game_info_destroy (&game_info);
+    retro_game_info_init (&game_info, game_path);
+  }
+  else {
+    game_path = g_file_get_path (files[1]);
+    retro_game_info_destroy (&game_info);
+    retro_game_info_init_with_data (&game_info, game_path, &error);
+    if (G_UNLIKELY (error != NULL)) {
+      retro_game_info_destroy (&game_info);
+      g_free (game_path);
+      g_clear_error (&error);
+
+      return;
+    }
+  }
+
+  g_warning ("loaded?");
+  retro_core_load_game (self->core, &game_info);
+  g_warning ("loaded");
+  /* if (!retro_core_load_game (self->core, &game_info)) */
+  /*   return; */
+
+  retro_game_info_destroy (&game_info);
+
+  // TODO Use all files.
+
+  g_application_activate (application);
+}
+
+static RetroTesterApplication *
+retro_tester_application_new (void)
+{
+  return g_object_new (RETRO_TYPE_TESTER_APPLICATION, NULL);
+}
+
+static void
+retro_tester_application_finalize (GObject *object)
+{
+  RetroTesterApplication *self = RETRO_TESTER_APPLICATION (object);
+
+  if (self->core != NULL)
+    g_object_unref (self->core);
+
+  G_OBJECT_CLASS (retro_tester_application_parent_class)->finalize (object);
+}
+
+
+static void
+retro_tester_activate (GApplication* application)
+{
+  RetroTesterApplication *self;
+  GtkSettings *settings;
+  RetroTesterWindow *window;
+
+  self = RETRO_TESTER_APPLICATION (application);
+
+  settings = gtk_settings_get_default ();
+  g_object_set (G_OBJECT (settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
+
+  window = retro_tester_window_new (self->core);
+  gtk_widget_show (GTK_WIDGET (window));
+  gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (window));
+}
+
+static void
+retro_tester_application_class_init (RetroTesterApplicationClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+
+  object_class->finalize = retro_tester_application_finalize;
+
+  application_class->activate = retro_tester_activate;
+  application_class->open = retro_tester_open;
+}
+
+static void
+retro_tester_application_init (RetroTesterApplication *self)
+{
+  g_application_set_application_id (G_APPLICATION (self), "org.gnome.RetroGtkTester");
+  g_application_set_flags (G_APPLICATION (self), G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_OPEN);
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  RetroTesterApplication *app;
+  int status;
+
+  g_set_prgname ("retro-gtk-tester");
+  g_set_application_name ("org.gnome.RetroGtkTester");
+
+  app = retro_tester_application_new();
+  status = g_application_run (G_APPLICATION (app), argc, argv);
+  g_object_unref (app);
+
+  return status;
+}
diff --git a/tests/retro-tester/retro-tester.gresource.xml b/tests/retro-tester/retro-tester.gresource.xml
new file mode 100644
index 0000000..66589ee
--- /dev/null
+++ b/tests/retro-tester/retro-tester.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/retro-gtk/tester">
+    <file preprocess="xml-stripblanks">retro-tester-window.ui</file>
+  </gresource>
+</gresources>
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]