From ba47de0e4b652ee4ceb1c2592ebf500d44639fbc Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 7 Jan 2018 16:30:33 -0600 Subject: [PATCH] Add objstore_clear(), tests for objstore --- include/objstore.h | 3 ++- src/objstore.c | 10 ++++++++++ tests/objstore.c | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/objstore.h b/include/objstore.h index 283a638..f13885a 100644 --- a/include/objstore.h +++ b/include/objstore.h @@ -13,8 +13,9 @@ typedef struct { vm_8bit apple2_sysfont[APPLE2_SYSFONT_SIZE]; } objstore; -extern int objstore_init(); extern bool objstore_ready(); +extern int objstore_init(); +extern void objstore_clear(); #define OBJSTORE_DECL(x) \ const vm_8bit *objstore_##x() diff --git a/src/objstore.c b/src/objstore.c index ad6cde0..2002380 100644 --- a/src/objstore.c +++ b/src/objstore.c @@ -51,6 +51,16 @@ objstore_init() return OK; } +/* + * This will empty out the store, which is not very _practically_ + * useful, but is a bit useful when testing. + */ +void +objstore_clear() +{ + memset(&store, 0, sizeof(store)); +} + /* * Return true if the object store is ready to be used. */ diff --git a/tests/objstore.c b/tests/objstore.c index 4faaea6..33572c1 100644 --- a/tests/objstore.c +++ b/tests/objstore.c @@ -5,5 +5,23 @@ Test(objstore, init) { + objstore_clear(); cr_assert_eq(objstore_init(), OK); + cr_assert_eq(objstore_ready(), true); +} + +Test(objstore, ready) +{ + objstore_clear(); + cr_assert_eq(objstore_ready(), false); + objstore_init(); + cr_assert_eq(objstore_ready(), true); +} + +Test(objstore, clear) +{ + objstore_init(); + cr_assert_eq(objstore_ready(), true); + objstore_clear(); + cr_assert_eq(objstore_ready(), false); }