From aa369974ea63b143444bac3d2f149119736c713c Mon Sep 17 00:00:00 2001 From: Ackerley Tng Date: Tue, 7 Jul 2020 21:17:51 +0800 Subject: [PATCH] Override << operator for better test error messages --- jwt_verify_lib/status.h | 8 ++++++++ src/status.cc | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/jwt_verify_lib/status.h b/jwt_verify_lib/status.h index 4b26d57..1c55570 100644 --- a/jwt_verify_lib/status.h +++ b/jwt_verify_lib/status.h @@ -209,6 +209,14 @@ enum class Status { JwksBioAllocError, }; +/** + * Overload << to output a Status to std::ostream + * @param os the std::ostream to write to + * @param status is the enum status. + * @return the std::ostream os + */ +std::ostream& operator<<(std::ostream& os, const Status& status); + /** * Convert enum status to string. * @param status is the enum status. diff --git a/src/status.cc b/src/status.cc index 3f7abb4..e96f186 100644 --- a/src/status.cc +++ b/src/status.cc @@ -15,6 +15,7 @@ #include "jwt_verify_lib/status.h" #include +#include namespace google { namespace jwt_verify { @@ -173,5 +174,12 @@ std::string getStatusString(Status status) { return ""; } +std::ostream& operator<<(std::ostream& os, const Status& status) { + return os << + "Status(" << + static_cast(status) << ", " << + getStatusString(status) << ")"; +} + } // namespace jwt_verify } // namespace google