Skip to content

Commit 9321a4d

Browse files
authored
Update the unit test project to use named modules (#35)
Note: using a single copy of module winrt doesn't work warnings from base.h (winrt include file) are then reported.
1 parent 2b060b0 commit 9321a4d

16 files changed

+178
-169
lines changed

std-header-units/std-header-units.vcxproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,5 @@
180180
<ClInclude Include="win.h" />
181181
</ItemGroup>
182182
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
183-
<ImportGroup Label="ExtensionTargets">
184-
</ImportGroup>
183+
<ImportGroup Label="ExtensionTargets" />
185184
</Project>

test/dll_main_test.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "util.h"
55

6+
import <win.h>;
7+
import test.winrt;
68
import test.errors;
79
import factory;
810

@@ -12,15 +14,14 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
1214
// {358bb60e-2b77-4411-8a76-27164945c93d}
1315
constexpr GUID random_class_id{0x358bb60e, 0x2b77, 0x4411, {0x8a, 0x76, 0x27, 0x16, 0x49, 0x45, 0xc9, 0x3d}};
1416

15-
1617
TEST_CLASS(dllmain_test)
1718
{
1819
public:
1920
TEST_METHOD(class_factory_netpbm_decoder_lock_server) // NOLINT
2021
{
2122
const auto class_factory{factory_.get_class_factory(net_pbm_decoder_class_id)};
2223

23-
hresult result{class_factory->LockServer(true)};
24+
auto result{class_factory->LockServer(true)};
2425
Assert::AreEqual(error_ok, result);
2526

2627
result = class_factory->LockServer(false);
@@ -30,7 +31,7 @@ TEST_CLASS(dllmain_test)
3031
TEST_METHOD(class_factory_unknown_id) // NOLINT
3132
{
3233
com_ptr<IClassFactory> class_factory;
33-
const hresult result{factory_.get_class_factory(random_class_id, class_factory)};
34+
const auto result{factory_.get_class_factory(random_class_id, class_factory)};
3435

3536
Assert::AreEqual(error_class_not_available, result);
3637
}
@@ -40,7 +41,7 @@ TEST_CLASS(dllmain_test)
4041
const auto class_factory{factory_.get_class_factory(net_pbm_decoder_class_id)};
4142

4243
SUPPRESS_WARNING_6387_INVALID_ARGUMENT_NEXT_LINE
43-
const hresult result{class_factory->CreateInstance(nullptr, random_class_id, nullptr)};
44+
const auto result{class_factory->CreateInstance(nullptr, random_class_id, nullptr)};
4445

4546
Assert::AreEqual(error_pointer, result);
4647
}
@@ -51,7 +52,7 @@ TEST_CLASS(dllmain_test)
5152

5253
auto outer = reinterpret_cast<IUnknown*>(1);
5354
com_ptr<IWICBitmapDecoder> decoder;
54-
const hresult result{class_factory->CreateInstance(outer, IID_PPV_ARGS(decoder.put()))};
55+
const auto result{class_factory->CreateInstance(outer, IID_PPV_ARGS(decoder.put()))};
5556

5657
Assert::AreEqual(error_no_aggregation, result);
5758
}

test/factory.ixx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Copyright (c) Victor Derks.
22
// SPDX-License-Identifier: MIT
3-
module;
4-
5-
#include <Windows.h>
6-
#include <wincodec.h>
7-
#include "winrt.h"
83

94
export module factory;
105

6+
import "win.h";
7+
import test.winrt;
8+
119
export inline constexpr GUID net_pbm_decoder_class_id{0x6891bbe, 0xcc02, 0x4bb2, {0x9c, 0xf0, 0x30, 0x3f, 0xc4, 0xe6, 0x68, 0xc3}};
1210

1311
export class factory final

test/netpbm_bitmap_decoder_test.cpp

+32-35
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33

44
#include "util.h"
55

6-
#include "winrt.h"
6+
import <std.h>;
7+
import <win.h>;
8+
import test.winrt;
79

810
import test.errors;
9-
import test_stream;
11+
import test.stream;
12+
import test.util;
1013
import factory;
1114

12-
import <shlwapi.h>;
13-
import <wincodec.h>;
14-
15-
import <vector>;
16-
17-
1815
using namespace winrt;
1916
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
2017
using std::vector;
@@ -29,7 +26,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
2926
TEST_METHOD(GetContainerFormat) // NOLINT
3027
{
3128
GUID container_format;
32-
const hresult result{factory_.create_decoder()->GetContainerFormat(&container_format)};
29+
const auto result{factory_.create_decoder()->GetContainerFormat(&container_format)};
3330

3431
Assert::AreEqual(error_ok, result);
3532
Assert::IsTrue(container_format_netpbm == container_format);
@@ -38,7 +35,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
3835
TEST_METHOD(GetContainerFormat_with_nullptr) // NOLINT
3936
{
4037
SUPPRESS_WARNING_6387_INVALID_ARGUMENT_NEXT_LINE
41-
const hresult result{factory_.create_decoder()->GetContainerFormat(nullptr)};
38+
const auto result{factory_.create_decoder()->GetContainerFormat(nullptr)};
4239

4340
Assert::IsTrue(failed(result));
4441
}
@@ -48,7 +45,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
4845
com_ptr<IWICBitmapDecoder> decoder = factory_.create_decoder();
4946

5047
com_ptr<IWICBitmapDecoderInfo> decoder_info;
51-
const hresult result{decoder->GetDecoderInfo(decoder_info.put())};
48+
const auto result{decoder->GetDecoderInfo(decoder_info.put())};
5249

5350
Assert::IsTrue(result == error_ok || result == wincodec::error_component_not_found);
5451
if (succeeded(result))
@@ -64,31 +61,31 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
6461
TEST_METHOD(GetDecoderInfo_with_nullptr) // NOLINT
6562
{
6663
SUPPRESS_WARNING_6387_INVALID_ARGUMENT_NEXT_LINE
67-
const hresult result{factory_.create_decoder()->GetDecoderInfo(nullptr)};
64+
const auto result{factory_.create_decoder()->GetDecoderInfo(nullptr)};
6865

6966
Assert::IsTrue(failed(result));
7067
}
7168

7269
TEST_METHOD(CopyPalette) // NOLINT
7370
{
7471
const com_ptr<IWICPalette> palette;
75-
const hresult result{factory_.create_decoder()->CopyPalette(palette.get())};
72+
const auto result{factory_.create_decoder()->CopyPalette(palette.get())};
7673

7774
Assert::AreEqual(wincodec::error_palette_unavailable, result);
7875
}
7976

8077
TEST_METHOD(GetMetadataQueryReader) // NOLINT
8178
{
8279
com_ptr<IWICMetadataQueryReader> metadata_query_reader;
83-
const hresult result{factory_.create_decoder()->GetMetadataQueryReader(metadata_query_reader.put())};
80+
const auto result{factory_.create_decoder()->GetMetadataQueryReader(metadata_query_reader.put())};
8481

8582
Assert::AreEqual(wincodec::error_unsupported_operation, result);
8683
}
8784

8885
TEST_METHOD(GetPreview) // NOLINT
8986
{
9087
com_ptr<IWICBitmapSource> bitmap_source;
91-
const hresult result{factory_.create_decoder()->GetPreview(bitmap_source.put())};
88+
const auto result{factory_.create_decoder()->GetPreview(bitmap_source.put())};
9289

9390
Assert::AreEqual(wincodec::error_unsupported_operation, result);
9491
}
@@ -97,7 +94,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
9794
{
9895
com_ptr<IWICColorContext> color_contexts;
9996
uint32_t actual_count;
100-
const hresult result{factory_.create_decoder()->GetColorContexts(1, color_contexts.put(), &actual_count)};
97+
const auto result{factory_.create_decoder()->GetColorContexts(1, color_contexts.put(), &actual_count)};
10198

10299
Assert::AreEqual(error_ok, result);
103100
Assert::AreEqual(0U, actual_count);
@@ -106,15 +103,15 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
106103
TEST_METHOD(GetThumbnail) // NOLINT
107104
{
108105
com_ptr<IWICBitmapSource> bitmap_source;
109-
const hresult result{factory_.create_decoder()->GetThumbnail(bitmap_source.put())};
106+
const auto result{factory_.create_decoder()->GetThumbnail(bitmap_source.put())};
110107

111108
Assert::AreEqual(wincodec::error_codec_no_thumbnail, result);
112109
}
113110

114111
TEST_METHOD(GetFrameCount) // NOLINT
115112
{
116113
uint32_t frame_count;
117-
const hresult result{factory_.create_decoder()->GetFrameCount(&frame_count)};
114+
const auto result{factory_.create_decoder()->GetFrameCount(&frame_count)};
118115

119116
Assert::AreEqual(error_ok, result);
120117
Assert::AreEqual(1U, frame_count);
@@ -123,7 +120,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
123120
TEST_METHOD(GetFrameCount_count_parameter_is_null) // NOLINT
124121
{
125122
SUPPRESS_WARNING_6387_INVALID_ARGUMENT_NEXT_LINE
126-
const hresult result{factory_.create_decoder()->GetFrameCount(nullptr)};
123+
const auto result{factory_.create_decoder()->GetFrameCount(nullptr)};
127124

128125
Assert::AreEqual(error_pointer, result);
129126
}
@@ -134,7 +131,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
134131
stream.attach(SHCreateMemStream(nullptr, 0));
135132

136133
DWORD capability;
137-
const hresult result{factory_.create_decoder()->QueryCapability(stream.get(), &capability)};
134+
const auto result{factory_.create_decoder()->QueryCapability(stream.get(), &capability)};
138135

139136
Assert::AreEqual(error_ok, result);
140137
Assert::AreEqual(0UL, capability);
@@ -143,7 +140,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
143140
TEST_METHOD(QueryCapability_stream_argument_null) // NOLINT
144141
{
145142
DWORD capability;
146-
const hresult result{factory_.create_decoder()->QueryCapability(nullptr, &capability)};
143+
const auto result{factory_.create_decoder()->QueryCapability(nullptr, &capability)};
147144

148145
Assert::AreEqual(error_invalid_argument, result);
149146
}
@@ -154,7 +151,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
154151
stream.attach(SHCreateMemStream(nullptr, 0));
155152

156153
SUPPRESS_WARNING_6387_INVALID_ARGUMENT_NEXT_LINE
157-
const hresult result{factory_.create_decoder()->QueryCapability(stream.get(), nullptr)};
154+
const auto result{factory_.create_decoder()->QueryCapability(stream.get(), nullptr)};
158155

159156
Assert::AreEqual(error_pointer, result);
160157
}
@@ -165,7 +162,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
165162
check_hresult(
166163
SHCreateStreamOnFileEx(L"tulips-gray-8bit-512-512.pgm", STGM_READ | STGM_SHARE_DENY_WRITE, 0, false, nullptr, stream.put()));
167164
DWORD capability;
168-
const hresult result{factory_.create_decoder()->QueryCapability(stream.get(), &capability)};
165+
const auto result{factory_.create_decoder()->QueryCapability(stream.get(), &capability)};
169166

170167
Assert::AreEqual(error_ok, result);
171168
Assert::AreEqual(static_cast<DWORD>(WICBitmapDecoderCapabilityCanDecodeAllImages), capability);
@@ -176,7 +173,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
176173
com_ptr<IStream> stream{winrt::make<test_stream>(true, 2)};
177174

178175
DWORD capability;
179-
const hresult result = factory_.create_decoder()->QueryCapability(stream.get(), &capability);
176+
const auto result = factory_.create_decoder()->QueryCapability(stream.get(), &capability);
180177

181178
Assert::IsTrue(failed(result));
182179
}
@@ -186,7 +183,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
186183
com_ptr<IStream> stream{winrt::make<test_stream>(false, 1)};
187184

188185
DWORD capability;
189-
const hresult result = factory_.create_decoder()->QueryCapability(stream.get(), &capability);
186+
const auto result = factory_.create_decoder()->QueryCapability(stream.get(), &capability);
190187

191188
Assert::IsTrue(failed(result));
192189
}
@@ -196,7 +193,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
196193
com_ptr<IStream> stream{winrt::make<test_stream>(false, 2)};
197194

198195
DWORD capability;
199-
const hresult result = factory_.create_decoder()->QueryCapability(stream.get(), &capability);
196+
const auto result = factory_.create_decoder()->QueryCapability(stream.get(), &capability);
200197

201198
Assert::IsTrue(failed(result));
202199
}
@@ -206,7 +203,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
206203
com_ptr<IStream> stream;
207204
stream.attach(SHCreateMemStream(nullptr, 0));
208205

209-
const hresult result{factory_.create_decoder()->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
206+
const auto result{factory_.create_decoder()->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
210207
Assert::AreEqual(error_ok, result);
211208
}
212209

@@ -215,7 +212,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
215212
com_ptr<IStream> stream;
216213
stream.attach(SHCreateMemStream(nullptr, 0));
217214

218-
const hresult result{factory_.create_decoder()->Initialize(stream.get(), WICDecodeMetadataCacheOnLoad)};
215+
const auto result{factory_.create_decoder()->Initialize(stream.get(), WICDecodeMetadataCacheOnLoad)};
219216
Assert::AreEqual(error_ok, result);
220217
}
221218

@@ -225,7 +222,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
225222
stream.attach(SHCreateMemStream(nullptr, 0));
226223

227224
com_ptr<IWICBitmapDecoder> decoder = factory_.create_decoder();
228-
hresult result{decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
225+
auto result{decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
229226
Assert::AreEqual(error_ok, result);
230227

231228
result = decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnLoad);
@@ -237,15 +234,15 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
237234
com_ptr<IStream> stream;
238235
stream.attach(SHCreateMemStream(nullptr, 0));
239236

240-
const hresult result{factory_.create_decoder()->Initialize(stream.get(), static_cast<WICDecodeOptions>(4))};
237+
const auto result{factory_.create_decoder()->Initialize(stream.get(), static_cast<WICDecodeOptions>(4))};
241238

242239
// Cache options is not used by decoder and by design not validated.
243240
Assert::AreEqual(error_ok, result);
244241
}
245242

246243
TEST_METHOD(Initialize_null_stream) // NOLINT
247244
{
248-
const hresult result{factory_.create_decoder()->Initialize(nullptr, WICDecodeMetadataCacheOnDemand)};
245+
const auto result{factory_.create_decoder()->Initialize(nullptr, WICDecodeMetadataCacheOnDemand)};
249246
Assert::AreEqual(error_invalid_argument, result);
250247
}
251248

@@ -256,7 +253,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
256253
SHCreateStreamOnFileEx(L"tulips-gray-8bit-512-512.pgm", STGM_READ | STGM_SHARE_DENY_WRITE, 0, false, nullptr, stream.put()));
257254

258255
com_ptr<IWICBitmapDecoder> decoder = factory_.create_decoder();
259-
hresult result{decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
256+
auto result{decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
260257
Assert::AreEqual(error_ok, result);
261258

262259
uint32_t frame_count;
@@ -277,7 +274,7 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
277274
SHCreateStreamOnFileEx(L"tulips-gray-8bit-512-512.pgm", STGM_READ | STGM_SHARE_DENY_WRITE, 0, false, nullptr, stream.put()));
278275

279276
com_ptr<IWICBitmapDecoder> decoder = factory_.create_decoder();
280-
hresult result{decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
277+
auto result{decoder->Initialize(stream.get(), WICDecodeMetadataCacheOnDemand)};
281278
Assert::AreEqual(error_ok, result);
282279

283280
SUPPRESS_WARNING_6387_INVALID_ARGUMENT_NEXT_LINE
@@ -289,15 +286,15 @@ TEST_CLASS(netpbm_bitmap_decoder_test)
289286
TEST_METHOD(GetFrame_with_bad_index) // NOLINT
290287
{
291288
com_ptr<IWICBitmapFrameDecode> bitmap_frame_decode;
292-
const hresult result{factory_.create_decoder()->GetFrame(1, bitmap_frame_decode.put())};
289+
const auto result{factory_.create_decoder()->GetFrame(1, bitmap_frame_decode.put())};
293290

294291
Assert::AreEqual(wincodec::error_frame_missing, result);
295292
}
296293

297294
TEST_METHOD(GetFrame_not_initialized) // NOLINT
298295
{
299296
com_ptr<IWICBitmapFrameDecode> bitmap_frame_decode;
300-
const hresult result{factory_.create_decoder()->GetFrame(0, bitmap_frame_decode.put())};
297+
const auto result{factory_.create_decoder()->GetFrame(0, bitmap_frame_decode.put())};
301298

302299
Assert::AreEqual(wincodec::error_not_initialized, result);
303300
}

0 commit comments

Comments
 (0)