1
我正在使用Google測試和Google Mock來處理我的C++/Qt應用程序。我一直有這個設置了巨大的成功,直到剛纔,當我嘗試這樣做:Google Mock在嘗試指定返回值時給出編譯錯誤
QList<AbstractSurface::VertexRow> rowList;
for (unsigned i = 0; i < rows; ++i)
{
AbstractSurface::VertexRow curRow(new AbstractSurface::Vertex[cols]);
for (unsigned j = 0; j < cols; ++j)
{
curRow[j] = AbstractSurface::Vertex();
}
rowList.append(curRow);
}
ON_CALL(surface, numRows_impl()).WillByDefault(Return(rows));
ON_CALL(surface, numColumns_impl()).WillByDefault(Return(cols));
ON_CALL(surface, popAllRows_impl()).WillOnce(Return(rowList));
/* ... */
試圖編譯這將導致以下錯誤消息從GCC:
../../3DWaveSurface/test/TestWaterfallPresenter.cc: In member function ‘virtual void<unnamed>::WaterfallPresenterTest_CallingPaintGLCallsPaintRowForEachRowInSurface_Test::TestBody()’:
../../3DWaveSurface/test/TestWaterfallPresenter.cc:140:41: error: ‘class testing::internal::OnCallSpec<QList<boost::shared_array<AbstractSurface::Vertex> >()>’ has no member named ‘WillOnce’
如果有幫助,VertexRow
是typedef
,對於boost::shared_array<Vertex>
和Vertex
是帶有有效的空構造函數的struct
。
這是我寫的測試錯誤還是與使用QList
或shared_array
有些不兼容?
SOLUTION 以下VJo的建議後,我的測試編譯和運行,但隨後崩潰:
Stack trace:
: Failure
Uninteresting mock function call - returning default value.
Function call: popAllRows_impl()
The mock function has no default action set, and its return type has no default value set.
The process "/home/corey/development/3DWaveSurface-build-desktop-debug/test/test" crashed.
因爲沒有爲popAllRows_impl()
沒有默認的回報。我加了默認:
ON_CALL(surface, popAllRows_impl()).WillByDefault(Return(QList<AbstractSurface::VertexRow>()));
要我SetUp()
,一切都很好。作爲VJo指出,沒有爲ON_CALL
WillOnce()但對於EXPECT_CALL
,我錯過了這個烹調手冊..
這實際上工作(有一個額外的我做了我的設置)。將在原始問題中發佈完整解決方案。 –