2017-05-03 15 views
0

何らかの理由で、GTestが私の開発ステーションでうまく動作していません。いくつかのASSERT/EXPECTテストは動作していますが、文字列を動作させるために比較することはできません。これは、コードがCLionでどのように見えるかです。エラーポップオーバーに気づく:また、下部に取り付けたWindows GTest EXPECT_STREQ:エラー: 'CmpHelperSTREQ'への呼び出しに一致する関数がありません

enter image description here

は、コンパイル時にエラーが出力されます。私はWindows 10でJetBrains CLionを使用しているので、GTestは "MinGW Makefiles" CMakeジェネレータとMinGW make(CMakeのデフォルトのVisual Studioジェネレータではなく)で構築する必要があります。さらに、私が見つけることができる唯一の作業のソースは、最新のGithub GTestマスターブランチでした。 2016年11月の最新リリースはMinGWのWindows上に構築されません。

In file included from C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1874:0, 
       from C:\projects\gtest-test\tests\basic_test.cpp:4: 
C:\projects\gtest-test\tests\basic_test.cpp: In member function 'virtual void basic_test_helloWorldEqualsHelloWorld_Test::TestBody()': 
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:147:45: error: no matching function for call to 'CmpHelperSTREQ(const char [7], const char [7], std::__cxx11::string&, std::__cxx11::string&)' 
    GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \ 
              ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro 'GTEST_ASSERT_' 
    if (const ::testing::AssertionResult gtest_ar = (expression)) \ 
                ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:162:3: note: in expansion of macro 'GTEST_PRED_FORMAT2_' 
    GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_) 
^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1996:3: note: in expansion of macro 'EXPECT_PRED_FORMAT2' 
    EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) 
^
C:\projects\gtest-test\tests\basic_test.cpp:14:5: note: in expansion of macro 'EXPECT_STREQ' 
    EXPECT_STREQ(hello2, hello3); 
    ^
In file included from C:\projects\gtest-test\tests\basic_test.cpp:4:0: 
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1537:28: note: candidate: testing::AssertionResult testing::internal::CmpHelperSTREQ(const char*, const char*, const char*, const char*) 
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, 
          ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1537:28: note: no known conversion for argument 3 from 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'const char*' 
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1570:28: note: candidate: testing::AssertionResult testing::internal::CmpHelperSTREQ(const char*, const char*, const wchar_t*, const wchar_t*) 
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, 
          ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1570:28: note: no known conversion for argument 3 from 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'const wchar_t*' 
tests\CMakeFiles\gtestTest_tests.dir\build.make:62: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/basic_test.cpp.obj' failed 
mingw32-make.exe[3]: *** [tests/CMakeFiles/gtestTest_tests.dir/basic_test.cpp.obj] Error 1 
mingw32-make.exe[2]: *** [tests/CMakeFiles/gtestTest_tests.dir/all] Error 2 
CMakeFiles\Makefile2:1063: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/all' failed 
mingw32-make.exe[1]: *** [tests/CMakeFiles/gtestTest_tests.dir/rule] Error 2 
CMakeFiles\Makefile2:1075: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/rule' failed 
Makefile:494: recipe for target 'gtestTest_tests' failed 
mingw32-make.exe: *** [gtestTest_tests] Error 2 

答えて

4

あなたは、生のCの文字列(char*)を比較する際には使用されるべきとき、2つのstd::string Sを比較するEXPECT_STREQを使用するようにしてください。その上でGoogleのテスト入門セクションがあります

std::string sのあなたがEXPECT_EQを使用する必要がありますを比較するためにhttps://github.com/google/googletest/blob/master/googletest/docs/Primer.md#string-comparison

+0

私はGoogleのテスト入門を読んでも、彼らの使用例を見てEXPECT_STREQをgoogletestコードベースで使用し、間違った考えを得ました。それをクリアしていただきありがとうございます。 –

0

プロジェクトでは、Googleテストのネストされたソースツリーを https://github.com/google/googletest.git から使用してください。例えば

、プロジェクトフォルダがCの場合:\プロジェクト\ GTESTテスト\テストgoogletestサブフォルダに クローンGT(C:\プロジェクト\ GTESTテスト\テスト googletest \)シェルコールgitクローンhttps://github.com/google/googletest.git C:¥projects¥gtest-test¥testsディレクトリです。

CであなたのCMakeLists.txt:\プロジェクト\ GTESTテスト\テストはこのようにする必要があります

CMAKE_MINIMUM_REQUIRED(VERSION 3.3) 
PROJECT(TestGoogleTargets) 

add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1 -DGTEST_HAS_TR1_TUPLE=1) 
IF (APPLE) 
    add_definitions(-D__GLIBCXX__) 
ENDIF (APPLE) 

add_subdirectory(googletest) 

INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include) 
INCLUDE_DIRECTORIES(${gmock_SOURCE_DIR}/include) 

ADD_EXECUTABLE(TestWithGMockMain dummyMock.cc) 
TARGET_LINK_LIBRARIES(TestWithGMockMain gmock_main) 

ADD_EXECUTABLE(TestWithGMock dummyMockWithMain.cc) 
TARGET_LINK_LIBRARIES(TestWithGMock gmock) 

ADD_EXECUTABLE(TestWithGTestMain dummy.cc) 
TARGET_LINK_LIBRARIES(TestWithGTestMain gtest_main) 

ADD_EXECUTABLE(TestWithGTest dummyWithMain.cc) 
TARGET_LINK_LIBRARIES(TestWithGTest gtest) 
+0

ありがとう、うた - 私はこれについて考えます。実際に私のライブラリはシステムディレクトリにインストールされており、ハムは find_package(GTest REQUIRED) include_directories($ {GTEST_INCLUDE_DIRS})を使って取得しています。 –

関連する問題