GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 61 / 0 / 61
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 47 / 0 / 47

fxe_system_date_set.c
Line Branch Exec Source
1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2026-present Eclipse ThreadX contributors
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** FileX Component */
17 /** */
18 /** System */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define FX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "fx_api.h"
29 #include "fx_system.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _fxe_system_date_set PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function checks for errors in the set system date call. */
45 /* */
46 /* INPUT */
47 /* */
48 /* year Year (1980-2107) */
49 /* month Month (1-12) */
50 /* day Day (1-28/29/30/31) */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* FX_INVALID_YEAR Supplied year is invalid */
55 /* FX_INVALID_MONTH Supplied month is invalid */
56 /* FX_INVALID_DAY Supplied day is invalid */
57 /* status Actual completion status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _fx_system_date_set Actual system date set call */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /**************************************************************************/
68 256 UINT _fxe_system_date_set(UINT year, UINT month, UINT day)
69 {
70
71 UINT status;
72
73
74 /* Check for invalid year. */
75
4/4
✓ Branch 2 → 3 taken 248 times.
✓ Branch 2 → 4 taken 8 times.
✓ Branch 3 → 4 taken 8 times.
✓ Branch 3 → 5 taken 240 times.
256 if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR))
76 {
77 16 return(FX_INVALID_YEAR);
78 }
79
80 /* Check for invalid day. */
81
2/2
✓ Branch 5 → 6 taken 8 times.
✓ Branch 5 → 7 taken 232 times.
240 if (day < 1)
82 {
83 8 return(FX_INVALID_DAY);
84 }
85
86 /* Check for invalid day. */
87
13/13
✓ Branch 7 → 8 taken 16 times.
✓ Branch 7 → 11 taken 40 times.
✓ Branch 7 → 17 taken 16 times.
✓ Branch 7 → 20 taken 16 times.
✓ Branch 7 → 23 taken 16 times.
✓ Branch 7 → 26 taken 16 times.
✓ Branch 7 → 29 taken 16 times.
✓ Branch 7 → 32 taken 16 times.
✓ Branch 7 → 35 taken 16 times.
✓ Branch 7 → 38 taken 16 times.
✓ Branch 7 → 41 taken 16 times.
✓ Branch 7 → 44 taken 24 times.
✓ Branch 7 → 47 taken 8 times.
232 switch (month)
88 {
89
90 16 case 1:
91 {
92
93 /* Check for 31 days. */
94
2/2
✓ Branch 8 → 9 taken 8 times.
✓ Branch 8 → 10 taken 8 times.
16 if (day > 31)
95 {
96 8 return(FX_INVALID_DAY);
97 }
98 8 break;
99 }
100
101 40 case 2:
102 {
103
104 /* Check for leap year. */
105
2/2
✓ Branch 11 → 12 taken 24 times.
✓ Branch 11 → 14 taken 16 times.
40 if ((year % 4) == 0)
106 {
107
108 /* Leap year, February has 29 days. */
109
2/2
✓ Branch 12 → 13 taken 16 times.
✓ Branch 12 → 16 taken 8 times.
24 if (day > 29)
110 {
111 16 return(FX_INVALID_DAY);
112 }
113 }
114 else
115 {
116
117 /* Otherwise, non-leap year. February has
118 28 days. */
119
2/2
✓ Branch 14 → 15 taken 8 times.
✓ Branch 14 → 16 taken 8 times.
16 if (day > 28)
120 {
121 8 return(FX_INVALID_DAY);
122 }
123 }
124 16 break;
125 }
126
127 16 case 3:
128 {
129
130 /* Check for 31 days. */
131
2/2
✓ Branch 17 → 18 taken 8 times.
✓ Branch 17 → 19 taken 8 times.
16 if (day > 31)
132 {
133 8 return(FX_INVALID_DAY);
134 }
135 8 break;
136 }
137
138 16 case 4:
139 {
140
141 /* Check for 30 days. */
142
2/2
✓ Branch 20 → 21 taken 8 times.
✓ Branch 20 → 22 taken 8 times.
16 if (day > 30)
143 {
144 8 return(FX_INVALID_DAY);
145 }
146 8 break;
147 }
148
149 16 case 5:
150 {
151
152 /* Check for 31 days. */
153
2/2
✓ Branch 23 → 24 taken 8 times.
✓ Branch 23 → 25 taken 8 times.
16 if (day > 31)
154 {
155 8 return(FX_INVALID_DAY);
156 }
157 8 break;
158 }
159
160 16 case 6:
161 {
162
163 /* Check for 30 days. */
164
2/2
✓ Branch 26 → 27 taken 8 times.
✓ Branch 26 → 28 taken 8 times.
16 if (day > 30)
165 {
166 8 return(FX_INVALID_DAY);
167 }
168 8 break;
169 }
170
171 16 case 7:
172 {
173
174 /* Check for 31 days. */
175
2/2
✓ Branch 29 → 30 taken 8 times.
✓ Branch 29 → 31 taken 8 times.
16 if (day > 31)
176 {
177 8 return(FX_INVALID_DAY);
178 }
179 8 break;
180 }
181
182 16 case 8:
183 {
184
185 /* Check for 31 days. */
186
2/2
✓ Branch 32 → 33 taken 8 times.
✓ Branch 32 → 34 taken 8 times.
16 if (day > 31)
187 {
188 8 return(FX_INVALID_DAY);
189 }
190 8 break;
191 }
192
193 16 case 9:
194 {
195
196 /* Check for 30 days. */
197
2/2
✓ Branch 35 → 36 taken 8 times.
✓ Branch 35 → 37 taken 8 times.
16 if (day > 30)
198 {
199 8 return(FX_INVALID_DAY);
200 }
201 8 break;
202 }
203
204 16 case 10:
205 {
206
207 /* Check for 31 days. */
208
2/2
✓ Branch 38 → 39 taken 8 times.
✓ Branch 38 → 40 taken 8 times.
16 if (day > 31)
209 {
210 8 return(FX_INVALID_DAY);
211 }
212 8 break;
213 }
214
215 16 case 11:
216 {
217
218 /* Check for 30 days. */
219
2/2
✓ Branch 41 → 42 taken 8 times.
✓ Branch 41 → 43 taken 8 times.
16 if (day > 30)
220 {
221 8 return(FX_INVALID_DAY);
222 }
223 8 break;
224 }
225
226 24 case 12:
227 {
228
229 /* Check for 31 days. */
230
2/2
✓ Branch 44 → 45 taken 8 times.
✓ Branch 44 → 46 taken 16 times.
24 if (day > 31)
231 {
232 8 return(FX_INVALID_DAY);
233 }
234 16 break;
235 }
236
237 8 default:
238
239 /* Invalid month. */
240 8 return(FX_INVALID_MONTH);
241 }
242
243 /* Call actual system date set service. */
244 112 status = _fx_system_date_set(year, month, day);
245
246 /* Return status. */
247 112 return(status);
248 }
249
250