unit Myc.Test.Trade.DataServer; interface uses System.SysUtils, System.Generics.Collections, DUnitX.TestFramework, Myc.Signals, Myc.Lazy, Myc.Futures, Myc.Trade.DataPoint, Myc.Trade.DataSeries, Myc.Trade.DataServer; type // Test fixture for TDataServer and TAuraTABFileServer, focusing on data equivalence // with TDataSeries.LoadDataSeries. [TestFixture] [IgnoreMemoryLeaks(true)] TTest_TABFileServer_Equivalence = class(TObject) private FServer: IDataServer>; public [SetupFixture] procedure SetupFixture; [Setup] procedure Setup; [TearDown] procedure TearDown; [TearDownFixture] procedure TearDownFixture; [Test] procedure Test_ServerReturnsSameDataAs_LoadDataSeries; end; implementation uses Myc.TaskManager; const // The reference data file for this test. C_TEST_FILENAME = '\\COFFEE\TickData\Pepperstone\GER40_2025_03.tab_zip'; // The chunk size for fetching data from the server. C_MAX_FETCH = 200; { TTest_TABFileServer_Equivalence } procedure TTest_TABFileServer_Equivalence.SetupFixture; begin // TAskBid.ClearCache ensures a clean state for data series loading. TAskBid.ClearCache; end; procedure TTest_TABFileServer_Equivalence.TearDownFixture; begin // Resets the global IsMemoryLow function pointer, if it was set for testing. IsMemoryLow := nil; end; procedure TTest_TABFileServer_Equivalence.Setup; begin // Initializes the data server with a specific test file. FServer := TAuraTABFileServer.Create(C_TEST_FILENAME); end; procedure TTest_TABFileServer_Equivalence.TearDown; begin // Releases the data server instance. FServer := nil; // Clears any cached data to prevent interference with subsequent tests. TAskBid.ClearCache; end; procedure TTest_TABFileServer_Equivalence.Test_ServerReturnsSameDataAs_LoadDataSeries; var chunk: array[0..C_MAX_FETCH - 1] of TDataPoint; Dst: TArray>; i: Int64; begin // Loads the expected data directly using TAskBid.LoadDataSeries.WaitFor. var ExpectedData := TAskBid.LoadDataSeries(C_TEST_FILENAME).WaitFor; SetLength(Dst, Length(ExpectedData)); var cnt: Int64 := 0; var n: Integer; // Fetches data chunks from the server until all data is retrieved or server indicates live data. while not FServer.IsLiveData.Value and (cnt < Length(Dst)) do begin n := FServer.GetChunk(chunk); if n > 0 then Move(chunk[0], dst[cnt], n * sizeof(TDataPoint)); inc(cnt, n); end; // --- Assertions --- // 1. Verify that the total number of records fetched from the server matches the expected count. Assert.AreEqual(Length(ExpectedData), cnt, 'Data record count mismatch'); // 2. Verify that the content of each record is identical. // The loop checks every 1000th element for efficiency. for n := 0 to High(ExpectedData) div 1000 do begin i := n * 1000; Assert.AreEqual(ExpectedData[i].TimeStamp, Dst[i].Time, 'Timestamp mismatch'); Assert.AreEqual(ExpectedData[i].Data.Ask, Dst[i].Data.Ask, 'Ask price mismatch'); Assert.AreEqual(ExpectedData[i].Data.Bid, Dst[i].Data.Bid, 'Bid price mismatch'); end; end; initialization // Registers the test fixture with DUnitX. TDUnitX.RegisterTestFixture(TTest_TABFileServer_Equivalence); end.