1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stddef.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include "syscap_define.h"
20
CheckSortBySyscapNum(void)21 int CheckSortBySyscapNum(void)
22 {
23 int size = (int)sizeof(g_arraySyscap) / sizeof(SyscapWithNum);
24 int flag = 0;
25
26 for (int i = 0; i < size; i++) {
27 if (g_arraySyscap[i].num != i) {
28 printf("[ERROR][syscap_define.h]: %s -> num(%u) should be %d.\n",
29 g_arraySyscap[i].str, g_arraySyscap[i].num, i);
30 flag++;
31 }
32 }
33 return flag;
34 }
35
CheckSyscapNumOrder(void)36 int CheckSyscapNumOrder(void)
37 {
38 if (COMMUNICATION_NETMANAGER_VPN != 227) { // 227, special number
39 printf("[ERROR][syscap_define.h]: "
40 "enum value 'COMMUNICATION_NETMANAGER_VPN' should be 227. "
41 "Please don't change original SyscapNum's enum value order, "
42 "and add the new enum value at the end.\n");
43 return 1;
44 }
45 return 0;
46 }
47
main(void)48 int main(void)
49 {
50 if (CheckSyscapNumOrder() != 0) {
51 return -1;
52 }
53 if (CheckSortBySyscapNum() != 0) {
54 return -1;
55 }
56 return 0;
57 }