예제 #1
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        private static void TestSingle(Type t, int rounds)
        {
            for (int i = 0; i < rounds; i++)
            {
                ICommand raw = (ICommand)RandomPropertyGenerator.Create(t);

                string jsonStr = JsonConvert.SerializeObject(raw);
                var    cmd     = (ICommand)JsonConvert.DeserializeObject(jsonStr, t);
                if (!t.GetTypeInfo().IsAssignableFrom(cmd.GetType()))
                {
                    throw new Exception("Deserialized command of wrong type");
                }

                Assert.Equal(raw.ToByteArray(), cmd.ToByteArray());
            }
        }
예제 #6
0
        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 IEnumerable <CommandEntry> GenerateData(IReadOnlyList <CommandEntry> lastData)
        {
            var lastDataByHash = new Dictionary <string, List <CommandEntry> >();

            foreach (CommandEntry entry in lastData)
            {
                if (string.IsNullOrEmpty(entry.commandHash))
                {
                    continue;
                }

                if (lastDataByHash.TryGetValue(entry.commandHash, out var tmp))
                {
                    tmp.Add(entry);
                }
                else
                {
                    lastDataByHash.Add(entry.commandHash, new List <CommandEntry> {
                        entry
                    });
                }
            }

            Assembly           assembly = typeof(ICommand).GetTypeInfo().Assembly;
            IEnumerable <Type> types    = assembly.GetTypes().Where(t => typeof(ICommand).GetTypeInfo().IsAssignableFrom(t));

            foreach (Type type in types)
            {
                if (type.IsAbstract)
                {
                    continue;
                }

                var commandHash = GenerateCommandHash(type);
                if (lastDataByHash.TryGetValue(commandHash, out var previous))
                {
                    // Re-use the ones from last time, as they must still be valid

                    foreach (var entry in previous)
                    {
                        yield return(entry);
                    }

                    continue;
                }

                if (!typeof(SerializableCommandBase).GetTypeInfo().IsAssignableFrom(type))
                {
                    if (type == typeof(DataTransferDataCommand))
                    {
                        // TODO
                        yield return(new CommandEntry(new DataTransferDataCommand {
                            TransferId = 0x1bf4,
                            Body = RandomBytes(12)
                        }));

                        yield return(new CommandEntry(new DataTransferDataCommand {
                            TransferId = 0x001b,
                            Body = RandomBytes(242)
                        }));
                    }

                    continue;
                }

                // if (type != typeof(PowerStatusCommand))
                //     continue;

                var cases = new List <string>();

                for (int i = 0; i < 10; i++)
                {
                    ICommand raw = (ICommand)RandomPropertyGenerator.Create(type);

                    var cs1 = new CommandEntry(raw)
                    {
                        commandHash = commandHash
                    };
                    var cs1s = JsonConvert.SerializeObject(cs1, Formatting.Indented, new Int64Converter());
                    if (cases.Contains(cs1s))
                    {
                        continue;
                    }

                    cases.Add(cs1s);
                    yield return(cs1);
                }
            }
        }