Beispiel #1
0
        public void FloatTest()
        {
            void Test(Single start)
            {
                MemoryStream ms = MSCreate();

                using (TinkarOutput output = new TinkarOutput(ms))
                {
                    output.WriteField(start);
                }

                ms.Position = 0;
                using (TinkarInput input = new TinkarInput(ms))
                {
                    Single value = (Single)input.GetField();
                    Assert.True(start == value);
                }
            }

            Test(Single.MinValue);
            Test(Single.MaxValue);
            Test(0.1F);
            Test(-1.234F);
            Test(100.987F);
        }
Beispiel #2
0
        public void StampDTOMarshalTest()
        {
            DateTime time = new DateTime(2020, 12, 31);

            StampDTO dtoStart = new StampDTO(
                Misc.PublicIdG,
                Misc.PublicIdH,
                time,
                Misc.PublicIdI,
                Misc.PublicIdJ,
                Misc.PublicIdK
                );

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.Marshal(output);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                StampDTO dtoEnd = StampDTO.Make(input);
                Assert.True(dtoStart.CompareTo(dtoEnd) == 0);
            }
        }
Beispiel #3
0
        public void Int32Test()
        {
            void Test(Int32 start)
            {
                MemoryStream ms = MSCreate();

                using (TinkarOutput output = new TinkarOutput(ms))
                {
                    output.WriteField(start);
                }

                ms.Position = 0;
                using (TinkarInput input = new TinkarInput(ms))
                {
                    Int32 value = (Int32)input.GetField();
                    Assert.True(start == value);
                }
            }

            Test(Int32.MinValue);
            Test(Int32.MaxValue);
            Test(0);
            Test(-1);
            Test(100);
            Test((Int32)0x7fe1deab);
        }
Beispiel #4
0
        public void A_BinaryWriteObjects()
        {
            guidNumber = 0xfedd;
            String outputPath = TestFile("TinkarExport.tink");

            using FileStream fs       = new FileStream(outputPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            using TinkarOutput output = new TinkarOutput(fs);
            foreach (Object dto in this.CreateComponents())
            {
                output.WriteField(dto);
            }
        }
Beispiel #5
0
        public void WriteIntTest()
        {
            {
                MemoryStream ms    = new MemoryStream();
                TinkarOutput to    = new TinkarOutput(ms);
                Int32        value = (1
                                      | (2 * 0x100)
                                      | (3 * 0x10000)
                                      | (4 * 0x1000000));
                to.WriteInt32(value);
                ms.Position = 0;

                Assert.True(ms.Length == 8);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);

                Assert.True(ms.ReadByte() == 4);
                Assert.True(ms.ReadByte() == 3);
                Assert.True(ms.ReadByte() == 2);
                Assert.True(ms.ReadByte() == 1);
            }

            {
                MemoryStream ms    = new MemoryStream();
                TinkarOutput to    = new TinkarOutput(ms);
                Int32        value = (0xf1
                                      | (0xf2 * 0x100)
                                      | (0xf3 * 0x10000)
                                      | (0x74 * 0x1000000));
                to.WriteInt32(value);
                ms.Position = 0;

                Assert.True(ms.Length == 8);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);

                Assert.True(ms.ReadByte() == 0x74);
                Assert.True(ms.ReadByte() == 0xf3);
                Assert.True(ms.ReadByte() == 0xf2);
                Assert.True(ms.ReadByte() == 0xf1);
            }
        }
Beispiel #6
0
        public void DiTreeDTOMarshalTest()
        {
            DiTreeDTO dtoStart = Misc.CreateDiTreeDTO();

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.Marshal(output);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                DiTreeDTO dtoRead = DiTreeDTO.Make(input);
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
Beispiel #7
0
        public void GraphDTOMarshalTest()
        {
            GraphDTO dtoStart = Misc.CreateGraphDTO();

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.MarshalVertexMap(output);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                ImmutableList <VertexDTO> dtoRead = GraphDTO.UnmarshalVertexMap(input);
                Assert.True(FieldCompare.CompareSequence(dtoRead, dtoStart.VertexMap) == 0);
            }
        }
Beispiel #8
0
        public void PatternDTOMarshalTest()
        {
            PatternDTO dtoStart = Misc.CreatePatternDTO;

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                output.WriteField(dtoStart);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                PatternDTO dtoRead = (PatternDTO)input.GetField();
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
Beispiel #9
0
        public void SemanticVersionDTOMarshalTest()
        {
            SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO;

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.Marshal(output);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                SemanticVersionDTO dtoRead = SemanticVersionDTO.Make(input,
                                                                     dtoStart.PublicId);
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
Beispiel #10
0
        public void ConceptVersionDTOMarshalTest()
        {
            ConceptVersionDTO dtoStart = Misc.CreateConceptVersionDTO;

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.Marshal(output);
            }


            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                ConceptVersionDTO dtoRead = ConceptVersionDTO.Make(input,
                                                                   new PublicId(Misc.g1, Misc.g2, Misc.g3, Misc.g4));
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
        public void FieldDefinitionDTOMarshalTest()
        {
            FieldDefinitionDTO dtoStart = new FieldDefinitionDTO(
                Misc.PublicIdG,
                Misc.PublicIdH,
                Misc.PublicIdI
                );

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                dtoStart.Marshal(output);
            }

            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                FieldDefinitionDTO dtoRead = FieldDefinitionDTO.Make(input);
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
        public void ConceptChronologyDTOMarshalTest()
        {
            ConceptChronologyDTO dtoStart = new ConceptChronologyDTO(
                Misc.PublicIdG,
                Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray()
                );

            MemoryStream ms = new MemoryStream();

            using (TinkarOutput output = new TinkarOutput(ms))
            {
                output.WriteField(dtoStart);
            }


            ms.Position = 0;
            using (TinkarInput input = new TinkarInput(ms))
            {
                ConceptChronologyDTO dtoRead = (ConceptChronologyDTO)input.GetField();
                Assert.True(dtoStart.CompareTo(dtoRead) == 0);
            }
        }
Beispiel #13
0
        public void BoolTest()
        {
            void Test(bool start)
            {
                MemoryStream ms = MSCreate();

                using (TinkarOutput output = new TinkarOutput(ms))
                {
                    output.WriteField(start);
                }

                ms.Position = 0;
                using (TinkarInput input = new TinkarInput(ms))
                {
                    Boolean value = (Boolean)input.GetField();
                    Assert.True(start == value);
                }
            }

            Test(true);
            Test(false);
        }
Beispiel #14
0
        public void InstantTest()
        {
            void Test(DateTime start)
            {
                MemoryStream ms = MSCreate();

                using (TinkarOutput output = new TinkarOutput(ms))
                {
                    output.WriteField(start);
                }

                ms.Position = 0;
                using (TinkarInput input = new TinkarInput(ms))
                {
                    DateTime value = (DateTime)input.GetField();
                    Assert.True(start == value);
                }
            }

            Test(new DateTime(1900, 1, 1));
            Test(new DateTime(2020, 1, 2, 12, 30, 30, 100));
        }
Beispiel #15
0
        public void ByteArrayTest()
        {
            void Test(byte[] start)
            {
                MemoryStream ms = MSCreate();

                using (TinkarOutput output = new TinkarOutput(ms))
                {
                    output.WriteField(start);
                }

                ms.Position = 0;
                using (TinkarInput input = new TinkarInput(ms))
                {
                    byte[] value = (byte[])input.GetField();
                    Assert.True(start.SequenceEqual(value));
                }
            }

            Test(new byte[] { });
            Test(new byte[] { 1 });
            Test(new byte[] { 1, 30, 255 });
        }
Beispiel #16
0
        public void StringTest()
        {
            void Test(String start)
            {
                MemoryStream ms = MSCreate();

                using (TinkarOutput output = new TinkarOutput(ms))
                {
                    output.WriteField(start);
                }

                ms.Position = 0;
                using (TinkarInput input = new TinkarInput(ms))
                {
                    String value = (String)input.GetField();
                    Assert.True(start == value);
                }
            }

            Test(String.Empty);
            Test("a");
            Test("This is a test string");
        }
Beispiel #17
0
        public void WriteUuidArrayTest()
        {
            {
                MemoryStream ms = MSCreate();
                TinkarOutput ti = new TinkarOutput(ms);
                ti.WriteUuids(new Guid[0]);
                ms.Position = 0;
                Assert.True(ms.Length == 8);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);

                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
            }

            {
                MemoryStream ms = MSCreate();
                TinkarOutput ti = new TinkarOutput(ms);
                Guid         g1 = new Guid(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
                ti.WriteUuids(new Guid[] { g1 });
                ms.Position = 0;
                Assert.True(ms.Length == 24);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);

                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 1);

                Assert.True(ms.ReadByte() == 1);
                Assert.True(ms.ReadByte() == 2);
                Assert.True(ms.ReadByte() == 3);
                Assert.True(ms.ReadByte() == 4);
                Assert.True(ms.ReadByte() == 5);
                Assert.True(ms.ReadByte() == 6);
                Assert.True(ms.ReadByte() == 7);
                Assert.True(ms.ReadByte() == 8);
                Assert.True(ms.ReadByte() == 9);
                Assert.True(ms.ReadByte() == 10);
                Assert.True(ms.ReadByte() == 11);
                Assert.True(ms.ReadByte() == 12);
                Assert.True(ms.ReadByte() == 13);
                Assert.True(ms.ReadByte() == 14);
                Assert.True(ms.ReadByte() == 15);
                Assert.True(ms.ReadByte() == 16);
            }

            {
                MemoryStream ms = MSCreate();
                TinkarOutput ti = new TinkarOutput(ms);
                Guid         g1 = new Guid(new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff });
                ti.WriteUuids(new Guid[] { g1 });
                ms.Position = 0;
                Assert.True(ms.Length == 24);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);

                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 1);

                Assert.True(ms.ReadByte() == 0xf0);
                Assert.True(ms.ReadByte() == 0xf1);
                Assert.True(ms.ReadByte() == 0xf2);
                Assert.True(ms.ReadByte() == 0xf3);
                Assert.True(ms.ReadByte() == 0xf4);
                Assert.True(ms.ReadByte() == 0xf5);
                Assert.True(ms.ReadByte() == 0xf6);
                Assert.True(ms.ReadByte() == 0xf7);
                Assert.True(ms.ReadByte() == 0xf8);
                Assert.True(ms.ReadByte() == 0xf9);
                Assert.True(ms.ReadByte() == 0xfa);
                Assert.True(ms.ReadByte() == 0xfb);
                Assert.True(ms.ReadByte() == 0xfc);
                Assert.True(ms.ReadByte() == 0xfd);
                Assert.True(ms.ReadByte() == 0xfe);
                Assert.True(ms.ReadByte() == 0xff);
            }

            {
                MemoryStream ms = MSCreate();
                TinkarOutput ti = new TinkarOutput(ms);
                Guid         g1 = new Guid(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
                Guid         g2 = new Guid(new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff });
                ti.WriteUuids(new Guid[] { g1, g2 });
                ms.Position = 0;
                Assert.True(ms.Length == 40);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);


                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 2);

                Assert.True(ms.ReadByte() == 1);
                Assert.True(ms.ReadByte() == 2);
                Assert.True(ms.ReadByte() == 3);
                Assert.True(ms.ReadByte() == 4);
                Assert.True(ms.ReadByte() == 5);
                Assert.True(ms.ReadByte() == 6);
                Assert.True(ms.ReadByte() == 7);
                Assert.True(ms.ReadByte() == 8);
                Assert.True(ms.ReadByte() == 9);
                Assert.True(ms.ReadByte() == 10);
                Assert.True(ms.ReadByte() == 11);
                Assert.True(ms.ReadByte() == 12);
                Assert.True(ms.ReadByte() == 13);
                Assert.True(ms.ReadByte() == 14);
                Assert.True(ms.ReadByte() == 15);
                Assert.True(ms.ReadByte() == 16);

                Assert.True(ms.ReadByte() == 0xf0);
                Assert.True(ms.ReadByte() == 0xf1);
                Assert.True(ms.ReadByte() == 0xf2);
                Assert.True(ms.ReadByte() == 0xf3);
                Assert.True(ms.ReadByte() == 0xf4);
                Assert.True(ms.ReadByte() == 0xf5);
                Assert.True(ms.ReadByte() == 0xf6);
                Assert.True(ms.ReadByte() == 0xf7);
                Assert.True(ms.ReadByte() == 0xf8);
                Assert.True(ms.ReadByte() == 0xf9);
                Assert.True(ms.ReadByte() == 0xfa);
                Assert.True(ms.ReadByte() == 0xfb);
                Assert.True(ms.ReadByte() == 0xfc);
                Assert.True(ms.ReadByte() == 0xfd);
                Assert.True(ms.ReadByte() == 0xfe);
                Assert.True(ms.ReadByte() == 0xff);
            }
        }
Beispiel #18
0
        public void WriteLongTest()
        {
            {
                MemoryStream ms    = new MemoryStream();
                TinkarOutput ti    = new TinkarOutput(ms);
                Int64        value = (1L
                                      | (2L * 0x100)
                                      | (3L * 0x10000)
                                      | (4L * 0x1000000)
                                      | (5L * 0x100000000)
                                      | (6L * 0x10000000000)
                                      | (7L * 0x1000000000000)
                                      | (8L * 0x100000000000000));
                ti.WriteInt64(value);
                ms.Position = 0;

                Assert.True(ms.Length == 12);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);


                Assert.True(ms.ReadByte() == 8);
                Assert.True(ms.ReadByte() == 7);
                Assert.True(ms.ReadByte() == 6);
                Assert.True(ms.ReadByte() == 5);
                Assert.True(ms.ReadByte() == 4);
                Assert.True(ms.ReadByte() == 3);
                Assert.True(ms.ReadByte() == 2);
                Assert.True(ms.ReadByte() == 1);
            }

            {
                MemoryStream ms    = new MemoryStream();
                TinkarOutput ti    = new TinkarOutput(ms);
                Int64        value = (0xf1L
                                      | (0xf2L * 0x100)
                                      | (0xf3L * 0x10000)
                                      | (0xf4L * 0x1000000)
                                      | (0xf5L * 0x100000000)
                                      | (0xf6L * 0x10000000000)
                                      | (0xf7L * 0x1000000000000)
                                      | (0x78L * 0x100000000000000));
                ti.WriteInt64(value);
                ms.Position = 0;

                Assert.True(ms.Length == 12);

                // read 4 byte marshal version
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 0);
                Assert.True(ms.ReadByte() == 3);

                Assert.True(ms.ReadByte() == 0x78);
                Assert.True(ms.ReadByte() == 0xf7);
                Assert.True(ms.ReadByte() == 0xf6);
                Assert.True(ms.ReadByte() == 0xf5);
                Assert.True(ms.ReadByte() == 0xf4);
                Assert.True(ms.ReadByte() == 0xf3);
                Assert.True(ms.ReadByte() == 0xf2);
                Assert.True(ms.ReadByte() == 0xf1);
            }
        }