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
19const int32_t FAILED = -1;
20
21/**
22 * @tc.name      : getopt_long_0100
23 * @tc.desc      : Each parameter is valid, and the command line parsing of the long option is successful.
24 * @tc.level     : Level 0
25 */
26void getopt_long_0100(int a)
27{
28    int c = a;
29    EXPECT_NE("getopt_long_0100", c, FAILED);
30}
31
32/**
33 * @tc.name      : getopt_long_0200
34 * @tc.desc      : Invalid argument, command line parsing of long options failed.
35 * @tc.level     : Level 2
36 */
37void getopt_long_0200(int b)
38{
39    int c = b;
40    EXPECT_EQ("getopt_long_0200", c, FAILED);
41}
42
43int 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(argc, argv, short_options, long_options, NULL);
57    getopt_long_0100(c);
58    c = getopt_long(0, 0, 0, 0, NULL);
59    getopt_long_0200(c);
60    return t_status;
61}