regulators: Add toErrorType() utility function
Add a utility function to convert a PhaseFaultType value to the
corresponding ErrorType value.
The ErrorType enumeration is used by the ErrorHistory class.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Ia0e2c7789087f5782006fcb6c6ede0faedaf5e0b
diff --git a/phosphor-regulators/src/phase_fault.hpp b/phosphor-regulators/src/phase_fault.hpp
index fbcb255..18597c7 100644
--- a/phosphor-regulators/src/phase_fault.hpp
+++ b/phosphor-regulators/src/phase_fault.hpp
@@ -15,6 +15,8 @@
*/
#pragma once
+#include "error_history.hpp"
+
#include <string>
namespace phosphor::power::regulators
@@ -51,6 +53,29 @@
};
/**
+ * Returns the ErrorType that corresponds to the specified PhaseFaultType.
+ *
+ * The ErrorType enum is used with the ErrorHistory class.
+ *
+ * @param type phase fault type
+ * @return error type
+ */
+inline ErrorType toErrorType(PhaseFaultType type)
+{
+ ErrorType errorType;
+ switch (type)
+ {
+ case PhaseFaultType::n:
+ errorType = ErrorType::phaseFaultN;
+ break;
+ case PhaseFaultType::n_plus_1:
+ errorType = ErrorType::phaseFaultNPlus1;
+ break;
+ }
+ return errorType;
+}
+
+/**
* Returns the name of the specified PhaseFaultType.
*
* @param type phase fault type
diff --git a/phosphor-regulators/test/phase_fault_tests.cpp b/phosphor-regulators/test/phase_fault_tests.cpp
index 5c18add..bbe0003 100644
--- a/phosphor-regulators/test/phase_fault_tests.cpp
+++ b/phosphor-regulators/test/phase_fault_tests.cpp
@@ -13,12 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "error_history.hpp"
#include "phase_fault.hpp"
#include <gtest/gtest.h>
using namespace phosphor::power::regulators;
+TEST(PhaseFaultTests, ToErrorType)
+{
+ EXPECT_EQ(toErrorType(PhaseFaultType::n), ErrorType::phaseFaultN);
+ EXPECT_EQ(toErrorType(PhaseFaultType::n_plus_1),
+ ErrorType::phaseFaultNPlus1);
+}
+
TEST(PhaseFaultTests, ToString)
{
EXPECT_EQ(toString(PhaseFaultType::n), "n");