tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / vcl / qa / cppunit / blocklistparsertest.cxx
blobd0592f33c975e1739d2375f723f3e722334c7e5f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/types.h>
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <cppunit/plugin/TestPlugIn.h>
17 #include <unotest/bootstrapfixturebase.hxx>
19 #include <driverblocklist.hxx>
21 using namespace DriverBlocklist;
23 namespace
26 class BlocklistParserTest : public test::BootstrapFixtureBase
28 void testParse();
29 void testEvaluate();
30 void testVulkan();
32 CPPUNIT_TEST_SUITE(BlocklistParserTest);
33 CPPUNIT_TEST(testParse);
34 CPPUNIT_TEST(testEvaluate);
35 CPPUNIT_TEST(testVulkan);
36 CPPUNIT_TEST_SUITE_END();
39 void BlocklistParserTest::testParse()
41 std::vector<DriverInfo> aDriveInfos;
43 Parser aBlocklistParser(m_directories.getURLFromSrc(u"vcl/qa/cppunit/") + "test_blocklist_parse.xml",
44 aDriveInfos, VersionType::OpenGL);
45 aBlocklistParser.parse();
47 size_t const n = aDriveInfos.size();
48 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(16), n);
50 size_t i = 0;
52 for (bool bIsAllowlisted : {true, false})
54 DriverInfo& aDriveInfo = aDriveInfos[i++];
55 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
56 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorAll), aDriveInfo.maAdapterVendor); // "all"
57 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_LESS_THAN, aDriveInfo.meComparisonOp);
58 CPPUNIT_ASSERT_EQUAL(OpenGLVersion(10,20,30,40), aDriveInfo.mnDriverVersion);
60 aDriveInfo = aDriveInfos[i++];
61 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
62 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorNVIDIA), aDriveInfo.maAdapterVendor);
63 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_EQUAL, aDriveInfo.meComparisonOp);
65 aDriveInfo = aDriveInfos[i++];
66 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
67 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorMicrosoft), aDriveInfo.maAdapterVendor);
68 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_NOT_EQUAL, aDriveInfo.meComparisonOp);
70 aDriveInfo = aDriveInfos[i++];
71 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
72 CPPUNIT_ASSERT_EQUAL(u"0xcafe"_ustr, aDriveInfo.maAdapterVendor);
73 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_NOT_EQUAL, aDriveInfo.meComparisonOp);
75 aDriveInfo = aDriveInfos[i++];
76 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
77 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorAll), aDriveInfo.maAdapterVendor);
78 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_BETWEEN_EXCLUSIVE, aDriveInfo.meComparisonOp);
80 aDriveInfo = aDriveInfos[i++];
81 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
82 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorAll), aDriveInfo.maAdapterVendor);
83 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_BETWEEN_INCLUSIVE, aDriveInfo.meComparisonOp);
85 aDriveInfo = aDriveInfos[i++];
86 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
87 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorAll), aDriveInfo.maAdapterVendor);
88 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_BETWEEN_INCLUSIVE_START, aDriveInfo.meComparisonOp);
90 aDriveInfo = aDriveInfos[i++];
91 CPPUNIT_ASSERT_EQUAL(bIsAllowlisted, aDriveInfo.mbAllowlisted);
92 CPPUNIT_ASSERT_EQUAL(GetVendorId(VendorAll), aDriveInfo.maAdapterVendor);
93 CPPUNIT_ASSERT_EQUAL(VersionComparisonOp::DRIVER_COMPARISON_IGNORED, aDriveInfo.meComparisonOp);
97 void BlocklistParserTest::testEvaluate()
99 std::vector<DriverInfo> aDriveInfos;
101 Parser aBlocklistParser(m_directories.getURLFromSrc(u"vcl/qa/cppunit/") + "test_blocklist_evaluate.xml",
102 aDriveInfos, VersionType::OpenGL);
103 aBlocklistParser.parse();
105 OUString vendorAMD = GetVendorId(VendorAMD);
106 OUString vendorNVIDIA = GetVendorId(VendorNVIDIA);
107 OUString vendorIntel = GetVendorId(VendorIntel);
108 OUString vendorMicrosoft = GetVendorId(VendorMicrosoft);
110 // Check OS
111 CPPUNIT_ASSERT_EQUAL(false, FindBlocklistedDeviceInList(
112 aDriveInfos, VersionType::OpenGL, u"10.20.30.40", vendorNVIDIA, u"all"_ustr, DRIVER_OS_WINDOWS_10));
114 // Check generic OS
115 CPPUNIT_ASSERT_EQUAL(false, FindBlocklistedDeviceInList(
116 aDriveInfos, VersionType::OpenGL, u"10.20.30.50", vendorMicrosoft, u"all"_ustr, DRIVER_OS_WINDOWS_10));
117 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
118 aDriveInfos, VersionType::OpenGL, u"10.20.30.50", vendorMicrosoft, u"all"_ustr, DRIVER_OS_LINUX));
119 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
120 aDriveInfos, VersionType::OpenGL, u"10.20.30.50", vendorMicrosoft, u"all"_ustr, DRIVER_OS_OSX_10_7));
121 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
122 aDriveInfos, VersionType::OpenGL, u"10.20.30.50", vendorMicrosoft, u"all"_ustr, DRIVER_OS_OSX_10_8));
124 // Check Vendors
125 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
126 aDriveInfos, VersionType::OpenGL, u"10.20.30.40", vendorMicrosoft, u"all"_ustr, DRIVER_OS_WINDOWS_10));
128 // Check Versions
129 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
130 aDriveInfos, VersionType::OpenGL, u"10.20.30.39", vendorAMD, u"all"_ustr, DRIVER_OS_WINDOWS_10));
131 CPPUNIT_ASSERT_EQUAL(false, FindBlocklistedDeviceInList(
132 aDriveInfos, VersionType::OpenGL, u"10.20.30.40", vendorAMD, u"all"_ustr, DRIVER_OS_WINDOWS_10));
133 CPPUNIT_ASSERT_EQUAL(false, FindBlocklistedDeviceInList(
134 aDriveInfos, VersionType::OpenGL, u"10.20.30.41", vendorAMD, u"all"_ustr, DRIVER_OS_WINDOWS_10));
136 // Check
137 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
138 aDriveInfos, VersionType::OpenGL, u"9.17.10.4229", vendorIntel, u"all"_ustr, DRIVER_OS_WINDOWS_10));
143 void BlocklistParserTest::testVulkan()
145 std::vector<DriverInfo> aDriveInfos;
147 Parser aBlocklistParser(m_directories.getURLFromSrc(u"vcl/qa/cppunit/") + "test_blocklist_vulkan.xml",
148 aDriveInfos, VersionType::Vulkan);
149 aBlocklistParser.parse();
151 OUString vendorAMD = GetVendorId(VendorAMD);
153 // Check Versions
154 CPPUNIT_ASSERT_EQUAL(false, FindBlocklistedDeviceInList(
155 aDriveInfos, VersionType::Vulkan, u"1.2.3", vendorAMD, u"all"_ustr, DRIVER_OS_ALL));
156 CPPUNIT_ASSERT_EQUAL(true, FindBlocklistedDeviceInList(
157 aDriveInfos, VersionType::Vulkan, u"1.2.2", vendorAMD, u"all"_ustr, DRIVER_OS_ALL));
158 CPPUNIT_ASSERT_EQUAL(false, FindBlocklistedDeviceInList(
159 aDriveInfos, VersionType::Vulkan, u"1.2.20", vendorAMD, u"all"_ustr, DRIVER_OS_ALL));
162 } // namespace
164 CPPUNIT_TEST_SUITE_REGISTRATION(BlocklistParserTest);
166 CPPUNIT_PLUGIN_IMPLEMENT();
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */