刚刚下载了https://qt.gitorious.org/~niandong/qt/niandongs-qttools/commits/qtmock,因为我迫切需要模拟 QNetworkAccessManager。
我能够使用 Qt 4.7.4 在 QtCreator 2.3.1 中构建 qtmock.pro。所有测试都按预期运行,我非常兴奋!
然后我必须使用 Visual Studio 构建它才能使用我的项目的库及其所有依赖项。我在 Visual Studio 2010 pro 中使用 Qt 4.8。我导入了主要的 qtmock.pro,首先我尝试构建仅包含框架的底层 qtmock 项目(没有测试或任何东西)。它构建得很好,我得到了一个 .lib 和 .dll 文件。然后我尝试构建 qtnetworkstub.pro,其中 QNetwork 的所有模拟对象都是我的项目所需的。以下是我的构建命令行:
/OUT:"......\lib\qtnetworkmock.dll" /NOLOGO /LIBPATH:"E:\QT\4.8.0\lib" /LIBPATH:"e:\QT\4.8.0\lib" / LIBPATH:"../../../lib" /DLL "../../../lib\qtmock.lib" "E:\QT\4.8.0\lib\QtTestd4.lib" "E :\QT\4.8.0\lib\QtCored4.lib""kernel32.lib""user32.lib""gdi32.lib""winspool.lib""comdlg32.lib""advapi32.lib""shell32.lib"" ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Win32\qtnetworkmock.dll.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker ' uiAccess='false'" /DEBUG /PDB:"E:.Qt.UnitTest\qtmock\lib\qtnetworkmock.pdb" /PGD:"E:\src\Qt.UnitTest\qtmock\lib\qtnetworkmock.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
我只使用 testLib 和 Core。
然后我收到以下链接错误:
Error 4 error LNK2019: unresolved external symbol "public: static struct QMetaObject const QAbstractSocket::staticMetaObject" (?staticMetaObject@QAbstractSocket@@2UQMetaObject@@B) referenced in function "public: __thiscall QNetworkRequest::~QNetworkRequest(void)" (??1QNetworkRequest@@QAE@XZ) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkrequest.obj qtnetworkstub
Error 5 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QTcpSocket::staticMetaObject" (?staticMetaObject@QTcpSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkreply.obj qtnetworkstub
Error 6 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QTcpSocket::staticMetaObject" (?staticMetaObject@QTcpSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkrequest.obj qtnetworkstub
Error 7 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QSslSocket::staticMetaObject" (?staticMetaObject@QSslSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkreply.obj qtnetworkstub
Error 8 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QSslSocket::staticMetaObject" (?staticMetaObject@QSslSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkrequest.obj qtnetworkstub
Error 1 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QAbstractSocket::staticMetaObject" (?staticMetaObject@QAbstractSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkaccessmanager.obj qtnetworkstub
Error 2 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QAbstractSocket::staticMetaObject" (?staticMetaObject@QAbstractSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkproxy.obj qtnetworkstub
Error 3 error LNK2001: unresolved external symbol "public: static struct QMetaObject const QAbstractSocket::staticMetaObject" (?staticMetaObject@QAbstractSocket@@2UQMetaObject@@B) E:\src\Qt.UnitTest\qtmock\test\stublib\network\qnetworkreply.obj qtnetworkstub
Error 9 error LNK1120: 3 unresolved externals E:\src\Qt.UnitTest\qtmock\lib\\qtnetworkmock.dll qtnetworkstub
我没有得到的是:我没有使用任何这些对象,并且在该项目的任何地方都没有引用它们。它们都继承自 QIODevice,但我不太确定这有多大帮助。
我非常卡住,我会很感激任何帮助,因为我真的很想使用这个框架(它对于单元测试来说似乎真的很棒!)