Introduce 'default' method type for credential helpers
[platform/core/security/cynara.git] / test / cyad / commandline_options.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        test/cyad/commandline_options.cpp
18  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
19  * @version     1.0
20  * @brief       Tests for command-line options
21  */
22
23 #include <cyad/CommandlineParser/CmdlineOpts.h>
24 #include <gmock/gmock.h>
25 #include <gtest/gtest.h>
26
27
28 TEST(CommandlineOptions, allOptionsPresent) {
29     using Cynara::CmdlineOpts::CmdlineOpt;
30     using Cynara::CmdlineOpts::commandlineOptions;
31
32     // A cheap trick to make sure this test is updated, when new options are added
33     ASSERT_EQ(16, commandlineOptions.size());
34
35     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::SetBucket));
36     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::DeleteBucket));
37     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::SetPolicy));
38     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Erase));
39     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Check));
40     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::ListPolicies));
41     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::ListPoliciesDesc));
42
43     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Type));
44     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Metadata));
45     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Client));
46     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::User));
47     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Privilege));
48     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Bulk));
49     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Bucket));
50     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Recursive));
51
52     ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Help));
53 }
54
55
56 void ASSERT_OPTS_END_WITH_NULL(const std::vector<option> &opts) {
57     const auto &lastOpt = opts.end() - 1;
58     ASSERT_EQ(nullptr, lastOpt->name);
59     ASSERT_EQ(0, lastOpt->has_arg);
60     ASSERT_EQ(nullptr, lastOpt->flag);
61     ASSERT_EQ(0, lastOpt->val);
62 }
63
64 TEST(CommandlineOptions, makeOptionsNone) {
65     const auto opts = Cynara::CmdlineOpts::makeLongOptions({});
66     ASSERT_OPTS_END_WITH_NULL(opts);
67 }
68
69 TEST(CommandlineOptions, makeOptionsOne) {
70     using Cynara::CmdlineOpts::CmdlineOpt;
71     using Cynara::CmdlineOpts::commandlineOptions;
72
73     const auto opts = Cynara::CmdlineOpts::makeLongOptions({ CmdlineOpt::Help });
74
75     ASSERT_OPTS_END_WITH_NULL(opts);
76     ASSERT_STREQ(commandlineOptions.at(CmdlineOpt::Help).longOption, opts.at(0).name);
77 }
78
79 TEST(CommandlineOptions, makeOptionsMore) {
80     using Cynara::CmdlineOpts::CmdlineOpt;
81     using Cynara::CmdlineOpts::commandlineOptions;
82
83     const auto opts = Cynara::CmdlineOpts::makeLongOptions({ CmdlineOpt::Help,
84                                                              CmdlineOpt::SetPolicy });
85
86     ASSERT_OPTS_END_WITH_NULL(opts);
87     ASSERT_STREQ(commandlineOptions.at(CmdlineOpt::Help).longOption, opts.at(0).name);
88     ASSERT_STREQ(commandlineOptions.at(CmdlineOpt::SetPolicy).longOption, opts.at(1).name);
89 }