errors-testhelper.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*############################################################################
  2. # Copyright 2016-2017 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /*!
  17. * \file
  18. * \brief Error handling C++ wrapper interface.
  19. */
  20. #ifndef EPID_COMMON_TESTHELPER_ERRORS_TESTHELPER_H_
  21. #define EPID_COMMON_TESTHELPER_ERRORS_TESTHELPER_H_
  22. #include <cstdio>
  23. #include <initializer_list>
  24. #include <stdexcept>
  25. #include <string>
  26. #include <vector>
  27. extern "C" {
  28. #include "epid/common/math/bignum.h"
  29. }
  30. /// Macro used to indicate fatal error during unit test run
  31. #define THROW_ON_EPIDERR(actual) \
  32. if (kEpidNoErr != actual) { \
  33. printf("%s(%d): error: %s\n", __FILE__, __LINE__, "test defect"); \
  34. throw std::logic_error(std::string("Failed to call: ") + #actual); \
  35. }
  36. /// Macro used to indicate fatal error during unit test run
  37. #define THROW_NE(expected, actual) \
  38. if (expected != actual) { \
  39. printf("%s(%d): error: %s\n", __FILE__, __LINE__, "test defect"); \
  40. throw std::logic_error(std::string("Failed to call: ") + #actual); \
  41. }
  42. #endif // EPID_COMMON_TESTHELPER_ERRORS_TESTHELPER_H_