Port of schuchert.wikispaces.com


cpptraining.GettingStartedWithFitNesseInCpp

cpptraining.GettingStartedWithFitNesseInCpp

Initial Downloads

Download cslim from github

This requires a git client.

[~]% cd src
/Users/schuchert/src
[~/src]% mkdir cpp_fitnesse
[~/src]% cd cpp_fitnesse 
/Users/schuchert/src/cpp_fitnesse
[~/src/cpp_fitnesse]% git clone http://github.com/dougbradbury/cslim.git
got f463e11c5d718a50a6986a64714342b59c566d02
walk f463e11c5d718a50a6986a64714342b59c566d02
<snip>
walk 9362f2b10fd30590a8f14c1caebf76cd2fcbe3ca
walk 4ac0cbd8d58cfe9c353142a5363bd39718f43acf

Get CppUTest

The README.txt in the root of the cslim directory just created uses CppUTest.

[~/src/cpp_fitnesse/cpputest]% make
compiling AllTests.cpp
compiling CommandLineArgumentsTest.cpp
<snip>
compiling Utest.cpp
compiling UtestPlatform.cpp
Building archive lib/libCppUTest.a
ar: creating archive lib/libCppUTest.a
a - src/CppUTest/CommandLineArguments.o
<snip>
a - src/Platforms/Gcc/UtestPlatform.o
Linking CppUTest_tests
Running CppUTest_tests
.......!!.........................................
.............................................!....
..................................................
...!.................
OK (171 tests, 167 ran, 599 checks, 4 ignored, 0 filtered out, 10 ms)

Get FitNesse

[~/src/cpp_fitnesse]% ls
cpputest/	cslim/		fitnesse.jar

Building cslim

[~/src/cpp_fitnesse/cslim]% make
compiling FixtureInCpp.cpp
<snip>
compiling TcpComLink.c
Building archive lib/libCSlim.a
ar: creating archive lib/libCSlim.a
a - src/CSlim/ListExecutor.o
<snip>
a - src/Com/TcpComLink.o
Linking CSlim_cslim
[~/src/cpp_fitnesse/cslim]% 

Run FitNesse

The first time you run FitNesse, it will extract a base wiki and then start. After the first execution, it will just start. If you replace the fitnesse.jar with a new version, starting FitNesse the first time after that will update the base wiki, but leave the pages you created alone.

[~/src/cpp_fitnesse]% java -jar fitnesse.jar -p 8080
Unpacking new version of FitNesse resources.  Please be patient.
.........<snip>..........FitNesse (v20100711) Started...
	port:              8080
	root page:         fitnesse.wiki.FileSystemPage at ./FitNesseRoot
	logger:            none
	authenticator:     fitnesse.authentication.PromiscuousAuthenticator
	html page factory: fitnesse.html.HtmlPageFactory
	page version expiration set to 14 days.
[~/src/cpp_fitnesse]% ls
FitNesseRoot/	cpputest/	cslim/		fitnesse.jar
[~/src/cpp_fitnesse]% java -jar fitnesse.jar -p 8080
FitNesse (v20100711) Started...
	port:              8080
	root page:         fitnesse.wiki.FileSystemPage at ./FitNesseRoot
	logger:            none
	authenticator:     fitnesse.authentication.PromiscuousAuthenticator
	html page factory: fitnesse.html.HtmlPageFactory
	page version expiration set to 14 days.

Create Top-Level Page

This assumes you’re running FitNesse on port 8080. Update the url with your port as necessary.

!contents -R2 -g -p -f -h

!define TEST_SYSTEM {slim}
!define TEST_RUNNER {/Users/schuchert/src/cpp_fitnesse/cslim/CSlim_cslim}

!define COMMAND_PATTERN {%m}

!define SLIM_VERSION {0.2}
|Modulus                 |
|value|divisor|remainder?|
|6    |2      |0         |
|13   |27     |13        |
|5    |2      |1         |

If you click theTest Button, you’ll see a bit of yellow. It’s time to write a fixture.

Writing the Fixture

This example originated from the one provided with cslim. It’s been somewhat simplified and moved closer to C++. You can review the original example in ~/src/cpp_fitnesse/cslim/fixtures/FixtureInCpp.cpp.

#include <stdlib.h>
#include <stdio.h>
#include "SlimList.h"
#include "Fixtures.h"

struct Modulus
{
	Modulus() { 
		lastValue[0] = 0;
	}
	int remainder() {
		return value % divisor;
	}
	static Modulus *from(void *voidSelf) {
		return reinterpret_cast<Modulus*>(voidSelf);
	}
	char lastValue[32];
	int value;
	int divisor;
};

static int getInt(SlimList* args) {
	return atoi(SlimList_GetStringAt(args, 0));
}

extern "C" {
void* Modulus_Create(StatementExecutor* errorHandler, SlimList* args) {
	return new Modulus;
}

void Modulus_Destroy(void* self) {
	delete Modulus::from(self);
}

static char* setValue(void* voidSelf, SlimList* args) {
	Modulus *self = Modulus::from(voidSelf);
	self->value = getInt(args);
	return self->lastValue;
}

static char* setDivisor(void* voidSelf, SlimList* args) {
	Modulus *self = Modulus::from(voidSelf);
	self->divisor = getInt(args);
	return self->lastValue;
}

static char* remainder(void* voidSelf, SlimList* args) {
	Modulus *self = Modulus::from(voidSelf);
	int result = self->remainder();
	snprintf(self->lastValue, sizeof(self->lastValue), "%d", result);
	return self->lastValue;
}

SLIM_CREATE_FIXTURE(Modulus) 
	SLIM_FUNCTION(setValue)
	SLIM_FUNCTION(setDivisor)
	SLIM_FUNCTION(remainder)
SLIM_END

}
#include "Fixtures.h"

SLIM_FIXTURES
  SLIM_FIXTURE(Division)
  SLIM_FIXTURE(Count)
  SLIM_FIXTURE(EmployeePayRecordsRow)
  SLIM_FIXTURE(ExceptionsExample)
  SLIM_FIXTURE(Multiplication)
SLIM_END
#include "Fixtures.h"

SLIM_FIXTURES
  SLIM_FIXTURE(Modulus)
  SLIM_FIXTURE(Division)
  SLIM_FIXTURE(Count)
  SLIM_FIXTURE(EmployeePayRecordsRow)
  SLIM_FIXTURE(ExceptionsExample)
  SLIM_FIXTURE(Multiplication)
SLIM_END
[~/src/cpp_fitnesse/cslim/fixtures]% cd ..
/Users/schuchert/src/cpp_fitnesse/cslim
[~/src/cpp_fitnesse/cslim]% make
compiling Modulus.cpp
compiling Fixtures.c
Linking CSlim_cslim

If you see mostly green, congratulations. As of this writing, there’s an exception on the slim protocol version. Once this gets fixed, I’ll update these instructions


Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.