]> j8takagi.net Git Repository - YACASL2.git/commitdiff
ユニットテストの修正
authorj8takagi <j8takagi@nifty.com>
Sun, 21 Mar 2010 18:46:54 +0000 (03:46 +0900)
committerj8takagi <j8takagi@nifty.com>
Sun, 21 Mar 2010 18:46:54 +0000 (03:46 +0900)
21 files changed:
test/unit/Makefile
test/unit/TEST.mk
test/unit/addcerrlist/0.txt [new file with mode: 0644]
test/unit/cerrtest/0.txt
test/unit/getcmdcode/getcmdcode.c
test/unit/getcmdtype/getcmdtype.c
test/unit/getgr/getgr.c
test/unit/h2word/h2word.c
test/unit/hash/0.txt
test/unit/hash/hash.c
test/unit/linetok/0.txt
test/unit/linetok/linetok.c
test/unit/n2word/getint.c
test/unit/opdtok/0.txt
test/unit/opdtok/opdtok.c
test/unit/print_cerrmsg/Makefile
test/unit/print_cerrmsg/print_cerrmsg.c
test/unit/print_cmdtype_code/print_cmdtype_code.c
test/unit/print_cmdtype_code_hash/print_cmdtype_code.c
test/unit/print_code_type/print_code_type.c
test/unit/print_code_type_hash/print_code_type.c

index e1a3dff528fce4e7374bd4db679de108ffdae63c..f5b6616390282bb18daa993f20e78e88ede74a26 100644 (file)
@@ -14,7 +14,7 @@ all: check report
 check:
        @rm -f $(LOGFILE)
        @for target in $(TESTS); do \
-         $(MAKE) check -C $$target; \
+         $(MAKE) check -sC $$target; \
      done
 $(LOGFILE):
        @for target in $(TESTS); do \
index 4e506fc322fbbc6592c3e6427030384d20385678..2a26ddeb1e318ed3c8c2bc69d7210e044a0735a4 100644 (file)
@@ -15,6 +15,9 @@ COMMONSRC = $(SRCDIR)/word.o $(SRCDIR)/struct.o $(SRCDIR)/hash.o $(SRCDIR)/cmd.o
 ASSRC = $(SRCDIR)/assemble.o $(SRCDIR)/token.o $(SRCDIR)/label.o $(SRCDIR)/macro.o
 EXECSRC = $(SRCDIR)/exec.o $(SRCDIR)/dump.o
 
+ifeq "$(UCLASS)" "ALL"
+  SRC = $(COMMONSRC) $(ASSRC) $(EXECSRC)
+endif
 ifeq "$(UCLASS)" "AS"
   SRC = $(COMMONSRC) $(ASSRC)
 endif
diff --git a/test/unit/addcerrlist/0.txt b/test/unit/addcerrlist/0.txt
new file mode 100644 (file)
index 0000000..96fdd38
--- /dev/null
@@ -0,0 +1,36 @@
+126: source file is not specified
+101: label already defined
+102: label table is full
+103: label not found
+104: label length is too long
+105: no command in the line
+106: operand mismatch in assemble command
+107: no label in START
+108: not command of operand "r"
+109: not command of operand "r1,r2"
+110: not command of operand "r,adr[,x]"
+111: not command of operand "adr[,x]"
+112: not command of no operand
+113: operand too many in COMET II command
+117: operand too many in DC
+118: operand length too long
+119: out of COMET II memory
+120: GR0 in operand x
+121: cannot get operand token
+122: cannot create hash table
+123: unclosed quote
+124: more than one character in literal
+125: not GR in operand x
+114: not integer
+115: not hex
+116: out of hex range
+114: not integer
+115: not hex
+116: out of hex range
+201: Load object file - full of COMET II memory
+202: SVC input - out of Input memory
+203: SVC output - out of COMET II memory
+204: Program Register (PR) - out of COMET II memory
+205: Stack Pointer (SP) - cannot allocate stack buffer
+206: Address - out of COMET II memory
+207: Stack Pointer (SP) - out of COMET II memory
index fcbc023523b0ca8ccd2a6ff6c3a710fd4f24d800..40776ec20a36eb6003afb2d082f2e3802bab0f3b 100644 (file)
@@ -29,7 +29,7 @@
 205: (null) - 205      Stack Pointer (SP) - cannot allocate stack buffer
 206: (null) - 206      Address - out of COMET II memory
 207: (null) - 207      Stack Pointer (SP) - out of COMET II memory
-999: (null) - 999      unkown error
+999: (null) - 999      unknown error
 101: foobar - 101      foobar: label already defined
 102: foobar - 102      foobar: label table is full
 103: foobar - 103      foobar: label not found
@@ -61,4 +61,4 @@
 205: foobar - 205      foobar: Stack Pointer (SP) - cannot allocate stack buffer
 206: foobar - 206      foobar: Address - out of COMET II memory
 207: foobar - 207      foobar: Stack Pointer (SP) - out of COMET II memory
-999: foobar - 999      foobar: unkown error
+999: foobar - 999      foobar: unknown error
index 2c5286d3f1c522e64a5b20450376308678784a1c..b8eed2b243b67eac2cdc234ae6ccdf4a624231d6 100644 (file)
@@ -23,8 +23,7 @@ int main(){
         { "SVC", ADR_X }, { "RET", NONE }
     };
     create_cmdtype_code();
-    /* エラーの初期化 */
-    cerr = malloc_chk(sizeof(CERR), "cerr");
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
     for(i = 0; i < sizeof(cmdcodelist)/sizeof(cmdcodelist[0]); i++) {
         code = getcmdcode(cmdcodelist[i].cmd, cmdcodelist[i].type);
         printf("%s:0%02o ---> #%04X\n", cmdcodelist[i].cmd, cmdcodelist[i].type, code);
index f020b4e026a5cc0d2222771d1cc2a474d57caad1..2c3337c9ca74f8b6f8525fe4161f04b356c9663d 100644 (file)
@@ -14,12 +14,14 @@ int main(){
         0x6400, 0x6500, 0x6600, 0x7000, 0x7100,
         0x8000, 0xF000, 0x8100
     };
+
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
     create_code_type();
     for(i = 0; i < ARRAYSIZE(codelist); i++) {
         type = getcmdtype(codelist[i]);
         printf("#%04X ---> 0%02o\n", codelist[i], type);
-        if(cerrno != 0) {
-            printf("\t%s", cerrmsg);
+        if(cerr->num != 0) {
+            printf("\t%s", cerr->msg);
             freecerr();
         }
     }
index e342501f6cc799e3bda270d356ca1dde57793fba..c7fc5e3ca5a5bfba35f9a589e51c8a6d7894bb7b 100644 (file)
@@ -12,18 +12,22 @@ int main(){
         "", "0", "aaa", "GR", "GR8", "GR20",
         "GR0", "GR1", "GR2", "GR3", "GR4", "GR5", "GR6", "GR7"
     };
+
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
+    addcerrlist_assemble();
     for(i = 0; i <= 1; i++) {
         title = (is_x[i] == false) ? "Generel Register" : "Index Register";
         printf("== %s ==\n", title);
         for(j = 0; j < ARRAYSIZE(str); j++) {
+            cerr->num = 0;
             r = getgr(str[j], is_x[i]);
             printf("%s\t#%04X", str[j], r);
-            if(cerrno > 0) {
-                printf("\tError - %d\t%s", cerrno, cerrmsg);
-                freecerr();
+            if(cerr->num > 0) {
+                printf("\tError - %d\t%s", cerr->num, cerr->msg);
             }
             printf("\n");
         }
     }
+    freecerr();
     return 0;
 }
index a4c34f8b6b1b36787eb33242bffb8a22d9b183cc..3514241ab6481623e6363b4cfc8e578085bd9d7e 100644 (file)
@@ -9,14 +9,18 @@ int main(){
     char *str[] = {
         "#32768", "#-1", "#G", "#FFFF", "#0", "#1", "#ab", "#AB", "#20"
     };
+
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
+    addcerrlist_word();
     for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
+        cerr->num = 0;
         r = h2word(str[i]);
         printf("%s\t#%04X", str[i], r);
-        if(cerrno > 0) {
-            printf("\tError - %d\t%s", cerrno, cerrmsg);
-            freecerr();
+        if(cerr->num > 0) {
+            printf("\tError - %d\t%s", cerr->num, cerr->msg);
         }
         printf("\n");
     }
+    freecerr();
     return 0;
 }
index bc8892a5584af5dfcac6a4d6716cd7547d2781ab..352fe24bf4ad5b8af5352f2a3fca7e943c1d6885 100644 (file)
@@ -1,3 +1,3 @@
 HASH VALUE: 20
 HASH VALUE: 11
-HASH VALUE: 2
+HASH VALUE: 16
index 57e1cae01fe012376fff31b1df959adf54720974..2acdc81625130e8ed4657780aab0e5c52ba9bb1d 100644 (file)
@@ -37,19 +37,19 @@ unsigned hash_int2(int tsize)
 unsigned hash_char2_int2(int tsize)
 {
     char *str[2] = {"abc", "123"};
-    int num[2] = {19, 11}, i;
+    int num[2] = {19, 11}, i, cnt = 0;
     HKEY *keys[4];
 
     /* ハッシュ共用体の設定 */
     for(i = 0; i < 2; i++) {
-        keys[i] = malloc(sizeof(HKEY));
-        keys[i]->type = CHARS;
-        keys[i]->val.s = strdup(str[i]);
+        keys[cnt] = malloc(sizeof(HKEY));
+        keys[cnt]->type = CHARS;
+        keys[cnt++]->val.s = strdup(str[i]);
     }
-    for(i = 2; i < 4; i++) {
-        keys[i] = malloc(sizeof(HKEY));
-        keys[i]->type = INT;
-        keys[i]->val.i = num[i];
+    for(i = 0; i < 2; i++) {
+        keys[cnt] = malloc(sizeof(HKEY));
+        keys[cnt]->type = INT;
+        keys[cnt++]->val.i = num[i];
     }
     /* ハッシュ値を取得する */
     return hash(4, keys, tsize);
index b83e906471faafba89f5bed26b89ad537d9643b8..40c7fb315fd6795831521c951e458106c63edac4 100644 (file)
@@ -48,7 +48,9 @@ cl->opdv[0]: GR1
 
 8: 
 cl is NULL
+       error - 121: cannot get operand token
 
 9:     ;comment
 cl is NULL
+       error - 121: cannot get operand token
 
index a4ea1734e053393869cf09d0f10a911a5f407257..28555cd26b2e0fa90d79e5f8f99dc93ea479e445 100644 (file)
@@ -17,8 +17,10 @@ int main(){
         "\n",
         "      ;comment\n"
     };
+
     CMDLINE *testcl = malloc(sizeof(CMDLINE));
-    
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
+    addcerrlist_assemble();
     for(i = 0; i < sizeof testline /sizeof testline[0]; i++) {
         printf("%d: %s", i, testline[i]);
         testcl = linetok(testline[i]);
@@ -36,11 +38,11 @@ int main(){
                 }
             }
         }
-        if(cerrno != 0) {
-            printf("\terror - %d: %s\n", cerrno, cerrmsg);
-            freecerr();
+        if(cerr->num != 0) {
+            printf("\terror - %d: %s\n", cerr->num, cerr->msg);
         }
         printf("\n");
     }
+    freecerr();
     return 0;
 }
index 945db38e5ad10f837b57fb744db802a2fab39b8e..8d1d04eba1b437918185be0ed0ce2fc1d6283623 100644 (file)
@@ -9,14 +9,18 @@ int main(){
         "0", "01", "1a", "-5G", "123", "32767", "32768", "32769",
         "-1", "-2345", "-32768", "-32769", "-32770"
     };
+
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
+    addcerrlist_word();
     for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
+        cerr->num = 0;
         r = n2word(str[i]);
         printf("%s\t0x%04x", str[i], r);
-        if(cerrno > 0) {
-            printf("\tError - %d\t%s", cerrno, cerrmsg);
-            freecerr();
+        if(cerr->num > 0) {
+            printf("\tError - %d\t%s", cerr->num, cerr->msg);
         }
         printf("\n");
     }
+    freecerr();
     return 0;
 }
index 6930eb2b3331182126ae24e3ed570f80fb3f5017..acdfb420efcbc6dbee2fa0067f79b703ee1c1f2a 100644 (file)
@@ -126,7 +126,7 @@ OPDC[36]:7
 OPDC[37]:8
 OPDC[38]:9
 OPDC[39]:0
-Error - 117: operand is too many
+Error - 117: operand too many in DC
 
 '1234567890123456789012345678901234567890'
 OPDC:1
@@ -134,5 +134,5 @@ OPDC[0]:'1234567890123456789012345678901234567890'
 
 '12345678901234567890123456789012345678901'
 OPDC:0
-Error - 118: operand length is too long
+Error - 118: operand length too long
 
index d65a42016427cc7f00745fedfad436a0164a15cd..bad4603d221ee29618f56b88b512459575e5c3f6 100644 (file)
@@ -12,18 +12,22 @@ int main(){
         "\'1234567890123456789012345678901234567890\'",
         "\'12345678901234567890123456789012345678901\'",
     };
+
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
+    addcerrlist_assemble();
     for(i = 0; i < ARRAYSIZE(str); i++) {
+        cerr->num = 0;
         printf("%s\n", str[i]);
         opd = opdtok(str[i]);
         printf("OPDC:%d\n", opd->opdc);
         for(j = 0; j < opd->opdc; j++) {
             printf("OPDC[%d]:%s\n", j, opd->opdv[j]);
         }
-        if(cerrno > 0){
-            printf("Error - %d: %s\n", cerrno, cerrmsg);
-            freecerr();
+        if(cerr->num > 0){
+            printf("Error - %d: %s\n", cerr->num, cerr->msg);
         }
         printf("\n");
     }
+    freecerr();
     return 0;
 }
index fd5d996dba91ecfc67b3e98f533835cdbf585c01..e253b41919f3bd1a7690991acc7f9dd0d9fd235b 100644 (file)
@@ -1,3 +1,3 @@
-UCLASS = COMMON
+UCLASS = ALL
 TESTSRCFILE = ../CERRARRAY.c print_cerrmsg.c
 include ../TEST.mk
index 09c274e20ea246548e46cfdb33f9ead8b06fd399..34de8f85a766856c24ba6a3a26b713d707a0891e 100644 (file)
@@ -1,13 +1,19 @@
 #include <stdio.h>
 #include "casl2.h"
+#include "assemble.h"
+#include "exec.h"
 
 int main(){
-    int i, num;
+    CERRLIST *p;
 
-    for(i = 0; (num = cerr[i].num) > 0; i++) {
-        setcerr(num, NULL);
-        printf("%d: %s\n", cerrno, cerrmsg);
-        freecerr();
+    addcerrlist_word();
+    addcerrlist_assemble();
+    addcerrlist_exec();
+    cerr = malloc_chk(sizeof(CERR), "cerr");    /* エラーの初期化 */
+    for(p = cerrlist; p != NULL; p = p->next) {
+        setcerr(p->cerr->num, NULL);
+        printf("%d: %s\n", cerr->num, cerr->msg);
     }
+    freecerr();
     return 0;
 }
index 04d311e55e096d85a2d3c6fb2f67cc958def0c91..70bcd782ed3f66a4ef5a9813ed6fac35e13c11e1 100644 (file)
@@ -4,10 +4,11 @@
 
 int compare_code(const void *a, const void *b)
 {
-    const CMDTYPECODE ca = **(const CMDTYPECODE **)a;
-    const CMDTYPECODE cb = **(const CMDTYPECODE **)b;
+    const CMD ca = **(const CMD **)a;
+    const CMD cb = **(const CMD **)b;
     int diff;
-    if((diff = strcmp(ca.cmd, cb.cmd)) == 0) {
+
+    if((diff = strcmp(ca.name, cb.name)) == 0) {
         return ca.type - cb.type;
     } else {
         return diff;
@@ -18,19 +19,19 @@ int compare_code(const void *a, const void *b)
 void print_cmdtype_code()
 {
     int i, j = 0;
-    CMDCODETAB *np;
-    CMDTYPECODE **ar;
-    ar = malloc(sizeof(*ar) * cmdtypecodesize);
-    for(i = 0; i < cmdtabsize; i++) {
+    CMDTAB *np;
+    CMD **ar;
+    ar = malloc(sizeof(*ar) * comet2cmdsize);
+    for(i = 0; i < comet2cmdsize; i++) {
         np = cmdtype_code[i];
         while(np != NULL) {
-            ar[j++] = np->cmdtypecode;
+            ar[j++] = np->cmd;
             np = np->next;
         }
     }
-    qsort(ar, cmdcodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
-    for(i = 0; i < cmdcodesize; i++) {
-        fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->cmd, ar[i]->type, ar[i]->code);
+    qsort(ar, comet2cmdsize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
+    for(i = 0; i < comet2cmdsize; i++) {
+        fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->name, ar[i]->type, ar[i]->code);
     }
 }
 
index d075ae469e08f3b4b604ad763b0f4e44e73c40cb..ba26a740019487149e2f6f5a15e10a7334cc1a1b 100644 (file)
@@ -4,12 +4,12 @@
 void print_cmdtype_code()
 {
     int i;
-    CMDCODETAB *np;
-    for(i = 0; i < cmdtabsize; i++){
+    CMDTAB *np;
+    for(i = 0; i < comet2cmdsize; i++){
         np = cmdtype_code[i];
         while(np != NULL) {
             fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n",
-                    i, np->cmdtypecode->cmd, np->cmdtypecode->type, np->cmdtypecode->code);
+                    i, np->cmd->name, np->cmd->type, np->cmd->code);
             np = np->next;
         }
     }
index a7ba676cf7e5bbc4592984a3c178df16cde6dd5c..0a5a3128d7cc35415a5ccda963629600ff76c74e 100644 (file)
@@ -3,26 +3,26 @@
 
 int compare_code(const void *a, const void *b)
 {
-    return (**(const CMDTYPECODE **)a).code - (**(const CMDTYPECODE **)b).code;
+    return (**(const CMD **)a).code - (**(const CMD **)b).code;
 }
 
 /* 命令コードがキーのハッシュ表を表示する */
 void print_code_type()
 {
     int i, j = 0;
-    CMDCODETAB *np;
-    CMDTYPECODE **ar;
-    ar = malloc(sizeof(*ar) * cmdtypecodesize);
+    CMDTAB *np;
+    CMD **ar;
+    ar = malloc(sizeof(*ar) * comet2cmdsize);
     for(i = 0; i < cmdtabsize; i++) {
         np = code_type[i];
         while(np != NULL) {
-            ar[j++] = np->cmdtypecode;
+            ar[j++] = np->cmd;
             np = np->next;
         }
     }
-    qsort(ar, cmdtypecodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
-    for(i = 0; i < cmdtypecodesize; i++) {
-        fprintf(stdout, "#%04X\t0%02o\t%s\n", ar[i]->code, ar[i]->type, ar[i]->cmd);
+    qsort(ar, comet2cmdsize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
+    for(i = 0; i < comet2cmdsize; i++) {
+        fprintf(stdout, "#%04X\t0%02o\t%s\n", ar[i]->code, ar[i]->type, ar[i]->name);
     }
 }
 
index a8860c463c3ad462a975319bd5c963c666951d7f..80fea831cc9b8cca0f6401fb7bc36486fc5dc469 100644 (file)
@@ -5,11 +5,11 @@
 void print_code_type()
 {
     int i;
-    CMDCODETAB *np;
+    CMDTAB *np;
     for(i = 0; i < cmdtabsize; i++){
         for(np = code_type[i]; np != NULL; np = np->next) {
             fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n",
-                    i, np->cmdtypecode->code, np->cmdtypecode->type, np->cmdtypecode->cmd);
+                    i, np->cmd->code, np->cmd->type, np->cmd->name);
         }
     }
 }