"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/test/gtest-unittest-api_test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gtest-unittest-api_test.cc  (googletest-release-1.11.0):gtest-unittest-api_test.cc  (googletest-release-1.12.0)
skipping to change at line 35 skipping to change at line 35
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// The Google C++ Testing and Mocking Framework (Google Test) // The Google C++ Testing and Mocking Framework (Google Test)
// //
// This file contains tests verifying correctness of data provided via // This file contains tests verifying correctness of data provided via
// UnitTest's public methods. // UnitTest's public methods.
#include "gtest/gtest.h"
#include <string.h> // For strcmp. #include <string.h> // For strcmp.
#include <algorithm> #include <algorithm>
#include "gtest/gtest.h"
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
namespace testing { namespace testing {
namespace internal { namespace internal {
template <typename T> template <typename T>
struct LessByName { struct LessByName {
bool operator()(const T* a, const T* b) { bool operator()(const T* a, const T* b) {
return strcmp(a->name(), b->name()) < 0; return strcmp(a->name(), b->name()) < 0;
} }
}; };
class UnitTestHelper { class UnitTestHelper {
public: public:
// Returns the array of pointers to all test suites sorted by the test suite // Returns the array of pointers to all test suites sorted by the test suite
// name. The caller is responsible for deleting the array. // name. The caller is responsible for deleting the array.
static TestSuite const** GetSortedTestSuites() { static TestSuite const** GetSortedTestSuites() {
UnitTest& unit_test = *UnitTest::GetInstance(); UnitTest& unit_test = *UnitTest::GetInstance();
auto const** const test_suites = new const TestSuite*[static_cast<size_t>( auto const** const test_suites = new const TestSuite*[static_cast<size_t>(
unit_test.total_test_suite_count())]; unit_test.total_test_suite_count())];
for (int i = 0; i < unit_test.total_test_suite_count(); ++i) for (int i = 0; i < unit_test.total_test_suite_count(); ++i)
test_suites[i] = unit_test.GetTestSuite(i); test_suites[i] = unit_test.GetTestSuite(i);
std::sort(test_suites, std::sort(test_suites, test_suites + unit_test.total_test_suite_count(),
test_suites + unit_test.total_test_suite_count(),
LessByName<TestSuite>()); LessByName<TestSuite>());
return test_suites; return test_suites;
} }
// Returns the test suite by its name. The caller doesn't own the returned // Returns the test suite by its name. The caller doesn't own the returned
// pointer. // pointer.
static const TestSuite* FindTestSuite(const char* name) { static const TestSuite* FindTestSuite(const char* name) {
UnitTest& unit_test = *UnitTest::GetInstance(); UnitTest& unit_test = *UnitTest::GetInstance();
for (int i = 0; i < unit_test.total_test_suite_count(); ++i) { for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
const TestSuite* test_suite = unit_test.GetTestSuite(i); const TestSuite* test_suite = unit_test.GetTestSuite(i);
if (0 == strcmp(test_suite->name(), name)) if (0 == strcmp(test_suite->name(), name)) return test_suite;
return test_suite;
} }
return nullptr; return nullptr;
} }
// Returns the array of pointers to all tests in a particular test suite // Returns the array of pointers to all tests in a particular test suite
// sorted by the test name. The caller is responsible for deleting the // sorted by the test name. The caller is responsible for deleting the
// array. // array.
static TestInfo const** GetSortedTests(const TestSuite* test_suite) { static TestInfo const** GetSortedTests(const TestSuite* test_suite) {
TestInfo const** const tests = new const TestInfo*[static_cast<size_t>( TestInfo const** const tests = new const TestInfo*[static_cast<size_t>(
test_suite->total_test_count())]; test_suite->total_test_count())];
for (int i = 0; i < test_suite->total_test_count(); ++i) for (int i = 0; i < test_suite->total_test_count(); ++i)
tests[i] = test_suite->GetTestInfo(i); tests[i] = test_suite->GetTestInfo(i);
std::sort(tests, tests + test_suite->total_test_count(), std::sort(tests, tests + test_suite->total_test_count(),
LessByName<TestInfo>()); LessByName<TestInfo>());
return tests; return tests;
} }
}; };
template <typename T> class TestSuiteWithCommentTest : public Test {}; template <typename T>
class TestSuiteWithCommentTest : public Test {};
TYPED_TEST_SUITE(TestSuiteWithCommentTest, Types<int>); TYPED_TEST_SUITE(TestSuiteWithCommentTest, Types<int>);
TYPED_TEST(TestSuiteWithCommentTest, Dummy) {} TYPED_TEST(TestSuiteWithCommentTest, Dummy) {}
const int kTypedTestSuites = 1; const int kTypedTestSuites = 1;
const int kTypedTests = 1; const int kTypedTests = 1;
// We can only test the accessors that do not change value while tests run. // We can only test the accessors that do not change value while tests run.
// Since tests can be run in any order, the values the accessors that track // Since tests can be run in any order, the values the accessors that track
// test execution (such as failed_test_count) can not be predicted. // test execution (such as failed_test_count) can not be predicted.
TEST(ApiTest, UnitTestImmutableAccessorsWork) { TEST(ApiTest, UnitTestImmutableAccessorsWork) {
skipping to change at line 322 skipping to change at line 322
EXPECT_EQ(0, tests[0]->result()->test_property_count()); EXPECT_EQ(0, tests[0]->result()->test_property_count());
delete[] tests; delete[] tests;
delete[] test_suites; delete[] test_suites;
} }
}; };
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
int main(int argc, char **argv) { int main(int argc, char** argv) {
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
AddGlobalTestEnvironment(new testing::internal::FinalSuccessChecker()); AddGlobalTestEnvironment(new testing::internal::FinalSuccessChecker());
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
 End of changes. 9 change blocks. 
10 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)