mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fill test with code, fix extra qualification error
This commit is contained in:
parent
f8dea5c0a2
commit
4041c557d8
@ -46,15 +46,15 @@ public:
|
||||
|
||||
// catalog overload api
|
||||
|
||||
const char * LanguageCatalog::gettext(const char * msgid);
|
||||
const char * LanguageCatalog::ngettext(const char * msgid, const char * msgid_plural, spirit_po::uint plural);
|
||||
const char * LanguageCatalog::pgettext(const char * msgctxt, const char * msgid);
|
||||
const char * LanguageCatalog::npgettext(const char * msgctxt, const char * msgid, const char * msgid_plural, spirit_po::uint plural);
|
||||
const char * gettext(const char * msgid);
|
||||
const char * ngettext(const char * msgid, const char * msgid_plural, spirit_po::uint plural);
|
||||
const char * pgettext(const char * msgctxt, const char * msgid);
|
||||
const char * npgettext(const char * msgctxt, const char * msgid, const char * msgid_plural, spirit_po::uint plural);
|
||||
|
||||
std::string LanguageCatalog::gettext_str(const std::string & msgid);
|
||||
std::string LanguageCatalog::ngettext_str(const std::string & msgid, const std::string & msgid_plural, spirit_po::uint plural);
|
||||
std::string LanguageCatalog::pgettext_str(const std::string & msgctxt, const std::string & msgid);
|
||||
std::string LanguageCatalog::npgettext_str(const std::string & msgctxt, const std::string & msgid, const std::string & msgid_plural, spirit_po::uint plural);
|
||||
std::string gettext_str(const std::string & msgid);
|
||||
std::string ngettext_str(const std::string & msgid, const std::string & msgid_plural, spirit_po::uint plural);
|
||||
std::string pgettext_str(const std::string & msgctxt, const std::string & msgid);
|
||||
std::string npgettext_str(const std::string & msgctxt, const std::string & msgid, const std::string & msgid_plural, spirit_po::uint plural);
|
||||
|
||||
inline Languages getLanguage() { return mThisLanguage; }
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "model/User.h"
|
||||
#include "model/Session.h"
|
||||
|
||||
#ifndef _TEST_BUILD
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
@ -21,3 +22,4 @@ int main(int argc, char** argv)
|
||||
Gradido_LoginServer app;
|
||||
return app.run(argc, argv);
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,15 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_TEST_
|
||||
#define __GRADIDO_LOGIN_SERVER_TEST_
|
||||
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
//! \return 0 if init okay, else return != 0
|
||||
virtual int init() = 0;
|
||||
|
||||
//! \return 0 if okay, else return != 0
|
||||
virtual int test() = 0;
|
||||
virtual const char* getName() = 0;
|
||||
};
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_TEST_
|
||||
@ -0,0 +1,152 @@
|
||||
|
||||
#include "TestTasks.h"
|
||||
#include "Poco/Environment.h"
|
||||
#include <sodium.h>
|
||||
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/AsyncChannel.h"
|
||||
#include "Poco/SimpleFileChannel.h"
|
||||
#include "Poco/ConsoleChannel.h"
|
||||
#include "Poco/SplitterChannel.h"
|
||||
|
||||
RandomCPUTask::RandomCPUTask(UniLib::controller::CPUSheduler* scheduler, TestTasks* parent, int nr)
|
||||
: UniLib::controller::CPUTask(scheduler), mParent(parent), mHeaviness(0), mNr(nr)
|
||||
{
|
||||
int zahl = randombytes_random() % 2;
|
||||
if (zahl == 0) {
|
||||
mType = RANDOM_CPU_TASK_CALCULATE;
|
||||
mHeaviness = randombytes_random() % 10000 + 1000;
|
||||
}
|
||||
else {
|
||||
mType = RANDOM_CPU_TASK_SLEEP;
|
||||
mHeaviness = randombytes_random() % 1000;
|
||||
}
|
||||
}
|
||||
|
||||
const char* RandomCPUTask::getName() const
|
||||
{
|
||||
if (mType == RANDOM_CPU_TASK_CALCULATE) return "Calculate";
|
||||
if (mType == RANDOM_CPU_TASK_SLEEP) return "Sleep";
|
||||
return "not set";
|
||||
}
|
||||
|
||||
RandomCPUTask::~RandomCPUTask()
|
||||
{
|
||||
mParent->releaseTask(mNr);
|
||||
}
|
||||
|
||||
int RandomCPUTask::run()
|
||||
{
|
||||
if (mType == RANDOM_CPU_TASK_SLEEP) {
|
||||
Poco::Thread::sleep(mHeaviness);
|
||||
}
|
||||
else if (mType == RANDOM_CPU_TASK_CALCULATE) {
|
||||
for (int i = 0; i < mHeaviness; i++) {
|
||||
double zahl = sqrtf(powf(i, sqrtf(i)));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// *************************************************************************************
|
||||
|
||||
TestTasks::TestTasks()
|
||||
: mTaskScheduler(Poco::Environment::processorCount() * 4, "testScheduler")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TestTasks::~TestTasks()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int TestTasks::init()
|
||||
{
|
||||
// init speed logger
|
||||
Poco::AutoPtr<Poco::SimpleFileChannel> speedLogFileChannel(new Poco::SimpleFileChannel("speedLog.txt"));
|
||||
/*
|
||||
The optional log file rotation mode:
|
||||
never: no rotation (default)
|
||||
<n>: rotate if file size exceeds <n> bytes
|
||||
<n> K: rotate if file size exceeds <n> Kilobytes
|
||||
<n> M: rotate if file size exceeds <n> Megabytes
|
||||
*/
|
||||
speedLogFileChannel->setProperty("rotation", "500 K");
|
||||
Poco::AutoPtr<Poco::AsyncChannel> speedLogAsyncChannel(new Poco::AsyncChannel(speedLogFileChannel));
|
||||
|
||||
Poco::Logger& speedLogger = Poco::Logger::get("SpeedLog");
|
||||
speedLogger.setChannel(speedLogAsyncChannel);
|
||||
speedLogger.setLevel("information");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestTasks::test()
|
||||
{
|
||||
auto workerCount = Poco::Environment::processorCount() * 4;
|
||||
auto taskCount = workerCount + workerCount * (randombytes_random() % 4);
|
||||
printf("[TestTasks::test] taskCount: %d\n", taskCount);
|
||||
for (int i = 1; i <= taskCount; i++) {
|
||||
Poco::AutoPtr<RandomCPUTask> task = new RandomCPUTask(&mTaskScheduler, this, i);
|
||||
lock();
|
||||
mTasks.insert(std::pair<int, RandomCPUTask*>(i, task));
|
||||
unlock();
|
||||
task->scheduleTask(task);
|
||||
}
|
||||
int maxWaitCylces = 3000;
|
||||
bool finished = false;
|
||||
do {
|
||||
maxWaitCylces--;
|
||||
Poco::Thread::sleep(5);
|
||||
lock();
|
||||
if (mTasks.size() == 0) {
|
||||
finished = true;
|
||||
}
|
||||
unlock();
|
||||
} while (!finished && maxWaitCylces > 0);
|
||||
|
||||
lock();
|
||||
bool hasErrors = false;
|
||||
if (mTasks.size() > 0 || mErrors.size() > 0) {
|
||||
hasErrors = true;
|
||||
printf("[TestTasks::test] error running TestTasks\n");
|
||||
if (mTasks.size() > 0) {
|
||||
printf("%d not exited\n", mTasks.size());
|
||||
for (auto it = mTasks.begin(); it != mTasks.end(); it++) {
|
||||
if (!it->second->isReady()) {
|
||||
printf("task %d not ready\n", it->first);
|
||||
}
|
||||
if (!it->second->isTaskFinished()) {
|
||||
printf("task %d isn't finished\n", it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mErrors.size(); i++) {
|
||||
printf("error: %s\n", mErrors[i].data());
|
||||
}
|
||||
}
|
||||
unlock();
|
||||
|
||||
if (hasErrors) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void TestTasks::releaseTask(int nr)
|
||||
{
|
||||
lock();
|
||||
auto it = mTasks.find(nr);
|
||||
if (it != mTasks.end()) {
|
||||
mTasks.erase(it);
|
||||
}
|
||||
else {
|
||||
mErrors.push_back("[TestTasks] task entry not found" + std::to_string(nr));
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_TEST_TASKS_
|
||||
#define __GRADIDO_LOGIN_SERVER_TEST_TASKS_
|
||||
|
||||
#include "Test.h"
|
||||
#include <map>
|
||||
|
||||
#include "../tasks/CPUSheduler.h"
|
||||
#include "../tasks/CPUTask.h"
|
||||
|
||||
#include "../lib/MultithreadContainer.h"
|
||||
|
||||
enum RandomCPUTaskType {
|
||||
RANDOM_CPU_TASK_CALCULATE,
|
||||
RANDOM_CPU_TASK_SLEEP
|
||||
};
|
||||
class TestTasks;
|
||||
|
||||
class RandomCPUTask : public UniLib::controller::CPUTask
|
||||
{
|
||||
public:
|
||||
RandomCPUTask(UniLib::controller::CPUSheduler* scheduler, TestTasks* parent, int nr);
|
||||
virtual ~RandomCPUTask();
|
||||
|
||||
int run();
|
||||
|
||||
const char* getResourceType() const { return "RandomCPUTask"; };
|
||||
const char* getName() const;
|
||||
|
||||
|
||||
protected:
|
||||
TestTasks* mParent;
|
||||
RandomCPUTaskType mType;
|
||||
Poco::UInt32 mHeaviness;
|
||||
int mNr;
|
||||
};
|
||||
|
||||
class TestTasks : public Test, public UniLib::lib::MultithreadContainer
|
||||
{
|
||||
public:
|
||||
TestTasks();
|
||||
virtual ~TestTasks();
|
||||
|
||||
int init();
|
||||
int test();
|
||||
inline const char* getName() { return "TestTasks"; }
|
||||
|
||||
void releaseTask(int nr);
|
||||
|
||||
protected:
|
||||
UniLib::controller::CPUSheduler mTaskScheduler;
|
||||
std::map<int, RandomCPUTask*> mTasks;
|
||||
|
||||
std::vector<std::string> mErrors;
|
||||
};
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_TEST_TASKS_
|
||||
@ -1,6 +1,54 @@
|
||||
|
||||
#include "main.h"
|
||||
#include <list>
|
||||
|
||||
std::list<Test*> gTests;
|
||||
|
||||
void fillTests()
|
||||
{
|
||||
gTests.push_back(new TestTasks());
|
||||
// gTests.push_back(new LoginTest());
|
||||
}
|
||||
|
||||
int load() {
|
||||
fillTests();
|
||||
for (std::list<Test*>::iterator it = gTests.begin(); it != gTests.end(); it++)
|
||||
{
|
||||
if ((*it)->init()) printf("Fehler bei Init test: %s\n", (*it)->getName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
//printf("running tests\n");
|
||||
printf("running tests\n");
|
||||
for (std::list<Test*>::iterator it = gTests.begin(); it != gTests.end(); it++)
|
||||
{
|
||||
//printf("running: %s\n", it->getName());
|
||||
printf("running test: %s", (*it)->getName());
|
||||
if (!(*it)->test()) printf("success\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ende()
|
||||
{
|
||||
for (std::list<Test*>::iterator it = gTests.begin(); it != gTests.end(); it++)
|
||||
{
|
||||
if (*it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
}
|
||||
gTests.clear();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
load();
|
||||
run();
|
||||
ende();
|
||||
return 42;
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
|
||||
#include "TestTasks.h"
|
||||
Loading…
x
Reference in New Issue
Block a user