void EnvironmentTestCase::testEvaluateCallRegFunction() {
    Environment engine;

    engine.registerFunction( "arg", QtScriptFunctions::arg );

    ASSERT_EQUAL( engine.callFunction( "arg" ).isUndefined(), true );
    ASSERT_EQUAL( engine.callFunction( "arg", 5 ).toNumber(), 5 );
    ASSERT_EXCEPTION( engine.callFunction( "arg", 5, engine.newArray() ), ScriptException );
};
void RegistrationClassTestCase::testRegisterStaticMethods() {
    Environment engine;

    QSharedPointer<RegistrationClass> f( RegistrationClass::newClass<QtScriptObject>() );
    f->getStaticFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
    f->registerObject( engine.globalObject(), &engine );

    ASSERT_EQUAL( engine.callFunction( engine.globalObject().property( "QtScriptObject" ), "arg", 5 ).toInt32(), 5 );
};
void RegistrationClassTestCase::testRegisterExtendStaticMethods() {
    Environment engine;

    RegistrationClass f( "String" );
    f.getStaticFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
    f.registerObject( engine.globalObject(), &engine );

    ASSERT_EQUAL( engine.callFunction( engine.globalObject().property( "String" ), "arg", 5 ).toInt32(), 5 );
};
void RegistrationClassTestCase::testRegisterExtendDynamicMethods() {
    Environment engine;

    RegistrationClass f( "String" );
    f.getDynamicFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
    f.registerObject( engine.globalObject(), &engine );

    QScriptValue v = engine.evaluate( "new String();" );
    ASSERT_REQUIRE_EQUAL( v.isObject(), true );

    ASSERT_EQUAL( engine.callFunction( v, "arg", 5 ).toInt32(), 5 );
};
void RegistrationClassTestCase::testRegisterDynamicMethods() {
    Environment engine;

    QSharedPointer<RegistrationClass> f( RegistrationClass::newClass<QtScriptObject>() );
    f->getDynamicFunctions().push_back( RegistrationFunction( "arg", QtScriptFunctions::arg ) );
    f->registerObject( engine.globalObject(), &engine );

    QScriptValue v = engine.evaluate( "new QtScriptObject();" );
    ASSERT_REQUIRE_EQUAL( v.isObject(), true );

    ASSERT_EQUAL( engine.callFunction( v, "arg", 5 ).toInt32(), 5 );
};
void EnvironmentTestCase::testEvaluateCallScriptFunction() {
    Environment engine;

    QString script = "function fun() { return arguments.length; }";

    ASSERT_EQUAL( engine.evaluate( script ).isValid(), true );
    ASSERT_EQUAL( engine.callFunction( "fun" ).toInteger(), 0 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1 ).toInteger(), 1 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2 ).toInteger(), 2 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3 ).toInteger(), 3 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4 ).toInteger(), 4 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5 ).toInteger(), 5 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6 ).toInteger(), 6 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7 ).toInteger(), 7 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7, 8 ).toInteger(), 8 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7, 8, 9 ).toInteger(), 9 );
    ASSERT_EQUAL( engine.callFunction( "fun", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).toInteger(), 10 );
};