refs #354, initial cleanup of cfg entries samples / code before adding new functionality

* fixed styles such as copyright headers
* use text stream instead of qDebug() for output
* int instead of qint
* misc. smaller tweaks
* extended the JSON example (special chars). JSON might be used to "cache" the FSX entries
This commit is contained in:
Klaus Basan
2014-12-05 23:44:16 +01:00
parent e75b1360bb
commit e4bea8ffa8
14 changed files with 206 additions and 111 deletions

View File

@@ -84,9 +84,18 @@ namespace BlackMiscTest
stations.clear();
stations.convertFromJson(json);
qDebug() << stations;
qDebug() << "------- Enter -----";
cin.readLine();
// testing escaping special characters
CUser specialCharacters("123456", "With quote \"", "With double quote\"\"", "foobar");
json = specialCharacters.toJson();
doc.setObject(json);
qDebug() << doc.toJson(QJsonDocument::Indented);
qDebug() << "------- Enter ---------------------------------";
cin.readLine();
return 0;
}

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blacksim/blacksimfreefunctions.h"
#include "blackmisc/blackmiscfreefunctions.h"
@@ -12,40 +16,49 @@
#include <QCoreApplication>
#include <QTextStream>
#include <QDebug>
#include <QTime>
/*!
* Samples
*/
int main(int argc, char *argv[])
{
Q_UNUSED(argc);
Q_UNUSED(argv);
QTextStream streamIn(stdin);
QTextStream streamOut(stdout);
BlackMisc::registerMetadata();
BlackSim::registerMetadata();
qDebug() << "Run samples:";
qDebug() << "1 .. FS common";
qDebug() << "2 .. FSX";
qDebug() << "3 .. Mappings";
qDebug() << "x .. exit";
streamOut << "Run samples:" << endl;
streamOut << "1 .. FS common" << endl;
streamOut << "2 .. FSX" << endl;
streamOut << "3 .. Mappings" << endl;
streamOut << "x .. exit" << endl;
QString i = streamIn.readLine().toLower().trimmed();
QTime t;
t.start();
if (i.startsWith("1"))
{
BlackSimTest::CSamplesFsCommon::samples();
BlackSimTest::CSamplesFsCommon::samples(streamOut, streamIn);
}
else if (i.startsWith("2"))
{
BlackSimTest::CSamplesFsx::samples();
BlackSimTest::CSamplesFsx::samples(streamOut);
}
else if (i.startsWith("3"))
{
BlackSimTest::CSamplesModelMapping::samples();
BlackSimTest::CSamplesModelMapping::samples(streamOut);
}
else if (i.startsWith("x"))
{
return 0;
}
QCoreApplication a(argc, argv);
return a.exec();
streamOut << "time elapsed: " << t.elapsed() << "ms" << endl;
streamOut << "press key to exit" << endl;
streamIn.readLine();
return 0;
}

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "samplesfscommon.h"
#include "blacksim/fscommon/aircraftcfgentrieslist.h"
@@ -9,7 +13,11 @@
#include <QDebug>
#include <QFuture>
#include <QTime>
#include <QTextStream>
#include <QTemporaryFile>
using namespace BlackSim::FsCommon;
namespace BlackSimTest
{
@@ -17,11 +25,10 @@ namespace BlackSimTest
/*
* Samples
*/
int CSamplesFsCommon::samples()
int CSamplesFsCommon::samples(QTextStream &streamOut, QTextStream &streamIn)
{
QTextStream streamIn(stdin);
QTextStream streamOut(stdout);
QString fsxDir = "P:/FlightSimulatorX (MSI)/SimObjects";
// QString fsxDir = "P:/FlightSimulatorX (MSI)/SimObjects";
QString fsxDir = "P:/Temp/SimObjects";
streamOut << "Enter FSX directory:" << endl;
streamOut << fsxDir << '\r';
streamOut.flush();
@@ -31,25 +38,49 @@ namespace BlackSimTest
input = streamIn.readLine();
if (!input.startsWith("b"))
{
qDebug() << "reading directly";
BlackSim::FsCommon::CAircraftCfgEntriesList entriesList(fsxDir);
streamOut << "reading directly" << endl;
CAircraftCfgEntriesList entriesList(fsxDir);
if (entriesList.existsDir())
{
QTime time;
time.start();
streamOut << "reading " << entriesList.getRootDirectory() << endl;
entriesList.read();
streamOut << "read entries: " << entriesList.size() << endl;
// streamOut << entriesList << endl;
streamOut << "read entries: " << entriesList.size() << " in " << time.restart() << "ms" << endl;
QJsonDocument doc(entriesList.toJson());
QByteArray jsonArray(doc.toJson());
streamOut << "write JSON array with size " << jsonArray.size() << endl;
QTemporaryFile tempFile;
tempFile.open();
tempFile.write(jsonArray);
tempFile.close();
streamOut << "written to " << tempFile.fileName() << " in " << time.restart() << "ms" << endl;
// re-read
tempFile.open();
jsonArray = tempFile.readAll();
doc = QJsonDocument::fromJson(jsonArray);
entriesList.clear();
entriesList.convertFromJson(doc.object());
streamOut << "read JSON array with size " << jsonArray.size() << endl;
streamOut << "read entries from disk: " << entriesList.size() << " in " << time.restart() << "ms" << endl;
tempFile.close();
}
}
else
{
qDebug() << "reading in background";
streamOut << "reading in background" << endl;
QFuture<int> f = BlackSim::FsCommon::CAircraftIndexer::readInBackground(fsxDir);
int i = 0;
do
{
streamOut << ".";
streamOut.flush();
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000 * 3);
if (i % 20 == 0)
{
streamOut << ".";
streamOut.flush();
}
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000 * 5);
}
while (!f.isFinished());
streamOut << endl << f.result() << " entries" << endl;

View File

@@ -1,23 +1,27 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMTEST_SAMPLESFSCOMMON_H
#define BLACKSIMTEST_SAMPLESFSCOMMON_H
#include <QTextStream>
namespace BlackSimTest
{
/*!
* \brief Samples for FsCommon classes
*/
//! Samples for FsCommon classes
class CSamplesFsCommon
{
public:
/*!
* \brief Run the samples
*/
static int samples();
//! Run the samples
static int samples(QTextStream &streamOut, QTextStream &streamIn);
};
} // namespace

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "samplesfsx.h"
#include "blacksim/blacksimfreefunctions.h"
@@ -16,12 +20,12 @@ namespace BlackSimTest
/*
* Samples
*/
int CSamplesFsx::samples()
int CSamplesFsx::samples(QTextStream &streamOut)
{
BlackSim::registerMetadata();
qDebug() << CSimConnectUtilities::simConnectExceptionToString(CSimConnectUtilities::SIMCONNECT_EXCEPTION_ALREADY_SUBSCRIBED);
qDebug() << CSimConnectUtilities::simConnectExceptionToString(CSimConnectUtilities::SIMCONNECT_EXCEPTION_ILLEGAL_OPERATION);
qDebug() << CSimConnectUtilities::simConnectSurfaceTypeToString(CSimConnectUtilities::Bituminus);
streamOut << CSimConnectUtilities::simConnectExceptionToString(CSimConnectUtilities::SIMCONNECT_EXCEPTION_ALREADY_SUBSCRIBED) << endl;
streamOut << CSimConnectUtilities::simConnectExceptionToString(CSimConnectUtilities::SIMCONNECT_EXCEPTION_ILLEGAL_OPERATION) << endl;
streamOut << CSimConnectUtilities::simConnectSurfaceTypeToString(CSimConnectUtilities::Bituminus) << endl;
return 0;
}

View File

@@ -1,23 +1,27 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMTEST_SAMPLESFSX_H
#define BLACKSIMTEST_SAMPLESFSX_H
#include <QTextStream>
namespace BlackSimTest
{
/*!
* \brief Samples for FSX classes
*/
//! Samples for FSX classes
class CSamplesFsx
{
public:
/*!
* \brief Run the samples
*/
static int samples();
//! Run the samples
static int samples(QTextStream &streamOut);
};
} // namespace

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "samplesmodelmapping.h"
#include "blackmisc/blackmiscfreefunctions.h"
@@ -18,7 +22,7 @@ namespace BlackSimTest
/*
* Samples
*/
int CSamplesModelMapping::samples()
int CSamplesModelMapping::samples(QTextStream &streamOut)
{
BlackMisc::registerMetadata();
BlackSim::registerMetadata();
@@ -26,10 +30,10 @@ namespace BlackSimTest
CVPilotModelMappings cvm;
cvm.addDirectory(CVPilotModelMappings::standardMappingsDirectory());
bool s = cvm.load();
qDebug() << "loaded:" << s << "size:" << cvm.size();
streamOut << "loaded:" << s << "size:" << cvm.size() << endl;
BlackMisc::Aviation::CAircraftIcao icao("C172");
qDebug() << cvm.findByIcaoWildcard(icao);
streamOut << cvm.findByIcaoWildcard(icao) << endl;
return 0;
}

View File

@@ -1,23 +1,27 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMTEST_SAMPLESMODELMAPPING_H
#define BLACKSIMTEST_SAMPLESMODELMAPPING_H
#include <QTextStream>
namespace BlackSimTest
{
/*!
* \brief Samples for model mapping classes
*/
//! Samples for model mapping classes
class CSamplesModelMapping
{
public:
/*!
* \brief Run the samples
*/
static int samples();
//! Run the samples
static int samples(QTextStream &streamOut);
};
} // namespace