1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-27 20:51:17 +00:00
erc-c/tests/apple2.dd.c

168 lines
4.0 KiB
C
Raw Normal View History

2017-12-15 04:47:11 +00:00
#include <criterion/criterion.h>
#include "apple2.dd.h"
static apple2dd *drive;
static void
setup()
{
drive = apple2_dd_create();
2017-12-15 04:47:11 +00:00
}
static void
teardown()
{
apple2_dd_free(drive);
2017-12-15 04:47:11 +00:00
}
2018-01-07 20:38:51 +00:00
TestSuite(apple2_dd, .init = setup, .fini = teardown);
2017-12-15 04:47:11 +00:00
2018-01-07 20:38:51 +00:00
Test(apple2_dd, create)
2017-12-15 04:47:11 +00:00
{
cr_assert_eq(drive->data, NULL);
cr_assert_eq(drive->track_pos, 0);
cr_assert_eq(drive->sector_pos, 0);
cr_assert_eq(drive->online, false);
cr_assert_eq(drive->write_protect, true);
cr_assert_eq(drive->mode, DD_READ);
}
/* Test(apple2_dd, free) */
2018-01-07 20:38:51 +00:00
Test(apple2_dd, insert)
2017-12-15 04:47:11 +00:00
{
2017-12-26 23:20:06 +00:00
FILE *stream;
2017-12-15 04:47:11 +00:00
2017-12-26 23:20:06 +00:00
// In a successful drive open, we would also reset the track and
// sector pos.
drive->track_pos = 123;
drive->sector_pos = 33;
2017-12-15 04:47:11 +00:00
2017-12-26 23:20:06 +00:00
stream = fopen("../data/zero.img", "r");
cr_assert_eq(apple2_dd_insert(drive, stream), OK);
2017-12-15 04:47:11 +00:00
cr_assert_eq(drive->track_pos, 0);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->sector_pos, 0);
fclose(stream);
2017-12-15 05:09:32 +00:00
2017-12-26 23:20:06 +00:00
stream = fopen("../data/bad.img", "r");
cr_assert_eq(apple2_dd_insert(drive, stream), ERR_BADFILE);
2017-12-26 23:20:06 +00:00
fclose(stream);
2017-12-15 05:09:32 +00:00
}
2018-01-07 20:38:51 +00:00
Test(apple2_dd, position)
2017-12-15 05:09:32 +00:00
{
// Without any data, the drive should return a null position
// regardless of track position
drive->track_pos = 3;
drive->sector_pos = 44;
cr_assert_eq(apple2_dd_position(drive), 0);
2017-12-15 05:09:32 +00:00
// FIXME: we need some dummy data for the drive...
}
2017-12-15 22:46:40 +00:00
2018-01-07 20:38:51 +00:00
Test(apple2_dd, read)
2017-12-26 23:20:06 +00:00
{
drive->data = vm_segment_create(_140K_);
vm_segment_set(drive->data, 0, 123);
vm_segment_set(drive->data, 1, 234);
cr_assert_eq(apple2_dd_read(drive), 123);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->track_pos, 0);
cr_assert_eq(drive->sector_pos, 1);
cr_assert_eq(apple2_dd_read(drive), 234);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->track_pos, 0);
cr_assert_eq(drive->sector_pos, 2);
}
2018-01-07 20:38:51 +00:00
Test(apple2_dd, eject)
2017-12-15 22:46:40 +00:00
{
drive->data = vm_segment_create(1000);
apple2_dd_eject(drive);
2017-12-15 22:46:40 +00:00
cr_assert_eq(drive->data, NULL);
}
2018-01-07 20:38:51 +00:00
Test(apple2_dd, set_mode)
2017-12-15 22:46:40 +00:00
{
apple2_dd_set_mode(drive, DD_WRITE);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->mode, DD_WRITE);
apple2_dd_set_mode(drive, DD_READ);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->mode, DD_READ);
2017-12-15 22:46:40 +00:00
2017-12-26 23:20:06 +00:00
// let's try shenanigans
apple2_dd_set_mode(drive, 111111111);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->mode, DD_READ);
2017-12-15 22:46:40 +00:00
}
2017-12-15 22:53:12 +00:00
2018-01-07 20:38:51 +00:00
Test(apple2_dd, shift)
2017-12-15 22:53:12 +00:00
{
apple2_dd_shift(drive, 5);
2017-12-15 22:53:12 +00:00
cr_assert_eq(drive->sector_pos, 5);
// Push it beyond the sector boundary; see if the track position
// updates as it should.
apple2_dd_shift(drive, MAX_SECTOR_POS + 3);
2017-12-15 22:53:12 +00:00
cr_assert_eq(drive->track_pos, 2);
// this should be the mod of sector_pos and MAX_SECTOR_POS
cr_assert_eq(drive->sector_pos, 7);
}
2017-12-16 03:01:49 +00:00
2018-01-07 20:38:51 +00:00
Test(apple2_dd, step)
2017-12-16 03:01:49 +00:00
{
2017-12-26 23:20:06 +00:00
// Does step work at all?
apple2_dd_step(drive, 5);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->track_pos, 5);
apple2_dd_step(drive, 3);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->track_pos, 8);
apple2_dd_step(drive, -2);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->track_pos, 6);
2017-12-16 03:01:49 +00:00
2017-12-26 23:20:06 +00:00
// Do we handle going over the maximum track position properly?
apple2_dd_step(drive, 100);
2017-12-26 23:20:06 +00:00
cr_assert_eq(drive->track_pos, MAX_DRIVE_STEPS);
2017-12-16 03:01:49 +00:00
2017-12-26 23:20:06 +00:00
// Do we handle going to the 0 track properly if we get a radically
// high number of negative track shifts?
apple2_dd_step(drive, -1000);
2017-12-16 03:01:49 +00:00
cr_assert_eq(drive->track_pos, 0);
2017-12-26 23:20:06 +00:00
}
2018-01-07 20:38:51 +00:00
Test(apple2_dd, turn_on)
2017-12-26 23:20:06 +00:00
{
apple2_dd_turn_on(drive, true);
2017-12-26 23:20:06 +00:00
cr_assert(drive->online);
apple2_dd_turn_on(drive, false);
2017-12-26 23:20:06 +00:00
cr_assert(!drive->online);
// I mean, ok
apple2_dd_turn_on(drive, 1111333);
2017-12-26 23:20:06 +00:00
cr_assert(drive->online);
2017-12-16 03:01:49 +00:00
}
2018-01-07 20:38:51 +00:00
Test(apple2_dd, write)
2017-12-16 03:01:49 +00:00
{
drive->data = vm_segment_create(_140K_);
apple2_dd_write(drive, 123);
2017-12-16 03:01:49 +00:00
cr_assert_eq(vm_segment_get(drive->data, 0), 123);
cr_assert_eq(drive->track_pos, 0);
cr_assert_eq(drive->sector_pos, 1);
apple2_dd_write(drive, 234);
2017-12-16 03:01:49 +00:00
cr_assert_eq(vm_segment_get(drive->data, 1), 234);
cr_assert_eq(drive->track_pos, 0);
cr_assert_eq(drive->sector_pos, 2);
}
2017-12-26 23:20:06 +00:00
2018-01-07 20:38:51 +00:00
Test(apple2_dd, write_protect)
2017-12-26 23:20:06 +00:00
{
apple2_dd_write_protect(drive, true);
2017-12-26 23:20:06 +00:00
cr_assert(drive->write_protect);
apple2_dd_write_protect(drive, false);
2017-12-26 23:20:06 +00:00
cr_assert(!drive->write_protect);
apple2_dd_write_protect(drive, 2222);
2017-12-26 23:20:06 +00:00
cr_assert(drive->write_protect);
}