1
1
/* SPDX-License-Identifier: MIT */
2
2
/*
3
- * Copyright (c) 2014 by Intel Corp
3
+ * Copyright (c) 2014-2022 Intel Corp
4
+ */
4
5
/*------------------------------------------------------------------
5
6
* test_strisdigit_s
6
7
*
13
14
#define LEN ( 128 )
14
15
15
16
16
- int test_strisdigit_s ()
17
+ int test_strisdigit_s (void )
17
18
{
18
19
bool rc ;
19
20
20
- uint32_t len ;
21
- char str [LEN ];
21
+ rsize_t len ;
22
+ char str [LEN ];
23
+ unsigned int testno = 0 ;
24
+ unsigned int err = 0 ;
25
+
26
+
27
+ printf ("\nTesting strisdigit_s:\n" );
22
28
23
29
/*--------------------------------------------------*/
24
30
31
+ /* 1: Test for first parameter, char string, being sent in as NULL */
32
+ printf ("Test #%d:\n" , ++ testno );
33
+
25
34
len = 5 ;
26
35
rc = strisdigit_s (NULL , len );
27
36
if (rc != false) {
28
37
printf ("%s %u Error rc=%u \n" ,
29
38
__FUNCTION__ , __LINE__ , rc );
39
+ err ++ ;
30
40
}
31
41
32
42
/*--------------------------------------------------*/
33
43
44
+ printf ("Test #%d:\n" , ++ testno );
45
+
34
46
len = 0 ;
35
47
rc = strisdigit_s ("1234" , len );
36
48
if (rc != false) {
37
49
printf ("%s %u Error rc=%u \n" ,
38
50
__FUNCTION__ , __LINE__ , rc );
51
+ err ++ ;
39
52
}
40
53
41
54
/*--------------------------------------------------*/
42
55
56
+ printf ("Test #%d:\n" , ++ testno );
57
+
43
58
len = 99999 ;
44
59
rc = strisdigit_s ("1234" , len );
45
60
if (rc != false) {
46
61
printf ("%s %u Error rc=%u \n" ,
47
62
__FUNCTION__ , __LINE__ , rc );
63
+ err ++ ;
48
64
}
49
65
50
66
/*--------------------------------------------------*/
51
67
68
+ printf ("Test #%d:\n" , ++ testno );
69
+
52
70
len = 9 ;
53
71
rc = strisdigit_s ("" , len );
54
72
if (rc != false) {
55
73
printf ("%s %u Error rc=%u \n" ,
56
74
__FUNCTION__ , __LINE__ , rc );
75
+ err ++ ;
57
76
}
58
77
59
78
/*--------------------------------------------------*/
60
79
80
+ printf ("Test #%d:\n" , ++ testno );
81
+
61
82
strcpy (str , "123456789" );
62
83
len = 4 ;
63
84
64
85
rc = strisdigit_s (str , len );
65
86
if (rc != true) {
66
87
printf ("%s %u Error rc=%u \n" ,
67
88
__FUNCTION__ , __LINE__ , rc );
89
+ err ++ ;
68
90
}
69
91
70
92
/*--------------------------------------------------*/
71
93
94
+ printf ("Test #%d:\n" , ++ testno );
95
+
72
96
strcpy (str , "1" );
73
97
len = strlen (str );
74
98
75
99
rc = strisdigit_s (str , len );
76
100
if (rc != true) {
77
101
printf ("%s %u Error rc=%u \n" ,
78
102
__FUNCTION__ , __LINE__ , rc );
103
+ err ++ ;
79
104
}
80
105
81
106
/*--------------------------------------------------*/
82
107
108
+ printf ("Test #%d:\n" , ++ testno );
109
+
83
110
strcpy (str , "12" );
84
111
len = strlen (str );
85
112
86
113
rc = strisdigit_s (str , len );
87
114
if (rc != true) {
88
115
printf ("%s %u Error rc=%u \n" ,
89
116
__FUNCTION__ , __LINE__ , rc );
117
+ err ++ ;
90
118
}
91
119
92
120
/*--------------------------------------------------*/
93
121
122
+ printf ("Test #%d:\n" , ++ testno );
123
+
94
124
strcpy (str , "1abcd" );
95
125
len = strlen (str );
96
126
@@ -102,16 +132,32 @@ int test_strisdigit_s()
102
132
103
133
/*--------------------------------------------------*/
104
134
135
+ printf ("Test #%d:\n" , ++ testno );
136
+
105
137
strcpy (str , "abcd" );
106
138
len = strlen (str );
107
139
108
140
rc = strisdigit_s (str , len );
109
141
if (rc != false) {
110
142
printf ("%s %u Error rc=%u \n" ,
111
143
__FUNCTION__ , __LINE__ , rc );
144
+ err ++ ;
112
145
}
113
146
114
147
/*--------------------------------------------------*/
115
148
116
- return (0 );
149
+ /* Test for non terminated string */
150
+ printf ("Test #%d:\n" , ++ testno );
151
+
152
+ memset (str , '6' , LEN );
153
+ len = LEN - 3 ;
154
+
155
+ rc = strisdigit_s (str , len );
156
+ if (rc != true) {
157
+ printf ("%s %u Error rc=%u \n" ,
158
+ __FUNCTION__ , __LINE__ , rc );
159
+ err ++ ;
160
+ }
161
+
162
+ return (err == 0 ) ? 0 : 1 ;
117
163
}
0 commit comments