[retro-gtk] retro-core: Rework state and memory API



commit 5e7e4748a2db7f2240f7f92431e0c00da52c260c
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Jan 6 23:56:42 2020 +0500

    retro-core: Rework state and memory API
    
    When getting state or memory, don't return anything and instead write the
    result into a file. Similarly, when setting them, read them from a file.
    
    This will be important when the core runs in a separate process, as it will
    allow to only send the filename through IPC instead of the whole savestate,
    which can be fairly large for some cores.
    
    Since the get/set terminology doesn't make much sense anymore, rename:
    * retro_core_get_state() -> retro_core_save_state()
    * retro_core_set_state() -> retro_core_load_state()
    * retro_core_get_memory() -> retro_core_save_memory()
    * retro_core_set_memory() -> retro_core_load_memory()
    
    Throw errors for retro_core_load/save_memory() as well, not just for state
    functions.
    
    Use temporary files for tests, and similarly rename them.

 retro-gtk/retro-core.c | 188 ++++++++++++++++++++++++++++++-------------------
 retro-gtk/retro-core.h |  24 ++++---
 tests/meson.build      |   1 +
 tests/retro-reftest.c  |  12 ++--
 tests/test-core.c      | 147 +++++++++++++++++++++++++++++---------
 5 files changed, 252 insertions(+), 120 deletions(-)
---
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index f5d92fc..e1ece22 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -11,10 +11,14 @@
 #define RETRO_CORE_ERROR (retro_core_error_quark ())
 
 enum {
+  RETRO_CORE_ERROR_COULDNT_ACCESS_FILE,
   RETRO_CORE_ERROR_COULDNT_SERIALIZE,
   RETRO_CORE_ERROR_COULDNT_DESERIALIZE,
   RETRO_CORE_ERROR_SERIALIZATION_NOT_SUPPORTED,
   RETRO_CORE_ERROR_NO_CALLBACK,
+  RETRO_CORE_ERROR_NO_MEMORY_REGION,
+  RETRO_CORE_ERROR_UNEXPECTED_MEMORY_REGION,
+  RETRO_CORE_ERROR_SIZE_MISMATCH,
 };
 
 G_DEFINE_QUARK (retro-core-error, retro_core_error)
@@ -1656,25 +1660,27 @@ retro_core_get_can_access_state (RetroCore *self)
 }
 
 /**
- * retro_core_get_state:
+ * retro_core_save_state:
  * @self: a #RetroCore
+ * @filename: the file to save the state to
  * @error: return location for a #GError, or %NULL
  *
- * Gets the state of @self.
- *
- * Returns: (transfer full): a #GBytes, or %NULL
+ * Saves the state of @self.
  */
-GBytes *
-retro_core_get_state (RetroCore  *self,
-                      GError    **error)
+void
+retro_core_save_state (RetroCore    *self,
+                       const gchar  *filename,
+                       GError      **error)
 {
   RetroSerializeSize serialize_size = NULL;
   RetroSerialize serialize = NULL;
-  guint8 *data;
+  g_autofree guint8 *data = NULL;
   gsize size;
   gboolean success;
+  g_autoptr (GError) tmp_error = NULL;
 
-  g_return_val_if_fail (RETRO_IS_CORE (self), NULL);
+  g_return_if_fail (RETRO_IS_CORE (self));
+  g_return_if_fail (filename != NULL);
 
   serialize_size = retro_module_get_serialize_size (self->module);
 
@@ -1688,7 +1694,7 @@ retro_core_get_state (RetroCore  *self,
                  RETRO_CORE_ERROR_SERIALIZATION_NOT_SUPPORTED,
                  "Couldn't serialize the internal state: serialization not supported.");
 
-    return NULL;
+    return;
   }
 
   serialize = retro_module_get_serialize (self->module);
@@ -1703,46 +1709,58 @@ retro_core_get_state (RetroCore  *self,
                  RETRO_CORE_ERROR,
                  RETRO_CORE_ERROR_COULDNT_SERIALIZE,
                  "Couldn't serialize the internal state: serialization failed.");
-    g_free (data);
 
-    return NULL;
+    return;
   }
 
-  return g_bytes_new_take (data, size);
+  g_file_set_contents (filename, (gchar *) data, size, &tmp_error);
+  if (G_UNLIKELY (tmp_error != NULL))
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_COULDNT_ACCESS_FILE,
+                 "Couldn't serialize the internal state: %s", tmp_error->message);
 }
 
 /**
- * retro_core_set_state:
+ * retro_core_load_state:
  * @self: a #RetroCore
- * @bytes: a #GBytes
+ * @filename: the file to load the state from
  * @error: return location for a #GError, or %NULL
  *
- * Sets the state of the @self.
+ * Loads the state of the @self.
  */
 void
-retro_core_set_state (RetroCore  *self,
-                      GBytes     *bytes,
-                      GError    **error)
+retro_core_load_state (RetroCore    *self,
+                       const gchar  *filename,
+                       GError      **error)
 {
   RetroSerializeSize serialize_size = NULL;
   RetroUnserialize unserialize = NULL;
-  gsize size;
-  gconstpointer bytes_data;
-  gsize bytes_size;
+  gsize expected_size, data_size;
+  g_autofree gchar *data = NULL;
   gboolean success;
+  g_autoptr (GError) tmp_error = NULL;
 
   g_return_if_fail (RETRO_IS_CORE (self));
-  g_return_if_fail (bytes != NULL);
+  g_return_if_fail (filename != NULL);
+
+  g_file_get_contents (filename, &data, &data_size, &tmp_error);
+  if (G_UNLIKELY (tmp_error != NULL)) {
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_COULDNT_ACCESS_FILE,
+                 "Couldn't deserialize the internal state: %s", tmp_error->message);
+
+    return;
+  }
 
   serialize_size = retro_module_get_serialize_size (self->module);
 
   retro_core_push_cb_data (self);
-  size = serialize_size ();
+  expected_size = serialize_size ();
   retro_core_pop_cb_data ();
 
-  bytes_data = g_bytes_get_data (bytes, &bytes_size);
-
-  if (size == 0) {
+  if (expected_size == 0) {
     g_set_error (error,
                  RETRO_CORE_ERROR,
                  RETRO_CORE_ERROR_SERIALIZATION_NOT_SUPPORTED,
@@ -1751,14 +1769,14 @@ retro_core_set_state (RetroCore  *self,
     return;
   }
 
-  if (bytes_size > size) {
+  if (data_size > expected_size) {
     g_set_error (error,
                  RETRO_CORE_ERROR,
                  RETRO_CORE_ERROR_COULDNT_DESERIALIZE,
                  "Couldn't deserialize the internal state: expected at most %"
                  G_GSIZE_FORMAT" bytes, got %"G_GSIZE_FORMAT".",
-                 size,
-                 bytes_size);
+                 expected_size,
+                 data_size);
 
     return;
   }
@@ -1766,7 +1784,7 @@ retro_core_set_state (RetroCore  *self,
   unserialize = retro_module_get_unserialize (self->module);
 
   retro_core_push_cb_data (self);
-  success = unserialize ((guint8 *) bytes_data, bytes_size);
+  success = unserialize ((guint8 *) data, data_size);
   retro_core_pop_cb_data ();
 
   if (!success) {
@@ -1804,24 +1822,28 @@ retro_core_get_memory_size (RetroCore       *self,
 }
 
 /**
- * retro_core_get_memory:
+ * retro_core_save_memory:
  * @self: a #RetroCore
  * @memory_type: the type of memory
+ * @filename: a file to save the data to
+ * @error: return location for a #GError, or %NULL
  *
- * Gets a memory region of @self.
- *
- * Returns: (transfer full): a #GBytes, or %NULL
+ * Saves a memory region of @self.
  */
-GBytes *
-retro_core_get_memory (RetroCore       *self,
-                       RetroMemoryType  memory_type)
+void
+retro_core_save_memory (RetroCore        *self,
+                        RetroMemoryType   memory_type,
+                        const gchar      *filename,
+                        GError          **error)
 {
   RetroGetMemoryData get_mem_data;
   RetroGetMemorySize get_mem_size;
-  guint8 *data;
+  gchar *data;
   gsize size;
+  g_autoptr (GError) tmp_error = NULL;
 
-  g_return_val_if_fail (RETRO_IS_CORE (self), NULL);
+  g_return_if_fail (RETRO_IS_CORE (self));
+  g_return_if_fail (filename != NULL);
 
   get_mem_data = retro_module_get_get_memory_data (self->module);
   get_mem_size = retro_module_get_get_memory_size (self->module);
@@ -1831,31 +1853,39 @@ retro_core_get_memory (RetroCore       *self,
   size = get_mem_size (memory_type);
   retro_core_pop_cb_data ();
 
-  return g_bytes_new (data, size);
+  g_file_set_contents (filename, data, size, &tmp_error);
+  if (G_UNLIKELY (tmp_error != NULL))
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_COULDNT_ACCESS_FILE,
+                 "Couldn't save the memory state: %s", tmp_error->message);
 }
 
 /**
- * retro_core_set_memory:
+ * retro_core_load_memory:
  * @self: a #RetroCore
  * @memory_type: the type of memory
- * @bytes: a #GBytes
+ * @filename: a file to load the data from
+ * @error: return location for a #GError, or %NULL
  *
- * Sets a memory region of @self.
+ * Loads a memory region of @self.
  */
 void
-retro_core_set_memory (RetroCore       *self,
-                       RetroMemoryType  memory_type,
-                       GBytes          *bytes)
+retro_core_load_memory (RetroCore        *self,
+                        RetroMemoryType   memory_type,
+                        const gchar      *filename,
+                        GError          **error)
 {
   RetroGetMemoryData get_mem_region;
   RetroGetMemorySize get_mem_region_size;
   guint8 *memory_region;
   gsize memory_region_size;
-  gconstpointer data;
-  gsize size;
+  g_autofree gchar *data = NULL;
+  gsize data_size;
+  GError *tmp_error = NULL;
 
   g_return_if_fail (RETRO_IS_CORE (self));
-  g_return_if_fail (bytes != NULL);
+  g_return_if_fail (filename != NULL);
 
   get_mem_region = retro_module_get_get_memory_data (self->module);
   get_mem_region_size = retro_module_get_get_memory_size (self->module);
@@ -1865,48 +1895,64 @@ retro_core_set_memory (RetroCore       *self,
   memory_region_size = get_mem_region_size (memory_type);
   retro_core_pop_cb_data ();
 
-  data = g_bytes_get_data (bytes, &size);
+  g_file_get_contents (filename, &data, &data_size, &tmp_error);
+  if (G_UNLIKELY (tmp_error != NULL)) {
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_COULDNT_ACCESS_FILE,
+                 "Couldn't load the memory state: %s", tmp_error->message);
+
+    return;
+  }
 
   if (memory_region == NULL) {
-    g_debug ("%s doesn't have memory region %d.",
-             retro_core_get_name (self),
-             memory_type);
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_NO_MEMORY_REGION,
+                 "Couldn't load the memory state: %s doesn't have memory region %d",
+                 retro_core_get_name (self),
+                 memory_type);
 
     return;
   }
 
   if (memory_region_size == 0) {
-    g_debug ("%s has an unexpected 0-sized non-null memory region %d. Aborting "
-             "setting the memory region.",
-             retro_core_get_name (self),
-             memory_type);
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_UNEXPECTED_MEMORY_REGION,
+                 "Couldn't load the memory state: %s has an unexpected 0-sized non-null memory region %d",
+                 retro_core_get_name (self),
+                 memory_type);
 
     return;
   }
 
-  if (memory_region_size < size) {
-    g_debug ("%s expects %"G_GSIZE_FORMAT" bytes for memory region %d: %"
-             G_GSIZE_FORMAT" bytes were passed. Aborting setting the memory "
-             "region.",
-             retro_core_get_name (self),
-             memory_region_size,
-             memory_type,
-             size);
+  if (memory_region_size < data_size) {
+    g_set_error (error,
+                 RETRO_CORE_ERROR,
+                 RETRO_CORE_ERROR_SIZE_MISMATCH,
+                 "Couldn't load the memory state: %s expects %"G_GSIZE_FORMAT
+                 " bytes for memory region %d: %"G_GSIZE_FORMAT
+                 " bytes were passed",
+                 retro_core_get_name (self),
+                 memory_region_size,
+                 memory_type,
+                 data_size);
 
     return;
   }
 
-  if (memory_region_size != size)
+  if (memory_region_size != data_size)
     g_debug ("%s expects %"G_GSIZE_FORMAT" bytes for memory region %d: %"
-             G_GSIZE_FORMAT" bytes were passed. The excess will be filled with"
+             G_GSIZE_FORMAT" bytes were passed. The excess will be filled with "
              "zeros.",
              retro_core_get_name (self),
              memory_region_size,
              memory_type,
-             size);
+             data_size);
 
-  memcpy (memory_region, data, size);
-  memset (memory_region + size, 0, memory_region_size - size);
+  memcpy (memory_region, data, data_size);
+  memset (memory_region + data_size, 0, memory_region_size - data_size);
 }
 
 /**
diff --git a/retro-gtk/retro-core.h b/retro-gtk/retro-core.h
index 13ca1ab..a00b719 100644
--- a/retro-gtk/retro-core.h
+++ b/retro-gtk/retro-core.h
@@ -43,18 +43,22 @@ void retro_core_set_current_media (RetroCore  *self,
 void retro_core_reset (RetroCore *self);
 void retro_core_run (RetroCore *self);
 gboolean retro_core_get_can_access_state (RetroCore *self);
-GBytes *retro_core_get_state (RetroCore  *self,
-                              GError    **error);
-void retro_core_set_state (RetroCore  *self,
-                           GBytes     *bytes,
-                           GError    **error);
+void retro_core_save_state (RetroCore    *self,
+                            const gchar  *filename,
+                            GError      **error);
+void retro_core_load_state (RetroCore    *self,
+                            const gchar  *filename,
+                            GError      **error);
 gsize retro_core_get_memory_size (RetroCore       *self,
                                   RetroMemoryType  memory_type);
-GBytes *retro_core_get_memory (RetroCore       *self,
-                               RetroMemoryType  memory_type);
-void retro_core_set_memory (RetroCore       *self,
-                            RetroMemoryType  memory_type,
-                            GBytes          *bytes);
+void retro_core_save_memory (RetroCore        *self,
+                             RetroMemoryType   memory_type,
+                             const gchar      *filename,
+                             GError          **error);
+void retro_core_load_memory (RetroCore        *self,
+                             RetroMemoryType   memory_type,
+                             const gchar      *filename,
+                             GError          **error);
 void retro_core_set_default_controller (RetroCore           *self,
                                         RetroControllerType  controller_type,
                                         RetroController     *controller);
diff --git a/tests/meson.build b/tests/meson.build
index 3d4ea2c..c0074e3 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -47,6 +47,7 @@ build_conf.set('testexecdir', join_paths(meson.build_root(), 'tests'))
 build_conf.set('testdatadir', join_paths(meson.source_root(), 'tests'))
 
 test_c_args = [
+  '-DRETRO_LOG_DOMAIN="Retro"',
   '-DRETRO_GTK_USE_UNSTABLE_API',
 ]
 
diff --git a/tests/retro-reftest.c b/tests/retro-reftest.c
index 51b4f58..414d56c 100644
--- a/tests/retro-reftest.c
+++ b/tests/retro-reftest.c
@@ -20,6 +20,7 @@
 
 #include "retro-reftest-file.h"
 #include "retro-test-controller.h"
+#include <glib/gstdio.h>
 
 typedef struct {
   guint refs;
@@ -416,7 +417,7 @@ retro_reftest_test_state_none (RetroReftestData *data)
 static void
 retro_reftest_test_state_refresh (RetroReftestData *data)
 {
-  GBytes *state;
+  g_autofree gchar *filename = NULL, *tmpname = NULL;
   GError *error = NULL;
 
   if (!retro_core_get_can_access_state (data->core)) {
@@ -425,12 +426,15 @@ retro_reftest_test_state_refresh (RetroReftestData *data)
     return;
   }
 
-  state = retro_core_get_state (data->core, &error);
+  tmpname = g_strdup_printf ("retro-reftest-state-%d", g_random_int ());
+  filename = g_build_filename (g_get_tmp_dir (), tmpname, NULL);
+
+  retro_core_save_state (data->core, filename, &error);
   g_assert_no_error (error);
-  retro_core_set_state (data->core, state, &error);
+  retro_core_load_state (data->core, filename, &error);
   g_assert_no_error (error);
 
-  g_bytes_unref (state);
+  g_remove (filename);
 }
 
 static void
diff --git a/tests/test-core.c b/tests/test-core.c
index 5ff87c7..fd23f1e 100644
--- a/tests/test-core.c
+++ b/tests/test-core.c
@@ -17,8 +17,10 @@
  */
 
 #include <retro-gtk.h>
+#include <glib/gstdio.h>
 
 static gchar *arg_core_filename = NULL;
+static gchar *tmp_filename = NULL;
 
 static void
 test_setup (RetroCore     **core_pointer,
@@ -34,6 +36,50 @@ test_teardown (RetroCore     **core_pointer,
   g_object_unref (*core_pointer);
 }
 
+static gsize
+get_file_size (const gchar *filename)
+{
+  GStatBuf buf;
+
+  g_stat (filename, &buf);
+
+  return buf.st_size;
+}
+
+static void
+tmp_file_test_setup (RetroCore     **core_pointer,
+                     gconstpointer   core_filename)
+{
+  gint handle;
+  g_autoptr (GError) error = NULL;
+
+  g_assert_null (tmp_filename);
+
+  handle = g_file_open_tmp ("retro-test-core-XXXXXX", &tmp_filename, &error);
+  g_assert_no_error (error);
+
+  g_close (handle, &error);
+  g_assert_no_error (error);
+
+  g_file_set_contents (tmp_filename, NULL, 0, &error);
+  g_assert_no_error (error);
+  g_assert_cmpuint (get_file_size (tmp_filename), ==, 0);
+
+  test_setup (core_pointer, core_filename);
+}
+
+static void
+tmp_file_test_teardown (RetroCore     **core_pointer,
+                        gconstpointer   data)
+{
+  test_teardown (core_pointer, data);
+
+  g_assert_nonnull (tmp_filename);
+  g_remove (tmp_filename);
+
+  tmp_filename = NULL;
+}
+
 static void
 test_boot (RetroCore     **core_pointer,
            gconstpointer   data)
@@ -124,8 +170,8 @@ test_get_can_access_state (RetroCore     **core_pointer,
 }
 
 static void
-test_get_state (RetroCore     **core_pointer,
-                gconstpointer   data)
+test_save_state (RetroCore     **core_pointer,
+                 gconstpointer   data)
 {
   RetroCore *core = *core_pointer;
   GError *error = NULL;
@@ -133,28 +179,38 @@ test_get_state (RetroCore     **core_pointer,
   retro_core_boot (core, &error);
   g_assert_no_error (error);
 
-  retro_core_get_state (core, &error);
+  retro_core_save_state (core, tmp_filename, &error);
+
   /* g_assert_error() should be used but the expected error domain is private. */
   g_assert_nonnull (error);
   g_clear_error (&error);
+
+  g_test_expect_message (RETRO_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "retro_core_save_state: assertion 'filename 
!= NULL' failed");
+  retro_core_save_state (core, NULL, &error);
+  g_test_assert_expected_messages ();
+  g_assert_no_error (error);
 }
 
 static void
-test_set_state (RetroCore     **core_pointer,
-                gconstpointer   data)
+test_load_state (RetroCore     **core_pointer,
+                 gconstpointer   data)
 {
   RetroCore *core = *core_pointer;
-  GBytes *state = g_bytes_new (NULL, 0);
   GError *error = NULL;
 
   retro_core_boot (core, &error);
   g_assert_no_error (error);
 
-  retro_core_set_state (core, state, &error);
+  retro_core_load_state (core, tmp_filename, &error);
+
   /* g_assert_error() should be used but the expected error domain is private. */
   g_assert_nonnull (error);
   g_clear_error (&error);
-  g_bytes_unref (state);
+
+  g_test_expect_message (RETRO_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "retro_core_load_state: assertion 'filename 
!= NULL' failed");
+  retro_core_load_state (core, NULL, &error);
+  g_test_assert_expected_messages ();
+  g_assert_no_error (error);
 }
 
 static void
@@ -174,49 +230,70 @@ test_get_memory_size (RetroCore     **core_pointer,
 }
 
 static void
-test_get_memory (RetroCore     **core_pointer,
-                 gconstpointer   data)
+test_save_valid_memory_type (RetroCore       *core,
+                             RetroMemoryType  type)
+{
+  gsize size;
+  GError *error = NULL;
+
+  retro_core_save_memory (core, type, tmp_filename, &error);
+  size = get_file_size (tmp_filename);
+  g_assert_no_error (error);
+  g_assert_cmpuint (size, ==, 0);
+}
+
+static void
+test_save_memory (RetroCore     **core_pointer,
+                  gconstpointer   data)
 {
   RetroCore *core = *core_pointer;
-  GBytes *memory;
   GError *error = NULL;
 
   retro_core_boot (core, &error);
   g_assert_no_error (error);
 
-  memory = retro_core_get_memory (core, RETRO_MEMORY_TYPE_SAVE_RAM);
-  g_assert_cmpuint (g_bytes_get_size (memory), ==, 0);
-  g_bytes_unref (memory);
+  test_save_valid_memory_type (core, RETRO_MEMORY_TYPE_SAVE_RAM);
+  test_save_valid_memory_type (core, RETRO_MEMORY_TYPE_RTC);
+  test_save_valid_memory_type (core, RETRO_MEMORY_TYPE_SYSTEM_RAM);
+  test_save_valid_memory_type (core, RETRO_MEMORY_TYPE_VIDEO_RAM);
 
-  memory = retro_core_get_memory (core, RETRO_MEMORY_TYPE_RTC);
-  g_assert_cmpuint (g_bytes_get_size (memory), ==, 0);
-  g_bytes_unref (memory);
+  g_test_expect_message (RETRO_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "retro_core_save_memory: assertion 
'filename != NULL' failed");
+  retro_core_save_memory (core, RETRO_MEMORY_TYPE_SAVE_RAM, NULL, &error);
+  g_test_assert_expected_messages ();
+  g_assert_no_error (error);
+}
 
-  memory = retro_core_get_memory (core, RETRO_MEMORY_TYPE_SYSTEM_RAM);
-  g_assert_cmpuint (g_bytes_get_size (memory), ==, 0);
-  g_bytes_unref (memory);
+static void
+test_load_valid_memory_type (RetroCore       *core,
+                             RetroMemoryType  type)
+{
+  GError *error = NULL;
 
-  memory = retro_core_get_memory (core, RETRO_MEMORY_TYPE_VIDEO_RAM);
-  g_assert_cmpuint (g_bytes_get_size (memory), ==, 0);
-  g_bytes_unref (memory);
+  retro_core_load_memory (core, type, tmp_filename, &error);
+  /* g_assert_error() should be used but the expected error domain is private. */
+  g_assert_nonnull (error);
+  g_clear_error (&error);
 }
 
 static void
-test_set_memory (RetroCore     **core_pointer,
-                 gconstpointer   data)
+test_load_memory (RetroCore     **core_pointer,
+                  gconstpointer   data)
 {
   RetroCore *core = *core_pointer;
-  GBytes *memory = g_bytes_new (NULL, 0);
   GError *error = NULL;
 
   retro_core_boot (core, &error);
   g_assert_no_error (error);
 
-  retro_core_set_memory (core, RETRO_MEMORY_TYPE_SAVE_RAM, memory);
-  retro_core_set_memory (core, RETRO_MEMORY_TYPE_RTC, memory);
-  retro_core_set_memory (core, RETRO_MEMORY_TYPE_SYSTEM_RAM, memory);
-  retro_core_set_memory (core, RETRO_MEMORY_TYPE_VIDEO_RAM, memory);
-  g_bytes_unref (memory);
+  test_load_valid_memory_type (core, RETRO_MEMORY_TYPE_SAVE_RAM);
+  test_load_valid_memory_type (core, RETRO_MEMORY_TYPE_RTC);
+  test_load_valid_memory_type (core, RETRO_MEMORY_TYPE_SYSTEM_RAM);
+  test_load_valid_memory_type (core, RETRO_MEMORY_TYPE_VIDEO_RAM);
+
+  g_test_expect_message (RETRO_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "retro_core_load_memory: assertion 
'filename != NULL' failed");
+  retro_core_load_memory (core, RETRO_MEMORY_TYPE_SAVE_RAM, NULL, &error);
+  g_test_assert_expected_messages ();
+  g_assert_no_error (error);
 }
 
 static void
@@ -258,11 +335,11 @@ main (int   argc,
   g_test_add ("/RetroCore/get_support_no_game", RetroCore *, arg_core_filename, test_setup, 
test_get_support_no_game, test_teardown);
   g_test_add ("/RetroCore/get_frames_per_second", RetroCore *, arg_core_filename, test_setup, 
test_get_frames_per_second, test_teardown);
   g_test_add ("/RetroCore/get_can_access_state", RetroCore *, arg_core_filename, test_setup, 
test_get_can_access_state, test_teardown);
-  g_test_add ("/RetroCore/get_state", RetroCore *, arg_core_filename, test_setup, test_get_state, 
test_teardown);
-  g_test_add ("/RetroCore/set_state", RetroCore *, arg_core_filename, test_setup, test_set_state, 
test_teardown);
+  g_test_add ("/RetroCore/save_state", RetroCore *, arg_core_filename, tmp_file_test_setup, test_save_state, 
tmp_file_test_teardown);
+  g_test_add ("/RetroCore/load_state", RetroCore *, arg_core_filename, tmp_file_test_setup, test_load_state, 
tmp_file_test_teardown);
   g_test_add ("/RetroCore/get_memory_size", RetroCore *, arg_core_filename, test_setup, 
test_get_memory_size, test_teardown);
-  g_test_add ("/RetroCore/get_memory", RetroCore *, arg_core_filename, test_setup, test_get_memory, 
test_teardown);
-  g_test_add ("/RetroCore/set_memory", RetroCore *, arg_core_filename, test_setup, test_set_memory, 
test_teardown);
+  g_test_add ("/RetroCore/save_memory", RetroCore *, arg_core_filename, tmp_file_test_setup, 
test_save_memory, tmp_file_test_teardown);
+  g_test_add ("/RetroCore/load_memory", RetroCore *, arg_core_filename, tmp_file_test_setup, 
test_load_memory, tmp_file_test_teardown);
   g_test_add ("/RetroCore/has_option", RetroCore *, arg_core_filename, test_setup, test_has_option, 
test_teardown);
 
   return g_test_run();


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