Unverified Commit 56343e13 by Rémi Verschelde Committed by GitHub

Merge pull request #38723 from neikeq/initial-classdb-test

Added tests for ClassDB
parents 8896425e 9fa4b402
/*************************************************************************/
/* test_class_db.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef GODOT_TEST_CLASS_DB_H
#define GODOT_TEST_CLASS_DB_H
#include "core/os/main_loop.h"
namespace TestClassDB {
MainLoop *test();
}
#endif //GODOT_TEST_CLASS_DB_H
......@@ -35,6 +35,7 @@
#ifdef DEBUG_ENABLED
#include "test_astar.h"
#include "test_class_db.h"
#include "test_gdscript.h"
#include "test_gui.h"
#include "test_math.h"
......@@ -54,6 +55,7 @@ const char **tests_get_names() {
"physics_3d",
"render",
"oa_hash_map",
"class_db",
"gui",
"shaderlang",
"gd_tokenizer",
......@@ -93,6 +95,10 @@ MainLoop *test_main(String p_test, const List<String> &p_args) {
return TestOAHashMap::test();
}
if (p_test == "class_db") {
return TestClassDB::test();
}
#ifndef _3D_DISABLED
if (p_test == "gui") {
return TestGUI::test();
......
......@@ -102,6 +102,8 @@ class BindingsGenerator {
TypeReference type;
String name;
Variant def_param_value;
DefaultParamMode def_param_mode = CONSTANT;
/**
......@@ -355,8 +357,9 @@ class BindingsGenerator {
const MethodInterface *find_method_by_name(const StringName &p_cname) const {
for (const List<MethodInterface>::Element *E = methods.front(); E; E = E->next()) {
if (E->get().cname == p_cname)
if (E->get().cname == p_cname) {
return &E->get();
}
}
return nullptr;
......@@ -364,8 +367,9 @@ class BindingsGenerator {
const PropertyInterface *find_property_by_name(const StringName &p_cname) const {
for (const List<PropertyInterface>::Element *E = properties.front(); E; E = E->next()) {
if (E->get().cname == p_cname)
if (E->get().cname == p_cname) {
return &E->get();
}
}
return nullptr;
......@@ -373,8 +377,9 @@ class BindingsGenerator {
const PropertyInterface *find_property_by_proxy_name(const String &p_proxy_name) const {
for (const List<PropertyInterface>::Element *E = properties.front(); E; E = E->next()) {
if (E->get().proxy_name == p_proxy_name)
if (E->get().proxy_name == p_proxy_name) {
return &E->get();
}
}
return nullptr;
......@@ -382,8 +387,9 @@ class BindingsGenerator {
const MethodInterface *find_method_by_proxy_name(const String &p_proxy_name) const {
for (const List<MethodInterface>::Element *E = methods.front(); E; E = E->next()) {
if (E->get().proxy_name == p_proxy_name)
if (E->get().proxy_name == p_proxy_name) {
return &E->get();
}
}
return nullptr;
......@@ -523,58 +529,70 @@ class BindingsGenerator {
void _initialize_blacklisted_methods();
struct NameCache {
StringName type_void;
StringName type_Array;
StringName type_Dictionary;
StringName type_Variant;
StringName type_VarArg;
StringName type_Object;
StringName type_Reference;
StringName type_RID;
StringName type_String;
StringName type_StringName;
StringName type_NodePath;
StringName type_at_GlobalScope;
StringName enum_Error;
StringName type_sbyte;
StringName type_short;
StringName type_int;
StringName type_long;
StringName type_byte;
StringName type_ushort;
StringName type_uint;
StringName type_ulong;
StringName type_float;
StringName type_double;
NameCache() {
type_void = StaticCString::create("void");
type_Array = StaticCString::create("Array");
type_Dictionary = StaticCString::create("Dictionary");
type_Variant = StaticCString::create("Variant");
type_VarArg = StaticCString::create("VarArg");
type_Object = StaticCString::create("Object");
type_Reference = StaticCString::create("Reference");
type_RID = StaticCString::create("RID");
type_String = StaticCString::create("String");
type_StringName = StaticCString::create("StringName");
type_NodePath = StaticCString::create("NodePath");
type_at_GlobalScope = StaticCString::create("@GlobalScope");
enum_Error = StaticCString::create("Error");
type_sbyte = StaticCString::create("sbyte");
type_short = StaticCString::create("short");
type_int = StaticCString::create("int");
type_long = StaticCString::create("long");
type_byte = StaticCString::create("byte");
type_ushort = StaticCString::create("ushort");
type_uint = StaticCString::create("uint");
type_ulong = StaticCString::create("ulong");
type_float = StaticCString::create("float");
type_double = StaticCString::create("double");
StringName type_void = StaticCString::create("void");
StringName type_Variant = StaticCString::create("Variant");
StringName type_VarArg = StaticCString::create("VarArg");
StringName type_Object = StaticCString::create("Object");
StringName type_Reference = StaticCString::create("Reference");
StringName type_RID = StaticCString::create("RID");
StringName type_String = StaticCString::create("String");
StringName type_StringName = StaticCString::create("StringName");
StringName type_NodePath = StaticCString::create("NodePath");
StringName type_at_GlobalScope = StaticCString::create("@GlobalScope");
StringName enum_Error = StaticCString::create("Error");
StringName type_sbyte = StaticCString::create("sbyte");
StringName type_short = StaticCString::create("short");
StringName type_int = StaticCString::create("int");
StringName type_byte = StaticCString::create("byte");
StringName type_ushort = StaticCString::create("ushort");
StringName type_uint = StaticCString::create("uint");
StringName type_long = StaticCString::create("long");
StringName type_ulong = StaticCString::create("ulong");
StringName type_bool = StaticCString::create("bool");
StringName type_float = StaticCString::create("float");
StringName type_double = StaticCString::create("double");
StringName type_Vector2 = StaticCString::create("Vector2");
StringName type_Rect2 = StaticCString::create("Rect2");
StringName type_Vector3 = StaticCString::create("Vector3");
// Object not included as it must be checked for all derived classes
static constexpr int nullable_types_count = 17;
StringName nullable_types[nullable_types_count] = {
type_String,
type_StringName,
type_NodePath,
StaticCString::create(_STR(Array)),
StaticCString::create(_STR(Dictionary)),
StaticCString::create(_STR(Callable)),
StaticCString::create(_STR(Signal)),
StaticCString::create(_STR(PackedByteArray)),
StaticCString::create(_STR(PackedInt32Array)),
StaticCString::create(_STR(PackedInt64rray)),
StaticCString::create(_STR(PackedFloat32Array)),
StaticCString::create(_STR(PackedFloat64Array)),
StaticCString::create(_STR(PackedStringArray)),
StaticCString::create(_STR(PackedVector2Array)),
StaticCString::create(_STR(PackedVector3Array)),
StaticCString::create(_STR(PackedColorArray)),
};
bool is_nullable_type(const StringName &p_type) const {
for (int i = 0; i < nullable_types_count; i++) {
if (p_type == nullable_types[i]) {
return true;
}
}
return false;
}
NameCache() {}
private:
NameCache(const NameCache &);
NameCache &operator=(const NameCache &);
......@@ -585,8 +603,9 @@ class BindingsGenerator {
const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) {
const List<InternalCall>::Element *it = p_list.front();
while (it) {
if (it->get().name == p_name)
if (it->get().name == p_name) {
return it;
}
it = it->next();
}
return nullptr;
......@@ -594,20 +613,22 @@ class BindingsGenerator {
const ConstantInterface *find_constant_by_name(const String &p_name, const List<ConstantInterface> &p_constants) const {
for (const List<ConstantInterface>::Element *E = p_constants.front(); E; E = E->next()) {
if (E->get().name == p_name)
if (E->get().name == p_name) {
return &E->get();
}
}
return nullptr;
}
inline String get_unique_sig(const TypeInterface &p_type) {
if (p_type.is_reference)
if (p_type.is_reference) {
return "Ref";
else if (p_type.is_object_type)
} else if (p_type.is_object_type) {
return "Obj";
else if (p_type.is_enum)
} else if (p_type.is_enum) {
return "int";
}
return p_type.name;
}
......@@ -626,6 +647,7 @@ class BindingsGenerator {
StringName _get_float_type_name_from_meta(GodotTypeInfo::Metadata p_meta);
bool _arg_default_value_from_variant(const Variant &p_val, ArgumentInterface &r_iarg);
bool _arg_default_value_is_assignable_to_type(const Variant &p_val, const TypeInterface &p_arg_type);
bool _populate_object_type_interfaces();
void _populate_builtin_type_interfaces();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment