summaryrefslogtreecommitdiff
path: root/main/tests
diff options
context:
space:
mode:
Diffstat (limited to 'main/tests')
-rw-r--r--main/tests/test_astar.cpp77
-rw-r--r--main/tests/test_gdscript.cpp201
-rw-r--r--main/tests/test_gui.cpp5
-rw-r--r--main/tests/test_main.cpp18
-rw-r--r--main/tests/test_math.cpp36
-rw-r--r--main/tests/test_oa_hash_map.cpp9
-rw-r--r--main/tests/test_ordered_hash_map.cpp8
-rw-r--r--main/tests/test_physics_2d.cpp35
-rw-r--r--main/tests/test_physics_3d.cpp28
-rw-r--r--main/tests/test_render.cpp12
-rw-r--r--main/tests/test_shader_lang.cpp37
-rw-r--r--main/tests/test_string.cpp126
12 files changed, 216 insertions, 376 deletions
diff --git a/main/tests/test_astar.cpp b/main/tests/test_astar.cpp
index 3cc754e230..fe335589b0 100644
--- a/main/tests/test_astar.cpp
+++ b/main/tests/test_astar.cpp
@@ -173,8 +173,9 @@ bool test_add_remove() {
for (int i = 0; i < 20000; i++) {
int u = Math::rand() % 5;
int v = Math::rand() % 4;
- if (u == v)
+ if (u == v) {
v = 4;
+ }
if (Math::rand() % 2 == 1) {
// Add a (possibly existing) directed edge and confirm connectivity
a.connect_points(u, v, false);
@@ -189,19 +190,22 @@ bool test_add_remove() {
// Random tests for point removal
for (int i = 0; i < 20000; i++) {
a.clear();
- for (int j = 0; j < 5; j++)
+ for (int j = 0; j < 5; j++) {
a.add_point(j, Vector3(0, 0, 0));
+ }
// Add or remove random edges
for (int j = 0; j < 10; j++) {
int u = Math::rand() % 5;
int v = Math::rand() % 4;
- if (u == v)
+ if (u == v) {
v = 4;
- if (Math::rand() % 2 == 1)
+ }
+ if (Math::rand() % 2 == 1) {
a.connect_points(u, v, false);
- else
+ } else {
a.disconnect_points(u, v, false);
+ }
}
// Remove point 0
@@ -241,8 +245,9 @@ bool test_solutions() {
int u, v;
u = Math::rand() % N;
v = Math::rand() % (N - 1);
- if (u == v)
+ if (u == v) {
v = N - 1;
+ }
// Pick a random operation
int op = Math::rand();
@@ -256,16 +261,18 @@ bool test_solutions() {
// Add edge (u, v); possibly bidirectional
a.connect_points(u, v, op % 2);
adj[u][v] = true;
- if (op % 2)
+ if (op % 2) {
adj[v][u] = true;
+ }
break;
case 6:
case 7:
// Remove edge (u, v); possibly bidirectional
a.disconnect_points(u, v, op % 2);
adj[u][v] = false;
- if (op % 2)
+ if (op % 2) {
adj[v][u] = false;
+ }
break;
case 8:
// Remove point u and add it back; clears adjacent edges and changes coordinates
@@ -274,42 +281,55 @@ bool test_solutions() {
p[u].y = Math::rand() % 100;
p[u].z = Math::rand() % 100;
a.add_point(u, p[u]);
- for (v = 0; v < N; v++)
+ for (v = 0; v < N; v++) {
adj[u][v] = adj[v][u] = false;
+ }
break;
}
}
// Floyd-Warshall
float d[N][N];
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
d[u][v] = (u == v || adj[u][v]) ? p[u].distance_to(p[v]) : INFINITY;
+ }
+ }
- for (int w = 0; w < N; w++)
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (d[u][v] > d[u][w] + d[w][v])
+ for (int w = 0; w < N; w++) {
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (d[u][v] > d[u][w] + d[w][v]) {
d[u][v] = d[u][w] + d[w][v];
+ }
+ }
+ }
+ }
// Display statistics
int count = 0;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (adj[u][v])
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (adj[u][v]) {
count++;
+ }
+ }
+ }
printf("Test #%4d: %3d edges, ", test + 1, count);
count = 0;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (!Math::is_inf(d[u][v]))
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (!Math::is_inf(d[u][v])) {
count++;
+ }
+ }
+ }
printf("%3d/%d pairs of reachable points\n", count - N, N * (N - 1));
// Check A*'s output
bool match = true;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
if (u != v) {
Vector<int> route = a.get_id_path(u, v);
if (!Math::is_inf(d[u][v])) {
@@ -344,10 +364,13 @@ bool test_solutions() {
}
}
}
+ }
+ }
exit:
- if (!match)
+ if (!match) {
return false;
+ }
}
return true;
}
@@ -367,11 +390,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp
index 971460c655..10586c6495 100644
--- a/main/tests/test_gdscript.cpp
+++ b/main/tests/test_gdscript.cpp
@@ -45,7 +45,6 @@
namespace TestGDScript {
static void _print_indent(int p_ident, const String &p_text) {
-
String txt;
for (int i = 0; i < p_ident; i++) {
txt += '\t';
@@ -55,18 +54,18 @@ static void _print_indent(int p_ident, const String &p_text) {
}
static String _parser_extends(const GDScriptParser::ClassNode *p_class) {
-
String txt = "extends ";
if (String(p_class->extends_file) != "") {
txt += "\"" + p_class->extends_file + "\"";
- if (p_class->extends_class.size())
+ if (p_class->extends_class.size()) {
txt += ".";
+ }
}
for (int i = 0; i < p_class->extends_class.size(); i++) {
-
- if (i != 0)
+ if (i != 0) {
txt += ".";
+ }
txt += p_class->extends_class[i];
}
@@ -75,21 +74,19 @@ static String _parser_extends(const GDScriptParser::ClassNode *p_class) {
}
static String _parser_expr(const GDScriptParser::Node *p_expr) {
-
String txt;
switch (p_expr->type) {
-
case GDScriptParser::Node::TYPE_IDENTIFIER: {
-
const GDScriptParser::IdentifierNode *id_node = static_cast<const GDScriptParser::IdentifierNode *>(p_expr);
txt = id_node->name;
} break;
case GDScriptParser::Node::TYPE_CONSTANT: {
const GDScriptParser::ConstantNode *c_node = static_cast<const GDScriptParser::ConstantNode *>(p_expr);
- if (c_node->value.get_type() == Variant::STRING)
+ if (c_node->value.get_type() == Variant::STRING) {
txt = "\"" + String(c_node->value) + "\"";
- else
+ } else {
txt = c_node->value;
+ }
} break;
case GDScriptParser::Node::TYPE_SELF: {
@@ -99,9 +96,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
const GDScriptParser::ArrayNode *arr_node = static_cast<const GDScriptParser::ArrayNode *>(p_expr);
txt += "[";
for (int i = 0; i < arr_node->elements.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += _parser_expr(arr_node->elements[i]);
}
txt += "]";
@@ -110,9 +107,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
const GDScriptParser::DictionaryNode *dict_node = static_cast<const GDScriptParser::DictionaryNode *>(p_expr);
txt += "{";
for (int i = 0; i < dict_node->elements.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
const GDScriptParser::DictionaryNode::Pair &p = dict_node->elements[i];
txt += _parser_expr(p.key);
@@ -122,37 +119,32 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
txt += "}";
} break;
case GDScriptParser::Node::TYPE_OPERATOR: {
-
const GDScriptParser::OperatorNode *c_node = static_cast<const GDScriptParser::OperatorNode *>(p_expr);
switch (c_node->op) {
-
case GDScriptParser::OperatorNode::OP_PARENT_CALL:
txt += ".";
[[fallthrough]];
case GDScriptParser::OperatorNode::OP_CALL: {
-
ERR_FAIL_COND_V(c_node->arguments.size() < 1, "");
String func_name;
const GDScriptParser::Node *nfunc = c_node->arguments[0];
int arg_ofs = 0;
if (nfunc->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) {
-
const GDScriptParser::BuiltInFunctionNode *bif_node = static_cast<const GDScriptParser::BuiltInFunctionNode *>(nfunc);
func_name = GDScriptFunctions::get_func_name(bif_node->function);
arg_ofs = 1;
} else if (nfunc->type == GDScriptParser::Node::TYPE_TYPE) {
-
const GDScriptParser::TypeNode *t_node = static_cast<const GDScriptParser::TypeNode *>(nfunc);
func_name = Variant::get_type_name(t_node->vtype);
arg_ofs = 1;
} else {
-
ERR_FAIL_COND_V(c_node->arguments.size() < 2, "");
nfunc = c_node->arguments[1];
ERR_FAIL_COND_V(nfunc->type != GDScriptParser::Node::TYPE_IDENTIFIER, "");
- if (c_node->arguments[0]->type != GDScriptParser::Node::TYPE_SELF)
+ if (c_node->arguments[0]->type != GDScriptParser::Node::TYPE_SELF) {
func_name = _parser_expr(c_node->arguments[0]) + ".";
+ }
func_name += _parser_expr(nfunc);
arg_ofs = 2;
@@ -161,10 +153,10 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
txt += func_name + "(";
for (int i = arg_ofs; i < c_node->arguments.size(); i++) {
-
const GDScriptParser::Node *arg = c_node->arguments[i];
- if (i > arg_ofs)
+ if (i > arg_ofs) {
txt += ", ";
+ }
txt += _parser_expr(arg);
}
@@ -172,7 +164,6 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
} break;
case GDScriptParser::OperatorNode::OP_INDEX: {
-
ERR_FAIL_COND_V(c_node->arguments.size() != 2, "");
//index with []
@@ -180,7 +171,6 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
} break;
case GDScriptParser::OperatorNode::OP_INDEX_NAMED: {
-
ERR_FAIL_COND_V(c_node->arguments.size() != 2, "");
txt = _parser_expr(c_node->arguments[0]) + "." + _parser_expr(c_node->arguments[1]);
@@ -296,11 +286,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
} break;
case GDScriptParser::Node::TYPE_NEWLINE: {
-
//skippie
} break;
default: {
-
ERR_FAIL_V_MSG("", "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type));
}
}
@@ -309,20 +297,14 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
}
static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_indent) {
-
for (int i = 0; i < p_block->statements.size(); i++) {
-
const GDScriptParser::Node *statement = p_block->statements[i];
switch (statement->type) {
-
case GDScriptParser::Node::TYPE_CONTROL_FLOW: {
-
const GDScriptParser::ControlFlowNode *cf_node = static_cast<const GDScriptParser::ControlFlowNode *>(statement);
switch (cf_node->cf_type) {
-
case GDScriptParser::ControlFlowNode::CF_IF: {
-
ERR_FAIL_COND(cf_node->arguments.size() != 1);
String txt;
txt += "if ";
@@ -351,7 +333,6 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
} break;
case GDScriptParser::ControlFlowNode::CF_WHILE: {
-
ERR_FAIL_COND(cf_node->arguments.size() != 1);
String txt;
txt += "while ";
@@ -366,25 +347,22 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
// FIXME: Implement
} break;
case GDScriptParser::ControlFlowNode::CF_CONTINUE: {
-
_print_indent(p_indent, "continue");
} break;
case GDScriptParser::ControlFlowNode::CF_BREAK: {
-
_print_indent(p_indent, "break");
} break;
case GDScriptParser::ControlFlowNode::CF_RETURN: {
-
- if (cf_node->arguments.size())
+ if (cf_node->arguments.size()) {
_print_indent(p_indent, "return " + _parser_expr(cf_node->arguments[0]));
- else
+ } else {
_print_indent(p_indent, "return ");
+ }
} break;
}
} break;
case GDScriptParser::Node::TYPE_LOCAL_VAR: {
-
const GDScriptParser::LocalVarNode *lv_node = static_cast<const GDScriptParser::LocalVarNode *>(statement);
_print_indent(p_indent, "var " + String(lv_node->name));
} break;
@@ -397,21 +375,22 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
}
static void _parser_show_function(const GDScriptParser::FunctionNode *p_func, int p_indent, GDScriptParser::BlockNode *p_initializer = nullptr) {
-
String txt;
- if (p_func->_static)
+ if (p_func->_static) {
txt = "static ";
+ }
txt += "func ";
- if (p_func->name == "") // initializer
+ if (p_func->name == "") { // initializer
txt += "[built-in-initializer]";
- else
+ } else {
txt += String(p_func->name);
+ }
txt += "(";
for (int i = 0; i < p_func->arguments.size(); i++) {
-
- if (i != 0)
+ if (i != 0) {
txt += ", ";
+ }
txt += "var " + String(p_func->arguments[i]);
if (i >= (p_func->arguments.size() - p_func->default_values.size())) {
int defarg = i - (p_func->arguments.size() - p_func->default_values.size());
@@ -427,25 +406,24 @@ static void _parser_show_function(const GDScriptParser::FunctionNode *p_func, in
txt += ":";
_print_indent(p_indent, txt);
- if (p_initializer)
+ if (p_initializer) {
_parser_show_block(p_initializer, p_indent + 1);
+ }
_parser_show_block(p_func->body, p_indent + 1);
}
static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_indent, const Vector<String> &p_code) {
-
if (p_indent == 0 && (String(p_class->extends_file) != "" || p_class->extends_class.size())) {
-
_print_indent(p_indent, _parser_extends(p_class));
print_line("\n");
}
for (int i = 0; i < p_class->subclasses.size(); i++) {
-
const GDScriptParser::ClassNode *subclass = p_class->subclasses[i];
String line = "class " + subclass->name;
- if (String(subclass->extends_file) != "" || subclass->extends_class.size())
+ if (String(subclass->extends_file) != "" || subclass->extends_class.size()) {
line += " " + _parser_extends(subclass);
+ }
line += ":";
_print_indent(p_indent, line);
_parser_show_class(subclass, p_indent + 1, p_code);
@@ -458,7 +436,6 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
}
for (int i = 0; i < p_class->variables.size(); i++) {
-
const GDScriptParser::ClassNode::Member &m = p_class->variables[i];
_print_indent(p_indent, "var " + String(m.identifier));
@@ -467,17 +444,16 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
print_line("\n");
for (int i = 0; i < p_class->static_functions.size(); i++) {
-
_parser_show_function(p_class->static_functions[i], p_indent);
print_line("\n");
}
for (int i = 0; i < p_class->functions.size(); i++) {
-
if (String(p_class->functions[i]->name) == "_init") {
_parser_show_function(p_class->functions[i], p_indent, p_class->initializer);
- } else
+ } else {
_parser_show_function(p_class->functions[i], p_indent);
+ }
print_line("\n");
}
//_parser_show_function(p_class->initializer,p_indent);
@@ -485,11 +461,9 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
}
static String _disassemble_addr(const Ref<GDScript> &p_script, const GDScriptFunction &func, int p_addr) {
-
int addr = p_addr & GDScriptFunction::ADDR_MASK;
switch (p_addr >> GDScriptFunction::ADDR_BITS) {
-
case GDScriptFunction::ADDR_TYPE_SELF: {
return "self";
} break;
@@ -497,33 +471,28 @@ static String _disassemble_addr(const Ref<GDScript> &p_script, const GDScriptFun
return "class";
} break;
case GDScriptFunction::ADDR_TYPE_MEMBER: {
-
return "member(" + p_script->debug_get_member_by_index(addr) + ")";
} break;
case GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT: {
-
return "class_const(" + func.get_global_name(addr) + ")";
} break;
case GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT: {
-
Variant v = func.get_constant(addr);
String txt;
- if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH)
+ if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH) {
txt = "\"" + String(v) + "\"";
- else
+ } else {
txt = v;
+ }
return "const(" + txt + ")";
} break;
case GDScriptFunction::ADDR_TYPE_STACK: {
-
return "stack(" + itos(addr) + ")";
} break;
case GDScriptFunction::ADDR_TYPE_STACK_VARIABLE: {
-
return "var_stack(" + itos(addr) + ")";
} break;
case GDScriptFunction::ADDR_TYPE_GLOBAL: {
-
return "global(" + func.get_global_name(addr) + ")";
} break;
case GDScriptFunction::ADDR_TYPE_NIL: {
@@ -535,11 +504,9 @@ static String _disassemble_addr(const Ref<GDScript> &p_script, const GDScriptFun
}
static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String> &p_code) {
-
const Map<StringName, GDScriptFunction *> &mf = p_class->debug_get_member_functions();
for (const Map<StringName, GDScriptFunction *>::Element *E = mf.front(); E; E = E->next()) {
-
const GDScriptFunction &func = *E->get();
const int *code = func.get_code();
int codelen = func.get_code_size();
@@ -547,9 +514,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
if (func.get_default_argument_count()) {
defargs = "defarg at: ";
for (int i = 0; i < func.get_default_argument_count(); i++) {
-
- if (i > 0)
+ if (i > 0) {
defargs += ",";
+ }
defargs += itos(func.get_default_argument_addr(i));
}
defargs += " ";
@@ -559,14 +526,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
#define DADDR(m_ip) (_disassemble_addr(p_class, func, code[ip + m_ip]))
for (int ip = 0; ip < codelen;) {
-
int incr = 0;
String txt = itos(ip) + " ";
switch (code[ip]) {
-
case GDScriptFunction::OPCODE_OPERATOR: {
-
int op = code[ip + 1];
txt += " op ";
@@ -581,7 +545,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_SET: {
-
txt += "set ";
txt += DADDR(1);
txt += "[";
@@ -592,7 +555,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_GET: {
-
txt += " get ";
txt += DADDR(3);
txt += "=";
@@ -604,7 +566,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_SET_NAMED: {
-
txt += " set_named ";
txt += DADDR(1);
txt += "[\"";
@@ -615,7 +576,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_GET_NAMED: {
-
txt += " get_named ";
txt += DADDR(3);
txt += "=";
@@ -627,7 +587,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_SET_MEMBER: {
-
txt += " set_member ";
txt += "[\"";
txt += func.get_global_name(code[ip + 1]);
@@ -637,7 +596,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_GET_MEMBER: {
-
txt += " get_member ";
txt += DADDR(2);
txt += "=";
@@ -648,7 +606,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_ASSIGN: {
-
txt += " assign ";
txt += DADDR(1);
txt += "=";
@@ -657,7 +614,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_ASSIGN_TRUE: {
-
txt += " assign ";
txt += DADDR(1);
txt += "= true";
@@ -665,7 +621,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_ASSIGN_FALSE: {
-
txt += " assign ";
txt += DADDR(1);
txt += "= false";
@@ -673,7 +628,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_ASSIGN_TYPED_BUILTIN: {
-
txt += " assign typed builtin (";
txt += Variant::get_type_name((Variant::Type)code[ip + 1]);
txt += ") ";
@@ -697,7 +651,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_CAST_TO_SCRIPT: {
-
txt += " cast ";
txt += DADDR(3);
txt += "=";
@@ -708,7 +661,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_CONSTRUCT: {
-
Variant::Type t = Variant::Type(code[ip + 1]);
int argc = code[ip + 2];
@@ -718,9 +670,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += Variant::get_type_name(t) + "(";
for (int i = 0; i < argc; i++) {
-
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(i + 3);
}
txt += ")";
@@ -729,15 +681,15 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_CONSTRUCT_ARRAY: {
-
int argc = code[ip + 1];
txt += " make_array ";
txt += DADDR(2 + argc);
txt += " = [ ";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(2 + i);
}
@@ -747,15 +699,15 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY: {
-
int argc = code[ip + 1];
txt += " make_dict ";
txt += DADDR(2 + argc * 2);
txt += " = { ";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(2 + i * 2 + 0);
txt += ":";
txt += DADDR(2 + i * 2 + 1);
@@ -769,13 +721,13 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
case GDScriptFunction::OPCODE_CALL:
case GDScriptFunction::OPCODE_CALL_RETURN: {
-
bool ret = code[ip] == GDScriptFunction::OPCODE_CALL_RETURN;
- if (ret)
+ if (ret) {
txt += " call-ret ";
- else
+ } else {
txt += " call ";
+ }
int argc = code[ip + 1];
if (ret) {
@@ -787,8 +739,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(4 + i);
}
txt += ")";
@@ -797,7 +750,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_CALL_BUILT_IN: {
-
txt += " call-built-in ";
int argc = code[ip + 2];
@@ -807,8 +759,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(3 + i);
}
txt += ")";
@@ -817,7 +770,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_CALL_SELF_BASE: {
-
txt += " call-self-base ";
int argc = code[ip + 2];
@@ -827,8 +779,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(3 + i);
}
txt += ")";
@@ -837,13 +790,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_YIELD: {
-
txt += " yield ";
incr = 1;
} break;
case GDScriptFunction::OPCODE_YIELD_SIGNAL: {
-
txt += " yield_signal ";
txt += DADDR(1);
txt += ",";
@@ -851,13 +802,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
incr = 3;
} break;
case GDScriptFunction::OPCODE_YIELD_RESUME: {
-
txt += " yield resume: ";
txt += DADDR(1);
incr = 2;
} break;
case GDScriptFunction::OPCODE_JUMP: {
-
txt += " jump ";
txt += itos(code[ip + 1]);
@@ -865,7 +814,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_JUMP_IF: {
-
txt += " jump-if ";
txt += DADDR(1);
txt += " to ";
@@ -874,7 +822,6 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
incr = 3;
} break;
case GDScriptFunction::OPCODE_JUMP_IF_NOT: {
-
txt += " jump-if-not ";
txt += DADDR(1);
txt += " to ";
@@ -883,12 +830,10 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
incr = 3;
} break;
case GDScriptFunction::OPCODE_JUMP_TO_DEF_ARGUMENT: {
-
txt += " jump-to-default-argument ";
incr = 1;
} break;
case GDScriptFunction::OPCODE_RETURN: {
-
txt += " return ";
txt += DADDR(1);
@@ -896,33 +841,29 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_ITERATE_BEGIN: {
-
txt += " for-init " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]);
incr += 5;
} break;
case GDScriptFunction::OPCODE_ITERATE: {
-
txt += " for-loop " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]);
incr += 5;
} break;
case GDScriptFunction::OPCODE_LINE: {
-
int line = code[ip + 1] - 1;
- if (line >= 0 && line < p_code.size())
+ if (line >= 0 && line < p_code.size()) {
txt = "\n" + itos(line + 1) + ": " + p_code[line] + "\n";
- else
+ } else {
txt = "";
+ }
incr += 2;
} break;
case GDScriptFunction::OPCODE_END: {
-
txt += " end";
incr += 1;
} break;
case GDScriptFunction::OPCODE_ASSERT: {
-
txt += " assert ";
txt += DADDR(1);
incr += 2;
@@ -931,19 +872,18 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
}
if (incr == 0) {
-
ERR_BREAK_MSG(true, "Unhandled opcode: " + itos(code[ip]));
}
ip += incr;
- if (txt != "")
+ if (txt != "") {
print_line(txt);
+ }
}
}
}
MainLoop *test(TestType p_type) {
-
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
if (cmdlargs.empty()) {
@@ -972,40 +912,38 @@ MainLoop *test(TestType p_type) {
int last = 0;
for (int i = 0; i <= code.length(); i++) {
-
if (code[i] == '\n' || code[i] == 0) {
-
lines.push_back(code.substr(last, i - last));
last = i + 1;
}
}
if (p_type == TEST_TOKENIZER) {
-
GDScriptTokenizerText tk;
tk.set_code(code);
int line = -1;
while (tk.get_token() != GDScriptTokenizer::TK_EOF) {
-
String text;
- if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER)
+ if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER) {
text = "'" + tk.get_token_identifier() + "' (identifier)";
- else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
+ } else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
const Variant &c = tk.get_token_constant();
- if (c.get_type() == Variant::STRING)
+ if (c.get_type() == Variant::STRING) {
text = "\"" + String(c) + "\"";
- else
+ } else {
text = c;
+ }
text = text + " (" + Variant::get_type_name(c.get_type()) + " constant)";
- } else if (tk.get_token() == GDScriptTokenizer::TK_ERROR)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_ERROR) {
text = "ERROR: " + tk.get_token_error();
- else if (tk.get_token() == GDScriptTokenizer::TK_NEWLINE)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_NEWLINE) {
text = "newline (" + itos(tk.get_token_line()) + ") + indent: " + itos(tk.get_token_line_indent());
- else if (tk.get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) {
text = "'" + String(GDScriptFunctions::get_func_name(tk.get_token_built_in_func())) + "' (built-in function)";
- else
+ } else {
text = tk.get_token_name(tk.get_token());
+ }
if (tk.get_token_line() != line) {
int from = line + 1;
@@ -1024,7 +962,6 @@ MainLoop *test(TestType p_type) {
}
if (p_type == TEST_PARSER) {
-
GDScriptParser parser;
Error err = parser.parse(code);
if (err) {
@@ -1041,7 +978,6 @@ MainLoop *test(TestType p_type) {
}
if (p_type == TEST_COMPILER) {
-
GDScriptParser parser;
Error err = parser.parse(code);
@@ -1057,7 +993,6 @@ MainLoop *test(TestType p_type) {
GDScriptCompiler gdc;
err = gdc.compile(&parser, gds.ptr());
if (err) {
-
print_line("Compile Error:\n" + itos(gdc.get_error_line()) + ":" + itos(gdc.get_error_column()) + ":" + gdc.get_error());
return nullptr;
}
@@ -1065,7 +1000,6 @@ MainLoop *test(TestType p_type) {
Ref<GDScript> current = gds;
while (current.is_valid()) {
-
print_line("** CLASS **");
_disassemble_class(current, lines);
@@ -1073,7 +1007,6 @@ MainLoop *test(TestType p_type) {
}
} else if (p_type == TEST_BYTECODE) {
-
Vector<uint8_t> buf2 = GDScriptTokenizerBuffer::parse_code_string(code);
String dst = test.get_basename() + ".gdc";
FileAccess *fw = FileAccess::open(dst, FileAccess::WRITE);
@@ -1085,6 +1018,7 @@ MainLoop *test(TestType p_type) {
return nullptr;
}
+
} // namespace TestGDScript
#else
@@ -1095,6 +1029,7 @@ MainLoop *test(TestType p_type) {
ERR_PRINT("The GDScript module is disabled, therefore GDScript tests cannot be used.");
return nullptr;
}
+
} // namespace TestGDScript
#endif
diff --git a/main/tests/test_gui.cpp b/main/tests/test_gui.cpp
index c5c8917a51..d46a13d2c0 100644
--- a/main/tests/test_gui.cpp
+++ b/main/tests/test_gui.cpp
@@ -59,14 +59,11 @@
namespace TestGUI {
class TestMainLoop : public SceneTree {
-
public:
virtual void request_quit() {
-
quit();
}
virtual void init() {
-
SceneTree::init();
Panel *frame = memnew(Panel);
@@ -266,9 +263,9 @@ public:
};
MainLoop *test() {
-
return memnew(TestMainLoop);
}
+
} // namespace TestGUI
#endif
diff --git a/main/tests/test_main.cpp b/main/tests/test_main.cpp
index 922a55b88e..eb60372e6c 100644
--- a/main/tests/test_main.cpp
+++ b/main/tests/test_main.cpp
@@ -47,7 +47,6 @@
#include "test_string.h"
const char **tests_get_names() {
-
static const char *test_names[] = {
"string",
"math",
@@ -70,76 +69,61 @@ const char **tests_get_names() {
}
MainLoop *test_main(String p_test, const List<String> &p_args) {
-
if (p_test == "string") {
-
return TestString::test();
}
if (p_test == "math") {
-
return TestMath::test();
}
if (p_test == "physics_2d") {
-
return TestPhysics2D::test();
}
if (p_test == "physics_3d") {
-
return TestPhysics3D::test();
}
if (p_test == "render") {
-
return TestRender::test();
}
if (p_test == "oa_hash_map") {
-
return TestOAHashMap::test();
}
#ifndef _3D_DISABLED
if (p_test == "gui") {
-
return TestGUI::test();
}
#endif
if (p_test == "shaderlang") {
-
return TestShaderLang::test();
}
if (p_test == "gd_tokenizer") {
-
return TestGDScript::test(TestGDScript::TEST_TOKENIZER);
}
if (p_test == "gd_parser") {
-
return TestGDScript::test(TestGDScript::TEST_PARSER);
}
if (p_test == "gd_compiler") {
-
return TestGDScript::test(TestGDScript::TEST_COMPILER);
}
if (p_test == "gd_bytecode") {
-
return TestGDScript::test(TestGDScript::TEST_BYTECODE);
}
if (p_test == "ordered_hash_map") {
-
return TestOrderedHashMap::test();
}
if (p_test == "astar") {
-
return TestAStar::test();
}
@@ -150,7 +134,6 @@ MainLoop *test_main(String p_test, const List<String> &p_args) {
#else
const char **tests_get_names() {
-
static const char *test_names[] = {
nullptr
};
@@ -159,7 +142,6 @@ const char **tests_get_names() {
}
MainLoop *test_main(String p_test, const List<String> &p_args) {
-
return nullptr;
}
diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp
index fbd1aa275a..11aa164709 100644
--- a/main/tests/test_math.cpp
+++ b/main/tests/test_math.cpp
@@ -50,7 +50,6 @@
namespace TestMath {
class GetClassAndNamespace {
-
String code;
int idx;
int line;
@@ -77,12 +76,9 @@ class GetClassAndNamespace {
};
Token get_token() {
-
while (true) {
switch (code[idx]) {
-
case '\n': {
-
line++;
idx++;
break;
@@ -92,37 +88,30 @@ class GetClassAndNamespace {
} break;
case '{': {
-
idx++;
return TK_CURLY_BRACKET_OPEN;
};
case '}': {
-
idx++;
return TK_CURLY_BRACKET_CLOSE;
};
case '[': {
-
idx++;
return TK_BRACKET_OPEN;
};
case ']': {
-
idx++;
return TK_BRACKET_CLOSE;
};
case ':': {
-
idx++;
return TK_COLON;
};
case ',': {
-
idx++;
return TK_COMMA;
};
case '.': {
-
idx++;
return TK_PERIOD;
};
@@ -134,7 +123,6 @@ class GetClassAndNamespace {
continue;
} break;
case '/': {
-
switch (code[idx + 1]) {
case '*': { // block comment
@@ -145,7 +133,6 @@ class GetClassAndNamespace {
error = true;
return TK_ERROR;
} else if (code[idx] == '*' && code[idx + 1] == '/') {
-
idx += 2;
break;
} else if (code[idx] == '\n') {
@@ -174,7 +161,6 @@ class GetClassAndNamespace {
} break;
case '\'':
case '"': {
-
CharType begin_str = code[idx];
idx++;
String tk_string = String();
@@ -198,7 +184,6 @@ class GetClassAndNamespace {
CharType res = 0;
switch (next) {
-
case 'b':
res = 8;
break;
@@ -228,8 +213,9 @@ class GetClassAndNamespace {
tk_string += res;
} else {
- if (code[idx] == '\n')
+ if (code[idx] == '\n') {
line++;
+ }
tk_string += code[idx];
}
idx++;
@@ -241,7 +227,6 @@ class GetClassAndNamespace {
} break;
default: {
-
if (code[idx] <= 32) {
idx++;
break;
@@ -262,11 +247,9 @@ class GetClassAndNamespace {
return TK_NUMBER;
} else if ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
-
String id;
while ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
-
id += code[idx];
idx++;
}
@@ -285,7 +268,6 @@ class GetClassAndNamespace {
public:
Error parse(const String &p_code, const String &p_known_class_name = String()) {
-
code = p_code;
idx = 0;
line = 0;
@@ -301,7 +283,6 @@ public:
int curly_stack = 0;
while (!error || tk != TK_EOF) {
-
if (tk == TK_BRACKET_OPEN) {
tk = get_token();
if (tk == TK_IDENTIFIER && String(value) == "ScriptClass") {
@@ -358,8 +339,9 @@ public:
tk = get_token();
}
- if (error)
+ if (error) {
return ERR_PARSE_ERROR;
+ }
return OK;
}
@@ -374,7 +356,6 @@ public:
};
void test_vec(Plane p_vec) {
-
CameraMatrix cm;
cm.set_perspective(45, 1, 0, 100);
Plane v0 = cm.xform4(p_vec);
@@ -413,7 +394,6 @@ uint32_t ihash3(uint32_t a) {
}
MainLoop *test() {
-
{
Vector<Vector3> points;
points.push_back(Vector3(0, 0, 0));
@@ -564,26 +544,22 @@ MainLoop *test() {
}
{
-
Vector<int> hashes;
List<StringName> tl;
ClassDB::get_class_list(&tl);
for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
-
Vector<uint8_t> m5b = E->get().operator String().md5_buffer();
hashes.push_back(hashes.size());
}
for (int i = nearest_shift(hashes.size()); i < 20; i++) {
-
bool success = true;
for (int s = 0; s < 10000; s++) {
Set<uint32_t> existing;
success = true;
for (int j = 0; j < hashes.size(); j++) {
-
uint32_t eh = ihash2(ihash3(hashes[j] + ihash(s) + s)) & ((1 << i) - 1);
if (existing.has(eh)) {
success = false;
@@ -597,8 +573,9 @@ MainLoop *test() {
break;
}
}
- if (success)
+ if (success) {
break;
+ }
}
print_line("DONE");
@@ -721,4 +698,5 @@ MainLoop *test() {
return nullptr;
}
+
} // namespace TestMath
diff --git a/main/tests/test_oa_hash_map.cpp b/main/tests/test_oa_hash_map.cpp
index cffec7fa77..cae143bb5d 100644
--- a/main/tests/test_oa_hash_map.cpp
+++ b/main/tests/test_oa_hash_map.cpp
@@ -36,7 +36,6 @@
namespace TestOAHashMap {
MainLoop *test() {
-
OS::get_singleton()->print("\n\n\nHello from test\n");
// test element tracking.
@@ -71,8 +70,9 @@ MainLoop *test() {
uint32_t num_elems = 0;
for (int i = 0; i < 500; i++) {
int tmp;
- if (map.lookup(i, tmp) && tmp == i * 2)
+ if (map.lookup(i, tmp) && tmp == i * 2) {
num_elems++;
+ }
}
OS::get_singleton()->print("elements %d == %d.\n", map.get_num_elements(), num_elems);
@@ -105,8 +105,9 @@ MainLoop *test() {
keys[i] = Math::rand();
map.set(keys[i], dummy);
- if (!map.lookup(keys[i], dummy))
+ if (!map.lookup(keys[i], dummy)) {
OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i]));
+ }
}
// check whether the keys are still present
@@ -122,7 +123,6 @@ MainLoop *test() {
// regression test / test for issue related to #31402
{
-
OS::get_singleton()->print("test for issue #31402 started...\n");
const int num_test_values = 12;
@@ -154,4 +154,5 @@ MainLoop *test() {
return nullptr;
}
+
} // namespace TestOAHashMap
diff --git a/main/tests/test_ordered_hash_map.cpp b/main/tests/test_ordered_hash_map.cpp
index e909626243..d18a3784be 100644
--- a/main/tests/test_ordered_hash_map.cpp
+++ b/main/tests/test_ordered_hash_map.cpp
@@ -146,16 +146,17 @@ TestFunc test_funcs[] = {
};
MainLoop *test() {
-
int count = 0;
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
@@ -170,4 +171,5 @@ MainLoop *test() {
return nullptr;
}
+
} // namespace TestOrderedHashMap
diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp
index 6feff3b0a9..6cb9bf7b60 100644
--- a/main/tests/test_physics_2d.cpp
+++ b/main/tests/test_physics_2d.cpp
@@ -44,7 +44,6 @@ static const unsigned char convex_png[] = {
};
class TestPhysics2DMainLoop : public MainLoop {
-
GDCLASS(TestPhysics2DMainLoop, MainLoop);
RID circle_img;
@@ -58,7 +57,6 @@ class TestPhysics2DMainLoop : public MainLoop {
Vector2 ray_from, ray_to;
struct BodyShapeData {
-
RID image;
RID shape;
};
@@ -72,13 +70,10 @@ class TestPhysics2DMainLoop : public MainLoop {
// SEGMENT
{
-
Vector<uint8_t> pixels;
pixels.resize(32 * 2 * 2);
for (int i = 0; i < 2; i++) {
-
for (int j = 0; j < 32; j++) {
-
pixels.set(i * 32 * 2 + j * 2 + 0, (j == 0) ? 255 : 0);
pixels.set(i * 32 * 2 + j * 2 + 1, 255);
}
@@ -97,13 +92,10 @@ class TestPhysics2DMainLoop : public MainLoop {
// CIRCLE
{
-
Vector<uint8_t> pixels;
pixels.resize(32 * 32 * 2);
for (int i = 0; i < 32; i++) {
-
for (int j = 0; j < 32; j++) {
-
bool black = Vector2(i - 16, j - 16).length_squared() < 16 * 16;
pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16) ? 255 : 0);
@@ -124,13 +116,10 @@ class TestPhysics2DMainLoop : public MainLoop {
// BOX
{
-
Vector<uint8_t> pixels;
pixels.resize(32 * 32 * 2);
for (int i = 0; i < 32; i++) {
-
for (int j = 0; j < 32; j++) {
-
bool black = i > 0 && i < 31 && j > 0 && j < 31;
pixels.set(i * 32 * 2 + j * 2 + 0, black ? 0 : 255);
@@ -151,13 +140,10 @@ class TestPhysics2DMainLoop : public MainLoop {
// CAPSULE
{
-
Vector<uint8_t> pixels;
pixels.resize(32 * 64 * 2);
for (int i = 0; i < 64; i++) {
-
for (int j = 0; j < 32; j++) {
-
int si = i > 48 ? i - 32 : (i < 16 ? i : 16);
bool black = Vector2(si - 16, j - 16).length_squared() < 16 * 16;
@@ -179,7 +165,6 @@ class TestPhysics2DMainLoop : public MainLoop {
// CONVEX
{
-
Ref<Image> image = memnew(Image(convex_png));
body_shape_data[PhysicsServer2D::SHAPE_CONVEX_POLYGON].image = vs->texture_2d_create(image);
@@ -202,7 +187,6 @@ class TestPhysics2DMainLoop : public MainLoop {
}
void _do_ray_query() {
-
/*
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
ps->query_intersection_segment(ray_query,ray_from,ray_to);
@@ -211,13 +195,10 @@ class TestPhysics2DMainLoop : public MainLoop {
protected:
void input_event(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
-
if (mb->is_pressed()) {
-
Point2 p(mb->get_position().x, mb->get_position().y);
if (mb->get_button_index() == 1) {
@@ -233,7 +214,6 @@ protected:
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
Point2 p = mm->get_position();
if (mm->get_button_mask() & BUTTON_MASK_LEFT) {
@@ -247,7 +227,6 @@ protected:
}
RID _add_body(PhysicsServer2D::ShapeType p_shape, const Transform2D &p_xform) {
-
RenderingServer *vs = RenderingServer::get_singleton();
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
@@ -272,7 +251,6 @@ protected:
}
void _add_plane(const Vector2 &p_normal, real_t p_d) {
-
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
Array arr;
@@ -289,7 +267,6 @@ protected:
}
void _add_concave(const Vector<Vector2> &p_points, const Transform2D &p_xform = Transform2D()) {
-
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
RenderingServer *vs = RenderingServer::get_singleton();
@@ -315,7 +292,6 @@ protected:
}
void _ray_query_callback(const RID &p_rid, ObjectID p_id, int p_shape, const Vector2 &p_point, const Vector2 &p_normal) {
-
Vector2 ray_end;
if (p_rid.is_valid()) {
@@ -328,19 +304,18 @@ protected:
vs->canvas_item_clear(ray);
vs->canvas_item_add_line(ray, ray_from, ray_end, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
- if (p_rid.is_valid())
+ if (p_rid.is_valid()) {
vs->canvas_item_add_line(ray, ray_end, ray_end + p_normal * 20, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
+ }
}
static void _bind_methods() {
-
ClassDB::bind_method(D_METHOD("_body_moved"), &TestPhysics2DMainLoop::_body_moved);
ClassDB::bind_method(D_METHOD("_ray_query_callback"), &TestPhysics2DMainLoop::_ray_query_callback);
}
public:
virtual void init() {
-
RenderingServer *vs = RenderingServer::get_singleton();
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
@@ -351,7 +326,6 @@ public:
ps->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY, 98);
{
-
RID vp = vs->viewport_create();
canvas = vs->canvas_create();
@@ -377,7 +351,6 @@ public:
_create_body_shape_data();
for (int i = 0; i < 32; i++) {
-
PhysicsServer2D::ShapeType types[4] = {
PhysicsServer2D::SHAPE_CIRCLE,
PhysicsServer2D::SHAPE_CAPSULE,
@@ -402,7 +375,6 @@ public:
Vector<Point2> parr;
for (int i = 0; i < 30; i++) {
-
Point2 p(i * 60, Math::randf() * 70 + 340);
if (i > 0) {
parr.push_back(prev);
@@ -418,7 +390,6 @@ public:
}
virtual bool idle(float p_time) {
-
return false;
}
virtual void finish() {
@@ -430,7 +401,7 @@ public:
namespace TestPhysics2D {
MainLoop *test() {
-
return memnew(TestPhysics2DMainLoop);
}
+
} // namespace TestPhysics2D
diff --git a/main/tests/test_physics_3d.cpp b/main/tests/test_physics_3d.cpp
index 2d208ee317..fe54ece98e 100644
--- a/main/tests/test_physics_3d.cpp
+++ b/main/tests/test_physics_3d.cpp
@@ -41,7 +41,6 @@
#include "servers/rendering_server.h"
class TestPhysics3DMainLoop : public MainLoop {
-
GDCLASS(TestPhysics3DMainLoop, MainLoop);
enum {
@@ -69,7 +68,6 @@ class TestPhysics3DMainLoop : public MainLoop {
Map<PhysicsServer3D::ShapeType, RID> type_mesh_map;
void body_changed_transform(Object *p_state, RID p_visual_instance) {
-
PhysicsDirectBodyState3D *state = (PhysicsDirectBodyState3D *)p_state;
RenderingServer *vs = RenderingServer::get_singleton();
Transform t = state->get_transform();
@@ -80,12 +78,10 @@ class TestPhysics3DMainLoop : public MainLoop {
protected:
static void _bind_methods() {
-
ClassDB::bind_method("body_changed_transform", &TestPhysics3DMainLoop::body_changed_transform);
}
RID create_body(PhysicsServer3D::ShapeType p_shape, PhysicsServer3D::BodyMode p_body, const Transform p_location, bool p_active_default = true, const Transform &p_shape_xform = Transform()) {
-
RenderingServer *vs = RenderingServer::get_singleton();
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
@@ -101,14 +97,12 @@ protected:
bodies.push_back(body);
if (p_body == PhysicsServer3D::BODY_MODE_STATIC) {
-
vs->instance_set_transform(mesh_instance, p_location);
}
return body;
}
RID create_static_plane(const Plane &p_plane) {
-
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
RID world_margin_shape = ps->shape_create(PhysicsServer3D::SHAPE_PLANE);
@@ -122,7 +116,6 @@ protected:
}
void configure_body(RID p_body, float p_mass, float p_friction, float p_bounce) {
-
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_MASS, p_mass);
ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_FRICTION, p_friction);
@@ -130,7 +123,6 @@ protected:
}
void init_shapes() {
-
RenderingServer *vs = RenderingServer::get_singleton();
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
@@ -188,7 +180,6 @@ protected:
}
void make_trimesh(Vector<Vector3> p_faces, const Transform &p_xform = Transform()) {
-
RenderingServer *vs = RenderingServer::get_singleton();
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
RID trimesh_shape = ps->shape_create(PhysicsServer3D::SHAPE_CONCAVE_POLYGON);
@@ -196,7 +187,6 @@ protected:
p_faces = ps->shape_get_data(trimesh_shape); // optimized one
Vector<Vector3> normals; // for drawing
for (int i = 0; i < p_faces.size() / 3; i++) {
-
Plane p(p_faces[i * 3 + 0], p_faces[i * 3 + 1], p_faces[i * 3 + 2]);
normals.push_back(p.normal);
normals.push_back(p.normal);
@@ -222,17 +212,14 @@ protected:
}
void make_grid(int p_width, int p_height, float p_cellsize, float p_cellheight, const Transform &p_xform = Transform()) {
-
Vector<Vector<float>> grid;
grid.resize(p_width);
for (int i = 0; i < p_width; i++) {
-
grid.write[i].resize(p_height);
for (int j = 0; j < p_height; j++) {
-
grid.write[i].write[j] = 1.0 + Math::random(-p_cellheight, p_cellheight);
}
}
@@ -240,9 +227,7 @@ protected:
Vector<Vector3> faces;
for (int i = 1; i < p_width; i++) {
-
for (int j = 1; j < p_height; j++) {
-
#define MAKE_VERTEX(m_x, m_z) \
faces.push_back(Vector3((m_x - p_width / 2) * p_cellsize, grid[m_x][m_z], (m_z - p_height / 2) * p_cellsize))
@@ -261,21 +246,17 @@ protected:
public:
virtual void input_event(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && mm->get_button_mask() & 4) {
-
ofs_y -= mm->get_relative().y / 200.0;
ofs_x += mm->get_relative().x / 200.0;
}
if (mm.is_valid() && mm->get_button_mask() & 1) {
-
float y = -mm->get_relative().y / 20.0;
float x = mm->get_relative().x / 20.0;
if (mover.is_valid()) {
-
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
Transform t = ps->body_get_state(mover, PhysicsServer3D::BODY_STATE_TRANSFORM);
t.origin += Vector3(x, y, 0);
@@ -286,11 +267,9 @@ public:
}
virtual void request_quit() {
-
quit = true;
}
virtual void init() {
-
ofs_x = ofs_y = 0;
init_shapes();
@@ -332,7 +311,6 @@ public:
quit = false;
}
virtual bool iteration(float p_time) {
-
if (mover.is_valid()) {
static float joy_speed = 10;
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
@@ -360,7 +338,6 @@ public:
}
void test_character() {
-
RenderingServer *vs = RenderingServer::get_singleton();
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
@@ -393,9 +370,7 @@ public:
}
void test_fall() {
-
for (int i = 0; i < 35; i++) {
-
static const PhysicsServer3D::ShapeType shape_idx[] = {
PhysicsServer3D::SHAPE_CAPSULE,
PhysicsServer3D::SHAPE_BOX,
@@ -417,7 +392,6 @@ public:
}
void test_activate() {
-
create_body(PhysicsServer3D::SHAPE_BOX, PhysicsServer3D::BODY_MODE_RIGID, Transform(Basis(), Vector3(0, 2, 0)), true);
create_static_plane(Plane(Vector3(0, 1, 0), -1));
}
@@ -433,7 +407,7 @@ public:
namespace TestPhysics3D {
MainLoop *test() {
-
return memnew(TestPhysics3DMainLoop);
}
+
} // namespace TestPhysics3D
diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp
index bcfcf61e25..afc09374b9 100644
--- a/main/tests/test_render.cpp
+++ b/main/tests/test_render.cpp
@@ -44,7 +44,6 @@
namespace TestRender {
class TestMainLoop : public MainLoop {
-
RID test_cube;
RID instance;
RID camera;
@@ -53,7 +52,6 @@ class TestMainLoop : public MainLoop {
RID scenario;
struct InstanceInfo {
-
RID instance;
Transform base;
Vector3 rot_axis;
@@ -67,13 +65,12 @@ class TestMainLoop : public MainLoop {
protected:
public:
virtual void input_event(const Ref<InputEvent> &p_event) {
-
- if (p_event->is_pressed())
+ if (p_event->is_pressed()) {
quit = true;
+ }
}
virtual void init() {
-
print_line("INITIALIZING TEST RENDER");
RenderingServer *vs = RenderingServer::get_singleton();
test_cube = vs->get_test_cube();
@@ -144,7 +141,6 @@ public:
};
for (int i = 0; i < object_count; i++) {
-
InstanceInfo ii;
ii.instance = vs->instance_create2(test_cube, scenario);
@@ -205,7 +201,6 @@ public:
quit = false;
}
virtual bool iteration(float p_time) {
-
RenderingServer *vs = RenderingServer::get_singleton();
//Transform t;
//t.rotate(Vector3(0, 1, 0), ofs);
@@ -217,7 +212,6 @@ public:
//return quit;
for (List<InstanceInfo>::Element *E = instances.front(); E; E = E->next()) {
-
Transform pre(Basis(E->get().rot_axis, ofs), Vector3());
vs->instance_set_transform(E->get().instance, pre * E->get().base);
/*
@@ -240,7 +234,7 @@ public:
};
MainLoop *test() {
-
return memnew(TestMainLoop);
}
+
} // namespace TestRender
diff --git a/main/tests/test_shader_lang.cpp b/main/tests/test_shader_lang.cpp
index abcf30c97f..34ee3e3210 100644
--- a/main/tests/test_shader_lang.cpp
+++ b/main/tests/test_shader_lang.cpp
@@ -44,7 +44,6 @@ typedef ShaderLanguage SL;
namespace TestShaderLang {
static String _mktab(int p_level) {
-
String tb;
for (int i = 0; i < p_level; i++) {
tb += "\t";
@@ -54,12 +53,10 @@ static String _mktab(int p_level) {
}
static String _typestr(SL::DataType p_type) {
-
return ShaderLanguage::get_datatype_name(p_type);
}
static String _prestr(SL::DataPrecision p_pres) {
-
switch (p_pres) {
case SL::PRECISION_LOWP:
return "lowp ";
@@ -74,12 +71,10 @@ static String _prestr(SL::DataPrecision p_pres) {
}
static String _opstr(SL::Operator p_op) {
-
return ShaderLanguage::get_operator_text(p_op);
}
static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
-
switch (p_type) {
case SL::TYPE_BOOL:
return p_values[0].boolean ? "true" : "false";
@@ -119,17 +114,13 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
}
static String dump_node_code(SL::Node *p_node, int p_level) {
-
String code;
switch (p_node->type) {
-
case SL::Node::TYPE_SHADER: {
-
SL::ShaderNode *pnode = (SL::ShaderNode *)p_node;
for (Map<StringName, SL::ShaderNode::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) {
-
String ucode = "uniform ";
ucode += _prestr(E->get().precision);
ucode += _typestr(E->get().type);
@@ -149,14 +140,14 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
"white"
};
- if (E->get().hint)
+ if (E->get().hint) {
ucode += " : " + String(hint_name[E->get().hint]);
+ }
code += ucode + "\n";
}
for (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) {
-
String vcode = "varying ";
vcode += _prestr(E->get().precision);
vcode += _typestr(E->get().type);
@@ -165,15 +156,14 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
code += vcode + "\n";
}
for (int i = 0; i < pnode->functions.size(); i++) {
-
SL::FunctionNode *fnode = pnode->functions[i].function;
String header;
header = _typestr(fnode->return_type) + " " + fnode->name + "(";
for (int j = 0; j < fnode->arguments.size(); j++) {
-
- if (j > 0)
+ if (j > 0) {
header += ", ";
+ }
header += _prestr(fnode->arguments[j].precision) + _typestr(fnode->arguments[j].type) + " " + fnode->arguments[j].name;
}
@@ -185,10 +175,8 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
//code+=dump_node_code(pnode->body,p_level);
} break;
case SL::Node::TYPE_STRUCT: {
-
} break;
case SL::Node::TYPE_FUNCTION: {
-
} break;
case SL::Node::TYPE_BLOCK: {
SL::BlockNode *bnode = (SL::BlockNode *)p_node;
@@ -196,12 +184,10 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
//variables
code += _mktab(p_level - 1) + "{\n";
for (Map<StringName, SL::BlockNode::Variable>::Element *E = bnode->variables.front(); E; E = E->next()) {
-
code += _mktab(p_level) + _prestr(E->get().precision) + _typestr(E->get().type) + " " + E->key() + ";\n";
}
for (int i = 0; i < bnode->statements.size(); i++) {
-
String scode = dump_node_code(bnode->statements[i], p_level);
if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) {
@@ -240,7 +226,6 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
switch (onode->op) {
-
case SL::OP_ASSIGN:
case SL::OP_ASSIGN_ADD:
case SL::OP_ASSIGN_SUB:
@@ -269,14 +254,14 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
case SL::OP_CONSTRUCT:
code = dump_node_code(onode->arguments[0], p_level) + "(";
for (int i = 1; i < onode->arguments.size(); i++) {
- if (i > 1)
+ if (i > 1) {
code += ", ";
+ }
code += dump_node_code(onode->arguments[i], p_level);
}
code += ")";
break;
default: {
-
code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
break;
}
@@ -286,17 +271,14 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
case SL::Node::TYPE_CONTROL_FLOW: {
SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
if (cfnode->flow_op == SL::FLOW_OP_IF) {
-
code += _mktab(p_level) + "if (" + dump_node_code(cfnode->expressions[0], p_level) + ")\n";
code += dump_node_code(cfnode->blocks[0], p_level + 1);
if (cfnode->blocks.size() == 2) {
-
code += _mktab(p_level) + "else\n";
code += dump_node_code(cfnode->blocks[1], p_level + 1);
}
} else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
-
if (cfnode->blocks.size()) {
code = "return " + dump_node_code(cfnode->blocks[0], p_level);
} else {
@@ -316,7 +298,6 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
}
static Error recreate_code(void *p_str, SL::ShaderNode *p_program) {
-
String *str = (String *)p_str;
*str = dump_node_code(p_program, 0);
@@ -325,7 +306,6 @@ static Error recreate_code(void *p_str, SL::ShaderNode *p_program) {
}
MainLoop *test() {
-
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
if (cmdlargs.empty()) {
@@ -346,8 +326,9 @@ MainLoop *test() {
while (true) {
CharType c = fa->get_8();
- if (fa->eof_reached())
+ if (fa->eof_reached()) {
break;
+ }
code += c;
}
@@ -366,7 +347,6 @@ MainLoop *test() {
Error err = sl.compile(code, dt, rm, types, nullptr);
if (err) {
-
print_line("Error at line: " + rtos(sl.get_error_line()) + ": " + sl.get_error_text());
return nullptr;
} else {
@@ -377,4 +357,5 @@ MainLoop *test() {
return nullptr;
}
+
} // namespace TestShaderLang
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index 76631f9eae..775c039282 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -45,7 +45,6 @@
namespace TestString {
bool test_1() {
-
OS::get_singleton()->print("\n\nTest 1: Assign from cstr\n");
String s = "Hello";
@@ -57,7 +56,6 @@ bool test_1() {
}
bool test_2() {
-
OS::get_singleton()->print("\n\nTest 2: Assign from string (operator=)\n");
String s = "Dolly";
@@ -70,7 +68,6 @@ bool test_2() {
}
bool test_3() {
-
OS::get_singleton()->print("\n\nTest 3: Assign from c-string (copycon)\n");
String s("Sheep");
@@ -83,7 +80,6 @@ bool test_3() {
}
bool test_4() {
-
OS::get_singleton()->print("\n\nTest 4: Assign from c-widechar (operator=)\n");
String s(L"Give me");
@@ -95,7 +91,6 @@ bool test_4() {
}
bool test_5() {
-
OS::get_singleton()->print("\n\nTest 5: Assign from c-widechar (copycon)\n");
String s(L"Wool");
@@ -107,67 +102,72 @@ bool test_5() {
}
bool test_6() {
-
OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n");
String s = "Test Compare";
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (!(s == "Test Compare"))
+ if (!(s == "Test Compare")) {
return false;
+ }
- if (!(s == L"Test Compare"))
+ if (!(s == L"Test Compare")) {
return false;
+ }
- if (!(s == String("Test Compare")))
+ if (!(s == String("Test Compare"))) {
return false;
+ }
return true;
}
bool test_7() {
-
OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n");
String s = "Test Compare";
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (!(s != "Peanut"))
+ if (!(s != "Peanut")) {
return false;
+ }
- if (!(s != L"Coconut"))
+ if (!(s != L"Coconut")) {
return false;
+ }
- if (!(s != String("Butter")))
+ if (!(s != String("Butter"))) {
return false;
+ }
return true;
}
bool test_8() {
-
OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n");
String s = "Bees";
OS::get_singleton()->print("\tComparing to \"Bees\"\n");
- if (!(s < "Elephant"))
+ if (!(s < "Elephant")) {
return false;
+ }
- if (s < L"Amber")
+ if (s < L"Amber") {
return false;
+ }
- if (s < String("Beatrix"))
+ if (s < String("Beatrix")) {
return false;
+ }
return true;
}
bool test_9() {
-
OS::get_singleton()->print("\n\nTest 9: Concatenation\n");
String s;
@@ -186,23 +186,24 @@ bool test_9() {
}
bool test_10() {
-
OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n");
- if (!String("").empty())
+ if (!String("").empty()) {
return false;
+ }
- if (String("Mellon").size() != 7)
+ if (String("Mellon").size() != 7) {
return false;
+ }
- if (String("Oranges").length() != 7)
+ if (String("Oranges").length() != 7) {
return false;
+ }
return true;
}
bool test_11() {
-
OS::get_singleton()->print("\n\nTest 11: Operator[]\n");
String a = "Kugar Sane";
@@ -210,32 +211,34 @@ bool test_11() {
a[0] = 'S';
a[6] = 'C';
- if (a != "Sugar Cane")
+ if (a != "Sugar Cane") {
return false;
+ }
- if (a[1] != 'u')
+ if (a[1] != 'u') {
return false;
+ }
return true;
}
bool test_12() {
-
OS::get_singleton()->print("\n\nTest 12: case functions\n");
String a = "MoMoNgA";
- if (a.to_upper() != "MOMONGA")
+ if (a.to_upper() != "MOMONGA") {
return false;
+ }
- if (a.nocasecmp_to("momonga") != 0)
+ if (a.nocasecmp_to("momonga") != 0) {
return false;
+ }
return true;
}
bool test_13() {
-
OS::get_singleton()->print("\n\nTest 13: UTF8\n");
/* how can i embed UTF in here? */
@@ -252,7 +255,6 @@ bool test_13() {
}
bool test_14() {
-
OS::get_singleton()->print("\n\nTest 14: ASCII\n");
String s = L"Primero Leche";
@@ -263,7 +265,6 @@ bool test_14() {
}
bool test_15() {
-
OS::get_singleton()->print("\n\nTest 15: substr\n");
String s = "Killer Baby";
@@ -273,7 +274,6 @@ bool test_15() {
}
bool test_16() {
-
OS::get_singleton()->print("\n\nTest 16: find\n");
String s = "Pretty Woman";
@@ -281,17 +281,18 @@ bool test_16() {
OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty"));
OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck"));
- if (s.find("tty") != 3)
+ if (s.find("tty") != 3) {
return false;
+ }
- if (s.find("Revenge of the Monster Truck") != -1)
+ if (s.find("Revenge of the Monster Truck") != -1) {
return false;
+ }
return true;
}
bool test_17() {
-
OS::get_singleton()->print("\n\nTest 17: find no case\n");
String s = "Pretty Whale";
@@ -299,17 +300,18 @@ bool test_17() {
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA") != 7)
+ if (s.findn("WHA") != 7) {
return false;
+ }
- if (s.findn("Revenge of the Monster SawFish") != -1)
+ if (s.findn("Revenge of the Monster SawFish") != -1) {
return false;
+ }
return true;
}
bool test_18() {
-
OS::get_singleton()->print("\n\nTest 18: find no case\n");
String s = "Pretty Whale";
@@ -317,17 +319,18 @@ bool test_18() {
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA") != 7)
+ if (s.findn("WHA") != 7) {
return false;
+ }
- if (s.findn("Revenge of the Monster SawFish") != -1)
+ if (s.findn("Revenge of the Monster SawFish") != -1) {
return false;
+ }
return true;
}
bool test_19() {
-
OS::get_singleton()->print("\n\nTest 19: Search & replace\n");
String s = "Happy Birthday, Anna!";
@@ -340,7 +343,6 @@ bool test_19() {
}
bool test_20() {
-
OS::get_singleton()->print("\n\nTest 20: Insertion\n");
String s = "Who is Frederic?";
@@ -353,7 +355,6 @@ bool test_20() {
}
bool test_21() {
-
OS::get_singleton()->print("\n\nTest 21: Number -> String\n");
OS::get_singleton()->print("\tPi is %f\n", 33.141593);
@@ -363,7 +364,6 @@ bool test_21() {
}
bool test_22() {
-
OS::get_singleton()->print("\n\nTest 22: String -> Int\n");
static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" };
@@ -372,15 +372,15 @@ bool test_22() {
for (int i = 0; i < 4; i++) {
OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int());
- if (String(nums[i]).to_int() != num[i])
+ if (String(nums[i]).to_int() != num[i]) {
return false;
+ }
}
return true;
}
bool test_23() {
-
OS::get_singleton()->print("\n\nTest 23: String -> Float\n");
static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" };
@@ -389,15 +389,15 @@ bool test_23() {
for (int i = 0; i < 4; i++) {
OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double());
- if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001)
+ if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001) {
return false;
+ }
}
return true;
}
bool test_24() {
-
OS::get_singleton()->print("\n\nTest 24: Slicing\n");
String s = "Mars,Jupiter,Saturn,Uranus";
@@ -407,18 +407,17 @@ bool test_24() {
OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n", s.c_str(), ",");
for (int i = 0; i < s.get_slice_count(","); i++) {
-
OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str());
- if (s.get_slice(",", i) != slices[i])
+ if (s.get_slice(",", i) != slices[i]) {
return false;
+ }
}
return true;
}
bool test_25() {
-
OS::get_singleton()->print("\n\nTest 25: Erasing\n");
String s = "Josephine is such a cute girl!";
@@ -433,7 +432,6 @@ bool test_25() {
}
bool test_26() {
-
OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n");
#ifndef MODULE_REGEX_ENABLED
@@ -461,7 +459,6 @@ struct test_27_data {
};
bool test_27() {
-
OS::get_singleton()->print("\n\nTest 27: begins_with\n");
test_27_data tc[] = {
{ "res://foobar", "res://", true },
@@ -486,7 +483,6 @@ bool test_27() {
};
bool test_28() {
-
OS::get_singleton()->print("\n\nTest 28: sprintf\n");
bool success, state = true;
@@ -822,7 +818,6 @@ bool test_28() {
}
bool test_29() {
-
bool state = true;
IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
@@ -972,32 +967,35 @@ bool test_31() {
String a = "";
success = a[0] == 0;
OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
String b = "Godot";
success = b[b.size()] == 0;
OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
const String c = "";
success = c[0] == 0;
OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
const String d = "Godot";
success = d[d.size()] == 0;
OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
return state;
};
bool test_32() {
-
#define STRIP_TEST(x) \
{ \
bool success = x; \
@@ -1173,7 +1171,6 @@ TestFunc test_funcs[] = {
};
MainLoop *test() {
-
/** A character length != wchar_t may be forced, so the tests won't work */
static_assert(sizeof(CharType) == sizeof(wchar_t));
@@ -1182,11 +1179,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
@@ -1201,4 +1200,5 @@ MainLoop *test() {
return nullptr;
}
+
} // namespace TestString