Re: Assert::IsNotNull or Assert::IsNull do not work for my C++ unit test
Greg Fleming <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <[email protected]> |
[email protected] wrote: > Below is the code snippet. I got "error C2665: > 'NUnit::Framework::Assert::IsNotNull' : none of the 3 overloads could > convert all the argument types ".What I did wrong? > > Histogram1D<T>* histoptr = new Histogram1D<T> (64); > Assert::IsNotNull(histo, "Test object."); > Assert::IsNull(histo, "Test object."); > "new" in C++ produces pointers on the unmanaged heap, whereas Assert::IsNull expects a managed reference, which is produced by gcnew. Try this (VS 2005; syntax will differ in VS 2003): System::Object^ myObj = gcnew System::Object(); System::Object^ nullObj = nullptr; Assert::IsNotNull( myObj, gcnew System::String( "this one should not be null" ) ); Assert::IsNull( nullObj, gcnew System::String( "this one should be null" ) ); Histogram1D<T>* histoptr = new Histogram1D<T> (64); char* p = null; Assert::IsFalse( null == histoptr, gcnew System::String( "new operator should nto return null" )); Assert::IsTrue( null == p ); ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/