Skip to content

Commit d5992a5

Browse files
committed
Add test case 2 with optional data (from Windows)
1 parent 563c53b commit d5992a5

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

tests/test_data.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,65 @@ const unsigned char test_boot_data[TEST_BOOT_DATA_LENGTH] = {
4343

4444
const char* test_boot_name = "rEFInd Boot Manager";
4545
const char* test_boot_path = "\\EFI\\refind\\refind_x64.efi";
46+
47+
48+
#define TEST_BOOT_DATA2_LENGTH 300
49+
const unsigned char test_boot_data2[TEST_BOOT_DATA2_LENGTH] = {
50+
0x1, 0x0, 0x0, 0x0, // Attribute
51+
0x74, 0x0, // Device Path List length
52+
// Description
53+
0x57, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x77, 0x00, 0x73, 0x00, 0x20, 0x00,
54+
0x42, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x61, 0x00, 0x6e, 0x00,
55+
0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00, 0x00, 0x00,
56+
57+
// Device Path Header
58+
0x04, // Type
59+
0x01, // Subtype
60+
0x2a, 0x00, // Length
61+
// MEDIA, Hard Disk type:
62+
// uint32_t partition_number;
63+
0x02, 0x00, 0x00, 0x00,
64+
// uint64_t start;
65+
0x00, 0xa0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
66+
// uint64_t size;
67+
0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
68+
// uint8_t signature[16];
69+
0xd5, 0xdf, 0x32, 0x86, 0x0f, 0x91, 0x3d, 0x4b, 0xb2, 0x50, 0x2c, 0x7f, 0x17, 0x44, 0x15, 0x45,
70+
// uint8_t format;
71+
0x02, // GPT
72+
// uint8_t signature_type;
73+
0x02, // GUID
74+
// File Device Path Header
75+
0x04, // Type
76+
0x04, // Subtype
77+
0x46, 0x00, // Length
78+
0x5c, 0x00, 0x45, 0x00, 0x46, 0x00, 0x49, 0x00, 0x5c, 0x00,
79+
0x4d, 0x00, 0x69, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6f, 0x00,
80+
0x73, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x74, 0x00, 0x5c, 0x00,
81+
0x42, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x5c, 0x00,
82+
0x62, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x6d, 0x00,
83+
0x67, 0x00, 0x66, 0x00, 0x77, 0x00, 0x2e, 0x00, 0x65, 0x00,
84+
0x66, 0x00, 0x69, 0x00, 0x00, 0x00,
85+
// End Device Path Header
86+
0x7f, // Type
87+
0xff, // Subtype
88+
0x04, 0x00, // Length
89+
90+
0x57, 0x49, 0x4e, 0x44, 0x4f, 0x57, 0x53, 0x00, 0x01, 0x00,
91+
0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
92+
0x42, 0x00, 0x43, 0x00, 0x44, 0x00, 0x4f, 0x00, 0x42, 0x00,
93+
0x4a, 0x00, 0x45, 0x00, 0x43, 0x00, 0x54, 0x00, 0x3d, 0x00,
94+
0x7b, 0x00, 0x39, 0x00, 0x64, 0x00, 0x65, 0x00, 0x61, 0x00,
95+
0x38, 0x00, 0x36, 0x00, 0x32, 0x00, 0x63, 0x00, 0x2d, 0x00,
96+
0x35, 0x00, 0x63, 0x00, 0x64, 0x00, 0x64, 0x00, 0x2d, 0x00,
97+
0x34, 0x00, 0x65, 0x00, 0x37, 0x00, 0x30, 0x00, 0x2d, 0x00,
98+
0x61, 0x00, 0x63, 0x00, 0x63, 0x00, 0x31, 0x00, 0x2d, 0x00,
99+
0x66, 0x00, 0x33, 0x00, 0x32, 0x00, 0x62, 0x00, 0x33, 0x00,
100+
0x34, 0x00, 0x34, 0x00, 0x64, 0x00, 0x34, 0x00, 0x37, 0x00,
101+
0x39, 0x00, 0x35, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x49, 0x00,
102+
0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00,
103+
0x00, 0x00, 0x7f, 0xff, 0x04, 0x00
104+
};
105+
106+
const char* test_boot_name2 = "Windows Boot Manager";
107+
const char* test_boot_path2 = "\\EFI\\Microsoft\\Boot\\bootmgfw.efi";

tests/test_load_option_parsing.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TestLoadOptionParsing: public QObject
88
Q_OBJECT
99
private slots:
1010
void testParseTestBootData();
11+
void testParseTestBootData2();
1112
void testParseEmptyData();
1213
};
1314

@@ -37,6 +38,32 @@ void TestLoadOptionParsing::testParseTestBootData()
3738
}
3839
}
3940

41+
void TestLoadOptionParsing::testParseTestBootData2()
42+
{
43+
QByteArray data((const char *)test_boot_data2, TEST_BOOT_DATA2_LENGTH);
44+
QEFILoadOption loadOption(data);
45+
QVERIFY(loadOption.isVisible() == true);
46+
QVERIFY(loadOption.name() == QString(test_boot_name2));
47+
QVERIFY(loadOption.path() == QString(test_boot_path2));
48+
QVERIFY(loadOption.devicePathList().size() == 2);
49+
auto devicePathList = loadOption.devicePathList();
50+
for (int i = 0; i < devicePathList.size(); i++) {
51+
QSharedPointer<QEFIDevicePath> &dp = devicePathList[i];
52+
if (dp->type() == QEFIDevicePathType::DP_Media &&
53+
dp->subType() == QEFIDevicePathMediaSubType::MEDIA_HD) {
54+
QEFIDevicePathMediaHD *dpMediaHD =
55+
dynamic_cast<QEFIDevicePathMediaHD *>(dp.get());
56+
QVERIFY(dpMediaHD != nullptr);
57+
QVERIFY(dpMediaHD->signatureType() ==
58+
QEFIDevicePathMediaHD::QEFIDevicePathMediaHDSignatureType::GUID);
59+
QVERIFY(!dpMediaHD->gptGuid().isNull());
60+
QVERIFY(dpMediaHD->gptGuid() ==
61+
QUuid("8632dfd5-910f-4b3d-b250-2c7f17441545"));
62+
break;
63+
}
64+
}
65+
}
66+
4067
void TestLoadOptionParsing::testParseEmptyData()
4168
{
4269
QByteArray data;

tests/test_parse_boot_name.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TestParseBootName: public QObject
88
Q_OBJECT
99
private slots:
1010
void testParseTestBootData();
11+
void testParseTestBootData2();
1112
void testParseEmptyData();
1213
};
1314

@@ -18,6 +19,13 @@ void TestParseBootName::testParseTestBootData()
1819
QVERIFY(name == QString(test_boot_name));
1920
}
2021

22+
void TestParseBootName::testParseTestBootData2()
23+
{
24+
QByteArray data((const char *)test_boot_data2, TEST_BOOT_DATA2_LENGTH);
25+
QString name = qefi_extract_name(data);
26+
QVERIFY(name == QString(test_boot_name2));
27+
}
28+
2129
void TestParseBootName::testParseEmptyData()
2230
{
2331
QByteArray data;

tests/test_parse_boot_optional_data.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TestParseBootOptionalData: public QObject
88
Q_OBJECT
99
private slots:
1010
void testParseTestBootData();
11+
void testParseTestBootData2();
1112
void testParseEmptyData();
1213
};
1314

@@ -18,6 +19,13 @@ void TestParseBootOptionalData::testParseTestBootData()
1819
QVERIFY(optionalData.size() == 0);
1920
}
2021

22+
void TestParseBootOptionalData::testParseTestBootData2()
23+
{
24+
QByteArray data((const char *)test_boot_data2, TEST_BOOT_DATA2_LENGTH);
25+
QByteArray optionalData = qefi_extract_optional_data(data);
26+
QVERIFY(optionalData.size() == 136);
27+
}
28+
2129
void TestParseBootOptionalData::testParseEmptyData()
2230
{
2331
QByteArray data;

tests/test_parse_boot_path.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TestParseBootPath: public QObject
88
Q_OBJECT
99
private slots:
1010
void testParseTestBootData();
11+
void testParseTestBootData2();
1112
void testParseEmptyData();
1213
};
1314

@@ -18,6 +19,13 @@ void TestParseBootPath::testParseTestBootData()
1819
QVERIFY(path == QString(test_boot_path));
1920
}
2021

22+
void TestParseBootPath::testParseTestBootData2()
23+
{
24+
QByteArray data((const char *)test_boot_data2, TEST_BOOT_DATA2_LENGTH);
25+
QString path = qefi_extract_path(data);
26+
QVERIFY(path == QString(test_boot_path2));
27+
}
28+
2129
void TestParseBootPath::testParseEmptyData()
2230
{
2331
QByteArray data;

0 commit comments

Comments
 (0)