Moves TestResult from gtest-internal-inl.h to gtest.h to prepare for the even listener API work (by Vlad Losev); cleans up the scons script (by Zhanyong Wan).

This commit is contained in:
zhanyong.wan 2009-06-19 21:20:40 +00:00
parent 4853a50337
commit 3c181b5657
4 changed files with 313 additions and 304 deletions

View File

@ -383,6 +383,102 @@ class TestProperty {
String value_;
};
// The result of a single Test. This includes a list of
// TestPartResults, a list of TestProperties, a count of how many
// death tests there are in the Test, and how much time it took to run
// the Test.
//
// TestResult is not copyable.
class TestResult {
public:
// Creates an empty TestResult.
TestResult();
// D'tor. Do not inherit from TestResult.
~TestResult();
// Gets the list of TestPartResults.
const internal::List<TestPartResult>& test_part_results() const {
return *test_part_results_;
}
// Gets the list of TestProperties.
const internal::List<internal::TestProperty>& test_properties() const {
return *test_properties_;
}
// Gets the number of successful test parts.
int successful_part_count() const;
// Gets the number of failed test parts.
int failed_part_count() const;
// Gets the number of all test parts. This is the sum of the number
// of successful test parts and the number of failed test parts.
int total_part_count() const;
// Returns true iff the test passed (i.e. no test part failed).
bool Passed() const { return !Failed(); }
// Returns true iff the test failed.
bool Failed() const { return failed_part_count() > 0; }
// Returns true iff the test fatally failed.
bool HasFatalFailure() const;
// Returns true iff the test has a non-fatal failure.
bool HasNonfatalFailure() const;
// Returns the elapsed time, in milliseconds.
TimeInMillis elapsed_time() const { return elapsed_time_; }
// Sets the elapsed time.
void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
// Adds a test part result to the list.
void AddTestPartResult(const TestPartResult& test_part_result);
// Adds a test property to the list. The property is validated and may add
// a non-fatal failure if invalid (e.g., if it conflicts with reserved
// key names). If a property is already recorded for the same key, the
// value will be updated, rather than storing multiple values for the same
// key.
void RecordProperty(const internal::TestProperty& test_property);
// Adds a failure if the key is a reserved attribute of Google Test
// testcase tags. Returns true if the property is valid.
// TODO(russr): Validate attribute names are legal and human readable.
static bool ValidateTestProperty(const internal::TestProperty& test_property);
// Returns the death test count.
int death_test_count() const { return death_test_count_; }
// Increments the death test count, returning the new count.
int increment_death_test_count() { return ++death_test_count_; }
// Clears the test part results.
void ClearTestPartResults();
// Clears the object.
void Clear();
private:
// Protects mutable state of the property list and of owned properties, whose
// values may be updated.
internal::Mutex test_properites_mutex_;
// The list of TestPartResults
scoped_ptr<internal::List<TestPartResult> > test_part_results_;
// The list of TestProperties
scoped_ptr<internal::List<internal::TestProperty> > test_properties_;
// Running count of death tests.
int death_test_count_;
// The elapsed time, in milliseconds.
TimeInMillis elapsed_time_;
// We disallow copying TestResult.
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
}; // class TestResult
} // namespace internal
// A TestInfo object stores the following information about a test:

View File

@ -1,7 +1,6 @@
#!/usr/bin/python2.4
#
# Copyright 2008, Google Inc.
# All rights reserved.
# Copyright 2008 Google Inc. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@ -93,6 +92,11 @@ env.SConscript(env.File('scons/SConscript', gtest_dir))
__author__ = 'joi@google.com (Joi Sigurdsson)'
import os
############################################################
# Environments for building the targets, sorted by name.
Import('env')
env = env.Clone()
@ -102,24 +106,13 @@ env = env.Clone()
env.Prepend(CPPPATH = ['#/..',
'#/../include'])
# Sources used by base library and library that includes main.
gtest_source = '../src/gtest-all.cc'
gtest_main_source = '../src/gtest_main.cc'
# gtest.lib to be used by most apps (if you have your own main
# function)
gtest = env.StaticLibrary(target='gtest',
source=[gtest_source])
# gtest_main.lib can be used if you just want a basic main function;
# it is also used by the tests for Google Test itself.
gtest_main = env.StaticLibrary(target='gtest_main',
source=[gtest_source, gtest_main_source])
env_use_own_tuple = env.Clone()
env_use_own_tuple.Append(CPPDEFINES = 'GTEST_USE_OWN_TR1_TUPLE=1')
env_with_exceptions = env.Clone()
if env_with_exceptions['PLATFORM'] == 'win32':
env_with_exceptions.Append(CCFLAGS = ['/EHsc'])
env_with_exceptions.Append(CPPDEFINES = '_HAS_EXCEPTIONS=1')
env_with_exceptions.Append(CCFLAGS=['/EHsc'])
env_with_exceptions.Append(CPPDEFINES='_HAS_EXCEPTIONS=1')
# Undoes the _TYPEINFO_ hack, which is unnecessary and only creates
# trouble when exceptions are enabled.
cppdefines = env_with_exceptions['CPPDEFINES']
@ -131,198 +124,208 @@ else:
if '-fno-exceptions' in ccflags:
ccflags.remove('-fno-exceptions')
env_without_rtti = env.Clone()
if env_without_rtti['PLATFORM'] == 'win32':
env_without_rtti.Append(CCFLAGS = ['/GR-'])
else:
env_without_rtti.Append(CCFLAGS = ['-fno-rtti'])
env_without_rtti.Append(CPPDEFINES = 'GTEST_HAS_RTTI=0')
env_use_own_tuple = env.Clone()
env_use_own_tuple.Append(CPPDEFINES = 'GTEST_USE_OWN_TR1_TUPLE=1')
gtest_ex_obj = env_with_exceptions.Object(target='gtest_ex',
source=gtest_source)
gtest_main_ex_obj = env_with_exceptions.Object(target='gtest_main_ex',
source=gtest_main_source)
gtest_ex = env_with_exceptions.StaticLibrary(
target='gtest_ex',
source=gtest_ex_obj)
gtest_ex_main = env_with_exceptions.StaticLibrary(
target='gtest_ex_main',
source=gtest_ex_obj + gtest_main_ex_obj)
# Install the libraries if needed.
if 'LIB_OUTPUT' in env.Dictionary():
env.Install('$LIB_OUTPUT', source=[gtest, gtest_main, gtest_ex_main])
def ConstructSourceList(target, dir_prefix, additional_sources=None):
"""Helper to create source file list for gtest binaries.
Args:
target: The basename of the target's main source file.
dir_prefix: The path to prefix the main source file.
gtest_lib: The gtest lib to use.
additional_sources: A list of additional source files in the target.
"""
source = [env.File('%s.cc' % target, env.Dir(dir_prefix))]
if additional_sources:
source += additional_sources
return source
def GtestBinary(env, target, gtest_libs, sources):
"""Helper to create gtest binaries: tests, samples, etc.
Args:
env: The SCons construction environment to use to build.
target: The basename of the target's main source file, also used as target
name.
gtest_libs: A list of gtest libraries to use.
sources: A list of source files in the target.
"""
binary = env.Program(target=target, source=sources, LIBS=gtest_libs)
if 'EXE_OUTPUT' in env.Dictionary():
env.Install('$EXE_OUTPUT', source=[binary])
def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
"""Helper to create gtest unit tests.
Args:
env: The SCons construction environment to use to build.
target: The basename of the target unit test .cc file.
gtest_lib: The gtest lib to use.
additional_sources: A list of additional source files in the target.
"""
GtestBinary(env,
target,
[gtest_lib],
ConstructSourceList(target, "../test",
additional_sources=additional_sources))
GtestUnitTest(env, 'gtest-filepath_test', gtest_main)
GtestUnitTest(env, 'gtest-message_test', gtest_main)
GtestUnitTest(env, 'gtest-options_test', gtest_main)
GtestUnitTest(env, 'gtest_environment_test', gtest)
GtestUnitTest(env, 'gtest_main_unittest', gtest_main)
GtestUnitTest(env, 'gtest_no_test_unittest', gtest)
GtestUnitTest(env, 'gtest_pred_impl_unittest', gtest_main)
GtestUnitTest(env, 'gtest_prod_test', gtest_main,
additional_sources=['../test/production.cc'])
GtestUnitTest(env, 'gtest_repeat_test', gtest)
GtestUnitTest(env, 'gtest_sole_header_test', gtest_main)
GtestUnitTest(env, 'gtest-test-part_test', gtest_main)
GtestUnitTest(env, 'gtest-typed-test_test', gtest_main,
additional_sources=['../test/gtest-typed-test2_test.cc'])
GtestUnitTest(env, 'gtest-param-test_test', gtest,
additional_sources=['../test/gtest-param-test2_test.cc'])
GtestUnitTest(env, 'gtest_unittest', gtest_main)
GtestUnitTest(env, 'gtest_output_test_', gtest)
GtestUnitTest(env, 'gtest_color_test_', gtest)
GtestUnitTest(env, 'gtest-linked_ptr_test', gtest_main)
GtestUnitTest(env, 'gtest-port_test', gtest_main)
GtestUnitTest(env, 'gtest_break_on_failure_unittest_', gtest)
GtestUnitTest(env, 'gtest_filter_unittest_', gtest)
GtestUnitTest(env, 'gtest_help_test_', gtest_main)
GtestUnitTest(env, 'gtest_list_tests_unittest_', gtest)
GtestUnitTest(env, 'gtest_throw_on_failure_test_', gtest)
GtestUnitTest(env_with_exceptions, 'gtest_throw_on_failure_ex_test', gtest_ex)
GtestUnitTest(env, 'gtest_xml_outfile1_test_', gtest_main)
GtestUnitTest(env, 'gtest_xml_outfile2_test_', gtest_main)
GtestUnitTest(env, 'gtest_xml_output_unittest_', gtest_main)
# Assuming POSIX-like environment with GCC.
# TODO(vladl@google.com): sniff presence of pthread_atfork instead of
# selecting on a platform.
env_with_threads = env.Clone()
if env_with_threads['PLATFORM'] != 'win32':
env_with_threads.Append(CCFLAGS = ['-pthread'])
env_with_threads.Append(LINKFLAGS = ['-pthread'])
GtestUnitTest(env_with_threads, 'gtest-death-test_test', gtest_main)
gtest_unittest_ex_obj = env_with_exceptions.Object(
target='gtest_unittest_ex',
source='../test/gtest_unittest.cc')
GtestBinary(env_with_exceptions,
'gtest_ex_unittest',
[gtest_ex_main],
gtest_unittest_ex_obj)
gtest_unittest_no_rtti_obj = env_without_rtti.Object(
target='gtest_unittest_no_rtti',
source='../test/gtest_unittest.cc')
gtest_all_no_rtti_obj = env_without_rtti.Object(
target='gtest_all_no_rtti',
source='../src/gtest-all.cc')
gtest_main_no_rtti_obj = env_without_rtti.Object(
target='gtest_main_no_rtti',
source='../src/gtest_main.cc')
GtestBinary(env_without_rtti,
'gtest_no_rtti_test',
[],
gtest_unittest_no_rtti_obj +
gtest_all_no_rtti_obj +
gtest_main_no_rtti_obj)
# Builds a test for gtest's own TR1 tuple implementation.
gtest_all_use_own_tuple_obj = env_use_own_tuple.Object(
target='gtest_all_use_own_tuple',
source='../src/gtest-all.cc')
gtest_main_use_own_tuple_obj = env_use_own_tuple.Object(
target='gtest_main_use_own_tuple',
source='../src/gtest_main.cc')
GtestBinary(env_use_own_tuple,
'gtest-tuple_test',
[],
['../test/gtest-tuple_test.cc',
gtest_all_use_own_tuple_obj,
gtest_main_use_own_tuple_obj])
# Builds a test for gtest features that use tuple.
gtest_param_test_test_use_own_tuple_obj = env_use_own_tuple.Object(
target='gtest_param_test_test_use_own_tuple',
source='../test/gtest-param-test_test.cc')
gtest_param_test2_test_use_own_tuple_obj = env_use_own_tuple.Object(
target='gtest_param_test2_test_use_own_tuple',
source='../test/gtest-param-test2_test.cc')
GtestBinary(env_use_own_tuple,
'gtest_use_own_tuple_test',
[],
gtest_param_test_test_use_own_tuple_obj +
gtest_param_test2_test_use_own_tuple_obj +
gtest_all_use_own_tuple_obj)
# TODO(wan@google.com): simplify the definition of build targets that
# use alternative environments.
# We need to disable some optimization flags for some tests on
# Windows; otherwise the redirection of stdout does not work
# (apparently because of a compiler bug).
env_with_less_optimization = env.Clone()
if env_with_less_optimization['PLATFORM'] == 'win32':
linker_flags = env_with_less_optimization['LINKFLAGS']
for flag in ["/O1", "/Os", "/Og", "/Oy"]:
for flag in ['/O1', '/Os', '/Og', '/Oy']:
if flag in linker_flags:
linker_flags.remove(flag)
GtestUnitTest(env_with_less_optimization, 'gtest_env_var_test_', gtest)
GtestUnitTest(env_with_less_optimization, 'gtest_uninitialized_test_', gtest)
def GtestSample(env, target, gtest_lib, additional_sources=None):
"""Helper to create gtest samples.
# Assuming POSIX-like environment with GCC.
# TODO(vladl@google.com): sniff presence of pthread_atfork instead of
# selecting on a platform.
env_with_threads = env.Clone()
if env_with_threads['PLATFORM'] != 'win32':
env_with_threads.Append(CCFLAGS=['-pthread'])
env_with_threads.Append(LINKFLAGS=['-pthread'])
env_without_rtti = env.Clone()
if env_without_rtti['PLATFORM'] == 'win32':
env_without_rtti.Append(CCFLAGS=['/GR-'])
else:
env_without_rtti.Append(CCFLAGS=['-fno-rtti'])
env_without_rtti.Append(CPPDEFINES='GTEST_HAS_RTTI=0')
############################################################
# Helpers for creating build targets.
def GtestObject(build_env, source, obj_suffix=None):
"""Returns a target to build an object file from the given .cc source file.
When obj_suffix is provided, appends it to the end of the object
file base name.
"""
if obj_suffix:
obj_suffix = '_' + obj_suffix
else:
obj_suffix = ''
return build_env.Object(
target=os.path.basename(source).rstrip('.cc') + obj_suffix,
source=source)
def GtestStaticLibrary(build_env, lib_target, sources, obj_suffix=None):
"""Returns a target to build the given static library from sources."""
if obj_suffix:
srcs = [GtestObject(build_env, src, obj_suffix) for src in sources]
else:
srcs = sources
return build_env.StaticLibrary(target=lib_target, source=srcs)
def GtestBinary(build_env, target, gtest_lib, sources, obj_suffix=None):
"""Creates a target to build a binary (either test or sample).
Args:
env: The SCons construction environment to use to build.
target: The basename of the target unit test .cc file.
gtest_lib: The gtest lib to use.
build_env: The SCons construction environment to use to build.
target: The basename of the target's main source file, also used as the
target name.
gtest_lib: The gtest library to use.
sources: A list of source files in the target.
obj_suffix: A suffix to append to all object file's basenames.
"""
if obj_suffix:
srcs = [] # The object targets corresponding to sources.
for src in sources:
if type(src) is str:
srcs.append(GtestObject(build_env, src, obj_suffix))
else:
srcs.append(src)
else:
srcs = sources
if gtest_lib:
gtest_libs=[gtest_lib]
else:
gtest_libs=[]
binary = build_env.Program(target=target, source=srcs, LIBS=gtest_libs)
if 'EXE_OUTPUT' in build_env.Dictionary():
build_env.Install('$EXE_OUTPUT', source=[binary])
def GtestTest(build_env, target, gtest_lib, additional_sources=None):
"""Creates a target to build the given test.
Args:
build_env: The SCons construction environment to use to build.
target: The basename of the target test .cc file.
gtest_lib: The gtest lib to use.
additional_sources: A list of additional source files in the target.
"""
GtestBinary(env,
target,
[gtest_lib],
ConstructSourceList(target, "../samples",
additional_sources=additional_sources))
GtestBinary(build_env, target, gtest_lib,
['../test/%s.cc' % target] + (additional_sources or []))
def GtestSample(build_env, target, gtest_lib, additional_sources=None):
"""Creates a target to build the given sample.
Args:
build_env: The SCons construction environment to use to build.
target: The basename of the target sample .cc file.
gtest_lib: The gtest lib to use.
additional_sources: A list of additional source files in the target.
"""
GtestBinary(build_env, target, gtest_lib,
['../samples/%s.cc' % target] + (additional_sources or []))
############################################################
# Object and library targets.
# Sources used by base library and library that includes main.
gtest_source = '../src/gtest-all.cc'
gtest_main_source = '../src/gtest_main.cc'
gtest_main_obj = GtestObject(env, gtest_main_source)
gtest_unittest_obj = GtestObject(env, '../test/gtest_unittest.cc')
# gtest.lib to be used by most apps (if you have your own main
# function).
gtest = env.StaticLibrary(target='gtest',
source=[gtest_source])
# gtest_main.lib can be used if you just want a basic main function;
# it is also used by some tests for Google Test itself.
gtest_main = env.StaticLibrary(target='gtest_main',
source=[gtest_source, gtest_main_obj])
gtest_ex = GtestStaticLibrary(
env_with_exceptions, 'gtest_ex', [gtest_source], obj_suffix='ex')
gtest_ex_main = GtestStaticLibrary(
env_with_exceptions, 'gtest_ex_main', [gtest_source, gtest_main_source],
obj_suffix='ex')
gtest_use_own_tuple_main = GtestStaticLibrary(
env_use_own_tuple, 'gtest_use_own_tuple_main',
[gtest_source, gtest_main_source],
obj_suffix='use_own_tuple')
# Install the libraries if needed.
if 'LIB_OUTPUT' in env.Dictionary():
env.Install('$LIB_OUTPUT', source=[gtest, gtest_main, gtest_ex_main])
############################################################
# Test targets using the standard environment.
GtestTest(env, 'gtest-filepath_test', gtest_main)
GtestTest(env, 'gtest-message_test', gtest_main)
GtestTest(env, 'gtest-options_test', gtest_main)
GtestTest(env, 'gtest_environment_test', gtest)
GtestTest(env, 'gtest_main_unittest', gtest_main)
GtestTest(env, 'gtest_no_test_unittest', gtest)
GtestTest(env, 'gtest_pred_impl_unittest', gtest_main)
GtestTest(env, 'gtest_prod_test', gtest_main,
additional_sources=['../test/production.cc'])
GtestTest(env, 'gtest_repeat_test', gtest)
GtestTest(env, 'gtest_sole_header_test', gtest_main)
GtestTest(env, 'gtest-test-part_test', gtest_main)
GtestTest(env, 'gtest-typed-test_test', gtest_main,
additional_sources=['../test/gtest-typed-test2_test.cc'])
GtestTest(env, 'gtest-param-test_test', gtest,
additional_sources=['../test/gtest-param-test2_test.cc'])
GtestTest(env, 'gtest_output_test_', gtest)
GtestTest(env, 'gtest_color_test_', gtest)
GtestTest(env, 'gtest-linked_ptr_test', gtest_main)
GtestTest(env, 'gtest-port_test', gtest_main)
GtestTest(env, 'gtest_break_on_failure_unittest_', gtest)
GtestTest(env, 'gtest_filter_unittest_', gtest)
GtestTest(env, 'gtest_help_test_', gtest_main)
GtestTest(env, 'gtest_list_tests_unittest_', gtest)
GtestTest(env, 'gtest_throw_on_failure_test_', gtest)
GtestTest(env, 'gtest_xml_outfile1_test_', gtest_main)
GtestTest(env, 'gtest_xml_outfile2_test_', gtest_main)
GtestTest(env, 'gtest_xml_output_unittest_', gtest_main)
GtestBinary(env, 'gtest_unittest', gtest_main, [gtest_unittest_obj])
############################################################
# Tests targets using custom environments.
GtestTest(env_with_exceptions, 'gtest_throw_on_failure_ex_test', gtest_ex)
GtestTest(env_with_threads, 'gtest-death-test_test', gtest_main)
GtestTest(env_with_less_optimization, 'gtest_env_var_test_', gtest)
GtestTest(env_with_less_optimization, 'gtest_uninitialized_test_', gtest)
GtestBinary(env_use_own_tuple, 'gtest-tuple_test', gtest_use_own_tuple_main,
['../test/gtest-tuple_test.cc'],
obj_suffix='use_own_tuple')
GtestBinary(env_use_own_tuple, 'gtest_use_own_tuple_test',
gtest_use_own_tuple_main,
['../test/gtest-param-test_test.cc',
'../test/gtest-param-test2_test.cc'],
obj_suffix='use_own_tuple')
GtestBinary(env_with_exceptions, 'gtest_ex_unittest', gtest_ex_main,
['../test/gtest_unittest.cc'], obj_suffix='ex')
GtestBinary(env_without_rtti, 'gtest_no_rtti_test', None,
['../test/gtest_unittest.cc', gtest_source, gtest_main_source],
obj_suffix='no_rtti')
############################################################
# Sample targets.
# Use the GTEST_BUILD_SAMPLES build variable to control building of samples.
# In your SConstruct file, add
@ -330,7 +333,6 @@ def GtestSample(env, target, gtest_lib, additional_sources=None):
# vars.Add(BoolVariable('GTEST_BUILD_SAMPLES', 'Build samples', True))
# my_environment = Environment(variables = vars, ...)
# Then, in the command line use GTEST_BUILD_SAMPLES=true to enable them.
#
if env.get('GTEST_BUILD_SAMPLES', False):
sample1_obj = env.Object('../samples/sample1.cc')
GtestSample(env, 'sample1_unittest', gtest_main,

View File

@ -472,102 +472,6 @@ class TestPropertyKeyIs {
String key_;
};
// The result of a single Test. This includes a list of
// TestPartResults, a list of TestProperties, a count of how many
// death tests there are in the Test, and how much time it took to run
// the Test.
//
// TestResult is not copyable.
class TestResult {
public:
// Creates an empty TestResult.
TestResult();
// D'tor. Do not inherit from TestResult.
~TestResult();
// Gets the list of TestPartResults.
const internal::List<TestPartResult> & test_part_results() const {
return test_part_results_;
}
// Gets the list of TestProperties.
const internal::List<internal::TestProperty> & test_properties() const {
return test_properties_;
}
// Gets the number of successful test parts.
int successful_part_count() const;
// Gets the number of failed test parts.
int failed_part_count() const;
// Gets the number of all test parts. This is the sum of the number
// of successful test parts and the number of failed test parts.
int total_part_count() const;
// Returns true iff the test passed (i.e. no test part failed).
bool Passed() const { return !Failed(); }
// Returns true iff the test failed.
bool Failed() const { return failed_part_count() > 0; }
// Returns true iff the test fatally failed.
bool HasFatalFailure() const;
// Returns true iff the test has a non-fatal failure.
bool HasNonfatalFailure() const;
// Returns the elapsed time, in milliseconds.
TimeInMillis elapsed_time() const { return elapsed_time_; }
// Sets the elapsed time.
void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
// Adds a test part result to the list.
void AddTestPartResult(const TestPartResult& test_part_result);
// Adds a test property to the list. The property is validated and may add
// a non-fatal failure if invalid (e.g., if it conflicts with reserved
// key names). If a property is already recorded for the same key, the
// value will be updated, rather than storing multiple values for the same
// key.
void RecordProperty(const internal::TestProperty& test_property);
// Adds a failure if the key is a reserved attribute of Google Test
// testcase tags. Returns true if the property is valid.
// TODO(russr): Validate attribute names are legal and human readable.
static bool ValidateTestProperty(const internal::TestProperty& test_property);
// Returns the death test count.
int death_test_count() const { return death_test_count_; }
// Increments the death test count, returning the new count.
int increment_death_test_count() { return ++death_test_count_; }
// Clears the test part results.
void ClearTestPartResults() { test_part_results_.Clear(); }
// Clears the object.
void Clear();
private:
// Protects mutable state of the property list and of owned properties, whose
// values may be updated.
internal::Mutex test_properites_mutex_;
// The list of TestPartResults
internal::List<TestPartResult> test_part_results_;
// The list of TestProperties
internal::List<internal::TestProperty> test_properties_;
// Running count of death tests.
int death_test_count_;
// The elapsed time, in milliseconds.
TimeInMillis elapsed_time_;
// We disallow copying TestResult.
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
}; // class TestResult
class TestInfoImpl {
public:
TestInfoImpl(TestInfo* parent, const char* test_case_name,

View File

@ -1778,7 +1778,9 @@ String AppendUserMessage(const String& gtest_msg,
// Creates an empty TestResult.
TestResult::TestResult()
: death_test_count_(0),
: test_part_results_(new List<TestPartResult>),
test_properties_(new List<TestProperty>),
death_test_count_(0),
elapsed_time_(0) {
}
@ -1786,9 +1788,14 @@ TestResult::TestResult()
TestResult::~TestResult() {
}
// Clears the test part results.
void TestResult::ClearTestPartResults() {
test_part_results_->Clear();
}
// Adds a test part result to the list.
void TestResult::AddTestPartResult(const TestPartResult& test_part_result) {
test_part_results_.PushBack(test_part_result);
test_part_results_->PushBack(test_part_result);
}
// Adds a test property to the list. If a property with the same key as the
@ -1800,9 +1807,9 @@ void TestResult::RecordProperty(const TestProperty& test_property) {
}
MutexLock lock(&test_properites_mutex_);
ListNode<TestProperty>* const node_with_matching_key =
test_properties_.FindIf(TestPropertyKeyIs(test_property.key()));
test_properties_->FindIf(TestPropertyKeyIs(test_property.key()));
if (node_with_matching_key == NULL) {
test_properties_.PushBack(test_property);
test_properties_->PushBack(test_property);
return;
}
TestProperty& property_with_matching_key = node_with_matching_key->element();
@ -1826,8 +1833,8 @@ bool TestResult::ValidateTestProperty(const TestProperty& test_property) {
// Clears the object.
void TestResult::Clear() {
test_part_results_.Clear();
test_properties_.Clear();
test_part_results_->Clear();
test_properties_->Clear();
death_test_count_ = 0;
elapsed_time_ = 0;
}
@ -1839,7 +1846,7 @@ static bool TestPartPassed(const TestPartResult & result) {
// Gets the number of successful test parts.
int TestResult::successful_part_count() const {
return test_part_results_.CountIf(TestPartPassed);
return test_part_results_->CountIf(TestPartPassed);
}
// Returns true iff the test part failed.
@ -1849,7 +1856,7 @@ static bool TestPartFailed(const TestPartResult & result) {
// Gets the number of failed test parts.
int TestResult::failed_part_count() const {
return test_part_results_.CountIf(TestPartFailed);
return test_part_results_->CountIf(TestPartFailed);
}
// Returns true iff the test part fatally failed.
@ -1859,7 +1866,7 @@ static bool TestPartFatallyFailed(const TestPartResult& result) {
// Returns true iff the test fatally failed.
bool TestResult::HasFatalFailure() const {
return test_part_results_.CountIf(TestPartFatallyFailed) > 0;
return test_part_results_->CountIf(TestPartFatallyFailed) > 0;
}
// Returns true iff the test part non-fatally failed.
@ -1869,13 +1876,13 @@ static bool TestPartNonfatallyFailed(const TestPartResult& result) {
// Returns true iff the test has a non-fatal failure.
bool TestResult::HasNonfatalFailure() const {
return test_part_results_.CountIf(TestPartNonfatallyFailed) > 0;
return test_part_results_->CountIf(TestPartNonfatallyFailed) > 0;
}
// Gets the number of all test parts. This is the sum of the number
// of successful test parts and the number of failed test parts.
int TestResult::total_part_count() const {
return test_part_results_.size();
return test_part_results_->size();
}
} // namespace internal