Allow v8 autotest to run without Qt
authorAaron Kennedy <aaron.kennedy@nokia.com>
Fri, 10 Jun 2011 01:53:56 +0000 (11:53 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Fri, 10 Jun 2011 01:53:56 +0000 (11:53 +1000)
tests/auto/declarative/v8/Makefile.nonqt [new file with mode: 0644]
tests/auto/declarative/v8/README.txt [new file with mode: 0644]
tests/auto/declarative/v8/tst_v8.cpp
tests/auto/declarative/v8/v8.pro
tests/auto/declarative/v8/v8main.cpp [new file with mode: 0644]
tests/auto/declarative/v8/v8test.cpp [new file with mode: 0644]
tests/auto/declarative/v8/v8test.h [new file with mode: 0644]

diff --git a/tests/auto/declarative/v8/Makefile.nonqt b/tests/auto/declarative/v8/Makefile.nonqt
new file mode 100644 (file)
index 0000000..20be72e
--- /dev/null
@@ -0,0 +1,11 @@
+release-m32:
+       g++ -o v8test_release_m32 -m32 -O2 v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8
+
+debug-m32:
+       g++ -o v8test_debug_m32 -m32 -g v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8_g
+
+release:
+       g++ -o v8test_release -O2 v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8
+
+debug:
+       g++ -o v8test_debug -g v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8_g
diff --git a/tests/auto/declarative/v8/README.txt b/tests/auto/declarative/v8/README.txt
new file mode 100644 (file)
index 0000000..a5df620
--- /dev/null
@@ -0,0 +1,13 @@
+The v8 tests are actually implemented in v8test.[h|cpp].  There are also QtTest
+(tst_v8.cpp) and non-Qt (v8main.cpp) stubs provided to run these tests.  This
+is done to allow the tests to be run both in the Qt CI system, and manually 
+without a build of Qt.  The latter is necessary to run them against more exotic
+build of V8, like the ARM simulator.
+
+To build the non-Qt version of the tests, first build a debug or release V8 
+library under src/3rdparty/v8 using scons, and then use the Makefile.nonqt
+makefile selecting one of the following targets:
+    release: Build the tests with -O2 and link against libv8
+    debug: Build the tests with -g and link against libv8_g
+    release-m32: Build the tests with -O2 -m32 and link against libv8
+    debug-m32: Build the tests with -g -m32 and link against libv8_g
index 740bd89..4749da0 100644 (file)
@@ -39,7 +39,7 @@
 **
 ****************************************************************************/
 #include <qtest.h>
-#include "../../../../src/3rdparty/v8/include/v8.h"
+#include "v8test.h"
 
 using namespace v8;
 
@@ -51,37 +51,14 @@ public:
 
 private slots:
     void initTestCase() {}
-    void cleanupTestCase();
+    void cleanupTestCase() {}
 
     void eval();
-
-private:
-    Persistent<Context> context;
 };
 
 void tst_v8::eval()
 {
-    HandleScope handle_scope;
-    context = Context::New();
-    Context::Scope context_scope(context);
-
-    Local<Object> qmlglobal = Object::New();
-    qmlglobal->Set(String::New("a"), v8::Integer::New(1922));
-
-    Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL, 
-                                           Handle<String>(), Script::QmlMode);
-    
-    TryCatch tc;
-    Local<Value> result = script->Run(qmlglobal);
-
-    QVERIFY(!tc.HasCaught());
-    QCOMPARE(result->Int32Value(), 1922);
-}
-
-void tst_v8::cleanupTestCase()
-{
-    context.Dispose();
-    context = Persistent<Context>();
+    QVERIFY(v8test_eval());
 }
 
 int main(int argc, char *argv[]) 
index 0fc27d8..1030d17 100644 (file)
@@ -1,7 +1,8 @@
 load(qttest_p4)
 macx:CONFIG -= app_bundle
 
-SOURCES += tst_v8.cpp 
+SOURCES += tst_v8.cpp v8test.cpp
+HEADERS += v8test.h
 
 CONFIG += parallel_test
 
diff --git a/tests/auto/declarative/v8/v8main.cpp b/tests/auto/declarative/v8/v8main.cpp
new file mode 100644 (file)
index 0000000..bf37e2d
--- /dev/null
@@ -0,0 +1,16 @@
+#include "v8test.h"
+#include <stdio.h>
+
+#define RUN_TEST(testname) { \
+    if (!v8test_ ## testname()) \
+        printf ("Test %s FAILED\n", # testname); \
+} 
+
+int main(int argc, char *argv[])
+{
+    v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+
+    RUN_TEST(eval);
+
+    return -1;
+}
diff --git a/tests/auto/declarative/v8/v8test.cpp b/tests/auto/declarative/v8/v8test.cpp
new file mode 100644 (file)
index 0000000..9b80b08
--- /dev/null
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "v8test.h"
+
+using namespace v8;
+
+#define BEGINTEST() bool _testPassed = true;
+#define ENDTEST() return _testPassed;
+
+#define VERIFY(expr) { \
+    if (!(expr)) { \
+        _testPassed = false; \
+        goto cleanup; \
+    }  \
+}
+
+
+bool v8test_eval()
+{
+    BEGINTEST();
+
+    HandleScope handle_scope;
+    v8::Persistent<v8::Context> context = Context::New();
+    Context::Scope context_scope(context);
+
+    Local<Object> qmlglobal = Object::New();
+    qmlglobal->Set(String::New("a"), v8::Integer::New(1922));
+
+    Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL, 
+                                           Handle<String>(), Script::QmlMode);
+    
+    TryCatch tc;
+    Local<Value> result = script->Run(qmlglobal);
+
+    VERIFY(!tc.HasCaught());
+    VERIFY(result->Int32Value() == 1922);
+
+cleanup:
+    context.Dispose();
+
+    ENDTEST();
+}
+
diff --git a/tests/auto/declarative/v8/v8test.h b/tests/auto/declarative/v8/v8test.h
new file mode 100644 (file)
index 0000000..f887846
--- /dev/null
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef V8TEST_H
+#define V8TEST_H
+
+#include "../../../../src/3rdparty/v8/include/v8.h"
+
+bool v8test_eval();
+
+#endif // V8TEST_H
+