Skip to content

Commit

Permalink
work on code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
squinky86 committed Nov 27, 2019
1 parent 00e816f commit d33ca66
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/common.cpp
Expand Up @@ -160,7 +160,7 @@ QString DownloadPage(const QUrl &url)
event.exec();

//read the response and return its contents
QString html = response->readAll();
QString html = QString::fromLatin1(response->readAll());
delete response;
return html;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ QMap<QString, QByteArray> GetFilesFromZip(const QString &fileName, const QString
{
if (zip_stat_index(za, i, 0, &sb) == 0)
{
QString name(sb.name);
QString name(QString::fromLatin1(sb.name));
if (!fileNameFilter.isNull() && !fileNameFilter.isEmpty() && !name.endsWith(fileNameFilter, Qt::CaseInsensitive))
{
continue;
Expand Down Expand Up @@ -360,7 +360,7 @@ QString TrimFileName(const QString &fileName)
void Warning(const QString &title, const QString &message, const bool quiet)
{
qDebug() << title << ": " << message << endl;
if (!IgnoreWarnings && !quiet && (QThread::currentThread() == QApplication::instance()->thread())) //make sure we're in the GUI thread before popping a messagae box
if (!IgnoreWarnings && !quiet && (QThread::currentThread() == QApplication::instance()->thread())) //make sure we're in the GUI thread before popping a message box
{
int ret = QMessageBox::warning(nullptr, title, message, QMessageBox::Ignore | QMessageBox::Ok);
//if ignoring messages, move to quiet mode
Expand Down
6 changes: 3 additions & 3 deletions src/common.h
Expand Up @@ -24,7 +24,7 @@
#include <QFile>
#include <QNetworkReply>

#define VERSION QLatin1String("1.0.0")
#define VERSION QStringLiteral("1.0.0")

[[maybe_unused]] static bool IgnoreWarnings = false;

Expand All @@ -33,10 +33,10 @@ bool DownloadFile(const QUrl &url, QFile *file);
QString DownloadPage(const QUrl &url);
QString Excelify(const QString &s);
int GetCCINumber(QString cci);
QMap<QString, QByteArray> GetFilesFromZip(const QString &fileName, const QString &fileNameFilter = "");
QMap<QString, QByteArray> GetFilesFromZip(const QString &fileName, const QString &fileNameFilter = QLatin1String(""));
int GetReleaseNumber(const QString &release);
QString GetUserAgent();
QString Pluralize(const int count, const QString &plural = "s", const QString &singular = "");
QString Pluralize(const int count, const QString &plural = QStringLiteral("s"), const QString &singular = QLatin1String(""));
QString PrintTrueFalse(bool tf);
QString Sanitize(QString s);
QString SanitizeFile(QString s);
Expand Down
4 changes: 2 additions & 2 deletions src/dbmanager.cpp
Expand Up @@ -920,7 +920,7 @@ Asset DbManager::GetAsset(const Asset &asset)
*/
Asset DbManager::GetAsset(int id)
{
QList<Asset> tmp = GetAssets(QStringLiteral("WHERE Asset.id = :id"), {std::make_tuple<QString, QVariant>(":id", id)});
QList<Asset> tmp = GetAssets(QStringLiteral("WHERE Asset.id = :id"), {std::make_tuple<QString, QVariant>(QStringLiteral(":id"), id)});
if (tmp.count() > 0)
return tmp.first();
QMessageBox::warning(nullptr, QStringLiteral("Unable to Find Asset"), "The Asset ID " + QString::number(id) + " was not found in the database.");
Expand Down Expand Up @@ -982,7 +982,7 @@ QList<Asset> DbManager::GetAssets(const QString &whereClause, const QList<std::t
{
QSqlQuery q(db);
QString toPrep = QStringLiteral("SELECT Asset.`id`, Asset.`assetType`, Asset.`hostName`, Asset.`hostIP`, Asset.`hostMAC`, Asset.`hostFQDN`, Asset.`techArea`, Asset.`targetKey`, Asset.`webOrDatabase`, Asset.`webDBSite`, Asset.`webDBInstance`");
toPrep.append(" FROM Asset");
toPrep.append(QStringLiteral(" FROM Asset"));
if (!whereClause.isNull() && !whereClause.isEmpty())
toPrep.append(" " + whereClause);
toPrep.append(QStringLiteral(" ORDER BY LOWER(hostName), hostName"));
Expand Down
51 changes: 50 additions & 1 deletion src/main.cpp
Expand Up @@ -17,8 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.h"
#include "dbmanager.h"
#include "stigqter.h"
#include "workerstigadd.h"

#include <QApplication>
#include <QTemporaryFile>
#include <QThread>
#include <cstdlib>

Expand All @@ -41,6 +46,13 @@ int main(int argc, char *argv[])
if (tests)
{
//run tests
IgnoreWarnings = true;

//test 0 - reset DB
{
DbManager db;
db.DeleteDB();
}

//test 1 - index CCIs
QMetaObject::invokeMethod(&w, "UpdateCCIs", Qt::DirectConnection);
Expand All @@ -50,7 +62,44 @@ int main(int argc, char *argv[])
a.processEvents();
}

//test 2 - delete CCIs
//test 2 - add STIGs
QTemporaryFile tmpFile;
if (tmpFile.open())
{
QUrl stigs(QStringLiteral("https://dl.dod.cyber.mil/wp-content/uploads/stigs/zip/U_SRG-STIG_Library_2019_10v2.zip"));
DownloadFile(stigs, &tmpFile);
auto stigFiles = GetFilesFromZip(tmpFile.fileName().toStdString().c_str(), QStringLiteral(".zip")).values();
Q_FOREACH (auto stigFile, stigFiles)
{
WorkerSTIGAdd tmpWorker;
QTemporaryFile tmpFile2;
if (tmpFile2.open())
{
tmpFile2.write((stigFile));
}
tmpFile2.close();
QStringList tmpList;
tmpList.push_back(tmpFile2.fileName());
tmpWorker.AddSTIGs(tmpList);
tmpWorker.process();
a.processEvents();
}
tmpFile.close();
a.processEvents();
}

//test 3 - delete STIGs
{
DbManager db;
Q_FOREACH (auto stig, db.GetSTIGs())
{
db.DeleteSTIG(stig);
a.processEvents();
}
a.processEvents();
}

//test 4 - delete CCIs
QMetaObject::invokeMethod(&w, "DeleteCCIs", Qt::DirectConnection);
while (!w.isProcessingEnabled())
{
Expand Down
4 changes: 2 additions & 2 deletions src/workercmrsexport.cpp
Expand Up @@ -147,7 +147,7 @@ void WorkerCMRSExport::process()
stream.writeCharacters(elementKey);
stream.writeEndElement(); //TARGET_KEY

foreach (CKLCheck c, a.GetCKLChecks(&s))
Q_FOREACH (CKLCheck c, a.GetCKLChecks(&s))
{
STIGCheck s = c.GetSTIGCheck();

Expand Down Expand Up @@ -203,5 +203,5 @@ void WorkerCMRSExport::process()
}

Q_EMIT updateStatus(QStringLiteral("Done!"));
emit finished();
Q_EMIT finished();
}

0 comments on commit d33ca66

Please sign in to comment.