diff options
Diffstat (limited to 'tools/NUnit/samples/cpp/cpp-cli')
10 files changed, 1297 insertions, 0 deletions
diff --git a/tools/NUnit/samples/cpp/cpp-cli/cpp-cli.sln b/tools/NUnit/samples/cpp/cpp-cli/cpp-cli.sln new file mode 100644 index 0000000..a30cf36 --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/cpp-cli.sln @@ -0,0 +1,41 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp-cli-failures", "failures\cpp-cli-failures.vcproj", "{A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp-cli-syntax", "syntax\cpp-cli-syntax.vcproj", "{72448C2D-17C9-419E-B28D-3B533E7E0CD5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Debug|Win32.ActiveCfg = Debug|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Debug|Win32.Build.0 = Debug|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Release|Any CPU.ActiveCfg = Release|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Release|Mixed Platforms.Build.0 = Release|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Release|Win32.ActiveCfg = Release|Win32 + {A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}.Release|Win32.Build.0 = Release|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Debug|Win32.ActiveCfg = Debug|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Debug|Win32.Build.0 = Debug|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Release|Any CPU.ActiveCfg = Release|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Release|Mixed Platforms.Build.0 = Release|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Release|Win32.ActiveCfg = Release|Win32 + {72448C2D-17C9-419E-B28D-3B533E7E0CD5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tools/NUnit/samples/cpp/cpp-cli/failures/AssemblyInfo.cpp b/tools/NUnit/samples/cpp/cpp-cli/failures/AssemblyInfo.cpp new file mode 100644 index 0000000..e64d6ee --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/failures/AssemblyInfo.cpp @@ -0,0 +1,56 @@ +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("2.2.0.0")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + diff --git a/tools/NUnit/samples/cpp/cpp-cli/failures/cpp-cli-failures.build b/tools/NUnit/samples/cpp/cpp-cli/failures/cpp-cli-failures.build new file mode 100644 index 0000000..8cf139e --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/failures/cpp-cli-failures.build @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<project name="cpp-cli-failures" default="build"> + + <include buildfile="../../../samples.common"/> + + <patternset id="source-files"> + <include name="AssemblyInfo.cpp" /> + <include name="cppsample.cpp" /> + <include name="cppsample.h" /> + </patternset> + + <target name="packagex"> + <copy todir="${package.samples.dir}/cpp/cpp-cli/failures"> + <fileset basedir="."> + <include name="cpp-cli-failures.vcproj" /> + <include name="cpp-cli-failures.build" /> + <include name="AssemblyInfo.cpp" /> + <include name="cppsample.cpp" /> + <include name="cppsample.h" /> + </fileset> + </copy> + </target> + +</project>
\ No newline at end of file diff --git a/tools/NUnit/samples/cpp/cpp-cli/failures/cpp-cli-failures.vcproj b/tools/NUnit/samples/cpp/cpp-cli/failures/cpp-cli-failures.vcproj new file mode 100644 index 0000000..364a6be --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/failures/cpp-cli-failures.vcproj @@ -0,0 +1,208 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="cpp-cli-failures" + ProjectGUID="{A0987BCD-AFE6-40E4-95A8-ADA7ADB7E97D}" + RootNamespace="cpp-failures" + Keyword="ManagedCProj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="2" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + ManagedExtensions="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalUsingDirectories="" + PreprocessorDefinitions="WIN32;_DEBUG" + MinimalRebuild="false" + BasicRuntimeChecks="0" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/cpp-cli-failures.dll" + LinkIncremental="2" + GenerateDebugInformation="true" + AssemblyDebug="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="2" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + ManagedExtensions="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + InlineFunctionExpansion="1" + AdditionalUsingDirectories="" + PreprocessorDefinitions="WIN32;NDEBUG" + MinimalRebuild="false" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/cpp-cli-failures.dll" + LinkIncremental="1" + GenerateDebugInformation="true" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + <AssemblyReference + RelativePath="..\..\..\..\solutions\vs2005\NUnitFramework\framework\bin\Debug\nunit.framework.dll" + AssemblyName="nunit.framework, Version=2.5.0.0, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" + /> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm" + > + <File + RelativePath="AssemblyInfo.cpp" + > + </File> + <File + RelativePath="cppsample.cpp" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc" + > + <File + RelativePath="cppsample.h" + > + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;r" + > + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/tools/NUnit/samples/cpp/cpp-cli/failures/cppsample.cpp b/tools/NUnit/samples/cpp/cpp-cli/failures/cppsample.cpp new file mode 100644 index 0000000..f5aea7c --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/failures/cppsample.cpp @@ -0,0 +1,48 @@ +// **************************************************************** +// This is free software licensed under the NUnit license. You +// may obtain a copy of the license as well as information regarding +// copyright ownership at http://nunit.org/?p=license&r=2.4. +// **************************************************************** + +#include "cppsample.h" + +namespace NUnitSamples { + + void SimpleCPPSample::Init() { + fValue1 = 2; + fValue2 = 3; + } + + void SimpleCPPSample::Add() { + int result = fValue1 + fValue2; + Assert::AreEqual(6,result); + } + + void SimpleCPPSample::DivideByZero() + { + int zero= 0; + int result= 8/zero; + } + + void SimpleCPPSample::Equals() { + Assert::AreEqual(12, 12, "Integer"); + Assert::AreEqual(12L, 12L, "Long"); + Assert::AreEqual('a', 'a', "Char"); + + + Assert::AreEqual(12, 13, "Expected Failure (Integer)"); + Assert::AreEqual(12.0, 11.99, 0.0, "Expected Failure (Double)"); + } + + void SimpleCPPSample::IgnoredTest() + { + throw gcnew InvalidCastException(); + } + + void SimpleCPPSample::ExpectAnException() + { + throw gcnew InvalidCastException(); + } + +} + diff --git a/tools/NUnit/samples/cpp/cpp-cli/failures/cppsample.h b/tools/NUnit/samples/cpp/cpp-cli/failures/cppsample.h new file mode 100644 index 0000000..863feb5 --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/failures/cppsample.h @@ -0,0 +1,28 @@ +// **************************************************************** +// This is free software licensed under the NUnit license. You +// may obtain a copy of the license as well as information regarding +// copyright ownership at http://nunit.org/?p=license&r=2.4. +// **************************************************************** + +#pragma once + +using namespace System; +using namespace NUnit::Framework; + +namespace NUnitSamples +{ + [TestFixture] + public ref class SimpleCPPSample + { + int fValue1; + int fValue2; + public: + [SetUp] void Init(); + + [Test] void Add(); + [Test] void DivideByZero(); + [Test] void Equals(); + [Test] [Ignore("ignored test")] void IgnoredTest(); + [Test] [ExpectedException(InvalidOperationException::typeid)] void ExpectAnException(); + }; +} diff --git a/tools/NUnit/samples/cpp/cpp-cli/syntax/AssemblyInfo.cpp b/tools/NUnit/samples/cpp/cpp-cli/syntax/AssemblyInfo.cpp new file mode 100644 index 0000000..b18cdfa --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/syntax/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("cppclisyntax")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("cppclisyntax")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2007")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.build b/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.build new file mode 100644 index 0000000..f3b6328 --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.build @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<project name="cpp-cli-syntax" default="build"> + + <include buildfile="../../../samples.common"/> + + <patternset id="source-files"> + <include name="AssemblyInfo.cpp" /> + <include name="cpp-cli-syntax.cpp" /> + </patternset> + +</project>
\ No newline at end of file diff --git a/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.cpp b/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.cpp new file mode 100644 index 0000000..a554e95 --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.cpp @@ -0,0 +1,641 @@ +// **************************************************************** +// This is free software licensed under the NUnit license. You +// may obtain a copy of the license as well as information regarding +// copyright ownership at http://nunit.org/?p=license&r=2.4. +// **************************************************************** + +using namespace NUnit::Framework; +using NUnit::Framework::Is; +using NUnit::Framework::Text; +using NUnit::Framework::List; +using NUnit::Framework::Has; +using System::String; + +namespace NUnitSamples +{ + [TestFixture] + public ref class AssertSyntaxTests : AssertionHelper + { + public: + [Test] + void IsNull() + { + Object ^nada = nullptr; + + // Classic syntax + Assert::IsNull(nada); + + // Helper syntax + Assert::That(nada, Is::Null); + + // Inherited syntax + Expect(nada, Null); + } + + [Test] + void IsNotNull() + { + // Classic syntax + Assert::IsNotNull(42); + + // Helper syntax + Assert::That(42, Is::Not->Null); + + // Inherited syntax + Expect( 42, Not->Null ); + } + + [Test] + void IsTrue() + { + // Classic syntax + Assert::IsTrue(2+2==4); + + // Helper syntax + Assert::That(2+2==4, Is::True); + Assert::That(2+2==4); + + // Inherited syntax + Expect(2+2==4, True); + Expect(2+2==4); + } + + [Test] + void IsFalse() + { + // Classic syntax + Assert::IsFalse(2+2==5); + + // Helper syntax + Assert::That(2+2==5, Is::False); + + // Inherited syntax + Expect(2+2==5, False); + } + + [Test] + void IsNaN() + { + double d = double::NaN; + float f = float::NaN; + + // Classic syntax + Assert::IsNaN(d); + Assert::IsNaN(f); + + // Helper syntax + Assert::That(d, Is::NaN); + Assert::That(f, Is::NaN); + + // Inherited syntax + Expect(d, NaN); + Expect(f, NaN); + } + + [Test] + void EmptyStringTests() + { + // Classic syntax + Assert::IsEmpty(""); + Assert::IsNotEmpty("Hello!"); + + // Helper syntax + Assert::That("", Is::Empty); + Assert::That("Hello!", Is::Not->Empty); + + // Inherited syntax + Expect("", Empty); + Expect("Hello!", Not->Empty); + } + + [Test] + void EmptyCollectionTests() + { + // Classic syntax + Assert::IsEmpty(gcnew array<bool>(0)); + Assert::IsNotEmpty(gcnew array<int>(3)); + + // Helper syntax + Assert::That(gcnew array<bool>(0), Is::Empty); + Assert::That(gcnew array<int>(3), Is::Not->Empty); + + // Inherited syntax + Expect(gcnew array<bool>(0), Empty); + Expect(gcnew array<int>(3), Not->Empty); + } + + [Test] + void ExactTypeTests() + { + // Classic syntax workarounds) + String^ greeting = "Hello"; + Assert::AreEqual(String::typeid, greeting->GetType()); + Assert::AreEqual("System.String", greeting->GetType()->FullName); + Assert::AreNotEqual(int::typeid, greeting->GetType()); + Assert::AreNotEqual("System.Int32", greeting->GetType()->FullName); + + // Helper syntax + Assert::That(greeting, Is::TypeOf(String::typeid)); + Assert::That(greeting, Is::Not->TypeOf(int::typeid)); + + // Inherited syntax + Expect( "Hello", TypeOf(String::typeid)); + Expect( "Hello", Not->TypeOf(int::typeid)); + } + + [Test] + void InstanceOfTypeTests() + { + // Classic syntax + Assert::IsInstanceOfType(String::typeid, "Hello"); + Assert::IsNotInstanceOfType(String::typeid, 5); + + // Helper syntax + Assert::That("Hello", Is::InstanceOfType(String::typeid)); + Assert::That(5, Is::Not->InstanceOfType(String::typeid)); + + // Inherited syntax + Expect("Hello", InstanceOfType(String::typeid)); + Expect(5, Not->InstanceOfType(String::typeid)); + } + + [Test] + void AssignableFromTypeTests() + { + // Classic syntax + Assert::IsAssignableFrom(String::typeid, "Hello"); + Assert::IsNotAssignableFrom(String::typeid, 5); + + // Helper syntax + Assert::That( "Hello", Is::AssignableFrom(String::typeid)); + Assert::That( 5, Is::Not->AssignableFrom(String::typeid)); + + // Inherited syntax + Expect( "Hello", AssignableFrom(String::typeid)); + Expect( 5, Not->AssignableFrom(String::typeid)); + } + + [Test] + void SubstringTests() + { + String^ phrase = "Hello World!"; + array<String^>^ strings = {"abc", "bad", "dba" }; + + // Classic Syntax + StringAssert::Contains("World", phrase); + + // Helper syntax + Assert::That(phrase, Contains("World")); + // Only available using new syntax + Assert::That(phrase, Text::DoesNotContain("goodbye")); + Assert::That(phrase, Text::Contains("WORLD")->IgnoreCase); + Assert::That(phrase, Text::DoesNotContain("BYE")->IgnoreCase); + Assert::That(strings, Text::All->Contains( "b" ) ); + + // Inherited syntax + Expect(phrase, Contains("World")); + // Only available using new syntax + Expect(phrase, Not->Contains("goodbye")); + Expect(phrase, Contains("WORLD")->IgnoreCase); + Expect(phrase, Not->Contains("BYE")->IgnoreCase); + Expect(strings, All->Contains("b")); + } + + [Test] + void StartsWithTests() + { + String^ phrase = "Hello World!"; + array<String^>^ greetings = { "Hello!", "Hi!", "Hola!" }; + + // Classic syntax + StringAssert::StartsWith("Hello", phrase); + + // Helper syntax + Assert::That(phrase, Text::StartsWith("Hello")); + // Only available using new syntax + Assert::That(phrase, Text::DoesNotStartWith("Hi!")); + Assert::That(phrase, Text::StartsWith("HeLLo")->IgnoreCase); + Assert::That(phrase, Text::DoesNotStartWith("HI")->IgnoreCase); + Assert::That(greetings, Text::All->StartsWith("h")->IgnoreCase); + + // Inherited syntax + Expect(phrase, StartsWith("Hello")); + // Only available using new syntax + Expect(phrase, Not->StartsWith("Hi!")); + Expect(phrase, StartsWith("HeLLo")->IgnoreCase); + Expect(phrase, Not->StartsWith("HI")->IgnoreCase); + Expect(greetings, All->StartsWith("h")->IgnoreCase); + } + + [Test] + void EndsWithTests() + { + String^ phrase = "Hello World!"; + array<String^>^ greetings = { "Hello!", "Hi!", "Hola!" }; + + // Classic Syntax + StringAssert::EndsWith("!", phrase); + + // Helper syntax + Assert::That(phrase, Text::EndsWith("!")); + // Only available using new syntax + Assert::That(phrase, Text::DoesNotEndWith("?")); + Assert::That(phrase, Text::EndsWith("WORLD!")->IgnoreCase); + Assert::That(greetings, Text::All->EndsWith("!")); + + // Inherited syntax + Expect(phrase, EndsWith("!")); + // Only available using new syntax + Expect(phrase, Not->EndsWith("?")); + Expect(phrase, EndsWith("WORLD!")->IgnoreCase); + Expect(greetings, All->EndsWith("!") ); + } + + [Test] + void EqualIgnoringCaseTests() + { + String^ phrase = "Hello World!"; + + // Classic syntax + StringAssert::AreEqualIgnoringCase("hello world!",phrase); + + // Helper syntax + Assert::That(phrase, Is::EqualTo("hello world!")->IgnoreCase); + //Only available using new syntax + Assert::That(phrase, Is::Not->EqualTo("goodbye world!")->IgnoreCase); + Assert::That(gcnew array<String^> { "Hello", "World" }, + Is::EqualTo(gcnew array<Object^> { "HELLO", "WORLD" })->IgnoreCase); + Assert::That(gcnew array<String^> {"HELLO", "Hello", "hello" }, + Is::All->EqualTo( "hello" )->IgnoreCase); + + // Inherited syntax + Expect(phrase, EqualTo("hello world!")->IgnoreCase); + //Only available using new syntax + Expect(phrase, Not->EqualTo("goodbye world!")->IgnoreCase); + Expect(gcnew array<String^> { "Hello", "World" }, + EqualTo(gcnew array<Object^> { "HELLO", "WORLD" })->IgnoreCase); + Expect(gcnew array<String^> {"HELLO", "Hello", "hello" }, + All->EqualTo( "hello" )->IgnoreCase); + } + + [Test] + void RegularExpressionTests() + { + String^ phrase = "Now is the time for all good men to come to the aid of their country."; + array<String^>^ quotes = { "Never say never", "It's never too late", "Nevermore!" }; + + // Classic syntax + StringAssert::IsMatch( "all good men", phrase ); + StringAssert::IsMatch( "Now.*come", phrase ); + + // Helper syntax + Assert::That( phrase, Text::Matches( "all good men" ) ); + Assert::That( phrase, Text::Matches( "Now.*come" ) ); + // Only available using new syntax + Assert::That(phrase, Text::DoesNotMatch("all.*men.*good")); + Assert::That(phrase, Text::Matches("ALL")->IgnoreCase); + Assert::That(quotes, Text::All->Matches("never")->IgnoreCase); + + // Inherited syntax + Expect( phrase, Matches( "all good men" ) ); + Expect( phrase, Matches( "Now.*come" ) ); + // Only available using new syntax + Expect(phrase, Not->Matches("all.*men.*good")); + Expect(phrase, Matches("ALL")->IgnoreCase); + Expect(quotes, All->Matches("never")->IgnoreCase); + } + + [Test] + void EqualityTests() + { + array<int>^ i3 = { 1, 2, 3 }; + array<double>^ d3 = { 1.0, 2.0, 3.0 }; + array<int>^ iunequal = { 1, 3, 2 }; + + // Classic Syntax + Assert::AreEqual(4, 2 + 2); + Assert::AreEqual(i3, d3); + Assert::AreNotEqual(5, 2 + 2); + Assert::AreNotEqual(i3, iunequal); + + // Helper syntax + Assert::That(2 + 2, Is::EqualTo(4)); + Assert::That(2 + 2 == 4); + Assert::That(i3, Is::EqualTo(d3)); + Assert::That(2 + 2, Is::Not->EqualTo(5)); + Assert::That(i3, Is::Not->EqualTo(iunequal)); + + // Inherited syntax + Expect(2 + 2, EqualTo(4)); + Expect(2 + 2 == 4); + Expect(i3, EqualTo(d3)); + Expect(2 + 2, Not->EqualTo(5)); + Expect(i3, Not->EqualTo(iunequal)); + } + + [Test] + void EqualityTestsWithTolerance() + { + // CLassic syntax + Assert::AreEqual(5.0, 4.99, 0.05); + Assert::AreEqual(5.0F, 4.99F, 0.05F); + + // Helper syntax + Assert::That(4.99L, Is::EqualTo(5.0L)->Within(0.05L)); + Assert::That(4.99f, Is::EqualTo(5.0f)->Within(0.05f)); + + // Inherited syntax + Expect(4.99L, EqualTo(5.0L)->Within(0.05L)); + Expect(4.99f, EqualTo(5.0f)->Within(0.05f)); + } + + [Test] + void ComparisonTests() + { + // Classic Syntax + Assert::Greater(7, 3); + Assert::GreaterOrEqual(7, 3); + Assert::GreaterOrEqual(7, 7); + + // Helper syntax + Assert::That(7, Is::GreaterThan(3)); + Assert::That(7, Is::GreaterThanOrEqualTo(3)); + Assert::That(7, Is::AtLeast(3)); + Assert::That(7, Is::GreaterThanOrEqualTo(7)); + Assert::That(7, Is::AtLeast(7)); + + // Inherited syntax + Expect(7, GreaterThan(3)); + Expect(7, GreaterThanOrEqualTo(3)); + Expect(7, AtLeast(3)); + Expect(7, GreaterThanOrEqualTo(7)); + Expect(7, AtLeast(7)); + + // Classic syntax + Assert::Less(3, 7); + Assert::LessOrEqual(3, 7); + Assert::LessOrEqual(3, 3); + + // Helper syntax + Assert::That(3, Is::LessThan(7)); + Assert::That(3, Is::LessThanOrEqualTo(7)); + Assert::That(3, Is::AtMost(7)); + Assert::That(3, Is::LessThanOrEqualTo(3)); + Assert::That(3, Is::AtMost(3)); + + // Inherited syntax + Expect(3, LessThan(7)); + Expect(3, LessThanOrEqualTo(7)); + Expect(3, AtMost(7)); + Expect(3, LessThanOrEqualTo(3)); + Expect(3, AtMost(3)); + } + + [Test] + void AllItemsTests() + { + array<Object^>^ ints = { 1, 2, 3, 4 }; + array<Object^>^ strings = { "abc", "bad", "cab", "bad", "dad" }; + + // Classic syntax + CollectionAssert::AllItemsAreNotNull(ints); + CollectionAssert::AllItemsAreInstancesOfType(ints, int::typeid); + CollectionAssert::AllItemsAreInstancesOfType(strings, String::typeid); + CollectionAssert::AllItemsAreUnique(ints); + + // Helper syntax + Assert::That(ints, Is::All->Not->Null); + Assert::That(ints, Is::All->InstanceOfType(int::typeid)); + Assert::That(strings, Is::All->InstanceOfType(String::typeid)); + Assert::That(ints, Is::Unique); + // Only available using new syntax + Assert::That(strings, Is::Not->Unique); + Assert::That(ints, Is::All->GreaterThan(0)); + Assert::That(strings, Text::All->Contains( "a" ) ); + Assert::That(strings, Has::Some->StartsWith( "ba" ) ); + + // Inherited syntax + Expect(ints, All->Not->Null); + Expect(ints, All->InstanceOfType(int::typeid)); + Expect(strings, All->InstanceOfType(String::typeid)); + Expect(ints, Unique); + // Only available using new syntax + Expect(strings, Not->Unique); + Expect(ints, All->GreaterThan(0)); + Expect(strings, All->Contains( "a" ) ); + Expect(strings, Some->StartsWith( "ba" ) ); + } + + [Test] + void SomeItemsTests() + { + array<Object^>^ mixed = { 1, 2, "3", nullptr, "four", 100 }; + array<Object^>^ strings = { "abc", "bad", "cab", "bad", "dad" }; + + // Not available using the classic syntax + + // Helper syntax + Assert::That(mixed, Has::Some->Null); + Assert::That(mixed, Has::Some->InstanceOfType(int::typeid)); + Assert::That(mixed, Has::Some->InstanceOfType(String::typeid)); + Assert::That(strings, Has::Some->StartsWith( "ba" ) ); + Assert::That(strings, Has::Some->Not->StartsWith( "ba" ) ); + + // Inherited syntax + Expect(mixed, Some->Null); + Expect(mixed, Some->InstanceOfType(int::typeid)); + Expect(mixed, Some->InstanceOfType(String::typeid)); + Expect(strings, Some->StartsWith( "ba" ) ); + Expect(strings, Some->Not->StartsWith( "ba" ) ); + } + + [Test] + void NoItemsTests() + { + array<Object^>^ ints = { 1, 2, 3, 4, 5 }; + array<Object^>^ strings = { "abc", "bad", "cab", "bad", "dad" }; + + // Not available using the classic syntax + + // Helper syntax + Assert::That(ints, Has::None->Null); + Assert::That(ints, Has::None->InstanceOfType(String::typeid)); + Assert::That(ints, Has::None->GreaterThan(99)); + Assert::That(strings, Has::None->StartsWith( "qu" ) ); + + // Inherited syntax + Expect(ints, None->Null); + Expect(ints, None->InstanceOfType(String::typeid)); + Expect(ints, None->GreaterThan(99)); + Expect(strings, None->StartsWith( "qu" ) ); + } + + [Test] + void CollectionContainsTests() + { + array<int>^ iarray = { 1, 2, 3 }; + array<String^>^ sarray = { "a", "b", "c" }; + + // Classic syntax + Assert::Contains(3, iarray); + Assert::Contains("b", sarray); + CollectionAssert::Contains(iarray, 3); + CollectionAssert::Contains(sarray, "b"); + CollectionAssert::DoesNotContain(sarray, "x"); + + // Helper syntax + Assert::That(iarray, Has::Member(3)); + Assert::That(sarray, Has::Member("b")); + Assert::That(sarray, Has::No->Member("x")); // Yuck! + Assert::That(sarray, !Has::Member("x")); + + // Inherited syntax + Expect(iarray, Contains(3)); + Expect(sarray, Contains("b")); + Expect(sarray, Not->Contains("x")); + Expect(sarray, !Contains("x")); + } + + [Test] + void CollectionEquivalenceTests() + { + array<int>^ ints1to5 = { 1, 2, 3, 4, 5 }; + + // Classic syntax + CollectionAssert::AreEquivalent(gcnew array<int> { 2, 1, 4, 3, 5 }, ints1to5); + CollectionAssert::AreNotEquivalent(gcnew array<int> { 2, 2, 4, 3, 5 }, ints1to5); + CollectionAssert::AreNotEquivalent(gcnew array<int> { 2, 4, 3, 5 }, ints1to5); + CollectionAssert::AreNotEquivalent(gcnew array<int> { 2, 2, 1, 1, 4, 3, 5 }, ints1to5); + + // Helper syntax + Assert::That(gcnew array<int> { 2, 1, 4, 3, 5 }, Is::EquivalentTo(ints1to5)); + Assert::That(gcnew array<int> { 2, 2, 4, 3, 5 }, Is::Not->EquivalentTo(ints1to5)); + Assert::That(gcnew array<int> { 2, 4, 3, 5 }, Is::Not->EquivalentTo(ints1to5)); + Assert::That(gcnew array<int> { 2, 2, 1, 1, 4, 3, 5 }, Is::Not->EquivalentTo(ints1to5)); + + // Inherited syntax + Expect(gcnew array<int> { 2, 1, 4, 3, 5 }, EquivalentTo(ints1to5)); + Expect(gcnew array<int> { 2, 2, 4, 3, 5 }, Not->EquivalentTo(ints1to5)); + Expect(gcnew array<int> { 2, 4, 3, 5 }, Not->EquivalentTo(ints1to5)); + Expect(gcnew array<int> { 2, 2, 1, 1, 4, 3, 5 }, Not->EquivalentTo(ints1to5)); + } + + [Test] + void SubsetTests() + { + array<int>^ ints1to5 = { 1, 2, 3, 4, 5 }; + + // Classic syntax + CollectionAssert::IsSubsetOf(gcnew array<int> { 1, 3, 5 }, ints1to5); + CollectionAssert::IsSubsetOf(gcnew array<int> { 1, 2, 3, 4, 5 }, ints1to5); + CollectionAssert::IsNotSubsetOf(gcnew array<int> { 2, 4, 6 }, ints1to5); + CollectionAssert::IsNotSubsetOf(gcnew array<int> { 1, 2, 2, 2, 5 }, ints1to5); + + // Helper syntax + Assert::That(gcnew array<int> { 1, 3, 5 }, Is::SubsetOf(ints1to5)); + Assert::That(gcnew array<int> { 1, 2, 3, 4, 5 }, Is::SubsetOf(ints1to5)); + Assert::That(gcnew array<int> { 2, 4, 6 }, Is::Not->SubsetOf(ints1to5)); + Assert::That(gcnew array<int> { 1, 2, 2, 2, 5 }, Is::Not->SubsetOf(ints1to5)); + + // Inherited syntax + Expect(gcnew array<int> { 1, 3, 5 }, SubsetOf(ints1to5)); + Expect(gcnew array<int> { 1, 2, 3, 4, 5 }, SubsetOf(ints1to5)); + Expect(gcnew array<int> { 2, 4, 6 }, Not->SubsetOf(ints1to5)); + Expect(gcnew array<int> { 1, 2, 2, 2, 5 }, Not->SubsetOf(ints1to5)); + } + + [Test] + void PropertyTests() + { + array<String^>^ strings = { "abc", "bca", "xyz" }; + + // Helper syntax + Assert::That( "Hello", Has::Property("Length")->EqualTo(5) ); + Assert::That( "Hello", Has::Length->EqualTo( 5 ) ); + Assert::That( strings , Has::All->Property( "Length")->EqualTo(3) ); + Assert::That( strings, Has::All->Length->EqualTo( 3 ) ); + + // Inherited syntax + Expect( "Hello", Property("Length")->EqualTo(5) ); + Expect( "Hello", Length->EqualTo( 5 ) ); + Expect( strings, All->Property("Length")->EqualTo(3) ); + Expect( strings, All->Length->EqualTo( 3 ) ); + } + + [Test] + void NotTests() + { + // Not available using the classic syntax + + // Helper syntax + Assert::That(42, Is::Not->Null); + Assert::That(42, Is::Not->True); + Assert::That(42, Is::Not->False); + Assert::That(2.5, Is::Not->NaN); + Assert::That(2 + 2, Is::Not->EqualTo(3)); + Assert::That(2 + 2, Is::Not->Not->EqualTo(4)); + Assert::That(2 + 2, Is::Not->Not->Not->EqualTo(5)); + + // Inherited syntax + Expect(42, Not->Null); + Expect(42, Not->True); + Expect(42, Not->False); + Expect(2.5, Not->NaN); + Expect(2 + 2, Not->EqualTo(3)); + Expect(2 + 2, Not->Not->EqualTo(4)); + Expect(2 + 2, Not->Not->Not->EqualTo(5)); + } + + [Test] + void NotOperator() + { + // The ! operator is only available in the new syntax + Assert::That(42, !Is::Null); + // Inherited syntax + Expect( 42, !Null ); + } + + [Test] + void AndOperator() + { + // The & operator is only available in the new syntax + Assert::That(7, Is::GreaterThan(5) & Is::LessThan(10)); + // Inherited syntax + Expect( 7, GreaterThan(5) & LessThan(10)); + } + + [Test] + void OrOperator() + { + // The | operator is only available in the new syntax + Assert::That(3, Is::LessThan(5) | Is::GreaterThan(10)); + Expect( 3, LessThan(5) | GreaterThan(10)); + } + + [Test] + void ComplexTests() + { + Assert::That(7, Is::Not->Null & Is::Not->LessThan(5) & Is::Not->GreaterThan(10)); + Expect(7, Not->Null & Not->LessThan(5) & Not->GreaterThan(10)); + + Assert::That(7, !Is::Null & !Is::LessThan(5) & !Is::GreaterThan(10)); + Expect(7, !Null & !LessThan(5) & !GreaterThan(10)); + } + + // This method contains assertions that should not compile + // You can check by uncommenting it. + //void WillNotCompile() + //{ + // Assert::That(42, Is::Not); + // Assert::That(42, Is::All); + // Assert::That(42, Is::Null->Not); + // Assert::That(42, Is::Not->Null->GreaterThan(10)); + // Assert::That(42, Is::GreaterThan(10)->LessThan(99)); + + // object[] c = new object[0]; + // Assert::That(c, Is::Null->All); + // Assert::That(c, Is::Not->All); + // Assert::That(c, Is::All->Not); + //} + }; +}
\ No newline at end of file diff --git a/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.vcproj b/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.vcproj new file mode 100644 index 0000000..ff1efe8 --- /dev/null +++ b/tools/NUnit/samples/cpp/cpp-cli/syntax/cpp-cli-syntax.vcproj @@ -0,0 +1,200 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="cpp-cli-syntax" + ProjectGUID="{72448C2D-17C9-419E-B28D-3B533E7E0CD5}" + RootNamespace="cppclisyntax" + Keyword="ManagedCProj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + ManagedExtensions="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG" + RuntimeLibrary="3" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(NoInherit)" + LinkIncremental="2" + GenerateDebugInformation="true" + AssemblyDebug="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + ManagedExtensions="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG" + RuntimeLibrary="2" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="$(NoInherit)" + LinkIncremental="1" + GenerateDebugInformation="true" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + <AssemblyReference + RelativePath="System.dll" + AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" + /> + <AssemblyReference + RelativePath="..\..\..\..\solutions\vs2005\NUnitFramework\framework\bin\Debug\nunit.framework.dll" + AssemblyName="nunit.framework, Version=2.5.0.0, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" + /> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\cpp-cli-syntax.cpp" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> |