first commit

This commit is contained in:
2026-02-21 17:11:31 +09:00
commit 18b4338361
4001 changed files with 365464 additions and 0 deletions

View File

@@ -0,0 +1,461 @@
#include "rm_test_process.h"
#if (RM_TESTING)
//#include <windows.h>
#include <QDebug>
#include <QFile>
#include <QMessageBox>
#include <QMouseEvent>
#include <QFileInfo>
#include "../data/rm_video_list.h"
#include "../ui/window_main.h"
#include "../ui/rm_frame_right.h"
#include "../ui/rm_frame_left.h"
#include "../ui/rm_frame_list.h"
#include "../ui/rm_frame_play.h"
#include "../ui/rm_frame_slider.h"
#include "../ui/rm_button.h"
#include "../ui/rm_play_slider.h"
#include "../ui/rm_slider.h"
#include "../ui/rm_frame_video_sub.h"
#include "../ui/rm_frame_video_main.h"
RMTestProcess::RMTestProcess(QObject *parent,QString path) : QObject(parent)
{
_optionLogDrawFrame = false;
_optionLogFileName = false;
_timer = NULL;
_running = false;
_processDelay = 1000; // 기본값 1초?
_loop = 0;
_nextFileTimeout = -1;
_nextFileWatchTimer = NULL;
load(path);
// PLAY_EVENT
connect(RMPlayer::instance(),SIGNAL(playEvent(PLAY_EVENT,RMVideoItem*)),SLOT(onPlayEvent(PLAY_EVENT,RMVideoItem*)));
}
void RMTestProcess::onPlayEvent(PLAY_EVENT event,RMVideoItem* item)
{
if(_running == false) {
return;
}
// LOG 처리
if (event == PLAY_DID_LOADED)
{
QFileInfo f1(item->filePath);
QString name = f1.baseName();
#if !(DUAL_CH_FILE)
if(name.endsWith("_1") || name.endsWith("_2"))
{
name = name.remove(name.length()-3,2);
}
#endif
lastFileName = name;
// 파일명 표시 로그
if(_optionLogFileName)
{
//QApplication::beep();
emit log("->" + name);
}
if(_nextFileTimeout > 0)
{
if(_nextFileWatchTimer != NULL)
{
_nextFileWatchTimer->stop();
delete _nextFileWatchTimer;
_nextFileWatchTimer = NULL;
}
_nextFileWatchTimer = new QTimer(this);
_nextFileWatchTimer->setSingleShot(true);
_nextFileWatchTimer->setInterval(_nextFileTimeout);
connect(_nextFileWatchTimer,SIGNAL(timeout()),SLOT(onFileTimeout()));
_nextFileWatchTimer->start();
}
}
else if(event == PLAY_DID_CLEARED)
{
// DRAW FRAME COUNT 표시
if(_optionLogDrawFrame)
{
int f = RMPlayer::instance()->playerF()->displyedFrameCount();
#if !(SINGLE_CH_VIEWER)
int r = RMPlayer::instance()->playerR()->displyedFrameCount();
if(f > 0 || r > 0)
#else
if(f > 0)
#endif
{
QString str;
#if (SINGLE_CH_VIEWER)
str.sprintf("DRAW FRAME:F:%d",RMPlayer::instance()->playerF()->displyedFrameCount());
#else
str.sprintf("DRAW FRAME:F:%d,R:%d",RMPlayer::instance()->playerF()->displyedFrameCount(),RMPlayer::instance()->playerR()->displyedFrameCount());
#endif
emit log(str);
#if (SINGLE_CH_VIEWER)
if(f <= 0)
#else
if(f <= 0 || r <= 0)
#endif
{
_running = false;
emit error(str);
return;
}
}
}
}
if(_waitPlayEvent == event)
{
// 다음 프로세스로 이동
QTimer::singleShot(_processDelay,Qt::PreciseTimer,this,SLOT(onProcessNext()));
_waitPlayEvent = PLAY_UNDEFINED;
}
}
void RMTestProcess::onFileTimeout()
{
if(_nextFileWatchTimer != NULL)
{
_nextFileWatchTimer->stop();
delete _nextFileWatchTimer;
_nextFileWatchTimer = NULL;
}
_running = false;
emit error("FILE TIME OUT");
}
void RMTestProcess::load(QString path)
{
QFile file(path);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", file.errorString());
}
QTextStream in(&file);
while(!in.atEnd()) {
QString line = in.readLine();
// comment 처리
if(line.length() < 2 || line.startsWith("#")) {
continue;
}
// 전체 옵션 처리
if(line.startsWith("$"))
{
if(line.toUpper() == "$LOG_DRAW_FRAME")
{
_optionLogDrawFrame = true;
}
else if(line.toUpper() == "$LOG_FILE_NAME")
{
_optionLogFileName = true;
}
else if(line.toUpper().startsWith("$PROCESS_DELAY") && line.contains("="))
{
_processDelay = line.split("=").last().toInt();
}
else if(line.toUpper().startsWith("$WATCH_TIMEOUT") && line.contains("="))
{
_nextFileTimeout = line.split("=").last().toInt();
}
continue;
}
QStringList fields = line.split(",");
processes.append(fields);
//model->appendRow(fields);
}
file.close();
filePath = path;
_running = false;
}
int RMTestProcess::count()
{
return processes.count();
}
bool RMTestProcess::isRunning()
{
return _running;
}
void RMTestProcess::onRun()
{
// foreach (QStringList process, processes) {
// qInfo() << "CMD:" << process.first() << ":" << process.last();
// }
_processIndex = 0;
_running = true;
elapsedTimer.start();
_timer = new QTimer(this);
_timer->setSingleShot(false);
_timer->setInterval(100);
connect(_timer,SIGNAL(timeout()),SLOT(onSyncTime()));
_timer->start();
//qInfo() << "TIMER START";
_loop = 1;
emit loopChange(_loop);
QTimer::singleShot(_processDelay,Qt::PreciseTimer,this,SLOT(onProcessNext()));
}
void RMTestProcess::makeClick(QWidget* control,float x)
{
//qInfo() << __FUNCTION__ << control << x;
QPoint pos = control->rect().center();
if(x > 0.0f)
{
pos.setX( (int)(((float)control->rect().size().width()) * (float)x));
}
//qInfo() << __FUNCTION__ << pos << " global:" << control->mapToGlobal(pos);
QMouseEvent* pEvent = new QMouseEvent(QEvent::MouseButtonPress,
pos,
control->mapToGlobal(pos),
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
QApplication::instance()->sendEvent(control,pEvent);
QThread::msleep((rand() % 20) + 10);
pos.setX(pos.x() + ((rand() % 4) - 2));
pos.setY(pos.y() + ((rand() % 4) - 2));
QMouseEvent* pEventM = new QMouseEvent(QEvent::MouseMove,
pos,
control->mapToGlobal(pos),
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
QApplication::instance()->sendEvent(control,pEventM);
QThread::msleep((rand() % 20) + 10);
pos.setX(pos.x() + ((rand() % 4) - 2));
pos.setY(pos.y() + ((rand() % 4) - 2));
QMouseEvent* pEvent2 = new QMouseEvent(QEvent::MouseButtonRelease,
pos,
control->mapToGlobal(pos),
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
QApplication::instance()->sendEvent(control,pEvent2);
}
// rand(0.7-0.9) 구문 처리
float RMTestProcess::parseRandFloat(QString range)
{
if(range.startsWith("RAND(") && range.endsWith(")") && range.contains("-"))
{
QString cleared = range.remove(0,5); // "RAND("
cleared = cleared.remove(cleared.length()-1,1); // ")"
QStringList ls = cleared.split("-");
int f1 = (int)(ls.first().toFloat() * 1000.0f);
int f2 = (int)(ls.last().toFloat() * 1000.0f);
int res = (rand() % (f2 - f1)) + f1;
return ((float)res) / 1000.0f;
}
return range.toFloat();
}
int RMTestProcess::parseRandInt(QString range)
{
if(range.startsWith("RAND(") && range.endsWith(")") && range.contains("-"))
{
QString cleared = range.remove(0,5);
cleared = cleared.remove(cleared.length()-1,1); // ")"
QStringList ls = cleared.split("-");
int f1 = ls.first().toInt();
int f2 = ls.last().toInt();
int res = (rand() % (f2 - f1)) + f1;
return res;
}
return range.toInt();
}
void RMTestProcess::onProcessNext()
{
if(_running == false)
{
//qInfo() << "STOP PROCESS";
return;
}
if(_processIndex >= processes.count())
{
_processIndex = 0;
_loop += 1;
emit loopChange(_loop);
}
QStringList list = processes.at(_processIndex);
QString cmd = list.first().toUpper();
list.removeFirst();
qint64 wait = _processDelay;
QMap<QString,QString> params;
foreach (QString param, list)
{
QStringList cmdp = param.split("=");
// 2의 배수 cmd = param
if (cmdp.count() % 2 != 0)
{
continue;
}
// PARAMETER 처리
for(int i=0;i<cmdp.count()/2;i++)
{
QString scmd = cmdp.at((i*2)+0).toUpper();
QString sparam = cmdp.at((i*2)+1).toUpper();
params.insert(scmd,sparam);
}
}
// 프로세스 추가
_processIndex += 1;
// LOOP 확인하여 처리
if(params.contains("LOOP"))
{
int loop = params.value("LOOP","0").toInt();
if(_loop != loop)
{
QTimer::singleShot(0,Qt::PreciseTimer,this,SLOT(onProcessNext()));
return;
}
}
// 대기시작 확인
if(params.contains("WAIT"))
{
wait = parseRandInt(params.value("WAIT","0"));
}
QString statusMessage = cmd;
WindowMain* pWin = (WindowMain*)RMApp::instance()->pMainWindow;
// 다음 명령 실행 or 대기
bool runNext = true;
// 명령 실행
if(cmd == "OPEN" && params.contains("PATH"))
{
// 연결 -> onLoadingListDone 에서 처리
connect(RMVideoFileList::instance(),SIGNAL(listUpdateEnd(bool)),this,SLOT(onLoadingListEnd(bool)));
pWin->_frameRight->frameList->openFolder(params.value("PATH"));
runNext = false;
}
else if(cmd == "CLICK" && params.contains("CONTROL"))
{
QString buttonName = params.value("CONTROL");
statusMessage += (" " + buttonName);
if(buttonName == "PLAY")
{
makeClick(pWin->_frameLeft->framePlay->playButton);
_waitPlayEvent = PLAY_DID_PLAYED; // 재생 시작까지 대기
runNext = false;
}
else if (buttonName == "SLIDER")
{
float x = 0.5;
if(params.contains("X"))
{
x = parseRandFloat(params.value("X"));
}
makeClick(pWin->_frameLeft->frameSlider->playSlider->slider,x);
}
else if (buttonName == "SWAP")
{
makeClick(pWin->_frameRight->frameVideoSub->_toggleButton);
}
else if (buttonName == "VOLUME")
{
float x = 0.5;
if(params.contains("X"))
{
x = parseRandFloat(params.value("X"));
}
makeClick(pWin->_frameLeft->frameSlider->volumeSlider,x);
}
//CLICK,button=play)
}
else if(cmd == "WAIT" && params.contains("FOR"))
{
QString eventName = params.value("FOR");
if(eventName == "PLAY_DID_PLAYED")
{
statusMessage += " FOR NEXT PLAY";
_waitPlayEvent = PLAY_DID_PLAYED;
}
else if(eventName == "PLAY_DID_LOADED")
{
statusMessage += " FOR NEXT LOADED";
_waitPlayEvent = PLAY_DID_LOADED;
}
else if(eventName == "PLAY_DID_CLEARED")
{
statusMessage += " FOR NEXT CLEARED";
_waitPlayEvent = PLAY_DID_CLEARED;
}
else if(eventName == "PLAY_CUSTOM_EVENT")
{
statusMessage += " FOR NEXT CUSTOM";
_waitPlayEvent = PLAY_CUSTOM_EVENT;
}
runNext = false;
}
emit statusChange(statusMessage);
// 다음 명령 실행
if(runNext == true)
{
QTimer::singleShot(wait,Qt::PreciseTimer,this,SLOT(onProcessNext()));
}
}
void RMTestProcess::onSyncTime()
{
//qInfo() << __FUNCTION__;
emit timer(elapsedTimer.elapsed());
}
void RMTestProcess::onStop()
{
elapsedTimer.invalidate();
_running = false;
}
void RMTestProcess::onLoadingListEnd(bool bLoading)
{
Q_UNUSED(bLoading);
disconnect(RMVideoFileList::instance(),SIGNAL(listUpdateEnd(bool)),this,SLOT(onLoadingListEnd(bool)));
// 다음 프로세스로 이동
QTimer::singleShot(_processDelay,Qt::PreciseTimer,this,SLOT(onProcessNext()));
}
#endif // #if (RM_TESTING)