Skip to content

Commit

Permalink
[core / Tests/unit/core] : Fix build 'test_valuerecorder'. (#1590)
Browse files Browse the repository at this point in the history
* [core / Tests/unit/core] : Fix build 'test_valuerecorder'.

* [core / Tests/unit/core] : prepare 'test_value_recorder' for unpredictable failure.

---------

Co-authored-by: Pierre Wielders <pierre@wielders.net>
  • Loading branch information
msieben and pwielders authored Jun 13, 2024
1 parent be5d9c1 commit 3274a16
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Source/core/ValueRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ namespace Core {
ASSERT((_storage[_index] & 0x80) == 0);

// we need to loopback for another 0..
while ((_storage[_index - 1] & 0x80) != 0) {
while (_index > 0 && (_storage[_index - 1] & 0x80) != 0) {
result = (result << 7) | (_storage[_index] & 0x7F);
_index--;
stepBack++;
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ add_executable(${TEST_RUNNER_NAME}
test_time.cpp
test_timer.cpp
test_tristate.cpp
#test_valuerecorder.cpp
test_valuerecorder.cpp
test_weblinkjson.cpp
test_weblinktext.cpp
test_websocketjson.cpp
Expand Down
36 changes: 24 additions & 12 deletions Tests/unit/core/test_valuerecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class WriterClass : public RecorderType<uint32_t, BLOCKSIZE>::Writer
{
uint8_t arr[] = {1,2,3};
SetBuffer(arr);
Create(_file);
auto object = Create(_file);
Record(10);
Time();
Source();
Value();
uint64_t TimeValue = Time();
std::string storageName = Source();
uint32_t value = Value();
object.Release();
}

private:
Expand Down Expand Up @@ -82,14 +83,18 @@ class ReaderClass : public RecorderType<uint32_t, BLOCKSIZE>::Reader
public:
void ReaderJob()
{
Next();
EXPECT_TRUE(IsValid());

uint32_t time = 20;
Core::Time curTime = Core::Time::Now();
curTime.Add(time);
Store(curTime.Ticks(), 1);
uint32_t index = Store(curTime.Ticks(), 1);

StepForward();
StepBack();
ClearData();

Reader obj1(_file, 1u);
EXPECT_FALSE(obj1.Previous());
EXPECT_TRUE(obj1.Next());
Expand All @@ -101,8 +106,8 @@ class ReaderClass : public RecorderType<uint32_t, BLOCKSIZE>::Reader
else
EXPECT_EQ(EndId(),2u);

EndId();
Source();
uint32_t id = EndId();
std::string storageName = Source();
}

private:
Expand All @@ -112,12 +117,19 @@ class ReaderClass : public RecorderType<uint32_t, BLOCKSIZE>::Reader
TEST(test_valuerecorder, test_writer)
{
string filename = "baseRecorder.txt";
WriterClass obj1(filename);
obj1.Copy(obj1,1);
obj1.Copy(obj1,100);
obj1.WriterJob();

auto obj1 = RecorderType<uint32_t, BLOCKSIZE>::Writer::Create(filename);

obj1->Copy(*(obj1),1);
obj1->Copy(*(obj1),100);

static_cast<WriterClass&>(*obj1).WriterJob();

ReaderClass obj2(filename);
obj2.ReaderJob();
ReaderClass obj3(ProxyType<WriterClass>(obj1));

ReaderClass obj4(ProxyType<WriterClass>(obj3));

obj1.Release();
}

0 comments on commit 3274a16

Please sign in to comment.