private static void TestSingle(Type t, int rounds) { for (int i = 0; i < rounds; i++) { ICommand raw = (ICommand)RandomPropertyGenerator.Create(t); var nameAndVersion = CommandManager.FindNameAndVersionForType(raw); ICommand cmd = DeserializeSingle(nameAndVersion.Item2, raw.ToByteArray()); if (!t.GetTypeInfo().IsAssignableFrom(cmd.GetType())) { throw new Exception("Deserialized command of wrong type"); } RandomPropertyGenerator.AssertAreTheSame(raw, cmd); } // Create an 'empty' class ICommand raw2 = (ICommand)Activator.CreateInstance(t); var nameAndVersion2 = CommandManager.FindNameAndVersionForType(raw2); ICommand cmd2 = DeserializeSingle(nameAndVersion2.Item2, raw2.ToByteArray()); if (!t.GetTypeInfo().IsAssignableFrom(cmd2.GetType())) { throw new Exception("Deserialized command of wrong type"); } }
private void TestStartingWithMacroOperationSingle(Type t, int rounds) { for (int i = 0; i < rounds; i++) { MacroOpBase raw = (MacroOpBase)RandomPropertyGenerator.Create(t); ICommand cmd = raw.ToCommand(); bool nullCommand = cmd == null; bool shouldBeNull = expectedNullCommand.Contains(t); //Assert.Equal(shouldBeNull, nullCommand); // TODO - reenable this once possible if (shouldBeNull || nullCommand) { continue; } var serCmd = cmd as SerializableCommandBase; // TODO - this shouldnt be needed once all Commands have appropriate macro stuff set Assert.NotNull(serCmd); MacroOpBase entry = serCmd.ToMacroOps().Single(); if (entry == null) { throw new Exception("Deserialized not implemented"); } if (!t.GetTypeInfo().IsAssignableFrom(entry.GetType())) { throw new Exception("Deserialized operation of wrong type"); } RandomPropertyGenerator.AssertAreTheSame(raw, entry); } }
private static void TestSingle(Type t, int rounds) { for (int i = 0; i < rounds; i++) { ICommand raw = (ICommand)RandomPropertyGenerator.Create(t); ICommand cmd = DeserializeSingle(raw.ToByteArray()); if (!t.GetTypeInfo().IsAssignableFrom(cmd.GetType())) { throw new Exception("Deserialized command of wrong type"); } RandomPropertyGenerator.AssertAreTheSame(raw, cmd); } }
private static void TestSingle(Type t, int rounds) { for (int i = 0; i < rounds; i++) { MacroOpBase raw = (MacroOpBase)RandomPropertyGenerator.Create(t); MacroOpBase cmd = DeserializeSingle(raw.ToByteArray()); if (!t.GetTypeInfo().IsInstanceOfType(cmd)) { throw new Exception("Deserialized operation of wrong type"); } RandomPropertyGenerator.AssertAreTheSame(raw, cmd); } }
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); } }