ユニットテストを修正
authorj8takagi <j8takagi@nifty.com>
Tue, 28 Dec 2010 07:01:44 +0000 (16:01 +0900)
committerj8takagi <j8takagi@nifty.com>
Tue, 28 Dec 2010 07:01:44 +0000 (16:01 +0900)
test/unit/getgr/0.txt [new file with mode: 0644]
test/unit/getgr/Makefile [new file with mode: 0644]
test/unit/getgr/cmd.c [new file with mode: 0644]

diff --git a/test/unit/getgr/0.txt b/test/unit/getgr/0.txt
new file mode 100644 (file)
index 0000000..8b7ead1
--- /dev/null
@@ -0,0 +1,30 @@
+== Generel Register ==
+       #FFFF
+0      #FFFF
+aaa    #FFFF
+GR     #FFFF
+GR8    #FFFF
+GR20   #FFFF
+GR0    #0000
+GR1    #0001
+GR2    #0002
+GR3    #0003
+GR4    #0004
+GR5    #0005
+GR6    #0006
+GR7    #0007
+== Index Register ==
+       #FFFF
+0      #FFFF
+aaa    #FFFF
+GR     #FFFF
+GR8    #FFFF
+GR20   #FFFF
+GR0    #0000   Error - 120     GR0 in operand x
+GR1    #0001
+GR2    #0002
+GR3    #0003
+GR4    #0004
+GR5    #0005
+GR6    #0006
+GR7    #0007
diff --git a/test/unit/getgr/Makefile b/test/unit/getgr/Makefile
new file mode 100644 (file)
index 0000000..1e7d9a2
--- /dev/null
@@ -0,0 +1,11 @@
+include ../Define.mk
+include ../Define_test.mk
+include ../Test.mk
+
+.INTERMEDIATE: cmd
+
+SRCDIR = ../../../src
+SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/token.c
+
+cmd: cmd.c $(SRCFILES)
+       gcc -g -Wall -I ../../../include -o $@ $^
diff --git a/test/unit/getgr/cmd.c b/test/unit/getgr/cmd.c
new file mode 100644 (file)
index 0000000..bdd89f4
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include "assemble.h"
+#include "cerr.h"
+
+WORD getgr(const char *str, bool is_x);
+
+int main(){
+    int i, j;
+    char *title = malloc(64);
+    WORD r;
+    bool is_x[] = {
+        false, true
+    };
+    char *str[] = {
+        "", "0", "aaa", "GR", "GR8", "GR20",
+        "GR0", "GR1", "GR2", "GR3", "GR4", "GR5", "GR6", "GR7"
+    };
+    static CERR cerr_getgr[] = {
+        { 120, "GR0 in operand x" },
+    };
+
+    cerr_init();    /* エラーの初期化 */
+    addcerrlist(ARRAYSIZE(cerr_getgr), cerr_getgr);
+    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(cerr->num > 0) {
+                printf("\tError - %d\t%s", cerr->num, cerr->msg);
+            }
+            printf("\n");
+        }
+    }
+    freecerr();
+    return 0;
+}