c++ - 如何将 C++ 枚举与 UnitTest++ 检查一起使用?

标签 c++ enums unittest++

我有以下枚举:

namespace Country {
    enum {
        ITALY = 1,
        SPAIN = 2
    };
}

以及以下 UnitTest++ 测试:

TEST(something) {
    CHECK_EQUAL(Country::SPAIN, object.getCountry(1)); // getCountry returns int
}

这行不通。我以为 Country::SPAIN 会自动转换为 int 2,但我得到了这个错误:

error: no matching function for call to ‘CheckEqual(UnitTest::TestResults&, Country::<anonymous enum>, int, UnitTest::TestDetails)’

最佳答案

自己将枚举转换为 int:

TEST(something) {
    CHECK_EQUAL(static_cast<int>(Country::SPAIN), object.getCountry(1));
}

关于c++ - 如何将 C++ 枚举与 UnitTest++ 检查一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5480190/

相关文章:

将一个类传递给另一个类的构造函数时,C++ 无默认构造函数错误

c++ - 井字游戏

c# - 拥有 "generic"枚举是不好的做法吗?

c++ - UnitTest++ 命令行参数

c++ - opencv估计RigidTransform : How to get global scale?

c++ - boost::program_options 卡在 ARM 上 "sometimes"

java - java代码有什么问题?

带枚举的 Hibernate 查找表

c++ - 单元测试++入门

c++ - 配置要包含在 C++ 测试中的库