From 38e2f611d8cfafc5972a5e69672416dd6de36074 Mon Sep 17 00:00:00 2001 From: jose_morato Date: Wed, 18 Dec 2024 11:09:41 +0100 Subject: [PATCH] Use internal class publisher for all tests --- .../OpenDDSharp.UnitTest/DataReaderCDRTest.cs | 160 +++++------------- 1 file changed, 44 insertions(+), 116 deletions(-) diff --git a/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs b/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs index ef53560c..fe1bf81a 100644 --- a/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs +++ b/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs @@ -545,9 +545,8 @@ public void TestGetSampleRejectedStatus() statusCondition.EnabledStatuses = StatusKind.SampleRejectedStatus; TestHelper.CreateWaitSetThread(evt, statusCondition); - var publisher = _participant.CreatePublisher(); var dwQos = new DataWriterQos(); - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -590,9 +589,7 @@ public void TestGetSampleRejectedStatus() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -629,7 +626,6 @@ public void TestGetLivelinessChangedStatus() Assert.AreEqual(InstanceHandle.HandleNil, status.LastPublicationHandle); // Creates a datawriter - var publisher = _participant.CreatePublisher(); var dwQos = new DataWriterQos { Liveliness = @@ -638,7 +634,7 @@ public void TestGetLivelinessChangedStatus() LeaseDuration = new Duration { Seconds = 1 }, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); Assert.IsNotNull(dataWriter); @@ -682,9 +678,7 @@ public void TestGetLivelinessChangedStatus() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -697,9 +691,6 @@ public void TestGetRequestedDeadlineMissedStatus() using var evt = new ManualResetEventSlim(false); // Initialize entities - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var qos = new DataWriterQos { Deadline = @@ -707,7 +698,7 @@ public void TestGetRequestedDeadlineMissedStatus() Period = new Duration { Seconds = 1 }, }, }; - var writer = publisher.CreateDataWriter(_topic, qos); + var writer = _publisher.CreateDataWriter(_topic, qos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -755,9 +746,7 @@ public void TestGetRequestedDeadlineMissedStatus() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -795,9 +784,6 @@ public void TestGetRequestedIncompatibleQosStatus() Assert.AreEqual(0, status.LastPolicyId); // Create a not compatible writer - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -805,7 +791,7 @@ public void TestGetRequestedIncompatibleQosStatus() Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); Assert.IsTrue(evt.Wait(1_500)); @@ -823,9 +809,7 @@ public void TestGetRequestedIncompatibleQosStatus() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -863,9 +847,6 @@ public void TestGetSubscriptionMatchedStatus() Assert.AreEqual(InstanceHandle.HandleNil, status.LastPublicationHandle); // Create a not compatible writer - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -873,7 +854,7 @@ public void TestGetSubscriptionMatchedStatus() Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); // Wait for discovery and check the status @@ -888,7 +869,7 @@ public void TestGetSubscriptionMatchedStatus() Assert.AreEqual(InstanceHandle.HandleNil, status.LastPublicationHandle); // Create a compatible writer - var otherWriter = publisher.CreateDataWriter(_topic); + var otherWriter = _publisher.CreateDataWriter(_topic); Assert.IsNotNull(otherWriter); // Wait for discovery and check the status @@ -904,10 +885,8 @@ public void TestGetSubscriptionMatchedStatus() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteDataWriter(otherWriter); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); + _publisher.DeleteDataWriter(otherWriter); } /// @@ -943,9 +922,8 @@ public void TestGetSampleLostStatus() statusCondition.EnabledStatuses = StatusKind.SampleLostStatus; TestHelper.CreateWaitSetThread(evt, statusCondition); - var publisher = _participant.CreatePublisher(); var dwQos = new DataWriterQos(); - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -985,9 +963,7 @@ public void TestGetSampleLostStatus() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -1000,9 +976,6 @@ public void TestWaitForHistoricalData() using var evt = new ManualResetEventSlim(false); // Initialize entities - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1018,7 +991,7 @@ public void TestWaitForHistoricalData() Kind = DurabilityQosPolicyKind.TransientLocalDurabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -1086,9 +1059,7 @@ public void TestWaitForHistoricalData() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -1126,9 +1097,6 @@ public void TestGetMatchedPublications() Assert.AreEqual(ReturnCode.BadParameter, result); // Create a not compatible writer - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1136,7 +1104,7 @@ public void TestGetMatchedPublications() Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); // Wait for discovery and check the matched subscriptions @@ -1147,7 +1115,7 @@ public void TestGetMatchedPublications() Assert.AreEqual(0, list.Count); // Create a compatible writer - var otherWriter = publisher.CreateDataWriter(_topic); + var otherWriter = _publisher.CreateDataWriter(_topic); Assert.IsNotNull(otherWriter); // Wait for discovery and check the matched subscriptions @@ -1160,10 +1128,8 @@ public void TestGetMatchedPublications() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteDataWriter(otherWriter); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); + _publisher.DeleteDataWriter(otherWriter); } /// @@ -1278,9 +1244,6 @@ public void TestRead() statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; TestHelper.CreateWaitSetThread(evt, statusCondition); - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1288,7 +1251,7 @@ public void TestRead() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -1376,9 +1339,7 @@ public void TestRead() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -1411,9 +1372,6 @@ public void TestTake() statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; TestHelper.CreateWaitSetThread(evt, statusCondition); - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1421,7 +1379,7 @@ public void TestTake() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -1537,8 +1495,7 @@ public void TestTake() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -1571,9 +1528,6 @@ public void TestReadInstance() var statusCondition = reader.StatusCondition; statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1581,7 +1535,7 @@ public void TestReadInstance() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -1688,9 +1642,7 @@ public void TestReadInstance() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -1723,9 +1675,6 @@ public void TestTakeInstance() var statusCondition = reader.StatusCondition; statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1733,7 +1682,7 @@ public void TestTakeInstance() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -1846,9 +1795,7 @@ public void TestTakeInstance() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -1892,7 +1839,9 @@ public void TestReadNextInstance() }; var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); + var dataWriter = new TestIncludeDataWriter(writer); + Assert.IsNotNull(dataWriter); // Wait for discovery var found = reader.WaitForPublications(1, 5_000); @@ -1909,8 +1858,8 @@ public void TestReadNextInstance() result = dataWriter.Write(new TestInclude { Id = i.ToString() }); Assert.AreEqual(ReturnCode.Ok, result); - // result = dataWriter.WaitForAcknowledgments(duration); - // Assert.AreEqual(ReturnCode.Ok, result); + result = dataWriter.WaitForAcknowledgments(duration); + Assert.AreEqual(ReturnCode.Ok, result); Assert.IsTrue(evt.Wait(1_500)); @@ -1920,8 +1869,8 @@ public void TestReadNextInstance() result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i }); Assert.AreEqual(ReturnCode.Ok, result); - // result = dataWriter.WaitForAcknowledgments(duration); - // Assert.AreEqual(ReturnCode.Ok, result); + result = dataWriter.WaitForAcknowledgments(duration); + Assert.AreEqual(ReturnCode.Ok, result); Assert.IsTrue(evt.Wait(1_500)); } @@ -2011,9 +1960,6 @@ public void TestTakeNextInstance() var statusCondition = reader.StatusCondition; statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -2021,7 +1967,7 @@ public void TestTakeNextInstance() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -2109,9 +2055,7 @@ public void TestTakeNextInstance() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -2144,9 +2088,6 @@ public void TestReadNextSample() var statusCondition = reader.StatusCondition; statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -2154,7 +2095,7 @@ public void TestReadNextSample() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -2227,9 +2168,7 @@ public void TestReadNextSample() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -2262,9 +2201,6 @@ public void TestTakeNextSample() var statusCondition = reader.StatusCondition; statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -2272,7 +2208,7 @@ public void TestTakeNextSample() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -2345,9 +2281,7 @@ public void TestTakeNextSample() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -2375,7 +2309,6 @@ public void TestGetKeyValue() statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; TestHelper.CreateWaitSetThread(evt, statusCondition); - var publisher = _participant.CreatePublisher(); var dwQos = new DataWriterQos { Reliability = @@ -2383,7 +2316,7 @@ public void TestGetKeyValue() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -2423,9 +2356,7 @@ public void TestGetKeyValue() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -2453,8 +2384,7 @@ public void TestLookupInstance() statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; TestHelper.CreateWaitSetThread(evt, statusCondition); - var publisher = _participant.CreatePublisher(); - var writer = publisher.CreateDataWriter(_topic); + var writer = _publisher.CreateDataWriter(_topic); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); @@ -2484,9 +2414,7 @@ public void TestLookupInstance() reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } #endregion }