Skip to content

Commit aae4902

Browse files
committed
tests: Add a few util tests
1 parent 85f5cf3 commit aae4902

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

tests/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include "../inc/catch_amalgamated.hpp"
33
#include "section_listener.h"
44

5-
CATCH_REGISTER_TAG_ALIAS("[@unit-tests]", "[d3d],[d3d11],[d3d12],[drs],[sysinfo],[sysinfo-topo],[sysinfo-nvml],[sysinfo-hdr]")
5+
CATCH_REGISTER_TAG_ALIAS("[@unit-tests]", "[d3d],[d3d11],[d3d12],[drs],[sysinfo],[sysinfo-topo],[sysinfo-nvml],[sysinfo-hdr],[util]")
66
CATCH_REGISTER_TAG_ALIAS("[@system]", "[system]")
7-
CATCH_REGISTER_TAG_ALIAS("[@all]", "[d3d],[d3d11],[d3d12],[drs],[sysinfo],[sysinfo-topo],[sysinfo-nvml],[sysinfo-hdr],[system]")
7+
CATCH_REGISTER_TAG_ALIAS("[@all]", "[d3d],[d3d11],[d3d12],[drs],[sysinfo],[sysinfo-topo],[sysinfo-nvml],[sysinfo-hdr],[util],[system]")
88

99
CATCH_REGISTER_LISTENER(SectionListener)

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ nvapi_tests_src = files([
3939
'nvapi_sysinfo_nvml.cpp',
4040
'nvapi_sysinfo_hdr.cpp',
4141
'nvapi_system.cpp',
42+
'util.cpp',
4243
])
4344

4445
nvapi_exe = executable('nvapi'+target_suffix+'-tests', [ nvapi_src, catch2_src, nvapi_tests_src, dxvk_nvapi_version ],

tests/util.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "nvapi_tests_private.h"
2+
#include "../src/util/util_string.h"
3+
#include "../src/util/util_version.h"
4+
5+
using namespace Catch::Matchers;
6+
7+
TEST_CASE("String", "[.util]") {
8+
SECTION("NVAPI Unicode-String") {
9+
NvAPI_UnicodeString us = {'U', 'n', 'i', 'c', 'o', 'd', 'e'};
10+
REQUIRE(dxvk::str::fromnvus(us) == std::string("Unicode"));
11+
}
12+
13+
SECTION("NVAPI Short-String") {
14+
NvAPI_ShortString ss{};
15+
16+
dxvk::str::tonvss(ss, std::string("Short-String"));
17+
REQUIRE_THAT(ss, Equals("Short-String"));
18+
19+
dxvk::str::tonvss(ss, std::string("Longer-Than-Short-String-Longer-Than-Short-String-Longer-Than-Short-String"));
20+
REQUIRE_THAT(ss, SizeIs(64));
21+
}
22+
}
23+
24+
TEST_CASE("Version", "[.util]") {
25+
SECTION("Vulkan version packing") {
26+
struct Data {
27+
uint32_t driverVersion;
28+
uint32_t major;
29+
uint32_t minor;
30+
uint32_t patch;
31+
};
32+
auto args = GENERATE(
33+
Data{0x0, 0x0, 0x0, 0x0},
34+
Data{0xffffffff, 0x3ff, 0xff, 0xff},
35+
Data{0x85eac100, 535, 171, 04});
36+
37+
REQUIRE(dxvk::nvVersionMajor(args.driverVersion) == args.major);
38+
REQUIRE(dxvk::nvVersionMinor(args.driverVersion) == args.minor);
39+
REQUIRE(dxvk::nvVersionPatch(args.driverVersion) == args.patch);
40+
}
41+
42+
SECTION("Make Vulkan version") {
43+
REQUIRE(dxvk::nvMakeVersion(0xffff, 0xffff, 0xffff) == 0xffffffc0);
44+
}
45+
}

0 commit comments

Comments
 (0)