Browse Source

Run script test

O01eg 4 years ago
parent
commit
279d63d6c5
8 changed files with 99 additions and 8 deletions
  1. 14 2
      .github/workflows/ci.yml
  2. 1 1
      test/SConstruct
  3. 0 2
      test/demo/.gitignore
  4. 20 0
      test/gdexample.gdnlib
  5. 9 0
      test/gdexample.gdns
  6. 19 0
      test/project.godot
  7. 30 0
      test/script.gd
  8. 6 3
      test/src/init.cpp

+ 14 - 2
.github/workflows/ci.yml

@@ -21,6 +21,8 @@ jobs:
           sudo apt-get update -qq
           sudo apt-get install -qqq build-essential pkg-config
           python -m pip install scons
+          curl -LO https://downloads.tuxfamily.org/godotengine/3.2.3/Godot_v3.2.3-stable_linux_server.64.zip
+          unzip Godot_v3.2.3-stable_linux_server.64.zip
 
       - name: Build godot-cpp
         run: |
@@ -35,7 +37,11 @@ jobs:
 
       - name: Build test GDNative library
         run: |
-          scons target=release platform=linux bits=64 -j $(nproc) -C test;
+          scons target=release platform=linux bits=64 -j $(nproc) -C test
+
+      - name: Run test GDNative library
+        run: |
+          ./Godot_v3.2.3-stable_linux_server.64 --path test -s script.gd
 
   windows-msvc:
     name: Build (Windows, MSVC)
@@ -117,6 +123,8 @@ jobs:
       - name: Install dependencies
         run: |
           python -m pip install scons
+          curl -LO https://downloads.tuxfamily.org/godotengine/3.2.3/Godot_v3.2.3-stable_osx.64.zip
+          unzip Godot_v3.2.3-stable_osx.64.zip
 
       - name: Build godot-cpp
         run: |
@@ -131,7 +139,11 @@ jobs:
 
       - name: Build test GDNative library
         run: |
-          scons target=release platform=osx bits=64 -j $(sysctl -n hw.logicalcpu) -C test;
+          scons target=release platform=osx bits=64 -j $(sysctl -n hw.logicalcpu) -C test
+
+      - name: Run test GDNative library
+        run: |
+          ./Godot.app/Contents/MacOS/Godot --path test -s script.gd
 
   static-checks:
     name: Static Checks (clang-format)

+ 1 - 1
test/SConstruct

@@ -26,7 +26,7 @@ opts.Add(EnumVariable('platform', "Compilation platform", host_platform, ['', 'w
 opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", host_platform, ['', 'windows', 'x11', 'linux', 'osx']))
 opts.Add(EnumVariable('bits', 'Target platform bits', '64', ('32', '64')))
 opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
-opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/bin/', PathVariable.PathAccept))
+opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/', PathVariable.PathAccept))
 opts.Add(PathVariable('target_name', 'The library name.', 'libgdexample', PathVariable.PathAccept))
 
 # Local dependency paths, adapt them to your setup

+ 0 - 2
test/demo/.gitignore

@@ -1,2 +0,0 @@
-*
-!.gitignore

+ 20 - 0
test/gdexample.gdnlib

@@ -0,0 +1,20 @@
+[general]
+
+singleton=false
+load_once=true
+symbol_prefix="godot_"
+reloadable=false
+
+[entry]
+
+X11.64="res://bin/x11/libgdexample.so"
+Server.64="res://bin/x11/libgdexample.so"
+Windows.64="res://bin/win64/libgdexample.dll"
+OSX.64="res://bin/osx/libgdexample.dylib"
+
+[dependencies]
+
+X11.64=[]
+Server.64=[]
+Windows.64=[]
+OSX.64=[]

+ 9 - 0
test/gdexample.gdns

@@ -0,0 +1,9 @@
+[gd_resource type="NativeScript" load_steps=2 format=2]
+
+[ext_resource path="res://gdexample.gdnlib" type="GDNativeLibrary" id=1]
+
+[resource]
+
+resource_name = "gdexample"
+class_name = "SimpleClass"
+library = ExtResource( 1 )

+ 19 - 0
test/project.godot

@@ -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=4
+
+_global_script_classes=[  ]
+_global_script_class_icons={
+
+}
+
+[application]
+
+config/name="Test CI project"
+

+ 30 - 0
test/script.gd

@@ -0,0 +1,30 @@
+
+extends MainLoop
+
+func _initialize():
+    OS.exit_code = 1
+    var native_script = load("res://gdexample.gdns")
+    print("Native Script ", native_script)
+    if native_script == null || !is_instance_valid(native_script):
+        return
+    print("Library ", native_script.library)
+    if native_script.library == null || !is_instance_valid(native_script.library):
+        return
+    var ref = native_script.new()
+    print("Reference ", ref)
+    if ref == null || !is_instance_valid(ref):
+        return
+    print("Reference name ", ref.name)
+    if ref.name != "SimpleClass":
+        return
+    print("Reference value ", ref.value)
+    if ref.value != 0:
+        return
+    print("Call method ", ref.method(1))
+    if ref.method(1) != 1:
+        return
+    OS.exit_code = 0
+
+func _idle(_delta):
+    return true
+

+ 6 - 3
test/src/init.cpp

@@ -10,7 +10,10 @@ public:
 	SimpleClass() {}
 
 	/** `_init` must exist as it is called by Godot. */
-	void _init() {}
+	void _init() {
+		_name = String("SimpleClass");
+		_value = 0;
+	}
 
 	void test_void_method() {
 		Godot::print("This is test");
@@ -30,10 +33,10 @@ public:
 		 * The line below is equivalent to the following GDScript export:
 		 *	 export var _name = "SimpleClass"
 		 **/
-		register_property<SimpleClass, String>("base/name", &SimpleClass::_name, String("SimpleClass"));
+		register_property<SimpleClass, String>("name", &SimpleClass::_name, String("SimpleClass"));
 
 		/** Alternatively, with getter and setter methods: */
-		register_property<SimpleClass, int>("base/value", &SimpleClass::set_value, &SimpleClass::get_value, 0);
+		register_property<SimpleClass, int>("value", &SimpleClass::set_value, &SimpleClass::get_value, 0);
 
 		/** Registering a signal: **/
 		register_signal<SimpleClass>("signal_name0"); // windows: error C2668: 'godot::register_signal': ambiguous call to overloaded function