Skip to content

Commit

Permalink
Tests and fixes for the UK Pound and any other double wide UTF-8 char…
Browse files Browse the repository at this point in the history
…acter.
  • Loading branch information
unknown authored and unknown committed Sep 24, 2009
1 parent 4a43aec commit a6b9da3
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 262 deletions.
21 changes: 20 additions & 1 deletion MongoDB.Net-Tests/Bson/TestBsonDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,26 @@ public void TestFormatting(){
hexdump = hexdump.Replace("-","");
Assert.AreEqual(20,output[0],"Size didn't take into count null terminator");
Assert.AreEqual("1400000002746573740005000000746573740000",hexdump, "Dump not correct");
}
}

[Test]
public void TestFormattingWithUKPound(){
BsonDocument doc = new BsonDocument();
MemoryStream buf = new MemoryStream();
BsonWriter writer = new BsonWriter(buf);

doc.Add("_id", new BsonOid(new Oid("4ABBED9D1D8B0F0218000001")));
doc.Add("test", new BsonString("1234£56"));
doc.Write(writer);
writer.Flush();

Byte[] output = buf.ToArray();
String hexdump = BitConverter.ToString(output);
hexdump = hexdump.Replace("-","");
//Assert.AreEqual(20,output[0],"Size didn't take into count null terminator");
Assert.AreEqual("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000",hexdump, "Dump not correct");
}


[Test]
public void TestElements(){
Expand Down
25 changes: 25 additions & 0 deletions MongoDB.Net-Tests/Bson/TestBsonString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.IO;
using System.Text;

using NUnit.Framework;

Expand All @@ -13,6 +14,7 @@ namespace MongoDB.Driver.Bson
[TestFixture]
public class TestBsonString
{
private String empty;
[Test]
public void TestFormatting(){
BsonString str = new BsonString("test");
Expand All @@ -32,5 +34,28 @@ public void TestSize(){
BsonString str = new BsonString("test");
Assert.AreEqual(9,str.Size);
}

[Test]
public void TestSizeWithUKPound(){
UTF8Encoding encoding = new UTF8Encoding();
int baseSize = 5;
String test = "";
BsonString bstr = new BsonString(test);
Assert.AreEqual(baseSize + encoding.GetByteCount(test), bstr.Size, "Size didn't count the double wide pound symbol correctly");
}

[Test]
public void TestFormattingWithUKPound(){
BsonString str = new BsonString("1234£56");
MemoryStream buf = new MemoryStream();
BsonWriter writer = new BsonWriter(buf);
str.Write(writer);
writer.Flush();
Byte[] output = buf.ToArray();
String hexdump = BitConverter.ToString(output);
hexdump = hexdump.Replace("-","");
Assert.AreEqual("0900000031323334C2A3353600",hexdump, "Dump not correct");
Assert.AreEqual(9,output[0],"Size didn't take into account size of pound symbol");
}
}
}
227 changes: 114 additions & 113 deletions MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,114 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>MongoDB.Driver.Tests</AssemblyName>
<SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\scorder\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.5.0.9122, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="nunit.framework, Version=2.5.0.9122, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.core, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Package>nunit</Package>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestAuthentication.cs" />
<Compile Include="Bson\TestBsonConvert.cs" />
<Compile Include="Bson\TestBsonDate.cs" />
<Compile Include="Bson\TestBsonDocument.cs" />
<Compile Include="Bson\TestBsonElement.cs" />
<Compile Include="Bson\TestBsonReader.cs" />
<Compile Include="Bson\TestBsonString.cs" />
<Compile Include="Bson\TestBsonTypes.cs" />
<Compile Include="IO\TestQueryMessage.cs" />
<Compile Include="TestCollection.cs" />
<Compile Include="TestCursor.cs" />
<Compile Include="TestDatabase.cs" />
<Compile Include="TestDatabaseMetaData.cs" />
<Compile Include="TestDBRef.cs" />
<Compile Include="TestDocument.cs" />
<Compile Include="TestMongo.cs" />
<Compile Include="TestConnection.cs" />
<Compile Include="IO\TestMsgMessage.cs" />
<Compile Include="TestB.cs" />
<None Include="test-data\tests.reads.txt" />
<None Include="test-data\tests.smallreads.txt" />
<Compile Include="Bson\TestBsonRegex.cs" />
<Compile Include="TestMongoExceptions.cs" />
<Compile Include="TestOid.cs" />
<Compile Include="TestPairedConnection.cs" />
<Compile Include="Bson\TestBsonCode.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDBDriver\MongoDB.Driver.csproj">
<Project>{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}</Project>
<Name>MongoDB.Driver</Name>
</ProjectReference>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C8BC95AB-25C6-4133-BC9F-8B6BB782CA02}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>MongoDB.Driver.Tests</AssemblyName>
<SourceAnalysisOverrideSettingsFile>C:\Documents and Settings\scorder\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.5.0.9122, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="nunit.framework, Version=2.5.0.9122, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.core, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Package>nunit</Package>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestAuthentication.cs" />
<Compile Include="Bson\TestBsonConvert.cs" />
<Compile Include="Bson\TestBsonDate.cs" />
<Compile Include="Bson\TestBsonDocument.cs" />
<Compile Include="Bson\TestBsonElement.cs" />
<Compile Include="Bson\TestBsonReader.cs" />
<Compile Include="Bson\TestBsonString.cs" />
<Compile Include="Bson\TestBsonTypes.cs" />
<Compile Include="IO\TestQueryMessage.cs" />
<Compile Include="TestCollection.cs" />
<Compile Include="TestCursor.cs" />
<Compile Include="TestDatabase.cs" />
<Compile Include="TestDatabaseMetaData.cs" />
<Compile Include="TestDBRef.cs" />
<Compile Include="TestDocument.cs" />
<Compile Include="TestMongo.cs" />
<Compile Include="TestConnection.cs" />
<Compile Include="IO\TestMsgMessage.cs" />
<Compile Include="TestB.cs" />
<None Include="test-data\tests.charreads.txt" />
<None Include="test-data\tests.reads.txt" />
<None Include="test-data\tests.smallreads.txt" />
<Compile Include="Bson\TestBsonRegex.cs" />
<Compile Include="TestMongoExceptions.cs" />
<Compile Include="TestOid.cs" />
<Compile Include="TestPairedConnection.cs" />
<Compile Include="Bson\TestBsonCode.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDBDriver\MongoDB.Driver.csproj">
<Project>{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}</Project>
<Name>MongoDB.Driver</Name>
</ProjectReference>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions MongoDB.Net-Tests/TestCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public void TestFindGTRange(){
}
}

[Test]
public void TestFindOneObjectContainingUKPound(){
Document query = new Document();
Document result = db["tests"]["charreads"].FindOne(query);
Assert.IsNotNull(result);
Assert.IsTrue(result.Contains("test"));
Assert.AreEqual("1234£56",result["test"]);
}

[Test]
public void TestSimpleInsert(){
Collection inserts = db["tests"]["inserts"];
Expand Down Expand Up @@ -84,6 +93,17 @@ public void TestReallySimpleInsert(){
Assert.AreEqual(1,result["y"]);
}

[Test]
public void TestPoundSymbolInsert(){
Collection inserts = db["tests"]["inserts"];
Document indoc = new Document().Append("x","1234£56").Append("y",1);;
inserts.Insert(indoc);

Document result = inserts.FindOne(new Document().Append("x","1234£56"));
Assert.IsNotNull(result);
Assert.AreEqual(1,result["y"]);
}

[Test]
public void TestArrayInsert(){
Collection inserts = db["tests"]["inserts"];
Expand Down
1 change: 1 addition & 0 deletions MongoDB.Net-Tests/test-data/tests.charreads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "_id" : "4abbed9d1d8b0f0218000001", "test" : "1234£56" }
1 change: 1 addition & 0 deletions MongoDBDriver.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# SharpDevelop 3.1.0.4890
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver", "MongoDBDriver\MongoDB.Driver.csproj", "{B125BBA6-BFFD-44FA-9254-9B1754CD8AF3}"
EndProject
Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "Packages", "Packages.mdproj", "{502F3381-58AA-461B-B9D8-12578A588C61}"
Expand Down
Loading

0 comments on commit a6b9da3

Please sign in to comment.