Browse Source

Update JS tests.

pull/1581/head
Joao Matos 4 years ago committed by João Matos
parent
commit
be1298a35c
  1. 8
      tests2/Builtins.h
  2. 28
      tests2/Classes.h
  3. 4
      tests2/Classes2.h
  4. 14
      tests2/Delegates.h
  5. 6
      tests2/Overloads.h
  6. 21
      tests2/quickjs/premake5.lua
  7. 15
      tests2/quickjs/test-prop.js
  8. 91
      tests2/quickjs/test.js
  9. 23
      tests2/quickjs/test.sh
  10. 6
      tests2/test.sh

8
tests2/Builtins.h

@ -50,4 +50,10 @@ uint16_t PassAndReturnsUInt16 (uint16_t v) { return v; } @@ -50,4 +50,10 @@ uint16_t PassAndReturnsUInt16 (uint16_t v) { return v; }
int32_t PassAndReturnsInt32 (int32_t v) { return v; }
uint32_t PassAndReturnsUInt32 (uint32_t v) { return v; }
int64_t PassAndReturnsInt64 (int64_t v) { return v; }
uint64_t PassAndReturnsUInt64 (uint64_t v) { return v; }
uint64_t PassAndReturnsUInt64 (uint64_t v) { return v; }
// Pointer types
const char* ReturnsConstCharPtr() { return "Hello"; }
const char* PassAndReturnsConstCharPtr(const char* ptr) { return ptr; }

28
tests2/Classes.h

@ -1,8 +1,28 @@ @@ -1,8 +1,28 @@
#include "Classes2.h"
class Class
{
public:
void ReturnsVoid() {}
int ReturnsInt() { return 0; }
Class* PassAndReturnsClassPtr(Class* obj) { return obj; }
};
class ClassWithField
{
public:
ClassWithField() : Field(10) {}
int Field;
int ReturnsField() { return Field; }
};
class ClassWithOverloads
{
public:
ClassWithOverloads() {}
ClassWithOverloads(int) {}
void Overload() {}
void Overload(int) {}
};
class ClassWithSingleInheritance : public Class
@ -10,3 +30,11 @@ class ClassWithSingleInheritance : public Class @@ -10,3 +30,11 @@ class ClassWithSingleInheritance : public Class
public:
int ChildMethod() { return 2; }
};
class ClassWithExternalInheritance : public ClassFromAnotherUnit
{
};
void FunctionPassClassByRef(Class* klass) { }
Class* FunctionReturnsClassByRef() { return new Class(); }

4
tests2/Classes2.h

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
class ClassFromAnotherUnit
{
};

14
tests2/Delegates.h

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
#include <FastDelegates.h>
using namespace fastdelegate;
class ClassWithDelegate
{
public:
FastDelegate<int(int)> OnEvent0;
void FireEvent0(int value) { if (OnEvent0) OnEvent0(value); }
};
class ClassInheritsDelegate : public ClassWithDelegate
{
};

6
tests2/Overloads.h

@ -6,3 +6,9 @@ int Overload1(int) { return 2; } @@ -6,3 +6,9 @@ int Overload1(int) { return 2; }
int Overload(int, int) { return 1; }
int Overload(int, float) { return 2; }
int Overload(float, int) { return 3; }
int DefaultParamsOverload() { return 0; }
int DefaultParamsOverload(int a, int b) { return 2; }
int DefaultParamsOverload(int a, float b = 2) { return 3; }
int DefaultParamsOverload2(int a = 0, int b = 0, int c = 0) { return 1; }

21
tests2/quickjs/premake5.lua

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
qjs_inc_dir = path.getabsolute("../../deps/txiki.js/deps/quickjs/include")
qjs_lib_dir = path.getabsolute("../../deps/txiki.js/deps/quickjs/include")
local qjs_dir = path.getabsolute("../../deps/quickjs")
local runtime = "../../src/Generator/Generators/QuickJS/Runtime"
workspace "qjs"
configurations { "release" }
configurations { "debug", "release" }
location "gen"
symbols "On"
optimize "Off"
@ -10,8 +10,19 @@ workspace "qjs" @@ -10,8 +10,19 @@ workspace "qjs"
project "test"
kind "SharedLib"
language "C++"
files {"gen/**.cpp"}
includedirs { qjs_inc_dir, ".." }
files
{
"gen/**.cpp",
runtime .. "/*.cpp",
runtime .. "/*.c"
}
includedirs
{
qjs_dir,
runtime,
"..",
"../../include"
}
libdirs { qjs_lib_dir }
filter { "kind:StaticLib" }
links { "quickjs" }

15
tests2/quickjs/test-prop.js

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
class A
{
get foo() { return 1; }
}
class B extends A
{
}
let a = new A();
console.log(a.foo)
let b = new B();
console.log(b.foo)

91
tests2/quickjs/test.js

@ -103,5 +103,96 @@ function enums() @@ -103,5 +103,96 @@ function enums()
eq(test.PassAndReturnsEnum(test.Enum0.Item1), test.Enum0.Item1);
}
function overloads()
{
eq(test.Overload0(), undefined);
eq(test.Overload1(), 1);
eq(test.Overload1(2), 2);
eq(test.Overload(1, 2), 1);
//eq(test.Overload(1, 2.032), 2);
//eq(test.Overload(1.23, 2), 3);
eq(test.DefaultParamsOverload(0, 0), 2);
eq(test.DefaultParamsOverload(0, 0.0), 2);
eq(test.DefaultParamsOverload(0), 3);
eq(test.DefaultParamsOverload2(), 1);
eq(test.DefaultParamsOverload2(1), 1);
eq(test.DefaultParamsOverload2(1, 2), 1);
eq(test.DefaultParamsOverload2(1, 2, 3), 1);
}
function classes()
{
var c = new test.Class();
eq(typeof(c), "object")
eq(c.ReturnsVoid(), undefined)
eq(c.ReturnsInt(), 0)
eq(c.PassAndReturnsClassPtr(null), null)
var c1 = new test.ClassWithSingleInheritance();
eq(c1.__proto__.constructor.name, 'ClassWithSingleInheritance')
eq(c1.__proto__.__proto__.constructor.name, 'Class')
eq(c1.ReturnsVoid(), undefined);
eq(c1.ReturnsInt(), 0);
eq(c1.ChildMethod(), 2);
var classWithField = new test.ClassWithField();
eq(classWithField.ReturnsField(), 10);
}
function delegates()
{
const signal = new test.Signal();
eq(signal.toString(), "Signal");
const classWithDelegate = new test.ClassWithDelegate();
const event0 = classWithDelegate.OnEvent0;
eq(event0.__proto__.constructor.name, "Signal")
const event0_1 = classWithDelegate.OnEvent0;
eq(event0 === event0_1, true);
let anon_cb_called = false;
const anon_cb = () => { anon_cb_called = true; return 32; };
event0.connect(anon_cb);
classWithDelegate.FireEvent0(10);
eq(anon_cb_called, true);
}
function delegates2()
{
let anon_cb_called = false;
const anon_cb = () => { anon_cb_called = true; return 32; };
const classInheritsDelegate = new test.ClassInheritsDelegate();
const event0 = classInheritsDelegate.OnEvent0;
event0.connect(anon_cb);
classInheritsDelegate.FireEvent0(10);
eq(anon_cb_called, true);
}
builtins();
enums();
overloads();
classes();
delegates();
delegates2();
function printChain(obj)
{
console.log("\nprototypes:")
let proto = obj.__proto__
if (proto == null)
{
console.log("invalid proto")
return
}
while (proto != null)
{
console.log(proto.constructor.name)
proto = proto.__proto__
}
console.log("")
}

23
tests2/quickjs/test.sh

@ -2,25 +2,30 @@ @@ -2,25 +2,30 @@
set -e
dir=$(cd "$(dirname "$0")"; pwd)
rootdir="$dir/../.."
configuration=Release
dotnet_configuration=Release
configuration=debug
platform=x64
jsinterp="$rootdir/deps/quickjs/qjs"
jsinterp="$rootdir/deps/quickjs/qjs-debug"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
echo "${green}Generating bindings${reset}"
dotnet $rootdir/bin/${configuration}_${platform}/CppSharp.CLI.dll \
--gen=qjs -I$dir/.. -o $dir/gen -m tests $dir/../Builtins.h $dir/../Enums.h
generate=true
if [ $generate = true ]; then
echo "${green}Generating bindings${reset}"
dotnet $rootdir/bin/${dotnet_configuration}_${platform}/CppSharp.CLI.dll \
--gen=qjs -I$dir/.. -I$rootdir/include -o $dir/gen -m tests $dir/../*.h
fi
echo "${green}Building generated binding files${reset}"
premake=$rootdir/build/premake.sh
$premake --file=$dir/premake5.lua gmake
config=$configuration $premake --file=$dir/premake5.lua gmake
make -C $dir/gen
echo
echo "${green}Executing JS tests with QuickJS${reset}"
cp $dir/gen/bin/release/libtest.so $dir
#cp $dir/gen/bin/release/libtest.dylib $dir
$jsinterp $dir/test.js
cp $dir/gen/bin/$configuration/libtest.so $dir
#cp $dir/gen/bin/$configuration/libtest.dylib $dir
$jsinterp --std $dir/test.js

6
tests2/test.sh

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
dir=$(cd "$(dirname "$0")"; pwd)
$dir/napi/test.sh
$dir/quickjs/test.sh
Loading…
Cancel
Save