You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2004/01/06 15:49:11 UTC
cvs commit: apr/test testatomic.c
jorton 2004/01/06 06:49:11
Modified: test testatomic.c
Log:
* testatomic.c (check_basic_atomics32): Test wrapping around zero.
Revision Changes Path
1.38 +25 -0 apr/test/testatomic.c
Index: testatomic.c
===================================================================
RCS file: /home/cvs/apr/test/testatomic.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -b -d -u -r1.37 -r1.38
--- testatomic.c 9 Dec 2003 19:00:51 -0000 1.37
+++ testatomic.c 6 Jan 2004 14:49:11 -0000 1.38
@@ -84,6 +84,7 @@
{
apr_uint32_t oldval;
apr_uint32_t casval = 0;
+ apr_uint32_t minus1 = -1;
apr_atomic_set32(&y32, 2);
printf("%-60s", "testing apr_atomic_dec32");
@@ -178,6 +179,30 @@
return APR_EGENERAL;
}
fprintf(stdout, "OK\n");
+
+ printf("%-60s", "testing wrapping around zero");
+
+ apr_atomic_set32(&y32, 0);
+ if (apr_atomic_dec32(&y32) == 0) {
+ fprintf(stderr, "apr_atomic_dec32 on zero returned zero.\n");
+ return APR_EGENERAL;
+ }
+ if (apr_atomic_read32(&y32) != minus1) {
+ fprintf(stderr, "zero wrap failed: 0 - 1 = %d\n",
+ apr_atomic_read32(&y32));
+ return APR_EGENERAL;
+ }
+
+ if (apr_atomic_inc32(&y32) != minus1) {
+ fprintf(stderr, "apr_atomic_inc32 on -1 returned bad value.\n");
+ return APR_EGENERAL;
+ }
+ if (apr_atomic_read32(&y32) != 0) {
+ fprintf(stderr, "zero wrap failed: -1 + 1 = %u\n",
+ apr_atomic_read32(&y32));
+ return APR_EGENERAL;
+ }
+ printf("OK\n");
return APR_SUCCESS;
}