Example #1
0
        public void Test(TestValue tv, string s)
        {
            IIonHashWriter hashWriter = null;

            try
            {
                hashWriter = IonHashWriterBuilder.Standard()
                             .WithWriter(IonTextWriterBuilder.Build(new StringWriter()))
                             .WithHasherProvider(HasherProvider)
                             .Build();
                hashWriter.WriteValues(IonReaderBuilder.Build(s));
            }
            catch (IonException e)
            {
                if (tv.IsValidIon())
                {
                    throw e;
                }
            }

            IIonHashReader hashReader = null;

            try
            {
                hashReader = IonHashReaderBuilder.Standard()
                             .WithReader(IonReaderBuilder.Build(s))
                             .WithHasherProvider(HasherProvider)
                             .Build();
                hashReader.MoveNext();
                hashReader.MoveNext();
            }
            catch (IonException e)
            {
                if (tv.IsValidIon())
                {
                    throw e;
                }
            }

            if (tv.validIon == null || tv.validIon.Value == true)
            {
                TestUtil.AssertEquals(
                    hashWriter.Digest(),
                    hashReader.Digest(),
                    "Reader/writer hashes for line |" + tv.AsIon() + "| as |" + s + "| don't match");
            }
        }
Example #2
0
            public IEnumerable <object[]> GetData(MethodInfo methodInfo)
            {
                List <object[]> list = new List <object[]>();

                try
                {
                    var file       = DirStructure.IonHashTestFile("big_list_of_naughty_strings.txt");
                    var fileStream = file.OpenRead();
                    using (StreamReader sr = new StreamReader(fileStream))
                    {
                        while (!sr.EndOfStream)
                        {
                            String line = sr.ReadLine();
                            if (line.StartsWith("#") || string.IsNullOrEmpty(line))
                            {
                                continue;
                            }
                            TestValue tv = new TestValue(line);

                            list.Add(new object[] { tv, tv.AsSymbol() });
                            list.Add(new object[] { tv, tv.AsString() });
                            list.Add(new object[] { tv, tv.AsLongString() });
                            list.Add(new object[] { tv, tv.AsClob() });
                            list.Add(new object[] { tv, tv.AsBlob() });

                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsSymbol() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsString() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsLongString() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsClob() });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsBlob() });

                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsSymbol() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsString() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsLongString() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsClob() + "}" });
                            list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsBlob() + "}" });

                            if (tv.IsValidIon())
                            {
                                list.Add(new object[] { tv, tv.AsIon() });
                                list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsIon() });
                                list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsIon() + "}" });
                                list.Add(new object[] { tv, tv.AsSymbol() + "::{" + tv.AsSymbol() + ":" + tv.AsSymbol() + "::" + tv.AsIon() + "}" });
                            }

                            // list
                            list.Add(new object[]
                            {
                                tv,
                                tv.AsSymbol() + "::["
                                + tv.AsSymbol() + ", "
                                + tv.AsString() + ", "
                                + tv.AsLongString() + ", "
                                + tv.AsClob() + ", "
                                + tv.AsBlob() + ", "
                                + (tv.IsValidIon() ? tv.AsIon() : "")
                                + "]"
                            });

                            // sexp
                            list.Add(new object[]
                            {
                                tv,
                                tv.AsSymbol() + "::("
                                + tv.AsSymbol() + " "
                                + tv.AsString() + " "
                                + tv.AsLongString() + " "
                                + tv.AsClob() + " "
                                + tv.AsBlob() + " "
                                + (tv.IsValidIon() ? tv.AsIon() : "")
                                + ")"
                            });

                            // multiple annotations
                            list.Add(new object[] { tv, tv.AsSymbol() + "::" + tv.AsSymbol() + "::" + tv.AsSymbol() + "::" + tv.AsString() });
                        }
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("The file could not be read:");
                    Console.WriteLine(e.Message);
                }
                return(list);
            }