2017-12-15 04:47:11 +00:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
|
|
|
#include "apple2.dd.h"
|
|
|
|
|
|
|
|
static apple2dd *drive;
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup()
|
|
|
|
{
|
2018-01-07 19:44:07 +00:00
|
|
|
drive = apple2_dd_create();
|
2017-12-15 04:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
teardown()
|
|
|
|
{
|
2018-01-07 19:44:07 +00:00
|
|
|
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);
|
2018-02-04 00:10:29 +00:00
|
|
|
cr_assert_eq(drive->image, NULL);
|
|
|
|
cr_assert_eq(drive->image_type, DD_NOTYPE);
|
2017-12-15 04:47:11 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-01-07 20:45:59 +00:00
|
|
|
/* 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");
|
2018-02-04 00:10:29 +00:00
|
|
|
cr_assert_eq(apple2_dd_insert(drive, stream, DD_DOS33), 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);
|
2018-02-04 00:10:29 +00:00
|
|
|
cr_assert_eq(drive->image_type, DD_DOS33);
|
2017-12-26 23:20:06 +00:00
|
|
|
fclose(stream);
|
2017-12-15 05:09:32 +00:00
|
|
|
|
2017-12-26 23:20:06 +00:00
|
|
|
stream = fopen("../data/bad.img", "r");
|
2018-02-04 00:10:29 +00:00
|
|
|
cr_assert_eq(apple2_dd_insert(drive, stream, DD_DOS33), 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;
|
2018-01-07 19:44:07 +00:00
|
|
|
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);
|
|
|
|
|
2018-01-07 19:44:07 +00:00
|
|
|
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);
|
|
|
|
|
2018-01-07 19:44:07 +00:00
|
|
|
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
|
|
|
{
|
2018-02-04 02:50:30 +00:00
|
|
|
drive->image = vm_segment_create(1000);
|
2017-12-15 22:46:40 +00:00
|
|
|
drive->data = vm_segment_create(1000);
|
2018-02-04 02:50:30 +00:00
|
|
|
drive->image_type = DD_NIBBLE;
|
|
|
|
drive->stream = NULL;
|
2018-01-07 19:44:07 +00:00
|
|
|
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
|
|
|
{
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_set_mode(drive, DD_WRITE);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert_eq(drive->mode, DD_WRITE);
|
2018-01-07 19:44:07 +00:00
|
|
|
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
|
2018-01-07 19:44:07 +00:00
|
|
|
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
|
|
|
{
|
2018-01-07 19:44:07 +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.
|
2018-01-07 19:44:07 +00:00
|
|
|
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?
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_step(drive, 5);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert_eq(drive->track_pos, 5);
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_step(drive, 3);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert_eq(drive->track_pos, 8);
|
2018-01-07 19:44:07 +00:00
|
|
|
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?
|
2018-01-07 19:44:07 +00:00
|
|
|
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?
|
2018-01-07 19:44:07 +00:00
|
|
|
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
|
|
|
{
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_turn_on(drive, true);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert(drive->online);
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_turn_on(drive, false);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert(!drive->online);
|
|
|
|
|
|
|
|
// I mean, ok
|
2018-01-07 19:44:07 +00:00
|
|
|
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_);
|
|
|
|
|
2018-01-27 02:00:10 +00:00
|
|
|
drive->latch = 123;
|
|
|
|
apple2_dd_write(drive);
|
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);
|
|
|
|
|
2018-01-27 02:00:10 +00:00
|
|
|
drive->latch = 234;
|
|
|
|
apple2_dd_write(drive);
|
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
|
|
|
{
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_write_protect(drive, true);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert(drive->write_protect);
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_write_protect(drive, false);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert(!drive->write_protect);
|
2018-01-07 19:44:07 +00:00
|
|
|
apple2_dd_write_protect(drive, 2222);
|
2017-12-26 23:20:06 +00:00
|
|
|
cr_assert(drive->write_protect);
|
|
|
|
}
|
2018-02-04 06:22:14 +00:00
|
|
|
|
|
|
|
Test(apple2_dd, encode)
|
|
|
|
{
|
|
|
|
// Mostly we want to test if this handles the image types correct.
|
|
|
|
// The encode function won't actually try to encode anything if the
|
|
|
|
// image segment is NULL.
|
|
|
|
drive->image_type = DD_NIBBLE; cr_assert_eq(apple2_dd_encode(drive), OK);
|
|
|
|
drive->image_type = DD_DOS33; cr_assert_eq(apple2_dd_encode(drive), OK);
|
|
|
|
drive->image_type = DD_PRODOS; cr_assert_eq(apple2_dd_encode(drive), OK);
|
|
|
|
drive->image_type = -1; cr_assert_neq(apple2_dd_encode(drive), OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(apple2_dd, decode)
|
|
|
|
{
|
|
|
|
// Same drill as for the encode test
|
|
|
|
drive->image_type = DD_NIBBLE; cr_assert_eq(apple2_dd_encode(drive), OK);
|
|
|
|
drive->image_type = DD_DOS33; cr_assert_eq(apple2_dd_encode(drive), OK);
|
|
|
|
drive->image_type = DD_PRODOS; cr_assert_eq(apple2_dd_encode(drive), OK);
|
|
|
|
drive->image_type = -1; cr_assert_neq(apple2_dd_encode(drive), OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skipping this test because most everything it does is already tested
|
|
|
|
// in some other capacity
|
|
|
|
/* Test(apple2_dd, save) */
|
|
|
|
|
2018-02-04 07:11:09 +00:00
|
|
|
Test(apple2_dd, phaser)
|
|
|
|
{
|
|
|
|
drive->phase_state = 1;
|
|
|
|
drive->last_phase = 0;
|
|
|
|
|
|
|
|
apple2_dd_phaser(drive);
|
|
|
|
|
|
|
|
cr_assert_eq(drive->track_pos, 1);
|
|
|
|
cr_assert_eq(drive->last_phase, 1);
|
2018-02-04 06:22:14 +00:00
|
|
|
|
2018-02-04 07:11:09 +00:00
|
|
|
// This shouldn't work--we should stay at the track_pos we begin
|
|
|
|
// with
|
|
|
|
drive->phase_state = 0x4;
|
|
|
|
apple2_dd_phaser(drive);
|
|
|
|
cr_assert_eq(drive->track_pos, 1);
|
|
|
|
|
|
|
|
// And test that we can go backward
|
|
|
|
drive->phase_state = 0;
|
|
|
|
apple2_dd_phaser(drive);
|
|
|
|
cr_assert_eq(drive->track_pos, 0);
|
|
|
|
}
|