Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

File scope test with symbols in 2 .cpp files

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in C/C++test
I have the following:

IWidget.h:
class IWidget { virtual ~IWidget(); };

IWidget.cpp:
#include "IWidget.h"
IWidget::~IWidget {}

Widget.h:
#include "IWidget.h"
class Widget : public IWidget { virtual ~Widget(); };

Widget.cpp:
#include "Widget.h"
Widget::~Widget() {}

When I try to write a test for the Widget class, I get errors due to the ~IWidget symbol not being defined. I can stub it out to fix this, but I don't want to stub it (this would cause code duplication in our real-world case, plus should I really have to stub out an interface?). Is there a way to do "file scope" unit testing where the run can get symbols from two different CPP files?
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hello PatrickVHines,

    You are able to scan multiple individual files by holding down the control button ("ctrl") and clicking on the files you wish to scan in the GUI, including these multiple files into the scope. In this case, it would be both Widget.cpp (which calls Widget.h) and IWidget.cpp (which calls IWidget.h). In this way, you can include multiple necessary files into a file-scope level Test Configuration scan.

    To achieve the same on the command line, use the "-resource" option, once for each particular resource (in this case, file) you wish to have scanned. Example: "-resource jvann/workspace/Widget.cpp -resource jvann/workspace/IWidget.cpp". Please do note that the "-resource" option is not file-centric; it can be used to reference broader-scale resources, such as entire projects, as well.

    Best,

    -Jamie Vann
    Associate, Customer Support