Skip to content

Commit 85c2151

Browse files
committed
loader-test: Clang-tidy, with some manual adjustment afterward.
1 parent d14bd22 commit 85c2151

2 files changed

Lines changed: 42 additions & 53 deletions

File tree

src/tests/loader_test/loader_test.cpp

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool DetectInstalledRuntime() {
7777
std::vector<XrExtensionProperties> properties;
7878
properties.resize(ext_count);
7979
for (uint32_t prop = 0; prop < ext_count; ++prop) {
80-
properties[prop] = {XR_TYPE_EXTENSION_PROPERTIES, nullptr, 0, 0};
80+
properties[prop] = {XR_TYPE_EXTENSION_PROPERTIES, nullptr, {0, 0}};
8181
}
8282
ret = xrEnumerateInstanceExtensionProperties(nullptr, ext_count, &ext_count, properties.data());
8383
if (XR_FAILED(ret)) {
@@ -93,14 +93,14 @@ bool DetectInstalledRuntime() {
9393
#endif // XR_USE_GRAPHICS_API_D3D11
9494

9595
#ifdef XR_USE_GRAPHICS_API_VULKAN
96-
if (!strcmp(properties[ext].extensionName, XR_KHR_VULKAN_ENABLE_EXTENSION_NAME)) {
96+
if (strcmp(properties[ext].extensionName, XR_KHR_VULKAN_ENABLE_EXTENSION_NAME) == 0) {
9797
g_graphics_api_to_use = GRAPHICS_API_VULKAN;
9898
break;
9999
}
100100
#endif // XR_USE_GRAPHICS_API_VULKAN
101101

102102
#ifdef XR_USE_GRAPHICS_API_OPENGL
103-
if (!strcmp(properties[ext].extensionName, XR_KHR_OPENGL_ENABLE_EXTENSION_NAME)) {
103+
if (strcmp(properties[ext].extensionName, XR_KHR_OPENGL_ENABLE_EXTENSION_NAME) == 0) {
104104
g_graphics_api_to_use = GRAPHICS_API_OPENGL;
105105
break;
106106
}
@@ -109,7 +109,7 @@ bool DetectInstalledRuntime() {
109109

110110
// While we're here, also check for debug utils support
111111
for (uint32_t ext = 0; ext < ext_count; ext++) {
112-
if (!strcmp(properties[ext].extensionName, XR_EXT_DEBUG_UTILS_EXTENSION_NAME)) {
112+
if (strcmp(properties[ext].extensionName, XR_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) {
113113
g_debug_utils_exists = true;
114114
break;
115115
}
@@ -170,7 +170,7 @@ void TestEnumLayers(uint32_t& total, uint32_t& passed, uint32_t& skipped, uint32
170170
out_layer_value = 0;
171171
layer_props.resize(in_layer_value);
172172
for (uint32_t prop = 0; prop < in_layer_value; ++prop) {
173-
layer_props[prop] = {XR_TYPE_API_LAYER_PROPERTIES, nullptr, 0, 0};
173+
layer_props[prop] = {XR_TYPE_API_LAYER_PROPERTIES, nullptr, {0, 0}};
174174
}
175175
local_total++;
176176
cout << " " << subtest_name << " layer props query: ";
@@ -215,7 +215,7 @@ void TestEnumLayers(uint32_t& total, uint32_t& passed, uint32_t& skipped, uint32
215215
out_layer_value = 0;
216216
layer_props.resize(in_layer_value);
217217
for (uint32_t prop = 0; prop < in_layer_value; ++prop) {
218-
layer_props[prop] = {XR_TYPE_API_LAYER_PROPERTIES, nullptr, 0, 0};
218+
layer_props[prop] = {XR_TYPE_API_LAYER_PROPERTIES, nullptr, {0, 0}};
219219
}
220220
local_total++;
221221
cout << " " << subtest_name << " layer props query: ";
@@ -393,7 +393,7 @@ void TestEnumInstanceExtensions(uint32_t& total, uint32_t& passed, uint32_t& ski
393393
// Get the properties
394394
properties.resize(out_extension_value);
395395
for (uint32_t prop = 0; prop < out_extension_value; ++prop) {
396-
properties[prop] = {XR_TYPE_EXTENSION_PROPERTIES, nullptr, 0, 0};
396+
properties[prop] = {XR_TYPE_EXTENSION_PROPERTIES, nullptr, {0, 0}};
397397
}
398398
in_extension_value = out_extension_value;
399399
out_extension_value = 0;
@@ -408,7 +408,9 @@ void TestEnumInstanceExtensions(uint32_t& total, uint32_t& passed, uint32_t& ski
408408
bool found_error = false;
409409
for (XrExtensionProperties prop : properties) {
410410
// Just check if extension name begins with "XR_"
411-
if (strlen(prop.extensionName) < 4 || 0 != strncmp(prop.extensionName, "XR_", 3)) found_error = true;
411+
if (strlen(prop.extensionName) < 4 || 0 != strncmp(prop.extensionName, "XR_", 3)) {
412+
found_error = true;
413+
}
412414
}
413415

414416
if (found_error) {
@@ -764,7 +766,7 @@ DEFINE_TEST(TestCreateDestroySession) {
764766
XrSystemId systemId;
765767
TEST_EQUAL(xrGetSystem(instance, &system_get_info, &systemId), XR_SUCCESS, "xrGetSystem");
766768

767-
if (systemId) {
769+
if (systemId != XR_NULL_SYSTEM_ID) {
768770
void* graphics_binding = nullptr;
769771

770772
#ifdef XR_USE_GRAPHICS_API_VULKAN
@@ -885,7 +887,7 @@ DEFINE_TEST(TestCreateDestroySession) {
885887
}
886888
#endif // XR_USE_GRAPHICS_API_D3D11
887889

888-
if (graphics_binding) {
890+
if (graphics_binding != nullptr) {
889891
// Create a session for us to begin
890892
XrSession session;
891893
XrSessionCreateInfo session_create_info = {};
@@ -919,7 +921,7 @@ static uint64_t object_handle;
919921
static char object_name[64];
920922
static uint32_t num_objects = 0;
921923
const char test_message[] = "This is a test message - 1 . 2! 3";
922-
static void* expected_user_value = NULL;
924+
static void* expected_user_value = nullptr;
923925
static bool captured_error = false;
924926
static bool captured_warning = false;
925927
static bool captured_info = false;
@@ -949,21 +951,17 @@ static bool g_captured_only_expected_labels = false;
949951
XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT messageSeverity,
950952
XrDebugUtilsMessageTypeFlagsEXT messageType,
951953
const XrDebugUtilsMessengerCallbackDataEXT* callbackData, void* userData) {
952-
if (expected_user_value == userData) {
953-
user_data_correct = true;
954-
} else {
955-
user_data_correct = false;
956-
}
954+
user_data_correct = (expected_user_value == userData);
957955

958-
if (!strcmp(callbackData->functionName, test_function_name)) {
956+
if (strcmp(callbackData->functionName, test_function_name) == 0) {
959957
function_matches = true;
960958
}
961959

962-
if (!strcmp(callbackData->messageId, message_id)) {
960+
if (strcmp(callbackData->messageId, message_id) == 0) {
963961
message_id_matches = true;
964962
}
965963

966-
if (!strcmp(callbackData->message, test_message)) {
964+
if (strcmp(callbackData->message, test_message) == 0) {
967965
message_matches = true;
968966
}
969967

@@ -1022,7 +1020,7 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
10221020
if (callbackData->objects[0].type == XR_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT &&
10231021
callbackData->objects[0].next == nullptr && callbackData->objects[0].objectType == XR_OBJECT_TYPE_INSTANCE &&
10241022
callbackData->objects[0].objectHandle == object_handle &&
1025-
!strcmp(callbackData->objects[0].objectName, object_name)) {
1023+
(strcmp(callbackData->objects[0].objectName, object_name) == 0)) {
10261024
object_contents_match = true;
10271025
}
10281026
}
@@ -1036,8 +1034,8 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
10361034
// Should not have any label region in list
10371035
bool found_invalid = false;
10381036
for (uint32_t label_index = 0; label_index < callbackData->sessionLabelCount; ++label_index) {
1039-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_second_label_region_name) ||
1040-
!strcmp(callbackData->sessionLabels[label_index].labelName, g_first_label_region_name)) {
1037+
if ((strcmp(callbackData->sessionLabels[label_index].labelName, g_second_label_region_name) == 0) ||
1038+
(strcmp(callbackData->sessionLabels[label_index].labelName, g_first_label_region_name) == 0)) {
10411039
found_invalid = true;
10421040
}
10431041
}
@@ -1048,19 +1046,19 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
10481046
// Should have g_second_label_region_name in list
10491047
// Should have g_first_label_region_name in list
10501048
if (callbackData->sessionLabelCount >= 2 &&
1051-
(!strcmp(callbackData->sessionLabels[0].labelName, g_second_label_region_name) &&
1052-
!strcmp(callbackData->sessionLabels[1].labelName, g_first_label_region_name))) {
1049+
((strcmp(callbackData->sessionLabels[0].labelName, g_second_label_region_name) == 0) &&
1050+
(strcmp(callbackData->sessionLabels[1].labelName, g_first_label_region_name) == 0))) {
10531051
g_captured_only_expected_labels = true;
10541052
}
10551053
} else if (g_in_region_num == 1) {
10561054
// Should not have g_second_label_region_name in list
10571055
// Should have g_first_label_region_name in list
10581056
if (callbackData->sessionLabelCount >= 2 &&
1059-
(strcmp(callbackData->sessionLabels[0].labelName, g_second_label_region_name) &&
1060-
!strcmp(callbackData->sessionLabels[1].labelName, g_first_label_region_name))) {
1057+
(strcmp(callbackData->sessionLabels[0].labelName, g_second_label_region_name) != 0) &&
1058+
(strcmp(callbackData->sessionLabels[1].labelName, g_first_label_region_name) == 0)) {
10611059
g_captured_only_expected_labels = true;
10621060
} else if (callbackData->sessionLabelCount >= 1 &&
1063-
!strcmp(callbackData->sessionLabels[0].labelName, g_first_label_region_name)) {
1061+
(strcmp(callbackData->sessionLabels[0].labelName, g_first_label_region_name) == 0)) {
10641062
g_captured_only_expected_labels = true;
10651063
}
10661064
}
@@ -1069,9 +1067,9 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
10691067
// Should not have any individual label in list
10701068
bool found_invalid = false;
10711069
for (uint32_t label_index = 0; label_index < callbackData->sessionLabelCount; ++label_index) {
1072-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) ||
1073-
!strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name) ||
1074-
!strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name)) {
1070+
if ((strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) == 0) ||
1071+
(strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name) == 0) ||
1072+
(strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name) == 0)) {
10751073
found_invalid = true;
10761074
}
10771075
}
@@ -1086,11 +1084,11 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
10861084
bool found_invalid = false;
10871085
bool found_valid = false;
10881086
for (uint32_t label_index = 0; label_index < callbackData->sessionLabelCount; ++label_index) {
1089-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name) ||
1090-
!strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name)) {
1087+
if ((strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name) == 0) ||
1088+
(strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name) == 0)) {
10911089
found_invalid = true;
10921090
}
1093-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name)) {
1091+
if (strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) == 0) {
10941092
found_valid = true;
10951093
}
10961094
}
@@ -1104,11 +1102,11 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
11041102
bool found_invalid = false;
11051103
bool found_valid = false;
11061104
for (uint32_t label_index = 0; label_index < callbackData->sessionLabelCount; ++label_index) {
1107-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) ||
1108-
!strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name)) {
1105+
if ((strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) == 0) ||
1106+
(strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name) == 0)) {
11091107
found_invalid = true;
11101108
}
1111-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name)) {
1109+
if (strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name) == 0) {
11121110
found_valid = true;
11131111
}
11141112
}
@@ -1122,11 +1120,11 @@ XrBool32 XRAPI_PTR TestDebugUtilsCallback(XrDebugUtilsMessageSeverityFlagsEXT me
11221120
bool found_invalid = false;
11231121
bool found_valid = false;
11241122
for (uint32_t label_index = 0; label_index < callbackData->sessionLabelCount; ++label_index) {
1125-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) ||
1126-
!strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name)) {
1123+
if ((strcmp(callbackData->sessionLabels[label_index].labelName, g_first_individual_label_name) == 0) ||
1124+
(strcmp(callbackData->sessionLabels[label_index].labelName, g_second_individual_label_name) == 0)) {
11271125
found_invalid = true;
11281126
}
1129-
if (!strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name)) {
1127+
if (strcmp(callbackData->sessionLabels[label_index].labelName, g_third_individual_label_name) == 0) {
11301128
found_valid = true;
11311129
}
11321130
}
@@ -1725,7 +1723,7 @@ DEFINE_TEST(TestDebugUtils) {
17251723
XrSystemId systemId;
17261724
TEST_EQUAL(xrGetSystem(instance, &system_get_info, &systemId), XR_SUCCESS, "xrGetSystem");
17271725

1728-
if (systemId) {
1726+
if (systemId != XR_NULL_SYSTEM_ID) {
17291727
void* graphics_binding = nullptr;
17301728

17311729
#ifdef XR_USE_GRAPHICS_API_VULKAN
@@ -2118,8 +2116,7 @@ int main(int argc, char* argv[]) {
21182116
if (total_failed > 0) {
21192117
cout << "Failed" << endl;
21202118
return -1;
2121-
} else {
2122-
cout << "Passed" << endl;
2123-
return 0;
21242119
}
2120+
cout << "Passed" << endl;
2121+
return 0;
21252122
}

src/tests/loader_test/loader_test_utils.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ bool LoaderTestUnsetEnvironmentVariable(const std::string &variable) {
5353
#elif defined(XR_OS_LINUX)
5454

5555
bool LoaderTestSetEnvironmentVariable(const std::string &variable, const std::string &value) {
56-
if (0 == setenv(variable.c_str(), value.c_str(), 1)) {
57-
return true;
58-
}
59-
return false;
56+
return 0 == setenv(variable.c_str(), value.c_str(), 1);
6057
}
6158

6259
bool LoaderTestGetEnvironmentVariable(const std::string &variable, std::string &value) {
@@ -68,12 +65,7 @@ bool LoaderTestGetEnvironmentVariable(const std::string &variable, std::string &
6865
return true;
6966
}
7067

71-
bool LoaderTestUnsetEnvironmentVariable(const std::string &variable) {
72-
if (0 == unsetenv(variable.c_str())) {
73-
return true;
74-
}
75-
return false;
76-
}
68+
bool LoaderTestUnsetEnvironmentVariable(const std::string &variable) { return 0 == unsetenv(variable.c_str()); }
7769

7870
#elif defined(XR_OS_APPLE)
7971

0 commit comments

Comments
 (0)