#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <setjmp.h>#include <cmocka.h>#include "m68k.h"#include "run.h"#include "sym.h"#include "tests.h" static voidtest_c9open_end(void){ uint8_t *ctx, *b; ctx = mem+m68k_get_reg(NULL, M68K_REG_A0); assert_ptr_equal(ctx, mem+Ctx); b = mem+Begindst; assert_int_equal(ru32le(b), bufsz); // size assert_int_equal(b[4], EXPR_Topen); // type assert_int_equal(ru16le(b+5), 0); // tag assert_int_equal(ru32le(b+7), 0x12345678); // fid assert_int_equal(b[11], EXPR_C9write|EXPR_C9trunc); // mode assert_int_equal(b[12], fill); executed |= End;} voidtest_c9open(void **state){ uint8_t *ctx; uint16_t sr; (void)state; ctx = mem+Ctx; initctx(ctx, Msize); c9begin = generic_begin; c9end = test_c9open_end; executed = 0; m68k_set_reg(M68K_REG_A0, Ctx); m68k_set_reg(M68K_REG_D0, 0x12345678); m68k_set_reg(M68K_REG_D1, EXPR_C9write|EXPR_C9trunc); jsr(Progstart+SYM_c9open); sr = m68k_get_reg(NULL, M68K_REG_SR); assert_false(sr & SR_C); // check if the data buffer was used assert_int_equal(executed, Begin|End);}
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <cmocka.h>
#include "m68k.h"
#include "run.h"
#include "sym.h"
#include "tests.h"
static void
test_c9open_end(void)
{
uint8_t *ctx, *b;
ctx = mem+m68k_get_reg(NULL, M68K_REG_A0);
assert_ptr_equal(ctx, mem+Ctx);
b = mem+Begindst;
assert_int_equal(ru32le(b), bufsz); // size
assert_int_equal(b[4], EXPR_Topen); // type
assert_int_equal(ru16le(b+5), 0); // tag
assert_int_equal(ru32le(b+7), 0x12345678); // fid
assert_int_equal(b[11], EXPR_C9write|EXPR_C9trunc); // mode
assert_int_equal(b[12], fill);
executed |= End;
}
void
test_c9open(void **state)
{
uint8_t *ctx;
uint16_t sr;
(void)state;
ctx = mem+Ctx;
initctx(ctx, Msize);
c9begin = generic_begin;
c9end = test_c9open_end;
executed = 0;
m68k_set_reg(M68K_REG_A0, Ctx);
m68k_set_reg(M68K_REG_D0, 0x12345678);
m68k_set_reg(M68K_REG_D1, EXPR_C9write|EXPR_C9trunc);
jsr(Progstart+SYM_c9open);
sr = m68k_get_reg(NULL, M68K_REG_SR);
assert_false(sr & SR_C);
// check if the data buffer was used
assert_int_equal(executed, Begin|End);
}