Status::Status(ValueType err, ErrorType type)
: m_code(err), m_type(type), m_string() {}
+// This logic is confusing because c++ calls the traditional (posix) errno codes
+// "generic errors", while we use the term "generic" to mean completely
+// arbitrary (text-based) errors.
Status::Status(std::error_code EC)
- : m_code(EC.value()), m_type(ErrorType::eErrorTypeGeneric),
+ : m_code(EC.value()),
+ m_type(EC.category() == std::generic_category() ? eErrorTypePOSIX
+ : eErrorTypeGeneric),
m_string(EC.message()) {}
Status::Status(const char *format, ...)
EXPECT_TRUE(foo.Success());
}
+TEST(StatusTest, ErrorCodeConstructor) {
+ EXPECT_TRUE(Status(std::error_code()).Success());
+
+ Status eagain = std::error_code(EAGAIN, std::generic_category());
+ EXPECT_TRUE(eagain.Fail());
+ EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
+ EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
+}
+
TEST(StatusTest, ErrorConversion) {
EXPECT_FALSE(bool(Status().ToError()));