Skip to content

Commit 128d36d

Browse files
committed
fakedevice: return an error on read/write_memory
1 parent f2cda13 commit 128d36d

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/arvdebugprivate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ extern ArvDebugCategoryInfos arv_debug_category_infos[];
7373
#define arv_warning_device(...) arv_warning (ARV_DEBUG_CATEGORY_DEVICE, __VA_ARGS__)
7474
#define arv_info_device(...) arv_info (ARV_DEBUG_CATEGORY_DEVICE, __VA_ARGS__)
7575
#define arv_debug_device(...) arv_debug (ARV_DEBUG_CATEGORY_DEVICE, __VA_ARGS__)
76+
#define arv_trace_device(...) arv_trace (ARV_DEBUG_CATEGORY_DEVICE, __VA_ARGS__)
7677

7778
#define arv_warning_chunk(...) arv_warning (ARV_DEBUG_CATEGORY_CHUNK, __VA_ARGS__)
7879
#define arv_info_chunk(...) arv_info (ARV_DEBUG_CATEGORY_CHUNK, __VA_ARGS__)

src/arvfakedevice.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <arvfakestreamprivate.h>
3232
#include <arvfakecamera.h>
3333
#include <arvgc.h>
34-
#include <arvdebug.h>
34+
#include <arvdebugprivate.h>
3535

3636
enum
3737
{
@@ -85,16 +85,34 @@ static gboolean
8585
arv_fake_device_read_memory (ArvDevice *device, guint64 address, guint32 size, void *buffer, GError **error)
8686
{
8787
ArvFakeDevicePrivate *priv = arv_fake_device_get_instance_private (ARV_FAKE_DEVICE (device));
88+
gboolean success;
8889

89-
return arv_fake_camera_read_memory (priv->camera, address, size, buffer);
90+
success = arv_fake_camera_read_memory (priv->camera, address, size, buffer);
91+
92+
arv_trace_device ("[FakeDevice::read_memory] address 0x%" G_GINT64_MODIFIER "x, size = %d", address, size);
93+
94+
if (!success)
95+
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_INVALID_PARAMETER,
96+
"Invalid read at 0x%" G_GINT64_MODIFIER "x, size %d", address, size);
97+
98+
return success;
9099
}
91100

92101
static gboolean
93102
arv_fake_device_write_memory (ArvDevice *device, guint64 address, guint32 size, const void *buffer, GError **error)
94103
{
95104
ArvFakeDevicePrivate *priv = arv_fake_device_get_instance_private (ARV_FAKE_DEVICE (device));
105+
gboolean success;
106+
107+
arv_trace_device ("[FakeDevice::write_memory] address 0x%" G_GINT64_MODIFIER "x, size = %d", address, size);
108+
109+
success = arv_fake_camera_write_memory (priv->camera, address, size, buffer);
110+
111+
if (!success)
112+
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_INVALID_PARAMETER,
113+
"Invalid write at 0x%" G_GINT64_MODIFIER "x, size %d", address, size);
96114

97-
return arv_fake_camera_write_memory (priv->camera, address, size, buffer);
115+
return success;
98116
}
99117

100118
static gboolean

tests/device.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
assert bytes == b'0123\x00'
2121

22+
try:
23+
bytes = device.write_memory (0x10000, b'test')
24+
25+
except GLib.Error as err:
26+
assert err.matches (Aravis.device_error_quark(), Aravis.DeviceError.INVALID_PARAMETER)
27+
2228
device.write_register (0x48, 123)
2329
value = device.read_register (0x48)
2430

0 commit comments

Comments
 (0)