Example #1
0
        /// <summary>
        /// App entry point
        /// </summary>
        /// <param name="args">Command line arguments</param>
        public static void Main(string[] args)
        {
            try
            {
                string config;
                string explode;

                string job = ParseArguments(args, out config, out explode);
                if (job == null && explode == null)
                {
                    PrintUsage();
                    Environment.Exit(-1);
                }

                if (explode != null)
                {
                    FileInfo swfFile = new FileInfo(explode);
                    using (FileStream swfIn = new FileStream(explode, FileMode.Open, FileAccess.Read))
                    {
                        ABCCatcher catcher = new ABCCatcher();
                        SWFReader  reader  = new SWFReader(swfIn, new SWFReaderOptions(), null, catcher);
                        reader.ReadSWF(new SWFContext(explode));
                        catcher.SaveAll(explode, swfFile.DirectoryName);
                    }
                }

                Swiffotron swiffotron;
                if (config == null)
                {
                    swiffotron = new Swiffotron(null);
                }
                else
                {
                    using (FileStream cfs = new FileStream(config, FileMode.Open, FileAccess.Read))
                    {
                        swiffotron = new Swiffotron(cfs);
                    }
                }

                if (job != null)
                {
                    using (FileStream jobfs = new FileStream(job, FileMode.Open, FileAccess.Read))
                    {
                        swiffotron.Process(jobfs);
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
        }
Example #2
0
        public SWFProcessor()
        {
            this.EventLog        = new EventLog();
            this.EventLog.Source = "Swiffotron";
            this.EventLog.Log    = "Application";

            string swiffotronDLLPath = Assembly.GetAssembly(typeof(Swiffotron)).CodeBase;

            if (swiffotronDLLPath.StartsWith("file:///"))
            {
                swiffotronDLLPath = swiffotronDLLPath.Substring(8);
            }
            FileInfo      dllInfo = new FileInfo(swiffotronDLLPath);
            DirectoryInfo dllDir  = dllInfo.Directory;

            string configName = ConfigurationManager.AppSettings["SwiffotronConfig"];

            if (configName == null || configName == string.Empty)
            {
                configName = @"swiffotron-config.xml";
            }

            FileInfo configFile = new FileInfo(configName);

            if (!configFile.Exists)
            {
                configFile = new FileInfo(dllDir + @"\" + configName);
            }

            if (!configFile.Exists)
            {
                this.EventLog.WriteEntry(
                    "Failed to find a Swiffotron config file at " + configFile.FullName,
                    EventLogEntryType.Error,
                    (int)LogEvents.BadConfig);
                return;
            }

            try
            {
                using (FileStream fs = new FileStream(configFile.FullName, FileMode.Open, FileAccess.Read))
                {
                    this.Swiffotron = new Swiffotron(fs);
                }
            }
            catch (Exception e)
            {
                this.EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error, (int)LogEvents.BadConfig);
            }

            this.EventLog.WriteEntry("Swiffotron is using configuration found at " + configFile.FullName + " (SwiffotronConfig = '" + ConfigurationManager.AppSettings["SwiffotronConfig"] + "')", EventLogEntryType.Information, (int)LogEvents.StartupInfo);
        }
Example #3
0
        private void SvgOutputTest(string xmlIn, string imageOut, out Swiffotron swiffotron)
        {
            MockStore store;
            MockCache cache;

            swiffotron = CreateMockSwiffotron(out store, out cache);

            Dictionary <string, byte[]> commits = new Dictionary <string, byte[]>();

            swiffotron.Process(ResourceAsStream(xmlIn), commits, null, null, null, null);
            CheckCommits(commits);

            CopyStoreToTestDir(store);

            Assert.IsTrue(store.Has(imageOut), @"Output was not saved");
        }
Example #4
0
        /// <summary>
        /// Creates a swiffotron from the mock config profile and checks that everything is created
        /// correctly.
        /// </summary>
        /// <param name="mockStore">Returns a reference to the private store for testing.</param>
        /// <param name="htCache">Returns a reference to the private cache for testing.</param>
        /// <returns>A private accessor reference to the new Swiffotron.</returns>
        protected Swiffotron CreateMockSwiffotron(out MockStore mockStore, out MockCache htCache)
        {
#if(EXPRESS2010)
            Swiffotron swiffotron = new Swiffotron(ResourceAsStream(@"mock-config-express.xml"));
#else
            Swiffotron swiffotron = new Swiffotron(ResourceAsStream(@"mock-config.xml"));
#endif

            mockStore = (MockStore)swiffotron.conf_accessor.Stores.stores_accessor[@"store"];
            Assert.IsNotNull(mockStore, @"The store object was not created.");
            Assert.IsTrue(mockStore.InitialisedProperly, @"The store was not initialised properly");

            htCache = (MockCache)swiffotron.conf_accessor.Caches.caches_accessor[@"cache"];

            Assert.IsNotNull(htCache, @"The cache object was not created.");

            return swiffotron;
        }
Example #5
0
        /// <summary>
        /// Creates a swiffotron from the mock config profile and checks that everything is created
        /// correctly.
        /// </summary>
        /// <param name="mockStore">Returns a reference to the private store for testing.</param>
        /// <param name="htCache">Returns a reference to the private cache for testing.</param>
        /// <returns>A private accessor reference to the new Swiffotron.</returns>
        protected Swiffotron CreateMockSwiffotron(out MockStore mockStore, out MockCache htCache)
        {
#if (EXPRESS2010)
            Swiffotron swiffotron = new Swiffotron(ResourceAsStream(@"mock-config-express.xml"));
#else
            Swiffotron swiffotron = new Swiffotron(ResourceAsStream(@"mock-config.xml"));
#endif

            mockStore = (MockStore)swiffotron.conf_accessor.Stores.stores_accessor[@"store"];
            Assert.IsNotNull(mockStore, @"The store object was not created.");
            Assert.IsTrue(mockStore.InitialisedProperly, @"The store was not initialised properly");

            htCache = (MockCache)swiffotron.conf_accessor.Caches.caches_accessor[@"cache"];

            Assert.IsNotNull(htCache, @"The cache object was not created.");

            return(swiffotron);
        }
        private void TestExpectedSwiffotronError(
            string inputXML,
            SwiffotronError error,
            string errorSentinel,
            SWFModellerError?innerError = null,
            string innerSentinel        = null)
        {
            /* Why not use expected exception attributes from MSTest? Well because we want to inspect not
             * only the extra error information that our fabulous custom exceptions provide, but we want to
             * inspect inner exceptions too. We're that thorough. */

            MockStore  store;
            MockCache  cache;
            Swiffotron swiffotron = CreateMockSwiffotron(out store, out cache);

            StringBuilder writeLog    = new StringBuilder();
            StringBuilder abcWriteLog = new StringBuilder();

            try
            {
                swiffotron.Process(ResourceAsStream(inputXML), null, null, null, null, null);
                Assert.Fail("An exception of type " + error + " was expected. No exception was thrown.");
            }
            catch (SwiffotronException se)
            {
                Assert.AreEqual(error, se.Error, "Error mismatch: " + se.Message);
                Assert.AreEqual(errorSentinel, se.Sentinel, "Error sentinel mismatch: " + se.Message);
                if (innerError != null)
                {
                    Assert.IsTrue(se.InnerException is SWFModellerException, "Expected an inner exception of type SWFModellerException");
                    Assert.AreEqual(innerError, (se.InnerException as SWFModellerException).Error, "Error mismatch: " + se.InnerException.Message);
                    Assert.AreEqual(innerSentinel, (se.InnerException as SWFModellerException).Sentinel, "Error sentinel mismatch: " + se.InnerException.Message);
                }
            }

            /* And as a parting shot: */
            Assert.AreNotEqual(error, SwiffotronError.Internal, "Can't test for Internal errors. This test is clearly not written properly.");
        }
Example #7
0
        private void SvgOutputTest(string xmlIn, string imageOut, out Swiffotron swiffotron)
        {
            MockStore store;
            MockCache cache;
            swiffotron = CreateMockSwiffotron(out store, out cache);

            Dictionary<string, byte[]> commits = new Dictionary<string, byte[]>();
            swiffotron.Process(ResourceAsStream(xmlIn), commits, null, null, null, null);
            CheckCommits(commits);

            CopyStoreToTestDir(store);

            Assert.IsTrue(store.Has(imageOut), @"Output was not saved");
        }
Example #8
0
        private bool ENABLED = false; /* Shady way to do this really. Set to true to see the blue-sky tests and
                                       * inevitably, by definition, fail. */

        private void Process(Swiffotron swiffotron, string name)
        {
            swiffotron.Process(ResourceAsStream(name), null, null, null, null, null);
        }
        private void PredictedOutputTest(string xmlIn, string swfOut, out Swiffotron swiffotron)
        {
            MockStore store;
            MockCache cache;

            swiffotron = CreateMockSwiffotron(out store, out cache);

            StringBuilder writeLog              = new StringBuilder();
            StringBuilder abcWriteLog           = new StringBuilder();
            Dictionary <string, byte[]> commits = new Dictionary <string, byte[]>();

            swiffotron.Process(ResourceAsStream(xmlIn), commits, writeLog, abcWriteLog, this, this);
            CheckCommits(commits);

            using (FileStream fs = new FileStream(TestDir + xmlIn + ".writelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(writeLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            using (FileStream fs = new FileStream(TestDir + xmlIn + ".abcwritelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(abcWriteLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            CopyStoreToTestDir(store);

            Assert.IsTrue(store.Has(swfOut), @"Output was not saved");

            /* Check that a valid SWF file was produced by reading it back: */
            StringBuilder binDump = new StringBuilder();

            SWF swf = null;

            SWFReader sr = new SWFReader(
                store.OpenInput(swfOut),
                new SWFReaderOptions()
            {
                StrictTagLength = true
            },
                binDump,
                this);     /* constantFilter is a delegate function that will throw an exception
                            * if it spots something objectionable in the SWF's constants. */

            try
            {
                swf = sr.ReadSWF(new SWFContext(swfOut));

                /* The delegate we gave to the SWF reader for trapping ABC constants will
                 * not have been run yet since the SWF reader doesn't parse the ABC unless
                 * it really needs to. Here's how we force it to, and run the filter
                 * delegate... */

                swf.ScriptProc(delegate(DoABC abc)
                {
                    AbcCode code = abc.Code; /* Transparently parses the ABC */
                });
            }
            finally
            {
                using (FileStream fs = new FileStream(TestDir + xmlIn + ".bin.dump.txt", FileMode.Create))
                {
                    byte[] dumpbindata = new ASCIIEncoding().GetBytes(binDump.ToString());
                    fs.Write(dumpbindata, 0, dumpbindata.Length);
                }
            }

            string predicted = TestDir + swfOut + ".model.predict.txt";

            using (Stream input = ResourceAsStream("predicted." + swfOut + ".txt"))
                using (FileStream output = new FileStream(predicted, FileMode.Create))
                {
                    Assert.IsNotNull(input, "Predicted output is missing! " + swfOut);
                    CopyStream(input, output);
                }

            using (StreamWriter acceptScript = new StreamWriter(new FileStream(TestDir + "accept.bat", FileMode.Create)))
            {
                acceptScript.WriteLine("copy \"" + lastCommitModelOutput + "\" \"" + new FileInfo("..\\..\\..\\SwiffotronTest\\res\\predicted\\" + swfOut + ".txt").FullName + "\"");
            }

            using (StreamWriter viewScript = new StreamWriter(new FileStream(TestDir + "viewdiff.bat", FileMode.Create)))
            {
                /* ISSUE 44: This should be a diff tool env var */
                viewScript.WriteLine("\"c:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" \"" + lastCommitModelOutput + "\" \"" + new FileInfo("..\\..\\..\\SwiffotronTest\\res\\predicted\\" + swfOut + ".txt").FullName + "\"");
            }

            CompareFiles(
                predicted,
                lastCommitModelOutput,
                "Predicted output failure! These files differ: " + swfOut + ".model.predict.txt" + ", " + swfOut + ".model.txt");
        }
Example #10
0
 public void TestBrokenConfig()
 {
     Swiffotron swiffotron = new Swiffotron(ResourceAsStream(@"TestBrokenConfig.xml"));
 }
Example #11
0
 public void TestDefaultConfig()
 {
     Swiffotron swiffotron = new Swiffotron(null);
 }
Example #12
0
        private bool ENABLED = false; /* Shady way to do this really. Set to true to see the blue-sky tests and
                                       * inevitably, by definition, fail. */

        private void Process(Swiffotron swiffotron, string name)
        {
            swiffotron.Process(ResourceAsStream(name), null, null, null, null, null);
        }