vtk-m/vtkm/exec/testing/UnitTestErrorMessageBuffer.cxx

48 lines
1.7 KiB
C++
Raw Normal View History

2014-06-10 17:21:55 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2014-06-10 17:21:55 +00:00
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
#include <cstring>
2017-05-18 14:51:24 +00:00
#include <vtkm/testing/Testing.h>
2014-06-10 17:21:55 +00:00
2017-05-18 14:29:41 +00:00
namespace
{
2014-06-10 17:21:55 +00:00
void TestErrorMessageBuffer()
{
char messageBuffer[100];
std::cout << "Testing buffer large enough for message." << std::endl;
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer largeBuffer(messageBuffer, 100);
VTKM_TEST_ASSERT(!largeBuffer.IsErrorRaised(), "Message created with error.");
largeBuffer.RaiseError("Hello World");
VTKM_TEST_ASSERT(largeBuffer.IsErrorRaised(), "Error not reported.");
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(strcmp(messageBuffer, "Hello World") == 0, "Did not record error message.");
2014-06-10 17:21:55 +00:00
std::cout << "Testing truncated error message." << std::endl;
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer smallBuffer(messageBuffer, 9);
VTKM_TEST_ASSERT(!smallBuffer.IsErrorRaised(), "Message created with error.");
smallBuffer.RaiseError("Hello World");
VTKM_TEST_ASSERT(smallBuffer.IsErrorRaised(), "Error not reported.");
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(strcmp(messageBuffer, "Hello Wo") == 0, "Did not record error message.");
2014-06-10 17:21:55 +00:00
}
} // anonymous namespace
int UnitTestErrorMessageBuffer(int argc, char* argv[])
2014-06-10 17:21:55 +00:00
{
return vtkm::testing::Testing::Run(TestErrorMessageBuffer, argc, argv);
2014-06-10 17:21:55 +00:00
}