From 90825e2392b2d70e43c7a25b8a3752299a933894 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kjsembed/cpptests/Makefile.am | 2 + kjsembed/cpptests/jsaccess/Makefile.am | 18 ++++++ kjsembed/cpptests/jsaccess/jsaccess.cpp | 106 ++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 kjsembed/cpptests/Makefile.am create mode 100644 kjsembed/cpptests/jsaccess/Makefile.am create mode 100644 kjsembed/cpptests/jsaccess/jsaccess.cpp (limited to 'kjsembed/cpptests') diff --git a/kjsembed/cpptests/Makefile.am b/kjsembed/cpptests/Makefile.am new file mode 100644 index 00000000..f70b1e8b --- /dev/null +++ b/kjsembed/cpptests/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = jsaccess + diff --git a/kjsembed/cpptests/jsaccess/Makefile.am b/kjsembed/cpptests/jsaccess/Makefile.am new file mode 100644 index 00000000..eda2e3e1 --- /dev/null +++ b/kjsembed/cpptests/jsaccess/Makefile.am @@ -0,0 +1,18 @@ +# -*- makefile -*- + +# Make sure the include path includes Qt's uilib +INCLUDES = -I$(QTDIR)/tools/designer/uilib -I$(srcdir)/../../../.. -I.. -I$(top_srcdir) $(all_includes) + +INCLUDES += -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST + +bin_PROGRAMS = jsaccess + +jsaccess_SOURCES = jsaccess.cpp +jsaccess_LDFLAGS = $(all_libraries) $(KDE_RPATH) +jsaccess_LDADD = $(top_builddir)/kjsembed/libkjsembed.la + +METASOURCES = AUTO + + + + diff --git a/kjsembed/cpptests/jsaccess/jsaccess.cpp b/kjsembed/cpptests/jsaccess/jsaccess.cpp new file mode 100644 index 00000000..5693ceea --- /dev/null +++ b/kjsembed/cpptests/jsaccess/jsaccess.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2004 Ian Reinhart Geiser + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace KJSEmbed; + +int main( int argc, char **argv ) +{ + KAboutData about( "test-kjsembed", I18N_NOOP("KJS Embed Test For C++ access of variables and functions."), "0.1", + I18N_NOOP("Test"), + KAboutData::License_LGPL, I18N_NOOP("(c) 2004 Ian Reinhart Geiser") ); + KCmdLineArgs::init( argc, argv, &about ); + KApplication app; + + // Setup Interpreter + KJSEmbed::JSSecurityPolicy::setDefaultPolicy( KJSEmbed::JSSecurityPolicy::CapabilityAll ); + KJSEmbed::KJSEmbedPart *part = new KJSEmbed::KJSEmbedPart; + KJS::Interpreter *js = part->interpreter(); + KJS::ExecState *exec = js->globalExec(); + + QString script = "var foobar = \"test from javascript.\";" + "function testNoArgsFunction( ){ return foobar; }" + "function testNoReturnFunction( value ){ foobar = value; }" + "function testFunction( value ){ return \"testFunction dorks with \" + value;}"; + KJS::Value returnValue = part->evaluate(script,js->globalObject()); + if( returnValue.isValid() && !returnValue.toBoolean(exec ) ) + kdWarning() << "Script failed to run." << endl; + + /** + * Test extraction of a Variant from javascript + */ + QString value = part->getVariant("foobar").toString(); + if( value != "test from javascript." ) + kdWarning() << "Get variant failed with: " << value << endl; + + /** + * Test manipulation of a Variant from C++ + */ + part->putVariant("foobar", "test from C++."); + value = part->getVariant("foobar").toString(); + if( value != "test from C++." ) + kdWarning() << "Put variant failed with: " << value << endl; + + /** + * Test to see if a function is present + */ + if( !part->hasMethod("testFunction") ) + kdWarning() << "error finding testFunction" << endl; + + if( part->hasMethod("foobar") ) + kdWarning() << "error i found a value and was looking for a method" << endl; + /** + * Test calling function that takes an arg, and returns a value. + */ + KJS::List args; + args.append(KJS::String("C++ String")); + value = part->callMethod("testFunction", args).toString(exec).qstring(); + if ( value != "testFunction dorks with C++ String" ) + kdWarning() << "error calling testFunction, wanted \"testFunction dorks with C++ String\" but got " << value << endl; + + /** + * Test calling function that takes an arg, and returns nothing. + */ + args.clear(); + args.append(KJS::String("C++ String")); + returnValue = part->callMethod("testNoReturnFunction", args); + if ( returnValue.isNull() ) + kdWarning() << "error calling testNoReturnFunction is suppose to be null and was " << returnValue.toString(exec).qstring() << endl; + /** + * Test calling function that takes no args, and returns a value + */ + args.clear(); + value = part->callMethod("testNoArgsFunction", args).toString(exec).qstring(); + if ( value != "C++ String" ) + kdWarning() << "error calling testNoArgsFunction, wanted \"C++ String\" but got " << value << endl; + return 1; +} -- cgit v1.2.1