grahamr (work)
June 9th, 2008, 04:14 AM
I have a legacy project that I am writing unit-tests against, called (for the sake of this argument) Test and Project. All my classes are named something descriptive (again for the sake of argument) like SomethingImportant, and the unit-test against it is TestSomethingImportant. Most of the functions in SomethingImportant are either public or protected, so I can do test the protected members by creating a class that inherits SomethingImportant.
This is where it got tricky. I needed to test a section that edits the UI. To get around this in TestSomethingImportant I create a stub called the same as the original class. The idea is that the Testing class will pick up the class that is in the same file as it while the full program will pick up the wider scoped file.
That's the idea. Now I don't own a copy of the C++ standard, but does the standard state where the classes are supposed to be referenced from? I was under the impression that there was and that a class declared locally (ie in the same file) took precedence over a remote (different file) class.
Any ideas on
a) to fix this and
b) whether this is just another annoyance in VC6
Thanks, G.
Here's the obligatory untested code snippet:
// SomethingImportant.h
class SomethingImportantUI;
class SomethingImportant {
public:
void RequiresUI(SomethingImportantUI* pDlg);
// other stuff
};
// SomethingImportantUI.h
class SomethingImportantUI : public CWnd {
// stuff
};
// TestSomethingImportant.cpp
#include "..\SomethingImportant.h"
class SomethingImportantUI {
public:
};
class TestSomethingImportant : public SomethingImportant {
};
TEST( TestRequiresUI )
{
TestSomethingImportant tester;
SomethingImportant dlg;
RequiresUI(&dlg);
CHECK (SomeSettings);
}
This is where it got tricky. I needed to test a section that edits the UI. To get around this in TestSomethingImportant I create a stub called the same as the original class. The idea is that the Testing class will pick up the class that is in the same file as it while the full program will pick up the wider scoped file.
That's the idea. Now I don't own a copy of the C++ standard, but does the standard state where the classes are supposed to be referenced from? I was under the impression that there was and that a class declared locally (ie in the same file) took precedence over a remote (different file) class.
Any ideas on
a) to fix this and
b) whether this is just another annoyance in VC6
Thanks, G.
Here's the obligatory untested code snippet:
// SomethingImportant.h
class SomethingImportantUI;
class SomethingImportant {
public:
void RequiresUI(SomethingImportantUI* pDlg);
// other stuff
};
// SomethingImportantUI.h
class SomethingImportantUI : public CWnd {
// stuff
};
// TestSomethingImportant.cpp
#include "..\SomethingImportant.h"
class SomethingImportantUI {
public:
};
class TestSomethingImportant : public SomethingImportant {
};
TEST( TestRequiresUI )
{
TestSomethingImportant tester;
SomethingImportant dlg;
RequiresUI(&dlg);
CHECK (SomeSettings);
}