📄 testshell.cpp
字号:
/****************************************************************************
STLport Test Shell for Symbian OS
Copyright (C) 2007 by Marco Jez
http://marcoplusplus.blogspot.com
This material is provided "as is", with absolutely no warranty expressed
or implied. Any use is at your own risk.
Permission to use or copy this software for any purpose is hereby granted
without fee, provided the above notices are retained on all copies.
Permission to modify the code and to distribute modified code is granted,
provided the above notices are retained, and a notice that the code was
modified is included with the above copyright notice.
****************************************************************************/
#include <e32base.h>
#include <e32keys.h>
#include <e32std.h>
#include <e32cons.h>
#include <f32file.h>
CConsoleBase* console;
TBuf<256> log_file_name(_L("x:\\stlplog.txt"));
enum State
{
state_start,
state_sel_test,
state_run_test_1,
state_run_test_2,
state_sel_log,
state_error,
state_finished,
state_exit
};
bool launch_test_program(const TDesC &filename, const TDesC &options = KNullDesC)
{
console->ClearScreen();
console->Write(_L("Please wait...\n\n"));
RFs fs;
RFile logfile;
bool logfile_ok = false;
if (fs.Connect() == KErrNone)
{
// replace log file if existing...
if (logfile.Replace(fs, log_file_name, EFileWrite) == KErrNone)
logfile.Close();
// ... then reopen it for reading only
if (logfile.Open(fs, log_file_name, EFileRead | EFileShareAny | EFileStreamText) == KErrNone)
logfile_ok = true;
else
fs.Close();
}
TBuf<512> cmdline(_L("-f="));
cmdline.Append(log_file_name);
if (options.Length() > 0)
{
cmdline.Append(_L(" "));
cmdline.Append(options);
}
RProcess process;
if (process.Create(filename, cmdline) != KErrNone)
return false;
if (!logfile_ok)
console->Write(_L("WARNING: error creating log file. Log will not be saved\n\n"));
process.Resume();
TBuf8<16> buf8;
TBuf<16> buf;
while (process.ExitType() == EExitPending)
{
User::After(1000);
if (logfile_ok)
{
while (logfile.Read(buf8) == KErrNone && buf8.Length() > 0)
{
buf.Copy(buf8);
console->Write(buf);
}
}
}
process.Close();
if (logfile_ok)
{
logfile.Close();
fs.Close();
}
return true;
}
bool is_num_key(int n, TKeyCode k)
{
switch (n)
{
case 0: return k == '0';
case 1: return k == '1';
case 2: return k == '2';
case 3: return k == '3';
case 4: return k == '4';
default: return false;
}
}
TKeyCode eatingGetch()
{
return console->Getch();
}
void waitkeypress()
{
console->Write(_L("[press key 1]\n"));
while (!is_num_key(1, eatingGetch())) {}
}
void display_header()
{
console->ClearScreen();
console->Write(_L("STLport Test Shell\n"));
console->Write(_L("--------------------\n"));
console->Write(_L("Copyright (C) 2007\n"));
console->Write(_L(" by Marco Jez\n"));
console->Write(_L("--------------------\n\n"));
}
State s_start()
{
display_header();
console->Write(_L("MAIN MENU\n"));
console->Write(_L(" 1. Run test\n"));
console->Write(_L(" 2. Select log file\n"));
console->Write(_L(" 0. Exit\n"));
TKeyCode k = eatingGetch();
if (is_num_key(1, k)) return state_sel_test;
if (is_num_key(2, k)) return state_sel_log;
if (is_num_key(0, k)) return state_exit;
return state_start;
}
State s_sel_test()
{
display_header();
console->Write(_L("SELECT TEST PROGRAM\n"));
console->Write(_L(" 1. Regression Test\n"));
console->Write(_L(" 2. Exception Test\n"));
console->Write(_L(" 3. [main menu]\n"));
TKeyCode k = eatingGetch();
if (is_num_key(1, k)) return state_run_test_1;
if (is_num_key(2, k)) return state_run_test_2;
if (is_num_key(3, k)) return state_start;
return state_sel_test;
}
State s_run_test_1()
{
if (launch_test_program(_L("stlunittest.exe")))
return state_finished;
return state_error;
}
State s_run_test_2()
{
if (launch_test_program(_L("stlehtest.exe"), _L("-n 1 -s 100")))
return state_finished;
return state_error;
}
State s_sel_log()
{
display_header();
console->Write(_L("SELECT LOG FILE\n"));
char log_drive = log_file_name[0];
console->Write(log_drive == 'C' ? _L(">") : _L(" "));
console->Write(_L(" 1. C:\\stlplog.txt\n"));
console->Write(log_drive == 'D' ? _L(">") : _L(" "));
console->Write(_L(" 2. D:\\stlplog.txt\n"));
console->Write(log_drive == 'E' ? _L(">") : _L(" "));
console->Write(_L(" 3. E:\\stlplog.txt\n"));
console->Write(_L(" 4. [main menu]\n"));
TKeyCode k = eatingGetch();
if (is_num_key(1, k))
log_file_name[0] = static_cast<unsigned short>('C');
if (is_num_key(2, k))
log_file_name[0] = static_cast<unsigned short>('D');
if (is_num_key(3, k))
log_file_name[0] = static_cast<unsigned short>('E');
if (is_num_key(4, k))
return state_start;
return state_sel_log;
}
State s_finished()
{
console->Write(_L("\n*** finished\n"));
waitkeypress();
return state_start;
}
State s_error()
{
console->Write(_L("\n*** error\n"));
waitkeypress();
return state_start;
}
void run_state_machine()
{
State state = state_start;
while (state != state_exit)
{
switch (state)
{
case state_start: state = s_start(); break;
case state_sel_test: state = s_sel_test(); break;
case state_run_test_1: state = s_run_test_1(); break;
case state_run_test_2: state = s_run_test_2(); break;
case state_sel_log: state = s_sel_log(); break;
case state_error: state = s_error(); break;
case state_finished: state = s_finished(); break;
case state_exit: break;
}
}
}
void DoStartL()
{
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
#ifdef __WINSCW__
log_file_name[0] = 'C';
#else
# ifdef __SERIES60_3X__
log_file_name[0] = 'E';
# else
log_file_name[0] = 'D';
# endif
#endif
run_state_machine();
// Delete active scheduler
CleanupStack::PopAndDestroy(scheduler);
}
TInt E32Main()
{
// Create cleanup stack
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New();
// Create output console
TRAPD(createError, console = Console::NewL(_L("STLport Test Shell"), TSize(KConsFullScreen, KConsFullScreen)));
if (createError)
return createError;
// Run application code inside TRAP harness, wait keypress when terminated
TRAPD(mainError, DoStartL());
if (mainError)
console->Printf(_L(" failed, leave code = %d"), mainError);
delete console;
delete cleanup;
__UHEAP_MARKEND;
return KErrNone;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -