-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMockingCApi.cpp
More file actions
39 lines (31 loc) · 1.09 KB
/
Copy pathMockingCApi.cpp
File metadata and controls
39 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "CppUnitTest.h"
#include "MockingCApi.h"
namespace ExampleUsageOfTBCI
{
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
TEST_CLASS(MockingCApiTests)
{
TEST_CLASS_INITIALIZE(Init) { std::ignore = ::CoInitialize(NULL); }
TEST_CLASS_CLEANUP(Cleanup) { ::CoUninitialize(); }
TEST_METHOD(OriginalCode)
{
TheProductionCode obj;
IUnknown* punk = nullptr;
HRESULT hr = obj.GetSomeCOMInterface(punk);
if (punk)
punk->Release(); // if only I could use an ATL smart pointer here...
Assert::IsNotNull(punk);
Assert::AreEqual(S_OK, hr);
}
TEST_METHOD(RefactoredForTBCI)
{
struct TestBase
{
HRESULT CoCreateInstance(...) { return E_FAIL; } // note use of ...
};
IUnknown* punk = nullptr;
Assert::AreEqual(E_FAIL, TheProductionCodeT<TestBase>().GetSomeCOMInterface(punk));
Assert::IsNull(punk);
}
};
}