Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 36fd93b

Browse files
committed
[[ Bug ]] Use custom function for string compare in rgb test
1 parent 2ae9f48 commit 36fd93b

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

engine/test/test_rgb.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2020
#include "util.h"
2121
#include "rgb.cpp"
2222

23+
static char to_lower(char p_char)
24+
{
25+
if ('A' <= p_char && p_char <= 'Z')
26+
p_char += 32;
27+
28+
return p_char;
29+
}
30+
31+
// We assume color name strings are ASCII
32+
static compare_t string_caseless_compare(const char *left, const char *right)
33+
{
34+
uindex_t t_left_length, t_right_length;
35+
t_left_length = strlen(left);
36+
t_right_length = strlen(right);
37+
38+
for(;;)
39+
{
40+
if (t_left_length == 0 || t_right_length == 0)
41+
break;
42+
43+
index_t t_diff;
44+
t_diff = to_lower(*left++) - tolower(*right++);
45+
if (t_diff != 0)
46+
return t_diff;
47+
48+
t_left_length -= 1;
49+
t_right_length -= 1;
50+
}
51+
52+
return t_left_length - t_right_length;
53+
}
54+
2355
TEST(rgb, color_table)
2456
//
2557
// Checks that the entries of rgb color table are in alphabetical order.
@@ -31,7 +63,8 @@ TEST(rgb, color_table)
3163
ASSERT_GE(color_table_size, (unsigned)1);
3264

3365
for(uint4 i = 0; i < color_table_size - 1; i++) {
34-
EXPECT_LT(MCU_strcasecmp(color_table[i].token, color_table[i+1].token), 0)
66+
EXPECT_LT(string_caseless_compare(color_table[i].token,
67+
color_table[i+1].token), 0)
3568
<< "\"" << color_table[i+1].token << "\""
3669
<< " comes before "
3770
<< "\"" << color_table[i].token << "\"";

0 commit comments

Comments
 (0)