private static MacroOpBase DeserializeSingle(byte[] arr) { Assert.True(arr.Length >= 4); int cmdLength = arr[0]; Assert.False(arr.Length != cmdLength || cmdLength == 0); return(MacroOpManager.CreateFromData(arr, false)); }
private void RunForFile(string byteFilename, string xmlFilename) { XmlState xmlSpec = XmlStatePersistor.LoadState(xmlFilename); Assert.NotNull(xmlSpec); bool failed = false; using (StreamReader byteFile = new StreamReader(byteFilename)) { while (!byteFile.EndOfStream) { string[] parts = byteFile.ReadLine().Split(": "); Assert.Equal(2, parts.Length); int index = int.Parse(parts[0]); int count = int.Parse(parts[1]); Macro macroXml = xmlSpec.MacroPool.FirstOrDefault(m => m.Index == index); Assert.NotNull(macroXml); List <byte[]> data = Enumerable.Range(0, count).Select(x => byteFile.ReadLine().HexToByteArray()).ToList(); Assert.Equal(macroXml.Operations.Count, data.Count); for (var i = 0; i < count; i++) { try { MacroOpBase converted = MacroOpManager.CreateFromData(data[i], false); MacroOpBase op = macroXml.Operations[i].ToMacroOp(); if (!Equals(converted, op)) { output.WriteLine("Line {2}\nGot:\n {0}Expected:\n {1}", ToString(converted), ToString(op), i); failed = true; } } catch (Exception e) { output.WriteLine(e.Message + "\n"); failed = true; } } } } Assert.False(failed); }
public void AutoTestMacroOps() { using (var helper = new AtemComparisonHelper(Client, Output)) { IBMDSwitcherMacroControl ctrl = GetMacroControl(); var failures = new List <string>(); Assembly assembly = typeof(ICommand).GetTypeInfo().Assembly; IEnumerable <Type> types = assembly.GetTypes().Where(t => typeof(SerializableCommandBase).GetTypeInfo().IsAssignableFrom(t)); foreach (Type type in types) { if (type == typeof(SerializableCommandBase)) { continue; } /* * if (type != typeof(AuxSourceSetCommand)) * continue;*/ try { Output.WriteLine("Testing: {0}", type.Name); for (int i = 0; i < 10; i++) { SerializableCommandBase raw = (SerializableCommandBase)RandomPropertyGenerator.Create(type, (o) => AvailabilityChecker.IsAvailable(helper.Profile, o)); // TODO - wants to be ICommand IEnumerable <MacroOpBase> expectedOps = raw.ToMacroOps(ProtocolVersion.Latest); if (expectedOps == null) { Output.WriteLine("Skipping"); break; } using (new StopMacroRecord(ctrl)) // Hopefully this will stop recording if it exceptions { ctrl.Record(0, string.Format("record-{0}-{1}", type.Name, i), ""); helper.SendCommand(raw); helper.Sleep(20); } helper.Sleep(40); byte[] r = DownloadMacro(0); if (r.Length == 0) { throw new Exception("Macro has no operations"); } MacroOpBase decoded = MacroOpManager.CreateFromData(r, false); // This is assuming that there is a single macro op RandomPropertyGenerator.AssertAreTheSame(expectedOps.Single(), decoded); } } catch (Exception e) { var msg = string.Format("{0}: {1}", type.Name, e.Message); Output.WriteLine(msg); failures.Add(msg); } } Assert.Empty(failures); } }
private static IReadOnlyList <MacroOpBase> Deserialize(IEnumerable <byte[]> data) { return(data?.Select(d => MacroOpManager.CreateFromData(d, true)).ToList()); }