Annotation of hatari/tests/test-evaluate.c, revision 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 "evaluate.h"
        !             8: #include "main.h"
        !             9: 
        !            10: int main(int argc, const char *argv[])
        !            11: {
        !            12:        /* expected to fail */
        !            13:        const char *failure[] = {
        !            14:                "1+2*",
        !            15:                "*1+2",
        !            16:                "1+(2",
        !            17:                "1)+2",
        !            18:        };
        !            19:        /* expected to succeed, with given result */
        !            20:        struct {
        !            21:                const char *expression;
        !            22:                Uint32 result;
        !            23:        } success[] = {
        !            24:                { "1+2*3", 7 },
        !            25:                { "(1+2)*3", 9 },
        !            26:                { "((0x21 * 0x200) + (-5)) ^ (~%111 & $f0f0f0)", 0xF0B10B },
        !            27:        };
        !            28:        int i, offset, tests = 0, errors = 0;
        !            29:        const char *expression, *errstr;
        !            30:        Uint32 result;
        !            31: 
        !            32:        fprintf(stderr, "\nExpressions that should FAIL:\n");
        !            33: 
        !            34:        for (i = 0; i < ARRAYSIZE(failure); i++) {
        !            35:                expression = failure[i];
        !            36:                errstr = Eval_Expression(expression, &result, &offset, false);
        !            37:                if (errstr) {
        !            38:                        fprintf(stderr, "- '%s'\n%*c-%s\n",
        !            39:                                expression, 3+offset, '^', errstr);
        !            40:                } else {
        !            41:                        fprintf(stderr, "***Unexpected SUCCESS from expression***\n- '%s' = %x\n",
        !            42:                                expression, (Uint32)result);
        !            43:                        errors++;
        !            44:                }
        !            45:        }
        !            46:        tests += i;
        !            47: 
        !            48:        fprintf(stderr, "\nExpressions that should SUCCEED with given result:\n");
        !            49:        
        !            50:        for (i = 0; i < ARRAYSIZE(success); i++) {
        !            51:                expression = success[i].expression;
        !            52:                errstr = Eval_Expression(expression, &result, &offset, false);
        !            53:                if (errstr) {
        !            54:                        fprintf(stderr, "***Unexpected ERROR in expression***\n- '%s'\n%*c-%s\n",
        !            55:                                expression, 3+offset, '^', errstr);
        !            56:                        errors++;
        !            57:                } else if (result != success[i].result) {
        !            58:                        fprintf(stderr, "***Wrong result from expression***\n- '%s' = %x (not %x)\n",
        !            59:                                expression, (Uint32)result, (Uint32)success[i].result);
        !            60:                        errors++;
        !            61:                } else {
        !            62:                        fprintf(stderr, "- '%s' = 0x%x\n",
        !            63:                                expression, (Uint32)result);
        !            64:                }
        !            65:        }
        !            66:        tests += i;
        !            67: 
        !            68:        if (errors) {
        !            69:                fprintf(stderr, "\n***Detected %d ERRORs in %d automated tests!***\n\n",
        !            70:                        errors, tests);
        !            71:        } else {
        !            72:                fprintf(stderr, "\nFinished without any errors!\n\n");
        !            73:        }
        !            74:        return errors;
        !            75: }

unix.superglobalmegacorp.com

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