feat(datastore): add getter and setter for string

This commit is contained in:
fallenoak 2023-02-10 00:14:40 -06:00
parent a4dfbeff7a
commit d1e4812aa3
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
3 changed files with 52 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#include "common/DataStore.hpp"
#include "test/Test.hpp"
#include <storm/String.hpp>
TEST_CASE("CDataStore::CDataStore", "[datastore]") {
SECTION("constructs new data store") {
@ -68,4 +69,28 @@ TEST_CASE("CDataStore::Get", "[datastore]") {
REQUIRE(readVal == writeVal);
}
SECTION("gets string") {
const char* writeVal = "foobar";
char readVal[7] = "barfoo";
CDataStore msg;
msg.PutString(writeVal);
msg.Finalize();
msg.GetString(readVal, sizeof(readVal));
REQUIRE(SStrCmp(readVal, writeVal, STORM_MAX_STR) == 0);
}
SECTION("gets string honoring maxchars") {
const char* writeVal = "foobar";
char readVal[7] = "bar";
CDataStore msg;
msg.PutString(writeVal);
msg.Finalize();
msg.GetString(readVal, 3);
REQUIRE(SStrCmp(readVal, "foo", STORM_MAX_STR) == 0);
}
}