1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <sal/types.h>
11 
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <cppunit/plugin/TestPlugIn.h>
16 
17 #include <unotest/bootstrapfixturebase.hxx>
18 
19 #include <opengl/win/blocklist_parser.hxx>
20 
21 namespace
22 {
23 
24 class BlocklistParserTest : public test::BootstrapFixtureBase
25 {
26     void testParse();
27     void testEvaluate();
28 
29     CPPUNIT_TEST_SUITE(BlocklistParserTest);
30     CPPUNIT_TEST(testParse);
31     CPPUNIT_TEST(testEvaluate);
32     CPPUNIT_TEST_SUITE_END();
33 };
34 
testParse()35 void BlocklistParserTest::testParse()
36 {
37     std::vector<wgl::DriverInfo> aDriveInfos;
38 
39     WinBlocklistParser aBlocklistParser(m_directories.getURLFromSrc("vcl/qa/cppunit/") + "test_blocklist_parse.xml", aDriveInfos);
40     aBlocklistParser.parse();
41 
42     size_t const n = aDriveInfos.size();
43     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(16), n);
44 
45     size_t i = 0;
46 
47     for (bool bIsWhitelisted : {true, false})
48     {
49         wgl::DriverInfo& aDriveInfo = aDriveInfos[i++];
50         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
51         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorAll), aDriveInfo.maAdapterVendor); // "all"
52         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_LESS_THAN, aDriveInfo.meComparisonOp);
53         CPPUNIT_ASSERT_EQUAL(wgl::V(10,20,30,40), aDriveInfo.mnDriverVersion);
54 
55         aDriveInfo = aDriveInfos[i++];
56         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
57         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorNVIDIA), aDriveInfo.maAdapterVendor);
58         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_EQUAL, aDriveInfo.meComparisonOp);
59 
60         aDriveInfo = aDriveInfos[i++];
61         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
62         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorMicrosoft), aDriveInfo.maAdapterVendor);
63         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_NOT_EQUAL, aDriveInfo.meComparisonOp);
64 
65         aDriveInfo = aDriveInfos[i++];
66         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
67         CPPUNIT_ASSERT_EQUAL(OUString("0xcafe"), aDriveInfo.maAdapterVendor);
68         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_NOT_EQUAL, aDriveInfo.meComparisonOp);
69 
70         aDriveInfo = aDriveInfos[i++];
71         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
72         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorAll), aDriveInfo.maAdapterVendor);
73         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_BETWEEN_EXCLUSIVE, aDriveInfo.meComparisonOp);
74 
75         aDriveInfo = aDriveInfos[i++];
76         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
77         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorAll), aDriveInfo.maAdapterVendor);
78         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_BETWEEN_INCLUSIVE, aDriveInfo.meComparisonOp);
79 
80         aDriveInfo = aDriveInfos[i++];
81         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
82         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorAll), aDriveInfo.maAdapterVendor);
83         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_BETWEEN_INCLUSIVE_START, aDriveInfo.meComparisonOp);
84 
85         aDriveInfo = aDriveInfos[i++];
86         CPPUNIT_ASSERT_EQUAL(bIsWhitelisted, aDriveInfo.mbWhitelisted);
87         CPPUNIT_ASSERT_EQUAL(WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorAll), aDriveInfo.maAdapterVendor);
88         CPPUNIT_ASSERT_EQUAL(wgl::VersionComparisonOp::DRIVER_COMPARISON_IGNORED, aDriveInfo.meComparisonOp);
89     }
90 }
91 
testEvaluate()92 void BlocklistParserTest::testEvaluate()
93 {
94     std::vector<wgl::DriverInfo> aDriveInfos;
95 
96     WinBlocklistParser aBlocklistParser(m_directories.getURLFromSrc("vcl/qa/cppunit/") + "test_blocklist_evaluate.xml", aDriveInfos);
97     aBlocklistParser.parse();
98 
99     OUString vendorAMD = WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorAMD);
100     OUString vendorNVIDIA = WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorNVIDIA);
101     OUString vendorIntel = WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorIntel);
102     OUString vendorMicrosoft = WinOpenGLDeviceInfo::GetDeviceVendor(wgl::VendorMicrosoft);
103 
104     uint32_t const osWindows7 = 0x00060001;
105     uint32_t const osWindows8 = 0x00060002;
106     uint32_t const osWindows10 = 0x000A0000;
107 
108     // Check OS
109     CPPUNIT_ASSERT_EQUAL(false, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
110                                     aDriveInfos, "10.20.30.40", vendorNVIDIA, "all", osWindows7));
111     CPPUNIT_ASSERT_EQUAL(false, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
112                                     aDriveInfos, "10.20.30.40", vendorNVIDIA, "all", osWindows8));
113     CPPUNIT_ASSERT_EQUAL(false, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
114                                     aDriveInfos, "10.20.30.40", vendorNVIDIA, "all", osWindows10));
115 
116 
117     // Check Vendors
118     CPPUNIT_ASSERT_EQUAL(true, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
119                                     aDriveInfos, "10.20.30.40", vendorMicrosoft, "all", osWindows7));
120     CPPUNIT_ASSERT_EQUAL(true, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
121                                     aDriveInfos, "10.20.30.40", vendorMicrosoft, "all", osWindows10));
122 
123     // Check Versions
124     CPPUNIT_ASSERT_EQUAL(true, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
125                                     aDriveInfos, "10.20.30.39", vendorAMD, "all", osWindows7));
126     CPPUNIT_ASSERT_EQUAL(false, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
127                                     aDriveInfos, "10.20.30.40", vendorAMD, "all", osWindows7));
128     CPPUNIT_ASSERT_EQUAL(false, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
129                                     aDriveInfos, "10.20.30.41", vendorAMD, "all", osWindows7));
130 
131     // Check
132     CPPUNIT_ASSERT_EQUAL(true, WinOpenGLDeviceInfo::FindBlocklistedDeviceInList(
133                                     aDriveInfos, "9.17.10.4229", vendorIntel, "all", osWindows7));
134 
135 
136 }
137 
138 } // namespace
139 
140 CPPUNIT_TEST_SUITE_REGISTRATION(BlocklistParserTest);
141 
142 CPPUNIT_PLUGIN_IMPLEMENT();
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
145