Ejemplo n.º 1
0
        public void TestParseNibbles_PNG()
        {
            var testset   = new Pix(@"Tests\Pocorgtfo12-53_24bit.png");
            var resultset = System.IO.File.ReadAllLines(@"Tests\OscarCompareResult_Pocorgtfo12-53_24bit.txt").
                            Where(x => !x.StartsWith(@"//"));

            Assert.AreEqual(4352, testset.Width);
            Assert.AreEqual(5648, testset.Height);

            var oscar = new Oscar(testset);

            var blocks = oscar.GetBlocks();

            var pulses = new List <Barcode.Pulse[]>(blocks.Count);

            foreach (var b in blocks)
            {
                pulses.Add(b.ComputePulses());
            }

            var symbols = new List <int[]>(pulses.Count);

            foreach (var p in pulses)
            {
                symbols.Add(oscar.PulsesToSymbols(p));
            }

            var nibbles = new List <int[]>(symbols.Count);

            foreach (var s in symbols)
            {
                nibbles.Add(oscar.SymbolsToNibbles(s));
            }

            var results = new List <int[]>(symbols.Count);

            foreach (var n in nibbles)
            {
                if (n == null)
                {
                    continue;
                }
                results.Add(oscar.ParseNibbles(n));
            }

            Assert.IsNull(results[0]);// control array so result should be null

            List <string> hexstrings = new List <string>(results.Count());

            foreach (var r in results)
            {
                if (r == null)
                {
                    continue;
                }
                hexstrings.Add(r.Select(x => x.ToString("x2")).Aggregate((a, b) => a + b));
            }

            int pos = -1;

            foreach (var expected in resultset)
            {
                pos++;

                if (pos == 1 || pos == 11 || pos == 13)
                {
                    // will fail
                    continue;
                }

                Assert.AreEqual(expected, hexstrings[pos]);
            }

            Assert.Inconclusive("data lines 1, 11 and 13 are not matching!");
        }