245 lines
4.8 KiB
C++
Executable File
245 lines
4.8 KiB
C++
Executable File
#include <time.h>
|
|
|
|
#include <applicat.h>
|
|
#include <mask.h>
|
|
#include <progind.h>
|
|
#include <urldefid.h>
|
|
|
|
#include <relapp.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Test Relapp
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TTestrel_application : public TRelation_application
|
|
{
|
|
const char* _maskname;
|
|
const char* _num;
|
|
|
|
TRelation* _rel;
|
|
TMask* _msk;
|
|
|
|
protected:
|
|
virtual bool user_create();
|
|
virtual bool user_destroy();
|
|
virtual TMask* get_mask(int) { return _msk; }
|
|
virtual bool changing_mask(int) { return FALSE;}
|
|
virtual TRelation* get_relation() const { return _rel; }
|
|
virtual int read(TMask& m) { m.autoload(*_rel); return NOERR; }
|
|
virtual int write(const TMask&) { return NOERR; }
|
|
virtual int rewrite(const TMask&) { return NOERR; }
|
|
|
|
public:
|
|
TTestrel_application(const char* name, const char* num);
|
|
};
|
|
|
|
TTestrel_application::TTestrel_application(const char* name, const char* num)
|
|
: _maskname(name), _num(num),
|
|
_msk(NULL), _rel(NULL)
|
|
{}
|
|
|
|
|
|
bool TTestrel_application::user_create()
|
|
{
|
|
_msk = new TMask(_maskname);
|
|
|
|
int id = atoi(_num);
|
|
if (id > 0) _rel = new TRelation(id);
|
|
else _rel = new TRelation(_num);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TTestrel_application::user_destroy()
|
|
{
|
|
delete _msk;
|
|
delete _rel;
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Testmask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TTest_application : public TApplication
|
|
{
|
|
TFilename _maskname;
|
|
|
|
protected:
|
|
bool create() { dispatch_e_menu(BAR_ITEM(1)); return TRUE; }
|
|
bool destroy() { return TRUE; }
|
|
bool menu(MENU_TAG);
|
|
|
|
public:
|
|
TTest_application(const char* name) : _maskname(name) {}
|
|
};
|
|
|
|
bool TTest_application::menu(MENU_TAG)
|
|
{
|
|
TMask m(_maskname);
|
|
KEY k = m.run();
|
|
if (k == K_QUIT) stop_run();
|
|
|
|
return k != K_QUIT;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TBenchmark_application : public TApplication
|
|
{
|
|
TIndwin* _iw;
|
|
clock_t _timer_start;
|
|
|
|
protected:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual bool menu(MENU_TAG);
|
|
|
|
void initializing();
|
|
void start_test(const char* msg);
|
|
void stop_test();
|
|
|
|
void test_relation_scan();
|
|
void test_cursor_scan();
|
|
|
|
public:
|
|
TBenchmark_application() : _iw(NULL) { }
|
|
virtual ~TBenchmark_application() { }
|
|
};
|
|
|
|
bool TBenchmark_application::create()
|
|
{
|
|
dispatch_e_menu(MENU_ITEM(1));
|
|
return TRUE;
|
|
}
|
|
|
|
bool TBenchmark_application::destroy()
|
|
{
|
|
if (_iw)
|
|
{
|
|
delete _iw;
|
|
_iw = NULL;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TBenchmark_application::menu(MENU_TAG)
|
|
{
|
|
TString test = argv(1); test.upper();
|
|
const bool test_all = test.find('*') >= 0;
|
|
|
|
if (test_all || test.find('R') >= 0)
|
|
test_relation_scan();
|
|
|
|
if (test_all || test.find('C') >= 0)
|
|
test_cursor_scan();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void TBenchmark_application::initializing()
|
|
{
|
|
CHECK(_iw == NULL, "Benchmark already in progress");
|
|
_iw = new TIndwin(48, "Initializing ...", TRUE, FALSE, 48);
|
|
}
|
|
|
|
void TBenchmark_application::start_test(const char* text)
|
|
{
|
|
CHECK(_iw != NULL, "Benchmark not started yet");
|
|
_iw->set_text(text);
|
|
do_events();
|
|
|
|
clock_t t;
|
|
_timer_start = clock();
|
|
do
|
|
{
|
|
t = clock();
|
|
} while (t == _timer_start);
|
|
_timer_start = t;
|
|
}
|
|
|
|
void TBenchmark_application::stop_test()
|
|
{
|
|
CHECK(_iw != NULL, "Benchmark not started yet");
|
|
const clock_t t = clock() - _timer_start;
|
|
const double s = t / CLOCKS_PER_SEC;
|
|
TString80 msg;
|
|
msg.format("Time to complete: %.1lf s", s);
|
|
_iw->set_text(msg);
|
|
|
|
while (!_iw->iscancelled())
|
|
do_events();
|
|
|
|
delete _iw;
|
|
_iw = NULL;
|
|
}
|
|
|
|
void TBenchmark_application::test_relation_scan()
|
|
{
|
|
initializing();
|
|
|
|
TRelation comuni(LF_COMUNI);
|
|
comuni.add("%UID", "CODTAB=UFFIIDD1");
|
|
comuni.first();
|
|
|
|
start_test("Scansione relazione COMUNI+%UID");
|
|
|
|
while (!comuni.eof())
|
|
comuni.next();
|
|
|
|
stop_test();
|
|
}
|
|
|
|
void TBenchmark_application::test_cursor_scan()
|
|
{
|
|
initializing();
|
|
|
|
TRelation comuni(LF_COMUNI);
|
|
comuni.add("%UID", "CODTAB=UFFIIDD1");
|
|
|
|
TCursor cur(&comuni);
|
|
cur = 0L;
|
|
|
|
start_test("Scansione cursore COMUNI+%UID");
|
|
|
|
while (cur.ok())
|
|
++cur;
|
|
|
|
stop_test();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TApplication::check_parameters(argc, argv);
|
|
|
|
if (argc > 1 && *argv[1] == '-')
|
|
{
|
|
TBenchmark_application bma;
|
|
bma.run(argc, argv, "Benchmark");
|
|
return 0;
|
|
}
|
|
|
|
if (argc < 3)
|
|
{
|
|
TFilename n = argv[1];
|
|
if (n.not_empty())
|
|
{
|
|
TTest_application a(n);
|
|
n = n.name(); n.insert("Test Mask ", 0);
|
|
a.run(argc, argv, n);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TTestrel_application a(argv[1], argv[2]);
|
|
a.run(argc, argv, "Test Relation Application");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|