ManaPlus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
TestMain Class Reference

#include <testmain.h>

Public Member Functions

 TestMain ()
 
 ~TestMain ()
 
int exec (const bool testAudio=true)
 
ConfigurationgetConfig ()
 

Static Public Member Functions

static int readValue (const int ver, int def)
 

Private Member Functions

void initConfig ()
 
int invokeTest (const std::string &test)
 
int invokeTest3 ()
 
int invokeTest4 ()
 
int invokeTest7 ()
 
int invokeSoftwareRenderTest (const std::string &test)
 
int invokeNormalOpenGLRenderTest (const std::string &test)
 
int invokeNormalOpenBatchTest (const std::string &test)
 
int invokeModernOpenGLRenderTest (const std::string &test)
 
int invokeModernOpenBatchTest (const std::string &test)
 
int invokeMobileOpenBatchTest (const std::string &test)
 
int invokeSafeOpenBatchTest (const std::string &test)
 
int invokeSafeOpenGLRenderTest (const std::string &test)
 
void testsMain ()
 
void writeConfig (const RenderType openGLMode, const int rescale, const int sound, const std::string &info, const int batchSize, const std::string &textureSize, const int detectMode)
 
int readValue2 (const int ver)
 

Private Attributes

Loggerlog
 
Configuration mConfig
 

Detailed Description

Definition at line 33 of file testmain.h.

Constructor & Destructor Documentation

◆ TestMain()

TestMain::TestMain ( )

Definition at line 42 of file testmain.cpp.

42  :
43  log(new Logger),
44  mConfig()
45 {
47  log->setLogFile(pathJoin(settings.localDataDir, "manaplustest.log"));
48 }
Definition: logger.h:69
void setLogFile(const std::string &logFilename)
Definition: logger.cpp:120
std::string localDataDir
Definition: settings.h:112
Configuration mConfig
Definition: testmain.h:90
Logger * log
Definition: testmain.h:88
std::string getSelfName()
Definition: paths.cpp:200
Settings settings
Definition: settings.cpp:32
std::string pathJoin(std::string str1, const std::string &str2)
std::string fileName
Definition: testmain.cpp:39

References fileName, getSelfName(), Settings::localDataDir, log, pathJoin(), Logger::setLogFile(), and settings.

◆ ~TestMain()

TestMain::~TestMain ( )

Definition at line 50 of file testmain.cpp.

51 {
52  delete2(log)
53 }
#define delete2(var)
Definition: delete2.h:25

References delete2, and log.

Member Function Documentation

◆ exec()

int TestMain::exec ( const bool  testAudio = true)

Definition at line 78 of file testmain.cpp.

79 {
80  initConfig();
81  int softwareTest = invokeSoftwareRenderTest("1");
82  int soundTest = -1;
83  int rescaleTest[6];
84  int softFps = 0;
85  int normalOpenGLFps = 0;
86  int safeOpenGLFps = 0;
87  int modernOpenGLFps = 0;
88  int textureSize[6];
89  std::string textureSizeStr;
90 
92  int detectMode = 0;
93  for (int f = 0; f < 6; f ++)
94  {
95  rescaleTest[f] = -1;
96  textureSize[f] = 1024;
97  }
98  std::string info;
99 
100  const int videoDetectTest = invokeTest("99");
101  if (videoDetectTest == 0)
102  detectMode = readValue2(99);
103 
104  int normalOpenGLTest = invokeNormalOpenGLRenderTest("2");
105  int safeOpenGLTest = invokeSafeOpenGLRenderTest("3");
106  int modernOpenGLTest = invokeModernOpenGLRenderTest("19");
107  if (testAudio)
108  soundTest = invokeTest4();
109  else
110  soundTest = 0;
111 
112  info.append(strprintf("%d.%d,%d,%d,%d.", soundTest, softwareTest,
113  normalOpenGLTest, safeOpenGLTest, modernOpenGLTest));
114 
115  if (softwareTest == 0)
116  {
117  int softFpsTest = invokeSoftwareRenderTest("8");
118  info.append(strprintf("%d", softFpsTest));
119  if (softFpsTest == 0)
120  {
121  softFps = readValue2(8);
122  info.append(strprintf(",%d", softFps));
123  if (softFps == 0)
124  {
125  softwareTest = -1;
126  softFpsTest = -1;
127  }
128  else
129  {
130  rescaleTest[0] = invokeSoftwareRenderTest("5");
131  info.append(strprintf(",%d", rescaleTest[0]));
132  }
133  }
134  else
135  {
136  softwareTest = -1;
137  }
138  }
139  info.append(".");
140  if (modernOpenGLTest == 0)
141  {
142  int modernOpenGLFpsTest = invokeModernOpenGLRenderTest("17");
143  info.append(strprintf("%d", modernOpenGLFpsTest));
144  if (modernOpenGLFpsTest == 0)
145  {
146  modernOpenGLFps = readValue2(17);
147  info.append(strprintf(",%d", modernOpenGLFps));
148  if (modernOpenGLFps == 0)
149  {
150  modernOpenGLTest = -1;
151  modernOpenGLFpsTest = -1;
152  }
153  else
154  {
155  rescaleTest[3] = invokeModernOpenGLRenderTest("18");
156  info.append(strprintf(",%d", rescaleTest[3]));
157  }
158  }
159  else
160  {
161  modernOpenGLTest = -1;
162  }
163  }
164  info.append(".");
165  if (normalOpenGLTest == 0)
166  {
167  int normalOpenGLFpsTest = invokeNormalOpenGLRenderTest("9");
168  info.append(strprintf("%d", normalOpenGLFpsTest));
169  if (normalOpenGLFpsTest == 0)
170  {
171  normalOpenGLFps = readValue2(9);
172  info.append(strprintf(",%d", normalOpenGLFps));
173  if (normalOpenGLFps == 0)
174  {
175  normalOpenGLTest = -1;
176  normalOpenGLFpsTest = -1;
177  }
178  else
179  {
180  rescaleTest[1] = invokeNormalOpenGLRenderTest("6");
181  info.append(strprintf(",%d", rescaleTest[1]));
182  }
183  }
184  else
185  {
186  normalOpenGLTest = -1;
187  }
188  }
189  info.append(".");
190  if (safeOpenGLTest == 0)
191  {
192  int safeOpenGLFpsTest = invokeSafeOpenGLRenderTest("10");
193  info.append(strprintf("%d", safeOpenGLFpsTest));
194  if (safeOpenGLFpsTest == 0)
195  {
196  safeOpenGLFps = readValue2(10);
197  info.append(strprintf(",%d", safeOpenGLFps));
198  if (safeOpenGLFps == 0)
199  {
200  safeOpenGLTest = -1;
201  safeOpenGLFpsTest = -1;
202  }
203  else
204  {
205  rescaleTest[2] = invokeSafeOpenGLRenderTest("7");
206  info.append(strprintf(",%d", rescaleTest[2]));
207  }
208  }
209  else
210  {
211  safeOpenGLTest = -1;
212  }
213  }
214  info.append(".");
215 
216  int maxFps = softFps;
217  if (maxFps < normalOpenGLFps)
218  {
220  maxFps = normalOpenGLFps;
221  }
222  if (maxFps < modernOpenGLFps)
223  {
225  maxFps = modernOpenGLFps;
226  }
227  if (maxFps < safeOpenGLFps)
228  {
230  maxFps = safeOpenGLFps;
231  }
232 
233  int batchSize = 256;
234 
235  if (invokeNormalOpenBatchTest("11") == 0)
236  batchSize = readValue2(11);
237  if (batchSize < 256)
238  batchSize = 256;
239 
240  if (invokeNormalOpenBatchTest("14") == 0)
241  {
242  textureSize[CAST_SIZE(RENDER_NORMAL_OPENGL)]
243  = readValue2(14);
244  }
245  if (invokeModernOpenBatchTest("15") == 0)
246  {
247  textureSize[CAST_SIZE(RENDER_MODERN_OPENGL)]
248  = readValue2(15);
249  }
250  if (invokeSafeOpenBatchTest("16") == 0)
251  {
252  textureSize[CAST_SIZE(RENDER_SAFE_OPENGL)]
253  = readValue2(16);
254  }
255  if (invokeMobileOpenBatchTest("20") == 0)
256  {
257  textureSize[CAST_SIZE(RENDER_GLES_OPENGL)]
258  = readValue2(20);
259  }
260  for (int f = 0; f < 6; f ++)
261  info.append(strprintf(",%d", textureSize[f]));
262  info.append(",-");
263 
264  textureSizeStr = toString(textureSize[0]);
265  for (int f = 1; f < 6; f ++)
266  textureSizeStr.append(strprintf(",%d", textureSize[f]));
267 
268  // if OpenGL implimentation is not good, disable it.
269  if ((detectMode & 15) == 0)
271 
273  soundTest, info, batchSize, textureSizeStr, detectMode);
274  return 0;
275 }
#define CAST_SIZE
Definition: cast.h:34
int invokeMobileOpenBatchTest(const std::string &test)
Definition: testmain.cpp:412
void initConfig()
Definition: testmain.cpp:55
int invokeNormalOpenGLRenderTest(const std::string &test)
Definition: testmain.cpp:376
int readValue2(const int ver)
Definition: testmain.cpp:319
int invokeModernOpenGLRenderTest(const std::string &test)
Definition: testmain.cpp:385
int invokeTest(const std::string &test)
Definition: testmain.cpp:349
int invokeSafeOpenGLRenderTest(const std::string &test)
Definition: testmain.cpp:430
int invokeSoftwareRenderTest(const std::string &test)
Definition: testmain.cpp:367
void writeConfig(const RenderType openGLMode, const int rescale, const int sound, const std::string &info, const int batchSize, const std::string &textureSize, const int detectMode)
Definition: testmain.cpp:277
int invokeModernOpenBatchTest(const std::string &test)
Definition: testmain.cpp:403
int invokeTest4()
Definition: testmain.cpp:358
int invokeNormalOpenBatchTest(const std::string &test)
Definition: testmain.cpp:394
int invokeSafeOpenBatchTest(const std::string &test)
Definition: testmain.cpp:421
RenderType openGLMode
bool info(InputEvent &event)
Definition: commands.cpp:57
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
RenderType
Definition: rendertype.h:26
@ RENDER_SAFE_OPENGL
Definition: rendertype.h:29
@ RENDER_GLES_OPENGL
Definition: rendertype.h:30
@ RENDER_MODERN_OPENGL
Definition: rendertype.h:32
@ RENDER_NORMAL_OPENGL
Definition: rendertype.h:28
@ RENDER_SOFTWARE
Definition: rendertype.h:27
std::string strprintf(const char *const format,...)

References CAST_SIZE, Actions::info(), initConfig(), invokeMobileOpenBatchTest(), invokeModernOpenBatchTest(), invokeModernOpenGLRenderTest(), invokeNormalOpenBatchTest(), invokeNormalOpenGLRenderTest(), invokeSafeOpenBatchTest(), invokeSafeOpenGLRenderTest(), invokeSoftwareRenderTest(), invokeTest(), invokeTest4(), openGLMode, readValue2(), RENDER_GLES_OPENGL, RENDER_MODERN_OPENGL, RENDER_NORMAL_OPENGL, RENDER_SAFE_OPENGL, RENDER_SOFTWARE, strprintf(), Catch::toString(), and writeConfig().

Referenced by GraphicsManager::startDetection().

◆ getConfig()

Configuration& TestMain::getConfig ( )
inline

Definition at line 46 of file testmain.h.

47  { return mConfig; }

References mConfig.

Referenced by Setup_Video::action(), and GraphicsManager::detectVideoSettings().

◆ initConfig()

void TestMain::initConfig ( )
private

Definition at line 55 of file testmain.cpp.

56 {
57  mConfig.init(settings.configDir + "/test.xml",
60  mConfig.clear();
61 // setConfigDefaults(mConfig);
62 
63  mConfig.setValue("hwaccel", false);
64  mConfig.setValue("screen", false);
65  mConfig.setValue("sound", false);
66  mConfig.setValue("guialpha", 0.8F);
67 // mConfig.setValue("remember", true);
68  mConfig.setValue("sfxVolume", 50);
69  mConfig.setValue("musicVolume", 60);
70  mConfig.setValue("fpslimit", 0);
71  mConfig.setValue("customcursor", true);
72  mConfig.setValue("useScreenshotDirectorySuffix", true);
73  mConfig.setValue("ChatLogLength", 128);
74  mConfig.setValue("screenwidth", 800);
75  mConfig.setValue("screenheight", 600);
76 }
void setValue(const std::string &key, const std::string &value)
void init(const std::string &filename, const UseVirtFs useResManager, const SkipError skipError)
std::string configDir
Definition: settings.h:111
const bool SkipError_false
Definition: skiperror.h:30
const bool UseVirtFs_false
Definition: usevirtfs.h:30

References ConfigurationObject::clear(), Settings::configDir, Configuration::init(), mConfig, settings, Configuration::setValue(), SkipError_false, and UseVirtFs_false.

Referenced by exec().

◆ invokeMobileOpenBatchTest()

int TestMain::invokeMobileOpenBatchTest ( const std::string &  test)
private

Definition at line 412 of file testmain.cpp.

413 {
415  mConfig.write();
416  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
417 // log->log("%s: %d", test.c_str(), ret);
418  return ret;
419 }
#define CAST_S32
Definition: cast.h:30
int execFileWait(const std::string &pathName, const std::string &name, const std::string &arg1, const std::string &arg2, int waitTime)
Definition: process.cpp:231

References CAST_S32, execFileWait(), fileName, mConfig, RENDER_GLES_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeModernOpenBatchTest()

int TestMain::invokeModernOpenBatchTest ( const std::string &  test)
private

Definition at line 403 of file testmain.cpp.

404 {
406  mConfig.write();
407  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
408 // log->log("%s: %d", test.c_str(), ret);
409  return ret;
410 }

References CAST_S32, execFileWait(), fileName, mConfig, RENDER_MODERN_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeModernOpenGLRenderTest()

int TestMain::invokeModernOpenGLRenderTest ( const std::string &  test)
private

Definition at line 385 of file testmain.cpp.

386 {
388  mConfig.write();
389  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
390  log->log("%s: %d", test.c_str(), ret);
391  return ret;
392 }
void log(const char *const log_text,...)
Definition: logger.cpp:269

References CAST_S32, execFileWait(), fileName, Logger::log(), log, mConfig, RENDER_MODERN_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeNormalOpenBatchTest()

int TestMain::invokeNormalOpenBatchTest ( const std::string &  test)
private

Definition at line 394 of file testmain.cpp.

395 {
397  mConfig.write();
398  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
399 // log->log("%s: %d", test.c_str(), ret);
400  return ret;
401 }

References CAST_S32, execFileWait(), fileName, mConfig, RENDER_NORMAL_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeNormalOpenGLRenderTest()

int TestMain::invokeNormalOpenGLRenderTest ( const std::string &  test)
private

Definition at line 376 of file testmain.cpp.

377 {
379  mConfig.write();
380  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
381  log->log("%s: %d", test.c_str(), ret);
382  return ret;
383 }

References CAST_S32, execFileWait(), fileName, Logger::log(), log, mConfig, RENDER_NORMAL_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeSafeOpenBatchTest()

int TestMain::invokeSafeOpenBatchTest ( const std::string &  test)
private

Definition at line 421 of file testmain.cpp.

422 {
424  mConfig.write();
425  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
426 // log->log("%s: %d", test.c_str(), ret);
427  return ret;
428 }

References CAST_S32, execFileWait(), fileName, mConfig, RENDER_SAFE_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeSafeOpenGLRenderTest()

int TestMain::invokeSafeOpenGLRenderTest ( const std::string &  test)
private

Definition at line 430 of file testmain.cpp.

431 {
433  mConfig.write();
434  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
435  log->log("%s: %d", test.c_str(), ret);
436  return ret;
437 }

References CAST_S32, execFileWait(), fileName, Logger::log(), log, mConfig, RENDER_SAFE_OPENGL, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeSoftwareRenderTest()

int TestMain::invokeSoftwareRenderTest ( const std::string &  test)
private

Definition at line 367 of file testmain.cpp.

368 {
370  mConfig.write();
371  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
372  log->log("%s: %d", test.c_str(), ret);
373  return ret;
374 }

References CAST_S32, execFileWait(), fileName, Logger::log(), log, mConfig, RENDER_SOFTWARE, Configuration::setValue(), and Configuration::write().

Referenced by exec().

◆ invokeTest()

int TestMain::invokeTest ( const std::string &  test)
private

Definition at line 349 of file testmain.cpp.

350 {
352 
353  mConfig.write();
354  const int ret = execFileWait(fileName, fileName, "-t", test, 0);
355  return ret;
356 }

References CAST_S32, execFileWait(), fileName, mConfig, RENDER_SOFTWARE, Configuration::setValue(), and Configuration::write().

Referenced by exec(), and invokeTest4().

◆ invokeTest3()

int TestMain::invokeTest3 ( )
private

◆ invokeTest4()

int TestMain::invokeTest4 ( )
private

Definition at line 358 of file testmain.cpp.

359 {
360  mConfig.setValue("sound", true);
361  const int ret = invokeTest("4");
362 
363  log->log("4: %d", ret);
364  return ret;
365 }

References invokeTest(), Logger::log(), log, mConfig, and Configuration::setValue().

Referenced by exec().

◆ invokeTest7()

int TestMain::invokeTest7 ( )
private

◆ readValue()

int TestMain::readValue ( const int  ver,
int  def 
)
static

Definition at line 326 of file testmain.cpp.

327 {
328  std::string tmp;
329  int var;
330  std::ifstream file;
331  file.open(pathJoin(settings.localDataDir, "test.log").c_str(),
332  std::ios::in);
333  if (!getline(file, tmp))
334  {
335  file.close();
336  return def;
337  }
338  var = atoi(tmp.c_str());
339  if (ver != var || !getline(file, tmp))
340  {
341  file.close();
342  return def;
343  }
344  def = atoi(tmp.c_str());
345  file.close();
346  return def;
347 }

References Settings::localDataDir, pathJoin(), and settings.

Referenced by readValue2().

◆ readValue2()

int TestMain::readValue2 ( const int  ver)
private

Definition at line 319 of file testmain.cpp.

320 {
321  const int def = readValue(ver, 0);
322  log->log("value for %d = %d", ver, def);
323  return def;
324 }
static int readValue(const int ver, int def)
Definition: testmain.cpp:326

References Logger::log(), log, and readValue().

Referenced by exec().

◆ testsMain()

void TestMain::testsMain ( )
private

◆ writeConfig()

void TestMain::writeConfig ( const RenderType  openGLMode,
const int  rescale,
const int  sound,
const std::string &  info,
const int  batchSize,
const std::string &  textureSize,
const int  detectMode 
)
private

Definition at line 277 of file testmain.cpp.

284 {
285  mConfig.init(settings.configDir + "/config.xml",
288 
289  log->log("set mode to %d", CAST_S32(openGLMode));
290 
291  // searched values
292  mConfig.setValue("opengl", CAST_S32(openGLMode));
293  mConfig.setValue("showBackground", rescale == 0);
294  mConfig.setValue("sound", sound == 0);
295 
296  // better performance
297  mConfig.setValue("hwaccel", true);
298  mConfig.setValue("fpslimit", 60);
299  mConfig.setValue("altfpslimit", 2);
300  mConfig.setValue("safemode", false);
301  mConfig.setValue("enableMapReduce", true);
302  mConfig.setValue("textureSize", textureSize);
303 
304  // max batch size
305 // mConfig.setValue("batchsize", batchSize);
306 
307  // additional modes
308  mConfig.setValue("useTextureSampler",
309  static_cast<bool>(detectMode & 1024));
310  mConfig.setValue("compresstextures",
311  static_cast<bool>(detectMode & 2048));
312 
313  // stats
314  mConfig.setValue("testInfo", info);
315 
316  mConfig.write();
317 }

References CAST_S32, Settings::configDir, Actions::info(), Configuration::init(), Logger::log(), log, mConfig, openGLMode, settings, Configuration::setValue(), SkipError_false, UseVirtFs_false, and Configuration::write().

Referenced by exec().

Field Documentation

◆ log

Logger* TestMain::log
private

◆ mConfig

Configuration TestMain::mConfig
private

The documentation for this class was generated from the following files: