testapp-testhelper.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*############################################################################
  2. # Copyright 2017 Intel Corporation
  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
  18. * \brief Main entry point helpers unit tests.
  19. */
  20. #include "epid/common-testhelper/testapp-testhelper.h"
  21. #include <sstream>
  22. #include <string>
  23. #include <vector>
  24. void split_filter(std::vector<std::string>* positive,
  25. std::vector<std::string>* negative, std::string filter_expr) {
  26. std::istringstream f(filter_expr);
  27. std::string s;
  28. bool is_neg = false;
  29. while (getline(f, s, ':')) {
  30. if (!is_neg) {
  31. if (s.compare(0, 1, "-") == 0) {
  32. is_neg = true;
  33. s = s.substr(1);
  34. } else {
  35. positive->push_back(s);
  36. }
  37. }
  38. if (is_neg) {
  39. negative->push_back(s);
  40. }
  41. }
  42. }
  43. std::string join_filter(std::vector<std::string> const& positive,
  44. std::vector<std::string> const& negative) {
  45. std::ostringstream s;
  46. bool first = true;
  47. bool first_neg = true;
  48. if (!positive.empty() || !negative.empty()) {
  49. s << "--gtest_filter=";
  50. }
  51. for (const auto& i : positive) {
  52. if (!first) {
  53. s << ":";
  54. } else {
  55. first = false;
  56. }
  57. s << i;
  58. }
  59. for (const auto& i : negative) {
  60. if (!first) {
  61. s << ":";
  62. } else {
  63. first = false;
  64. }
  65. if (first_neg) {
  66. s << "-";
  67. first_neg = false;
  68. }
  69. s << i;
  70. }
  71. return s.str();
  72. }