|
| 1 | +// Behavioral test for the godotengine.godot-cpp-m 10.0.0-rc1 module package (Godot 4.6): godot-cpp's |
| 2 | +// API reached with `import godot_cpp;` and no #include at all. |
| 3 | +// |
| 4 | +// The numbers are deliberately the same ones tests/examples/godot-cpp asserts |
| 5 | +// through headers -- that member is the header spelling of this one, so a |
| 6 | +// divergence here means the module re-export changed behaviour. |
| 7 | +// |
| 8 | +// Both halves can fail: |
| 9 | +// * Vector2::length(), Basis::orthonormalized(), Color::to_rgba32() and |
| 10 | +// AABB::get_volume() are DEFINED in compat.godot-cpp's src/variant/*.cpp, |
| 11 | +// so they only resolve if that dependency really compiled and linked. |
| 12 | +// * Node, Node2D, Node::PROCESS_MODE_*, godot::OK and Variant::OBJECT exist |
| 13 | +// only in the pre-generated gen/ tree. |
| 14 | +// |
| 15 | +// Not covered here, by nature: anything routed through the |
| 16 | +// gdextension_interface_* function pointers (String, Array, class |
| 17 | +// registration) needs a Godot process that has loaded the extension. The |
| 18 | +// GDCLASS/macro shape is covered by the package's own test suite. |
| 19 | + |
| 20 | +import std; |
| 21 | +import godot_cpp; |
| 22 | + |
| 23 | +namespace { |
| 24 | + |
| 25 | +bool close(double a, double b) { |
| 26 | + return std::fabs(a - b) < 1e-5; |
| 27 | +} |
| 28 | + |
| 29 | +} // namespace |
| 30 | + |
| 31 | +int main() { |
| 32 | + using namespace godot; |
| 33 | + |
| 34 | + const bool vec2_ok = close(Vector2(3, 4).length(), 5.0) && |
| 35 | + close(Vector2(3, 4).normalized().length(), 1.0); |
| 36 | + |
| 37 | + const Vector3 cross = Vector3(1, 0, 0).cross(Vector3(0, 1, 0)); |
| 38 | + const bool vec3_ok = cross == Vector3(0, 0, 1) && |
| 39 | + close(Vector3(2, 3, 6).length(), 7.0); |
| 40 | + |
| 41 | + const bool basis_ok = close(Basis().orthonormalized().determinant(), 1.0); |
| 42 | + |
| 43 | + const bool color_ok = Color(1.0f, 0.0f, 0.0f, 1.0f).to_rgba32() == 0xff0000ffu; |
| 44 | + |
| 45 | + const AABB box(Vector3(0, 0, 0), Vector3(2, 3, 4)); |
| 46 | + const AABB other(Vector3(1, 1, 1), Vector3(4, 4, 4)); |
| 47 | + const bool aabb_ok = close(box.get_volume(), 24.0) && |
| 48 | + box.intersects(other) && |
| 49 | + close(box.intersection(other).get_volume(), 6.0); |
| 50 | + |
| 51 | + // These bindings are Godot 4.6. The 4.5 member checks GODOT_VERSION_MAJOR |
| 52 | + // / _MINOR, but those are MACROS from version.hpp and a module cannot |
| 53 | + // export macros -- so the version is asserted through types instead: |
| 54 | + // EditorDock and AHashMap exist in 4.6 and not in 4.5. |
| 55 | + const bool version_ok = sizeof(EditorDock) > 0 && |
| 56 | + sizeof(AHashMap<int, int>) > 0; |
| 57 | + |
| 58 | + const bool gen_ok = sizeof(Node) > 0 && |
| 59 | + sizeof(Node2D) > 0 && |
| 60 | + Node::PROCESS_MODE_INHERIT == 0 && |
| 61 | + Node::PROCESS_MODE_DISABLED == 4 && |
| 62 | + godot::OK == 0 && |
| 63 | + godot::ERR_FILE_NOT_FOUND == 7 && |
| 64 | + godot::SIDE_LEFT == 0 && |
| 65 | + Variant::OBJECT != Variant::NIL; |
| 66 | + |
| 67 | + const bool math_ok = Math::is_equal_approx(1.0f, 1.0f) && |
| 68 | + !Math::is_zero_approx(1.0f) && |
| 69 | + close(Math::lerp(0.0, 10.0, 0.25), 2.5); |
| 70 | + |
| 71 | + const bool ok = version_ok && vec2_ok && vec3_ok && basis_ok && color_ok && |
| 72 | + aabb_ok && gen_ok && math_ok; |
| 73 | + std::println("version={} vec2={} vec3={} basis={} color={} aabb={} gen={} math={}", |
| 74 | + version_ok, vec2_ok, vec3_ok, basis_ok, color_ok, aabb_ok, gen_ok, math_ok); |
| 75 | + return ok ? 0 : 1; |
| 76 | +} |
0 commit comments