2011-03-27 52 views
0

我有一個如下提升遞歸變體。當我使用assert比較兩個遞歸變體對象時,它可以正常工作,但是使用EXPECT_EQ時,會產生編譯錯誤。谷歌測試EXPECT_EQ和boost :: make_recursive_variant

typedef boost::make_recursive_variant<bool, boost::uint8_t, boost::uint32_t, 
    boost::int32_t, double, std::string, boost::uuids::uuid>::type rvariant_type; 

variant_type b1 = true; 
rvariant_type b2 = true; 

assert(b1 == b2); //work fine 

EXPECT_EQ(b1,b2); //gives compiler error. 
EXPECT_EQ(boost::get<bool>(b1), boost::get<bool>(b2)); //works fine 

升壓/ v1.46.1 /包括/升壓/變體/細節/ variant_io.hpp:64:錯誤:不對應的在「((常量升壓::詳細::變體 '運算符< <': :打印機>> *)this) - > boost :: detail :: variant :: printer >>:out_ < < operand'

回答

1

gtest大量使用流輸出,但似乎boost :: variant支持通過超載運營商進行打印< <非常有限,如果不是不存在的話。

看看這個:

#include <boost/variant.hpp> 
#include <boost/cstdint.hpp> 
#include <boost/uuid/uuid.hpp> 
#include <iostream> 
typedef boost::make_recursive_variant<bool, boost::uint8_t, boost::uint32_t, 
    boost::int32_t, double, std::string, boost::uuids::uuid>::type rvariant_type; 

int main() { 
    rvariant_type v1 = true; 
    std::cout << v1 << std::endl; 
    return 0; 
} 

這種很短的方案爲您提供從GTEST得到了相同的編譯錯誤。

這個補充是:

std::ostream& operator<<(std::ostream& out, const rvariant_type& p) { 
    return out << boost::get<bool>(p); 
} 

讓我測試的編譯,我就來看看,如果我可以讓你的工作,例如,以及。

更新:我剛剛編譯,並把上述操作< <後成功運行基於代碼的測試,所以缺乏操作< <的恰恰是什麼導致它。

+0

這是正確的。這裏也是谷歌測試組的回答。 http://groups.google.com/group/googletestframework/browse_thread/thread/ceed41f2942ffa49備用的是使用EXPECT_TRUE()。 – rjoshi 2011-03-28 11:54:13