Skip to content

Commit 9cc7dd7

Browse files
committed
Fix const-correctness issues
Add tests
1 parent 82efbec commit 9cc7dd7

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

pawn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"user": "ziggi",
2+
"user": "Open-GTO",
33
"repo": "textlist",
44
"entry": "test.pwn",
55
"output": "test.amx",

test.pwn

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
#include "textlist.inc"
44

5+
TextListCreate:example_tl(playerid)
6+
{
7+
new items[][TEXTLIST_MAX_ITEM_NAME] = {
8+
"Test 1",
9+
"Big Test 2"
10+
};
11+
12+
new bg_colors[TEXTLIST_MAX_ITEMS] = {
13+
0xFF0000FF,
14+
0x00FF00FF
15+
};
16+
17+
TextList_Open(playerid, TextList:example_tl, items, sizeof(items),
18+
"Example header",
19+
"Button 1", "Button 2",
20+
.lists_bg_color = bg_colors);
21+
}
22+
23+
TextListResponse:example_tl(playerid, TextListType:response, itemid, itemvalue[])
24+
{
25+
new string[128];
26+
format(string, sizeof(string), " %d | %d | %d | %s", playerid, _:response, itemid, itemvalue);
27+
SendClientMessage(playerid, -1, string);
28+
return 1;
29+
}
30+
531
main() {
6-
// write tests for libraries here and run "sampctl package run"
32+
TextList_Show(0, TextList:example_tl);
733
}

textlist.inc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static
136136
137137
*/
138138

139-
stock TextList_Show(playerid, function[])
139+
stock TextList_Show(playerid, const function[])
140140
{
141141
new call_func[TEXTLIST_MAX_FUNCTION_NAME] = "tlc_";
142142
strcat(call_func, function);
@@ -171,11 +171,11 @@ stock TextList_Close(playerid)
171171
CancelSelectTextDraw(playerid);
172172
}
173173

174-
stock TextList_Open(playerid, function[], list_items[][], list_size = sizeof(list_items), header[] = "",
175-
button1[] = "", button2[] = "", Float:pos_x = 89.0, Float:pos_y = 140.0,
174+
stock TextList_Open(playerid, const function[], const list_items[][], const list_size = sizeof(list_items), const header[] = "",
175+
const button1[] = "", const button2[] = "", Float:pos_x = 89.0, Float:pos_y = 140.0,
176176
select_color = 0xFFA500FF,
177-
lists_bg_color[TEXTLIST_MAX_ITEMS] = {0x212121A0, ...},
178-
lists_fg_color[TEXTLIST_MAX_ITEMS] = {0xFFFFFFFF, ...},
177+
const lists_bg_color[TEXTLIST_MAX_ITEMS] = {0x212121A0, ...},
178+
const lists_fg_color[TEXTLIST_MAX_ITEMS] = {0xFFFFFFFF, ...},
179179
header_bg_color = 0xB71C1CAA, header_fg_color = 0xFFFFFFFF,
180180
paginator_bg_color = 0x21212160, paginator_fg_color = 0xFFFFFFFF,
181181
button1_bg_color = 0x6D4C41AA, button1_fg_color = 0xFFFFFFFF,
@@ -242,8 +242,8 @@ stock TextList_IsOpen(playerid)
242242

243243
static stock TD_SetPage(playerid, &page_id, items_count,
244244
Float:pos_x, Float:pos_y,
245-
buttons[][], list_item[][],
246-
lists_bg_color[TEXTLIST_MAX_ITEMS], lists_fg_color[TEXTLIST_MAX_ITEMS],
245+
const buttons[][], const list_item[][],
246+
const lists_bg_color[TEXTLIST_MAX_ITEMS], const lists_fg_color[TEXTLIST_MAX_ITEMS],
247247
paginator_bg_color, paginator_fg_color,
248248
button1_bg_color, button1_fg_color,
249249
button2_bg_color, button2_fg_color)
@@ -360,7 +360,7 @@ static stock GetPaginatorInfo(items_count, &curr_page = 0, &max_page = 0, &start
360360
}
361361
}
362362

363-
static stock TD_ListCreate(playerid, item_id, text[], bg_color, fg_color, Float:pos_x, Float:pos_y)
363+
static stock TD_ListCreate(playerid, item_id, const text[], bg_color, fg_color, Float:pos_x, Float:pos_y)
364364
{
365365
TD_ListItem[playerid][item_id] = CreatePlayerTextDraw(playerid, pos_x, pos_y, text);
366366
PlayerTextDrawLetterSize(playerid, TD_ListItem[playerid][item_id], 0.22, 1.5);
@@ -379,12 +379,12 @@ static stock TD_ListCreate(playerid, item_id, text[], bg_color, fg_color, Float:
379379
PlayerTextDrawShow(playerid, TD_ListItem[playerid][item_id]);
380380
}
381381

382-
static stock TD_ListUpdateText(playerid, item_id, text[])
382+
static stock TD_ListUpdateText(playerid, item_id, const text[])
383383
{
384384
PlayerTextDrawSetString(playerid, TD_ListItem[playerid][item_id], text);
385385
}
386386

387-
static stock TD_PaginatorCreate(playerid, pagestr[], bg_color, fg_color, Float:pos_x, Float:pos_y)
387+
static stock TD_PaginatorCreate(playerid, const pagestr[], bg_color, fg_color, Float:pos_x, Float:pos_y)
388388
{
389389
TD_ListUp[playerid] = CreatePlayerTextDraw(playerid, pos_x - 20.0, pos_y, "LD_BEAT:up");
390390
PlayerTextDrawLetterSize(playerid, TD_ListUp[playerid], 0.0, 0.0);
@@ -443,12 +443,12 @@ static stock TD_PaginatorCreate(playerid, pagestr[], bg_color, fg_color, Float:p
443443
PlayerTextDrawShow(playerid, TD_ListBox[playerid]);
444444
}
445445

446-
static stock TD_PaginatorUpdateText(playerid, pagestr[])
446+
static stock TD_PaginatorUpdateText(playerid, const pagestr[])
447447
{
448448
PlayerTextDrawSetString(playerid, TD_ListPage[playerid], pagestr);
449449
}
450450

451-
static stock TD_HeaderCreate(playerid, text[], bg_color, fg_color, Float:pos_x, Float:pos_y)
451+
static stock TD_HeaderCreate(playerid, const text[], bg_color, fg_color, Float:pos_x, Float:pos_y)
452452
{
453453
TD_ListHeader[playerid] = CreatePlayerTextDraw(playerid, pos_x, pos_y, text);
454454
PlayerTextDrawLetterSize(playerid, TD_ListHeader[playerid], 0.3, 1.5);
@@ -466,7 +466,7 @@ static stock TD_HeaderCreate(playerid, text[], bg_color, fg_color, Float:pos_x,
466466
PlayerTextDrawShow(playerid, TD_ListHeader[playerid]);
467467
}
468468

469-
static stock TD_ButtonCreate(playerid, &PlayerText:button, text[], bg_color, fg_color, Float:pos_x, Float:pos_y)
469+
static stock TD_ButtonCreate(playerid, &PlayerText:button, const text[], bg_color, fg_color, Float:pos_x, Float:pos_y)
470470
{
471471
button = CreatePlayerTextDraw(playerid, pos_x, pos_y, text);
472472
PlayerTextDrawLetterSize(playerid, button, 0.25, 1.4);
@@ -664,7 +664,7 @@ public OnPlayerClickTextDraw(playerid, Text:clickedid)
664664
665665
*/
666666

667-
static stock TL_strcpy(result[], source[], const size = sizeof(result))
667+
static stock TL_strcpy(result[], const source[], const size = sizeof(result))
668668
{
669669
result[0] = 0;
670670
return strcat(result, source, size);

0 commit comments

Comments
 (0)