1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Central place to house common unittest functionality for msf_lib.
16 :
17 : #ifndef SYZYGY_MSF_UNITTEST_UTIL_H_
18 : #define SYZYGY_MSF_UNITTEST_UTIL_H_
19 :
20 : #include "syzygy/msf/msf_decl.h"
21 : #include "syzygy/msf/msf_file.h"
22 :
23 : namespace testing {
24 :
25 : // Paths to various files.
26 : extern const wchar_t kTestPdbFilePath[];
27 :
28 : template <msf::MsfFileType T>
29 : void EnsureMsfContentsAreIdentical(
30 : const msf::detail::MsfFileImpl<T>& msf_file,
31 E : const msf::detail::MsfFileImpl<T>& msf_file_read) {
32 E : DCHECK_EQ(msf_file.StreamCount(), msf_file_read.StreamCount());
33 :
34 E : for (size_t i = 0; i < msf_file.StreamCount(); ++i) {
35 E : msf::detail::MsfStreamImpl<T>* stream = msf_file.GetStream(i).get();
36 : msf::detail::MsfStreamImpl<T>* stream_read =
37 E : msf_file_read.GetStream(i).get();
38 :
39 E : DCHECK_NE(static_cast<msf::detail::MsfStreamImpl<T>*>(nullptr), stream);
40 E : DCHECK_NE(static_cast<msf::detail::MsfStreamImpl<T>*>(nullptr),
41 : stream_read);
42 :
43 E : CHECK_EQ(stream->length(), stream_read->length());
44 :
45 E : std::vector<uint8> data;
46 E : std::vector<uint8> data_read;
47 E : CHECK(stream->Seek(0));
48 E : CHECK(stream_read->Seek(0));
49 E : CHECK(stream->Read(&data, stream->length()));
50 E : CHECK(stream_read->Read(&data_read, stream_read->length()));
51 :
52 : // We don't use ContainerEq because upon failure this generates a
53 : // ridiculously long and useless error message. We don't use memcmp because
54 : // it doesn't given any context as to where the failure occurs.
55 E : for (size_t j = 0; j < data.size(); ++j)
56 E : CHECK_EQ(data[j], data_read[j]);
57 E : }
58 E : }
59 :
60 : } // namespace testing
61 :
62 : #endif // SYZYGY_MSF_UNITTEST_UTIL_H_
|