Annotation of hatari/tests/debugger/test-evaluate.c, revision 1.1.1.1

1.1       root        1: /* 
                      2:  * Code to test Hatari expression evaluation in src/debug/evaluate.c
                      3:  */
                      4: #include <stdio.h>
                      5: #include <SDL_types.h>
                      6: #include <stdbool.h>
                      7: #include "stMemory.h"
                      8: #include "evaluate.h"
                      9: #include "m68000.h"
                     10: #include "main.h"
                     11: #include "screen.h"
                     12: #include "video.h"
                     13: 
                     14: #define VBL_VALUE 21
                     15: 
                     16: int main(int argc, const char *argv[])
                     17: {
                     18:        /* expected to fail */
                     19:        const char *failure[] = {
                     20:                "1+2*",
                     21:                "*1+2",
                     22:                "1+(2",
                     23:                "1)+2",
                     24:                "foo+1+bar",
                     25:        };
                     26:        /* expected to succeed, with given result */
                     27:        struct {
                     28:                const char *expression;
                     29:                Uint32 result;
                     30:        } success[] = {
                     31:                { "1+2*3", 7 },
                     32:                { "(2+5)*3", 9 },
                     33:                { "d0 + 2", 12 },
                     34:                { "VBL+10", VBL_VALUE + 10 },
                     35:                { "~%101 & $f0f0f ^ 0x21 * 0x200", 0xF4D0A },
                     36:        };
                     37:        int i, offset, tests = 0, errors = 0;
                     38:        const char *expression, *errstr;
                     39:        Uint32 result;
                     40: 
                     41:        /* set values needed by above succesful calculations */
                     42:        nVBLs = VBL_VALUE;
                     43:        memset(Regs, 0, sizeof(Regs));
                     44:        Regs[REG_D0] = 10;
                     45:        memset(STRam, 0, sizeof(STRam));
                     46:        /* expressions use long access */
                     47:        STRam[2+5] = 0;
                     48:        STRam[2+6] = 0;
                     49:        STRam[2+7] = 0;
                     50:        STRam[2+8] = 3;
                     51: 
                     52:        fprintf(stderr, "\nExpressions that should FAIL:\n");
                     53: 
                     54:        for (i = 0; i < ARRAYSIZE(failure); i++) {
                     55:                expression = failure[i];
                     56:                fprintf(stderr, "- '%s'\n", expression);
                     57:                errstr = Eval_Expression(expression, &result, &offset, false);
                     58:                if (errstr) {
                     59:                        fprintf(stderr, "%*c-%s\n",
                     60:                                3+offset, '^', errstr);
                     61:                } else {
                     62:                        fprintf(stderr, "  => %x\n  ***Unexpected SUCCESS from expression***\n",
                     63:                                (Uint32)result);
                     64:                        errors++;
                     65:                }
                     66:        }
                     67:        tests += i;
                     68: 
                     69:        fprintf(stderr, "\nExpressions that should SUCCEED with given result:\n");
                     70: 
                     71:        for (i = 0; i < ARRAYSIZE(success); i++) {
                     72:                expression = success[i].expression;
                     73:                fprintf(stderr, "- '%s'\n", expression);
                     74:                errstr = Eval_Expression(expression, &result, &offset, false);
                     75:                if (errstr) {
                     76:                        fprintf(stderr, "%*c-%s\n  ***Unexpected ERROR in expression***\n",
                     77:                                3+offset, '^', errstr);
                     78:                        errors++;
                     79:                } else if (result != success[i].result) {
                     80:                        fprintf(stderr, "  => %x (not %x)\n  ***Wrong result from expression***\n",
                     81:                                (Uint32)result, (Uint32)success[i].result);
                     82:                        errors++;
                     83:                } else {
                     84:                        fprintf(stderr, "  => 0x%x\n", (Uint32)result);
                     85:                }
                     86:        }
                     87:        tests += i;
                     88: 
                     89:        if (errors) {
                     90:                fprintf(stderr, "\n***Detected %d ERRORs in %d automated tests!***\n\n",
                     91:                        errors, tests);
                     92:        } else {
                     93:                fprintf(stderr, "\nFinished without any errors!\n\n");
                     94:        }
                     95:        return errors;
                     96: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.