Esempio n. 1
0
        public List <TestResult> CheckCommodityExtractor(string infoFile)
        {
            List <TestResult> results = new List <TestResult>();

            CaptureInfo  info = CaptureInfo.Deserialize("Test\\" + infoFile);
            UnsafeBitmap bm   = new UnsafeBitmap("Test\\" + info.BitmapFile);

            ppocr.ClearErrors();

            DateTime dtStart = DateTime.Now;

            Rectangle commodArea = ppocr.FindCommodityArea(bm);

            if (commodArea != info.CommodityRect)
            {
                results.Add(new TestResult(infoFile, "Commodity Rect Expected " + info.CommodityRect.ToString() + ", got " + commodArea.ToString()));
                return(results);
            }

            string island = ppocr.ExtractIslandName(bm);

            if (!island.Equals(info.Island))
            {
                results.Add(new TestResult(infoFile, "Expected island name: " + info.Island + ", Got: " + island));
            }

            List <Commodity> commodities = ppocr.ExtractCommodities(bm, commodArea);

            if (ppocr.Error.Length > 0)
            {
                results.Add(new TestResult(infoFile, ppocr.Error));
            }

            List <Commodity> refCommods = info.Commodities;

            if (refCommods.Count != commodities.Count)
            {
                results.Add(new TestResult(infoFile, "Commodities Count is " + commodities.Count.ToString() + ", expected " + refCommods.Count.ToString()));
            }

            for (int i = 0; i < refCommods.Count && i < commodities.Count; i++)
            {
                if (!commodities[i].ToString().Equals(refCommods[i].ToString()))
                {
                    results.Add(new TestResult(infoFile, "Expected: " + refCommods[i].ToString() + " Got: " + commodities[i].ToString()));
                }
            }

            DateTime dtStop = DateTime.Now;

            if (results.Count <= 0)
            {
                TestResult result = new TestResult(infoFile, "PASS");
                result.Duration = dtStop.Subtract(dtStart).TotalSeconds.ToString();
                results.Add(result);
            }

            return(results);
        }
Esempio n. 2
0
        public static CaptureInfo Deserialize(string file)
        {
            Console.WriteLine(Directory.GetCurrentDirectory());
            if (File.Exists(file) == false)
            {
                return(null);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(CaptureInfo));

            TextReader reader = new StreamReader(file);

            if (reader == null)
            {
                return(null);
            }

            CaptureInfo info = new CaptureInfo();

            info = (CaptureInfo)serializer.Deserialize(reader);

            reader.Close();
            return(info);
        }