Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Forked from flavius/.gitignore
Created March 13, 2012 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan2904/2025607 to your computer and use it in GitHub Desktop.
Save stefan2904/2025607 to your computer and use it in GitHub Desktop.
(old) SEP 2012 Toolchain
[submodule "cxxtest"]
path = cxxtest
url = git://github.com/CxxTest/cxxtest.git

This serves as a good starting point for testing and semi-automatization purposes for LV 706.007.

Getting started

  1. fork your own copy from https://gist.github.com/2012324
  2. git clone <that copy's private clone URL> framework side-by-side with your normal repository so you will end up with two directories uni/sep/project/ and uni/sep/framework/
  3. cd framework; git submodule init; git submodule update
  4. create a symlink from uni/sep/framework/src/ to uni/sep/project/<src> - <src> is where your .cpp and .h files lie, in your private repository (subversion or git) that noone will see.

Make Targets

  • make
    • just compile the program
  • make tests
    • compile the program if necessary, then run the tests on it
  • make deliverable
    • create archive (ready for abgabe, DO NOT FORGET to update the DELIVERABLES variable in Makefile)
    • run the tests beforehand => IMPOSSIBLE to hand in something that doesn't pass the tests
  • make format
    • run astyle over the source code (the DELIVERABLES variable) - not guaranteed to be perfect, but Weber-proof in the scope of astyle at least

Testing unit

Add your tests in uni/sep/framework/tests/. The documentation is at http://cxxtest.com/cxxtest/doc/guide.html.

Commit and push your tests, so anyone can benefit from them.

???

  • fun
  • profit (ECTS)
# files linked to the test runner (usually every .o file having a corresponding .cpp file, except main.cpp)
TESTABLE=Action.o Game.o Player.o
# files formatted by astyle
DELIVERABLES=Game.h Game.cpp Player.h Player.cpp
# deliverable name
ASS=ass1
# you shouldn't need to change anything below
#SHELL := /bin/bash
CXX=g++
RUNNER_SRC=runner.cpp
RUNNER=runner
TESTTOOL=./cxxtest/bin/cxxtestgen
CXXFLAGS=-Wall
OBJS=main.o $(TESTABLE)
TESTS=$(wildcard tests/*.h)
$(ASS): $(OBJS)
$(CXX) $(CXXFLAGS) $(OBJS) -o $(ASS)
%.o: src/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
.PHONY: tests clean
tests: $(RUNNER)
./$(RUNNER)
$(RUNNER): $(TESTABLE)
$(TESTTOOL) --error-printer -o $(RUNNER_SRC) tests/*.h
$(CXX) -o $(RUNNER) $(TESTABLE) $(RUNNER_SRC) -I./cxxtest -I.
#$(RUNNER): $(RUNNER_SRC) $(TESTABLE)
# $(CXX) -I./cxxtest -I./src/ $(CXXFLAGS) -o $@ $<
#$(RUNNER_SRC): $(TESTABLE) $(TESTS)
# $(TESTTOOL) --error-printer -o $(RUNNER_SRC) $(TESTS)
format:
cd src; astyle -A1 -j -c -s2 -p -k3 -Y $(DELIVERABLES)
deliverable: format tests
tar -czf $(ASS).tar.gz -C src $(DELIVERABLES)
clean:
rm -rf *.o *.gch $(ASS) $(RUNNER_SRC) $(RUNNER) $(ASS).tar.gz
// PlayerFullNames.h
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <src/Player.h>
#include <string>
class Fixture1 : public CxxTest::GlobalFixture
{
public:
unsigned setUpCount;
unsigned tearDownCount;
Fixture1() { setUpCount = tearDownCount = 0; }
bool setUp() { ++ setUpCount; return true; }
bool tearDown() { ++ tearDownCount; return true; }
bool setUpWorld() { return true;}
bool tearDownWorld() { return true;}
};
static Fixture1 fixture1;
/** CRAPPY SPECIFICATION DOES NOT ALLOW US TO DO IT PROPERLY
enum _Test_Color
{
BLACK, WHITE, RED, GREEN, BLUE, YELLOW, ORANGE, BROWN
};
*/
static const std::string _test_color_names[] = { "Black", "White", "Red", "Green",
"Blue", "Yellow", "Orange", "Brown"};
static const std::string _test_player_names[] = { "Foo Black", "Bar White",
"Red Moon", "Green World", "Blue Screen of Death", "Yellow Submarine",
"Orange X", "Brown ...haha, da sag ich nichts"};
class PlayerFullNames : public CxxTest::TestSuite
{
Player* player;
std::string expected;
Color color;
public:
void setUp() {
unsigned cnt = fixture1.setUpCount-1;
color = static_cast<Color>(cnt);
player = new Player(color, _test_player_names[cnt]);
expected = _test_player_names[cnt] + "(" + _test_color_names[cnt] + ")";
}
void tearDown() {
delete player;
}
void test_BlackPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_WhitePlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_RedPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_GreenPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_BluePlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_YellowPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_OrangePlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_BrownPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
};
// PlayerName.h
#include <cxxtest/TestSuite.h>
#include <src/Player.h>
#include <string>
class PlayerName : public CxxTest::TestSuite
{
Player* player;
public:
void setUp() {
player = new Player(BLACK, "Foo");
}
void tearDown() {
delete player;
}
void test_NormalName() {
TS_ASSERT_EQUALS("Foo", player->getName());
}
void test_SetName() {
player->setName("Bar");
TS_ASSERT_EQUALS("Bar", player->getName());
}
};
// PlayerFullNames.h
#include <cxxtest/TestSuite.h>
#include <cxxtest/GlobalFixture.h>
#include <src/Player.h>
#include <string>
class Fixture1 : public CxxTest::GlobalFixture
{
public:
unsigned setUpCount;
unsigned tearDownCount;
Fixture1() { setUpCount = tearDownCount = 0; }
bool setUp() { ++ setUpCount; return true; }
bool tearDown() { ++ tearDownCount; return true; }
bool setUpWorld() { return true;}
bool tearDownWorld() { return true;}
};
static Fixture1 fixture1;
/** CRAPPY SPECIFICATION DOES NOT ALLOW US TO DO IT PROPERLY
enum _Test_Color
{
BLACK, WHITE, RED, GREEN, BLUE, YELLOW, ORANGE, BROWN
};
*/
static const std::string _test_color_names[] = { "Black", "White", "Red", "Green",
"Blue", "Yellow", "Orange", "Brown"};
static const std::string _test_player_names[] = { "Foo Black", "Bar White",
"Red Moon", "Green World", "Blue Screen of Death", "Yellow Submarine",
"Orange X", "Brown ...haha, da sag ich nichts"};
class PlayerFullNames : public CxxTest::TestSuite
{
Player* player;
std::string expected;
Color color;
public:
void setUp() {
unsigned cnt = fixture1.setUpCount-1;
color = static_cast<Color>(cnt);
player = new Player(color, _test_player_names[cnt]);
expected = _test_player_names[cnt] + "(" + _test_color_names[cnt] + ")";
}
void tearDown() {
delete player;
}
void test_BlackPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_WhitePlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_RedPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_GreenPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_BluePlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_YellowPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_OrangePlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
void test_BrownPlayer(void)
{
TS_ASSERT_EQUALS(expected, player->getFullName());
}
};
// PlayerName.h
#include <cxxtest/TestSuite.h>
#include <src/Player.h>
#include <string>
class PlayerName : public CxxTest::TestSuite
{
Player* player;
public:
void setUp() {
player = new Player(BLACK, "Foo");
}
void tearDown() {
delete player;
}
void test_NormalName() {
TS_ASSERT_EQUALS("Foo", player->getName());
}
void test_SetName() {
player->setName("Bar");
TS_ASSERT_EQUALS("Bar", player->getName());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment