mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
31 lines
645 B
C++
31 lines
645 B
C++
#include <iostream>
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "libimp/error.h"
|
|
#include "libimp/result.h"
|
|
#include "libimp/fmt.h"
|
|
|
|
namespace {
|
|
|
|
class custom_error_category : public imp::error_category {
|
|
public:
|
|
std::string message(imp::result_code r) const {
|
|
return !r ? "success" : "failure";
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST(error, error_code) {
|
|
imp::error_code ecode;
|
|
EXPECT_FALSE(ecode);
|
|
std::cout << ecode.message() << "\n";
|
|
EXPECT_EQ(ecode.message(), "[0, \"success\"]");
|
|
|
|
custom_error_category cec;
|
|
ecode = {123, cec};
|
|
EXPECT_TRUE(ecode);
|
|
std::cout << ecode.message() << "\n";
|
|
EXPECT_EQ(ecode.message(), cec.message(123));
|
|
} |