Create a top-level directory for all of your work. I’ll be using ~/src/waat
Under that, create a workspace directory. I’ll use ~/src/waat/workspace
Retrieve the production code using the following command:
The output should resemble:
Retrieve the test code using the command:
The output should resemble:
Configuring the Eclipse Project
In previous tutorial, you created a directory called ~/src/cslim and under that is CppUTest. To create this project, we’ll use the equivalent of environment variables in Eclipse.
Create a new workspace. Select the directory containing two github projects you just checked out. In my case that’s Users/schuchert/src/waat/workspace
Close the Welcome to Eclipse tab.
Edit the Eclipse properties:
Under General:Workspce, enable Refresh automatically
Under Eclipse properties:C/C++:Build:Environment, define some environment variables:
This allows me to use g++ 4.4 or 4.5 instead of 4.2
Apply those changes.
Next, select File:Import
Under General select Existing Projects into Workspace
Click Next
Click the Browse button then simply press OK
You should see listed two projects
RpnCalculatorInCpp
RpnCalculatorInCppTests
Both of these projects should be selected by default.
Click Finish
Eclipse will probably attempt to build RpnCalculatorInCppTests, but it will fail because the other project must be build first.
Pull down the Project menu and select Build All
This should build the library libRpnCalculatorInCpp.a first and then build the executable RpnCalculatorInCppTests
When this is done, right-click on the RpnCalculatorInCppTests projects, select RunAs::Local C/C++ Application
You should see your tests pass. As of this writing, there are 70 tests:
Creating Your First Test Table
Since you’ve already worked through Getting Started With FitNesse in C++, you have FitNesse installed somewhere. Start your FitNesse instance. Here’s what it looks like on my computer:
Creating Top-Level Test Suite
Now that you have FitNesse started, create a top-level page for all of your work.
This project is neither a test or suite page by default (it has to do with the page’s name). So click on its Properties button, select the Test radio button and then click on Save Properties
This page makes reference to a fixture that does not yet exist. As in the previous step, don’t worry. That’s next.
Creating Fixture Project
Now you’re going to add a third project to contain your fixtures. This involves creating a project, linking to the calculator.
Select File:New:C++ Project
Create an Empty Project
Under Toolchains either select Mingw or some other “working” toolchain. As of this writing, the cygwin will work but you cannot use a debugger.
For the project name, enter ** RpnCalculatorFixtures**, which you can infer from the TEST_SYSTEM variable set on the top-level page.
The provided code uses features of G++ 4.4 and above, specifically the compiler flag-std=c++0x. The primary thing is the use of the standard class shared_ptr. As of the TR1 standard, this class’ namespace is std::tr1::. In the upcoming standard, the class is additionally in std::. To fix this, edit the project’s properties. Under C/C++ Build:Settings/C++ Compiler: Miscellaneous, add -std=c++0x (that’s zero, not o) to the Other flags.
You’ll need to copy in two boilerplate files, create the fixture class and then set up libraries and include paths.
Add a new file called Main.c and set its contents:
You’ll notice several warnings about unknown header files. Let’s fix that before moving on:
Edit the project’s properties.
Under C/C++ Build:Settings, select the C Compiler settings (That’s C not C++!)
Select the Includes and make the following additions:
”${CSLIM_BASE}/include/CSlim”
”${CSLIM_BASE}/include/Com”
Save your changes (click Apply then OK, or just OK if you’re feeling lucky)
Next, create another new file called Fixtures.c:
I’m having you preemptively add in the name of a fixture you have yet to write.
Now it’s time to create the fixture. Since this is a mechanics tutorial, I’ll give you the fixture source code:
ExecuteBinaryOperator.cpp
You’ll notice a few more warnings about unknown include files. You’ll add a few more include directories, this time under the C++ tab instead of the C Tab
Edit the project’s properties
Select C/C++ Build:Settings
Now select GCC C++ Compiler (or similar) and under Includes add:
**${workspace_loc:/RpnCalculatorInCpp}
**”${CSLIM_BASE}/include/CSlim”
Apply those changes.
Notice that there’s still one missing header file. This is in another library that I’ve written to make writing C++ cslim fixtures a bit easer:
Go back to your workspace directory
Clone the CSlimCppExtensions project from github with the following command:
Here’s what that will look like:
Back in Eclipse, File:Import
Select General:Existing Projects into Workspace
Click Browse and then Ok
There should be one project listed, CSlimCppExtensions
Click on Finish
Select the project, right-click and select build.
Warning: As of this writing, there is a “missing” method in the cslim library. You’ll need to make two changes to the cslim library that you’ve downloaded to resolve this.
Updating CSlim Library
/include/CSlim/SlimListSerializer.h
Add the following function declaration to the header file:
/src/CSlim/SlimListSerializer.h
Add a function declaration to the source file:
Now that you have the required missing project, you need to add it as a dependent project and include its header files in the RpnCalcualtorFixtures project:
Edit the properties of RpnCalculatorFixtures
Under the top-level Project References, select CSlimCppExtensions
Under C/C++ Build:Settings, select the C++ Compiler settings
Add under include the following directory: ${workspace_loc:/CSlimCppExtensions}
Now if you try to build the project, it will compile but it will not link.
Edit the project’s settings
Find the linker settings under C/C++ Build:Linker
Edit the Libraries and add the following list:
**CSlim
**RpnCalculatorInCpp
**CppUTest
**CSlimCppExtensions
Edit he Library search path and add the following list:
**${workspace_loc:/RpnCalculatorInCpp/Debug}
**${CSLIM_BASE}/lib
**${CPPUTEST_BASE}/lib
**${workspace_loc:/CSlimCppExtensions/Debug}
Save your changes and build again
You should now be able to run this executable. If you do, you’ll see in red text:
Running the Test
You should be able to run your FitNesse test and get to green.
You might see an error regarding a difference in protocol. That’s under construction. The cslim library should be updated in the near future (August 2010 I hope).
Working with a Script Table
Now it is time to program the calculator. First a test, then the fixture code.
Comments