summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-02-01 01:40:05 +0000
committerDavid Robillard <d@drobilla.net>2012-02-01 01:40:05 +0000
commit5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf (patch)
tree6b2d088aef4ed5099fbbc140c594a0ee1b7e67fa /test
parentdc7628a8eec281add045eb123ae06dbc94c1b950 (diff)
downloadzix-5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf.tar.gz
zix-5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf.tar.bz2
zix-5d071ef1c9ea2d39c03ca64b6a0c3bb9c67bd8cf.zip
Windows portability fixes.
git-svn-id: http://svn.drobilla.net/zix/trunk@58 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
Diffstat (limited to 'test')
-rw-r--r--test/ring_test.c17
-rw-r--r--test/sem_test.c1
-rw-r--r--test/sorted_array_test.c20
-rw-r--r--test/tree_test.c32
4 files changed, 31 insertions, 39 deletions
diff --git a/test/ring_test.c b/test/ring_test.c
index b7d181c..6cbe4fd 100644
--- a/test/ring_test.c
+++ b/test/ring_test.c
@@ -16,7 +16,6 @@
#include <limits.h>
#include <stdarg.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -69,15 +68,15 @@ reader(void* arg)
{
printf("Reader starting\n");
- int ref_msg[MSG_SIZE]; // Reference generated for comparison
- int read_msg[MSG_SIZE]; // Read from ring
- size_t count = 0;
- int start = gen_msg(ref_msg, 0);
+ int ref_msg[MSG_SIZE]; // Reference generated for comparison
+ int read_msg[MSG_SIZE]; // Read from ring
+ unsigned count = 0;
+ int start = gen_msg(ref_msg, 0);
for (size_t i = 0; i < n_writes; ++i) {
if (zix_ring_read_space(ring) >= MSG_SIZE * sizeof(int)) {
if (zix_ring_read(ring, read_msg, MSG_SIZE * sizeof(int))) {
if (!cmp_msg(ref_msg, read_msg)) {
- printf("FAIL: Message %zu is corrupt\n", count);
+ printf("FAIL: Message %u is corrupt\n", count);
read_error = true;
return NULL;
}
@@ -118,7 +117,7 @@ main(int argc, char** argv)
return 1;
}
- int size = 1024;
+ unsigned size = 1024;
if (argc > 1) {
size = atoi(argv[1]);
}
@@ -128,7 +127,7 @@ main(int argc, char** argv)
n_writes = atoi(argv[2]);
}
- printf("Testing %zu writes of %d ints to a %d int ring...\n",
+ printf("Testing %u writes of %d ints to a %d int ring...\n",
n_writes, MSG_SIZE, size);
ring = zix_ring_new(size);
@@ -216,7 +215,7 @@ main(int argc, char** argv)
return failure("Successful underrun read\n");
}
- char* big_buf = calloc(size, 1);
+ char* big_buf = (char*)calloc(size, 1);
n = zix_ring_write(ring, big_buf, size - 1);
if (n != (uint32_t)size - 1) {
return failure("Maximum size write failed (wrote %u)\n", n);
diff --git a/test/sem_test.c b/test/sem_test.c
index e5c7b55..b48ad4c 100644
--- a/test/sem_test.c
+++ b/test/sem_test.c
@@ -15,7 +15,6 @@
*/
#include <limits.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c
index d33151a..3b0a090 100644
--- a/test/sorted_array_test.c
+++ b/test/sorted_array_test.c
@@ -14,14 +14,15 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
+#include <time.h>
-#include <sys/time.h>
-
-#ifndef _MSC_VER
+#ifdef _MSC_VER
+# define PRIdPTR "Id"
+#else
# include <inttypes.h>
#endif
@@ -77,8 +78,7 @@ stress(int test_num, unsigned n_elems)
return test_fail();
}
if (*(intptr_t*)zix_sorted_array_get_data(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR
- ", expected %" PRIdPTR ")\n",
+ fprintf(stderr, "Data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n",
*(intptr_t*)zix_sorted_array_get_data(ti), r);
return test_fail();
}
@@ -94,8 +94,7 @@ stress(int test_num, unsigned n_elems)
return test_fail();
}
if (*(intptr_t*)zix_sorted_array_get_data(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR
- ", expected %" PRIdPTR ")\n",
+ fprintf(stderr, "Data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n",
*(intptr_t*)zix_sorted_array_get_data(ti), r);
return test_fail();
}
@@ -150,9 +149,6 @@ main(int argc, char** argv)
const unsigned n_tests = 3;
unsigned n_elems = 0;
- struct timeval time;
- gettimeofday(&time, NULL);
-
if (argc == 1) {
n_elems = 4096;
} else {
@@ -160,7 +156,7 @@ main(int argc, char** argv)
if (argc > 2) {
seed = atol(argv[2]);
} else {
- seed = time.tv_sec + time.tv_usec;
+ seed = time(NULL);
}
}
diff --git a/test/tree_test.c b/test/tree_test.c
index dc91ff8..6f25f6c 100644
--- a/test/tree_test.c
+++ b/test/tree_test.c
@@ -14,14 +14,15 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
+#include <time.h>
-#include <sys/time.h>
-
-#ifndef _MSC_VER
+#ifdef _MSC_VER
+# define PRIdPTR "Id"
+#else
# include <inttypes.h>
#endif
@@ -76,7 +77,7 @@ stress(int test_num, size_t n_elems)
return test_fail();
}
if ((intptr_t)zix_tree_get(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR ", expected %zu)\n",
+ fprintf(stderr, "Data corrupt (%" PRIdPTR" != %" PRIdPTR ")\n",
(intptr_t)zix_tree_get(ti), r);
return test_fail();
}
@@ -98,7 +99,7 @@ stress(int test_num, size_t n_elems)
return test_fail();
}
if ((intptr_t)zix_tree_get(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR ", expected %zu)\n",
+ fprintf(stderr, "Data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n",
(intptr_t)zix_tree_get(ti), r);
return test_fail();
}
@@ -115,7 +116,7 @@ stress(int test_num, size_t n_elems)
r = ith_elem(test_num, n_elems, i);
const intptr_t iter_data = (intptr_t)zix_tree_get(iter);
if (iter_data < last) {
- fprintf(stderr, "Iter corrupt (%" PRIdPTR " < %zu)\n",
+ fprintf(stderr, "Iter corrupt (%" PRIdPTR " < %" PRIdPTR ")\n",
iter_data, last);
return test_fail();
}
@@ -133,7 +134,7 @@ stress(int test_num, size_t n_elems)
r = ith_elem(test_num, n_elems, i);
const intptr_t iter_data = (intptr_t)zix_tree_get(iter);
if (iter_data > last) {
- fprintf(stderr, "Iter corrupt (%" PRIdPTR " < %zu)\n",
+ fprintf(stderr, "Iter corrupt (%" PRIdPTR " < %" PRIdPTR ")\n",
iter_data, last);
return test_fail();
}
@@ -172,7 +173,7 @@ stress(int test_num, size_t n_elems)
return test_fail();
}
if ((intptr_t)zix_tree_get(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR ", expected %zu)\n",
+ fprintf(stderr, "Data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n",
(intptr_t)zix_tree_get(ti), r);
return test_fail();
}
@@ -192,11 +193,8 @@ stress(int test_num, size_t n_elems)
int
main(int argc, char** argv)
{
- const size_t n_tests = 3;
- size_t n_elems = 0;
-
- struct timeval time;
- gettimeofday(&time, NULL);
+ const unsigned n_tests = 3;
+ unsigned n_elems = 0;
if (argc == 1) {
n_elems = 4096;
@@ -205,7 +203,7 @@ main(int argc, char** argv)
if (argc > 2) {
seed = atol(argv[2]);
} else {
- seed = time.tv_sec + time.tv_usec;
+ seed = time(NULL);
}
}
@@ -214,10 +212,10 @@ main(int argc, char** argv)
return 1;
}
- printf("Running %zu tests with %zu elements (seed %d)",
+ printf("Running %u tests with %u elements (seed %d)",
n_tests, n_elems, seed);
- for (size_t i = 0; i < n_tests; ++i) {
+ for (unsigned i = 0; i < n_tests; ++i) {
printf(".");
fflush(stdout);
if (stress(i, n_elems)) {