Is there a way to incorporate Fitnesse into C++ code?
Asked Answered
D

2

6

I'm trying to use Fitnesse to interface with some C++ code, but the Fit Cpp project file provided on the fitnesse.org website doesn't work (it's VC++ 6 which I don't have but I do have Visual Studio 2005 and 2008). I can't even seem to open the solution file in VS2005 or VS2008 (maybe because it was created in VC++ 6?).

Has anyone been able to get this working? Is there a way I can write a test fixture in C# that communicates with the C++ code? If so, how do I go about doing this.

Here is the website with the code: http://fitnesse.org/FrontPage.FitServers.CppFit.CppTestTools.SetUpCppTestTools

Ideally, I would like to be able to work on this in Visual Studio and avoid cygwin. Should I just bite the bullet and go with cygwin ... not sure that will even work either ... haven't tried.

Any help will be much appreciated. Thanks in advance.

Daydream answered 6/10, 2011 at 15:48 Comment(0)
R
2

Using C++/CLI is one option. That way you can use fitSharp as the bridge from FitNesse to your fixture code, but your fixture code can call directly into C++.

Here's a simple example of testing a Calculator class. First, here's the C++ code we want to test:

class Calculator
{
  public:
    int Add(int x, int y)
    {
      return x + y;
    }
};

and here's the C++/CLI fixture code:

public ref class CalculatorFixture
{
  public:
    property int X;
    property int Y;
    property int Z;

    void Execute()
    {
      Calculator calculator;
      Z = calculator.Add(X,Y);
    }
};

The FitNesse wiki page would look like this:

!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {%m -r fitSharp.Slim.Service.Runner,C:\fitnesse\fitsharp\fitsharp.dll %p}
!define TEST_RUNNER {C:\fitnesse\fitsharp\Runner.exe}

!path c:\CalculatorFixture.dll

!|CalculatorFixture|
|X         |Y         |Z?        |
|2         |2         |4         |
|3         |4         |7         |

One issue to watch out for is that C++/CLI DLLs are generally either 32-bit or 64-bit, whereas the fitSharp runner is 'any cpu'. So if you build your C++/CLI DLL as 32-bit and try to use fitSharp with it on a 64-bit OS, you'll get an 'incorrect format' error. In that case either build the C++/CLI DLL as 64-bit, or use corflags to force the fitsharp runner (Runner.exe) to be 32-bit.

Remuneration answered 13/10, 2011 at 0:28 Comment(3)
Great answer, but I need some more help. There are too many ways to setup Visual Studio projects and this assumes I know how to do that for C++/CLI code. Also, I would like to clarify that I need to access the C++ code via a legacy DLL that has been created already and I can't make any changes to the C++ code. Thanks for the helpDaydream
On my VS 2008 and 2010 installations you create a C++/CLI DLL via New Project->Other Languages->Visual C++->CLR->Class Library. Accessing a legacy DLL should be no problem - just use an import lib like you would from a standard C++ app.Remuneration
Could you please see my question here #32904187Tetracaine
T
0

Back in VC6 times there were no solutions files. Instead, VC6 used workspaces, stored in .dsw files. Project files were .dsp.

If you open the .dsw or .dsp in a newer Visual Studio it should prompt you to convert it, and that should result in new .sln and .vcproj files created for the project. I've converted many complex projects from VC6 to VS 2005, 2008 and 2010, in my experience the conversion works pretty reliably. If there are any issues with the conversion VS will show you that in the conversion log.

Tahitian answered 13/10, 2011 at 2:7 Comment(5)
Hmmm didn't get prompted to convert.Daydream
That can't be. Please check the folder where the dsw/dsp files are and make sure there are no left over .sln/.vcproj from previous attempts. Delete all of those and try again. When the conversion is done you should have a conversion log open indicating if there were any issues.Tahitian
I just tried this. I did get asked to convert, but the converter isn't working, I'm not getting anything. If you want to get VS to build, what I recommend is that you create brand new projects from within VS. You can open the dsp files that you are interested in recreating in notepad and see the list of files and options that are used.Tahitian
I deleted all the files and redownloaded them from the website and now it asked for conversion. I was able to build the project in Debug Config.Daydream
Interesting. I tried this with VS 2010 and I could not get a converted project. But anyway, glad you made progress!Tahitian

© 2022 - 2024 — McMap. All rights reserved.