/test/cyad/helpers.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 64 lines · 32 code · 11 blank · 21 comment · 13 complexity · 3d79e8f8976f6f66ebd12630c900709f MD5 · raw file

  1. /*
  2. * Copyright (c) 2014 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/helpers.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Helper functions, matchers and operators
  21. */
  22. #include <cstdlib>
  23. #include <cstring>
  24. #include <cynara-admin-types.h>
  25. #include "helpers.h"
  26. bool operator==(const cynara_admin_policy &lhs, const cynara_admin_policy &rhs) {
  27. auto strEq = [] (const char *lhs, const char *rhs) -> bool {
  28. if (lhs != nullptr && rhs != nullptr)
  29. return strcmp(lhs, rhs) == 0;
  30. else
  31. return lhs == rhs;
  32. };
  33. return lhs.result == rhs.result
  34. && strEq(lhs.bucket, rhs.bucket)
  35. && strEq(lhs.client, rhs.client)
  36. && strEq(lhs.user, rhs.user)
  37. && strEq(lhs.privilege, rhs.privilege)
  38. && strEq(lhs.result_extra, rhs.result_extra);
  39. }
  40. bool operator!=(const cynara_admin_policy &lhs, const cynara_admin_policy &rhs) {
  41. return !(lhs == rhs);
  42. }
  43. namespace Cynara {
  44. namespace Helpers {
  45. void freeAdminPolicyMembers(cynara_admin_policy *admin_policy) {
  46. free(admin_policy->bucket);
  47. free(admin_policy->client);
  48. free(admin_policy->user);
  49. free(admin_policy->privilege);
  50. free(admin_policy->result_extra);
  51. }
  52. } /* namespace Helpers */
  53. } /* namespace Cynara */