qml 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +5 -9
- data/LICENSE.txt +1 -1
- data/README.md +84 -114
- data/changes.md +5 -0
- data/examples/fizzbuzz/fizzbuzz.rb +3 -4
- data/examples/todo_array/todo_array.rb +4 -4
- data/examples/todo_sequel/todo_sequel.rb +7 -7
- data/examples/twitter/twitter.rb +5 -3
- data/ext/qml/application.c +88 -0
- data/ext/qml/application.h +9 -0
- data/ext/qml/component.c +89 -0
- data/ext/qml/component.h +10 -0
- data/ext/qml/conversion.c +60 -0
- data/ext/qml/conversion.h +8 -0
- data/ext/qml/dispatcher.c +31 -0
- data/ext/qml/dispatcher.h +7 -0
- data/ext/qml/engine.c +135 -0
- data/ext/qml/engine.h +10 -0
- data/ext/qml/exporter.c +93 -0
- data/ext/qml/exporter.h +7 -0
- data/ext/qml/extconf.rb +38 -97
- data/ext/qml/interface.c +156 -0
- data/ext/qml/interface.h +11 -0
- data/ext/qml/js_array.c +47 -0
- data/ext/qml/js_array.h +7 -0
- data/ext/qml/js_function.c +109 -0
- data/ext/qml/js_function.h +7 -0
- data/ext/qml/js_object.c +284 -0
- data/ext/qml/js_object.h +19 -0
- data/ext/qml/js_wrapper.c +19 -0
- data/ext/qml/js_wrapper.h +7 -0
- data/ext/qml/lib/libqmlbind/.gitignore +38 -0
- data/ext/qml/lib/libqmlbind/.gitmodules +3 -0
- data/ext/qml/lib/libqmlbind/.travis.yml +14 -0
- data/ext/qml/lib/libqmlbind/LICENSE.txt +22 -0
- data/ext/qml/lib/libqmlbind/libqmlbind.pro +3 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind.h +14 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/application.h +18 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/component.h +21 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/engine.h +34 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/exporter.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/interface.h +16 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/iterator.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/metaobject.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/plugin.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/qmlbind_global.h +78 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/register.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/signal_emitter.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/string.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/value.h +100 -0
- data/ext/qml/lib/libqmlbind/qmlbind/qmlbind.pro +62 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_application.cpp +103 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_component.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_engine.cpp +65 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_exporter.cpp +52 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_interface.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_iterator.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_metaobject.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_plugin.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_register.cpp +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_signal_emitter.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_string.cpp +22 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_value.cpp +215 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.h +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.cpp +73 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.h +46 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.cpp +75 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.cpp +101 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.cpp +33 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.h +25 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.cpp +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.cpp +112 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.h +28 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/util.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.cpp +23 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.h +29 -0
- data/ext/qml/lib/libqmlbind/readme.md +14 -0
- data/ext/qml/lib/libqmlbind/test/api.c +1 -0
- data/ext/qml/lib/libqmlbind/test/application_test.cpp +16 -0
- data/ext/qml/lib/libqmlbind/test/component_test.cpp +57 -0
- data/ext/qml/lib/libqmlbind/test/engine_test.cpp +94 -0
- data/ext/qml/lib/libqmlbind/test/exporter_test.cpp +312 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.cpp +36 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.h +6 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/qmldir +2 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/iterator_test.cpp +37 -0
- data/ext/qml/lib/libqmlbind/test/main.cpp +11 -0
- data/ext/qml/lib/libqmlbind/test/plugin_test.cpp +41 -0
- data/ext/qml/lib/libqmlbind/test/test.pro +26 -0
- data/ext/qml/lib/libqmlbind/test/test_helper.h +20 -0
- data/ext/qml/lib/libqmlbind/test/value_test.cpp +252 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.cpp +11 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.h +21 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.json +3 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.pro +21 -0
- data/ext/qml/meta_object.c +81 -0
- data/ext/qml/meta_object.h +8 -0
- data/ext/qml/plugin_loader.c +71 -0
- data/ext/qml/plugin_loader.h +7 -0
- data/ext/qml/qml.c +95 -0
- data/ext/qml/qml.h +10 -0
- data/ext/qml/rubyqml-plugin/listmodel.cpp +102 -0
- data/ext/qml/rubyqml-plugin/listmodel.h +37 -0
- data/ext/qml/rubyqml-plugin/rubyqml-plugin.pro +19 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.cpp +25 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.h +19 -0
- data/ext/qml/signal_emitter.c +71 -0
- data/ext/qml/signal_emitter.h +9 -0
- data/lib/qml.rb +11 -10
- data/lib/qml/access.rb +64 -86
- data/lib/qml/application.rb +20 -71
- data/lib/qml/component.rb +41 -33
- data/lib/qml/core_ext.rb +1 -0
- data/lib/qml/core_ext/to_qml.rb +70 -0
- data/lib/qml/data.rb +1 -0
- data/lib/qml/data/array_model.rb +99 -101
- data/lib/qml/data/list_model.rb +107 -131
- data/lib/qml/data/list_model_access.rb +44 -0
- data/lib/qml/data/query_model.rb +45 -47
- data/lib/qml/dispatcher.rb +5 -13
- data/lib/qml/engine.rb +9 -58
- data/lib/qml/errors.rb +0 -21
- data/lib/qml/interface.rb +21 -0
- data/lib/qml/js_array.rb +8 -0
- data/lib/qml/js_object.rb +69 -0
- data/lib/qml/js_util.rb +18 -0
- data/lib/qml/plugin_loader.rb +1 -13
- data/lib/qml/plugins.rb +3 -17
- data/lib/qml/proc_access.rb +28 -0
- data/lib/qml/qt.rb +21 -3
- data/lib/qml/reactive.rb +147 -8
- data/lib/qml/signal.rb +67 -0
- data/lib/qml/version.rb +1 -1
- data/qml.gemspec +8 -2
- data/spec/qml/access_spec.rb +33 -120
- data/spec/qml/application_spec.rb +11 -24
- data/spec/qml/component_spec.rb +4 -4
- data/spec/qml/data/array_model_spec.rb +2 -2
- data/spec/qml/data/list_model_spec.rb +2 -2
- data/spec/qml/data/query_model_spec.rb +4 -4
- data/spec/qml/engine_spec.rb +23 -21
- data/spec/qml/interface_spec.rb +20 -0
- data/spec/qml/js_array_spec.rb +29 -0
- data/spec/qml/js_function_spec.rb +32 -0
- data/spec/qml/js_object_spec.rb +113 -0
- data/spec/qml/plugin_loader_spec.rb +9 -11
- data/spec/qml/qt_spec.rb +9 -0
- data/spec/qml/reactive_spec.rb +37 -0
- data/spec/qml/signal_connect_spec.rb +27 -0
- data/spec/qml/signal_spec.rb +73 -0
- data/spec/qml/to_qml_spec.rb +76 -0
- data/spec/shared/qml/access_example.rb +21 -0
- data/spec/shared/qml/data/list_model.rb +12 -13
- data/spec/spec_helper.rb +2 -3
- metadata +141 -166
- data/examples/imageprovider/imageprovider.rb +0 -57
- data/examples/imageprovider/main.qml +0 -51
- data/ext/qml/accessclass.cpp +0 -65
- data/ext/qml/accessclass.h +0 -19
- data/ext/qml/accessobject.cpp +0 -30
- data/ext/qml/accessobject.h +0 -22
- data/ext/qml/common.h +0 -18
- data/ext/qml/conversionerror.h +0 -14
- data/ext/qml/ext_accesswrapperfactory.cpp +0 -75
- data/ext/qml/ext_accesswrapperfactory.h +0 -39
- data/ext/qml/ext_anywrapper.cpp +0 -34
- data/ext/qml/ext_anywrapper.h +0 -23
- data/ext/qml/ext_kernel.cpp +0 -81
- data/ext/qml/ext_kernel.h +0 -9
- data/ext/qml/ext_metaobject.cpp +0 -399
- data/ext/qml/ext_metaobject.h +0 -60
- data/ext/qml/ext_pluginloader.cpp +0 -53
- data/ext/qml/ext_pluginloader.h +0 -30
- data/ext/qml/ext_pointer.cpp +0 -132
- data/ext/qml/ext_pointer.h +0 -41
- data/ext/qml/ext_testutil.cpp +0 -40
- data/ext/qml/ext_testutil.h +0 -9
- data/ext/qml/foreignclass.cpp +0 -72
- data/ext/qml/foreignclass.h +0 -88
- data/ext/qml/foreignmetaobject.cpp +0 -345
- data/ext/qml/foreignmetaobject.h +0 -46
- data/ext/qml/foreignobject.cpp +0 -22
- data/ext/qml/foreignobject.h +0 -21
- data/ext/qml/functioninfo.h +0 -16
- data/ext/qml/init.cpp +0 -67
- data/ext/qml/kernel.cpp +0 -39
- data/ext/qml/kernel.h +0 -32
- data/ext/qml/listmodel.cpp +0 -137
- data/ext/qml/listmodel.h +0 -45
- data/ext/qml/markable.h +0 -12
- data/ext/qml/objectdata.cpp +0 -26
- data/ext/qml/objectdata.h +0 -20
- data/ext/qml/objectgc.cpp +0 -69
- data/ext/qml/objectgc.h +0 -28
- data/ext/qml/plugins/core/applicationextension.cpp +0 -29
- data/ext/qml/plugins/core/applicationextension.h +0 -25
- data/ext/qml/plugins/core/componentextension.cpp +0 -41
- data/ext/qml/plugins/core/componentextension.h +0 -28
- data/ext/qml/plugins/core/contextextension.cpp +0 -39
- data/ext/qml/plugins/core/contextextension.h +0 -29
- data/ext/qml/plugins/core/core.pro +0 -29
- data/ext/qml/plugins/core/coreplugin.cpp +0 -87
- data/ext/qml/plugins/core/coreplugin.h +0 -49
- data/ext/qml/plugins/core/engineextension.cpp +0 -43
- data/ext/qml/plugins/core/engineextension.h +0 -31
- data/ext/qml/plugins/core/imageprovider.cpp +0 -38
- data/ext/qml/plugins/core/imageprovider.h +0 -18
- data/ext/qml/plugins/core/imagerequestpromise.cpp +0 -19
- data/ext/qml/plugins/core/imagerequestpromise.h +0 -21
- data/ext/qml/plugins/core/qmlexception.cpp +0 -11
- data/ext/qml/plugins/core/qmlexception.h +0 -17
- data/ext/qml/plugins/testutil/imageprovidertest.cpp +0 -40
- data/ext/qml/plugins/testutil/imageprovidertest.h +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.cpp +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.h +0 -24
- data/ext/qml/plugins/testutil/ownershiptest.cpp +0 -26
- data/ext/qml/plugins/testutil/ownershiptest.h +0 -30
- data/ext/qml/plugins/testutil/testobject.cpp +0 -6
- data/ext/qml/plugins/testutil/testobject.h +0 -108
- data/ext/qml/plugins/testutil/testobjectsubclass.cpp +0 -10
- data/ext/qml/plugins/testutil/testobjectsubclass.h +0 -19
- data/ext/qml/plugins/testutil/testutil.pro +0 -22
- data/ext/qml/plugins/testutil/testutilplugin.cpp +0 -55
- data/ext/qml/plugins/testutil/testutilplugin.h +0 -36
- data/ext/qml/qmltyperegisterer.cpp +0 -74
- data/ext/qml/qmltyperegisterer.h +0 -30
- data/ext/qml/rubyclass.cpp +0 -82
- data/ext/qml/rubyclass.h +0 -230
- data/ext/qml/rubyvalue.cpp +0 -656
- data/ext/qml/rubyvalue.h +0 -224
- data/ext/qml/signalforwarder.cpp +0 -64
- data/ext/qml/signalforwarder.h +0 -29
- data/ext/qml/util.cpp +0 -112
- data/ext/qml/util.h +0 -82
- data/ext/qml/valuereference.cpp +0 -50
- data/ext/qml/valuereference.h +0 -22
- data/ext/qml/weakvaluereference.cpp +0 -51
- data/ext/qml/weakvaluereference.h +0 -21
- data/lib/qml/context.rb +0 -71
- data/lib/qml/data/error.rb +0 -5
- data/lib/qml/dispatchable.rb +0 -34
- data/lib/qml/error_converter.rb +0 -16
- data/lib/qml/geometry.rb +0 -3
- data/lib/qml/geometry/point.rb +0 -5
- data/lib/qml/geometry/rectangle.rb +0 -5
- data/lib/qml/geometry/size.rb +0 -5
- data/lib/qml/image_provider.rb +0 -87
- data/lib/qml/init.rb +0 -29
- data/lib/qml/meta_object.rb +0 -20
- data/lib/qml/models.rb +0 -1
- data/lib/qml/qt_classes.rb +0 -9
- data/lib/qml/qt_object_base.rb +0 -233
- data/lib/qml/reactive/bindable.rb +0 -79
- data/lib/qml/reactive/chained_signal.rb +0 -25
- data/lib/qml/reactive/error.rb +0 -5
- data/lib/qml/reactive/object.rb +0 -293
- data/lib/qml/reactive/property.rb +0 -19
- data/lib/qml/reactive/signal.rb +0 -115
- data/lib/qml/reactive/signal_spy.rb +0 -27
- data/lib/qml/reactive/signals/map_signal.rb +0 -21
- data/lib/qml/reactive/signals/merge_signal.rb +0 -21
- data/lib/qml/reactive/signals/select_signal.rb +0 -21
- data/lib/qml/reactive/simple_property.rb +0 -17
- data/lib/qml/reactive/unbound_property.rb +0 -42
- data/lib/qml/reactive/unbound_signal.rb +0 -51
- data/lib/qml/test_util.rb +0 -1
- data/lib/qml/test_util/object_life_checker.rb +0 -17
- data/lib/qml/wrappable.rb +0 -9
- data/spec/qml/context_spec.rb +0 -43
- data/spec/qml/conversion_spec.rb +0 -60
- data/spec/qml/dispatchable_spec.rb +0 -26
- data/spec/qml/dispatcher_spec.rb +0 -71
- data/spec/qml/geometry/point_spec.rb +0 -4
- data/spec/qml/geometry/rectangle_spec.rb +0 -4
- data/spec/qml/geometry/size_spec.rb +0 -4
- data/spec/qml/image_provider_spec.rb +0 -33
- data/spec/qml/qt_object_base_spec.rb +0 -119
- data/spec/qml/reactive/object_spec.rb +0 -249
- data/spec/qml/reactive/property_spec.rb +0 -70
- data/spec/qml/reactive/signal_spec.rb +0 -191
- data/spec/qml/reactive/signal_spy_spec.rb +0 -26
- data/spec/qml/reactive/unbound_property_spec.rb +0 -40
- data/spec/qml/reactive/unbound_signal_spec.rb +0 -70
- data/spec/qml/test_object_spec.rb +0 -186
- data/spec/qml/wrappable_spec.rb +0 -10
- data/spec/shared/qml/reactive/object.rb +0 -39
@@ -0,0 +1,36 @@
|
|
1
|
+
#include "emptyhandlers.h"
|
2
|
+
|
3
|
+
qmlbind_backref newObject(qmlbind_backref, qmlbind_signal_emitter)
|
4
|
+
{
|
5
|
+
return nullptr;
|
6
|
+
}
|
7
|
+
|
8
|
+
qmlbind_value invokeMethod(qmlbind_engine, qmlbind_backref, const char *, int, qmlbind_value *)
|
9
|
+
{
|
10
|
+
return qmlbind_value_new_undefined();
|
11
|
+
}
|
12
|
+
|
13
|
+
qmlbind_value invokeGetter(qmlbind_engine, qmlbind_backref, const char *)
|
14
|
+
{
|
15
|
+
return qmlbind_value_new_undefined();
|
16
|
+
}
|
17
|
+
|
18
|
+
void invokeSetter(qmlbind_engine, qmlbind_backref, const char *, qmlbind_value)
|
19
|
+
{
|
20
|
+
}
|
21
|
+
|
22
|
+
void deleteObject(qmlbind_backref)
|
23
|
+
{
|
24
|
+
}
|
25
|
+
|
26
|
+
qmlbind_interface_handlers emptyHandlers()
|
27
|
+
{
|
28
|
+
qmlbind_interface_handlers handlers = {
|
29
|
+
.new_object = &newObject,
|
30
|
+
.call_method = &invokeMethod,
|
31
|
+
.set_property = &invokeSetter,
|
32
|
+
.get_property = &invokeGetter,
|
33
|
+
.delete_object = &deleteObject
|
34
|
+
};
|
35
|
+
return handlers;
|
36
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#include "test_helper.h"
|
2
|
+
#include <catch.hpp>
|
3
|
+
#include <qmlbind.h>
|
4
|
+
#include <QList>
|
5
|
+
|
6
|
+
TEST_CASE("iterator")
|
7
|
+
{
|
8
|
+
constexpr auto count = 10;
|
9
|
+
|
10
|
+
auto engine = qmlbind_engine_new();
|
11
|
+
auto object = qmlbind_engine_new_object(engine);
|
12
|
+
|
13
|
+
for (auto i = 0; i < 10; ++i) {
|
14
|
+
auto value = qmlbind_value_new_number(i);
|
15
|
+
qmlbind_value_set_property(object, std::to_string(i).data(), value);
|
16
|
+
qmlbind_value_release(value);
|
17
|
+
}
|
18
|
+
|
19
|
+
auto iterator = qmlbind_iterator_new(object);
|
20
|
+
|
21
|
+
for (auto i = 0; qmlbind_iterator_has_next(iterator); ++i) {
|
22
|
+
qmlbind_iterator_next(iterator);
|
23
|
+
|
24
|
+
qmlbind_iterator_get_key(iterator);
|
25
|
+
auto key = qmlbind_iterator_get_key(iterator);
|
26
|
+
auto value = qmlbind_iterator_get_value(iterator);
|
27
|
+
REQUIRE(std::string(qmlbind_string_get_chars(key)) == std::to_string(i));
|
28
|
+
REQUIRE(qmlbind_value_get_number(value) == i);
|
29
|
+
|
30
|
+
qmlbind_string_release(key);
|
31
|
+
qmlbind_value_release(value);
|
32
|
+
}
|
33
|
+
|
34
|
+
qmlbind_iterator_release(iterator);
|
35
|
+
qmlbind_value_release(object);
|
36
|
+
qmlbind_engine_release(engine);
|
37
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#define CATCH_CONFIG_RUNNER
|
2
|
+
#include <catch.hpp>
|
3
|
+
#include <qmlbind.h>
|
4
|
+
|
5
|
+
int main(int argc, char **argv)
|
6
|
+
{
|
7
|
+
auto app = qmlbind_application_new(argc, argv);
|
8
|
+
auto result = Catch::Session().run();
|
9
|
+
qmlbind_application_release(app);
|
10
|
+
return result;
|
11
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
#include "test_helper.h"
|
3
|
+
#include <qmlbind.h>
|
4
|
+
|
5
|
+
TEST_CASE("plugin")
|
6
|
+
{
|
7
|
+
auto engine = qmlbind_engine_new();
|
8
|
+
|
9
|
+
SECTION("get_instance")
|
10
|
+
{
|
11
|
+
#ifdef Q_OS_MAC
|
12
|
+
auto path = "../testplugin/libtestplugin.dylib";
|
13
|
+
#else
|
14
|
+
auto path = "../testplugin/libtestplugin.so";
|
15
|
+
#endif
|
16
|
+
auto plugin = qmlbind_plugin_new(path);
|
17
|
+
|
18
|
+
auto instance = qmlbind_plugin_get_instance(plugin, engine);
|
19
|
+
auto test = qmlbind_value_get_property(instance, "test");
|
20
|
+
REQUIRE(qmlbind_value_get_number(test) == 12345);
|
21
|
+
qmlbind_value_release(test);
|
22
|
+
qmlbind_value_release(instance);
|
23
|
+
|
24
|
+
REQUIRE(qmlbind_plugin_get_error_string(plugin) == NULL);
|
25
|
+
|
26
|
+
qmlbind_plugin_release(plugin);
|
27
|
+
}
|
28
|
+
|
29
|
+
SECTION("get_error")
|
30
|
+
{
|
31
|
+
auto plugin = qmlbind_plugin_new("./wrong/path");
|
32
|
+
|
33
|
+
auto error = qmlbind_plugin_get_error_string(plugin);
|
34
|
+
REQUIRE(qmlbind_string_get_length(error) > 0);
|
35
|
+
qmlbind_string_release(error);
|
36
|
+
|
37
|
+
qmlbind_plugin_release(plugin);
|
38
|
+
}
|
39
|
+
|
40
|
+
qmlbind_engine_release(engine);
|
41
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
TEMPLATE = app
|
2
|
+
CONFIG += console
|
3
|
+
CONFIG -= app_bundle
|
4
|
+
CONFIG += c++11
|
5
|
+
|
6
|
+
SOURCES += \
|
7
|
+
api.c \
|
8
|
+
main.cpp \
|
9
|
+
engine_test.cpp \
|
10
|
+
value_test.cpp \
|
11
|
+
iterator_test.cpp \
|
12
|
+
component_test.cpp \
|
13
|
+
exporter_test.cpp \
|
14
|
+
application_test.cpp \
|
15
|
+
fixtures/emptyhandlers.cpp \
|
16
|
+
plugin_test.cpp
|
17
|
+
|
18
|
+
QMAKE_CFLAGS += "-std=c89"
|
19
|
+
|
20
|
+
LIBS += -L$$PWD/../qmlbind/ -lqmlbind
|
21
|
+
INCLUDEPATH += $$PWD/../qmlbind/include $$PWD/lib/Catch/include
|
22
|
+
DEPENDPATH += $$PWD/../qmlbind
|
23
|
+
|
24
|
+
HEADERS += \
|
25
|
+
test_helper.h \
|
26
|
+
fixtures/emptyhandlers.h
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <QByteArray>
|
4
|
+
#include <QString>
|
5
|
+
#include <ostream>
|
6
|
+
#include <catch.hpp>
|
7
|
+
|
8
|
+
#define DESCRIBE(what) SECTION(what)
|
9
|
+
#define CONTEXT(what) SECTION(what)
|
10
|
+
#define IT(what) SECTION(what)
|
11
|
+
|
12
|
+
inline std::ostream &operator<<(std::ostream &stream, const QByteArray &ba)
|
13
|
+
{
|
14
|
+
return stream << ba.data();
|
15
|
+
}
|
16
|
+
|
17
|
+
inline std::ostream &operator<<(std::ostream &stream, const QString &str)
|
18
|
+
{
|
19
|
+
return stream << str.toUtf8();
|
20
|
+
}
|
@@ -0,0 +1,252 @@
|
|
1
|
+
#include <catch.hpp>
|
2
|
+
#include <qmlbind.h>
|
3
|
+
#include <array>
|
4
|
+
#include <string.h>
|
5
|
+
|
6
|
+
TEST_CASE("value")
|
7
|
+
{
|
8
|
+
auto engine = qmlbind_engine_new();
|
9
|
+
auto global = qmlbind_engine_get_global_object(engine);
|
10
|
+
|
11
|
+
SECTION("clone")
|
12
|
+
{
|
13
|
+
auto value = qmlbind_value_new_number(3.14);
|
14
|
+
auto clone = qmlbind_value_clone(value);
|
15
|
+
|
16
|
+
REQUIRE(qmlbind_value_get_number(clone) == 3.14);
|
17
|
+
|
18
|
+
qmlbind_value_release(clone);
|
19
|
+
qmlbind_value_release(value);
|
20
|
+
}
|
21
|
+
|
22
|
+
SECTION("comparison")
|
23
|
+
{
|
24
|
+
auto one1 = qmlbind_value_new_number(1);
|
25
|
+
auto one2 = qmlbind_value_new_number(1);
|
26
|
+
auto strOne = qmlbind_value_new_string_cstr("1");
|
27
|
+
|
28
|
+
SECTION("is_equal")
|
29
|
+
{
|
30
|
+
REQUIRE(qmlbind_value_is_equal(one1, strOne));
|
31
|
+
}
|
32
|
+
|
33
|
+
SECTION("is_identical")
|
34
|
+
{
|
35
|
+
REQUIRE(!qmlbind_value_is_identical(one1, strOne));
|
36
|
+
REQUIRE(qmlbind_value_is_identical(one1, one2));
|
37
|
+
}
|
38
|
+
|
39
|
+
qmlbind_value_release(one1);
|
40
|
+
qmlbind_value_release(one2);
|
41
|
+
qmlbind_value_release(strOne);
|
42
|
+
}
|
43
|
+
|
44
|
+
SECTION("undefined")
|
45
|
+
{
|
46
|
+
auto value = qmlbind_value_new_undefined();
|
47
|
+
REQUIRE(qmlbind_value_is_undefined(value));
|
48
|
+
qmlbind_value_release(value);
|
49
|
+
}
|
50
|
+
|
51
|
+
SECTION("null")
|
52
|
+
{
|
53
|
+
auto value = qmlbind_value_new_null();
|
54
|
+
REQUIRE(qmlbind_value_is_null(value));
|
55
|
+
qmlbind_value_release(value);
|
56
|
+
}
|
57
|
+
|
58
|
+
SECTION("true")
|
59
|
+
{
|
60
|
+
auto value = qmlbind_value_new_boolean(true);
|
61
|
+
REQUIRE(qmlbind_value_is_boolean(value));
|
62
|
+
REQUIRE(qmlbind_value_get_boolean(value));
|
63
|
+
qmlbind_value_release(value);
|
64
|
+
}
|
65
|
+
|
66
|
+
SECTION("false")
|
67
|
+
{
|
68
|
+
auto value = qmlbind_value_new_boolean(false);
|
69
|
+
REQUIRE(qmlbind_value_is_boolean(value));
|
70
|
+
REQUIRE(!qmlbind_value_get_boolean(value));
|
71
|
+
qmlbind_value_release(value);
|
72
|
+
}
|
73
|
+
|
74
|
+
SECTION("number")
|
75
|
+
{
|
76
|
+
auto value = qmlbind_value_new_number(3.14);
|
77
|
+
REQUIRE(qmlbind_value_is_number(value));
|
78
|
+
REQUIRE(qmlbind_value_get_number(value) == 3.14);
|
79
|
+
qmlbind_value_release(value);
|
80
|
+
}
|
81
|
+
|
82
|
+
SECTION("string")
|
83
|
+
{
|
84
|
+
auto str = "hoge";
|
85
|
+
auto value = qmlbind_value_new_string(strlen(str), str);
|
86
|
+
auto result = qmlbind_value_get_string(value);
|
87
|
+
|
88
|
+
REQUIRE(qmlbind_value_is_string(value));
|
89
|
+
REQUIRE(std::string(qmlbind_string_get_chars(result)) == str);
|
90
|
+
REQUIRE(qmlbind_string_get_length(result) == strlen(str));
|
91
|
+
|
92
|
+
qmlbind_string_release(result);
|
93
|
+
qmlbind_value_release(value);
|
94
|
+
}
|
95
|
+
|
96
|
+
SECTION("object")
|
97
|
+
{
|
98
|
+
auto value = qmlbind_engine_new_object(engine);
|
99
|
+
REQUIRE(qmlbind_value_is_object(value));
|
100
|
+
|
101
|
+
auto prop = qmlbind_value_new_number(123);
|
102
|
+
qmlbind_value_set_property(value, "prop", prop);
|
103
|
+
qmlbind_value_release(prop);
|
104
|
+
|
105
|
+
prop = qmlbind_value_get_property(value, "prop");
|
106
|
+
REQUIRE(qmlbind_value_get_number(prop) == 123);
|
107
|
+
qmlbind_value_release(prop);
|
108
|
+
|
109
|
+
qmlbind_value_release(value);
|
110
|
+
}
|
111
|
+
|
112
|
+
SECTION("function")
|
113
|
+
{
|
114
|
+
auto parseInt = qmlbind_value_get_property(global, "parseInt");
|
115
|
+
|
116
|
+
REQUIRE(qmlbind_value_is_function(parseInt));
|
117
|
+
|
118
|
+
auto str = qmlbind_value_new_string_cstr("123");
|
119
|
+
auto parsed = qmlbind_value_call(parseInt, 1, &str);
|
120
|
+
|
121
|
+
REQUIRE(qmlbind_value_get_number(parsed) == 123);
|
122
|
+
|
123
|
+
qmlbind_value_release(parseInt);
|
124
|
+
qmlbind_value_release(str);
|
125
|
+
qmlbind_value_release(parsed);
|
126
|
+
}
|
127
|
+
|
128
|
+
SECTION("construtor")
|
129
|
+
{
|
130
|
+
auto arrayConstructor = qmlbind_value_get_property(global, "Array");
|
131
|
+
auto len = qmlbind_value_new_number(10);
|
132
|
+
|
133
|
+
auto array = qmlbind_value_call_constructor(arrayConstructor, 1, &len);
|
134
|
+
qmlbind_value_release(len);
|
135
|
+
|
136
|
+
REQUIRE(qmlbind_value_is_array(array));
|
137
|
+
|
138
|
+
len = qmlbind_value_get_property(array, "length");
|
139
|
+
REQUIRE(qmlbind_value_get_number(len) == 10);
|
140
|
+
|
141
|
+
qmlbind_value_release(array);
|
142
|
+
qmlbind_value_release(len);
|
143
|
+
qmlbind_value_release(arrayConstructor);
|
144
|
+
}
|
145
|
+
|
146
|
+
SECTION("array")
|
147
|
+
{
|
148
|
+
constexpr auto count = 10;
|
149
|
+
|
150
|
+
auto array = qmlbind_engine_new_array(engine, count);
|
151
|
+
|
152
|
+
for (auto i = 0; i < count; ++i) {
|
153
|
+
auto value = qmlbind_value_new_number(i);
|
154
|
+
qmlbind_value_set_array_item(array, i, value);
|
155
|
+
qmlbind_value_release(value);
|
156
|
+
}
|
157
|
+
|
158
|
+
REQUIRE(qmlbind_value_is_array(array));
|
159
|
+
|
160
|
+
for (auto i = 0; i < count; ++i) {
|
161
|
+
auto value = qmlbind_value_get_array_item(array, i);
|
162
|
+
REQUIRE(qmlbind_value_get_number(value) == i);
|
163
|
+
qmlbind_value_release(value);
|
164
|
+
}
|
165
|
+
|
166
|
+
qmlbind_value_release(array);
|
167
|
+
}
|
168
|
+
|
169
|
+
SECTION("set / get prototype")
|
170
|
+
{
|
171
|
+
auto proto = qmlbind_engine_new_object(engine);
|
172
|
+
|
173
|
+
{
|
174
|
+
auto prop = qmlbind_value_new_number(123);
|
175
|
+
qmlbind_value_set_property(proto, "prop", prop);
|
176
|
+
qmlbind_value_release(prop);
|
177
|
+
}
|
178
|
+
|
179
|
+
auto obj = qmlbind_engine_new_object(engine);
|
180
|
+
qmlbind_value_set_prototype(obj, proto);
|
181
|
+
|
182
|
+
{
|
183
|
+
auto prop = qmlbind_value_get_property(obj, "prop");
|
184
|
+
REQUIRE(qmlbind_value_get_number(prop) == 123);
|
185
|
+
qmlbind_value_release(prop);
|
186
|
+
}
|
187
|
+
|
188
|
+
auto gotProto = qmlbind_value_get_prototype(obj);
|
189
|
+
REQUIRE(qmlbind_value_is_identical(proto, gotProto));
|
190
|
+
|
191
|
+
qmlbind_value_release(obj);
|
192
|
+
qmlbind_value_release(proto);
|
193
|
+
qmlbind_value_release(gotProto);
|
194
|
+
}
|
195
|
+
|
196
|
+
SECTION("property manipulation")
|
197
|
+
{
|
198
|
+
auto proto = qmlbind_engine_new_object(engine);
|
199
|
+
|
200
|
+
{
|
201
|
+
auto prop = qmlbind_value_new_number(123);
|
202
|
+
qmlbind_value_set_property(proto, "inherited", prop);
|
203
|
+
qmlbind_value_release(prop);
|
204
|
+
}
|
205
|
+
|
206
|
+
auto obj = qmlbind_engine_new_object(engine);
|
207
|
+
qmlbind_value_set_prototype(obj, proto);
|
208
|
+
|
209
|
+
{
|
210
|
+
auto prop = qmlbind_value_new_number(456);
|
211
|
+
qmlbind_value_set_property(obj, "own", prop);
|
212
|
+
qmlbind_value_set_property(obj, "456", prop);
|
213
|
+
qmlbind_value_release(prop);
|
214
|
+
}
|
215
|
+
|
216
|
+
SECTION("#has_own_property")
|
217
|
+
{
|
218
|
+
REQUIRE(qmlbind_value_has_own_property(obj, "own"));
|
219
|
+
REQUIRE(!qmlbind_value_has_own_property(obj, "inherited"));
|
220
|
+
}
|
221
|
+
|
222
|
+
SECTION("#has_property")
|
223
|
+
{
|
224
|
+
REQUIRE(qmlbind_value_has_property(obj, "own"));
|
225
|
+
REQUIRE(qmlbind_value_has_property(obj, "inherited"));
|
226
|
+
}
|
227
|
+
|
228
|
+
SECTION("#has_key")
|
229
|
+
{
|
230
|
+
REQUIRE(qmlbind_value_has_index(obj, 456));
|
231
|
+
}
|
232
|
+
|
233
|
+
SECTION("#delete_property")
|
234
|
+
{
|
235
|
+
REQUIRE(qmlbind_value_delete_property(obj, "own"));
|
236
|
+
REQUIRE(!qmlbind_value_has_property(obj, "own"));
|
237
|
+
}
|
238
|
+
|
239
|
+
qmlbind_value_release(obj);
|
240
|
+
qmlbind_value_release(proto);
|
241
|
+
}
|
242
|
+
|
243
|
+
SECTION("error")
|
244
|
+
{
|
245
|
+
auto value = qmlbind_engine_eval(engine, "throw new Error('hoge')", "file", 1);
|
246
|
+
REQUIRE(qmlbind_value_is_error(value));
|
247
|
+
qmlbind_value_release(value);
|
248
|
+
}
|
249
|
+
|
250
|
+
qmlbind_value_release(global);
|
251
|
+
qmlbind_engine_release(engine);
|
252
|
+
}
|