• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "TestsController.h"
27 
28 #include "Test.h"
29 #include <algorithm>
30 #include <assert.h>
31 
32 namespace TestWebKitAPI {
33 
shared()34 TestsController& TestsController::shared()
35 {
36     static TestsController& shared = *new TestsController;
37     return shared;
38 }
39 
TestsController()40 TestsController::TestsController()
41     : m_testFailed(false)
42     , m_currentTest(0)
43 {
44 }
45 
dumpTestNames()46 void TestsController::dumpTestNames()
47 {
48     std::map<std::string, CreateTestFunction>::const_iterator it = m_createTestFunctions.begin();
49     std::map<std::string, CreateTestFunction>::const_iterator end = m_createTestFunctions.end();
50     for (; it != end; ++it)
51         printf("%s\n", (*it).first.c_str());
52 }
53 
runTestNamed(const std::string & identifier)54 bool TestsController::runTestNamed(const std::string& identifier)
55 {
56     CreateTestFunction createTestFunction = m_createTestFunctions[identifier];
57     if (!createTestFunction) {
58         printf("ERROR: Test not found - %s\n", identifier.c_str());
59         return false;
60     }
61 
62     m_currentTest = createTestFunction(identifier);
63     m_currentTest->run();
64 
65     delete m_currentTest;
66     m_currentTest = 0;
67 
68     return !m_testFailed;
69 }
70 
testFailed(const char * file,int line,const char * message)71 void TestsController::testFailed(const char* file, int line, const char* message)
72 {
73     m_testFailed = true;
74     printf("FAIL: %s\n\t%s (%s:%d)\n", m_currentTest->name().c_str(), message, file, line);
75 }
76 
registerCreateTestFunction(const std::string & identifier,CreateTestFunction createTestFunction)77 void TestsController::registerCreateTestFunction(const std::string& identifier, CreateTestFunction createTestFunction)
78 {
79     m_createTestFunctions[identifier] = createTestFunction;
80 }
81 
82 } // namespace TestWebKitAPI
83