/test/cyad/commandline_options.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 91 lines · 53 code · 16 blank · 22 comment · 0 complexity · 35e166cff50b900d0e4fbb56c9045e5a MD5 · raw file

  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. #include <cyad/CommandlineParser/CmdlineOpts.h>
  23. #include <gmock/gmock.h>
  24. #include <gtest/gtest.h>
  25. TEST(CommandlineOptions, allOptionsPresent) {
  26. using Cynara::CmdlineOpts::CmdlineOpt;
  27. using Cynara::CmdlineOpts::commandlineOptions;
  28. // A cheap trick to make sure this test is updated, when new options are added
  29. ASSERT_EQ(18, commandlineOptions.size());
  30. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::SetBucket));
  31. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::DeleteBucket));
  32. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::SetPolicy));
  33. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Erase));
  34. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Check));
  35. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::ListPolicies));
  36. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::ListPoliciesDesc));
  37. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Type));
  38. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Metadata));
  39. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Client));
  40. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::User));
  41. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Privilege));
  42. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::All));
  43. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Bulk));
  44. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Bucket));
  45. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Recursive));
  46. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Help));
  47. ASSERT_NO_THROW(commandlineOptions.at(CmdlineOpt::Humanize));
  48. }
  49. void ASSERT_OPTS_END_WITH_NULL(const std::vector<option> &opts) {
  50. const auto &lastOpt = opts.end() - 1;
  51. ASSERT_EQ(nullptr, lastOpt->name);
  52. ASSERT_EQ(0, lastOpt->has_arg);
  53. ASSERT_EQ(nullptr, lastOpt->flag);
  54. ASSERT_EQ(0, lastOpt->val);
  55. }
  56. TEST(CommandlineOptions, makeOptionsNone) {
  57. const auto opts = Cynara::CmdlineOpts::makeLongOptions({});
  58. ASSERT_OPTS_END_WITH_NULL(opts);
  59. }
  60. TEST(CommandlineOptions, makeOptionsOne) {
  61. using Cynara::CmdlineOpts::CmdlineOpt;
  62. using Cynara::CmdlineOpts::commandlineOptions;
  63. const auto opts = Cynara::CmdlineOpts::makeLongOptions({ CmdlineOpt::Help });
  64. ASSERT_OPTS_END_WITH_NULL(opts);
  65. ASSERT_STREQ(commandlineOptions.at(CmdlineOpt::Help).longOption, opts.at(0).name);
  66. }
  67. TEST(CommandlineOptions, makeOptionsMore) {
  68. using Cynara::CmdlineOpts::CmdlineOpt;
  69. using Cynara::CmdlineOpts::commandlineOptions;
  70. const auto opts = Cynara::CmdlineOpts::makeLongOptions({ CmdlineOpt::Help,
  71. CmdlineOpt::SetPolicy });
  72. ASSERT_OPTS_END_WITH_NULL(opts);
  73. ASSERT_STREQ(commandlineOptions.at(CmdlineOpt::Help).longOption, opts.at(0).name);
  74. ASSERT_STREQ(commandlineOptions.at(CmdlineOpt::SetPolicy).longOption, opts.at(1).name);
  75. }