1#!perl
2
3# Astro::Catalog test harness
4use Test::More tests => 8;
5
6use strict;
7
8use File::Temp qw/tempfile/;
9
10# load modules
11require_ok("Astro::Catalog");
12
13# In this test, we want to read from the DATA handle, write the
14# catalog to disk, read it in again and then make sure that we
15# have the correct number of stars. This guarantees that our
16# reader can read something generated by the writer
17
18my $tempfile = File::Temp->new();
19
20# Read catalog from Simple File from the DATA handle
21
22my $cat = new Astro::Catalog(Format => 'Simple', Data => \*DATA);
23
24isa_ok($cat, "Astro::Catalog");
25
26# Count the number of stars
27is($cat->sizeof, 5, "Confirm initial star count");
28
29# Write it to disk
30
31ok($cat->write_catalog(Format => 'Simple', File => $tempfile),
32    "Check catalog write");
33
34# Read it back in using filehandle
35seek($tempfile, 0, 0);
36my $newcat = new Astro::Catalog(Format => 'Simple', Data => $tempfile);
37
38isa_ok($newcat, "Astro::Catalog");
39
40# Count the number of stars
41is($newcat->sizeof, 5, "Confirm star count");
42
43
44# Read it back in (forcing the file name to be used)
45$newcat = new Astro::Catalog(Format => 'Simple', File => "$tempfile");
46
47isa_ok($newcat, "Astro::Catalog");
48
49# Count the number of stars
50is($newcat->sizeof, 5, "Confirm star count");
51
52exit;
53
54__DATA__
55# Catalog written automatically by class Astro::Catalog::IO::Simple
56# on date Sun Jul 27 03:37:59 2003UT
57# Origin of catalogue: <UNKNOWN>
58A  09 55 39.00  +60 07 23.60 B1950 # This is a comment
59B  10 44 57.00  +12 34 53.50 J2000 # This is another comment
60C  12:33:52    + 12:28:30
61D  12 33 52.0   +12 28 30.0  # A comment without epoch
62E  12 33 52    - 12 28 30.0  AZEL
63