[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:45:59 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit bd7d070a22dc44b30a790a11ce907826eca18ab9
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Sep 21 16:43:05 2001 +0000

    Started to add support for unit tests. This includes:
    
    	- A test harness program
    	- Some specific tests for our Qt class implementations
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Makefile.in b/WebCore/Makefile.in
index c651e29..16f03d5 100644
--- a/WebCore/Makefile.in
+++ b/WebCore/Makefile.in
@@ -29,6 +29,7 @@ SUBDIRS = \
 	src/kdelibs/khtml/rendering \
 	src/kwq/ \
 	src/kwq/qt \
+	src/kwq/tests \
 	src/kwq/tests/qt \
 	$(NULL)
 
@@ -54,6 +55,11 @@ all depend setup install clean distclean maintainer-clean:
 #----------------------------------------------------------------------
 # Custom targets
 
+test:
+	cd src/kwq/tests && \
+	make && \
+	./harness
+
 local-all:
 local-dep:
 local-install:
diff --git a/WebCore/configure b/WebCore/configure
index d1605c8..089ef9f 100644
--- a/WebCore/configure
+++ b/WebCore/configure
@@ -2915,6 +2915,7 @@ trap 'rm -fr `echo "Makefile
 	src/kdelibs/khtml/rendering/Makefile
 	src/kwq/Makefile
 	src/kwq/qt/Makefile
+	src/kwq/tests/Makefile
 	src/kwq/tests/qt/Makefile
  config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
 EOF
@@ -3030,6 +3031,7 @@ CONFIG_FILES=\${CONFIG_FILES-"Makefile
 	src/kdelibs/khtml/rendering/Makefile
 	src/kwq/Makefile
 	src/kwq/qt/Makefile
+	src/kwq/tests/Makefile
 	src/kwq/tests/qt/Makefile
 "}
 EOF
diff --git a/WebCore/configure.in b/WebCore/configure.in
index 8f5ede6..624c16d 100644
--- a/WebCore/configure.in
+++ b/WebCore/configure.in
@@ -257,6 +257,7 @@ AC_OUTPUT(
 	src/kdelibs/khtml/rendering/Makefile
 	src/kwq/Makefile
 	src/kwq/qt/Makefile
+	src/kwq/tests/Makefile
 	src/kwq/tests/qt/Makefile
 )
 
diff --git a/WebCore/kwq/KWQPtrDict.h b/WebCore/kwq/KWQPtrDict.h
index cdb984b..1d74ef3 100644
--- a/WebCore/kwq/KWQPtrDict.h
+++ b/WebCore/kwq/KWQPtrDict.h
@@ -30,6 +30,12 @@
 #include <config.h>
 #endif
 
+// _KWQ_COMPLETE_ ==============================================================
+
+#ifdef _KWQ_COMPLETE_
+#include <_qptrdict.h>
+#else
+
 #include <KWQDef.h>
 #include <_qcollection.h>
 
diff --git a/WebCore/kwq/KWQPtrVector.h b/WebCore/kwq/KWQPtrVector.h
index 5ebe386..3b4ad5b 100644
--- a/WebCore/kwq/KWQPtrVector.h
+++ b/WebCore/kwq/KWQPtrVector.h
@@ -30,6 +30,12 @@
 #include <config.h>
 #endif
 
+// _KWQ_COMPLETE_ ==============================================================
+
+#ifdef _KWQ_COMPLETE_
+#include <_qvector.h>
+#else
+
 #include <KWQDef.h>
 #include <_qcollection.h>
 
diff --git a/WebCore/kwq/qt/qptrdict.h b/WebCore/kwq/qt/qptrdict.h
index cdb984b..1d74ef3 100644
--- a/WebCore/kwq/qt/qptrdict.h
+++ b/WebCore/kwq/qt/qptrdict.h
@@ -30,6 +30,12 @@
 #include <config.h>
 #endif
 
+// _KWQ_COMPLETE_ ==============================================================
+
+#ifdef _KWQ_COMPLETE_
+#include <_qptrdict.h>
+#else
+
 #include <KWQDef.h>
 #include <_qcollection.h>
 
diff --git a/WebCore/kwq/qt/qvector.h b/WebCore/kwq/qt/qvector.h
index 5ebe386..3b4ad5b 100644
--- a/WebCore/kwq/qt/qvector.h
+++ b/WebCore/kwq/qt/qvector.h
@@ -30,6 +30,12 @@
 #include <config.h>
 #endif
 
+// _KWQ_COMPLETE_ ==============================================================
+
+#ifdef _KWQ_COMPLETE_
+#include <_qvector.h>
+#else
+
 #include <KWQDef.h>
 #include <_qcollection.h>
 
diff --git a/WebCore/src/kwq/qt/Makefile.in b/WebCore/kwq/tests/Makefile.in
similarity index 78%
copy from WebCore/src/kwq/qt/Makefile.in
copy to WebCore/kwq/tests/Makefile.in
index 82e0aba..5207acc 100644
--- a/WebCore/src/kwq/qt/Makefile.in
+++ b/WebCore/kwq/tests/Makefile.in
@@ -15,36 +15,33 @@ include $(TOPSRCDIR)/Makefile.vars
 #----------------------------------------------------------------------
 # Set variables for this directory
 
-SOURCES = $(wildcard *.cpp)
 CXXOBJECTS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
 
-OBJECTS = $(CXXOBJECTS)
-
-LIBRARY = lib_qt.a
+PROGRAM = harness
 
 CLEAN_FILES = *.o \
-    *.a \
+    $(PROGRAM) \
     $(NULL)
 
 #----------------------------------------------------------------------
 # Set flags for this directory
 
-CXXFLAGS = $(BASECXXFLAGS) \
-    -I$(TOPSRCDIR) \
-    -I.. \
-    -I. \
+CFLAGS = $(BASECFLAGS) \
+    -Wall \
+    -O2 \
     $(NULL)
 
-DEPFLAGS = $(CXXFLAGS)
+DEPFLAGS = $(CFLAGS)
 
 #----------------------------------------------------------------------
 # Set targets for this directory
 
-all: $(OBJECTS) $(LIBRARY)
+all: $(OBJECTS) $(PROGRAM)
+
+$(PROGRAM): harness.o
+	$(CC) -o $@ $< $(LDFLAGS)
 
-$(LIBRARY): $(OBJECTS)
-	$(AR) $(ARFLAGS) $(LIBRARY) $(CXXOBJECTS)
-	$(RANLIB) $(LIBRARY)
+depend: 
 
 #----------------------------------------------------------------------
 # include make rules boilerplate
diff --git a/WebCore/kwq/tests/harness.c b/WebCore/kwq/tests/harness.c
new file mode 100644
index 0000000..1e3e499
--- /dev/null
+++ b/WebCore/kwq/tests/harness.c
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 2001 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define LIST "test.list"
+#define BUFSIZE 1024
+#define MAX_NAME_LEN 40
+#define TEST_ERR_LEN 29
+#define CHK_ERR_LEN 28
+
+int ok = 0;
+int no = 0;
+
+void ppad(int pad) {
+    if (pad > 0) {
+        while (--pad) {
+            printf(".");
+        }
+    }
+}
+
+void *emalloc(size_t size) {
+     void *p;
+     
+     p = malloc(size);
+     
+     if (!p) {
+          fprintf(stderr, "memory allocation failure\n");
+          exit(1);
+     }
+     
+     return p;
+}
+
+int getfile(const char *filename, char **text) {
+    FILE *file = NULL;
+    int total_read = 0;
+
+    file = fopen(filename, "r");
+    if (file == NULL) {
+        fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, strerror(errno), filename);
+        return -1;
+    }
+    else {
+        int char_size = sizeof(char);
+        int index = 0;
+        int cap = BUFSIZE;
+        char *buf;
+
+        *text = emalloc(cap);
+        buf = emalloc(BUFSIZE);
+    
+        do {
+            int read;
+            read = fread(buf, char_size, BUFSIZE, file);
+            if (ferror(file) != 0) {
+                free(buf);
+                free(*text);
+                fclose(file);
+                fprintf(stderr, "io error: %d\n", __LINE__);
+                exit(1);
+            }
+            total_read += read;
+            if (total_read > cap) {
+                char *newmem = realloc(*text, (cap * 2));
+                if(newmem == NULL) {
+                    free(buf);
+                    free(*text);
+                    fprintf(stderr, "io error: %d\n", __LINE__);
+                    exit(1);
+                }
+                *text = newmem;    
+                cap = total_read;
+            }
+            memcpy((*text) + index, buf, read);
+            index = total_read;
+        }
+        while (feof(file) == 0);
+        free(buf);
+        (*text)[total_read] = '\0';
+        /* close file */
+        if (fclose(file) != 0) {
+            fprintf(stderr, "io error: %d\n", __LINE__);
+            exit(1);
+        }
+    }
+    return total_read;
+}
+
+int runtest(const char *test) {
+    int pid;
+    int fd;
+    char chkname[64];
+    char outname[64];
+    char *out;
+    char *chk;
+    int outlen;
+    int chklen;
+    struct stat buf;
+    int pad;
+    int result;
+
+    result = 0;
+
+    strcpy(chkname, test);
+    strcat(chkname, ".chk");
+
+    strcpy(outname, test);
+    strcat(outname, ".out");
+
+    printf("%s", test);
+    
+    if(stat(test, &buf)) {
+        pad = TEST_ERR_LEN - strlen(test);
+        ppad(pad);
+        printf("test file not found\n");
+        return -1;    
+    }
+
+    if(stat(chkname, &buf)) {
+        pad = CHK_ERR_LEN - strlen(test);
+        ppad(pad);
+        printf("check file not found\n");
+        return -1;    
+    }
+
+    /* pad with dots */
+    pad = MAX_NAME_LEN - strlen(test);
+    ppad(pad);
+
+    /* Fork a child to run the test */
+    pid = fork();
+    if (pid == 0) {     /* child */
+
+        /* Create a temporary file to catch output of test program */
+        fd = open(outname, O_CREAT | O_WRONLY, S_IRWXU);
+        if (fd == -1) {
+            fprintf(stderr, "open of outfile failed\n");
+        }
+        else {
+            /* Redirect stdout to a temporary file */
+            close(1);
+            dup(fd);
+            close(fd);
+
+            /* exec test file */
+            result = execl(test, test, NULL);
+
+            fprintf(stderr, "exec of %s failed\n", test);
+            exit(1);
+        }
+    } 
+    else if (pid == -1) {
+        fprintf(stderr, "fork failed\n");
+        exit(1);
+    }
+
+    /* Wait for child to complete before returning */
+    while (wait(NULL) != pid) {}  /* empty loop */
+
+    /* collect result and check output from files */    
+    outlen = getfile(outname, &out);
+    chklen = getfile(chkname, &chk);
+        
+    /* compare output with expected result */
+    if (result != 0) {
+        no++;
+        printf("fail [exit code]\n");
+    }
+    else if (outlen != chklen) {
+        no++;
+        printf("fail [!= lengths]\n");
+    }
+    else if (memcmp(out, chk, chklen) != 0) {
+        no++;
+         printf("fail [!= output]\n");
+   } 
+    else {
+        ok++;
+        printf(".ok\n");
+    }
+
+    free(out);
+    free(chk);
+
+    /* clean up the temporary file */
+    remove(outname);
+
+    return 0;
+}
+
+int main(int argc, char **argv) {
+    
+    char **suites;
+    char *list;
+    char *line;
+    int num;
+    int t;
+    int i;
+    int head;
+
+    printf("harness begin\n");
+    printf("=========================================================\n");
+
+    if (argc < 2) {
+        suites = emalloc(sizeof(char *));
+        suites[0] = LIST;
+        num = 1;
+    }
+    else {
+        num = argc - 1;
+        suites = emalloc(num * sizeof(char *));
+        for (i = 0; i < num; i++) {
+            suites[i] = argv[i + 1];
+        }
+    }
+
+    head = 1;
+    for (i = 0; i < num; i++) {
+        if (getfile(suites[i], &list) == -1) {
+          continue;
+        }
+        line = strtok(list, "\n");
+        while (line != NULL) {
+            if (line[0] == '#') {
+                head = 0;
+                printf("%s\n", line);
+            }
+            else {
+                if (head == 0) {
+                    printf("Test Name                             Output\n");
+                    printf("---------------------------------------------------------\n");
+                }
+                head = 1;
+                runtest(line);
+            }
+            line = strtok(NULL, "\n");
+        }
+        free(list);
+    }
+    free(suites);
+
+    t = ok + no;
+    printf("---------------------------------------------------------\n");
+    printf("Total Tests Run:  %4d\n", t);
+    printf("---------------------------------------------------------\n");
+    printf("Summary            Output\n");
+    printf("Passed:      %4d (%6.2f%%)\n", 
+             ok, ((float)ok / (float)t * 100)
+             );
+    printf("Failed:      %4d (%6.2f%%)\n", 
+             no, ((float)no / (float)t * 100)
+             );
+    printf("=========================================================\n");
+    printf("harness done\n");
+
+    return no;
+
+}
+
+/*=============================================================================
+// end of file: $RCSfile$
+==============================================================================*/
+
diff --git a/WebCore/kwq/tests/qt/Makefile.in b/WebCore/kwq/tests/qt/Makefile.in
index ae3b37e..854bd0d 100644
--- a/WebCore/kwq/tests/qt/Makefile.in
+++ b/WebCore/kwq/tests/qt/Makefile.in
@@ -19,16 +19,20 @@ CXXOBJECTS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
 
 OBJECTS = $(CXXOBJECTS)
 
-PROGRAM = test
+PROGRAMS = \
+    qpoint-test \
+    qsize-test \
+    $(NULL)
 
 CLEAN_FILES = *.o \
-    $(PROGRAM) \
+    $(PROGRAMS) \
     $(NULL)
 
 #----------------------------------------------------------------------
 # Set flags for this directory
 
 CXXFLAGS = $(BASECXXFLAGS) \
+    -Wall \
     -DQ_DELETING_VOID_UNDEFINED \
     -DQT_NO_TEXTCODEC \
     -DQT_NO_DATASTREAM \
@@ -49,9 +53,12 @@ DEPFLAGS = $(CXXFLAGS)
 #----------------------------------------------------------------------
 # Set targets for this directory
 
-all: $(OBJECTS) $(PROGRAM)
+all: $(OBJECTS) $(PROGRAMS)
+
+qpoint-test: qpoint-test.o
+	$(CXX) -o $@ $< $(LDFLAGS)
 
-$(PROGRAM): $(OBJECTS)
+qsize-test: qsize-test.o
 	$(CXX) -o $@ $< $(LDFLAGS)
 
 depend: 
diff --git a/WebCore/kwq/tests/qt/qpoint-test.chk b/WebCore/kwq/tests/qt/qpoint-test.chk
new file mode 100644
index 0000000..21a01bd
--- /dev/null
+++ b/WebCore/kwq/tests/qt/qpoint-test.chk
@@ -0,0 +1,10 @@
+QPoint: [x: 1; h: 1]
+QPoint: [x: 3; h: 3]
+QPoint: [x: 4; h: 4]
+1
+0
+0
+1
+1
+0
+QPoint: [x: 12; h: 12]
diff --git a/WebCore/kwq/tests/qt/qpoint-test.cpp b/WebCore/kwq/tests/qt/qpoint-test.cpp
new file mode 100644
index 0000000..98283c5
--- /dev/null
+++ b/WebCore/kwq/tests/qt/qpoint-test.cpp
@@ -0,0 +1,33 @@
+#include <iostream>
+
+#include <qpoint.h>
+
+int main() {
+
+    QPoint p0;
+    QPoint p1 = QPoint(1,1);
+    QPoint p2 = QPoint(3,3);
+    QPoint p3 = p1 + p2;
+    QPoint p4 = p3;
+    QPoint p5 = p3;
+
+    p5.setX(10);
+    p5.setY(10);
+    p5 += p1;
+    p5 -= p2;
+    p5 *= 3;
+    p5 /= 2;
+    
+    cout << p1 << endl;
+    cout << p2 << endl;
+    cout << p3 << endl;
+    cout << p0.isNull() << endl;
+    cout << p1.isNull() << endl;
+    cout << (p1 == p4) << endl;
+    cout << (p3 == p4) << endl;
+    cout << (p1 != p4) << endl;
+    cout << (p3 != p4) << endl;
+    cout << p5 << endl;
+
+    return 0;
+}
diff --git a/WebCore/kwq/tests/qt/qsize-test.chk b/WebCore/kwq/tests/qt/qsize-test.chk
new file mode 100644
index 0000000..3b55ef5
--- /dev/null
+++ b/WebCore/kwq/tests/qt/qsize-test.chk
@@ -0,0 +1,10 @@
+QSize: [w: 1; h: 1]
+QSize: [w: 3; h: 3]
+QSize: [w: 4; h: 4]
+0
+0
+0
+1
+1
+0
+QSize: [w: 12; h: 12]
diff --git a/WebCore/kwq/tests/qt/qsize-test.cpp b/WebCore/kwq/tests/qt/qsize-test.cpp
new file mode 100644
index 0000000..a81ce9d
--- /dev/null
+++ b/WebCore/kwq/tests/qt/qsize-test.cpp
@@ -0,0 +1,33 @@
+#include <iostream>
+
+#include <qsize.h>
+
+int main() {
+
+    QSize s0;
+    QSize s1 = QSize(1,1);
+    QSize s2 = QSize(3,3);
+    QSize s3 = s1 + s2;
+    QSize s4 = s3;
+    QSize s5 = s3;
+
+    s5.setWidth(10);
+    s5.setHeight(10);
+    s5 += s1;
+    s5 -= s2;
+    s5 *= 3;
+    s5 /= 2;
+    
+    cout << s1 << endl;
+    cout << s2 << endl;
+    cout << s3 << endl;
+    cout << s0.isNull() << endl;
+    cout << s1.isNull() << endl;
+    cout << (s1 == s4) << endl;
+    cout << (s3 == s4) << endl;
+    cout << (s1 != s4) << endl;
+    cout << (s3 != s4) << endl;
+    cout << s5 << endl;
+
+    return 0;
+}
diff --git a/WebCore/kwq/tests/test.list b/WebCore/kwq/tests/test.list
new file mode 100644
index 0000000..13f84d8
--- /dev/null
+++ b/WebCore/kwq/tests/test.list
@@ -0,0 +1,3 @@
+# Qt suite
+qt/qpoint-test
+qt/qsize-test
diff --git a/WebCore/src/kwq/qt/qptrdict.h b/WebCore/src/kwq/qt/qptrdict.h
index cdb984b..1d74ef3 100644
--- a/WebCore/src/kwq/qt/qptrdict.h
+++ b/WebCore/src/kwq/qt/qptrdict.h
@@ -30,6 +30,12 @@
 #include <config.h>
 #endif
 
+// _KWQ_COMPLETE_ ==============================================================
+
+#ifdef _KWQ_COMPLETE_
+#include <_qptrdict.h>
+#else
+
 #include <KWQDef.h>
 #include <_qcollection.h>
 
diff --git a/WebCore/src/kwq/qt/qvector.h b/WebCore/src/kwq/qt/qvector.h
index 5ebe386..3b4ad5b 100644
--- a/WebCore/src/kwq/qt/qvector.h
+++ b/WebCore/src/kwq/qt/qvector.h
@@ -30,6 +30,12 @@
 #include <config.h>
 #endif
 
+// _KWQ_COMPLETE_ ==============================================================
+
+#ifdef _KWQ_COMPLETE_
+#include <_qvector.h>
+#else
+
 #include <KWQDef.h>
 #include <_qcollection.h>
 
diff --git a/WebCore/src/kwq/qt/Makefile.in b/WebCore/src/kwq/tests/Makefile.in
similarity index 78%
copy from WebCore/src/kwq/qt/Makefile.in
copy to WebCore/src/kwq/tests/Makefile.in
index 82e0aba..5207acc 100644
--- a/WebCore/src/kwq/qt/Makefile.in
+++ b/WebCore/src/kwq/tests/Makefile.in
@@ -15,36 +15,33 @@ include $(TOPSRCDIR)/Makefile.vars
 #----------------------------------------------------------------------
 # Set variables for this directory
 
-SOURCES = $(wildcard *.cpp)
 CXXOBJECTS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
 
-OBJECTS = $(CXXOBJECTS)
-
-LIBRARY = lib_qt.a
+PROGRAM = harness
 
 CLEAN_FILES = *.o \
-    *.a \
+    $(PROGRAM) \
     $(NULL)
 
 #----------------------------------------------------------------------
 # Set flags for this directory
 
-CXXFLAGS = $(BASECXXFLAGS) \
-    -I$(TOPSRCDIR) \
-    -I.. \
-    -I. \
+CFLAGS = $(BASECFLAGS) \
+    -Wall \
+    -O2 \
     $(NULL)
 
-DEPFLAGS = $(CXXFLAGS)
+DEPFLAGS = $(CFLAGS)
 
 #----------------------------------------------------------------------
 # Set targets for this directory
 
-all: $(OBJECTS) $(LIBRARY)
+all: $(OBJECTS) $(PROGRAM)
+
+$(PROGRAM): harness.o
+	$(CC) -o $@ $< $(LDFLAGS)
 
-$(LIBRARY): $(OBJECTS)
-	$(AR) $(ARFLAGS) $(LIBRARY) $(CXXOBJECTS)
-	$(RANLIB) $(LIBRARY)
+depend: 
 
 #----------------------------------------------------------------------
 # include make rules boilerplate
diff --git a/WebCore/src/kwq/tests/harness.c b/WebCore/src/kwq/tests/harness.c
new file mode 100644
index 0000000..1e3e499
--- /dev/null
+++ b/WebCore/src/kwq/tests/harness.c
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 2001 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define LIST "test.list"
+#define BUFSIZE 1024
+#define MAX_NAME_LEN 40
+#define TEST_ERR_LEN 29
+#define CHK_ERR_LEN 28
+
+int ok = 0;
+int no = 0;
+
+void ppad(int pad) {
+    if (pad > 0) {
+        while (--pad) {
+            printf(".");
+        }
+    }
+}
+
+void *emalloc(size_t size) {
+     void *p;
+     
+     p = malloc(size);
+     
+     if (!p) {
+          fprintf(stderr, "memory allocation failure\n");
+          exit(1);
+     }
+     
+     return p;
+}
+
+int getfile(const char *filename, char **text) {
+    FILE *file = NULL;
+    int total_read = 0;
+
+    file = fopen(filename, "r");
+    if (file == NULL) {
+        fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, strerror(errno), filename);
+        return -1;
+    }
+    else {
+        int char_size = sizeof(char);
+        int index = 0;
+        int cap = BUFSIZE;
+        char *buf;
+
+        *text = emalloc(cap);
+        buf = emalloc(BUFSIZE);
+    
+        do {
+            int read;
+            read = fread(buf, char_size, BUFSIZE, file);
+            if (ferror(file) != 0) {
+                free(buf);
+                free(*text);
+                fclose(file);
+                fprintf(stderr, "io error: %d\n", __LINE__);
+                exit(1);
+            }
+            total_read += read;
+            if (total_read > cap) {
+                char *newmem = realloc(*text, (cap * 2));
+                if(newmem == NULL) {
+                    free(buf);
+                    free(*text);
+                    fprintf(stderr, "io error: %d\n", __LINE__);
+                    exit(1);
+                }
+                *text = newmem;    
+                cap = total_read;
+            }
+            memcpy((*text) + index, buf, read);
+            index = total_read;
+        }
+        while (feof(file) == 0);
+        free(buf);
+        (*text)[total_read] = '\0';
+        /* close file */
+        if (fclose(file) != 0) {
+            fprintf(stderr, "io error: %d\n", __LINE__);
+            exit(1);
+        }
+    }
+    return total_read;
+}
+
+int runtest(const char *test) {
+    int pid;
+    int fd;
+    char chkname[64];
+    char outname[64];
+    char *out;
+    char *chk;
+    int outlen;
+    int chklen;
+    struct stat buf;
+    int pad;
+    int result;
+
+    result = 0;
+
+    strcpy(chkname, test);
+    strcat(chkname, ".chk");
+
+    strcpy(outname, test);
+    strcat(outname, ".out");
+
+    printf("%s", test);
+    
+    if(stat(test, &buf)) {
+        pad = TEST_ERR_LEN - strlen(test);
+        ppad(pad);
+        printf("test file not found\n");
+        return -1;    
+    }
+
+    if(stat(chkname, &buf)) {
+        pad = CHK_ERR_LEN - strlen(test);
+        ppad(pad);
+        printf("check file not found\n");
+        return -1;    
+    }
+
+    /* pad with dots */
+    pad = MAX_NAME_LEN - strlen(test);
+    ppad(pad);
+
+    /* Fork a child to run the test */
+    pid = fork();
+    if (pid == 0) {     /* child */
+
+        /* Create a temporary file to catch output of test program */
+        fd = open(outname, O_CREAT | O_WRONLY, S_IRWXU);
+        if (fd == -1) {
+            fprintf(stderr, "open of outfile failed\n");
+        }
+        else {
+            /* Redirect stdout to a temporary file */
+            close(1);
+            dup(fd);
+            close(fd);
+
+            /* exec test file */
+            result = execl(test, test, NULL);
+
+            fprintf(stderr, "exec of %s failed\n", test);
+            exit(1);
+        }
+    } 
+    else if (pid == -1) {
+        fprintf(stderr, "fork failed\n");
+        exit(1);
+    }
+
+    /* Wait for child to complete before returning */
+    while (wait(NULL) != pid) {}  /* empty loop */
+
+    /* collect result and check output from files */    
+    outlen = getfile(outname, &out);
+    chklen = getfile(chkname, &chk);
+        
+    /* compare output with expected result */
+    if (result != 0) {
+        no++;
+        printf("fail [exit code]\n");
+    }
+    else if (outlen != chklen) {
+        no++;
+        printf("fail [!= lengths]\n");
+    }
+    else if (memcmp(out, chk, chklen) != 0) {
+        no++;
+         printf("fail [!= output]\n");
+   } 
+    else {
+        ok++;
+        printf(".ok\n");
+    }
+
+    free(out);
+    free(chk);
+
+    /* clean up the temporary file */
+    remove(outname);
+
+    return 0;
+}
+
+int main(int argc, char **argv) {
+    
+    char **suites;
+    char *list;
+    char *line;
+    int num;
+    int t;
+    int i;
+    int head;
+
+    printf("harness begin\n");
+    printf("=========================================================\n");
+
+    if (argc < 2) {
+        suites = emalloc(sizeof(char *));
+        suites[0] = LIST;
+        num = 1;
+    }
+    else {
+        num = argc - 1;
+        suites = emalloc(num * sizeof(char *));
+        for (i = 0; i < num; i++) {
+            suites[i] = argv[i + 1];
+        }
+    }
+
+    head = 1;
+    for (i = 0; i < num; i++) {
+        if (getfile(suites[i], &list) == -1) {
+          continue;
+        }
+        line = strtok(list, "\n");
+        while (line != NULL) {
+            if (line[0] == '#') {
+                head = 0;
+                printf("%s\n", line);
+            }
+            else {
+                if (head == 0) {
+                    printf("Test Name                             Output\n");
+                    printf("---------------------------------------------------------\n");
+                }
+                head = 1;
+                runtest(line);
+            }
+            line = strtok(NULL, "\n");
+        }
+        free(list);
+    }
+    free(suites);
+
+    t = ok + no;
+    printf("---------------------------------------------------------\n");
+    printf("Total Tests Run:  %4d\n", t);
+    printf("---------------------------------------------------------\n");
+    printf("Summary            Output\n");
+    printf("Passed:      %4d (%6.2f%%)\n", 
+             ok, ((float)ok / (float)t * 100)
+             );
+    printf("Failed:      %4d (%6.2f%%)\n", 
+             no, ((float)no / (float)t * 100)
+             );
+    printf("=========================================================\n");
+    printf("harness done\n");
+
+    return no;
+
+}
+
+/*=============================================================================
+// end of file: $RCSfile$
+==============================================================================*/
+
diff --git a/WebCore/src/kwq/tests/qt/Makefile.in b/WebCore/src/kwq/tests/qt/Makefile.in
index ae3b37e..854bd0d 100644
--- a/WebCore/src/kwq/tests/qt/Makefile.in
+++ b/WebCore/src/kwq/tests/qt/Makefile.in
@@ -19,16 +19,20 @@ CXXOBJECTS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
 
 OBJECTS = $(CXXOBJECTS)
 
-PROGRAM = test
+PROGRAMS = \
+    qpoint-test \
+    qsize-test \
+    $(NULL)
 
 CLEAN_FILES = *.o \
-    $(PROGRAM) \
+    $(PROGRAMS) \
     $(NULL)
 
 #----------------------------------------------------------------------
 # Set flags for this directory
 
 CXXFLAGS = $(BASECXXFLAGS) \
+    -Wall \
     -DQ_DELETING_VOID_UNDEFINED \
     -DQT_NO_TEXTCODEC \
     -DQT_NO_DATASTREAM \
@@ -49,9 +53,12 @@ DEPFLAGS = $(CXXFLAGS)
 #----------------------------------------------------------------------
 # Set targets for this directory
 
-all: $(OBJECTS) $(PROGRAM)
+all: $(OBJECTS) $(PROGRAMS)
+
+qpoint-test: qpoint-test.o
+	$(CXX) -o $@ $< $(LDFLAGS)
 
-$(PROGRAM): $(OBJECTS)
+qsize-test: qsize-test.o
 	$(CXX) -o $@ $< $(LDFLAGS)
 
 depend: 
diff --git a/WebCore/src/kwq/tests/qt/qpoint-test.chk b/WebCore/src/kwq/tests/qt/qpoint-test.chk
new file mode 100644
index 0000000..21a01bd
--- /dev/null
+++ b/WebCore/src/kwq/tests/qt/qpoint-test.chk
@@ -0,0 +1,10 @@
+QPoint: [x: 1; h: 1]
+QPoint: [x: 3; h: 3]
+QPoint: [x: 4; h: 4]
+1
+0
+0
+1
+1
+0
+QPoint: [x: 12; h: 12]
diff --git a/WebCore/src/kwq/tests/qt/qpoint-test.cpp b/WebCore/src/kwq/tests/qt/qpoint-test.cpp
new file mode 100644
index 0000000..98283c5
--- /dev/null
+++ b/WebCore/src/kwq/tests/qt/qpoint-test.cpp
@@ -0,0 +1,33 @@
+#include <iostream>
+
+#include <qpoint.h>
+
+int main() {
+
+    QPoint p0;
+    QPoint p1 = QPoint(1,1);
+    QPoint p2 = QPoint(3,3);
+    QPoint p3 = p1 + p2;
+    QPoint p4 = p3;
+    QPoint p5 = p3;
+
+    p5.setX(10);
+    p5.setY(10);
+    p5 += p1;
+    p5 -= p2;
+    p5 *= 3;
+    p5 /= 2;
+    
+    cout << p1 << endl;
+    cout << p2 << endl;
+    cout << p3 << endl;
+    cout << p0.isNull() << endl;
+    cout << p1.isNull() << endl;
+    cout << (p1 == p4) << endl;
+    cout << (p3 == p4) << endl;
+    cout << (p1 != p4) << endl;
+    cout << (p3 != p4) << endl;
+    cout << p5 << endl;
+
+    return 0;
+}
diff --git a/WebCore/src/kwq/tests/qt/qsize-test.chk b/WebCore/src/kwq/tests/qt/qsize-test.chk
new file mode 100644
index 0000000..3b55ef5
--- /dev/null
+++ b/WebCore/src/kwq/tests/qt/qsize-test.chk
@@ -0,0 +1,10 @@
+QSize: [w: 1; h: 1]
+QSize: [w: 3; h: 3]
+QSize: [w: 4; h: 4]
+0
+0
+0
+1
+1
+0
+QSize: [w: 12; h: 12]
diff --git a/WebCore/src/kwq/tests/qt/qsize-test.cpp b/WebCore/src/kwq/tests/qt/qsize-test.cpp
new file mode 100644
index 0000000..a81ce9d
--- /dev/null
+++ b/WebCore/src/kwq/tests/qt/qsize-test.cpp
@@ -0,0 +1,33 @@
+#include <iostream>
+
+#include <qsize.h>
+
+int main() {
+
+    QSize s0;
+    QSize s1 = QSize(1,1);
+    QSize s2 = QSize(3,3);
+    QSize s3 = s1 + s2;
+    QSize s4 = s3;
+    QSize s5 = s3;
+
+    s5.setWidth(10);
+    s5.setHeight(10);
+    s5 += s1;
+    s5 -= s2;
+    s5 *= 3;
+    s5 /= 2;
+    
+    cout << s1 << endl;
+    cout << s2 << endl;
+    cout << s3 << endl;
+    cout << s0.isNull() << endl;
+    cout << s1.isNull() << endl;
+    cout << (s1 == s4) << endl;
+    cout << (s3 == s4) << endl;
+    cout << (s1 != s4) << endl;
+    cout << (s3 != s4) << endl;
+    cout << s5 << endl;
+
+    return 0;
+}
diff --git a/WebCore/src/kwq/tests/test.list b/WebCore/src/kwq/tests/test.list
new file mode 100644
index 0000000..13f84d8
--- /dev/null
+++ b/WebCore/src/kwq/tests/test.list
@@ -0,0 +1,3 @@
+# Qt suite
+qt/qpoint-test
+qt/qsize-test

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list