summaryrefslogtreecommitdiffstats
path: root/kjsembed/cpptests/jsaccess
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/cpptests/jsaccess
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
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
Diffstat (limited to 'kjsembed/cpptests/jsaccess')
-rw-r--r--kjsembed/cpptests/jsaccess/Makefile.am18
-rw-r--r--kjsembed/cpptests/jsaccess/jsaccess.cpp106
2 files changed, 124 insertions, 0 deletions
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 <geiseri@kde.org>
+ *
+ * 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 <kdebug.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kjs/interpreter.h>
+
+#include <kjsembed/jsconsolewidget.h>
+#include <kjsembed/jsobjectproxy.h>
+#include <kjsembed/jsfactory.h>
+#include <kjsembed/kjsembedpart.h>
+#include <kjsembed/jssecuritypolicy.h>
+
+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;
+}