diff --git a/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs b/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs index 4fe6ea7c7d..1c71dc9516 100644 --- a/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs +++ b/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs @@ -100,11 +100,7 @@ namespace Google.ProtocolBuffers.Serialization private class JsonStreamWriter : JsonFormatWriter { -#if SILVERLIGHT || COMPACT_FRAMEWORK static readonly Encoding Encoding = new UTF8Encoding(false); -#else - private static readonly Encoding Encoding = Encoding.ASCII; -#endif private readonly byte[] _buffer; private Stream _output; private int _bufferPos; diff --git a/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs b/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs index a2f683f70d..14e72ba872 100644 --- a/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs +++ b/src/ProtocolBuffers.Serialization/RecursionLimitExceeded.cs @@ -7,9 +7,6 @@ namespace Google.ProtocolBuffers.Serialization /// /// The exception raised when a recursion limit is reached while parsing input. /// -#if !SILVERLIGHT && !COMPACT_FRAMEWORK - [Serializable] -#endif public sealed class RecursionLimitExceededException : FormatException { const string message = "Possible malicious message had too many levels of nesting."; @@ -17,12 +14,5 @@ namespace Google.ProtocolBuffers.Serialization internal RecursionLimitExceededException() : base(message) { } - -#if !SILVERLIGHT && !COMPACT_FRAMEWORK - private RecursionLimitExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - } -#endif } } diff --git a/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs b/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs index f6e7537ca1..172c14bdbb 100644 --- a/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs +++ b/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs @@ -196,7 +196,6 @@ namespace Google.ProtocolBuffers 0x9abcdef012345678UL); } -#if !SILVERLIGHT && !COMPACT_FRAMEWORK [TestMethod] public void WriteWholeMessage() { @@ -230,7 +229,6 @@ namespace Google.ProtocolBuffers TestUtil.AssertEqualBytes(TestUtil.GetGoldenPackedFieldsMessage().ToByteArray(), rawBytes); } -#endif [TestMethod] public void EncodeZigZag32() diff --git a/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs index 8438d94fcb..9707f8e8ed 100644 --- a/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/BinaryCompatibilityTests.cs @@ -1,11 +1,5 @@ using System; -#if SILVERLIGHT -using TestClass = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; -using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; -#else using Microsoft.VisualStudio.TestTools.UnitTesting; -#endif namespace Google.ProtocolBuffers.Compatibility { diff --git a/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs index fddddf849d..73037cce6a 100644 --- a/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs @@ -3,14 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using Google.ProtocolBuffers.Serialization; -#if SILVERLIGHT -using TestClass = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; -using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; -#else using Microsoft.VisualStudio.TestTools.UnitTesting; -#endif - namespace Google.ProtocolBuffers.Compatibility { diff --git a/src/ProtocolBuffers.Test/Compatibility/TestResources.cs b/src/ProtocolBuffers.Test/Compatibility/TestResources.cs index 2fc1322b82..c3ce58834d 100644 --- a/src/ProtocolBuffers.Test/Compatibility/TestResources.cs +++ b/src/ProtocolBuffers.Test/Compatibility/TestResources.cs @@ -2,14 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; -#if SILVERLIGHT -using TestClass = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; -using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; -#else using Microsoft.VisualStudio.TestTools.UnitTesting; -#endif - namespace Google.ProtocolBuffers.Compatibility { diff --git a/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs index 9113b58971..70614744b0 100644 --- a/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs +++ b/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs @@ -2,14 +2,7 @@ using System.IO; using System.Xml; using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.TestProtos; -#if SILVERLIGHT -using TestClass = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; -using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; -#else using Microsoft.VisualStudio.TestTools.UnitTesting; -#endif - namespace Google.ProtocolBuffers.Compatibility { diff --git a/src/ProtocolBuffers.Test/DescriptorsTest.cs b/src/ProtocolBuffers.Test/DescriptorsTest.cs index 5cf79e3ba8..ca10c62162 100644 --- a/src/ProtocolBuffers.Test/DescriptorsTest.cs +++ b/src/ProtocolBuffers.Test/DescriptorsTest.cs @@ -229,7 +229,6 @@ namespace Google.ProtocolBuffers Assert.IsFalse(repeatedField.IsRequired); Assert.IsTrue(repeatedField.IsRepeated); } -#if !SILVERLIGHT [TestMethod] public void FieldDescriptorDefault() { @@ -240,13 +239,12 @@ namespace Google.ProtocolBuffers Assert.AreEqual(41, d.FindDescriptor("default_int32").DefaultValue); d = TestExtremeDefaultValues.Descriptor; - Assert.AreEqual( - ByteString.CopyFrom("\u0000\u0001\u0007\b\f\n\r\t\u000b\\\'\"\u00fe", Encoding.GetEncoding("iso-8859-1")), + Assert.AreEqual(TestExtremeDefaultValues.DefaultInstance.EscapedBytes, d.FindDescriptor("escaped_bytes").DefaultValue); + Assert.AreEqual(uint.MaxValue, d.FindDescriptor("large_uint32").DefaultValue); Assert.AreEqual(ulong.MaxValue, d.FindDescriptor("large_uint64").DefaultValue); } -#endif [TestMethod] public void EnumDescriptor() { diff --git a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 0d9f0abee1..69b42306de 100644 --- a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -78,6 +78,11 @@ + + True + True + TestResources.resx + @@ -155,6 +160,20 @@ + + ResXFileCodeGenerator + TestResources.Designer.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Resources\golden_message;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Resources\golden_packed_fields_message;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Resources\text_format_unittest_data.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + Resources\text_format_unittest_extensions_data.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + \ No newline at end of file diff --git a/src/ProtocolBuffers.Test/TestUtil.cs b/src/ProtocolBuffers.Test/TestUtil.cs index ffbb91d5b3..19c0df349b 100644 --- a/src/ProtocolBuffers.Test/TestUtil.cs +++ b/src/ProtocolBuffers.Test/TestUtil.cs @@ -41,47 +41,12 @@ using System.IO; using System.Text; using System.Threading; using Google.ProtocolBuffers.TestProtos; -#if SILVERLIGHT -using TestClass = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; -using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; -#else using Microsoft.VisualStudio.TestTools.UnitTesting; -#endif namespace Google.ProtocolBuffers { internal static class TestUtil { -#if !SILVERLIGHT && !COMPACT_FRAMEWORK - private static string testDataDirectory; - - internal static string TestDataDirectory - { - get - { - if (testDataDirectory != null) - { - return testDataDirectory; - } - - DirectoryInfo ancestor = new DirectoryInfo("."); - // Search each parent directory looking for "testdata". - while (ancestor != null) - { - string candidate = Path.Combine(ancestor.FullName, "testdata"); - if (Directory.Exists(candidate)) - { - testDataDirectory = candidate; - return candidate; - } - ancestor = ancestor.Parent; - } - // TODO(jonskeet): Come up with a better exception to throw - throw new Exception("Unable to find directory containing test files"); - } - } - private static ByteString goldenMessage = null; internal static ByteString GoldenMessage @@ -90,23 +55,12 @@ namespace Google.ProtocolBuffers { if (goldenMessage == null) { - goldenMessage = ReadBytesFromFile("golden_message"); + goldenMessage = ByteString.CopyFrom(TestResources.golden_message); } return goldenMessage; } } - internal static string ReadTextFromFile(string filePath) - { - return ReadBytesFromFile(filePath).ToStringUtf8(); - } - - internal static ByteString ReadBytesFromFile(String filename) - { - byte[] data = File.ReadAllBytes(Path.Combine(TestDataDirectory, filename)); - return ByteString.CopyFrom(data); - } - private static ByteString goldenPackedFieldsMessage = null; /// @@ -120,12 +74,11 @@ namespace Google.ProtocolBuffers { if (goldenPackedFieldsMessage == null) { - goldenPackedFieldsMessage = ReadBytesFromFile("golden_packed_fields_message"); + goldenPackedFieldsMessage = ByteString.CopyFrom(TestResources.golden_packed_fields_message); } return goldenPackedFieldsMessage; } -#endif /// /// Creates an unmodifiable ExtensionRegistry containing all the extensions /// of TestAllExtensions. diff --git a/src/ProtocolBuffers.Test/TextFormatTest.cs b/src/ProtocolBuffers.Test/TextFormatTest.cs index 10ab4e150e..3008c599ce 100644 --- a/src/ProtocolBuffers.Test/TextFormatTest.cs +++ b/src/ProtocolBuffers.Test/TextFormatTest.cs @@ -41,17 +41,14 @@ using Google.ProtocolBuffers.TestProtos; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Globalization; using System.Threading; -#if !SILVERLIGHT && !COMPACT_FRAMEWORK namespace Google.ProtocolBuffers { [TestClass] public class TextFormatTest { - private static readonly string AllFieldsSetText = TestUtil.ReadTextFromFile("text_format_unittest_data.txt"); - - private static readonly string AllExtensionsSetText = - TestUtil.ReadTextFromFile("text_format_unittest_extensions_data.txt"); + private static readonly string AllFieldsSetText = TestResources.text_format_unittest_data; + private static readonly string AllExtensionsSetText = TestResources.text_format_unittest_extensions_data; /// /// Note that this is slightly different to the Java - 123.0 becomes 123, and 1.23E17 becomes 1.23E+17. @@ -572,5 +569,4 @@ namespace Google.ProtocolBuffers Assert.AreEqual(longText, builder.OptionalString); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ProtocolBuffers/CustomSerialization.cs b/src/ProtocolBuffers/CustomSerialization.cs index 256f2e679f..a1aee029c5 100644 --- a/src/ProtocolBuffers/CustomSerialization.cs +++ b/src/ProtocolBuffers/CustomSerialization.cs @@ -36,7 +36,7 @@ /* * This entire source file is not supported on the Silverlight platform */ -#if !SILVERLIGHT && !COMPACT_FRAMEWORK +#if !NOSERIALIZABLE using System; using System.Runtime.Serialization; diff --git a/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs b/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs index d2b6c51f36..24f7fba984 100644 --- a/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs +++ b/src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs @@ -63,8 +63,7 @@ namespace Google.ProtocolBuffers.FieldAccess /// /// Method used solely for implementing CreateUpcastDelegate. Public to avoid trust issues - /// in low-trust scenarios, e.g. Silverlight. - /// TODO(jonskeet): Check any of this actually works in Silverlight... + /// in low-trust scenarios. /// public static Func CreateUpcastDelegateImpl(MethodInfo method) { diff --git a/src/ProtocolBuffers/FrameworkPortability.cs b/src/ProtocolBuffers/FrameworkPortability.cs index 774d562534..78b7db31dd 100644 --- a/src/ProtocolBuffers/FrameworkPortability.cs +++ b/src/ProtocolBuffers/FrameworkPortability.cs @@ -42,7 +42,7 @@ using System.Text.RegularExpressions; namespace Google.ProtocolBuffers { /// - /// Class containing helpful workarounds for Silverlight compatibility + /// Class containing helpful workarounds for various platform compatibility /// internal static class FrameworkPortability { diff --git a/src/ProtocolBuffers/SortedList.cs b/src/ProtocolBuffers/SortedList.cs index 4dcf928273..2dd7da9222 100644 --- a/src/ProtocolBuffers/SortedList.cs +++ b/src/ProtocolBuffers/SortedList.cs @@ -34,7 +34,7 @@ #endregion -#if SILVERLIGHT +#if NOSORTEDLIST using System.Collections; using System.Collections.Generic; @@ -45,8 +45,6 @@ namespace Google.ProtocolBuffers /// This is not particularly efficient: it wraps a normal dictionary /// for most operations, but sorts by key when either iterating or /// fetching the Keys/Values properties. - /// This is only used for Silverlight, which doesn't have the normal - /// sorted collections. /// internal sealed class SortedList : IDictionary { diff --git a/src/ProtocolBuffers/ThrowHelper.cs b/src/ProtocolBuffers/ThrowHelper.cs index 22584dd0b8..34b3f65377 100644 --- a/src/ProtocolBuffers/ThrowHelper.cs +++ b/src/ProtocolBuffers/ThrowHelper.cs @@ -82,11 +82,7 @@ namespace Google.ProtocolBuffers public static Exception CreateMissingMethod(Type type, string methodName) { -#if SILVERLIGHT || COMPACT_FRAMEWORK return new MissingMethodException(String.Format("The method '{0}' was not found on type {1}", methodName, type)); -#else - return new MissingMethodException(String.Format("{0}", type), methodName); -#endif } } } \ No newline at end of file