コード例 #1
0
        TestResult TestWavAndStream(string mod)
        {
            DateTime   start  = DateTime.Now;
            TestResult result = new TestResult();

            result.ModName = mod;
            int  diffBytes         = 0;
            bool reportedMissMatch = false;

            String mikModCWav = Path.Combine(m_Options.TestDirectory, "mikmodC.wav");

            try
            {
                if (File.Exists(mikModCWav))
                {
                    BinaryReader mikModCReader = new BinaryReader(new FileStream(mikModCWav, FileMode.Open));

                    long cSize      = mikModCReader.BaseStream.Length;
                    long cSharpSize = m_SharpTest.MemStream.Length;


                    if (cSize == 44)                     // header size of a wav
                    {
                        // MikMod can't process the mod either so no point checking.
                        // Mark it as a pass but put a note in about it.

                        result.Error           = "MikMod wasn't able to load the mod, so no point checking";
                        result.Passed          = true;
                        result.MatchPercentage = 100;
                    }
                    else
                    {
                        if (cSize != cSharpSize + 44)
                        {
                            result.Error  = "file sizes don't match";
                            result.Passed = false;
                        }
                        else
                        {
                            byte cByte;
                            byte cSharpByte;

                            mikModCReader.BaseStream.Seek(44, SeekOrigin.Begin);
                            m_SharpTest.MemStream.Seek(0, SeekOrigin.Begin);
                            long size = cSize - 44;
                            for (long i = 0; i < size; i++)
                            {
                                cByte      = mikModCReader.ReadByte();
                                cSharpByte = (byte)m_SharpTest.MemStream.ReadByte();

                                if (cByte != cSharpByte)
                                {
                                    if (!reportedMissMatch)
                                    {
                                        reportedMissMatch = true;
                                        Console.WriteLine("First miss matched byte is at: " + i);
                                        result.FirstMissMatchByte = i;
                                    }
                                    diffBytes++;
                                }
                            }

                            result.MatchPercentage = 100.0f * (float)(cSize - diffBytes) / (float)cSize;
                            if (diffBytes > 0)
                            {
                                result.Passed = false;
                            }
                            else
                            {
                                result.Passed = true;
                            }
                        }
                    }



                    mikModCReader.Close();
                    mikModCReader.Dispose();
                }
            }
            catch (Exception ex)
            {
                result.Error  = ex.Message;
                result.Passed = false;
            }

            TimeSpan span = DateTime.Now - start;

            m_TestTime = (float)span.TotalSeconds;


            return(result);
        }
コード例 #2
0
        void TestThread()
        {
            DateTime totalStart = DateTime.Now;

            s_StopThread = false;
            //List<String> modFiles = new List<string>();
            List <TestResult> testResults = new List <TestResult>();

            //modFiles.Clear();

            var files = Directory.EnumerateFiles(m_Options.TestModFolder, "*.*", SearchOption.AllDirectories);

            List <String> modFiles = new List <String>();

            foreach (String name in files)
            {
                if (SharpMikCommon.MatchesExtentions(name))
                {
                    modFiles.Add(name);
                }
            }


            int count = 0;


            MethodInvoker action = delegate
            {
                progressBar2.Maximum = modFiles.Count();
                progressBar2.Value   = 0;
            };

            progressBar2.BeginInvoke(action);



            float total  = 0.0f;
            int   passed = 0;
            int   failed = 0;


            action = delegate
            {
                label7.Text = String.Format("Testing {0} of {1} mods in {5} seconds, Passed: {2}, Failed: {3}, Passing percentage {4}", count, modFiles.Count(), passed, failed, 0.0, (DateTime.Now - totalStart).TotalSeconds);
            };
            label7.BeginInvoke(action);

            foreach (String fileName in modFiles)
            {
                TestResult result = new TestResult();

                DateTime start = DateTime.Now;
                if (DoStreamTest(fileName, ref result))
                {
                    result = TestWavAndStream(fileName);
                }
                TimeSpan span = DateTime.Now - start;

                result.CTime         = m_CTestTime;
                result.CSharpTime    = m_CSTestTime;
                result.TotalTestTime = (float)span.TotalSeconds;
                testResults.Add(result);


                if (!result.Passed && checkBox1.Checked)
                {
                    String failedFolder = Path.Combine(m_Options.TestDirectory, "Failed");
                    String justFileName = Path.GetFileName(fileName);
                    String failName     = Path.Combine(failedFolder, justFileName);

                    if (!File.Exists(failName))
                    {
                        if (!Directory.Exists(failedFolder))
                        {
                            Directory.CreateDirectory(Path.Combine(m_Options.TestDirectory, "Failed"));
                        }

                        File.Copy(fileName, failName);
                    }
                }

                // Write out the results after each test, this will help if the app crashes.
                UnitTestHelpers.WriteXML <List <TestResult> >(Path.Combine(m_Options.TestDirectory, "test.xml"), testResults);

                total += result.MatchPercentage;
                count++;

                Object[] data = new Object[7];
                data[0] = Path.GetFileName(fileName);
                data[1] = result.MatchPercentage;
                data[3] = m_CTestTime;
                data[4] = m_CSTestTime;
                data[5] = m_TestTime;
                data[6] = span.TotalSeconds;

                if (result.Passed)
                {
                    data[2] = global::MikModUnitTest.Properties.Resources.Pass;
                    passed++;
                }
                else
                {
                    data[2] = global::MikModUnitTest.Properties.Resources.Fail;
                    failed++;
                }

                if (this.IsHandleCreated)
                {
                    action = delegate
                    {
                        progressBar2.Value = count;
                    };
                    progressBar2.BeginInvoke(action);

                    action = delegate
                    {
                        dataGridView1.Rows.Add(data);
                    };
                    dataGridView1.BeginInvoke(action);

                    action = delegate
                    {
                        label7.Text = String.Format("Testing {0} of {1} mods in {5} seconds, Passed: {2}, Failed: {3}, Passing percentage {4}", count, modFiles.Count(), passed, failed, total / count, (DateTime.Now - totalStart).TotalSeconds);
                        //label7.Text = String.Format("Testing {0} of {1} mods, Passed: {2}, Failed: {3}, Passing percentage {4}", count, modFiles.Count(), passed, failed, total / count);
                    };
                    label7.BeginInvoke(action);
                }

                if (s_StopThread)
                {
                    break;
                }
            }

            s_StopThread = false;
            ResetButtons();
        }