1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-30 08:51:53 +00:00
erc-c/tests/mos6502.branch.c
Peter Evans 00ff9f069d Vastly simplify unit tests for mos6502
Criterion's init and fini config options allow us to register setup and
teardown functions. We now use this to register the common cpu variable
for the mos6502 tests, albeit through the use of a global variable.

Doing so necessitated that each of the different test files have their
own suites, due to some implementation details in Criterion, but this is
No Big Deal.
2017-12-06 15:57:15 -06:00

104 lines
2.0 KiB
C

#include <criterion/criterion.h>
#include "mos6502.h"
#include "mos6502.enums.h"
#include "mos6502.tests.h"
TestSuite(mos6502_branch, .init = setup, .fini = teardown);
Test(mos6502_branch, bcc)
{
cpu->last_addr = 123;
mos6502_handle_bcc(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= CARRY;
cpu->last_addr = 125;
mos6502_handle_bcc(cpu, 0);
cr_assert_neq(cpu->PC, 125);
}
Test(mos6502_branch, bcs)
{
cpu->last_addr = 123;
mos6502_handle_bcs(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= CARRY;
cpu->last_addr = 125;
mos6502_handle_bcs(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}
Test(mos6502_branch, beq)
{
cpu->last_addr = 123;
mos6502_handle_beq(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= ZERO;
cpu->last_addr = 125;
mos6502_handle_beq(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}
Test(mos6502_branch, bmi)
{
cpu->last_addr = 123;
mos6502_handle_bmi(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= NEGATIVE;
cpu->last_addr = 125;
mos6502_handle_bmi(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}
Test(mos6502_branch, bne)
{
cpu->last_addr = 123;
mos6502_handle_bne(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= ZERO;
cpu->last_addr = 125;
mos6502_handle_bne(cpu, 0);
cr_assert_neq(cpu->PC, 125);
}
Test(mos6502_branch, bpl)
{
cpu->last_addr = 123;
mos6502_handle_bpl(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= NEGATIVE;
cpu->last_addr = 125;
mos6502_handle_bpl(cpu, 0);
cr_assert_neq(cpu->PC, 125);
}
Test(mos6502_branch, bvc)
{
cpu->last_addr = 123;
mos6502_handle_bvc(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= OVERFLOW;
cpu->last_addr = 125;
mos6502_handle_bvc(cpu, 0);
cr_assert_neq(cpu->PC, 125);
}
Test(mos6502_branch, bvs)
{
cpu->last_addr = 123;
mos6502_handle_bvs(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= OVERFLOW;
cpu->last_addr = 125;
mos6502_handle_bvs(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}