• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <getopt.h>
17 #include "functionalext.h"
18 
19 const int32_t FAILED = -1;
20 
21 /**
22  * @tc.name      : getopt_long_only_0100
23  * @tc.desc      : Each parameter is valid, and the short option command is first parsed with the long parameter.
24  * @tc.level     : Level 0
25  */
getopt_long_only_0100(int a)26 void getopt_long_only_0100(int a)
27 {
28     int c = a;
29     EXPECT_NE("getopt_long_only_0100", c, FAILED);
30 }
31 
32 /**
33  * @tc.name      : getopt_long_only_0200
34  * @tc.desc      : Invalid argument, command line parsing failed.
35  * @tc.level     : Level 2
36  */
getopt_long_only_0200(int b)37 void getopt_long_only_0200(int b)
38 {
39     int c = b;
40     EXPECT_EQ("getopt_long_only_0200", c, FAILED);
41 }
42 
main(int argc,char * argv[])43 int main(int argc, char *argv[])
44 {
45     argc = 2;
46     argv[1] = "-n";
47     char *l_opt_arg;
48     char *const short_options = "nbl:";
49     struct option long_options[] = {
50         {"name", 0, NULL, 'n'},
51         {"bf_name", 0, NULL, 'b'},
52         {"love", 1, NULL, 'l'},
53         {0, 0, 0, 0},
54     };
55     int c;
56     c = getopt_long_only(argc, argv, short_options, long_options, NULL);
57     getopt_long_only_0100(c);
58     c = getopt_long_only(0, 0, 0, 0, NULL);
59     getopt_long_only_0200(c);
60 
61     return t_status;
62 }