Skip to content

Commit

Permalink
WIP. Fixing MT5 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jan 27, 2023
1 parent c09b514 commit 88108ce
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 35 deletions.
28 changes: 21 additions & 7 deletions Database.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ struct DatabaseTableColumnEntry {
// State methods.
bool IsKey() { return bool(flags & DATABASE_COLUMN_FLAG_IS_KEY); }
bool IsNull() { return bool(flags & DATABASE_COLUMN_FLAG_IS_NULL); }

DatabaseTableColumnEntry() {}
DatabaseTableColumnEntry(const string _name, const ENUM_DATATYPE _type, unsigned short _flags = 0,
unsigned short _char_size = 0) {
name = _name;
type = _type;
flags = _flags;
char_size = _char_size;
}
DatabaseTableColumnEntry(const DatabaseTableColumnEntry &r) {
name = r.name;
type = r.type;
flags = r.flags;
char_size = r.char_size;
}
};
struct DatabaseTableSchema {
DictStruct<short, DatabaseTableColumnEntry> columns;
Expand All @@ -84,6 +99,7 @@ struct DatabaseTableSchema {
columns.Push(_columns[i]);
}
}
DatabaseTableSchema(const DatabaseTableSchema &r) { columns = r.columns; }
// Methods.
bool AddColumn(DatabaseTableColumnEntry &column) { return columns.Push(column); }
};
Expand All @@ -98,13 +114,11 @@ struct DbSymbolInfoEntry : public SymbolInfoEntry {
}
// Methods.
void DefineSchema() {
DatabaseTableColumnEntry _columns[] = {
{"bid", TYPE_DOUBLE}, {"ask", TYPE_DOUBLE}, {"last", TYPE_DOUBLE},
{"spread", TYPE_DOUBLE}, {"volume", TYPE_INT},
};
for (int i = 0; i < ArraySize(_columns); i++) {
schema.columns.Push(_columns[i]);
}
schema.columns.Push(DatabaseTableColumnEntry("bid", TYPE_DOUBLE));
schema.columns.Push(DatabaseTableColumnEntry("ask", TYPE_DOUBLE));
schema.columns.Push(DatabaseTableColumnEntry("last", TYPE_DOUBLE));
schema.columns.Push(DatabaseTableColumnEntry("spread", TYPE_DOUBLE));
schema.columns.Push(DatabaseTableColumnEntry("volume", TYPE_INT));
}
};
#endif
Expand Down
4 changes: 4 additions & 0 deletions DictSlot.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class DictSlot {

DictSlot(unsigned char flags = 0) : _flags(flags) {}

#ifdef __MQL__
DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key), value(r.value) {}
#else
DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key) { value = r.value; }
#endif

bool IsValid() { return !bool(_flags & DICT_SLOT_INVALID); }

Expand Down
3 changes: 2 additions & 1 deletion Draw.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Draw;
#include "Data.define.h"
#include "Object.extern.h"
//#include "Platform.h"
#include "Object.mqh"
#include "Terminal.define.h"

#ifndef __MQL4__
Expand Down Expand Up @@ -72,7 +73,7 @@ class Draw : public Object {
/**
* Class constructor.
*/
Draw(long _chart_id = 0) : chart_id(_chart_id != 0 ? _chart_id : Platform::ChartID()) {}
Draw(long _chart_id = 0) : chart_id(_chart_id != 0 ? _chart_id : ::ChartID()) {}

/* Graphic object related methods */

Expand Down
1 change: 1 addition & 0 deletions Market.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class Serializer;

// Includes.
#include "DateTime.entry.h"
#include "DateTime.struct.h"
#include "Serializer/SerializerNode.enum.h"
#include "Std.h"
Expand Down
2 changes: 1 addition & 1 deletion Matrix.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class MatrixDimension {
int position[MATRIX_DIMENSIONS - 1];

// Containers array if type is "Containers"
ARRAY(MatrixDimension<X>, containers);
ARRAY(MatrixDimension<X>*, containers);

/**
* Constructor.
Expand Down
2 changes: 2 additions & 0 deletions Order.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ enum ENUM_ORDER_TYPE {
ORDER_TYPE_CLOSE_BY, // Order to close a position by an opposite one.
ORDER_TYPE_UNSET // A NULL value.
};
#else
#define ORDER_TYPE_UNSET NULL
#endif

/* Positions */
Expand Down
10 changes: 5 additions & 5 deletions Order.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class Order : public SymbolInfo {
ENUM_ORDER_CONDITION _cond = oparams.Get<ENUM_ORDER_CONDITION>(ORDER_PARAM_COND_CLOSE, _ci);
ARRAY(DataParamEntry, _cond_args);
DataParamEntry _item0 = oparams.Get<long>(ORDER_PARAM_COND_CLOSE_ARG_VALUE, _ci);
ArrayPush(_cond_args, _item0);
ArrayPushObject(_cond_args, _item0);
_result |= Order::CheckCondition(_cond, _cond_args);
}
}
Expand Down Expand Up @@ -2478,7 +2478,7 @@ class Order : public SymbolInfo {
case ORDER_TIME_SETUP:
return OrderGetValue(DEAL_TIME, _type, _out);
case ORDER_TYPE:
switch (OrderGetValue(DEAL_TYPE, _type, _long)) {
switch ((int)OrderGetValue(DEAL_TYPE, _type, _long)) {
case DEAL_TYPE_BUY:
return ConvertBasic::LongTo<X>(ORDER_TYPE_BUY);
case DEAL_TYPE_SELL:
Expand Down Expand Up @@ -2512,7 +2512,7 @@ class Order : public SymbolInfo {
return NULL_VALUE;
default:
if ((int)_prop_id == (int)ORDER_REASON) {
switch (OrderGetValue(DEAL_REASON, _type, _long)) {
switch ((int)OrderGetValue(DEAL_REASON, _type, _long)) {
case DEAL_REASON_CLIENT:
return ConvertBasic::LongTo<X>(ORDER_REASON_CLIENT);
case DEAL_REASON_MOBILE:
Expand Down Expand Up @@ -2576,7 +2576,7 @@ class Order : public SymbolInfo {
case ORDER_TIME_SETUP:
return OrderGetValue(POSITION_TIME, _type, _out);
case ORDER_TYPE:
switch (OrderGetValue(POSITION_TYPE, _type, _long)) {
switch ((int)OrderGetValue(POSITION_TYPE, _type, _long)) {
case POSITION_TYPE_BUY:
return ConvertBasic::LongTo<X>(ORDER_TYPE_BUY);
case POSITION_TYPE_SELL:
Expand Down Expand Up @@ -2610,7 +2610,7 @@ class Order : public SymbolInfo {
return NULL_VALUE;
default:
if ((int)_prop_id == (int)ORDER_REASON) {
switch (OrderGetValue(POSITION_REASON, _type, _long)) {
switch ((int)OrderGetValue(POSITION_REASON, _type, _long)) {
case POSITION_REASON_CLIENT:
return ConvertBasic::LongTo<X>(ORDER_REASON_CLIENT);
case POSITION_REASON_MOBILE:
Expand Down
1 change: 0 additions & 1 deletion PlatformTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

// Includes.
#include "DateTime.enum.h"
#include "DateTime.mqh"

/**
* @file
Expand Down
6 changes: 5 additions & 1 deletion Task/TaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,19 @@ class TaskManager {
void Clear() {
Task *task0 = tasks[0].Ptr();

for (int i = 0; i < tasks.Size(); ++i) {
#ifndef __MQL__
for (unsigned int i = 0; i < tasks.Size(); ++i) {
std::cout << "Task #" << i << ": " << tasks[i].ToString() << std::endl;
}
#endif

tasks.Clear();

#ifndef __MQL__
std::cout << "Tasks cleared." << std::endl;
std::cout << task0 PTR_DEREF ToString() << std::endl;
// std::cout.flush();
#endif
}

/* Processing methods */
Expand Down
1 change: 1 addition & 0 deletions tests/EATest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
struct DataParamEntry;

// Includes.
#include "../Account/Account.struct.h"
#include "../EA.mqh"
#include "../Test.mqh"

Expand Down
2 changes: 1 addition & 1 deletion tests/OrderTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool OpenOrder(int _index, int _order_no) {
OrderParams _oparams;
if (_request.type == ORDER_TYPE_SELL) {
ARRAY(DataParamEntry, _cond_args);
DataParamEntry _param1 = ORDER_TYPE_TIME;
DataParamEntry _param1 = (int)ORDER_TYPE_TIME;
DataParamEntry _param2 = PeriodSeconds() * (MAX_ORDERS + _index);
ArrayPushObject(_cond_args, _param1);
ArrayPushObject(_cond_args, _param2);
Expand Down
33 changes: 17 additions & 16 deletions tests/RefsTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DynamicClass : public Dynamic {
int number;

DynamicClass(int _number, DynamicClass* _parent = NULL) : number(_number), parent(_parent) {}
DynamicClass(const DynamicClass& r) { THIS_REF = r; }
};

/**
Expand All @@ -57,7 +58,6 @@ class BadDynamicClass : public Dynamic {
*/
int OnInit() {
// Weak references only.

WeakRef<DynamicClass> dyn1 = new DynamicClass(1);
assertTrueOrFail(dyn1.ObjectExists(), "Object should exist");

Expand Down Expand Up @@ -137,25 +137,26 @@ int OnInit() {
// Dictionary of weak references.

DictStruct<string, WeakRef<DynamicClass>> refs2;
/*
Ref<DynamicClass> dyn9_1 = new DynamicClass(1);
Ref<DynamicClass> dyn9_2 = new DynamicClass(2);
Ref<DynamicClass> dyn9_3 = new DynamicClass(3);

WeakRef<DynamicClass> dyn9_1_weak_ref = dyn9_1;
WeakRef<DynamicClass> dyn9_2_weak_ref = dyn9_2;
WeakRef<DynamicClass> dyn9_3_weak_ref = dyn9_3;
Ref<DynamicClass> dyn9_1 = new DynamicClass(1);
Ref<DynamicClass> dyn9_2 = new DynamicClass(2);
Ref<DynamicClass> dyn9_3 = new DynamicClass(3);
refs2.Set("1", dyn9_1_weak_ref);
refs2.Set("2", dyn9_2_weak_ref);
refs2.Set("3", dyn9_3_weak_ref);
WeakRef<DynamicClass> dyn9_1_weak_ref = dyn9_1;
WeakRef<DynamicClass> dyn9_2_weak_ref = dyn9_2;
WeakRef<DynamicClass> dyn9_3_weak_ref = dyn9_3;
// Should make refs2["2"] to have no existing object.
dyn9_2 = NULL;
refs2.Set("1", dyn9_1_weak_ref);
refs2.Set("2", dyn9_2_weak_ref);
refs2.Set("3", dyn9_3_weak_ref);
assertTrueOrFail(refs2.GetByKey("1").ObjectExists(), "Object should exists");
assertTrueOrFail(!refs2.GetByKey("2").ObjectExists(), "Object should not exists as it has no more strong references");
assertTrueOrFail(refs2.GetByKey("3").ObjectExists(), "Object should exists");
// Should make refs2["2"] to have no existing object.
dyn9_2 = NULL;
assertTrueOrFail(refs2.GetByKey("1").ObjectExists(), "Object should exists");
assertTrueOrFail(!refs2.GetByKey("2").ObjectExists(), "Object should not exists as it has no more strong
references"); assertTrueOrFail(refs2.GetByKey("3").ObjectExists(), "Object should exists");
*/
return INIT_SUCCEEDED;
}
4 changes: 2 additions & 2 deletions tests/TerminalTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Terminal *terminal;
*/
int OnInit() {
terminal = new Terminal();
Print("TERMINAL (OnInit):\n\t\t\t", terminal.ToString("\n\t\t\t"));
Print("TERMINAL (OnInit):\n\t\t\t", terminal.ToString());
assertTrueOrFail(terminal.IsDllsAllowed(), "DLLs not allowed!");
assertTrueOrFail(terminal.IsExpertEnabled(), "Expert Advisors not allowed!");
assertTrueOrFail(terminal.IsLibrariesAllowed(), "Libraries not allowed!");
Expand Down Expand Up @@ -73,6 +73,6 @@ int OnInit() {
* Implements OnDeinit().
*/
void OnDeinit(const int reason) {
Print("TERMINAL (OnDeinit):\n\t\t\t", terminal.ToString("\n\t\t\t"));
Print("TERMINAL (OnDeinit):\n\t\t\t", terminal.ToString());
Object::Delete(terminal);
}

0 comments on commit 88108ce

Please sign in to comment.