2018-08-14 09:27:07 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2018 Tom Zander <tomz@freedommail.ch>
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-08-14 19:01:37 +02:00
|
|
|
#include "TestFloweeBase.h"
|
2018-08-14 09:27:07 +02:00
|
|
|
#include <Logger.h>
|
|
|
|
|
|
|
|
|
|
|
2018-08-14 19:01:37 +02:00
|
|
|
TestFloweeBase::TestFloweeBase()
|
2018-08-14 09:27:07 +02:00
|
|
|
{
|
2018-08-14 19:01:37 +02:00
|
|
|
memset(m_currentTestname, 0, sizeof(m_currentTestname));
|
|
|
|
|
Log::Manager::instance()->loadDefaultTestSetup(std::bind(&TestFloweeBase::currentTestName, this));
|
2018-08-14 09:27:07 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-14 19:01:37 +02:00
|
|
|
const char *TestFloweeBase::currentTestName()
|
2018-08-14 09:27:07 +02:00
|
|
|
{
|
|
|
|
|
if (m_prevTest == QTest::currentTestFunction())
|
|
|
|
|
return m_currentTestname;
|
|
|
|
|
m_prevTest = QTest::currentTestFunction();
|
|
|
|
|
|
|
|
|
|
const char * classname = metaObject()->className();
|
|
|
|
|
size_t len1 = strlen(classname);
|
|
|
|
|
const char * testName = QTest::currentTestFunction();
|
2018-09-20 21:03:27 +02:00
|
|
|
if (!testName)
|
|
|
|
|
return nullptr;
|
2018-08-14 09:27:07 +02:00
|
|
|
const size_t len2 = strlen(testName);
|
|
|
|
|
const size_t total = len1 + len2 + 2;
|
|
|
|
|
size_t offset = total >= sizeof(m_currentTestname) ? total - sizeof(m_currentTestname) : 0;
|
|
|
|
|
if (offset > len1)
|
|
|
|
|
len1 = 0;
|
|
|
|
|
else
|
|
|
|
|
len1 -= offset;
|
|
|
|
|
memset(m_currentTestname, 0, sizeof(m_currentTestname));
|
|
|
|
|
strncpy(m_currentTestname, classname + offset, len1);
|
|
|
|
|
m_currentTestname[len1] = '/';
|
|
|
|
|
strncpy(m_currentTestname + len1 + 1, testName,
|
|
|
|
|
std::min(len2, sizeof(m_currentTestname) - len1));
|
|
|
|
|
return m_currentTestname;
|
|
|
|
|
}
|