Skip to content

Commit

Permalink
Fix ktx_strncasecmp (#741)
Browse files Browse the repository at this point in the history
Fixes #740.
  • Loading branch information
Császár Mátyás authored Jul 17, 2023
1 parent 3153e94 commit 1ae04f8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/mkvkformatfiles
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ END {
begin_str2vk = begin_str2vk " ++us2;\n"
begin_str2vk = begin_str2vk " --length;\n"
begin_str2vk = begin_str2vk " }\n"
begin_str2vk = begin_str2vk " if (length == 0)\n"
begin_str2vk = begin_str2vk " return 0;\n"
begin_str2vk = begin_str2vk " return tolower(*us1) - tolower(*us2);\n"
begin_str2vk = begin_str2vk "}\n"
begin_str2vk = begin_str2vk "\n"
Expand Down
2 changes: 2 additions & 0 deletions lib/vkformat_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ static int ktx_strncasecmp(const char* s1, const char* s2, int length) {
++us2;
--length;
}
if (length == 0)
return 0;
return tolower(*us1) - tolower(*us2);
}

Expand Down
1 change: 1 addition & 0 deletions tests/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_subdirectory(streamtests)
add_executable( unittests
unittests/image_unittests.cc
unittests/test_fragment_uri.cc
unittests/test_string_to_vkformat.cc
unittests/unittests.cc
unittests/wthelper.h
tests.cmake
Expand Down
8 changes: 3 additions & 5 deletions tests/unittests/test_fragment_uri.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* -*- tab-width: 4; -*- */
/* vi: set sw=2 ts=4 expandtab: */

/*
* Copyright 2010-2020 Mark Callow.
* SPDX-License-Identifier: Apache-2.0
*/
// Copyright 2022-2023 The Khronos Group Inc.
// Copyright 2022-2023 RasterGrid Kft.
// SPDX-License-Identifier: Apache-2.0

#include <ktx/fragment_uri.h>
#include "gtest/gtest.h"
Expand Down
54 changes: 54 additions & 0 deletions tests/unittests/test_string_to_vkformat.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* -*- tab-width: 4; -*- */
/* vi: set sw=2 ts=4 expandtab: */
// Copyright 2022-2023 The Khronos Group Inc.
// Copyright 2022-2023 RasterGrid Kft.
// SPDX-License-Identifier: Apache-2.0

#include "vkformat_enum.h"
#include "gtest/gtest.h"


extern "C" {
VkFormat stringToVkFormat(const char* str);
}

// -------------------------------------------------------------------------------------------------

class StringToVkFormatTest : public ::testing::Test {
protected:
StringToVkFormatTest() {}
};

// -------------------------------------------------------------------------------------------------

namespace {

TEST_F(StringToVkFormatTest, stringToVkFormat) {
EXPECT_EQ(stringToVkFormat("UNDEFINED"), VK_FORMAT_UNDEFINED);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_UNDEFINED"), VK_FORMAT_UNDEFINED);
EXPECT_EQ(stringToVkFormat("Not a format"), VK_FORMAT_UNDEFINED);

EXPECT_EQ(stringToVkFormat("R4G4_UNORM_PACK8"), VK_FORMAT_R4G4_UNORM_PACK8);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_R4G4_UNORM_PACK8"), VK_FORMAT_R4G4_UNORM_PACK8);

EXPECT_EQ(stringToVkFormat("R8G8B8_UNORM"), VK_FORMAT_R8G8B8_UNORM);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_R8G8B8_UNORM"), VK_FORMAT_R8G8B8_UNORM);
EXPECT_EQ(stringToVkFormat("R8G8B8_SNORM"), VK_FORMAT_R8G8B8_SNORM);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_R8G8B8_SNORM"), VK_FORMAT_R8G8B8_SNORM);

EXPECT_EQ(stringToVkFormat("ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
EXPECT_EQ(stringToVkFormat("ASTC_6X6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
EXPECT_EQ(stringToVkFormat("astc_6x6_unorm_block"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6X6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6X6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
EXPECT_EQ(stringToVkFormat("vk_format_astc_6x6_unorm_block"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);

EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6x6_UNORM"), VK_FORMAT_UNDEFINED);
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6x6_UNORM_BLOC"), VK_FORMAT_UNDEFINED);
EXPECT_EQ(stringToVkFormat("K_FORMAT_ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_UNDEFINED);
EXPECT_EQ(stringToVkFormat("_ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_UNDEFINED);
EXPECT_EQ(stringToVkFormat("STC_6x6_UNORM_BLOCK"), VK_FORMAT_UNDEFINED);
}

} // namespace

0 comments on commit 1ae04f8

Please sign in to comment.