コード例 #1
0
        public void CfgVarMetadata_InflatAllWithMultipleVarsSections_FindsAllCfgVars()
        {
            var cfgWithTwoVarsSections =
                @"
[mapping]
$0000 - $0FFF = $5000

[vars]
name = wiglet

[preload]
whatevs man

[vars]
short_name = wig
";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgWithTwoVarsSections)))
            {
                var cfgVarMetadataValues = CfgVarMetadataBlock.InflateAll(stream).Cast <CfgVarMetadataString>().Select(c => c.StringValue);

                Assert.Equal(2, cfgVarMetadataValues.Count());
                Assert.Contains("wiglet", cfgVarMetadataValues);
                Assert.Contains("wig", cfgVarMetadataValues);
            }
        }
コード例 #2
0
        public void CfgVarMetadata_InflateFeatureCompatibility_GetsExpectedFeatureCompatibilty(string cfgFileValue, FeatureCompatibility expectedCfgVarMetadataFeatureCompatibilityValue)
        {
            var cfgFeatureCompatibilityEntry = "tv_compat = " + cfgFileValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgFeatureCompatibilityEntry)))
            {
                var cfgVarMetadataFeatureCompatibility = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataFeatureCompatibility;

                Assert.Equal(expectedCfgVarMetadataFeatureCompatibilityValue, cfgVarMetadataFeatureCompatibility.Compatibility);
            }
        }
コード例 #3
0
        public void CfgVarMetadata_InflateLegacyCompatibility_GetsExpectedFeatureCompatibility(CfgVarMetadataIdTag legacyTag, string cfgFileValue, FeatureCompatibility expectedCfgVarMetadataFeatureCompatibilityValue)
        {
            var cfgLegacyFeatureCompatibilityEntry = legacyTag.ToCfgVarString() + " = " + cfgFileValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgLegacyFeatureCompatibilityEntry)))
            {
                var cfgVarMetadataFeatureCompatibility = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataFeatureCompatibility;

                Assert.Equal(expectedCfgVarMetadataFeatureCompatibilityValue, cfgVarMetadataFeatureCompatibility.Compatibility);
            }
        }
コード例 #4
0
        public void CfgVarMetadata_InflateBoolean_GetsExpectedBooleanValue(string cfgFileValue, bool expectedCfgVarMetadataBooleanValue)
        {
            var cfgBooleanEntry = "  lto_mapper           =" + cfgFileValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgBooleanEntry)))
            {
                var cfgVarMetadataBoolean = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataBoolean;

                Assert.Equal(expectedCfgVarMetadataBooleanValue, cfgVarMetadataBoolean.BooleanValue);
            }
        }
コード例 #5
0
        public void CfgVarMetadata_InflateIntegralValue_GetsProperValue(string cfgFileValue, int expectedCfgVarMetadataIntegerValue)
        {
            var cfgIntegerValueEntry = "jlp_flash = " + cfgFileValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgIntegerValueEntry)))
            {
                var cfgVarMetadataInteger = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataInteger;

                Assert.Equal(expectedCfgVarMetadataIntegerValue, cfgVarMetadataInteger.IntegerValue);
            }
        }
コード例 #6
0
        public void CfgVarMetadata_InflateStringValue_GetsAppropriateString(string cfgFileValue, string expectedCfgVarMetadataStringValue)
        {
            var cfgStringValueEntry = "publisher=" + cfgFileValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgStringValueEntry)))
            {
                var cfgVarMetadataString = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataString;

                // The parser strips from beginning and end, so this is correct, despite being odd.
                Assert.Equal(expectedCfgVarMetadataStringValue, cfgVarMetadataString.StringValue);
            }
        }
コード例 #7
0
        public void CfgVarMetadata_InflateNonQuotedCfgVarMetadataStringWithCarriageReturn_ReturnsTheString()
        {
            var cfg = "name = Whatta\rHeck";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataString>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal("Whatta\rHeck", ((CfgVarMetadataString)cfgVarMetadata).StringValue);
            }
        }
コード例 #8
0
        public void CfgVarMetadata_InflateAllAsciiStreamWithNoValidContent_ReturnsEmptyEnumerable()
        {
            var meaninglessCfg =
                @"[Howdy] 
pard = ner";

            using (var stream = new System.IO.MemoryStream(Encoding.ASCII.GetBytes(meaninglessCfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.InflateAll(stream);

                Assert.Empty(cfgVarMetadata);
            }
        }
コード例 #9
0
        public void CfgVarMetadata_InflateAllUtf8StreamWithNoValidContent_ReturnsEmptyEnumerable()
        {
            var meaninglessCfg =
                @"[Doody]
dooh";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(meaninglessCfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.InflateAll(stream);

                Assert.Empty(cfgVarMetadata);
            }
        }
コード例 #10
0
        public void CfgVarMetadata_InflateQuotedCfgVarMetadataStringWithSpaceAndEscapedBell_ReturnsTheString()
        {
            var cfg = "name = \"The \\x07 bell has been rung.\"";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataString>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal("The \a bell has been rung.", ((CfgVarMetadataString)cfgVarMetadata).StringValue);
            }
        }
コード例 #11
0
        public void CfgVarMetadata_InflateCfgVarMetadataString()
        {
            var expectedValue = "Whee!";
            var cfg           = "name = " + expectedValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataString>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal(expectedValue, ((CfgVarMetadataString)cfgVarMetadata).StringValue);
            }
        }
コード例 #12
0
        public void CfgVarMetadata_InflateCfgVarMetadataInteger()
        {
            var expectedValue = 128;
            var cfg           = "jlp_flash = " + expectedValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataInteger>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal(expectedValue, ((CfgVarMetadataInteger)cfgVarMetadata).IntegerValue);
            }
        }
コード例 #13
0
        public void CfgVarMetadata_InflateCfgVarMetadataBoolean()
        {
            var expectedValue = true;
            var cfg           = "lto_mapper = 1";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataBoolean>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal(expectedValue, ((CfgVarMetadataBoolean)cfgVarMetadata).BooleanValue);
            }
        }
コード例 #14
0
        public void CfgVarMetadata_InflateCfgVarMetadataFeatureCompatibility()
        {
            var expectedValue = FeatureCompatibility.Requires;
            var cfg           = "ecs_compat = 3";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataFeatureCompatibility>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal(expectedValue, ((CfgVarMetadataFeatureCompatibility)cfgVarMetadata).Compatibility);
            }
        }
コード例 #15
0
        public void CfgVarMetadata_InflateMetadataDateTime_GetsExpectedMetadataDateTimeValue(string cfgFileValue, MetadataDateTime expectedCfgVarMetadataDateValue)
        {
            var cfgBooleanEntry = "build_date =" + cfgFileValue;

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgBooleanEntry)))
            {
                var cfgVarMetadataBoolean = CfgVarMetadataBlock.Inflate(stream) as CfgVarMetadataDate;

                var compareResult = expectedCfgVarMetadataDateValue.CompareTo(cfgVarMetadataBoolean.Date, strict: true, compareOnlyCommonValidFields: false);
                if (compareResult != 0)
                {
                    Output.WriteLine("Input:    [" + cfgFileValue + "]\nExpected: " + expectedCfgVarMetadataDateValue + "\nActual:   " + cfgVarMetadataBoolean.Date);
                }
                Assert.Equal(0, compareResult);
            }
        }
コード例 #16
0
        public void CfgVarMetadata_InflateCfgVarMetadataDate()
        {
            // YYYY-MM-DD HH:MM:SS +hhmm
            var dateTime      = new DateTimeOffset(2018, 9, 25, 22, 33, 44, new TimeSpan(6, 30, 0));
            var expectedValue = new MetadataDateTime(dateTime, UtcDateTime);
            var cfg           = "release_date = 2018-09-25 22:33:44 +0630";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfg)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType <CfgVarMetadataDate>(cfgVarMetadata);
                Assert.True(cfgVarMetadata.DeserializeByteCount > 0);
                Assert.Equal(expectedValue, ((CfgVarMetadataDate)cfgVarMetadata).Date);
            }
        }
コード例 #17
0
        public void CfgVarMetadata_InflateThenSerialize_ThrowsNotImplementedException(string stringToParse, Type expectedType)
        {
            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(stringToParse)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.Inflate(stream);

                Assert.IsType(expectedType, cfgVarMetadata);
                Assert.Equal(-1, cfgVarMetadata.SerializeByteCount);
                using (var writeStream = new System.IO.MemoryStream())
                {
                    using (var writer = new BinaryWriter(writeStream))
                    {
                        Assert.Throws <NotImplementedException>(() => cfgVarMetadata.Serialize(writer));
                    }
                }
            }
        }
コード例 #18
0
        public void CfgVarMetadata_InflatAllWithVarsSectionFirstAndNoValidVars_FindsNoCfgVars()
        {
            var cfgWithVarsFirstAndNoneValid =
                @"
[vars]
biff
Kipper = the dog
That's a toad, not a frog!
";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cfgWithVarsFirstAndNoneValid)))
            {
                var cfgVarMetadata = CfgVarMetadataBlock.InflateAll(stream);

                Assert.Empty(cfgVarMetadata);
            }
        }
コード例 #19
0
 public void CfgVarMetadata_InflateNullBinaryReader_ThrowsNullReferenceException()
 {
     Assert.Throws <NullReferenceException>(() => CfgVarMetadataBlock.Inflate((BinaryReader)null));
 }
コード例 #20
0
 public void CfgVarMetadata_InflateNullStream_ThrowsArgumentNullExcetpion()
 {
     Assert.Throws <ArgumentNullException>(() => CfgVarMetadataBlock.Inflate((System.IO.Stream)null));
 }
コード例 #21
0
 public void CfgVarMetadata_InflateAllNullStream_ThrowsNullReferenceExcetpion()
 {
     Assert.Throws <NullReferenceException>(() => CfgVarMetadataBlock.InflateAll(null));
 }