Пример #1
0
        public void WhenDocumentContainsNestedCollectionsAndComplexText_ThenDocumentIsParsedCorrectly()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/Pods-acknowledgements.plist"))
            {
                var root = PList.Load(stream) as DictionaryNode;

                Assert.IsNotNull(root);
                Assert.AreEqual(3, root.Count);

                Assert.IsInstanceOf <StringNode>(root["StringsTable"]);
                Assert.IsInstanceOf <StringNode>(root["Title"]);

                var array = root["PreferenceSpecifiers"] as ArrayNode;
                Assert.IsNotNull(array);
                Assert.AreEqual(15, array.Count);

                foreach (var node in array)
                {
                    Assert.IsInstanceOf <DictionaryNode>(node);

                    var dictionary = (DictionaryNode)node;
                    Assert.AreEqual(3, dictionary.Count);
                }
            }
        }
Пример #2
0
        public void WhenXmlFormatIsResavedAsBinaryAndOpened_ThenParsedDocumentMatchesTheOriginal()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/asdf-Info.plist"))
            {
                var node = PList.Load(stream);

                using (var outStream = new MemoryStream())
                {
                    PList.Save(node, outStream, PListFormat.Binary);

                    // rewind and reload
                    outStream.Seek(0, SeekOrigin.Begin);
                    var newNode = PList.Load(outStream);

                    // compare
                    Assert.AreEqual(node.GetType().Name, newNode.GetType().Name);

                    var oldDict = node as DictionaryNode;
                    var newDict = newNode as DictionaryNode;

                    Assert.AreEqual(oldDict.Count, newDict.Count);

                    foreach (var key in oldDict.Keys)
                    {
                        Assert.IsTrue(newDict.ContainsKey(key));

                        var oldValue = oldDict[key];
                        var newValue = newDict[key];

                        Assert.AreEqual(oldValue.GetType().Name, newValue.GetType().Name);
                        Assert.AreEqual(oldValue, newValue);
                    }
                }
            }
        }
Пример #3
0
        public void WhenXmlFormatIsSavedAndOpened_ThenParsedDocumentMatchesTheOriginal()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/utf8-Info.plist"))
            {
                // test for <ustring> elements
                bool containsUStrings;
                using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4096, true))
                {
                    var text = reader.ReadToEnd();
                    containsUStrings = text.Contains("<ustring>");
                    stream.Seek(0, SeekOrigin.Begin);
                }

                var node = PList.Load(stream);

                using (var outStream = new MemoryStream())
                {
                    PList.Save(node, outStream, PListFormat.Xml);

                    // rewind and reload
                    outStream.Seek(0, SeekOrigin.Begin);
                    var newNode = PList.Load(outStream);

                    // compare
                    Assert.AreEqual(node.GetType().Name, newNode.GetType().Name);

                    var oldDict = node as DictionaryNode;
                    var newDict = newNode as DictionaryNode;

                    Assert.NotNull(oldDict);
                    Assert.NotNull(newDict);
                    Assert.AreEqual(oldDict.Count, newDict.Count);

                    foreach (var key in oldDict.Keys)
                    {
                        Assert.IsTrue(newDict.ContainsKey(key));

                        var oldValue = oldDict[key];
                        var newValue = newDict[key];

                        Assert.AreEqual(oldValue.GetType().Name, newValue.GetType().Name);
                        Assert.AreEqual(oldValue, newValue);
                    }

                    // lastly, confirm <ustring> contents have not changed
                    outStream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(outStream))
                    {
                        var text = reader.ReadToEnd();
                        var outContainsUStrings = text.Contains("<ustring>");

                        Assert.AreEqual(containsUStrings, outContainsUStrings);
                    }
                }
            }
        }
Пример #4
0
        public void WhenParsingBinaryDocumentWithSingleDictionary_ThenItIsParsedCorrectly()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/asdf-Info-bin.plist"))
            {
                var node = PList.Load(stream);

                Assert.IsNotNull(node);

                var dictionary = node as DictionaryNode;
                Assert.IsNotNull(dictionary);

                Assert.AreEqual(14, dictionary.Count);
            }
        }
Пример #5
0
 public void ReadingFile_GitHub_Issue9_Fail()
 {
     using (var stream = TestFileHelper.GetTestFileStream("TestFiles/github-9.plist"))
     {
         try
         {
             var node = PList.Load(stream);
             Assert.Pass();
         }
         catch (PListFormatException ex)
         {
             Assert.Fail(ex.Message);
         }
     }
 }
Пример #6
0
 public void ReadingFile_With_16bit_Integers_Fail()
 {
     using (var stream = TestFileHelper.GetTestFileStream("TestFiles/unity.binary.plist"))
     {
         try
         {
             var node = PList.Load(stream);
             Assert.Pass();
         }
         catch (PListFormatException ex)
         {
             Assert.Fail(ex.Message);
         }
     }
 }
Пример #7
0
 public void WhenReadingUid_UidNodeIsParsed()
 {
     using (var stream = TestFileHelper.GetTestFileStream("TestFiles/github-7-binary.plist"))
     {
         try
         {
             var node = PList.Load(stream);
             Assert.Pass();
         }
         catch (PListFormatException ex)
         {
             Assert.Fail(ex.Message);
         }
     }
 }
Пример #8
0
 public void ReadingFile_With_UID_Field_Fail()
 {
     using (var stream = TestFileHelper.GetTestFileStream("TestFiles/uid-test.plist"))
     {
         try
         {
             var node = PList.Load(stream);
             Assert.Pass();
         }
         catch (PListFormatException ex)
         {
             Assert.Fail(ex.Message);
         }
     }
 }
Пример #9
0
        public void WhenDocumentContainsEmptyArray_ThenDocumentIsParsedCorrectly()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/empty-array.plist"))
            {
                var root = PList.Load(stream) as DictionaryNode;

                Assert.IsNotNull(root);
                Assert.AreEqual(1, root.Count);

                Assert.IsInstanceOf <DictionaryNode>(root["Entitlements"]);
                var dict = root["Entitlements"] as DictionaryNode;

                var array = dict["com.apple.developer.icloud-container-identifiers"] as ArrayNode;
                Assert.IsNotNull(array);
                Assert.AreEqual(0, array.Count);
            }
        }
Пример #10
0
        public void ReadingFile_GitHub_Issue15_FailReadingLargeArray()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/github-15-large-binary.plist"))
            {
                try
                {
                    var node = PList.Load(stream);

                    var dictNode = node as DictionaryNode;
                    Assert.IsNotNull(dictNode);
                    Assert.AreEqual(32768, dictNode.Keys.Count);
                }
                catch (PListFormatException ex)
                {
                    Assert.Fail(ex.Message);
                }
            }
        }
Пример #11
0
        public void WhenReadingFileWithUid_UidValueIsParsed()
        {
            // this binary .plist file came from https://bugs.python.org/issue26707
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/github-7-binary-2.plist"))
            {
                var root = PList.Load(stream) as DictionaryNode;

                Assert.IsNotNull(root);
                Assert.AreEqual(4, root.Count);

                var dict = root["$top"] as DictionaryNode;
                Assert.IsNotNull(dict);

                var uid = dict["data"] as UidNode;
                Assert.IsNotNull(uid);

                Assert.AreEqual(1, uid.Value);
            }
        }
Пример #12
0
        public void WhenDocumentContainsNestedCollections_ThenDocumentIsParsedCorrectly()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/dict-inside-array.plist"))
            {
                var node = PList.Load(stream);

                Assert.IsNotNull(node);
                Assert.IsInstanceOf <DictionaryNode>(node);

                var array = ((DictionaryNode)node).Values.First() as ArrayNode;
                Assert.IsNotNull(array);
                Assert.AreEqual(1, array.Count);

                var dictionary = array[0] as DictionaryNode;
                Assert.IsNotNull(dictionary);

                Assert.AreEqual(4, dictionary.Count);
            }
        }
Пример #13
0
        public void WhenXmlPlistWithBooleanValueIsLoadedAndSaved_ThenWhiteSpaceMatches()
        {
            using (var stream = TestFileHelper.GetTestFileStream("TestFiles/github-20.plist"))
            {
                // read in the source file and reset the stream so we can parse from it
                string source;
                using (var reader = new StreamReader(stream, Encoding.Default, true, 2048, true))
                {
                    source = reader.ReadToEnd();
                }
                stream.Seek(0, SeekOrigin.Begin);

                var root = PList.Load(stream) as DictionaryNode;
                Assert.IsNotNull(root);

                // verify that we parsed expected content
                var node = root["ABool"] as BooleanNode;
                Assert.IsNotNull(node);
                Assert.IsTrue(node.Value);

                // write the file out to memory and check that there is still no space
                // in the written out boolean node
                using (var outStream = new MemoryStream())
                {
                    // save and reset stream
                    PList.Save(root, outStream, PListFormat.Xml);
                    outStream.Seek(0, SeekOrigin.Begin);

                    // check that boolean was written out without a space per spec (see also issue #11)
                    using (var reader = new StreamReader(outStream))
                    {
                        var contents = reader.ReadToEnd();

                        Assert.AreEqual(source, contents);
                    }
                }
            }
        }