Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
90030d74
Commit
90030d74
authored
Mar 20, 2010
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes comments and tests for the moment of generator parameter evaluation in…
Fixes comments and tests for the moment of generator parameter evaluation in INSTANTIATE_TEST_CASE_P.
parent
06d04c09
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
11 deletions
+25
-11
gtest-param-test.h
include/gtest/gtest-param-test.h
+6
-3
gtest-param-test_test.cc
test/gtest-param-test_test.cc
+19
-8
No files found.
include/gtest/gtest-param-test.h
View file @
90030d74
...
...
@@ -133,9 +133,12 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
// in the given test case, whether their definitions come before or
// AFTER the INSTANTIATE_TEST_CASE_P statement.
//
// Please also note that generator expressions are evaluated in
// RUN_ALL_TESTS(), after main() has started. This allows evaluation of
// parameter list based on command line parameters.
// Please also note that generator expressions (including parameters to the
// generators) are evaluated in InitGoogleTest(), after main() has started.
// This allows the user on one hand, to adjust generator parameters in order
// to dynamically determine a set of tests to run and on the other hand,
// give the user a chance to inspect the generated tests with Google Test
// reflection API before RUN_ALL_TESTS() is executed.
//
// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
// for more examples.
...
...
test/gtest-param-test_test.cc
View file @
90030d74
...
...
@@ -692,13 +692,15 @@ INSTANTIATE_TEST_CASE_P(TestExpansionModule, TestGenerationTest,
ValuesIn
(
test_generation_params
));
// This test verifies that the element sequence (third parameter of
// INSTANTIATE_TEST_CASE_P) is evaluated in RUN_ALL_TESTS and not at the call
// site of INSTANTIATE_TEST_CASE_P.
// For that, we declare param_value_ to be a static member of
// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in main(),
// just before invocation of RUN_ALL_TESTS. If the sequence is evaluated
// before that moment, INSTANTIATE_TEST_CASE_P will create a test with
// parameter 0, and the test body will fail the assertion.
// INSTANTIATE_TEST_CASE_P) is evaluated in InitGoogleTest() and neither at
// the call site of INSTANTIATE_TEST_CASE_P nor in RUN_ALL_TESTS(). For
// that, we declare param_value_ to be a static member of
// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in
// main(), just before invocation of InitGoogleTest(). After calling
// InitGoogleTest(), we set the value to 2. If the sequence is evaluated
// before or after InitGoogleTest, INSTANTIATE_TEST_CASE_P will create a
// test with parameter other than 1, and the test body will fail the
// assertion.
class
GeneratorEvaluationTest
:
public
TestWithParam
<
int
>
{
public
:
static
int
param_value
()
{
return
param_value_
;
}
...
...
@@ -815,10 +817,19 @@ int main(int argc, char **argv) {
#if GTEST_HAS_PARAM_TEST
// Used in TestGenerationTest test case.
AddGlobalTestEnvironment
(
TestGenerationTest
::
Environment
::
Instance
());
// Used in GeneratorEvaluationTest test case.
// Used in GeneratorEvaluationTest test case. Tests that the updated value
// will be picked up for instantiating tests in GeneratorEvaluationTest.
GeneratorEvaluationTest
::
set_param_value
(
1
);
#endif // GTEST_HAS_PARAM_TEST
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
#if GTEST_HAS_PARAM_TEST
// Used in GeneratorEvaluationTest test case. Tests that value updated
// here will NOT be used for instantiating tests in
// GeneratorEvaluationTest.
GeneratorEvaluationTest
::
set_param_value
(
2
);
#endif // GTEST_HAS_PARAM_TEST
return
RUN_ALL_TESTS
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment