public void BitmaskFunctionalTest() { // set up a source tag, put it in a dictionary (like in the FDA), and make the dictionary available to the derived tags class Dictionary <Guid, FDADataPointDefinitionStructure> srcTags = new Dictionary <Guid, FDADataPointDefinitionStructure>(); FDADataPointDefinitionStructure srcTag = new FDADataPointDefinitionStructure() { DPDUID = Guid.NewGuid(), DPDSEnabled = true }; srcTags.Add(srcTag.DPDUID, srcTag); DerivedTag.Tags = srcTags; UInt32 expectedDerivedVal; // bitmask 0000 0000 0000 0000 0000 0000 0000 0001 DerivedTag softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":1"); softTag.Initialize(); softTag.DPDSEnabled = true; foreach (UInt32 testVal in TestValues) { // update the value in the source tag srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint( testVal, 192, DateTime.Now, "", DT, DataRequest.WriteMode.Insert); // check that the derived tag has the same timestamp and quality as the source tag Assert.AreEqual(srcTag.LastRead.Timestamp, softTag.LastRead.Timestamp); Assert.AreEqual(srcTag.LastRead.Quality, softTag.LastRead.Quality); // check that the value of the derived tag is correct expectedDerivedVal = testVal & 1; Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value); } // bitmask 0000 0000 0000 0000 1100 0000 0000 0001 softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":49153"); softTag.Initialize(); softTag.DPDSEnabled = true; foreach (UInt32 testVal in TestValues) { // update the value in the source tag srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint( testVal, 192, DateTime.Now, "", DT, DataRequest.WriteMode.Insert); // check that the derived tag has the same timestamp and quality as the source tag Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp); Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality); // check that the value of the derived tag is correct expectedDerivedVal = testVal & 49153; Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value); } // bitmask 1111 1111 1111 1111 1111 1111 1111 1111 softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":4294967295"); softTag.Initialize(); softTag.DPDSEnabled = true; foreach (UInt32 testVal in TestValues) { // update the value in the source tag srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint( testVal, 192, DateTime.Now, "", DT, DataRequest.WriteMode.Insert); // check that the derived tag has the same timestamp and quality as the source tag Assert.AreEqual(srcTag.LastRead.Timestamp, softTag.LastRead.Timestamp); Assert.AreEqual(srcTag.LastRead.Quality, softTag.LastRead.Quality); // check that the value of the derived tag is correct expectedDerivedVal = testVal; Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value); } // bitmask 0000 0000 0000 0000 1100 0000 0000 0001, source tag has bad quality softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":49153"); softTag.Initialize(); softTag.DPDSEnabled = true; FDADataPointDefinitionStructure.Datapoint lastRead_before_trigger; foreach (UInt32 testVal in TestValues) { lastRead_before_trigger = softTag.LastRead; // update the value in the source tag srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint( testVal, 0, // bad quality DateTime.Now, "", DT, DataRequest.WriteMode.Insert); // derived tag should not have updated (LastRead datapoint should not have changed) Assert.AreSame(lastRead_before_trigger, softTag.LastRead); } }
public void BitmaskArgumentValidityChecks() { // set up a source tag, put it in a dictionary (like in the FDA), and make the dictionary available to the derived tags class Dictionary <Guid, FDADataPointDefinitionStructure> srcTags = new Dictionary <Guid, FDADataPointDefinitionStructure>(); FDADataPointDefinitionStructure srcTag = new FDADataPointDefinitionStructure() { DPDSEnabled = true, DPDUID = Guid.NewGuid() }; srcTags.Add(srcTag.DPDUID, srcTag); DerivedTag.Tags = srcTags; // good arguments, should all produce a valid and enabled derived tag List <string> goodArgs = new List <string> { srcTag.DPDUID.ToString() + ":1", // 0000 srcTag.DPDUID.ToString() + ":2", // 0010 srcTag.DPDUID.ToString() + ":4", // 0100 srcTag.DPDUID.ToString() + ":8", // 1000 srcTag.DPDUID.ToString() + ":12", // 1100 srcTag.DPDUID.ToString() + ":2147483648", // 1000 0000 0000 0000 0000 0000 0000 0000 srcTag.DPDUID.ToString() + ":2147483649" // 1000 0000 0000 0000 0000 0000 0000 0001 }; // bad arguments, should all produce an invalid and disabled derived tag List <string> badArgs = new List <string> { null, // null argument "", // empty argument string Guid.NewGuid().ToString(), // not enough args (1) "123456-789:0:2", // invalid SrcID Guid.NewGuid().ToString() + ":0:2", // SrcID not found srcTag.DPDUID.ToString() + ":a", // bit mask not a number srcTag.DPDUID.ToString() + ":1.2", // bit mask not an integer srcTag.DPDUID.ToString() + ":4294967296", // bit mask too high srcTag.DPDUID.ToString() + ":-2" // bit mask too low }; // check that bad softtag id is detected DerivedTag softTag = DerivedTag.Create("12345-678", "bitmask", goodArgs[0]); Assert.AreEqual(softTag.IsValid, false); Assert.AreEqual(softTag.DPDSEnabled, false); // check that bad arguments are detected foreach (string badArgString in badArgs) { softTag = DerivedTag.Create(srcTag.DPDUID.ToString(), "bitmask", badArgString); softTag.Initialize(); Assert.AreEqual(softTag.IsValid, false); Assert.AreEqual(softTag.DPDSEnabled, false); } // check that good arguments are determined to be valid foreach (string goodArgString in goodArgs) { softTag = DerivedTag.Create(srcTag.DPDUID.ToString(), "bitmask", goodArgString); softTag.Initialize(); Assert.AreEqual(true, softTag.IsValid); } }