cpptraining.GettingStartedWithFitNesseInCpp

<--Back

=Initial Downloads=

Download [|cslim from github]
This requires a git client. code [~]% cd src /Users/schuchert/src [~/src]% mkdir cpp_fitnesse [~/src]% cd cpp_fitnesse /Users/schuchert/src/cpp_fitnesse code code [~/src/cpp_fitnesse]% git clone http://github.com/dougbradbury/cslim.git got f463e11c5d718a50a6986a64714342b59c566d02 walk f463e11c5d718a50a6986a64714342b59c566d02 walk 9362f2b10fd30590a8f14c1caebf76cd2fcbe3ca walk 4ac0cbd8d58cfe9c353142a5363bd39718f43acf code
 * Create a top-level directory in which to work (this example uses ~/src/cpp_fitnesse)
 * Use the public clone url to make a clone of the repository (as of this writing, it is: http://github.com/dougbradbury/cslim.git):

Get CppUTest
The README.txt in the root of the cslim directory just created uses CppUTest. code [~/src/cpp_fitnesse/cpputest]% make compiling AllTests.cpp compiling CommandLineArgumentsTest.cpp compiling Utest.cpp compiling UtestPlatform.cpp Building archive lib/libCppUTest.a ar: creating archive lib/libCppUTest.a a - src/CppUTest/CommandLineArguments.o 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) code
 * [|Download CppUTest from sourceforge]
 * Extract the zip, creating a sibling directory to cslim called cpputest. The top-level directory name should be ~/src/cpp_fitnesse/cpputest
 * Switch to that directory and build cpputest:

Get FitNesse
code [~/src/cpp_fitnesse]% ls cpputest/	cslim/		fitnesse.jar code =Building cslim= code [~/src/cpp_fitnesse/cslim]% make compiling FixtureInCpp.cpp compiling TcpComLink.c Building archive lib/libCSlim.a ar: creating archive lib/libCSlim.a a - src/CSlim/ListExecutor.o a - src/Com/TcpComLink.o Linking CSlim_cslim [~/src/cpp_fitnesse/cslim]% code =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. code [~/src/cpp_fitnesse]% java -jar fitnesse.jar -p 8080 Unpacking new version of FitNesse resources. Please be patient. ......... ..........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. code code [~/src/cpp_fitnesse]% ls FitNesseRoot/	cpputest/	cslim/		fitnesse.jar code code [~/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. code =Create Top-Level Page= This assumes you're running FitNesse on port 8080. Update the url with your port as necessary. code !contents -R2 -g -p -f -h
 * [|Download fitnesse.jar], these instructions were created using the edge build #398, dated July 11, 2010, 12:49, but the release at fitnesse.org should work fine.
 * Move fitnesse.jar into ~src/cpp_fitnesse/
 * The directory should look like this before you run fitnesse for the first time:
 * Go to ~/src/cpp_fitnesse/cslim
 * Type make:
 * The first execution looks like this
 * The directory structure after running FitNesse the first time should now look like this:
 * The next time you start FitNesse, you'll simply see the following:
 * Create a new top-level page at: []
 * Edit the contents. Set it to (note, update// **/User/schuchert**// with your top-level directory):

!define TEST_SYSTEM {slim} !define TEST_RUNNER {/Users/schuchert/src/cpp_fitnesse/cslim/CSlim_cslim} !define COMMAND_PATTERN {%m} !define SLIM_VERSION {0.2} code code code If you click the// **Test**// 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. code format="cpp"
 * Save the page.
 * Create a sub-page at the following URL: []
 * Edit the contents. Set it to (note, to make the columns line up, use the// **Format**// button):
 * Modulus                |
 * value|divisor|remainder?|
 * 6   |2      |0         |
 * 13  |27     |13        |
 * 5   |2      |1         |
 * Go to the fixtures directory under your cslim installation (cd ~/src/cpp_fitnesse/cslim/fixtures).
 * Create a new file, Modulus.cpp:
 * 1) include 
 * 2) include 
 * 3) include "SlimList.h"
 * 4) include "Fixtures.h"

struct Modulus {	Modulus { lastValue[0] = 0; }	int remainder { return value % divisor; }	static Modulus *from(void *voidSelf) { return reinterpret_cast(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

} code code format="cpp"
 * Update the fixture registry in Fixtures.c. This file is in the same directory. You'll see something close to this:
 * 1) include "Fixtures.h"

SLIM_FIXTURES SLIM_FIXTURE(Division) SLIM_FIXTURE(Count) SLIM_FIXTURE(EmployeePayRecordsRow) SLIM_FIXTURE(ExceptionsExample) SLIM_FIXTURE(Multiplication) SLIM_END code code format="cpp"
 * You need to add your new fixture, Modulus, in the list somewhere:
 * 1) 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 code code [~/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 code
 * Make your CSlim_cslim executable. Switch to ~/src/cpp_fixtures/cslim and type make:
 * Go back to your page and hit the// **Test**// button.

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

<--Back