test/fmw/gtest/src/gtest-typed-test.cc
author hseigel
Tue, 26 Jul 2016 08:23:25 -0400
changeset 43178 6fb98b21d035
parent 37967 8dd54c3bf02a
child 54913 9cfbe22bcdf8
permissions -rw-r--r--
8161218: Better bytecode loading Reviewed-by: acorn, mschoene, ctornqvi Contributed-by: harold.seigel@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37967
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     1
// Copyright 2008 Google Inc.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     2
// All Rights Reserved.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     3
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     4
// Redistribution and use in source and binary forms, with or without
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     5
// modification, are permitted provided that the following conditions are
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     6
// met:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     7
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     8
//     * Redistributions of source code must retain the above copyright
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     9
// notice, this list of conditions and the following disclaimer.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    10
//     * Redistributions in binary form must reproduce the above
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    11
// copyright notice, this list of conditions and the following disclaimer
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    12
// in the documentation and/or other materials provided with the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    13
// distribution.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    14
//     * Neither the name of Google Inc. nor the names of its
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    15
// contributors may be used to endorse or promote products derived from
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    16
// this software without specific prior written permission.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    17
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    29
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    30
// Author: wan@google.com (Zhanyong Wan)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    31
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    32
#include "gtest/gtest-typed-test.h"
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    33
#include "gtest/gtest.h"
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    34
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    35
namespace testing {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    36
namespace internal {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    37
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    38
#if GTEST_HAS_TYPED_TEST_P
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    39
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    40
// Skips to the first non-space char in str. Returns an empty string if str
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    41
// contains only whitespace characters.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    42
static const char* SkipSpaces(const char* str) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    43
  while (IsSpace(*str))
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    44
    str++;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    45
  return str;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    46
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    47
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    48
// Verifies that registered_tests match the test names in
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    49
// defined_test_names_; returns registered_tests if successful, or
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    50
// aborts the program otherwise.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    51
const char* TypedTestCasePState::VerifyRegisteredTestNames(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    52
    const char* file, int line, const char* registered_tests) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    53
  typedef ::std::set<const char*>::const_iterator DefinedTestIter;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    54
  registered_ = true;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    55
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    56
  // Skip initial whitespace in registered_tests since some
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    57
  // preprocessors prefix stringizied literals with whitespace.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    58
  registered_tests = SkipSpaces(registered_tests);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    59
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    60
  Message errors;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    61
  ::std::set<std::string> tests;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    62
  for (const char* names = registered_tests; names != NULL;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    63
       names = SkipComma(names)) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    64
    const std::string name = GetPrefixUntilComma(names);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    65
    if (tests.count(name) != 0) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    66
      errors << "Test " << name << " is listed more than once.\n";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    67
      continue;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    68
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    69
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    70
    bool found = false;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    71
    for (DefinedTestIter it = defined_test_names_.begin();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    72
         it != defined_test_names_.end();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    73
         ++it) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    74
      if (name == *it) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    75
        found = true;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    76
        break;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    77
      }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    78
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    79
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    80
    if (found) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    81
      tests.insert(name);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    82
    } else {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    83
      errors << "No test named " << name
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    84
             << " can be found in this test case.\n";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    85
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    86
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    87
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    88
  for (DefinedTestIter it = defined_test_names_.begin();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    89
       it != defined_test_names_.end();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    90
       ++it) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    91
    if (tests.count(*it) == 0) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    92
      errors << "You forgot to list test " << *it << ".\n";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    93
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    94
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    95
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    96
  const std::string& errors_str = errors.GetString();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    97
  if (errors_str != "") {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    98
    fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    99
            errors_str.c_str());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   100
    fflush(stderr);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   101
    posix::Abort();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   102
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   103
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   104
  return registered_tests;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   105
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   106
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   107
#endif  // GTEST_HAS_TYPED_TEST_P
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   108
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   109
}  // namespace internal
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   110
}  // namespace testing