mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
Catching and resolving the exception thrown when accessing an empty string from an ostrstream (MemoryOutStream GetString would throw if the stream was empty).
Moving the exception disable to the test file instead of the main file so the workaround is located where it is needed. All tests pass!!!
This commit is contained in:
parent
bcf039ecce
commit
c5aa621e64
4 changed files with 17 additions and 11 deletions
|
|
@ -6,14 +6,19 @@ namespace UnitTest {
|
|||
|
||||
char const* MemoryOutStream::GetText() const
|
||||
{
|
||||
m_text = this->str();
|
||||
try
|
||||
{
|
||||
m_text = this->str();
|
||||
}
|
||||
catch (...) { m_text = ""; }
|
||||
|
||||
return m_text.c_str();
|
||||
}
|
||||
|
||||
void MemoryOutStream::Clear()
|
||||
{
|
||||
this->str(std::string());
|
||||
m_text = this->str();
|
||||
m_text = std::string();
|
||||
}
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
#include "UnitTest++/UnitTestPP.h"
|
||||
#ifdef __BORLANDC__
|
||||
#include <vcl.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
int main(int, char const *[])
|
||||
{
|
||||
#ifdef __BORLANDC__
|
||||
// This is to allow the check test to pass when using Nan (invalid float numbers), otherwise, they throw an exception
|
||||
// and the test fails (CheckCloseWithNaNFails and CheckCloseWithNaNAgainstItselfFails)
|
||||
_control87(MCW_EM, MCW_EM);
|
||||
#endif
|
||||
return UnitTest::RunAllTests();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <cstring>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
using namespace UnitTest;
|
||||
|
||||
|
||||
|
|
@ -148,6 +153,11 @@ namespace {
|
|||
|
||||
TEST(CheckCloseWithNaNFails)
|
||||
{
|
||||
#ifdef __BORLANDC__
|
||||
// This is to allow the check test to pass when using Nan (invalid float numbers), otherwise, they throw an exception
|
||||
// and the test fails (CheckCloseWithNaNFails and CheckCloseWithNaNAgainstItselfFails)
|
||||
_control87(MCW_EM, MCW_EM);
|
||||
#endif
|
||||
const unsigned int bitpattern = 0xFFFFFFFF;
|
||||
float nan;
|
||||
UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern));
|
||||
|
|
|
|||
|
|
@ -257,7 +257,6 @@ namespace {
|
|||
CHECK_EQUAL("53124", stream.GetText());
|
||||
}
|
||||
|
||||
#ifndef __BORLANDC__
|
||||
// Not sure why but this test fails with the Borland C++ 5.5 compiler.
|
||||
// It throws an unhandled exception:
|
||||
// unexpected NULL pointer in function: basic_string( const charT*,size_type,const Allocator&)
|
||||
|
|
@ -268,7 +267,6 @@ namespace {
|
|||
stream.Clear();
|
||||
CHECK_EQUAL("", stream.GetText());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue