Skip to content

Commit caf1ee8

Browse files
nitinseshadrimateoconlechuga
authored andcommitted
Add tests for strlcpy
1 parent 92638bf commit caf1ee8

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

test/standalone/strlcpy/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
obj/
2+
bin/
3+
src/gfx/*.c
4+
src/gfx/*.h
5+
src/gfx/*.8xv
6+
.DS_Store
7+
convimg.yaml.lst
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"transfer_files": [
3+
"bin/STRLCPY.8xp"
4+
],
5+
"target": {
6+
"name": "STRLCPY",
7+
"isASM": true
8+
},
9+
"sequence": [
10+
"action|launch",
11+
"delay|1000",
12+
"hashWait|1",
13+
"key|enter",
14+
"delay|1000",
15+
"hashWait|2",
16+
"key|enter",
17+
"delay|1000",
18+
"hashWait|3",
19+
"key|enter",
20+
"delay|1000",
21+
"hashWait|4"
22+
],
23+
"hashes": {
24+
"1": {
25+
"description": "First set of tests passed",
26+
"timeout": 5000,
27+
"start": "vram_start",
28+
"size": "vram_16_size",
29+
"expected_CRCs": [
30+
"0835F244"
31+
]
32+
},
33+
"2": {
34+
"description": "Second set of tests passed",
35+
"timeout": 5000,
36+
"start": "vram_start",
37+
"size": "vram_16_size",
38+
"expected_CRCs": [
39+
"2CABBF0E"
40+
]
41+
},
42+
"3": {
43+
"description": "Third set of tests passed",
44+
"timeout": 5000,
45+
"start": "vram_start",
46+
"size": "vram_16_size",
47+
"expected_CRCs": [
48+
"508333F7"
49+
]
50+
},
51+
"4": {
52+
"description": "Exit",
53+
"start": "vram_start",
54+
"size": "vram_16_size",
55+
"expected_CRCs": [
56+
"FFAF89BA",
57+
"101734A5",
58+
"9DA19F44",
59+
"A32840C8",
60+
"349F4775"
61+
]
62+
}
63+
}
64+
}

test/standalone/strlcpy/makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ----------------------------
2+
# Makefile Options
3+
# ----------------------------
4+
5+
NAME = STRLCPY
6+
ICON = icon.png
7+
DESCRIPTION = "strlcpy test"
8+
COMPRESSED = NO
9+
10+
CFLAGS = -Wall -Wextra -O0
11+
CXXFLAGS = -Wall -Wextra -O0
12+
13+
# ----------------------------
14+
15+
include $(shell cedev-config --makefile)

test/standalone/strlcpy/src/main.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <ti/getcsc.h>
2+
#include <ti/screen.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
6+
void test_strlcpy_impl(size_t size) {
7+
char string[] = "Hello there, Venus";
8+
char buffer[20] = "xxxxxxxxxxxxxxxxxxx";
9+
size_t r = strlcpy(buffer, string, size);
10+
size_t len = strlen(buffer);
11+
12+
printf("Source: '%s', size: %d, buffer: '%s', len: %d, result: %d\n",
13+
string, size, buffer, len, r);
14+
}
15+
16+
17+
void test_strlcpy_impl_empty_src(size_t size) {
18+
char string[] = "";
19+
char buffer[20] = "xxxxxxxxxxxxxxxxxxx";
20+
size_t r = strlcpy(buffer, string, size);
21+
size_t len = strlen(buffer);
22+
23+
printf("Source: '%s', size: %d, buffer: '%s', len: %d, result: %d\n",
24+
string, size, buffer, len, r);
25+
}
26+
27+
28+
/* Main function, called first */
29+
int main(void)
30+
{
31+
/* Clear the homescreen */
32+
os_ClrHome();
33+
34+
/* Print a string */
35+
36+
printf("Testing strlcpy...\n\n");
37+
38+
test_strlcpy_impl(19);
39+
test_strlcpy_impl(10);
40+
41+
while (!os_GetCSC()) {};
42+
43+
test_strlcpy_impl(1);
44+
test_strlcpy_impl(0);
45+
46+
while (!os_GetCSC()) {};
47+
48+
test_strlcpy_impl_empty_src(10);
49+
test_strlcpy_impl_empty_src(1);
50+
51+
printf("all done!\n");
52+
53+
/* Waits for a key */
54+
while (!os_GetCSC());
55+
56+
/* Return 0 for success */
57+
return 0;
58+
}

0 commit comments

Comments
 (0)