I'm a beginner in C++ and am coding a Snake for uni, and have to run unit tests. FYI, I code on Xcode 7.1.1.
I manage to make sample tests run on my machine, but have a problem when it comes to creating a fixture for my snake. Here is the code I have :
#include "gtest/gtest.h"
#include "calc.h"
#include "Serpent.h"
#include "Map.h"
#include "Main.h"
using namespace std;
using namespace sf;
class Serpent_test_fixture: public ::testing::Test
{public:
Serpent* serpent_test;
Map* map_test;
Serpent_test_fixture(){
serpent_test = new Serpent(true);
RenderWindow window(VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32), "SnakeTest", Style::None);
map_test = new Map("", window, false);
}
virtual void SetUp(){
map_test->updateGameField(0, 0, HEAD_EAST);
serpent_test->setHead(*map_test, false);
int size_init = serpent_test->getSize();
}
virtual void TearDown(){
}
~Serpent_test_fixture(){
delete serpent_test;
delete map_test;
}
};
TEST_F(Serpent_test_fixture, cherry_action)
{
map_test->updateGameField(0,0,CHERRY);
Tiles head_tile_test = HEAD_EAST;
serpent_test->fruit_action(*map_test, head_tile_test);
EXPECT_EQ(20, 20);
}
int main(int argc, char * argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The way I understand it is, I create my snake (serpent in French) from my class Serpent, then I create my map from my class Map.
UpdateGameField
updates the tile in (0,0) of the map and puts "HEAD_EAST" on it.
Anyway, here is the message I have :
Undefined symbols for architecture x86_64:
"Map::updateGameField(int, int, Tiles)", referenced from:
Serpent_test_fixture_test_cherry_action_Test::TestBody() in main.o
Serpent_test_fixture::SetUp() in main.o
"Map::Map(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, sf::RenderWindow const&, bool)", referenced from:
Serpent_test_fixture::Serpent_test_fixture() in main.o
"Map::~Map()", referenced from:
Serpent_test_fixture::SetUp() in main.o
Serpent_test_fixture::~Serpent_test_fixture() in main.o
"Serpent::fruit_action(Map&, Tiles&)", referenced from:
Serpent_test_fixture_test_cherry_action_Test::TestBody() in main.o
"Serpent::getSize()", referenced from:
Serpent_test_fixture::SetUp() in main.o
"Serpent::setHead(Map, bool)", referenced from:
Serpent_test_fixture::SetUp() in main.o
"Serpent::Serpent(bool)", referenced from:
Serpent_test_fixture::Serpent_test_fixture() in main.o
"Serpent::~Serpent()", referenced from:
Serpent_test_fixture::~Serpent_test_fixture() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone help? It's my first time using Google tests and I'm having a hard time making it work.