Reworking DataRecords and DataFlow
This commit is contained in:
+18
-19
@@ -6,6 +6,7 @@ uses
|
||||
DunitX.TestFramework,
|
||||
System.SysUtils,
|
||||
System.DateUtils,
|
||||
System.Rtti,
|
||||
Myc.DataRecord;
|
||||
|
||||
type
|
||||
@@ -21,56 +22,54 @@ type
|
||||
|
||||
[TestFixture]
|
||||
TTestDataRecord = class(TObject)
|
||||
private
|
||||
FCtx: TRttiContext;
|
||||
|
||||
public
|
||||
[Test]
|
||||
[IgnoreMemoryLeaks]
|
||||
procedure TestLayoutCreation;
|
||||
|
||||
[Test]
|
||||
[IgnoreMemoryLeaks]
|
||||
procedure TestCreateFromInstanceAndGetValue;
|
||||
|
||||
[Test]
|
||||
[IgnoreMemoryLeaks]
|
||||
procedure TestSetValueAndGetValue;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.Rtti;
|
||||
|
||||
{ TTestDataRecord }
|
||||
|
||||
procedure TTestDataRecord.TestLayoutCreation;
|
||||
var
|
||||
layout: TDataRecord.TRecordLayout;
|
||||
layout: TDataRecord.TLayout;
|
||||
idx: Integer;
|
||||
expectedSize: Integer;
|
||||
begin
|
||||
// Test: Create layout from a record type
|
||||
layout := TDataRecord.TRecordLayout.CreateFrom<TMyTestRecord>;
|
||||
layout := TDataRecord.TLayout.FromRecord<TMyTestRecord>;
|
||||
|
||||
// Assert: Check field count
|
||||
Assert.IsTrue(Length(layout.Fields) = 6, 'Layout should have 6 fields');
|
||||
|
||||
// Assert: Check specific fields for correct type mapping
|
||||
idx := layout.IndexOf('MyTimestamp');
|
||||
Assert.IsTrue(idx > -1, 'Field MyTimestamp not found');
|
||||
Assert.AreEqual(TDataRecord.TFieldType.dfTimestamp, layout.Fields[idx].FieldType, 'MyTimestamp should be mapped to dfTimestamp');
|
||||
|
||||
idx := layout.IndexOf('MyInteger');
|
||||
Assert.IsTrue(idx > -1, 'Field MyInteger not found');
|
||||
Assert.AreEqual(TDataFieldType.dfInteger, layout.Fields[idx].FieldType, 'MyInteger should be mapped to dfInteger');
|
||||
Assert.AreEqual(TDataRecord.TFieldType.dfInteger, layout.Fields[idx].FieldType, 'MyInteger should be mapped to dfInteger');
|
||||
|
||||
idx := layout.IndexOf('MyString');
|
||||
Assert.IsTrue(idx > -1, 'Field MyString not found');
|
||||
Assert.AreEqual(TDataFieldType.dfString, layout.Fields[idx].FieldType, 'MyString should be mapped to dfString');
|
||||
Assert.AreEqual(TDataRecord.TFieldType.dfString, layout.Fields[idx].FieldType, 'MyString should be mapped to dfString');
|
||||
|
||||
idx := layout.IndexOf('MySingle');
|
||||
Assert.IsTrue(idx > -1, 'Field MySingle not found');
|
||||
Assert.AreEqual(TDataFieldType.dfFloat, layout.Fields[idx].FieldType, 'MySingle should be mapped to dfFloat');
|
||||
|
||||
idx := layout.IndexOf('MyTimestamp');
|
||||
Assert.IsTrue(idx > -1, 'Field MyTimestamp not found');
|
||||
Assert.AreEqual(TDataFieldType.dfTimestamp, layout.Fields[idx].FieldType, 'MyTimestamp should be mapped to dfTimestamp');
|
||||
|
||||
// Assert: Check total buffer size (6 fields * 8 bytes each on x64 due to type promotion and alignment)
|
||||
expectedSize := (sizeof(Int64) * 2) + (sizeof(Double) * 2) + sizeof(String) + sizeof(TDateTime);
|
||||
Assert.AreEqual(expectedSize, layout.GetBufferSize, 'Buffer size calculation is incorrect');
|
||||
Assert.AreEqual(TDataRecord.TFieldType.dfFloat, layout.Fields[idx].FieldType, 'MySingle should be mapped to dfFloat');
|
||||
end;
|
||||
|
||||
procedure TTestDataRecord.TestCreateFromInstanceAndGetValue;
|
||||
@@ -87,7 +86,7 @@ begin
|
||||
srcRecord.MyTimestamp := EncodeDateTime(2024, 7, 19, 10, 30, 0, 0);
|
||||
|
||||
// Test: Create a TDataRecord from the source record instance
|
||||
dataRecord := TDataRecord.CreateFrom<TMyTestRecord>(srcRecord);
|
||||
dataRecord := TDataRecord.FromRecord<TMyTestRecord>(srcRecord);
|
||||
|
||||
// Assert: Retrieve each value and check for correctness
|
||||
Assert.AreEqual(srcRecord.MyInt64, dataRecord.GetValue<Int64>('MyInt64'), 'Int64 value mismatch');
|
||||
@@ -114,7 +113,7 @@ var
|
||||
testTimestamp: TDateTime;
|
||||
begin
|
||||
// Setup: Create an empty TDataRecord with the layout of TMyTestRecord
|
||||
dataRecord := TDataRecord.CreateFrom<TMyTestRecord>;
|
||||
dataRecord := TDataRecord.FromRecord<TMyTestRecord>;
|
||||
|
||||
// Setup: Define test values
|
||||
testInt := 54321;
|
||||
|
||||
Reference in New Issue
Block a user