示例#1
0
        private static bool Equals(MacroOpBase x, MacroOpBase y)
        {
            if (x == null || y == null)
            {
                return(false);
            }

            if (x.GetType() != y.GetType())
            {
                return(false);
            }

            AutoSerializeBase.CommandPropertySpec info = AutoSerializeBase.GetPropertySpecForType(x.GetType());

            foreach (var prop in info.Properties)
            {
                object xVal = prop.Getter.DynamicInvoke(x);
                object yVal = prop.Getter.DynamicInvoke(y);
                if (Equals(xVal, yVal))
                {
                    continue;
                }

                if (prop.PropInfo.PropertyType == typeof(double) && Math.Abs((double)xVal - (double)yVal) <= 0.001)
                {
                    continue;
                }

                return(false);
            }

            return(true);
        }
        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++)
            {
                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);
            }
        }
示例#4
0
        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);
        }
示例#5
0
        private static string ToString(MacroOpBase op)
        {
            AutoSerializeBase.CommandPropertySpec info = AutoSerializeBase.GetPropertySpecForType(op.GetType());

            var sb = new StringBuilder();

            sb.Append(op.GetType().Name);
            sb.Append(":\n");

            foreach (var prop in info.Properties)
            {
                sb.AppendFormat("    {0}={1}\n", prop.PropInfo.Name, prop.Getter.DynamicInvoke(op));
            }

            return(sb.ToString());
        }
示例#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);
            }
        }