[Ktutorial-commits] SF.net SVN: ktutorial:[114] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-06 20:52:36
|
Revision: 114 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=114&view=rev Author: danxuliu Date: 2010-03-06 20:52:29 +0000 (Sat, 06 Mar 2010) Log Message: ----------- Add basic version of Tutorial class to store the data of a tutorial. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp trunk/ktutorial/ktutorial-editor/src/Tutorial.h trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-06 17:12:46 UTC (rev 113) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-06 20:52:29 UTC (rev 114) @@ -8,6 +8,7 @@ set(ktutorial_editor_SRCS KTutorialEditor.cpp + Tutorial.cpp ) # Instead of compiling the executable directly from the sources, the sources are Added: trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp 2010-03-06 20:52:29 UTC (rev 114) @@ -0,0 +1,97 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "Tutorial.h" + +#include <QStringList> + +//public: + +Tutorial::Tutorial(QObject* parent) { +} + +QString Tutorial::id() const { + return toLowerCamelCase(mName); +} + +QString Tutorial::name() const { + return mName; +} + +void Tutorial::setName(const QString& name) { + mName = name; + + emit dataChanged(this); +} + +QString Tutorial::description() const { + return mDescription; +} + +void Tutorial::setDescription(const QString& description) { + mDescription = description; + + emit dataChanged(this); +} + +QString Tutorial::licenseText() const { + return mLicenseText; +} + +void Tutorial::setLicenseText(const QString& licenseText) { + mLicenseText = licenseText; + + emit dataChanged(this); +} + +QString Tutorial::customSetupCode() const { + return mCustomSetupCode; +} + +void Tutorial::setCustomSetupCode(const QString& code) { + mCustomSetupCode = code; + + emit dataChanged(this); +} + +QString Tutorial::customTearDownCode() const { + return mCustomTearDownCode; +} + +void Tutorial::setCustomTearDownCode(const QString& code) { + mCustomTearDownCode = code; + + emit dataChanged(this); +} + +//private: + +QString Tutorial::toLowerCamelCase(const QString& text) const { + QStringList words = text.split(' ', QString::SkipEmptyParts); + + QString lowerCamelCase; + words[0][0] = words[0][0].toLower(); + lowerCamelCase += words[0]; + + for (int i=1; i<words.count(); ++i) { + words[i][0] = words[i][0].toUpper(); + lowerCamelCase += words[i]; + } + + return lowerCamelCase; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/Tutorial.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Tutorial.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/Tutorial.h 2010-03-06 20:52:29 UTC (rev 114) @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef TUTORIAL_H +#define TUTORIAL_H + +#include <QObject> + +/** + * Container for tutorial data. + * It stores the data used in KTutorial tutorials, but it has nothing to do with + * it (they don't even know each other). Its purpose is store the data needed to + * generate the code to create a true KTutorial::Tutorial. + * + * When any attribute is modified, dataChanged(Tutorial*) signal is emitted. + */ +class Tutorial: public QObject { +Q_OBJECT +public: + + Tutorial(QObject* parent = 0); + + /** + * Returns the id of this Tutorial. + * The id is a lowerCamelCase version of the name. + * + * @return The id of this Tutorial. + */ + QString id() const; + + QString name() const; + void setName(const QString& name); + + QString description() const; + void setDescription(const QString& description); + + QString licenseText() const; + void setLicenseText(const QString& licenseText); + + QString customSetupCode() const; + void setCustomSetupCode(const QString& code); + + QString customTearDownCode() const; + void setCustomTearDownCode(const QString& code); + +Q_SIGNALS: + + /** + * Emitted when any data in the tutorial changed. + * + * @param tutorial This tutorial. + */ + void dataChanged(Tutorial* tutorial); + +private: + + QString mName; + QString mDescription; + QString mLicenseText; + QString mCustomSetupCode; + QString mCustomTearDownCode; + + /** + * Returns the lowerCamelCase version of the given text. + * + * @param text The string to get its lowerCamelCase version. + * @return The lowerCamelCase version of the text. + */ + QString toLowerCamelCase(const QString& text) const; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/Tutorial.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-06 17:12:46 UTC (rev 113) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-06 20:52:29 UTC (rev 114) @@ -1 +1,25 @@ add_subdirectory(view) + +# Used by kde4_add_unit_test to set the full path to test executables +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) + +# include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial-editor_SOURCE_DIR}/src/view ${ktutorial-editor_BINARY_DIR}/src/view ${KDE4_INCLUDES}) +include_directories(${ktutorial-editor_SOURCE_DIR}/src/ ${KDE4_INCLUDES}) + +MACRO(UNIT_TESTS) + FOREACH(_className ${ARGN}) + set(_testName ${_className}Test) + kde4_add_unit_test(${_testName} TESTNAME ktutorial-editor-unit-${_testName} ${_testName}.cpp) + target_link_libraries(${_testName} ktutorial_editor ${QT_QTTEST_LIBRARY}) + ENDFOREACH(_className) +ENDMACRO(UNIT_TESTS) + +unit_tests(Tutorial) + +MACRO(MEM_TESTS) + FOREACH(_testname ${ARGN}) + add_test(ktutorial-editor-unit-mem-${_testname} ${CMAKE_CURRENT_SOURCE_DIR}/../runMemcheck.py ${CMAKE_CURRENT_BINARY_DIR}/${_testname}Test ${CMAKE_CURRENT_BINARY_DIR}) + ENDFOREACH(_testname) +ENDMACRO(MEM_TESTS) + +mem_tests(Tutorial) Added: trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp 2010-03-06 20:52:29 UTC (rev 114) @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "Tutorial.h" + +class TutorialTest: public QObject { +Q_OBJECT + +private slots: + + void testId(); + + void testSetName(); + + void testSetDescription(); + + void testSetLicenseText(); + + void testSetCustomSetupCode(); + + void testSetCustomTearDownCode(); + +}; + +void TutorialTest::testId() { + Tutorial tutorial; + tutorial.setName("ThE name of a tutoRial"); + + QCOMPARE(tutorial.id(), QString("thENameOfATutoRial")); +} + +//Tutorial* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Tutorial*); + +void TutorialTest::testSetName() { + Tutorial tutorial; + + //Tutorial* must be registered in order to be used with QSignalSpy + int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy dataChangedSpy(&tutorial, SIGNAL(dataChanged(Tutorial*))); + + tutorial.setName("The name"); + + QCOMPARE(tutorial.name(), QString("The name")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), tutorialStarType); + QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial); +} + +void TutorialTest::testSetDescription() { + Tutorial tutorial; + + //Tutorial* must be registered in order to be used with QSignalSpy + int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy dataChangedSpy(&tutorial, SIGNAL(dataChanged(Tutorial*))); + + tutorial.setDescription("The description"); + + QCOMPARE(tutorial.description(), QString("The description")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), tutorialStarType); + QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial); +} + +void TutorialTest::testSetLicenseText() { + Tutorial tutorial; + + //Tutorial* must be registered in order to be used with QSignalSpy + int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy dataChangedSpy(&tutorial, SIGNAL(dataChanged(Tutorial*))); + + tutorial.setLicenseText("The license text"); + + QCOMPARE(tutorial.licenseText(), QString("The license text")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), tutorialStarType); + QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial); +} + +void TutorialTest::testSetCustomSetupCode() { + Tutorial tutorial; + + //Tutorial* must be registered in order to be used with QSignalSpy + int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy dataChangedSpy(&tutorial, SIGNAL(dataChanged(Tutorial*))); + + tutorial.setCustomSetupCode("The setup code"); + + QCOMPARE(tutorial.customSetupCode(), QString("The setup code")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), tutorialStarType); + QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial); +} + +void TutorialTest::testSetCustomTearDownCode() { + Tutorial tutorial; + + //Tutorial* must be registered in order to be used with QSignalSpy + int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy dataChangedSpy(&tutorial, SIGNAL(dataChanged(Tutorial*))); + + tutorial.setCustomTearDownCode("The tear down code"); + + QCOMPARE(tutorial.customTearDownCode(), QString("The tear down code")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), tutorialStarType); + QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial); +} + +QTEST_MAIN(TutorialTest) + +#include "TutorialTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |