Commit ad73b425 authored by csharptest's avatar csharptest Committed by rogerk

Fixing build for SILVERLIGHT and COMPACT_FRAMEWORK before adding more build

variations (WP).  Changes are primarily superficial since they are to support
the Serialization assembly and unit tests compiling in the CF which has not
been done before.
parent 3cf33153

using System;
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
......@@ -50,4 +50,5 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting
NUnit.Framework.Assert.AreEqual(b1, b2);
}
}
}
\ No newline at end of file
}
#endif
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Globalization;
using Google.ProtocolBuffers.Descriptors;
//Disable CS3011: only CLS-compliant members can be abstract
......@@ -697,5 +698,28 @@ namespace Google.ProtocolBuffers.Serialization
}
#endregion
internal static bool TryParseInt32(string text, out int number)
{
return TryParseInt32(text, NumberStyles.Any, CultureInfo.InvariantCulture, out number);
}
internal static bool TryParseInt32(string text, NumberStyles style, IFormatProvider format, out int number)
{
#if COMPACT_FRAMEWORK
try
{
number = int.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture);
return true;
}
catch
{
number = 0;
return false;
}
#else
return int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number);
#endif
}
}
}
\ No newline at end of file
......@@ -163,7 +163,7 @@ namespace Google.ProtocolBuffers.Serialization
if (ReadAsText(ref text, typeof(Enum)))
{
int number;
if (int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
if (TryParseInt32(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
{
value = number;
return true;
......
......@@ -100,7 +100,7 @@ namespace Google.ProtocolBuffers.Serialization
private class JsonStreamWriter : JsonFormatWriter
{
#if SILVERLIGHT || COMPACT_FRAMEWORK_35
#if SILVERLIGHT || COMPACT_FRAMEWORK
static readonly Encoding Encoding = new UTF8Encoding(false);
#else
private static readonly Encoding Encoding = Encoding.ASCII;
......
......@@ -322,7 +322,7 @@ namespace Google.ProtocolBuffers.Serialization
string hex = new string(new char[] {ReadChar(), ReadChar(), ReadChar(), ReadChar()});
int result;
Assert(
int.TryParse(hex, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture,
AbstractTextReader.TryParseInt32(hex, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture,
out result),
"Expected a 4-character hex specifier.");
sb.Add((char) result);
......
......@@ -68,7 +68,7 @@ using System.Runtime.CompilerServices;
// [assembly: AssemblyVersion("2.4.1.473")]
[assembly: AssemblyVersion("2.4.1.473")]
#if !COMPACT_FRAMEWORK_35
#if !COMPACT_FRAMEWORK
[assembly: AssemblyFileVersion("2.4.1.473")]
#endif
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......
......@@ -7,7 +7,7 @@ namespace Google.ProtocolBuffers.Serialization
/// <summary>
/// The exception raised when a recursion limit is reached while parsing input.
/// </summary>
#if !SILVERLIGHT
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
[Serializable]
#endif
public sealed class RecursionLimitExceededException : FormatException
......@@ -18,7 +18,7 @@ namespace Google.ProtocolBuffers.Serialization
{
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
private RecursionLimitExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
......
......@@ -269,7 +269,7 @@ namespace Google.ProtocolBuffers.Serialization
{
int number;
string temp;
if (null != (temp = _input.GetAttribute("value")) && int.TryParse(temp, out number))
if (null != (temp = _input.GetAttribute("value")) && TryParseInt32(temp, out number))
{
Skip();
value = number;
......
......@@ -196,7 +196,7 @@ namespace Google.ProtocolBuffers
0x9abcdef012345678UL);
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
[TestMethod]
public void WriteWholeMessage()
{
......
......@@ -19,14 +19,15 @@ namespace Google.ProtocolBuffers.Compatibility
TextFormat.Merge(new StringReader((string)message), registry, (IBuilder)builder);
return builder;
}
[TestMethod, System.ComponentModel.Description("This test can take a very long time to run.")]
//This test can take a very long time to run.
[TestMethod]
public override void RoundTripMessage2OptimizeSize()
{
//base.RoundTripMessage2OptimizeSize();
}
[TestMethod, System.ComponentModel.Description("This test can take a very long time to run.")]
//This test can take a very long time to run.
[TestMethod]
public override void RoundTripMessage2OptimizeSpeed()
{
//base.RoundTripMessage2OptimizeSpeed();
......
......@@ -34,26 +34,32 @@
#endregion
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors;
using NUnit.Framework;
using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Issues.TestProtos;
namespace Google.ProtocolBuffers
{
/// <summary>
/// Tests for issues which aren't easily compartmentalized into other unit tests.
/// </summary>
[TestFixture]
[TestClass]
public class IssuesTest
{
// Issue 45
[Test]
[TestMethod]
public void FieldCalledItem()
{
ItemField message = new ItemField.Builder { Item = 3 }.Build();
FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
Assert.IsNotNull(field);
Assert.AreEqual(3, message[field]);
Assert.AreEqual(3, (int)message[field]);
}
}
}
......@@ -38,7 +38,11 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("2.4.1.473")]
[assembly: AssemblyVersion("2.4.1.473")]
#if !COMPACT_FRAMEWORK
[assembly: AssemblyFileVersion("2.4.1.473")]
#endif
// We don't really need CLSCompliance, but if the assembly builds with no warnings,
// that means the generator is okay.
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......@@ -58,14 +59,25 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkClass)' == 'CLIENTPROFILE' ">
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkClass)' != 'CLIENTPROFILE' ">
<Reference Include="Microsoft.Silverlight.Testing, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.Silverlight.Testing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\lib\NUnit-config\Microsoft.VisualStudio.TestTools.cs">
......@@ -83,6 +95,7 @@
<Compile Include="Compatibility\TestResources.cs" />
<Compile Include="Compatibility\TextCompatibilityTests.cs" />
<Compile Include="Compatibility\XmlCompatibilityTests.cs" />
<Compile Include="SerializableAttribute.cs" />
<Compile Include="TestProtos\UnitTestExtrasProtoFile.cs" />
<Compile Include="TestRpcForMimeTypes.cs" />
<Compile Include="TestReaderForUrlEncoded.cs" />
......
......@@ -13,7 +13,8 @@ namespace Google.ProtocolBuffers
[TestClass]
public class ReusableBuilderTest
{
[TestMethod, System.ComponentModel.Description("Issue 28: Circular message dependencies result in null defaults for DefaultInstance")]
//Issue 28: Circular message dependencies result in null defaults for DefaultInstance
[TestMethod]
public void EnsureStaticCicularReference()
{
MyMessageAReferenceB ab = MyMessageAReferenceB.DefaultInstance;
......
using System;
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
......@@ -175,3 +176,4 @@ namespace Google.ProtocolBuffers
}
}
}
#endif
\ No newline at end of file
......@@ -49,12 +49,11 @@ using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace Google.ProtocolBuffers
{
internal static class TestUtil
{
#if !SILVERLIGHT
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
private static string testDataDirectory;
internal static string TestDataDirectory
......@@ -1769,6 +1768,9 @@ namespace Google.ProtocolBuffers
public static void TestInMultipleCultures(CultureAction test)
{
#if COMPACT_FRAMEWORK
test();
#else
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
foreach (string culture in TestCultures)
{
......@@ -1782,6 +1784,7 @@ namespace Google.ProtocolBuffers
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
#endif
}
/// <summary>
......
......@@ -41,6 +41,7 @@ using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;
using System.Threading;
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
namespace Google.ProtocolBuffers
{
......@@ -175,7 +176,10 @@ namespace Google.ProtocolBuffers
/// </summary>
private static ByteString Bytes(string str)
{
return ByteString.CopyFrom(Encoding.GetEncoding(28591).GetBytes(str));
byte[] bytes = new byte[str.Length];
for (int i = 0; i < bytes.Length; i++)
bytes[i] = (byte)str[i];
return ByteString.CopyFrom(bytes);
}
[TestMethod]
......@@ -568,4 +572,5 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(longText, builder.OptionalString);
}
}
}
\ No newline at end of file
}
#endif
\ No newline at end of file
......@@ -231,7 +231,7 @@ namespace Google.ProtocolBuffers
/// </summary>
public bool ReadDouble(ref double value)
{
#if SILVERLIGHT || COMPACT_FRAMEWORK_35
#if SILVERLIGHT || COMPACT_FRAMEWORK
if (BitConverter.IsLittleEndian && 8 <= bufferSize - bufferPos)
{
value = BitConverter.ToDouble(buffer, bufferPos);
......
......@@ -496,7 +496,7 @@ namespace Google.ProtocolBuffers
/// </summary>
public void WriteDoubleNoTag(double value)
{
#if SILVERLIGHT || COMPACT_FRAMEWORK_35
#if SILVERLIGHT || COMPACT_FRAMEWORK
byte[] rawBytes = BitConverter.GetBytes(value);
if (!BitConverter.IsLittleEndian)
ByteArray.Reverse(rawBytes);
......
......@@ -40,7 +40,7 @@ using System.Runtime.Serialization;
/*
* This entire source file is not supported on the Silverlight platform
*/
#if !SILVERLIGHT
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
namespace Google.ProtocolBuffers
{
/*
......
......@@ -98,7 +98,7 @@ namespace Google.ProtocolBuffers
public EnumLiteMap()
{
items = new SortedList<int, IEnumLite>();
#if SILVERLIGHT
#if SILVERLIGHT || COMPACT_FRAMEWORK
// Silverlight doesn't support Enum.GetValues
// TODO(jonskeet): Validate that this reflection is permitted, e.g. in Windows Phone 7
foreach (System.Reflection.FieldInfo fi in typeof(TEnum).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public))
......
......@@ -68,7 +68,7 @@ using System.Runtime.CompilerServices;
// [assembly: AssemblyVersion("2.4.1.473")]
[assembly: AssemblyVersion("2.4.1.473")]
#if !COMPACT_FRAMEWORK_35
#if !COMPACT_FRAMEWORK
[assembly: AssemblyFileVersion("2.4.1.473")]
#endif
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......
......@@ -82,7 +82,7 @@ namespace Google.ProtocolBuffers
public static Exception CreateMissingMethod(Type type, string methodName)
{
#if SILVERLIGHT
#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);
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......@@ -39,14 +40,25 @@
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkClass)' == 'CLIENTPROFILE' ">
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkClass)' != 'CLIENTPROFILE' ">
<Reference Include="Microsoft.Silverlight.Testing, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.Silverlight.Testing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\lib\NUnit-config\Microsoft.VisualStudio.TestTools.cs">
......@@ -66,6 +78,7 @@
<Compile Include="ExtendableBuilderLiteTest.cs" />
<Compile Include="ExtendableMessageLiteTest.cs" />
<Compile Include="LiteTest.cs" />
<Compile Include="SerializableAttribute.cs" />
<Compile Include="SerializableLiteTest.cs" />
<Compile Include="TestLiteByApi.cs" />
<Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" />
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworkClass>CLIENTPROFILE</TargetFrameworkClass>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
......@@ -39,14 +40,25 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkClass)' == 'CLIENTPROFILE' ">
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkClass)' != 'CLIENTPROFILE' ">
<Reference Include="Microsoft.Silverlight.Testing, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.Silverlight.Testing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Silverlight.Testing\April2010\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\lib\NUnit-config\Microsoft.VisualStudio.TestTools.cs">
......@@ -62,6 +74,7 @@
<Compile Include="InteropLiteTest.cs" />
<Compile Include="LiteTest.cs" />
<Compile Include="MissingFieldAndExtensionTest.cs" />
<Compile Include="SerializableAttribute.cs" />
<Compile Include="TestLiteByApi.cs" />
<Compile Include="TestProtos\UnitTestExtrasFullProtoFile.cs" />
<Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" />
......
using System;
#if !SILVERLIGHT && !COMPACT_FRAMEWORK
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
......@@ -51,3 +52,4 @@ namespace Google.ProtocolBuffers
}
}
}
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment