You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by to...@apache.org on 2008/03/04 09:02:45 UTC
svn commit: r633384 [7/15] - in /harmony/enhanced/classlib/branches/java6:
depends/build/platform/ depends/files/ depends/files/bcprov/ doc/
doc/classlib/ make/ make/linux.ia64/ make/linux.ppc32/ make/linux.ppc64/
make/linux.x86.libstdc++6/ make/linux....
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h Tue Mar 4 00:02:13 2008
@@ -104,10 +104,10 @@
/*
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
* Method: readSocketDirectImpl
- * Signature: (Ljava/io/FileDescriptor;JIII)I
+ * Signature: (Ljava/io/FileDescriptor;JII)I
*/
JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_readSocketDirectImpl
- (JNIEnv *, jclass, jobject, jlong, jint, jint, jint);
+ (JNIEnv *, jclass, jobject, jlong, jint, jint);
/*
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
@@ -120,10 +120,10 @@
/*
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
* Method: writeSocketDirectImpl
- * Signature: (Ljava/io/FileDescriptor;JII)I
+ * Signature: (Ljava/io/FileDescriptor;JI)I
*/
JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_writeSocketDirectImpl
- (JNIEnv *, jclass, jobject, jlong, jint, jint);
+ (JNIEnv *, jclass, jobject, jlong, jint);
/*
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/process.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/process.c?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/process.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/process.c Tue Mar 4 00:02:13 2008
@@ -136,6 +136,12 @@
case 1002 :
sprintf(errMsg, "Unable to start program : %s", "fork() failed with errno = EAGAIN");
break;
+ case 1003 :
+ sprintf(errMsg, "Unable to start program : %s", "too many open files");
+ break;
+ case 1004 :
+ sprintf(errMsg, "Unable to start program : %s", "no such file or directory");
+ break;
default:
sprintf(errMsg, "Unable to start program : %s", "unknown");
break;
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c Tue Mar 4 00:02:13 2008
@@ -241,6 +241,7 @@
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
* Method: selectImpl
* Signature: ([Ljava/io/FileDescriptor;[Ljava/io/FileDescriptor;II[IJ)I
+ * Assumption: outFlags is zeroed
*/
JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_selectImpl
(JNIEnv * env, jclass thisClz, jobjectArray readFDArray, jobjectArray writeFDArray,
@@ -287,24 +288,23 @@
result = poll(my_pollfds, n_pollfds, timeout);
if (result > 0) {
+ int changed = 0; /* Record if we actually change the IntArray */
/* output result to int array */
- flagArray = (*env)->GetIntArrayElements(env,outFlags, &isCopy);
+ flagArray = (*env)->GetIntArrayElements(env, outFlags, &isCopy);
for (val=0; val<countReadC; val++) {
if (my_pollfds[val].revents & (POLLIN | POLLPRI)) {
flagArray[val] = SOCKET_OP_READ;
- } else {
- flagArray[val] = SOCKET_OP_NONE;
+ changed=1;
}
}
for (val=0; val<countWriteC; val++) {
if (my_pollfds[val+countReadC].revents & POLLOUT) {
flagArray[val+countReadC] = SOCKET_OP_WRITE;
- } else {
- flagArray[val+countReadC] = SOCKET_OP_NONE;
+ changed=1;
}
}
- (*env)->ReleaseIntArrayElements(env, outFlags, flagArray, 0);
+ (*env)->ReleaseIntArrayElements(env, outFlags, flagArray, changed ? 0 : JNI_ABORT);
}
hymem_free_memory(my_pollfds);
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/helpers.c Tue Mar 4 00:02:13 2008
@@ -298,7 +298,37 @@
getCustomTimeZoneInfo (JNIEnv * env, jintArray tzinfo,
jbooleanArray isCustomTimeZone)
{
- return NULL;
+ time_t curTime;
+ struct tm *tmStruct;
+ char tzInfo[9];
+ int h, m;
+
+ time(&curTime);
+ //curTime += 15552000l;
+ tmStruct = localtime(&curTime);
+ // timezone is now set to time zone offset
+ // tmStruct->tm_isdst is set to 1 if DST is in effect
+ strcpy(tzInfo, "GMT");
+ tzInfo[3] = timezone > 0 ? '-' : '+';
+ h = labs(timezone) / 3600;
+ if (tmStruct->tm_isdst) {
+ if (timezone > 0) {
+ h--;
+ } else {
+ h++;
+ }
+ }
+ m = (labs(timezone) % 3600) / 60;
+ tzInfo[4] = h / 10 + '0';
+ tzInfo[5] = h % 10 + '0';
+ tzInfo[6] = m / 10 + '0';
+ tzInfo[7] = m % 10 + '0';
+ tzInfo[8] = 0;
+
+ jboolean fls = JNI_FALSE;
+
+ (*env)->SetBooleanArrayRegion(env, isCustomTimeZone, 0, 1, &fls);
+ return (*env)->NewStringUTF(env, tzInfo);
}
void
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c Tue Mar 4 00:02:13 2008
@@ -25,6 +25,7 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
+#include <fcntl.h>
#if defined(MACOSX)
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
@@ -37,67 +38,56 @@
#include "procimpl.h"
void
-sleepFor (unsigned int nanoseconds)
+sleepFor(unsigned int nanoseconds)
{
#if defined(AIX) || defined(ZOS)
/* These platforms don't have nanosleep(). */
- unsigned int microseconds = (nanoseconds+999) / 1000;
- usleep(microseconds);
+ unsigned int microseconds = (nanoseconds + 999) / 1000;
+ usleep(microseconds);
#else /* other unix platforms */
struct timespec delay, remDelay;
delay.tv_sec = 0;
delay.tv_nsec = nanoseconds;
- while (nanosleep (&delay, &remDelay) == -1)
- {
- if (errno == EINTR)
- {
- delay.tv_nsec = remDelay.tv_nsec; /* tv_sec is zero */
- }
- else
- {
- break; /* Oops the sleep didn't work ??? */
- }
+ while (nanosleep(&delay, &remDelay) == -1) {
+ if (errno == EINTR) {
+ delay.tv_nsec = remDelay.tv_nsec; /* tv_sec is zero */
+ } else {
+ break; /* Oops the sleep didn't work ??? */
}
+ }
#endif /* AIX or ZOS */
}
int
-termProc (IDATA procHandle)
+termProc(IDATA procHandle)
{
int rc;
- rc = kill ((pid_t) procHandle, SIGTERM);
+ rc = kill((pid_t) procHandle, SIGTERM);
return rc;
}
int
-waitForProc (IDATA procHandle)
+waitForProc(IDATA procHandle)
{
int StatusLocation = -1;
- waitpid ((pid_t) procHandle, &StatusLocation, 0);
- if (WIFEXITED (StatusLocation) != 0)
- {
- StatusLocation = WEXITSTATUS (StatusLocation);
- }
- else
- {
- if (WIFSIGNALED (StatusLocation) != 0)
- {
- StatusLocation = WTERMSIG (StatusLocation);
- }
- else
- {
- if (WIFSTOPPED (StatusLocation) != 0)
- {
- StatusLocation = WSTOPSIG (StatusLocation);
- }
- }
+ waitpid((pid_t) procHandle, &StatusLocation, 0);
+ if (WIFEXITED(StatusLocation) != 0) {
+ StatusLocation = WEXITSTATUS(StatusLocation);
+ } else {
+ if (WIFSIGNALED(StatusLocation) != 0) {
+ StatusLocation = WTERMSIG(StatusLocation);
+ } else {
+ if (WIFSTOPPED(StatusLocation) != 0) {
+ StatusLocation = WSTOPSIG(StatusLocation);
+ }
}
+ }
return StatusLocation;
}
@@ -109,19 +99,21 @@
* does a fork/execvp to launch the program
*
* returns :
- * 0 successful
+ * 0 successful
* 1001 fork failure errno = ENOMEM
- * 1002 fork failure errno = EAGAIN
- * -1 error, unknown
+ * 1002 fork failure errno = EAGAIN
+ * 1003 pipe failure errno = EMFILE
+ * 1004 chdir failure errno = ENOENT
+ * -1 error, unknown
*
* Note - there is one error code 'namespace' for execProgram
* please coordinate w/ other platform impls
*/
int
-execProgram (JNIEnv * vmthread, jobject recv,
- char *command[], int commandLineLength,
- char *env[], int envSize, char *dir, IDATA * procHandle,
- IDATA * inHandle, IDATA * outHandle, IDATA * errHandle)
+execProgram(JNIEnv * vmthread, jobject recv,
+ char *command[], int commandLineLength,
+ char *env[], int envSize, char *dir, IDATA * procHandle,
+ IDATA * inHandle, IDATA * outHandle, IDATA * errHandle)
{
/* It is illegal to pass JNIEnv accross threads, so get the vm while
* we will go across another thread. The javaObject recv is used in
@@ -131,163 +123,189 @@
int result = -1;
char *cmd;
int grdpid, rc = 0;
- int newFD[3][2];
- int execvFailure[2];
- int forkedChildIsRunning[2];
+ int newFD[3][2] = { {0,0}, {0,0}, {0,0} };
+ int execvFailure[2] = {0,0};
+ int forkedChildIsRunning[2] = {0,0};
+ int error = 0;
/* Build the new io pipes (in/out/err) */
- pipe (newFD[0]);
- pipe (newFD[1]);
- pipe (newFD[2]);
+ if (pipe(newFD[0]) == -1) goto error;
+ if (pipe(newFD[1]) == -1) goto error;
+ if (pipe(newFD[2]) == -1) goto error;
/* pipes for synchronization */
- pipe (forkedChildIsRunning);
- pipe (execvFailure);
+ if (pipe(forkedChildIsRunning) == -1) goto error;
+ if (pipe(execvFailure) == -1) goto error;
cmd = command[0];
- grdpid = fork ();
+ grdpid = fork();
/*
* if we fail, lets clean up and bail right here
*/
-
- if (grdpid == -1) {
- int error = errno;
-
- close(newFD[0][0]);
- close(newFD[0][1]);
- close(newFD[1][0]);
- close(newFD[1][1]);
- close(newFD[2][0]);
- close(newFD[2][1]);
-
- close(forkedChildIsRunning[0]);
- close(forkedChildIsRunning[1]);
-
- close(execvFailure[0]);
- close(execvFailure[1]);
-
- if (error == ENOMEM) {
- result = 1001;
- }
- else if (error == EAGAIN) {
- result = 1002;
- }
-
- return result;
- }
-
- if (grdpid == 0)
- {
- /* Redirect pipes so grand-child inherits new pipes */
- char dummy = '\0';
- dup2 (newFD[0][0], 0);
- dup2 (newFD[1][1], 1);
- dup2 (newFD[2][1], 2);
-
- /* tells the parent that that very process is running */
- write (forkedChildIsRunning[1], &dummy, 1);
+ if (grdpid == -1) goto error;
- if (dir) {
- chdir (dir);
- }
-
- /* ===try to perform the execv : on success, it does not return ===== */
- if (envSize != 0) {
- environ = env;
+ if (grdpid == 0) {
+ /* Close file descriptors that are not used */
+ close(newFD[0][1]);
+ close(newFD[1][0]);
+ close(newFD[2][0]);
+ close(forkedChildIsRunning[0]);
+ close(execvFailure[0]);
+
+ /* Make sure the others close if the exec succeeds */
+ setCloseOnExec(newFD[0][0]); /* dup2 removes this on the new handle */
+ setCloseOnExec(newFD[1][1]);
+ setCloseOnExec(newFD[2][1]);
+ setCloseOnExec(forkedChildIsRunning[1]);
+ setCloseOnExec(execvFailure[1]);
+
+ /* Redirect pipes so grand-child inherits new pipes */
+ char dummy = '\0';
+ dup2(newFD[0][0], 0);
+ dup2(newFD[1][1], 1);
+ dup2(newFD[2][1], 2);
+
+ /* tells the parent that that very process is running */
+ write(forkedChildIsRunning[1], &dummy, 1);
+
+ if (dir) {
+ if (chdir(dir) == -1) {
+ write(execvFailure[1], &errno, sizeof(errno));
+ exit(-1);
}
+ }
+
+ /* ===try to perform the execv : on success, it does not return ===== */
+ if (envSize != 0) {
+ environ = env;
+ }
- rc = execvp (cmd, command);
+ rc = execvp(cmd, command);
- /* ===================================================== */
+ /* ===================================================== */
- /* if we get here ==> tell the parent that the execv failed ! */
- write (execvFailure[1], &dummy, 1);
- /* If the exec failed, we must exit or there will be two VM processes running. */
- exit (rc);
+ /* if we get here ==> tell the parent that the execv failed ! */
+ write(execvFailure[1], &errno, sizeof(errno));
+ /* If the exec failed, we must exit or there will be two VM processes running. */
+ exit(rc);
+ } else {
+ /* in the child-thread (not the grand-child) */
+ char dummy;
+ int avail = 0;
+ int noDataInThePipe;
+ int nbLoop;
+
+ close(newFD[0][0]);
+ close(newFD[1][1]);
+ close(newFD[2][1]);
+ /* Store the rw handles to the childs io */
+ *(inHandle) = (IDATA) newFD[0][1];
+ *(outHandle) = (IDATA) newFD[1][0];
+ *(errHandle) = (IDATA) newFD[2][0];
+ *(procHandle) = (IDATA) grdpid;
+
+ /* let the forked child start. */
+ read(forkedChildIsRunning[0], &dummy, 1);
+ close(forkedChildIsRunning[0]);
+ close(forkedChildIsRunning[1]);
+
+ /* Use the POSIX setpgid and its errno EACCES to detect the success of the execv function. When the feature is
+ not present on the platform, a delay is provided after which we conclude that if the execv didn't fail, it
+ must have propably succeeded. We loop on reading a pipe which will receive a byte if the execv fails. We
+ also break from the loop, if we have detected the success of the execv (or past a delay if the functionaly
+ is not present) */
+
+ rc = 0; /* at first glance, the execv will succeed (-1 is for failure) */
+ noDataInThePipe = 1;
+ ioctl(execvFailure[0], FIONREAD, &avail);
+ if (avail > 0) {
+ rc = -1; /* failure of the execv */
+ noDataInThePipe = 0;
+ if (read(execvFailure[0], &error, sizeof(error)) == sizeof(error)) {
+ goto error_with_error_set;
+ }
}
- else
- {
- /* in the child-thread (not the grand-child) */
- char dummy;
- int avail = 0;
- int noDataInThePipe;
- int nbLoop;
-
- close (newFD[0][0]);
- close (newFD[1][1]);
- close (newFD[2][1]);
- /* Store the rw handles to the childs io */
- *(inHandle) = (IDATA) newFD[0][1];
- *(outHandle) = (IDATA) newFD[1][0];
- *(errHandle) = (IDATA) newFD[2][0];
- *(procHandle) = (IDATA) grdpid;
-
- /* let the forked child start. */
- read (forkedChildIsRunning[0], &dummy, 1);
- close (forkedChildIsRunning[0]);
- close (forkedChildIsRunning[1]);
-
- /* Use the POSIX setpgid and its errno EACCES to detect the success of the execv function. When the feature is
- not present on the platform, a delay is provided after which we conclude that if the execv didn't fail, it
- must have propably succeeded. We loop on reading a pipe which will receive a byte if the execv fails. We
- also break from the loop, if we have detected the success of the execv (or past a delay if the functionaly
- is not present) */
-
- rc = 0; /* at first glance, the execv will succeed (-1 is for failure) */
- noDataInThePipe = 1;
- ioctl (execvFailure[0], FIONREAD, &avail);
- if (avail > 0)
- {
- rc = -1; /* failure of the execv */
- noDataInThePipe = 0;
- }
- nbLoop = 0;
- while (noDataInThePipe)
- {
- int setgpidResult;
- /* =======give the child a chance to run=========== */
- sleepFor (10000000); /* 10 ms */
+ nbLoop = 0;
+ while (noDataInThePipe) {
+ int setgpidResult;
+ /* =======give the child a chance to run=========== */
+ sleepFor(10000000); /* 10 ms */
/*========== probe the child for success of the execv ========*/
- setgpidResult = setpgid (grdpid, grdpid);
- if (setgpidResult == -1)
- {
- if (errno == EACCES)
- {
- /* fprintf(stdout,"\nSUCCESS DETECTED\n");fflush(stdout); */
- break; /* success of the execv */
- }
- else
- {
- /* setgpid is probably not supported . Give some a bit of time to the child to tell us if it has
- failed to launch the execv */
- nbLoop++;
- if (nbLoop > 10)
- {
- break; /* well, execv has probably succeeded */
- }
- }
- }
- /* =========Has a byte arrived in the pipe ? (failure test) ========= */
- ioctl (execvFailure[0], FIONREAD, &avail);
- if (avail > 0)
- {
- rc = -1; /* failure of the execv */
- noDataInThePipe = 0;
- }
- } /* end of the loop. rc==-1 iff the execv failed */
+ setgpidResult = setpgid(grdpid, grdpid);
+ if (setgpidResult == -1) {
+ if (errno == EACCES) {
+ /* fprintf(stdout,"\nSUCCESS DETECTED\n");fflush(stdout); */
+ break; /* success of the execv */
+ } else {
+ /* setgpid is probably not supported . Give some a bit of time to the child to tell us if it has
+ failed to launch the execv */
+ nbLoop++;
+ if (nbLoop > 10) {
+ break; /* well, execv has probably succeeded */
+ }
+ }
+ }
+ /* =========Has a byte arrived in the pipe ? (failure test) ========= */
+ ioctl(execvFailure[0], FIONREAD, &avail);
+ if (avail > 0) {
+ rc = -1; /* failure of the execv */
+ noDataInThePipe = 0;
+ if (read(execvFailure[0], &error, sizeof(error)) == sizeof(error)) {
+ goto error_with_error_set;
+ }
+ }
+ } /* end of the loop. rc==-1 iff the execv failed */
- /* if (rc==-1){ fprintf(stdout,"\nFAILURE DETECTED\n");fflush(stdout); } */
+ /* if (rc==-1){ fprintf(stdout,"\nFAILURE DETECTED\n");fflush(stdout); } */
- close (execvFailure[0]);
- close (execvFailure[1]);
+ close(execvFailure[0]);
+ close(execvFailure[1]);
- if (rc != -1) {
- result = 0;
- }
+ if (rc != -1) {
+ result = 0;
}
+ }
+
+ return result;
+
+ error:
+
+ error = errno;
+
+ error_with_error_set:
+
+ if (execvFailure[0]) close(execvFailure[0]);
+ if (execvFailure[1]) close(execvFailure[1]);
+
+ if (forkedChildIsRunning[0]) close(forkedChildIsRunning[0]);
+ if (forkedChildIsRunning[1]) close(forkedChildIsRunning[1]);
+
+ if (newFD[2][0]) close(newFD[2][0]);
+ if (newFD[2][1]) close(newFD[2][1]);
+
+ if (newFD[1][0]) close(newFD[1][0]);
+ if (newFD[1][1]) close(newFD[1][1]);
+
+ if (newFD[0][0]) close(newFD[0][0]);
+ if (newFD[0][1]) close(newFD[0][1]);
+
+ switch (error) {
+ case ENOMEM:
+ result = 1001;
+ break;
+ case EAGAIN:
+ result = 1002;
+ break;
+ case EMFILE:
+ result = 1003;
+ break;
+ case ENOENT:
+ result = 1004;
+ break;
+ }
return result;
}
@@ -295,18 +313,27 @@
/* Stream handling support */
/* Return the number of bytes available to be read without blocking */
int
-getAvailable (IDATA sHandle)
+getAvailable(IDATA sHandle)
{
int avail, rc;
- rc = ioctl ((int) sHandle, FIONREAD, &avail);
+ rc = ioctl((int) sHandle, FIONREAD, &avail);
if (rc == -1)
return -2;
return avail;
}
int
-closeProc (IDATA procHandle)
+closeProc(IDATA procHandle)
{
/* The procHandle (Process ID) should not be closed, as it isn't a file descriptor. */
return 0;
+}
+
+int
+setCloseOnExec(int fd)
+{
+ int flags = fcntl(fd, F_GETFD);
+ if (flags == -1) return -1;
+ flags |= FD_CLOEXEC;
+ return fcntl(fd, F_SETFD, flags);
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/procimpl.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/procimpl.c?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/procimpl.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/procimpl.c Tue Mar 4 00:02:13 2008
@@ -49,10 +49,12 @@
* does a fork/execvp to launch the program
*
* returns :
- * 0 successful
+ * 0 successful
* 1001 fork failure errno = ENOMEM
- * 1002 fork failure errno = EAGAIN
- * -1 error, unknown
+ * 1002 fork failure errno = EAGAIN
+ * 1003 pipe failure errno = EMFILE
+ * 1004 chdir failure errno = ENOENT
+ * -1 error, unknown
*
* TODO - fill in windows error codes
*
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java Tue Mar 4 00:02:13 2008
@@ -300,24 +300,25 @@
* @tests java.io.InputStreamReader#getEncoding()
*/
public void test_getEncoding() throws IOException {
- try {
- is = new InputStreamReader(fis, "8859_1");
- } catch (UnsupportedEncodingException e) {
- assertEquals("Returned incorrect encoding", "8859_1", is.getEncoding());
- }
+ InputStreamReader isr = new InputStreamReader(fis, "8859_1");
+ assertEquals("Returned incorrect encoding when setting 8859_1",
+ "ISO8859_1", isr.getEncoding());
+
+ isr = new InputStreamReader(fis, "ISO-8859-1");
+ assertEquals("Returned incorrect encoding when setting ISO-8859-1",
+ "ISO8859_1", isr.getEncoding());
- InputStreamReader in = null;
byte b[] = new byte[5];
- in = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
- in.close();
- assertNull(in.getEncoding());
+ isr = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
+ isr.close();
+ assertNull(isr.getEncoding());
try {
- in = new InputStreamReader(System.in, "UTF-16BE");
+ isr = new InputStreamReader(System.in, "UTF-16BE");
} catch (UnsupportedEncodingException e) {
// Ignored
}
- assertEquals("UnicodeBigUnmarked", in.getEncoding());
+ assertEquals("UnicodeBigUnmarked", isr.getEncoding());
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/MathTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/MathTest.java?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/MathTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/MathTest.java Tue Mar 4 00:02:13 2008
@@ -986,6 +986,10 @@
2.0, Math.rint(2.1), 0D);
assertTrue("Failed to round properly " + 2.5 + " to even", Math
.rint(2.5) == 2.0);
+ assertTrue("Failed to round properly " + (+0.0d),
+ Math.rint(+0.0d) == +0.0d);
+ assertTrue("Failed to round properly " + (-0.0d),
+ Math.rint(-0.0d) == -0.0d);
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java?rev=633384&r1=633383&r2=633384&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java Tue Mar 4 00:02:13 2008
@@ -19,6 +19,7 @@
import java.io.UnsupportedEncodingException;
import java.util.Locale;
+import java.nio.charset.Charset;
public class String2Test extends junit.framework.TestCase {
@@ -340,9 +341,20 @@
public void test_getBytes() {
// Test for method byte [] java.lang.String.getBytes()
byte[] sbytes = hw1.getBytes();
- for (int i = 0; i < hw1.length(); i++)
- assertTrue("Returned incorrect bytes", sbytes[i] == (byte) hw1
- .charAt(i));
+
+ boolean isEbcdic = Charset.defaultCharset().equals(Charset.forName("IBM1047"));
+ if (!isEbcdic) {
+ for (int i = 0; i < hw1.length(); i++)
+ assertTrue("Returned incorrect bytes", sbytes[i] == (byte) hw1
+ .charAt(i));
+ } else {
+ // On EBCDIC platforms, getBytes() returns different values
+ // Reference values taken from J9 5.0
+ byte[] expectedValues = {-56, -123, -109, -109, -106, -26, -106,
+ -103, -109, -124};
+ for (int i = 0; i < hw1.length(); i++)
+ assertEquals(expectedValues[i], sbytes[i]);
+ }
char[] chars = new char[1];
for (int i = 0; i < 65536; i++) {
@@ -418,7 +430,17 @@
// int)
byte[] buf = new byte[5];
"Hello World".getBytes(6, 11, buf, 0);
- assertEquals("Returned incorrect bytes", "World", new String(buf));
+
+ boolean isEbcdic = Charset.defaultCharset().equals(Charset.forName("IBM1047"));
+ if (!isEbcdic) {
+ assertEquals("Returned incorrect bytes", "World", new String(buf));
+ } else {
+ // On EBCDIC platforms, getBytes() returns different values
+ // Reference values taken from J9 5.0
+ byte[] expectedValues = {87, 111, 114, 108, 100};
+ for (int i = 0; i < 5; i++)
+ assertEquals(expectedValues[i], buf[i]);
+ }
try {
"Hello World".getBytes(-1, 1, null, 0);