commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1085936 - in /commons/sandbox/runtime/trunk: ./ src/main/native/ src/main/native/include/acr/ src/main/native/os/linux/ src/main/native/shared/ src/main/test/org/apache/commons/runtime/
Date Sun, 27 Mar 2011 13:50:22 GMT
Author: mturk
Date: Sun Mar 27 13:50:21 2011
New Revision: 1085936

URL: http://svn.apache.org/viewvc?rev=1085936&view=rev
Log:
Start adding TestNG cases

Added:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/system.c   (with props)
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java 
 (with props)
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/build.xml
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
    commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/native/shared/native.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java

Modified: commons/sandbox/runtime/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Sun Mar 27 13:50:21 2011
@@ -368,9 +368,14 @@ The Apache Software Foundation (http://w
     <!-- =================================================================== -->
     <target name="test" depends="tests">
         <testng outputdir="${build.dir}/out/report"
-                workingdir="${build.dir}/out">
+                workingdir="${build.dir}/out"
+                verbose="1"
+                haltOnfailure="true"
+                suitename="${name} Test Suite">
             <classpath refid="test.classpath"/>
-            <classfileset dir="${build.dest}/test" includes="**/*.class"/>
+            <classfileset dir="${build.dest}/test">
+                <include name="**/*.class"/>
+            </classfileset>
             <env key="PATH" path="${runtime.library.path}${path.separator}${java.library.path}"/>
             <env key="Path" path="${runtime.library.path}${path.separator}${java.library.path}"/>
             <jvmarg value="-Djava.library.path=${runtime.library.path}"/>

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Sun Mar 27 13:50:21 2011
@@ -95,6 +95,7 @@ LIBSOURCES=\
 	$(TOPDIR)/shared/object.c \
 	$(TOPDIR)/shared/observer.c \
 	$(TOPDIR)/shared/string.c \
+	$(TOPDIR)/shared/system.c \
 	$(TOPDIR)/shared/unsafe.c \
 	$(TOPDIR)/shared/version.c \
 	$(TOPDIR)/shared/buildmark.c

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Sun Mar 27 13:50:21 2011
@@ -94,7 +94,7 @@ includes="$INCLUDES"
 ssldflags=""
 bige=0
 so=.so
-dllext=.so
+sx=.so
 lib=.a
 obj=o
 bits=""
@@ -638,7 +638,7 @@ case "$host-$cctype" in
         varadds asflags +Z
         if [ ".$mach" = .parisc ]; then
             so=.sl
-            dllext=.sl
+            sx=.sl
         fi
         varadds shflags +Z -b
         if [ ".$has_shared_version" = .yes ]; then
@@ -852,7 +852,7 @@ int hello() {return getchar();}
 EOF
     do_printf 'Checking for %-32s' "shared library support"
     cl="$cc -c $ccflags $ccshare $cppopts $cccsrc.c -o $cccsrc.$obj"
-    ll="$ld $lddarch $shflags $cccsrc.$obj $ldflags -o $cccsrc$dllext"
+    ll="$ld $lddarch $shflags $cccsrc.$obj $ldflags -o $cccsrc$sx"
     co="`eval $cl 2>&1`"
     if [ ".$co" = "." ]; then
         co="`eval $ll 2>&1`"
@@ -1359,7 +1359,7 @@ extern "C" {
 #define PACKAGE_INCDIR          "$incdir"
 #define PACKAGE_SHAREDIR        "$shrdir"
 #define PACKAGE_CONFIGURED      "`date -u`"
-#define PACKAGE_DLLEXT          "$dllext"
+#define PACKAGE_DLLEXT          "$sx"
 #define PACKAGE_JNIEXT          "$so"
 
 #define CC_BITS                 $bits
@@ -1431,7 +1431,6 @@ CC=$cc
 CPP=$cpp
 LD=$ld
 SO=$so
-DLLEXT=$dllext
 LIB=$lib
 OBJ=$obj
 SLO=l$obj

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h Sun Mar 27 13:50:21
2011
@@ -56,9 +56,6 @@ int
 AcrInitCoreClasses(JNI_STDENV);
 
 int
-AcrInitOptionalClasses(JNI_STDENV);
-
-int
 AcrLoadRuntimeClasses(JNI_STDENV);
 
 void
@@ -72,13 +69,6 @@ jclass
 AcrGetCoreClass(int clazz);
 
 /**
- * Get optional class instance.
- * @param clazz Class to get. See acr_cclass_e enum
- */
-jclass
-AcrGetOptionalClass(int clazz);
-
-/**
  * Get core object array instance.
  * @param env Current JNI environment.
  * @param clazz Class to get. See acr_cclass_e enum
@@ -87,7 +77,6 @@ AcrGetOptionalClass(int clazz);
 jobjectArray
 AcrNewCoreObjectArray(JNI_STDENV, int clazz, jsize len);
 
-
 /**
  * Load and reference the class.
  * @param env Current JNI environment.

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Sun Mar 27 13:50:21
2011
@@ -1613,6 +1613,9 @@ extern "C" {
 #endif
 
 void
+AcrReleaseExceptionClasses(JNI_STDENV);
+
+void
 AcrFatalError(JNI_STDENV,
               const char *filename, const char *funcname, int lineno,
               int error, const char *msg, ...);

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Sun Mar 27 13:50:21
2011
@@ -34,6 +34,16 @@
     ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_##CL##_##MN
 #define ACR_JNX_EXPORT(RT, CP, CL, MN)  \
     ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_##CP##_##CL##_##MN
+#define ACR_OS_EXPORT(RT, CP, CL, MN)  \
+    ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_##CP##_##CL##_##MN
+#define ACR_WIN_EXPORT(RT, CL, MN)  \
+    ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_windows_##CL##_##MN
+#define ACR_IO_EXPORT(RT, CL, MN)  \
+    ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_io_##CL##_##MN
+#define ACR_NET_EXPORT(RT, CL, MN)  \
+    ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_net_##CL##_##MN
+#define ACR_UTIL_EXPORT(RT, CL, MN)  \
+    ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_net_##CL##_##MN
 
 #define JNI_STDARGS             JNIEnv *_E, jobject _O
 #define JNI_STDENV              JNIEnv *_E

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h Sun Mar 27 13:50:21
2011
@@ -57,6 +57,14 @@ AcrGetJavaStringW(JNI_STDENV, jstring s,
 char *
 AcrGetJavaStringA(JNI_STDENV, jstring s, char *b);
 
+/** Convert java string to UTF-8 char string.
+ * @param env Current JNI environment.
+ * @param s String to convert.
+ * @remark When done use ACR_Free to free the allocated memory.
+ */
+char *
+AcrGetJavaStringU(JNI_STDENV, jstring s, char *b);
+
 /** Convert java string array to platform char string array.
  * @param env Current JNI environment.
  * @param a String array to convert.

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h?rev=1085936&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h Sun Mar 27 13:50:21
2011
@@ -0,0 +1,63 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_SYSTEM_H
+#define _ACR_SYSTEM_H
+
+#include "acr/jniapi.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ACR_CLASS_CTOR(System);
+ACR_CLASS_DTOR(System);
+
+/**
+ * @file system.h
+ * @brief
+ *
+ * ACR java.lang.System support.
+ *
+ */
+
+/**
+ * Run the System.exit.
+ * @param env Current JNI environment
+ * @param status exit status.
+ * @return ACR error code.
+ */
+int
+AcrSystemExit(JNI_STDENV, jint status);
+
+/**
+ * Run the System.getProperty.
+ * @param env Current JNI environment
+ * @param key the name of the system property.
+ * @return the string value of the system property, or null if
+ * there is no property with that key. Use ACR_Free when the returned
+ * string is no longer needed.
+ */
+char *
+AcrSystemGetPropertyA(JNI_STDENV, const char *key);
+wchar_t *
+AcrSystemGetPropertyW(JNI_STDENV, const wchar_t *key);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_SYSTEM_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/system.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c Sun Mar 27 13:50:21 2011
@@ -39,7 +39,7 @@ int IsSelinuxEnabled()
     return (*sef)();
 }
 
-ACR_JNX_EXPORT(jboolean, platform_linux, Selinux, enabled0)(JNI_STDARGS)
+ACR_OS_EXPORT(jboolean, linux, Selinux, enabled0)(JNI_STDARGS)
 {
     return V2Z(IsSelinuxEnabled());
-}
\ No newline at end of file
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sun Mar 27 13:50:21 2011
@@ -15,10 +15,12 @@
  */
 
 #include "acr/clazz.h"
+#include "acr/misc.h"
 /* Runtime class includes */
 #include "acr/object.h"
 #include "acr/unsafe.h"
 #include "acr/string.h"
+#include "acr/system.h"
 #include "acr/callback.h"
 #include "acr/observer.h"
 
@@ -147,14 +149,7 @@ static struct {
     { 0,                            0 }
 };
 
-static struct {
-    const char *name;
-    jclass      clazz;
-} opts_classes[] = {
-    { "java/nio/Path",              0 },
-    { 0,                            0 }
-};
-
+static
 ACR_CLASS_CTOR(Class)
 {
     int rv;
@@ -181,6 +176,12 @@ ACR_CLASS_CTOR(Class)
     return 0;
 }
 
+static
+ACR_CLASS_DTOR(Class)
+{
+    AcrUnloadClass(_E, &_clazzn);
+}
+
 int
 AcrInitCoreClasses(JNI_STDENV)
 {
@@ -208,34 +209,8 @@ AcrInitCoreClasses(JNI_STDENV)
     ACR_CLASS_LOAD(Object);
     ACR_CLASS_LOAD(Class);
     ACR_CLASS_LOAD(String);
-    return 0;
-}
-
-int
-AcrInitOptionalClasses(JNI_STDENV)
-{
-    int i = 0;
-
-    if (opts_classes[0].clazz)
-        return 0;
-    while (opts_classes[i].name) {
-        jobject o = (jobject)(*_E)->FindClass(_E, opts_classes[i].name);
-        if (o != 0) {
-            opts_classes[i].clazz = (jclass)(*_E)->NewGlobalRef(_E, o);
-            (*_E)->DeleteLocalRef(_E, o);
-            if (opts_classes[i].clazz == 0) {
-                /* Reference failed */
-                return ACR_ENOMEM;
-            }
-        }
-        else {
-            /* Not found.
-             * Clear any pending exceptions so we can continue the loop
-             */
-            (*_E)->ExceptionClear(_E);
-        }
-        i++;
-    }
+    ACR_CLASS_LOAD(System);
+    ACR_CLASS_LOAD(Observer);
     return 0;
 }
 
@@ -244,7 +219,6 @@ AcrLoadRuntimeClasses(JNI_STDENV)
 {
     ACR_CLASS_LOPT(Unsafe);
     ACR_CLASS_LOAD(Callback);
-    ACR_CLASS_LOAD(Observer);
 
 #ifdef WIN32
 
@@ -257,9 +231,16 @@ AcrUnloadRuntimeClasses(JNI_STDENV)
 {
 
     ACR_CLASS_UNLOAD(Callback);
+    ACR_CLASS_UNLOAD(Observer);
+    ACR_CLASS_UNLOAD(Unsafe);
+    ACR_CLASS_UNLOAD(String);
+    ACR_CLASS_UNLOAD(System);
+    ACR_CLASS_UNLOAD(Object);
+    ACR_CLASS_UNLOAD(Class);
 #ifdef WIN32
 
 #endif
+    AcrReleaseExceptionClasses(_E);
 }
 
 jclass
@@ -271,15 +252,6 @@ AcrGetCoreClass(int clazz)
         return 0;
 }
 
-jclass
-AcrGetOptionalClass(int clazz)
-{
-    if (clazz >= 0 && clazz < ACR_CO_MAX)
-        return opts_classes[clazz].clazz;
-    else
-        return 0;
-}
-
 jobjectArray
 AcrNewCoreObjectArray(JNI_STDENV, int clazz, jsize len)
 {

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sun Mar 27 13:50:21 2011
@@ -19,6 +19,7 @@
 #include "acr/jniapi.h"
 #include "acr/string.h"
 #include "acr/port.h"
+#include "acr/misc.h"
 
 static struct {
     jclass      clazz;
@@ -594,8 +595,7 @@ AcrThrow(JNI_STDENV, int cls, const char
     if (cls < 0 && cls >= ACR_EX_LEN)
         cls = 0;
     if (IS_INVALID_HANDLE(_E)) {
-        ACR_DEBUG_TRACE("JNI Environment is invalid or unavailable (%d).", ACR_GET_OS_ERROR());
-        ACR_DEBUG_TRACE("Throwing class '%s'", _throw_classes[cls].name);
+        ACR_DEBUG_TRACE("JNI Environment is invalid or unavailable. Throwing '%s'", _throw_classes[cls].name);
         if (msg) {
             ACR_DEBUG_TRACE("%s", msg);
         }
@@ -623,13 +623,13 @@ AcrThrow(JNI_STDENV, int cls, const char
             }
             return;
         }
+        AcrLibLockAcquire();
         if (_throw_classes[cls].clazz == 0) {
-            /* XXX: This should be guarded by a mutex
-             * incase multiple threads throw united exception
-             * for the first time.
+            /* Create a global reference to the class.
              */
             _throw_classes[cls].clazz = (jclass)(*_E)->NewGlobalRef(_E, ec);
         }
+        AcrLibLockRelease();
         if (_throw_classes[cls].clazz == 0)
             return;
         (*_E)->DeleteLocalRef(_E, ec);
@@ -689,7 +689,19 @@ AcrThrowException(JNI_STDENV, int cls, i
     AcrThrow(_E, cls, msg);
 }
 
-ACR_JNX_EXPORT(jstring, io, Status, describe)(JNI_STDARGS, jint err)
+void
+AcrReleaseExceptionClasses(JNI_STDENV)
+{
+    int i;
+    for (i = 0; i < ACR_EX_LEN; i++) {
+        if (_throw_classes[i].clazz != 0) {
+            (*_E)->DeleteGlobalRef(_E,_throw_classes[i].clazz);
+            _throw_classes[i].clazz = 0;
+        }
+    }
+}
+
+ACR_IO_EXPORT(jstring, Status, describe)(JNI_STDARGS, jint err)
 {
     char buf[ACR_MBUFF_SIZ] = "";
 
@@ -697,7 +709,7 @@ ACR_JNX_EXPORT(jstring, io, Status, desc
     return AcrNewJavaStringA(_E, buf);
 }
 
-ACR_JNX_EXPORT(jboolean, io, Status, is0)(JNI_STDARGS, jint what, jint err)
+ACR_IO_EXPORT(jboolean, Status, is0)(JNI_STDARGS, jint what, jint err)
 {
     jboolean rv = JNI_FALSE;
     switch (what) {

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Sun Mar 27 13:50:21 2011
@@ -16,6 +16,7 @@
 
 #include "acr/clazz.h"
 
+static jboolean _loaded = JNI_FALSE;
 ACR_JNI_EXPORT(jboolean, Native, isdbg0)(JNI_STDARGS)
 {
 #if defined(DEBUG) || defined(_DEBUG)
@@ -29,5 +30,14 @@ ACR_JNI_EXPORT(jboolean, Native, init0)(
 {
     if (AcrLoadRuntimeClasses(_E) != 0)
         return JNI_FALSE;
-    return JNI_TRUE;
+    _loaded = JNI_TRUE;
+    return _loaded;
+}
+
+ACR_JNI_EXPORT(void, Native, clr0)(JNI_STDARGS)
+{
+    if (_loaded) {
+        _loaded = JNI_FALSE;
+        AcrUnloadRuntimeClasses(_E);
+    }
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Sun Mar 27 13:50:21 2011
@@ -876,6 +876,15 @@ AcrGetJavaStringA(JNIEnv *_E, jstring st
     return rv;
 }
 
+char *
+AcrGetJavaStringU(JNIEnv *_E, jstring str, char *b)
+{
+    if (str == 0)
+        return 0;
+    else
+        return get_string_utf_8(_E, str, b);
+}
+
 jstring
 AcrNewJavaStringW(JNIEnv *_E, const wchar_t *s)
 {
@@ -948,3 +957,26 @@ AcrNewJavaStringU(JNIEnv *_E, const char
     }
     return new_string_utf_8(_E, str);
 }
+
+#if defined(ENABLE_TEST_PRIVATE)
+
+ACR_JNI_EXPORT(jint, TestString, test0)(JNI_STDARGS, jstring s)
+{
+    char *cstr;
+    jint  clen;
+    cstr = AcrGetJavaStringU(_E, s, 0);
+    clen = (jint)strlen(cstr);
+    AcrFree(cstr);
+    return clen;
+}
+
+ACR_JNI_EXPORT(jint, TestString, test1)(JNI_STDARGS, jstring s)
+{
+    wchar_t *wstr;
+    jint  wlen;
+    wstr = AcrGetJavaStringW(_E, s, 0);
+    wlen = (jint)wcslen(wstr);
+    AcrFree(wstr);
+    return wlen;
+}
+#endif

Added: commons/sandbox/runtime/trunk/src/main/native/shared/system.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/system.c?rev=1085936&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/system.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/system.c Sun Mar 27 13:50:21 2011
@@ -0,0 +1,128 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/clazz.h"
+#include "acr/string.h"
+#include "acr/system.h"
+
+J_DECLARE_CLAZZ = {
+    0,
+    0,
+    0,
+    0,
+    "java/lang/System"
+};
+
+J_DECLARE_M_ID(0000) = {
+    0,
+    "exit",
+    "(I)V"
+};
+
+J_DECLARE_M_ID(0001) = {
+    0,
+    "getProperty",
+    "(Ljava/lang/String;)Ljava/lang/String;"
+};
+
+ACR_CLASS_CTOR(System)
+{
+    int rv;
+
+    if ((rv = AcrLoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_MLOCAL(0000);
+    J_LOAD_MLOCAL(0001);
+
+    return ACR_SUCCESS;
+}
+
+ACR_CLASS_DTOR(System)
+{
+    AcrUnloadClass(_E, &_clazzn);
+}
+
+int
+AcrSystemExit(JNI_STDENV, jint status)
+{
+    if (_E == 0)
+        _E = AcrGetJNIEnv();
+    if (IS_INVALID_HANDLE(_E))
+        return ACR_ENOJNIENV;
+    CALL_VMLOCAL1(0000, status);
+    if ((*_E)->ExceptionCheck(_E) == JNI_TRUE) {
+        (*_E)->ExceptionClear(_E);
+        /* System.exit() can throw only SecurityException
+         */
+        return ACR_EACCES;
+    }
+    return 0;
+}
+
+char *
+AcrSystemGetPropertyA(JNI_STDENV, const char *key)
+{
+    char *val = NULL;
+    jstring skey;
+    jstring sval;
+
+    if (_E == 0)
+        _E = AcrGetJNIEnv();
+    if (IS_INVALID_HANDLE(_E)) {
+        ACR_SET_OS_ERROR(ACR_ENOJNIENV);
+        return NULL;
+    }
+    skey = AcrNewJavaStringA(_E, key);
+    if (skey == 0)
+        return 0;
+    sval = (jstring)CALL_MLOCAL1(Object, 0001, skey);
+    (*_E)->DeleteLocalRef(_E, skey);
+    if (sval) {
+        val = AcrGetJavaStringA(_E, sval, NULL);
+        (*_E)->DeleteLocalRef(_E, sval);
+    }
+    return val;
+}
+
+wchar_t *
+AcrSystemGetPropertyW(JNI_STDENV, const wchar_t *key)
+{
+    wchar_t *val = NULL;
+    jstring skey;
+    jstring sval;
+
+    if (_E == 0)
+        _E = AcrGetJNIEnv();
+    if (IS_INVALID_HANDLE(_E)) {
+        ACR_SET_OS_ERROR(ACR_ENOJNIENV);
+        return NULL;
+    }
+    skey = AcrNewJavaStringW(_E, key);
+    if (skey == 0)
+        return 0;
+    sval = (jstring)CALL_MLOCAL1(Object, 0001, skey);
+    (*_E)->DeleteLocalRef(_E, skey);
+    if (sval) {
+        val = AcrGetJavaStringW(_E, sval, NULL);
+        (*_E)->DeleteLocalRef(_E, sval);
+    }
+    return val;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/system.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Sun Mar 27 13:50:21 2011
@@ -194,7 +194,7 @@ ACR_JNI_EXPORT(jint, Unsafe, get3)(JNI_S
 }
 
 #if defined(ENABLE_TEST_PRIVATE)
-ACR_JNI_EXPORT(jint, TestUnsafe, get0)(JNI_STDARGS, jobject o, jint off)
+ACR_JNI_EXPORT(jint, TestUnsafe, test0)(JNI_STDARGS, jobject o, jint off)
 {
     if (o != 0 && off > 0) {
         char *oa = *(char **)o;
@@ -205,10 +205,4 @@ ACR_JNI_EXPORT(jint, TestUnsafe, get0)(J
     }
     return 0;
 }
-
-ACR_JNI_EXPORT(jint, TestUnsafe, get1)(JNI_STDARGS, jobject o)
-{
-    return AcrUnsafeObjectFieldOffset(_E, o);
-}
-
 #endif

Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java?rev=1085936&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java Sun
Mar 27 13:50:21 2011
@@ -0,0 +1,30 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.testng.annotations.*;
+import org.testng.Assert;
+
+public class TestMain
+{
+    @BeforeSuite
+    public void setUp()
+    {
+        Assert.assertTrue(Loader.load());
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java?rev=1085936&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
Sun Mar 27 13:50:21 2011
@@ -0,0 +1,45 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.testng.annotations.*;
+import org.testng.Assert;
+import java.io.IOException;
+
+public class TestString
+{
+
+    /* Zwölf in UTF-8 */
+    static private final byte[] gUIF = { (byte)0x5a, (byte)0x77, (byte)0xc3, (byte)0xb6,
(byte)0x6c, (byte)0x66 };
+    static private native int test0(String s);
+    static private native int test1(String s);
+
+    @Test(groups = { "private" })
+    public void getStrlenTestA()
+    {
+        String s = new String(gUIF);
+        Assert.assertEquals(6, test0(s));
+    }
+
+    @Test(groups = { "private" })
+    public void getStrlenTestW()
+    {
+        String s = new String(gUIF);
+        Assert.assertEquals(5, test1(s));
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java?rev=1085936&r1=1085935&r2=1085936&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUtils.java
Sun Mar 27 13:50:21 2011
@@ -16,25 +16,15 @@
 
 package org.apache.commons.runtime;
 
-import org.testng.annotations.*;
-import org.testng.Assert;
 import java.io.IOException;
 import java.io.File;
-
+import org.testng.annotations.*;
+import org.testng.Assert;
 import org.apache.commons.runtime.util.Utils;
 
 public class TestUtils
 {
 
-    @BeforeClass
-    public void setUp()
-    {
-        Assert.assertTrue(Loader.load());
-        System.out.println("Running tests on " + Os.getSysname() +
-                                                 Os.getDataModel() + " (" +
-                                                 Os.getNodename()  + ")");
-    }
-
     @Test(groups = { "utils" })
     public void getTempPathTest()
     {
@@ -45,9 +35,9 @@ public class TestUtils
     public void createTempDirectoryTest()
         throws IOException
     {
-        File tmp = Utils.createTempDirectory("t1");
+        File tmp = Utils.createTempDirectory("acrTest");
         Assert.assertNotNull(tmp);
-        System.out.println("Created directory " + tmp.getPath());
+        System.out.println("Utils.createTempDirectory: `" + tmp.getPath() + "'");
         Assert.assertTrue(Utils.deleteDirectory(tmp));
     }
 



Mime
View raw message