Skip to content

Commit

Permalink
completed basic implementation of class Property. Unit tests splitted…
Browse files Browse the repository at this point in the history
… to the separate files. Json methods of class Property covered by tests.
  • Loading branch information
vt4a2h committed Jun 28, 2015
1 parent 581520e commit fc5892d
Show file tree
Hide file tree
Showing 16 changed files with 1,430 additions and 1,075 deletions.
3 changes: 3 additions & 0 deletions entity/entity_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ namespace entity {
using Scopes = QHash<QString, SharedScope>;
using ScopesList = QList<SharedScope>;

class Property;
using SharedProperty = std::shared_ptr<Property>;

class IComponents;
using SharedComponents = std::shared_ptr<IComponents>;

Expand Down
115 changes: 100 additions & 15 deletions entity/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ namespace {
const bool defaultUser = false;
const bool defaultConstant = false;
const bool defaultFinal = false;

const QString nameMark = "Name";
const QString idMark = "ID";

const QString fieldMark = "Field";

const QString getterMark = "Getter";
const QString setterMark = "Setter";
const QString resetterMark = "Resetter";
const QString notifierMark = "Notifier";

const QString designableGetterMark = "DesignableGetter";
const QString scriptableGetterMark = "ScriptableGetter";

const QString revisionMark = "revision";

const QString designableMark = "Designable";
const QString scriptableMark = "Scriptable";
const QString storedMark = "Stored";
const QString userMark = "User";
const QString constantMark = "Constant";
const QString finalMark = "Final";

void readOptionalMethod(const QJsonValue &val, entity::SharedMethod &dst, ErrorList &errors)
{
if (val.isObject()) {
if (!dst)
dst = std::make_shared<entity::ClassMethod>();

dst->fromJson(val.toObject(), errors);
} else {
dst.reset();
}
}
}

namespace entity {
Expand Down Expand Up @@ -143,18 +177,20 @@ namespace entity {
*/
bool operator ==(const Property &lhs, const Property &rhs)
{
using namespace utility;

return lhs.m_Name == rhs.m_Name &&
lhs.m_Id == rhs.m_Id &&

*lhs.m_Field == *rhs.m_Field &&
sharedPtrEq(lhs.m_Field, rhs.m_Field) &&

*lhs.m_Getter == *rhs.m_Getter &&
*lhs.m_Setter == *rhs.m_Setter &&
*lhs.m_Resetter == *rhs.m_Resetter &&
*lhs.m_Notifier == *rhs.m_Notifier &&
sharedPtrEq(lhs.m_Getter, rhs.m_Getter) &&
sharedPtrEq(lhs.m_Setter, rhs.m_Setter) &&
sharedPtrEq(lhs.m_Resetter, rhs.m_Resetter) &&
sharedPtrEq(lhs.m_Notifier, rhs.m_Notifier) &&

*lhs.m_DesignableGetter == *rhs.m_DesignableGetter &&
*lhs.m_ScriptableGetter == *rhs.m_ScriptableGetter &&
sharedPtrEq(lhs.m_DesignableGetter, rhs.m_DesignableGetter) &&
sharedPtrEq(lhs.m_ScriptableGetter, rhs.m_ScriptableGetter) &&

lhs.m_Revision == rhs.m_Revision &&

Expand Down Expand Up @@ -610,7 +646,30 @@ namespace entity {
*/
QJsonObject Property::toJson() const
{
return QJsonObject();
QJsonObject result;

result.insert(nameMark, m_Name);
result.insert(idMark, m_Id);
result.insert(fieldMark, m_Field->toJson());

result.insert(getterMark, m_Getter ? m_Getter->toJson() : QJsonValue(""));
result.insert(setterMark, m_Setter ? m_Setter->toJson() : QJsonValue(""));
result.insert(resetterMark, m_Resetter ? m_Resetter->toJson() : QJsonValue(""));
result.insert(notifierMark, m_Notifier ? m_Notifier->toJson() : QJsonValue(""));

result.insert(designableGetterMark, m_DesignableGetter ? m_DesignableGetter->toJson() : QJsonValue(""));
result.insert(scriptableGetterMark, m_ScriptableGetter ? m_ScriptableGetter->toJson() : QJsonValue(""));

result.insert(revisionMark, m_Revision);

result.insert(designableMark, m_Designable);
result.insert(scriptableMark, m_Scriptable);
result.insert(storedMark, m_Stored);
result.insert(userMark, m_User);
result.insert(constantMark, m_Constant);
result.insert(finalMark, m_Final);

return result;
}

/**
Expand All @@ -620,7 +679,33 @@ namespace entity {
*/
void Property::fromJson(const QJsonObject &src, QStringList &errorList)
{
Q_UNUSED(src); Q_UNUSED(errorList);
using namespace utility;

checkAndSet(src, nameMark, errorList, [&](){ m_Name = src[nameMark].toString(); });
checkAndSet(src, idMark, errorList, [&](){ m_Id = src[idMark].toString(); });

checkAndSet(src, fieldMark, errorList, [&](){ m_Field->fromJson( src[fieldMark].toObject(), errorList ); });

checkAndSet(src, getterMark, errorList, [&](){ readOptionalMethod(src[getterMark], m_Getter, errorList); });
checkAndSet(src, setterMark, errorList, [&](){ readOptionalMethod(src[setterMark], m_Setter, errorList); });
checkAndSet(src, resetterMark, errorList, [&](){ readOptionalMethod(src[resetterMark], m_Resetter, errorList); });
checkAndSet(src, notifierMark, errorList, [&](){ readOptionalMethod(src[notifierMark], m_Notifier, errorList); });

checkAndSet(src, designableGetterMark, errorList, [&](){
readOptionalMethod(src[designableGetterMark], m_DesignableGetter, errorList);
});
checkAndSet(src, scriptableGetterMark, errorList, [&](){
readOptionalMethod(src[scriptableGetterMark], m_ScriptableGetter, errorList);
});

checkAndSet(src, revisionMark, errorList, [&](){ m_Revision = src[revisionMark].toInt(); });

checkAndSet(src, designableMark, errorList, [&](){ m_Designable = src[designableMark].toBool(); });
checkAndSet(src, scriptableMark, errorList, [&](){ m_Scriptable = src[scriptableMark].toBool(); });
checkAndSet(src, storedMark, errorList, [&](){ m_Stored = src[storedMark].toBool(); });
checkAndSet(src, userMark, errorList, [&](){ m_User = src[userMark].toBool(); });
checkAndSet(src, constantMark, errorList, [&](){ m_Constant = src[constantMark].toBool(); });
checkAndSet(src, finalMark, errorList, [&](){ m_Final = src[finalMark].toBool(); });
}

/**
Expand Down Expand Up @@ -711,13 +796,13 @@ namespace entity {

m_Field = std::make_shared<Field>(*src.m_Field);

m_Getter = std::make_shared<ClassMethod>(*src.m_Getter);
m_Setter = std::make_shared<ClassMethod>(*src.m_Setter);
m_Resetter = std::make_shared<ClassMethod>(*src.m_Resetter);
m_Notifier = std::make_shared<ClassMethod>(*src.m_Notifier);
m_Getter = src.m_Getter ? std::make_shared<ClassMethod>(*src.m_Getter) : nullptr;
m_Setter = src.m_Setter ? std::make_shared<ClassMethod>(*src.m_Setter) : nullptr;
m_Resetter = src.m_Resetter ? std::make_shared<ClassMethod>(*src.m_Resetter) : nullptr;
m_Notifier = src.m_Notifier ? std::make_shared<ClassMethod>(*src.m_Notifier) : nullptr;

m_DesignableGetter = std::make_shared<ClassMethod>(*src.m_DesignableGetter);
m_ScriptableGetter = std::make_shared<ClassMethod>(*src.m_ScriptableGetter);
m_DesignableGetter = src.m_DesignableGetter ? std::make_shared<ClassMethod>(*src.m_DesignableGetter) : nullptr;
m_ScriptableGetter = src.m_ScriptableGetter ? std::make_shared<ClassMethod>(*src.m_ScriptableGetter) : nullptr;

m_Revision = src.m_Revision;

Expand Down
37 changes: 27 additions & 10 deletions tests/test/TestJson.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
/*****************************************************************************
**
**
** Copyright (C) 2014 Fanaskov Vitaly (vt4a2h@gmail.com)
**
** Created 23/10/2014.
**
** This file is part of Q-UML (UML tool for Qt).
**
**
** Q-UML is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
**
** Q-UML 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 Lesser General Public License for more details.
** You should have received a copy of the GNU Lesser General Public License
** along with Q-UML. If not, see <http://www.gnu.org/licenses/>.
** along with Q-UML. If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************************/

#pragma once

#pragma once

#include <gtest/gtest.h>

#include <QString>
#include <QDir>
#include <QTextStream>

#include "types.h"
#include <gtest/gtest.h>

#include <db/database.h>
#include <db/projectdatabase.h>

#include <entity/scope.h>
#include <entity/type.h>
#include <entity/class.h>
#include <entity/classmethod.h>
#include <entity/field.h>
#include <entity/property.h>

#include <relationship/node.h>
#include <relationship/relation.h>
#include <relationship/generalization.h>
#include <relationship/dependency.h>
#include <relationship/association.h>
#include <relationship/multiplyassociation.h>
#include <relationship/realization.h>

#include <types.h>

#include <constants.h>

struct RelationTestParameters
{
Expand Down
11 changes: 9 additions & 2 deletions tests/test/TestProjectTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@

#include <db/projectdatabase.h>
#include <db/database.h>

#include <entity/scope.h>
#include <entity/enum.h>
#include <enums.h>
#include <entity/extendedtype.h>
#include <translator/projecttranslator.h>
#include <entity/field.h>
#include <entity/union.h>
#include <entity/class.h>
#include <entity/templateclass.h>
#include <entity/templateclassmethod.h>

#include <translator/projecttranslator.h>
#include <translator/translator_types.hpp>
#include <translator/code.h>

#include <enums.h>

class ProjectTranslatorTest : public ::testing::Test
{
protected:
Expand Down
43 changes: 43 additions & 0 deletions tests/test/cases/depthsearchtestcases.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*****************************************************************************
**
** Copyright (C) 2015 Fanaskov Vitaly (vt4a2h@gmail.com)
**
** Created 28/06/2015.
**
** This file is part of Q-UML (UML tool for Qt).
**
** Q-UML is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Q-UML 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 Lesser General Public License for more details.
** You should have received a copy of the GNU Lesser General Public License
** along with Q-UML. If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************************/
#pragma once

#include "TestDepthSearch.h"
#include "helpers.h"

TEST_F(DepthSearch, ScopeSearchWorks)
{
entity::SharedScope p(nullptr);

search_circle(_scopes, depthScopeSearch, scope)
invalid_case(depthScopeSearch, "foobarid")
}

TEST_F(DepthSearch, TypeSearchWorks)
{
entity::SharedType p(nullptr);

search_circle(_types, depthTypeSearch, type)
invalid_case(depthTypeSearch, "foobarbaz")
}

Loading

0 comments on commit fc5892d

Please sign in to comment.