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); }
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 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 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 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 Constructor_FilenameSettings_SetsSettingsAndMakesThemReadOnly() { string filename = PathHelper.GetTempFilePath("pbfwriter-constructor-test.pbf"); PbfWriterSettings settings = new PbfWriterSettings(); using (PbfWriter target = new PbfWriter(filename, settings)) { Assert.Same(settings, target.Settings); Assert.True(settings.IsReadOnly); } }
public void Dispose_ClosesOutputStreamIfWritingToFiles() { string filename = PathHelper.GetTempFilePath("pbfwriter-closes-output-filestream-test.pbf"); PbfWriterSettings settings = new PbfWriterSettings(); PbfWriter target = new PbfWriter(filename, settings); target.Dispose(); new FileStream(filename, FileMode.Open, FileAccess.ReadWrite); }
public void Dispose_ClosesOutputStreamIfWritingToStream() { PbfWriterSettings settings = new PbfWriterSettings(); MemoryStream stream = new MemoryStream(); PbfWriter target = new PbfWriter(stream, settings); target.Dispose(); Assert.False(stream.CanRead); }
static void TestPbfWriterSpeedDenseDeflateWithoutMetadata() { using (PbfWriter writer = new PbfWriter("TestFiles\\temp.pbf", new PbfWriterSettings() { WriteMetadata = false, Compression = CompressionMode.ZlibDeflate, UseDenseFormat = true })) { foreach (var entity in _entities) { writer.Write(entity); } } }
public void Constructor_FilenameSettings_CreatesOutputFile() { string filename = PathHelper.GetTempFilePath("pbfwriter-constructor-creates-output-test.pbf"); PbfWriterSettings settings = new PbfWriterSettings(); using (PbfWriter target = new PbfWriter(filename, settings)) { ; } Assert.True(File.Exists(filename)); }
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_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 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)); } }
public void Write_IEntityInfo_WritesRelationWithTags() { PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false }; MemoryStream stream = new MemoryStream(); using (PbfWriter target = new PbfWriter(stream, settings)) { target.Write(_relationTags); } this.TestPbfOutput(stream, _relationTags); }
public void Constructor_FilenameSettings_WritesOsmHeader() { string filename = PathHelper.GetTempFilePath("pbfwriter-constructor-writes-header-test.pbf"); 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_WritesWayWithMetadata() { PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = true }; MemoryStream stream = new MemoryStream(); using (PbfWriter target = new PbfWriter(stream, settings)) { target.Write(_wayProperties); } this.TestPbfOutput(stream, _wayProperties); }
public void Write_IEntityInfo_DoesntWritesRelationMetadataIfWriteMetasdataSettingsIsFalse() { PbfWriterSettings settings = new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false }; MemoryStream stream = new MemoryStream(); using (PbfWriter target = new PbfWriter(stream, settings)) { target.Write(_relationNodeProperties); } this.TestPbfOutput(stream, _relationNode); }
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 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_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 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_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_NoDenseNoCompression() { string pbfFile = PathHelper.GetTempFilePath("pbfwriter-osmosis-compatibility-test-pbfwriter-real-file.pbf"); using (PbfWriter writer = new PbfWriter(pbfFile, new PbfWriterSettings() { WriteMetadata = true, Compression = CompressionMode.None, UseDenseFormat = false })) { foreach (var entityInfo in this.GetTestData()) { writer.Write(entityInfo); } } string osmosisXmlFile = PathHelper.GetTempFilePath("pbfwriter-osmosis-compatibility-test-test-file.osm"); 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); }
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 PbfReaderCanReadFileCreatedByPbfWriter_DenseDeflate() { MemoryStream stream = new MemoryStream(); using (PbfWriter writer = new PbfWriter(stream, new PbfWriterSettings() { WriteMetadata = true, UseDenseFormat = true, 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); } } }