如何在UnitTest ++检查中使用C ++枚举?

时间:2011-03-29 23:32:47

标签: 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)’

1 个答案:

答案 0 :(得分:1)

将枚举转换为int自己:

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