public void Constructor_FilenameSettings_CreatesOutputFile()
        {
            string filename = "TestFiles\\pbfwriter-constructor-creates-output-test.pbf";
            File.Delete(filename);

            PbfWriterSettings settings = new PbfWriterSettings();
            using (PbfWriter target = new PbfWriter(filename, settings)) {
                ;
            }

            Assert.True(File.Exists(filename));
        }
        public void PbfReaderCanReadFileCreatedByPbfWriter_NoDenseDeflate()
        {
            MemoryStream stream = new MemoryStream();

            using (PbfWriter writer = new PbfWriter(stream, new PbfWriterSettings() { WriteMetadata = true, UseDenseFormat = false, Compression = CompressionMode.ZlibDeflate })) {
                foreach (var info in this.GetTestData()) {
                    writer.Write(info);
                }

                writer.Flush();

                stream.Seek(0, SeekOrigin.Begin);
                using (PbfReader reader = new PbfReader(stream, new OsmReaderSettings() { ReadMetadata = true })) {
                    this.TestReader(reader);
                }
            }
        }
        public void Write_ThrowsArgumentNullExceptionIfMetadataContainsNullInsteadUsername()
        {
            _nodeProperties.Metadata.User = null;

            using (PbfWriter target = new PbfWriter(new MemoryStream(), new PbfWriterSettings() { UseDenseFormat = true, Compression = CompressionMode.None, WriteMetadata = true })) {
                Assert.Throws<ArgumentNullException>(() => target.Write(_nodeProperties));
            }
        }
        public void Write_IEntityInfo_WritesRelationWithMetadata()
        {
            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = true };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                target.Write(_relationNodeProperties);
            }

            this.TestPbfOutput(stream, _relationNodeProperties);
        }
        public void Write_IOsmGeometry_WritesWay()
        {
            Way way = new Way(10, new Node[] { new Node(1), new Node(2), new Node(3) });
            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                target.Write(way);
            }

            this.TestPbfOutput(stream, new WayInfo(way));
        }
 public void Write_ThrowsArgumentExceptionIfWriteMetadataIsTrueButEntityDoesntHaveMetadata()
 {
     using (PbfWriter target = new PbfWriter(new MemoryStream(), new PbfWriterSettings() { UseDenseFormat = true, Compression = CompressionMode.None, WriteMetadata = true })) {
         Assert.Throws<ArgumentException>(() => target.Write(_node));
     }
 }
        public void Write_IOsmGeometry_WritesNode()
        {
            Node node = new Node(1, 11.1, 12.1);
            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                target.Write(node);
            }

            this.TestPbfOutput(stream, new NodeInfo(node));
        }
        public void Write_IOsmGeometry_WritesRelation()
        {
            Relation relation = new Relation(100, new RelationMember[] { new RelationMember(new Node(1), "test-role") });

            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                target.Write(relation);
            }

            this.TestPbfOutput(stream, new RelationInfo(relation));
        }
        public void PbfWriterWritesFilesCompatibleWithOsmosis_DenseDeflate()
        {
            string pbfFile = Path.GetFullPath("TestFiles\\pbfwriter-osmosis-compatibility-test-pbfwriter-real-file-dc.pbf");
            if (File.Exists(pbfFile)) {
                File.Delete(pbfFile);
            }

            using (PbfWriter writer = new PbfWriter(pbfFile, new PbfWriterSettings() { WriteMetadata = true, Compression = CompressionMode.ZlibDeflate, UseDenseFormat = true })) {
                foreach (var entityInfo in this.GetTestData()) {
                    writer.Write(entityInfo);
                }
            }

            string osmosisXmlFile = Path.GetFullPath("TestFiles\\pbfwriter-osmosis-compatibility-test-test-file.osm");
            if (File.Exists(osmosisXmlFile)) {
                File.Delete(osmosisXmlFile);
            }

            string osmosisArguments = string.Format("--read-pbf file={0} --write-xml file={1}", pbfFile, osmosisXmlFile);
            this.CallOsmosis(osmosisArguments);

            Assert.True(File.Exists(osmosisXmlFile));
            Assert.True(new FileInfo(osmosisXmlFile).Length > 0);
        }
Exemple #10
0
 static void TestPbfWriterSpeedWithoutMetadata()
 {
     using (PbfWriter writer = new PbfWriter("TestFiles\\temp.pbf", new PbfWriterSettings() { WriteMetadata = false, Compression = CompressionMode.None, UseDenseFormat = false })) {
         foreach (var entity in _entities) {
             writer.Write(entity);
         }
     }
 }
        public void Write_IEntityInfo_DoesntWriteWayMetadataIfWriteMetadataSettingsIsFalse()
        {
            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                target.Write(_wayProperties);
            }

            this.TestPbfOutput(stream, _way);
        }
        public void Constructor_FilenameSettings_SetsSettingsAndMakesThemReadOnly()
        {
            string filename = "TestFiles\\pbfwriter-constructor-test.pbf";
            File.Delete(filename);

            PbfWriterSettings settings = new PbfWriterSettings();
            using (PbfWriter target = new PbfWriter(filename, settings)) {
                Assert.Same(settings, target.Settings);
                Assert.True(settings.IsReadOnly);
            }
        }
        public void Flush_ForcesWriterToWriteDataToUnderalyingStorage()
        {
            MemoryStream stream = new MemoryStream();

            PbfWriter target = new PbfWriter(stream, new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false });

            //1000 nodes should fit into tokens
            for (int i = 0; i < 1000; i++) {
                NodeInfo node = new NodeInfo(i, 45.87, -126.5, new TagsCollection());
                target.Write(node);
            }
            int minimalExpectedLengthIncrease = 1000 * 8;

            long originalStreamLength = stream.Length;
            target.Flush();

            Assert.True(stream.Length > originalStreamLength + minimalExpectedLengthIncrease);
        }
        public void Dispose_ClosesOutputStreamIfWritingToStream()
        {
            PbfWriterSettings settings = new PbfWriterSettings();
            MemoryStream stream = new MemoryStream();

            PbfWriter target = new PbfWriter(stream, settings);
            target.Dispose();

            Assert.False(stream.CanRead);
        }
        public void Dispose_ClosesOutputStreamIfWritingToFiles()
        {
            string filename = "TestFiles\\pbfwriter-closes-output-filestream-test.pbf";
            File.Delete(filename);

            PbfWriterSettings settings = new PbfWriterSettings();
            PbfWriter target = new PbfWriter(filename, settings);
            target.Dispose();

            Assert.DoesNotThrow(() => new FileStream(filename, FileMode.Open, FileAccess.ReadWrite));
        }
        public void Constructor_StreamSettings_WritesOsmHeader()
        {
            MemoryStream stream = new MemoryStream();
            PbfWriterSettings settings = new PbfWriterSettings();
            using (PbfWriter target = new PbfWriter(stream, settings)) {
                ;
            }

            Assert.True(stream.GetBuffer().Length > 0);
        }
 public void Constructor_StreamSettings_SetsSettingsAndMakeThemReadOnly()
 {
     PbfWriterSettings settings = new PbfWriterSettings();
     using (PbfWriter target = new PbfWriter(new MemoryStream(), settings)) {
         Assert.Same(settings, target.Settings);
         Assert.True(settings.IsReadOnly);
     }
 }
        public void Constructor_FilenameSettings_WritesOsmHeader()
        {
            string filename = "TestFiles\\pbfwriter-constructor-writes-header-test.pbf";
            File.Delete(filename);

            PbfWriterSettings settings = new PbfWriterSettings();
            using (PbfWriter target = new PbfWriter(filename, settings)) {
                ;
            }

            FileInfo fi = new FileInfo(filename);
            Assert.True(fi.Length > 0);
        }
        public void Write_IEntityInfo_WritesWayWithTags()
        {
            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                target.Write(_wayTags);
            }

            this.TestPbfOutput(stream, _wayTags);
        }
        public void Write_IOsmGeometry_ThrowsExceptionIfEntityIsNull()
        {
            PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false };
            MemoryStream stream = new MemoryStream();

            using (PbfWriter target = new PbfWriter(stream, settings)) {
                IOsmGeometry entity = null;
                Assert.Throws<ArgumentNullException>(() => target.Write(entity));
            }
        }
Exemple #21
0
 static void TestPbfWriterSpeedDenseDeflate()
 {
     using (PbfWriter writer = new PbfWriter("TestFiles\\temp.pbf", new PbfWriterSettings() { WriteMetadata = true, Compression = CompressionMode.ZlibDeflate, UseDenseFormat = true })) {
         foreach (var entity in _entities) {
             writer.Write(entity);
         }
     }
 }