umd/external/protobuf-2.6/gtest/fused-src/gtest/gtest-all.cc
int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
  const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
      Int32FromEnvOrDie(kTestTotalShards, -1) : -1;
  const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
      Int32FromEnvOrDie(kTestShardIndex, -1) : -1;

  // num_runnable_tests are the number of tests that will
  // run across all shards (i.e., match filter and are not disabled).
  // num_selected_tests are the number of tests to be run on
  // this shard.
  int num_runnable_tests = 0;
  int num_selected_tests = 0;
  for (size_t i = 0; i < test_cases_.size(); i++) {
    TestCase* const test_case = test_cases_[i];
    const String &test_case_name = test_case->name();
    test_case->set_should_run(false);

    for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
      TestInfo* const test_info = test_case->test_info_list()[j];
      const String test_name(test_info->name());
      // A test is disabled if test case name or test name matches
      // kDisableTestFilter.
      const bool is_disabled =
          internal::UnitTestOptions::MatchesFilter(test_case_name,
                                                   kDisableTestFilter) ||
          internal::UnitTestOptions::MatchesFilter(test_name,
                                                   kDisableTestFilter);
      test_info->impl()->set_is_disabled(is_disabled);

      const bool matches_filter =
          internal::UnitTestOptions::FilterMatchesTest(test_case_name,
                                                       test_name);
      test_info->impl()->set_matches_filter(matches_filter);

      const bool is_runnable =
          (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
          matches_filter;

      const bool is_selected = is_runnable &&
          (shard_tests == IGNORE_SHARDING_PROTOCOL ||
           ShouldRunTestOnShard(total_shards, shard_index,
                                num_runnable_tests));

      num_runnable_tests += is_runnable;
      num_selected_tests += is_selected;

      test_info->impl()->set_should_run(is_selected);
      test_case->set_should_run(test_case->should_run() || is_selected);
    }
  }
  return num_selected_tests;
}
// Compares the name of each test with the user-specified filter to
// decide whether the test should be run, then records the result in
// each TestCase and TestInfo object.
// If shard_tests == true, further filters tests based on sharding
// variables in the environment - see
// http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide.
// Returns the number of tests that should run.
Compares the name of each test with the user-specified filter to
decide whether the test should be run, then records the result in
each TestCase and TestInfo object.
Compares the name of each test with the user - specified filter to decide whether the test should be run then records the result in each TestCase and TestInfo object .
int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
  const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
      Int32FromEnvOrDie(kTestTotalShards, -1) : -1;
  const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
      Int32FromEnvOrDie(kTestShardIndex, -1) : -1;
  int num_runnable_tests = 0;
  int num_selected_tests = 0;
  for (size_t i = 0; i < test_cases_.size(); i++) {
    TestCase* const test_case = test_cases_[i];
    const String &test_case_name = test_case->name();
    test_case->set_should_run(false);
    for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
      TestInfo* const test_info = test_case->test_info_list()[j];
      const String test_name(test_info->name());
      const bool is_disabled =
          internal::UnitTestOptions::MatchesFilter(test_case_name,
                                                   kDisableTestFilter) ||
          internal::UnitTestOptions::MatchesFilter(test_name,
                                                   kDisableTestFilter);
      test_info->impl()->set_is_disabled(is_disabled);
      const bool matches_filter =
          internal::UnitTestOptions::FilterMatchesTest(test_case_name,
                                                       test_name);
      test_info->impl()->set_matches_filter(matches_filter);
      const bool is_runnable =
          (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
          matches_filter;
      const bool is_selected = is_runnable &&
          (shard_tests == IGNORE_SHARDING_PROTOCOL ||
           ShouldRunTestOnShard(total_shards, shard_index,
                                num_runnable_tests));
      num_runnable_tests += is_runnable;
      num_selected_tests += is_selected;
      test_info->impl()->set_should_run(is_selected);
      test_case->set_should_run(test_case->should_run() || is_selected);
    }
  }
  return num_selected_tests;
}
int UnitTestImpl :: FilterTests ( ReactionToSharding shard_tests ) { const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ? Int32FromEnvOrDie ( kTestTotalShards , -1 ) : -1 ; const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ? Int32FromEnvOrDie ( kTestShardIndex , -1 ) : -1 ; int num_runnable_tests = 0 ; int num_selected_tests = 0 ; for ( size_t i = 0 ; i < test_cases_ . size ( ) ; i ++ ) { TestCase * const test_case = test_cases_ [ i ] ; const String & test_case_name = test_case -> name ( ) ; test_case -> set_should_run ( false ) ; for ( size_t j = 0 ; j < test_case -> test_info_list ( ) . size ( ) ; j ++ ) { TestInfo * const test_info = test_case -> test_info_list ( ) [ j ] ; const String test_name ( test_info -> name ( ) ) ; const bool is_disabled = internal :: UnitTestOptions :: MatchesFilter ( test_case_name , kDisableTestFilter ) || internal :: UnitTestOptions :: MatchesFilter ( test_name , kDisableTestFilter ) ; test_info -> impl ( ) -> set_is_disabled ( is_disabled ) ; const bool matches_filter = internal :: UnitTestOptions :: FilterMatchesTest ( test_case_name , test_name ) ; test_info -> impl ( ) -> set_matches_filter ( matches_filter ) ; const bool is_runnable = ( GTEST_FLAG ( also_run_disabled_tests ) || ! is_disabled ) && matches_filter ; const bool is_selected = is_runnable && ( shard_tests == IGNORE_SHARDING_PROTOCOL || ShouldRunTestOnShard ( total_shards , shard_index , num_runnable_tests ) ) ; num_runnable_tests += is_runnable ; num_selected_tests += is_selected ; test_info -> impl ( ) -> set_should_run ( is_selected ) ; test_case -> set_should_run ( test_case -> should_run ( ) || is_selected ) ; } } return num_selected_tests ; }
Compares the name of each test with the user-specified filter to
decide whether the test should be run, then records the result in
each TestCase and TestInfo object.
Compares the name of each test with the user - specified filter to decide whether the test should be run then records the result in each TestCase and TestInfo object .
// num_runnable_tests are the number of tests that will // run across all shards (i.e., match filter and are not disabled). // num_selected_tests are the number of tests to be run on // this shard. // A test is disabled if test case name or test name matches // kDisableTestFilter.