#!/usr/bin/perl -w

# ICC::Profile::XYZ_ test module / 2020-01-11
#
# Copyright © 2004-2020 by William B. Birkett

use strict;

use lib $ENV{'PWD'}; # add current directory to @INC

use File::Spec;
use File::Temp;
use t::lib::Boot;
use Test::More tests => 6;

# local variables
my ($profile, $tag, $temp, $raw1, $raw2);

# does module load
BEGIN { use_ok('ICC::Profile::XYZ_') };

# test class methods
can_ok('ICC::Profile::XYZ_', qw(new new_fh write_fh size array XYZ sdump));

# make empty XYZ_ object
$tag = ICC::Profile::XYZ_->new;

# test object class
isa_ok($tag, 'ICC::Profile::XYZ_');

# read eciRGB_v2 profile
$profile = t::lib::Boot->new(File::Spec->catfile('t', 'data', 'eciRGB_v2.icc'));

# read 'rXYZ' tag
$tag = ICC::Profile::XYZ_->new_fh($profile, $profile->fh, $profile->tag_table->[6]);

# test object class
isa_ok($tag, 'ICC::Profile::XYZ_');

# test size method
ok($tag->size == $profile->tag_table->[6][2], 'tag size');

# open temporary file for write-read access, binmode
$temp = File::Temp::tempfile();

# write tag to temporary file
$tag->write_fh($profile, $temp, $profile->tag_table->[6]);

# flush buffer
$temp->flush;

# read profile raw data
seek($profile->fh, $profile->tag_table->[6][1], 0);
read($profile->fh, $raw1, $tag->size);

# read temporary raw data
seek($temp, $profile->tag_table->[6][1], 0);
read($temp, $raw2, $tag->size);

# test raw data round-trip integrity
ok($raw1 eq $raw2, 'raw data round-trip');

# close files
close($profile->fh);
close($temp);

##### more tests needed #####
