Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "gtest_stubs.h"
     18 
     19 namespace testing {
     20 
     21 bool g_test_status = false;
     22 
     23 namespace detail {
     24 
     25 void TestRegistry::RunAllTests() {
     26   int test_count = 0;
     27   int test_failures = 0;
     28   for (TestDeclarationBase* decl = tests_; decl; decl = decl->next) {
     29     TestInstanceBase* instance = decl->create_function();
     30     fprintf(stderr, "[ %s ] Starting...\n", decl->name);
     31     g_test_status = true;
     32     instance->Run();
     33     test_failures += g_test_status ? 0 : 1;
     34     ++test_count;
     35     fprintf(stderr, "[ %s ] %s\n", decl->name, g_test_status ? "PASS" : "FAIL");
     36     delete instance;
     37   }
     38 
     39   fprintf(stderr, "Ran %d tests, %d failures.\n", test_count, test_failures);
     40 }
     41 
     42 void TestRegistry::Register(TestDeclarationBase* test_declaration) {
     43   test_declaration->next = tests_;
     44   tests_ = test_declaration;
     45 }
     46 
     47 TestRegistry TestRegistry::g_instance;
     48 
     49 }  // namespace detail
     50 }  // namespace testing
     51 
     52 int main() {
     53   testing::detail::TestRegistry::instance()->RunAllTests();
     54 }
     55