예제 #1
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");
        }
예제 #2
0
        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.");
        }
예제 #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");
        }
예제 #4
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);
        }
예제 #5
0
        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");
        }
예제 #6
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);
        }