| Index: base/win/pe_image_unittest.cc
|
| diff --git a/base/win/pe_image_unittest.cc b/base/win/pe_image_unittest.cc
|
| index f0fb61d23ff187fb71285c54e413c5197cb44b51..e308eaea77e2e9425152aa60d9619e3da52c83a9 100644
|
| --- a/base/win/pe_image_unittest.cc
|
| +++ b/base/win/pe_image_unittest.cc
|
| @@ -83,6 +83,16 @@ bool DelayImportChunksCallback(const PEImage &image,
|
| return true;
|
| }
|
|
|
| +// Identifiers for the set of supported expectations.
|
| +enum ExpectationSet {
|
| + WIN_2K_SET,
|
| + WIN_XP_SET,
|
| + WIN_VISTA_SET,
|
| + WIN_7_SET,
|
| + WIN_8_SET,
|
| + UNSUPPORTED_SET,
|
| +};
|
| +
|
| // We'll be using some known values for the tests.
|
| enum Value {
|
| sections = 0,
|
| @@ -94,6 +104,20 @@ enum Value {
|
| relocs
|
| };
|
|
|
| +ExpectationSet GetExpectationSet(DWORD os) {
|
| + if (os == 50)
|
| + return WIN_2K_SET;
|
| + if (os == 51)
|
| + return WIN_XP_SET;
|
| + if (os == 60)
|
| + return WIN_VISTA_SET;
|
| + if (os == 61)
|
| + return WIN_7_SET;
|
| + if (os >= 62)
|
| + return WIN_8_SET;
|
| + return UNSUPPORTED_SET;
|
| +}
|
| +
|
| // Retrieves the expected value from advapi32.dll based on the OS.
|
| int GetExpectedValue(Value value, DWORD os) {
|
| const int xp_delay_dlls = 2;
|
| @@ -143,31 +167,24 @@ int GetExpectedValue(Value value, DWORD os) {
|
| vista_delay_imports, win7_delay_imports, win8_delay_imports},
|
| {w2k_relocs, xp_relocs, vista_relocs, win7_relocs, win8_relocs}
|
| };
|
| + COMPILE_ASSERT(arraysize(expected[0]) == UNSUPPORTED_SET,
|
| + expected_value_set_mismatch);
|
|
|
| if (value > relocs)
|
| return 0;
|
| - if (50 == os)
|
| - os = 0; // 5.0
|
| - else if (51 == os || 52 == os)
|
| - os = 1;
|
| - else if (os == 60)
|
| - os = 2; // 6.x
|
| - else if (os == 61)
|
| - os = 3;
|
| - else if (os >= 62)
|
| - os = 4;
|
| - else
|
| - return 0;
|
| + ExpectationSet expected_set = GetExpectationSet(os);
|
| + if (expected_set >= arraysize(expected)) {
|
| + // This should never happen. Log a failure if it does.
|
| + EXPECT_NE(UNSUPPORTED_SET, expected_set);
|
| + expected_set = WIN_2K_SET;
|
| + }
|
|
|
| - return expected[value][os];
|
| + return expected[value][expected_set];
|
| }
|
|
|
| // Tests that we are able to enumerate stuff from a PE file, and that
|
| // the actual number of items found is within the expected range.
|
| TEST(PEImageTest, EnumeratesPE) {
|
| - // Windows Server 2003 is not supported as a test environment for this test.
|
| - if (base::win::GetVersion() == base::win::VERSION_SERVER_2003)
|
| - return;
|
| HMODULE module = LoadLibrary(L"advapi32.dll");
|
| ASSERT_TRUE(NULL != module);
|
|
|
| @@ -178,6 +195,10 @@ TEST(PEImageTest, EnumeratesPE) {
|
| DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion;
|
| os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion;
|
|
|
| + // Skip this test for unsupported OS versions.
|
| + if (GetExpectationSet(os) == UNSUPPORTED_SET)
|
| + return;
|
| +
|
| pe.EnumSections(SectionsCallback, &count);
|
| EXPECT_EQ(GetExpectedValue(sections, os), count);
|
|
|
|
|