簡體   English   中英

Visual Studio 2012中的Google Test

[英]Google Test in Visual Studio 2012

我正在嘗試開始進行單元測試。 我下載了最新版本的gtest,並將其解壓縮到A:\\gtest根據指定的說明,我打開了gtest.sln。 如果我同意更新它,Visual Studio只允許我打開sln。 然后,當我嘗試構建時,我遇到了一堆錯誤:

1>------ Build started: Project: gtest, Configuration: Debug Win32 ------
1>  gtest-all.cc
1>a:\gtest\include\gtest\gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\gtest-printers.h(558): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4249) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4019): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Iterator' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4505) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4258): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Iterator' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4766) : see reference to class template instantiation 'testing::internal::CartesianProductHolder9<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2977: 'std::tuple' : too many template arguments
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4813) : see reference to class template instantiation 'testing::internal::CartesianProductHolder10<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9,Generator10>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2955: 'std::tuple' : use of class template requires template argument list
1>          b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我做錯了什么還是VS2012的問題? 我不依賴谷歌測試,並不反對使用不同的框架,如果它與VS更好地工作,我剛剛聽到關於gtest的非常好的事情。

VC ++ 2012不支持(也絕不會)支持可變參數模板; 因此,它的標准庫實現嘗試使用預處理器生成的重載和特化來偽造它們。 正如這篇博客文章指出的那樣,虛假的可變參數模板參數的數量默認為5 - 問題是gtest試圖使用多達10個模板參數來實例化std::tuple<>

正如博客文章所提到的,您可以在項目范圍內定義_VARIADIC_MAX宏以支持最多10個參數; 您可能希望通過項目的預處理程序定義設置來執行此操作,但重要的是確保每個TU在包含任何stdlib標頭(直接或間接)之前定義它。

我沒有使用_VARIADIC_MAX宏修改VS2012元組實現,而是通過在gtest項目和項目(包括gtest頭文件)上定義以下兩個宏來解決這個問題:

GTEST_HAS_TR1_TUPLE=0
GTEST_USE_OWN_TR1_TUPLE=1

GTEST_HAS_TR1_TUPLE設置為0可防止gtest嘗試使用STL頭中的元組類,並將GTEST_USE_OWN_TR1_TUPLE設置為1指示gtest使用其自己的元組實現,而不是省略需要元組支持的功能。 我個人更喜歡這個選項來調整STL實現,這個解決方案應該適用於任何其他有類似問題的編譯器。

這在版本r675中得到修復。 請參閱https://code.google.com/p/googletest/source/detail?r=675

此外,在獲得最新版本之前,請將GTEST_USE_OWN_TR1_TUPLE=0添加到預處理器定義中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM