Example #1
0
        public void ThrowsOnArrayWriteWhenValueExpected()
        {
            var elements = new List <PlyElement>()
            {
                new PlyElement("vertex", 1, new List <PlyProperty>()
                {
                    new PlyProperty("x", PlyType.Float),
                }),
                new PlyElement("face", 1, new List <PlyProperty>()
                {
                    new PlyArrayProperty("vertex_index", PlyType.Int, PlyType.Int)
                })
            };

            var header = new PlyHeader(PlyFormat.Ascii, elements);

            using (var stream = new MemoryStream())
            {
                var writer = new PlyAsciiWriter(stream, header);
                Assert.Throws <UnexpectedDataTypeException>(() => writer.WriteArray(1, 2, 3));
                Assert.DoesNotThrow(() => writer.WriteValue(1.2f));
                Assert.Throws <UnexpectedDataTypeException>(() => writer.WriteValue(12.0f));
                Assert.Throws <InvalidOperationException>(() => writer.Dispose());
                Assert.DoesNotThrow(() => writer.WriteArray(1, 2, 3));
                Assert.DoesNotThrow(() => writer.Dispose());
            }
        }
Example #2
0
        public void ThrowsWhenTooManyValuesWritten()
        {
            var elements = new List <PlyElement>()
            {
                new PlyElement("vertex", 1, new List <PlyProperty>()
                {
                    new PlyProperty("x", PlyType.Float),
                }),
                new PlyElement("face", 1, new List <PlyProperty>()
                {
                    new PlyArrayProperty("vertex_index", PlyType.Int, PlyType.Int)
                })
            };

            var header = new PlyHeader(PlyFormat.Ascii, elements);

            using (var stream = new MemoryStream())
            {
                using (var writer = new PlyAsciiWriter(stream, header))
                {
                    writer.WriteValue(1.0f);
                    writer.WriteArray(new int[] { 12, 16, 45 });
                    Assert.Throws <InvalidOperationException>(() => writer.WriteArray(new int[] { 1, 2, 3 }));
                }
            }
        }