示例#1
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");
        }