Skip to content

Commit

Permalink
Merge pull request #106 from libriscv/testing
Browse files Browse the repository at this point in the history
Testing framework
  • Loading branch information
fwsGonzo authored Sep 11, 2024
2 parents fb6e089 + 0da4bea commit 03f9d05
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/
.build/
.godot/
.mingw/
.vscode/
program/test
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "godot-cpp"]
path = godot-cpp
url = https://github.com/godotengine/godot-cpp.git
[submodule "ext/Gut"]
path = ext/Gut
url = https://github.com/bitwes/Gut.git
1 change: 1 addition & 0 deletions ext/Gut
Submodule Gut added at a55b6c
4 changes: 4 additions & 0 deletions program/cpp/api/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ inline Variant::Variant(const Array& a) {
v.i = a.get_variant_index();
}

inline Variant::operator Array() const {
return as_array();
}

class ArrayIterator {
public:
ArrayIterator(const Array &array, unsigned idx) : m_array(array), m_idx(idx) {}
Expand Down
4 changes: 4 additions & 0 deletions program/cpp/api/dictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ inline Variant::Variant(const Dictionary &d) {
v.i = d.get_variant_index();
}

inline Variant::operator Dictionary() const {
return as_dictionary();
}

struct DictAccessor {
DictAccessor(const Dictionary &dict, const Variant &key) : m_dict(dict), m_key(key) {}

Expand Down
5 changes: 1 addition & 4 deletions program/cpp/api/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ inline Variant::Variant(const String &s) {
}

inline Variant::operator String() const {
if (m_type != STRING) {
api_throw("std::bad_cast", "Failed to cast Variant to String", this);
}
return String::from_variant_index(v.i);
return as_string();
}

inline String Variant::as_string() const {
Expand Down
2 changes: 2 additions & 0 deletions program/cpp/api/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ struct Variant
operator std::string() const; // String for STRING and PACKED_BYTE_ARRAY
operator std::u32string() const; // u32string for STRING, STRING_NAME
operator String() const;
operator Array() const;
operator Dictionary() const;

Object as_object() const;
Node as_node() const;
Expand Down
1 change: 1 addition & 0 deletions src/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ String Sandbox::_to_string() const {
void Sandbox::_bind_methods() {
// Methods.
ClassDB::bind_method(D_METHOD("get_functions"), &Sandbox::get_functions);
ClassDB::bind_method(D_METHOD("set_program", "program"), &Sandbox::set_program);
{
MethodInfo mi;
mi.arguments.push_back(PropertyInfo(Variant::STRING, "function"));
Expand Down
1 change: 1 addition & 0 deletions tests/addons/gut
1 change: 1 addition & 0 deletions tests/extensions/bin/libgodot-riscv.linux.debug.x86_64.so
18 changes: 18 additions & 0 deletions tests/extensions/libgodot-riscv.gdextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[configuration]

entry_symbol = "riscv_library_init"
compatibility_minimum = "4.1"

[icons]


[libraries]

macos.debug = "bin/libgodot-riscv.macos.debug.framework"
macos.release = "bin/libgodot-riscv.macos.release.framework"
windows.debug.x86_64 = "bin/libgodot-riscv.windows.debug.x86_64.dll"
windows.release.x86_64 = "bin/libgodot-riscv.windows.release.x86_64.dll"
linux.debug.x86_64 = "bin/libgodot-riscv.linux.debug.x86_64.so"
linux.release.x86_64 = "bin/libgodot-riscv.linux.release.x86_64.so"
web.debug.wasm32 = "bin/libgodot_riscv.web.template_debug.wasm32.wasm"
web.release.wasm32 = "bin/libgodot_riscv.web.template_release.wasm32.wasm"
1 change: 1 addition & 0 deletions tests/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions tests/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://6xqmeymr5t3"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
19 changes: 19 additions & 0 deletions tests/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="tests"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"

[editor_plugins]

enabled=PackedStringArray("res://addons/gut/plugin.cfg")
9 changes: 9 additions & 0 deletions tests/tests/test_basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "api.hpp"

extern "C" Variant public_function() {
return "Hello from the other side";
}

extern "C" Variant test_dictionary(Variant dict) {
return Dictionary(dict)["1"];
}
17 changes: 17 additions & 0 deletions tests/tests/test_basic.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends GutTest

func test_instantiation():
# Create a new sandbox
var s = Sandbox.new()
# Set the test program
s.set_program(Sandbox_TestsTests)

# Verify that a basic function that returns a String works
assert_eq(s.vmcall("public_function"), "Hello from the other side")

# Verify that the sandbox can receive a Dictionary and return an element
var d : Dictionary
d["1"] = Dictionary()
d["1"]["2"] = "3"

assert_eq(s.vmcall("test_dictionary", d), d["1"])

0 comments on commit 03f9d05

Please sign in to comment.