changeset 495:c291e9201a3c api-inversion

libtests cleanups Delete unused functions from test_utils.lib.h. maketestfile()'s int* argument should be an int; fix that and alter the sources accordingly. Add -Werror to the Makefile for test files, now that they all do compile without warnings.
author mas01cr
date Sat, 10 Jan 2009 15:33:21 +0000
parents 1327b5cf4cb5
children 8fb85fbcaba6
files libtests/0022/prog1.c libtests/0023/prog1.c libtests/0024/prog1.c libtests/0028/prog1.c libtests/0034/prog1.c libtests/0037/prog1.c libtests/libtest.mk libtests/test_utils_lib.h
diffstat 8 files changed, 22 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/libtests/0022/prog1.c	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/0022/prog1.c	Sat Jan 10 15:33:21 2009 +0000
@@ -9,8 +9,8 @@
   if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
     return 1;
 
-  maketestfile("testfeature01", (int[1]){2}, (double[2]) {0, 1}, 2);
-  maketestfile("testfeature10", (int[1]){2}, (double[2]) {1, 0}, 2);
+  maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2);
+  maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2);
 
   batch[0].features="testfeature01";
   batch[1].features="testfeature10";
--- a/libtests/0023/prog1.c	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/0023/prog1.c	Sat Jan 10 15:33:21 2009 +0000
@@ -9,8 +9,8 @@
   if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
     return 1;
 
-  maketestfile("testfeature01", (int[1]){2}, (double[2]) {0, 1}, 2);
-  maketestfile("testfeature10", (int[1]){2}, (double[2]) {1, 0}, 2);
+  maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2);
+  maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2);
 
   batch[0].features="testfeature01";
   batch[1].features="testfeature10";
--- a/libtests/0024/prog1.c	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/0024/prog1.c	Sat Jan 10 15:33:21 2009 +0000
@@ -9,8 +9,8 @@
   if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
     return 1;
 
-  maketestfile("testfeature01", (int[1]){2}, (double[2]) {0, 1}, 2);
-  maketestfile("testfeature10", (int[1]){2}, (double[2]) {1, 0}, 2);
+  maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2);
+  maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2);
 
   batch[0].features="testfeature01";
   batch[1].features="testfeature10";
--- a/libtests/0028/prog1.c	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/0028/prog1.c	Sat Jan 10 15:33:21 2009 +0000
@@ -9,8 +9,8 @@
   if(!(adb = audiodb_create(TESTDB,0,0,0)))
     return 1;
 
-  maketestfile("testfeature", (int[1]) {2}, (double[4]){0, 1, 1, 0}, 4);
-  maketestfile("testpower", (int[1]) {1}, (double[2]) {-0.5, -1}, 2);
+  maketestfile("testfeature", 2, (double[4]){0, 1, 1, 0}, 4);
+  maketestfile("testpower", 1, (double[2]) {-0.5, -1}, 2);
 
   batch[0].features="testfeature";
   batch[0].power="testpower";
--- a/libtests/0034/prog1.c	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/0034/prog1.c	Sat Jan 10 15:33:21 2009 +0000
@@ -11,9 +11,9 @@
   if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
     return 1;
 
-  maketestfile("testfeature", (int[1]) {2}, (double[2]) {1, 1}, 2);
-  maketestfile("testfeature01", (int[1]) {2}, (double[2]) {0, 1}, 2);
-  maketestfile("testfeature10", (int[1]) {2}, (double[2]) {1, 0}, 2);
+  maketestfile("testfeature", 2, (double[2]) {1, 1}, 2);
+  maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2);
+  maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2);
 
   insert.features = "testfeature";
   if(audiodb_insert(adb, &insert))
--- a/libtests/0037/prog1.c	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/0037/prog1.c	Sat Jan 10 15:33:21 2009 +0000
@@ -12,8 +12,8 @@
     return 1;
   }
 
-  maketestfile("testfeature01", (int[1]) {2}, (double[4]) {0,1,1,0}, 4);
-  maketestfile("testfeature10", (int[1]) {2}, (double[4]) {1,0,0,1}, 4);
+  maketestfile("testfeature01", 2, (double[4]) {0,1,1,0}, 4);
+  maketestfile("testfeature10", 2, (double[4]) {1,0,0,1}, 4);
 
   batch = (adb_insert_t *) calloc(6, sizeof(adb_insert_t));
   if(!batch) {
--- a/libtests/libtest.mk	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/libtest.mk	Sat Jan 10 15:33:21 2009 +0000
@@ -28,7 +28,7 @@
 	-ln -s $< $@
 
 test1: prog1.c ../test_utils_lib.h ../../audioDB_API.h
-	gcc -g -std=c99 -Wall $(ARCH_FLAGS) -I.. -I../.. -laudioDB -L. -Wl,-rpath,. -o $@ $<
+	gcc -g -std=c99 -Wall -Werror $(ARCH_FLAGS) -I.. -I../.. -laudioDB -L. -Wl,-rpath,. -o $@ $<
 
 clean:
 	-rm $(LIBRARY_FULL) $(LIBRARY_VERS) $(LIBRARY)
--- a/libtests/test_utils_lib.h	Sat Jan 10 15:33:16 2009 +0000
+++ b/libtests/test_utils_lib.h	Sat Jan 10 15:33:21 2009 +0000
@@ -5,88 +5,22 @@
 #include <fcntl.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #define TESTDB "testdb"
 
-void clean_remove_db(char *dbname);
-int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos);
-void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize);
-int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, int count);
-void makekeylistfile(char * filename, char * item);
-
 void clean_remove_db(char * dbname) {
   unlink(dbname);
 }
 
-int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos){
+void maketestfile(const char *path, int dim, double *doubles, int ndoubles) {
+  FILE *file;
 
-    int ret=0;
-    double tolerance=.0001;
-
-
-    
-    if (strcmp(Rlist,myadbqueryresult->Rlist[i])){
-        ret=-1;
-    } 
-
-
-    if (fabs((double)Dist - (double)myadbqueryresult->Dist[i]) > tolerance){
-        ret=-1;
-    } 
-    
-    if (fabs((double)Qpos - (double)myadbqueryresult->Qpos[i]) > tolerance){
-        ret=-1;
-    } 
-
-    if (fabs((double)Spos - (double)myadbqueryresult->Spos[i]) > tolerance){
-        ret=-1;
-    } 
-
-    return ret;
-}
-
-
-int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, int count){
-
-    int ret=0;
-
-    if (strcmp(Rlist,myadbqueryresult->Rlist[i])){
-        ret=-1;
-    } 
-
-    /* KLUDGE: at the moment, the structure returned from "sequence"
-       queries with a radius has two unused fields, Dist and Qpos, and
-       the Spos field is punned to indicate the count of hits from
-       that track.  This is really ugly and needs to die. */
-    if (count != myadbqueryresult->Spos[i]) {
-        ret=-1;
-    } 
-
-    return ret;
-}
-
-void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize) {
-
-    FILE * myfile;
-
-    myfile=fopen(filename,"w");
-    fwrite(ivals,sizeof(int),1,myfile);
-    fwrite(dvals,sizeof(double),dvalsize,myfile);
-    fflush(myfile);
-    fclose(myfile);
-
-    /* should probably test for success, but then it is a test suite already... */
-}
-
-void makekeylistfile(char * filename, char * item){
-
-    FILE * myfile;
-
-    myfile=fopen(filename,"w");
-    fprintf(myfile,"%s\n",item);
-   fflush(myfile);
-    fclose(myfile);
-
+  file = fopen(path, "w");
+  fwrite(&dim, sizeof(int), 1, file);
+  fwrite(doubles, sizeof(double), ndoubles, file);
+  fflush(file);
+  fclose(file);
 }
 
 int close_enough(double a, double b, double epsilon) {
@@ -106,4 +40,3 @@
 
 #define result_present_or_fail(r, k, d, q, i) \
   if(result_position(r, k, d, q, i) < 0) return 1;
-