Skip to content

Commit

Permalink
#169: Merge AXRWrapper functionality into AXRCore and remove the former.
Browse files Browse the repository at this point in the history
Moved AXRTest* to a new target as that sort of functionality doesn't
belong in core and should later be integrated into a future unit test.
  • Loading branch information
jakepetroules committed Oct 19, 2012
1 parent 2d57143 commit 2d7d9a1
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 760 deletions.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ if(APPLE)
add_subdirectory(cocoa)
endif()

# TODO: Remove this and integrate these files' functionality into unit tests
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/TEST")
add_subdirectory(TEST)

add_subdirectory(prototype)

if(AXR_BUILD_EXAMPLES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
#include "AXRDebugging.h"
#include "AXRInitializer.h"
#include "AXRTestProducer.h"
#include "AXRTestRunner.h"

using namespace AXR;

// Constructor with name and the queue to use
AXRTestProducer::AXRTestProducer(AXRWrapper * wrapper, std::vector<QUrl> test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status)
AXRTestProducer::AXRTestProducer(AXRTestRunner * wrapper, std::vector<QUrl> test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status)
{
this->wrapper = wrapper;
this->test = test;
Expand All @@ -75,15 +76,12 @@ void AXRTestProducer::operator () ()
AXRString expectedRep;

//load the XML
AXRCore core = *AXRCore::getInstance();
AXRWrapper * wrapper = this->wrapper;
core = *AXRCore::getInstance();
AXRCore *core = AXRCore::getInstance();

testLoaded = wrapper->loadXMLFile(this->test[0]);
testLoaded = core->loadXMLFile(this->test[0]);

if (testLoaded)
{
AXRCore* core = AXRCore::getInstance();
AXRController::p controller = core->getController();
HSSContainer::p root = controller->getRoot();
core->getRender()->windowWidth = 400.;
Expand All @@ -101,7 +99,7 @@ void AXRTestProducer::operator () ()
//load the "expected" file
if (testLoaded)
{
AXRBuffer::p expectedFile = this->wrapper->getFile(test[1]);
AXRBuffer::p expectedFile = core->getFile(test[1]);
if (!expectedFile->isValid())
{
std_log("could not load file with expected results");
Expand All @@ -127,7 +125,7 @@ void AXRTestProducer::operator () ()
this->statusMutex.lock();
this->status->setContentText(AXRString("Passed %1 out of %2").arg(*this->totalPassed).arg(*this->totalTests));
this->statusMutex.unlock();
this->wrapper->setNeedsDisplay(true);
core->setNeedsDisplay(true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@

namespace AXR
{
class AXRWrapper;
class AXRTestRunner;

class AXR_API AXRTestProducer : public QRunnable
{
private:
AXRWrapper * wrapper;
AXRTestRunner * wrapper;
std::vector<QUrl> test; // the filename of the test
unsigned * totalTests;
unsigned * totalPassed;
Expand All @@ -66,7 +66,7 @@ namespace AXR
static QMutex statusMutex;

public:
AXRTestProducer(AXRWrapper * wrapper, std::vector<QUrl> test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status);
AXRTestProducer(AXRTestRunner *testRunner, std::vector<QUrl> test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status);
void operator () ();
void run();
};
Expand Down
102 changes: 102 additions & 0 deletions src/TEST/AXRTestRunner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/********************************************************************
* a A
* AM\/MA
* (MA:MMD
* :: VD
* :: º
* ::
* :: ** .A$MMMMND AMMMD AMMM6 MMMM MMMM6
+ 6::Z. TMMM MMMMMMMMMDA VMMMD AMMM6 MMMMMMMMM6
* 6M:AMMJMMOD V MMMA VMMMD AMMM6 MMMMMMM6
* :: TMMTMC ___MMMM VMMMMMMM6 MMMM
* MMM TMMMTTM, AMMMMMMMM VMMMMM6 MMMM
* :: MM TMMTMMMD MMMMMMMMMM MMMMMM MMMM
* :: MMMTTMMM6 MMMMMMMMMMM AMMMMMMD MMMM
* :. MMMMMM6 MMMM MMMM AMMMMMMMMD MMMM
* TTMMT MMMM MMMM AMMM6 MMMMD MMMM
* TMMMM8 MMMMMMMMMMM AMMM6 MMMMD MMMM
* TMMMMMM$ MMMM6 MMMM AMMM6 MMMMD MMMM
* TMMM MMMM
* TMMM .MMM
* TMM .MMD ARBITRARY·······XML········RENDERING
* TMM MMA ====================================
* TMN MM
* MN ZM
* MM,
*
*
* AUTHORS: see AUTHORS file
*
* COPYRIGHT: ©2012 - All Rights Reserved
*
* LICENSE: see LICENSE file
*
* WEB: http://axr.vg
*
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS"
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
* FITNESS FOR A PARTICULAR PURPOSE.
*
********************************************************************/

#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <QUrl>
#include "AXRDebugging.h"
#include "AXRInitializer.h"
#include "AXRTestThread.h"
#include "AXRTestRunner.h"
#include "AXRWarning.h"
#include "HSSFunction.h"
#include "HSSSelFunction.h"

using namespace AXR;

AXRTestRunner::AXRTestRunner()
{
}

AXRTestRunner::~AXRTestRunner()
{
}

AXRString AXRTestRunner::getPathToTestsFile()
{
QDir dir = QDir(QCoreApplication::applicationDirPath());
#ifdef Q_WS_MACX
dir.cdUp();
#endif
dir.cd("Resources");
dir.cd("views");
return dir.filePath("layoutTests.hss");
}

void AXRTestRunner::executeLayoutTests(HSSObservableProperty passnull, void*data)
{
HSSContainer::p status;
AXRCore* core = AXRCore::getInstance();
HSSContainer::p root = core->getController()->getRoot();
std::deque<HSSParserNode::p> arguments = *(std::deque<HSSParserNode::p>*)data;

for (std::deque<HSSParserNode::p>::iterator it = arguments.begin(); it != arguments.end(); ++it)
{
HSSParserNode::p argument = *it;
if (argument->isA(HSSFunctionTypeSel))
{
HSSSelFunction::p selFunction = qSharedPointerCast<HSSSelFunction>(argument);
QVariant remoteValue = selFunction->evaluate();
if (remoteValue.canConvert<std::vector< std::vector<HSSDisplayObject::p> > >())
{
std::vector< std::vector<HSSDisplayObject::p> > selection = remoteValue.value<std::vector< std::vector<HSSDisplayObject::p> > >();
std::vector<HSSDisplayObject::p> innerSelection = selection[0];
status = HSSContainer::asContainer(innerSelection[0]);
}
}
}

AXRTestThread thrd(this, QUrl::fromLocalFile(this->getPathToTestsFile()), status);
thrd.start();
}
85 changes: 85 additions & 0 deletions src/TEST/AXRTestRunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/********************************************************************
* a A
* AM\/MA
* (MA:MMD
* :: VD
* :: º
* ::
* :: ** .A$MMMMND AMMMD AMMM6 MMMM MMMM6
+ 6::Z. TMMM MMMMMMMMMDA VMMMD AMMM6 MMMMMMMMM6
* 6M:AMMJMMOD V MMMA VMMMD AMMM6 MMMMMMM6
* :: TMMTMC ___MMMM VMMMMMMM6 MMMM
* MMM TMMMTTM, AMMMMMMMM VMMMMM6 MMMM
* :: MM TMMTMMMD MMMMMMMMMM MMMMMM MMMM
* :: MMMTTMMM6 MMMMMMMMMMM AMMMMMMD MMMM
* :. MMMMMM6 MMMM MMMM AMMMMMMMMD MMMM
* TTMMT MMMM MMMM AMMM6 MMMMD MMMM
* TMMMM8 MMMMMMMMMMM AMMM6 MMMMD MMMM
* TMMMMMM$ MMMM6 MMMM AMMM6 MMMMD MMMM
* TMMM MMMM
* TMMM .MMM
* TMM .MMD ARBITRARY·······XML········RENDERING
* TMM MMA ====================================
* TMN MM
* MN ZM
* MM,
*
*
* AUTHORS: see AUTHORS file
*
* COPYRIGHT: ©2012 - All Rights Reserved
*
* LICENSE: see LICENSE file
*
* WEB: http://axr.vg
*
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS"
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
* FITNESS FOR A PARTICULAR PURPOSE.
*
********************************************************************/

#ifndef AXRWRAPPER_H
#define AXRWRAPPER_H

#include <QMap>
#include <QMutex>
#include <QSharedPointer>
#include <QThread>
#include <QThreadPool>
#include "AXRError.h"
#include "AXRBuffer.h"
#include "HSSContainer.h"
#include "HSSObservableProperties.h"

namespace AXR
{
/**
* @brief This is the abstract superclass from with all OS-specific wrappers
* should inherit from.
*/
class AXR_API AXRTestRunner
{
public:
/**
* Creates a new instance of the wrapper. It will obtain the singleton instance of
* the AXRCore and initialize it.
*/
AXRTestRunner();

/**
* Destructs the wrapper
*/
virtual ~AXRTestRunner();

virtual AXRString getPathToTestsFile();

void executeLayoutTests(HSSObservableProperty passnull, void*data);

QMap<unsigned, AXRBuffer::p> files;
};
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
#include "AXRDebugging.h"
#include "AXRInitializer.h"
#include "AXRTestProducer.h"
#include "AXRTestRunner.h"
#include "AXRTestThread.h"
#include "HSSContainer.h"

using namespace AXR;

AXRTestThread::AXRTestThread(AXRWrapper * wrapper, QUrl url, HSSContainer::p status)
AXRTestThread::AXRTestThread(AXRTestRunner * wrapper, QUrl url, HSSContainer::p status)
{
this->wrapper = wrapper;
this->url = url;
Expand All @@ -67,11 +69,10 @@ void AXRTestThread::operator () ()
try
{
//load the XML file
AXRWrapper * wrapper = this->wrapper;
AXRCore* core = AXRCore::getInstance();
XMLParser::p parser = core->getParserXML();
HSSContainer::p status = this->status;
AXRBuffer::p testsFile = wrapper->getFile(this->url);
AXRBuffer::p testsFile = core->getFile(this->url);
bool loadingSuccess = parser->loadFile(testsFile);
if (loadingSuccess)
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/debug/AXRTestThread.h → src/TEST/AXRTestThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@

namespace AXR
{
class AXRWrapper;
class AXRTestRunner;

class AXR_API AXRTestThread : public QThread
{
private:
AXRWrapper * wrapper;
AXRTestRunner *wrapper;
QUrl url;
unsigned totalTests;
unsigned totalPassed;
HSSContainer::p status;

public:
AXRTestThread(AXRWrapper * wrapper, QUrl url, HSSContainer::p status);
AXRTestThread(AXRTestRunner *testRunner, QUrl url, HSSContainer::p status);
void operator () ();
void run();
};
Expand Down
25 changes: 25 additions & 0 deletions src/TEST/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if(BUILD_SHARED_LIBS)
add_definitions(-DAXR_EXPORTS)
endif()

# Find all sources
file(GLOB_RECURSE test_SOURCES *.c *.cpp *.h)
list(SORT test_SOURCES)

group_by_folder(${CMAKE_CURRENT_SOURCE_DIR} "${test_SOURCES}")

add_library(TEST ${test_SOURCES})
target_link_libraries(TEST ${TARGET_NAME_LIB_CORE})
set_target_properties(TEST PROPERTIES FOLDER Libraries)

if(APPLE AND BUILD_SHARED_LIBS AND AXR_BUILD_FRAMEWORKS)
set_target_properties(TEST PROPERTIES FRAMEWORK TRUE)
endif()

if(IS_RELEASE_BUILD)
install(TARGETS TEST
LIBRARY DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_REL} COMPONENT libraries
ARCHIVE DESTINATION ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_REL} COMPONENT libraries
FRAMEWORK DESTINATION Frameworks COMPONENT frameworks
)
endif()
Loading

0 comments on commit 2d7d9a1

Please sign in to comment.