I'm able to run the Google tests setup in the official Jetbrains Clion guide using TEST_F
macros but I'm not able to setup the same environment for my project. The following is the test class I'm trying to run, everytime I refer to the ed1
instance I get a bunch of undefined reference
errors.
#include "gtest/gtest.h"
#include "../NetworkServer.h"
class SharedEditorTest : public ::testing::Test {
protected:
virtual void SetUp() {
ed1 = new SharedEditor(server);
/*ed1->getSymbols().push_back(Symbol(char('a'), std::string{"0_1"}, std::vector<int>{1}));
ed1->getSymbols().push_back(Symbol(char('n'), std::string{"0_2"}, std::vector<int>{2}));
ed1->getSymbols().push_back(Symbol(char('t'), std::string{"0_3"}, std::vector<int>{3}));
ed1->getSymbols().push_back(Symbol(char('o'), std::string{"0_4"}, std::vector<int>{4}));
ed1->getSymbols().push_back(Symbol(char('n'), std::string{"0_5"}, std::vector<int>{5}));
ed1->getSymbols().push_back(Symbol(char('i'), std::string{"0_6"}, std::vector<int>{6}));
ed1->getSymbols().push_back(Symbol(char('o'), std::string{"0_7"}, std::vector<int>{7}));
std::cout << "ed1: " << ed1->to_string() << std::endl;*/
}
virtual void TearDown() {
}
NetworkServer server;
SharedEditor* ed1{};
};
TEST_F(SharedEditorTest, TestName) {
std::cout << ed1->getCounter() << std::endl;
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Output
CMakeFiles\Google_Tests_run.dir/objects.a(SharedEditorTest.cpp.obj): In function `SharedEditorTest_TestName_Test::TestBody()':
D:/asant/workspace/CLionProjects/CRDTpp/Google_tests/SharedEditorTest.cpp:36: undefined reference to `SharedEditor::getCounter() const'
CMakeFiles\Google_Tests_run.dir/objects.a(SharedEditorTest.cpp.obj): In function `SharedEditorTest::SetUp()':
D:/asant/workspace/CLionProjects/CRDTpp/Google_tests/SharedEditorTest.cpp:14: undefined reference to `SharedEditor::SharedEditor(NetworkServer&)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Google_tests\CMakeFiles\Google_Tests_run.dir\build.make:89: Google_tests/Google_Tests_run.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:125: Google_tests/CMakeFiles/Google_Tests_run.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:132: Google_tests/CMakeFiles/Google_Tests_run.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:176: Google_Tests_run] Error 2
You can access the full project cloning this repo.
EDIT1:
CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(CRDTpp)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(Google_tests)
add_executable(CRDTpp "main.cpp" "Symbol.cpp" "Symbol.h" "NetworkServer.cpp" "NetworkServer.h" "SharedEditor.cpp" "SharedEditor.h" "Message.cpp" "Message.h")
Google_tests\CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(Google_tests)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(lib)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(Google_Tests_run SharedEditorTest.cpp)
target_link_libraries(Google_Tests_run gtest gtest_main)