/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2024 Mike Robeson [dijksterhuis]
*/

mod helpers;

use helpers::*;
use ot_tools_io::projects::metadata::OsMetadata;
use ot_tools_io::projects::settings::Settings;
use ot_tools_io::projects::slots::SlotsAttributes;
use ot_tools_io::projects::states::State;
use ot_tools_io::{OctatrackFileIO, ProjectFile};

// can read a project file without errors
#[test]
fn test_read_default_project_work_file() {
    let infile = get_blank_proj_dirpath().join("project.work");
    assert!(ProjectFile::from_data_file(&infile).is_ok());
}

// test that the metadata section is correct
#[test]
fn test_read_default_project_work_file_metadata() {
    let infile = get_blank_proj_dirpath().join("project.work");
    let p = ProjectFile::from_data_file(&infile).unwrap();

    let correct = OsMetadata::default();

    assert_eq!(p.metadata, correct);
}

// test that the states section is correct
#[test]
fn test_read_default_project_work_file_states() {
    let infile = get_blank_proj_dirpath().join("project.work");
    let p = ProjectFile::from_data_file(&infile).unwrap();

    let correct = State::default();

    assert_eq!(p.states, correct);
}

// test that the states section is correct
#[test]
fn test_read_default_project_work_file_settings() {
    let infile = get_blank_proj_dirpath().join("project.work");
    let p = ProjectFile::from_data_file(&infile).unwrap();

    let correct = Settings::default();

    assert_eq!(p.settings, correct);
}

// test that the states section is correct
#[test]
fn test_read_default_project_work_file_sslots() {
    let infile = get_blank_proj_dirpath().join("project.work");
    let p = ProjectFile::from_data_file(&infile).unwrap();
    let default_sslots = SlotsAttributes::default();

    assert_eq!(p.slots, default_sslots);
}

// test that reading and writing a single project gives the same outputs
#[test]
fn test_read_write_default_project_work_file() {
    let infile = get_blank_proj_dirpath().join("project.work");
    let outfile = std::env::temp_dir().join("default_1.work");
    let p = ProjectFile::from_data_file(&infile).unwrap();
    let _ = ProjectFile::to_data_file(&p, &outfile);

    let p_reread = ProjectFile::from_data_file(&infile).unwrap();

    assert_eq!(p, p_reread)
}
