Home | History | Annotate | Download | only in common-testhelper
      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 
     25 void split_filter(std::vector<std::string>* positive,
     26                   std::vector<std::string>* negative, std::string filter_expr) {
     27   std::istringstream f(filter_expr);
     28   std::string s;
     29   bool is_neg = false;
     30   while (getline(f, s, ':')) {
     31     if (!is_neg) {
     32       if (s.compare(0, 1, "-") == 0) {
     33         is_neg = true;
     34         s = s.substr(1);
     35       } else {
     36         positive->push_back(s);
     37       }
     38     }
     39     if (is_neg) {
     40       negative->push_back(s);
     41     }
     42   }
     43 }
     44 
     45 std::string join_filter(std::vector<std::string> const& positive,
     46                         std::vector<std::string> const& negative) {
     47   std::ostringstream s;
     48   bool first = true;
     49   bool first_neg = true;
     50   if (!positive.empty() || !negative.empty()) {
     51     s << "--gtest_filter=";
     52   }
     53   for (const auto& i : positive) {
     54     if (!first) {
     55       s << ":";
     56     } else {
     57       first = false;
     58     }
     59     s << i;
     60   }
     61   for (const auto& i : negative) {
     62     if (!first) {
     63       s << ":";
     64     } else {
     65       first = false;
     66     }
     67     if (first_neg) {
     68       s << "-";
     69       first_neg = false;
     70     }
     71     s << i;
     72   }
     73   return s.str();
     74 }
     75