Skip to content

Commit

Permalink
Merge branch 'master' into development/messagedispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
msieben authored Jun 26, 2024
2 parents cfcf37a + cb226b3 commit b337c28
Show file tree
Hide file tree
Showing 62 changed files with 8,783 additions and 8,480 deletions.
411 changes: 206 additions & 205 deletions Tests/unit/core/test_cyclicbuffer.cpp

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Tests/unit/core/test_databuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
#include <core/core.h>

namespace Thunder {
namespace Core {
namespace Tests {
namespace Core {

TEST(Core_DataBuffer, simple)
{
constexpr uint32_t blocksize = 10;
TEST(Core_DataBuffer, simple)
{
constexpr uint32_t blocksize = 10;

Thunder::Core::ScopedStorage<blocksize> storage;
::Thunder::Core::ScopedStorage<blocksize> storage;

EXPECT_EQ(storage.Size(), blocksize);
EXPECT_EQ(storage.Size(), blocksize);

EXPECT_NE(storage.Buffer(), nullptr);
}
EXPECT_NE(storage.Buffer(), nullptr);
}

} // Tests
} // Core
} // Tests
} // Thunder
189 changes: 97 additions & 92 deletions Tests/unit/core/test_dataelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,95 +25,100 @@

#include <core/DataElement.h>

using namespace Thunder;
using namespace Thunder::Core;

TEST(test_data, simple_data)
{
const uint8_t arr[] = {10,20,30,40,50,60,70,80,90,100};
const uint16_t len = 5;
const uint16_t off = 0;
DataStore obj1;
obj1.Copy(arr,len,off);
uint32_t size = 1024;
EXPECT_EQ(obj1.Size(),size);
obj1.Size(1025);
EXPECT_EQ(*obj1.Buffer(),10);

uint8_t arr1[] = {10,20,30,40,50,60,70,80,90,100};
const uint64_t s = 10;
DataElement obj_sample;
DataElement obj2(s,arr1);
DataElement obj_operator = obj2;
uint32_t crc = 4134036294;
EXPECT_EQ(obj2.CRC32(0,10),crc);
EXPECT_TRUE(obj2.Copy(obj2,0));

uint64_t alloc_size = 10;
EXPECT_EQ(obj2.AllocatedSize(), alloc_size);
EXPECT_TRUE(obj2.Size(sizeof(arr)));
EXPECT_TRUE(obj2.IsValid());
EXPECT_EQ(*obj2.Buffer(),10);

uint8_t arr2[] = {10,20,30,40,50};
const uint8_t infom = 10;
uint64_t SearchNumber = 10;
EXPECT_EQ((obj2.SearchNumber<uint8_t, Core::ENDIAN_BIG>(2,infom)),SearchNumber);
obj2.SetNumber<uint64_t, Core::ENDIAN_BIG>(2,10);
uint64_t GetNumber = 10;
EXPECT_EQ((obj2.GetNumber<uint64_t, Core::ENDIAN_BIG>(2)),GetNumber);

obj2.Search(2,arr2,5);
obj2.SetBitNumber<uint64_t>(2,5,8,10);
uint64_t GetBitNumber = 10;
EXPECT_EQ(obj2.GetBitNumber<uint64_t>(2,5,8),GetBitNumber);

const uint8_t val= 32;
const uint64_t offset= 0;
obj2.Set(val,offset);
obj2.Align<uint8_t>();

DataElement obj(obj2);
DataElement obj3 = obj;
DataElement obj4(obj2,0,0);

uint32_t ob_size = 10;
EXPECT_EQ(obj3.Size(),ob_size);
EXPECT_FALSE(obj3.Expand(0,0));
EXPECT_TRUE(obj3.Shrink(0,0));
EXPECT_FALSE(obj3.Copy(obj2));
}

TEST(test_linkeddata, simple_linkeddata)
{
uint8_t arr[] = {10,20,30,40,50,60,70,80,90,100};
uint8_t arr1[] ={};
const uint64_t offset= 0;
DataElement objt1(10,arr);
LinkedDataElement ob1;
LinkedDataElement ob2(objt1);
LinkedDataElement ob3(ob2);
ob3.Enclosed(&ob2);
EXPECT_EQ(ob3.Enclosed(), &ob2);
ob3.SetBuffer(2,9,arr);
ob3.GetBuffer(2,9,arr1);
LinkedDataElement ob4;
ob4 = ob2;
EXPECT_EQ(ob4.Copy(offset,ob2), unsigned(10));
EXPECT_EQ(ob2.Copy(offset,ob3), unsigned(10));

ob1.Enclosed();
EXPECT_EQ(ob2.LinkedSize(), unsigned(10));
EXPECT_EQ(ob2.LinkedElements(),unsigned(1));
}

TEST(test_dataParser, simple_dataParser)
{
uint8_t arr[] = {10,20,30,40,50};
DataElement object1(10,arr);
DataElementParser parser1(object1,0);
uint64_t size = -10;
EXPECT_TRUE(parser1.IsValid());
EXPECT_EQ(parser1.Size(),size);
parser1.SkipBytes(2);
}
namespace Thunder {
namespace Tests {
namespace Core {

TEST(test_data, simple_data)
{
const uint8_t arr[] = {10,20,30,40,50,60,70,80,90,100};
const uint16_t len = 5;
const uint16_t off = 0;
::Thunder::Core::DataStore obj1;
obj1.Copy(arr,len,off);
uint32_t size = 1024;
EXPECT_EQ(obj1.Size(),size);
obj1.Size(1025);
EXPECT_EQ(*obj1.Buffer(),10);

uint8_t arr1[] = {10,20,30,40,50,60,70,80,90,100};
const uint64_t s = 10;
::Thunder::Core::DataElement obj_sample;
::Thunder::Core::DataElement obj2(s,arr1);
::Thunder::Core::DataElement obj_operator = obj2;
uint32_t crc = 4134036294;
EXPECT_EQ(obj2.CRC32(0,10),crc);
EXPECT_TRUE(obj2.Copy(obj2,0));

uint64_t alloc_size = 10;
EXPECT_EQ(obj2.AllocatedSize(), alloc_size);
EXPECT_TRUE(obj2.Size(sizeof(arr)));
EXPECT_TRUE(obj2.IsValid());
EXPECT_EQ(*obj2.Buffer(),10);

uint8_t arr2[] = {10,20,30,40,50};
const uint8_t infom = 10;
uint64_t SearchNumber = 10;
EXPECT_EQ((obj2.SearchNumber<uint8_t, ::Thunder::Core::ENDIAN_BIG>(2,infom)),SearchNumber);
obj2.SetNumber<uint64_t, ::Thunder::Core::ENDIAN_BIG>(2,10);
uint64_t GetNumber = 10;
EXPECT_EQ((obj2.GetNumber<uint64_t, ::Thunder::Core::ENDIAN_BIG>(2)),GetNumber);

obj2.Search(2,arr2,5);
obj2.SetBitNumber<uint64_t>(2,5,8,10);
uint64_t GetBitNumber = 10;
EXPECT_EQ(obj2.GetBitNumber<uint64_t>(2,5,8),GetBitNumber);

const uint8_t val= 32;
const uint64_t offset= 0;
obj2.Set(val,offset);
obj2.Align<uint8_t>();

::Thunder::Core::DataElement obj(obj2);
::Thunder::Core::DataElement obj3 = obj;
::Thunder::Core::DataElement obj4(obj2,0,0);

uint32_t ob_size = 10;
EXPECT_EQ(obj3.Size(),ob_size);
EXPECT_FALSE(obj3.Expand(0,0));
EXPECT_TRUE(obj3.Shrink(0,0));
EXPECT_FALSE(obj3.Copy(obj2));
}

TEST(test_linkeddata, simple_linkeddata)
{
uint8_t arr[] = {10,20,30,40,50,60,70,80,90,100};
uint8_t arr1[] ={};
const uint64_t offset= 0;
::Thunder::Core::DataElement objt1(10,arr);
::Thunder::Core::LinkedDataElement ob1;
::Thunder::Core::LinkedDataElement ob2(objt1);
::Thunder::Core::LinkedDataElement ob3(ob2);
ob3.Enclosed(&ob2);
EXPECT_EQ(ob3.Enclosed(), &ob2);
ob3.SetBuffer(2,9,arr);
ob3.GetBuffer(2,9,arr1);
::Thunder::Core::LinkedDataElement ob4;
ob4 = ob2;
EXPECT_EQ(ob4.Copy(offset,ob2), unsigned(10));
EXPECT_EQ(ob2.Copy(offset,ob3), unsigned(10));

ob1.Enclosed();
EXPECT_EQ(ob2.LinkedSize(), unsigned(10));
EXPECT_EQ(ob2.LinkedElements(),unsigned(1));
}

TEST(test_dataParser, simple_dataParser)
{
uint8_t arr[] = {10,20,30,40,50};
::Thunder::Core::DataElement object1(10,arr);
::Thunder::Core::DataElementParser parser1(object1,0);
uint64_t size = -10;
EXPECT_TRUE(parser1.IsValid());
EXPECT_EQ(parser1.Size(),size);
parser1.SkipBytes(2);
}

} // Core
} // Tests
} // Thunder
111 changes: 58 additions & 53 deletions Tests/unit/core/test_dataelementfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,85 +25,90 @@

#include <core/core.h>

using namespace Thunder;
using namespace Thunder::Core;
namespace Thunder {
namespace Tests {
namespace Core {

class DataFile: public Core::DataElementFile
{
public:
DataFile() = delete;

DataFile(File& file)
: DataElementFile(file, File::USER_READ)
class DataFile: public ::Thunder::Core::DataElementFile
{
}

DataFile(string fileName, uint32_t type, uint32_t size)
:DataElementFile(fileName, type, size)
{
}

void MemoryMap()
public:
DataFile() = delete;

DataFile(::Thunder::Core::File& file)
: ::Thunder::Core::DataElementFile(file, ::Thunder::Core::File::USER_READ)
{
}

DataFile(string fileName, uint32_t type, uint32_t size)
: ::Thunder::Core::DataElementFile(fileName, type, size)
{
}

void MemoryMap()
{
Reallocation(54);
ReopenMemoryMappedFile();
}
};

TEST(test_datafile, simple_test)
{
Reallocation(54);
ReopenMemoryMappedFile();
}
};

TEST(test_datafile, simple_test)
{
const string fileName = "dataFile.txt";
const string message = ">echo 'DataElement file checking......'";
string buffer = message + fileName;
const string fileName = "dataFile.txt";
const string message = ">echo 'DataElement file checking......'";
string buffer = message + fileName;

#ifdef __POSIX__
errno = 0;
errno = 0;
#endif

File file(fileName);
::Thunder::Core::File file(fileName);

ASSERT_FALSE(file.Exists());
ASSERT_FALSE(file.Exists());

// Always for a non-existing file
// Always for a non-existing file
#ifdef __WINDOWS__
EXPECT_EQ(file.ErrorCode(), static_cast<uint32_t>(ERROR_FILE_NOT_FOUND));
EXPECT_EQ(file.ErrorCode(), static_cast<uint32_t>(ERROR_FILE_NOT_FOUND));
#endif
#ifdef __POSIX__
EXPECT_EQ(file.ErrorCode(), static_cast<uint32_t>(ENOENT));
EXPECT_EQ(file.ErrorCode(), static_cast<uint32_t>(ENOENT));
#endif

ASSERT_TRUE(file.Create(true));
EXPECT_EQ(file.IsOpen(), true);
EXPECT_EQ(file.Name(), fileName);
ASSERT_TRUE(file.Create(true));
EXPECT_EQ(file.IsOpen(), true);
EXPECT_EQ(file.Name(), fileName);

#ifdef __POSIX__
errno = 0;
errno = 0;
#endif

DataFile obj1(file);
DataFile obj1(file);
#ifdef __WINDOWS__
EXPECT_EQ(obj1.ErrorCode(), static_cast<uint32_t>(ERROR_SUCCESS));
EXPECT_EQ(obj1.ErrorCode(), static_cast<uint32_t>(ERROR_SUCCESS));
#endif
#ifdef __POSIX__
EXPECT_EQ(obj1.ErrorCode(), static_cast<uint32_t>(0));
EXPECT_EQ(obj1.ErrorCode(), static_cast<uint32_t>(0));
#endif

DataFile object(fileName, 1, 10);
DataFile obj2(fileName, 1, 50);
DataFile object(fileName, 1, 10);
DataFile obj2(fileName, 1, 50);

obj1.Sync();
obj2.MemoryMap();
obj1.Sync();
obj2.MemoryMap();

const string& name = obj1.Name();
const string& name = obj1.Name();

EXPECT_EQ(name.c_str(), fileName);
EXPECT_EQ(obj2.IsValid(), true);
EXPECT_EQ(name.c_str(), fileName);
EXPECT_EQ(obj2.IsValid(), true);

const File& obj1File = obj1.Storage();
EXPECT_STREQ(obj1File.FileName().c_str(), file.FileName().c_str());
const ::Thunder::Core::File& obj1File = obj1.Storage();
EXPECT_STREQ(obj1File.FileName().c_str(), file.FileName().c_str());

obj1.ReloadFileInfo();
obj1.MemoryMap();
obj1.ReloadFileInfo();
obj1.MemoryMap();

EXPECT_TRUE(file.Destroy());
}

EXPECT_TRUE(file.Destroy());
}
} // Core
} // Tests
} // Thunder
Loading

0 comments on commit b337c28

Please sign in to comment.