Add test for ErrorMessageBuffer

This commit is contained in:
Kenneth Moreland 2014-06-10 11:21:55 -06:00
parent b692cb3d89
commit 3ed7093945
3 changed files with 85 additions and 1 deletions

@ -25,4 +25,4 @@ set(headers
vtkm_declare_headers(${headers})
#add_subdirectory(test)
add_subdirectory(testing)

@ -0,0 +1,26 @@
##=============================================================================
##
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
##
## 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.
##
## Copyright 2014 Sandia Corporation.
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014. Los Alamos National Security
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##
##=============================================================================
set(unit_tests
UnitTestErrorMessageBuffer.cxx
)
vtkm_unit_tests(SOURCES ${unit_tests})

@ -0,0 +1,58 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. Los Alamos National Security
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
#include <vtkm/testing/Testing.h>
#include <cstring>
namespace {
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.");
VTKM_TEST_ASSERT(strcmp(messageBuffer, "Hello World") == 0,
"Did not record error message.");
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.");
VTKM_TEST_ASSERT(strcmp(messageBuffer, "Hello Wo") == 0,
"Did not record error message.");
}
} // anonymous namespace
int UnitTestErrorMessageBuffer(int, char *[])
{
return (vtkm::testing::Testing::Run(TestErrorMessageBuffer));
}