예제 #1
0
        public void Test001()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                // 0 件
            };

            // セクション テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateSectionTable(sections, new ulong[sections.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    var sectionTable = binLoader.LoadSectionTable(br);

                    // 0 件のセクション情報が格納されていることを確認
                    Assert.AreEqual(0, sectionTable.Count);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #2
0
        public void Test102()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // アイテム コレクションの定義
            var items = new PropItemCollection();

            // すべて null 値で追加
            var types = Enum.GetNames(typeof(PropType));

            foreach (var type in types)
            {
                items.Add(new PropItem(type + "Prop", (PropType)Enum.Parse(typeof(PropType), type), null));
            }

            // 処理実行
            try
            {
                var binResult = binBuilder.CreateItemBufferTable(items, new ulong[items.Count]);
                this.TestContext.WriteLine("Added props = {0}", items.Count);
                this.TestContext.WriteLine("Created buffer = {0} bytes", binResult.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #3
0
        public void Test101()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // セクションの定義
            var items = new PropItemCollection()
            {
                // 0 件
            };

            // アイテム バッファ テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateItemBufferTable(items, new ulong[items.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    // value データ本体は読み取らない
                    var itemBufferTable = binLoader.LoadItemBufferTable(br, false);

                    // 0 件のセクション情報が格納されていることを確認
                    Assert.AreEqual(0, itemBufferTable.Count);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #4
0
        public void Test051()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                new PropSection("DEBUG01"),
            };

            // 処理実行
            Exception thrown = null;

            try
            {
                var bufResult = binBuilder.CreateSectionTable(sections, new ulong[0]);
            }
            catch (Exception ex)
            {
                thrown = ex;

                this.TestContext.WriteLine("Thrown: {0}", ex);
            }

            Assert.IsTrue(thrown is ArgumentException);
        }
예제 #5
0
        public void Test003()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                new PropSection("DEBUG01"),
                new PropSection("DEBUG02"),
            };

            // 処理実行
            try
            {
                var bufResult1 = binBuilder.CreateSectionTable(sections, new ulong[] { 0, 0 });
                var bufResult2 = binBuilder.CreateSectionTable(sections, new ulong[] { 1000, 2000 });

                Assert.IsTrue(bufResult1.Length == bufResult2.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #6
0
        // 非公開メソッド

        private ulong[][] _createItemBufferMap(PropBinaryBuilder binBuilder, PropSectionCollection sections)
        {
            var itemBufferMap   = new ulong[sections.Count][];
            var currentPosition = 0uL;
            var ns = new NullStream();

            for (var i = 0; i < sections.Count; i++)
            {
                var section = sections[i];
                itemBufferMap[i] = new ulong[section.Items.Count];
                for (var j = 0; j < section.Items.Count; j++)
                {
                    var item = section.Items[j];
                    ns.Seek(0, SeekOrigin.Begin);

                    // Reference アルゴリズム未実装
                    var bufferMode = PropItemBufferMode.Buffered;
                    if (item.IsNull)
                    {
                        bufferMode = PropItemBufferMode.Null;
                    }
                    binBuilder.WriteItemBuffer(ns, item, bufferMode);

                    itemBufferMap[i][j] = currentPosition;
                    currentPosition    += (ulong)ns.Position;
                }
            }

            return(itemBufferMap);
        }
예제 #7
0
 public PropWriter(Stream stream, Encoding encoding, bool leaveOpen)
 {
     this._stream     = stream;
     this._encoding   = encoding;
     this._leaveOpen  = leaveOpen;
     this._isDisposed = false;
     this._binBuilder = new PropBinaryBuilder(this._encoding);
 }
예제 #8
0
        public void Test102()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // セクションの定義
            var propItemNames = new string[]
            {
                "DEBUG_PROP_01",
                "DEBUG_PROP_02",
                "DEBUG_PROP_03",
                "DEBUG_PROP_04",
                "DEBUG_PROP_05",
            };

            var propItems = new PropItemCollection()
            {
                new PropItem(propItemNames[0], PropType.String, null),
                new PropItem(propItemNames[1], PropType.String, null),
                new PropItem(propItemNames[2], PropType.String, null),
                new PropItem(propItemNames[3], PropType.String, null),
                new PropItem(propItemNames[4], PropType.String, null),
            };

            // アイテム バッファ テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateItemBufferTable(propItems, new ulong[propItems.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    var propItemBufferTable = binLoader.LoadItemBufferTable(br, false);

                    // 5 件のセクション情報が格納されていることを確認
                    Assert.AreEqual(5, propItemBufferTable.Count);

                    // 各セクションのセクション名が正しいことを確認
                    var loadedNames = propItemBufferTable.Keys.Select(s => s.Name).ToArray();
                    for (var i = 0; i < 5; i++)
                    {
                        this.TestContext.WriteLine("expected: {0}, actual: {1}", propItemNames[i], loadedNames[i]);
                        Assert.AreEqual(propItemNames[i], loadedNames[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #9
0
        public void Test002()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // セクションの定義
            var sectionNames = new string[]
            {
                "DEBUG_SECTION_01",
                "DEBUG_SECTION_02",
                "DEBUG_SECTION_03",
                "DEBUG_SECTION_04",
                "DEBUG_SECTION_05",
            };

            var sections = new PropSectionCollection()
            {
                new PropSection(sectionNames[0]),
                new PropSection(sectionNames[1]),
                new PropSection(sectionNames[2]),
                new PropSection(sectionNames[3]),
                new PropSection(sectionNames[4]),
            };

            // セクション テーブルを生成
            var ms = new MemoryStream(binBuilder.CreateSectionTable(sections, new ulong[sections.Count]));

            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    var sectionTable = binLoader.LoadSectionTable(br);

                    // 5 件のセクション情報が格納されていることを確認
                    Assert.AreEqual(5, sectionTable.Count);

                    // 各セクションのセクション名が正しいことを確認
                    var loadedNames = sectionTable.Keys.Select(s => s.Name).ToArray();
                    for (var i = 0; i < 5; i++)
                    {
                        this.TestContext.WriteLine("expected: {0}, actual: {1}", sectionNames[i], loadedNames[i]);
                        Assert.AreEqual(sectionNames[i], loadedNames[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #10
0
        public void Test204()
        {
            // UTF-8 でビルダ・ローダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);
            var binLoader  = new PropBinaryLoader(encoding);

            // アイテムの定義
            var propItemName  = "DEBUG_ITEM";
            var propItemType  = PropType.DateTime;
            var propItemValue = new DateTime(1970, 1, 1, 12, 0, 0, 500);
            var propItem      = new PropItem(propItemName, propItemType, propItemValue);

            // アイテム バッファの生成
            var ms = new MemoryStream();

            binBuilder.WriteItemBuffer(ms, propItem, PropItemBufferMode.Buffered);
            ms.Seek(0, SeekOrigin.Begin);

            // 処理実行
            try
            {
                using (var br = new BinaryReader(ms))
                {
                    // アイテム バッファ テーブルから読み取ったと想定するアイテム
                    var loadedItemFromBufferTable = new PropItem(propItemName, PropType.Buffer, null);

                    // フル ロード
                    var loadedItem = binLoader.LoadItemBuffer(br, loadedItemFromBufferTable, false);

                    // アイテム名が正しいことの確認
                    this.TestContext.WriteLine("Name> expected: {0}, actual: {1}", propItemName, loadedItem.Name);
                    Assert.AreEqual(propItemName, loadedItem.Name);

                    // タイプが正しいことの確認
                    this.TestContext.WriteLine("Type> expected: {0}, actual: {1}", propItemType, loadedItem.Type);
                    Assert.AreEqual(propItemType, loadedItem.Type);

                    // 値の内容の確認
                    this.TestContext.WriteLine("Value> expected: {0}, actual: {1}", propItemValue, loadedItem.Value);
                    Assert.AreEqual(propItemValue, loadedItem.Value);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #11
0
        public void Test002()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // セクションの定義
            var sections = new PropSectionCollection()
            {
                new PropSection("DEBUG01"),
            };

            // 処理実行
            try
            {
                var binResult = binBuilder.CreateSectionTable(sections, new ulong[sections.Count]);
                this.TestContext.WriteLine("Added sections = {0}", sections.Count);
                this.TestContext.WriteLine("Created buffer = {0} bytes", binResult.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }
예제 #12
0
        public void Test101()
        {
            // UTF-8 でビルダを初期化
            var encoding   = Encoding.UTF8;
            var binBuilder = new PropBinaryBuilder(encoding);

            // アイテム コレクションの定義
            var items = new PropItemCollection()
            {
                // 0 件
            };

            // 処理実行
            try
            {
                var binResult = binBuilder.CreateItemBufferTable(items, new ulong[items.Count]);
                this.TestContext.WriteLine("Added props = {0}", items.Count);
                this.TestContext.WriteLine("Created buffer = {0} bytes", binResult.Length);
            }
            catch (Exception ex)
            {
                Assert.Fail($"予期せぬエラー: {ex}");
            }
        }