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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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)); } } } }
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); } }
public void CfgVarMetadata_InflateNullBinaryReader_ThrowsNullReferenceException() { Assert.Throws <NullReferenceException>(() => CfgVarMetadataBlock.Inflate((BinaryReader)null)); }
public void CfgVarMetadata_InflateNullStream_ThrowsArgumentNullExcetpion() { Assert.Throws <ArgumentNullException>(() => CfgVarMetadataBlock.Inflate((System.IO.Stream)null)); }
public void CfgVarMetadata_InflateAllNullStream_ThrowsNullReferenceExcetpion() { Assert.Throws <NullReferenceException>(() => CfgVarMetadataBlock.InflateAll(null)); }