### ----------------------------------------------------
### -- OLE::Storage_Lite
### -- Licenses: NOASSERTION
### -- Authors: Jeffrey Goff
### -- File: t/20-write-big-ole.t
### ----------------------------------------------------
### -- Chunk 10 of 10
x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
);

# When you create the objects, fields like *Pps, No, Size, and StartBlock
# aren't initialized. They're filled when reading.
#
subtest 'before writing', {
  plan 4;

  my $workbook = OLE::Storage_Lite::PPS::File.new(
    "Workbook",
    $buf-workbook
  );

  my $summary-information = OLE::Storage_Lite::PPS::File.new(
    "\x05SummaryInformation",
    $buf-summary-information
  );

  my $document-summary-information = OLE::Storage_Lite::PPS::File.new(
    "\x[05]DocumentSummaryInformation",
    $buf-document-summary-information
  );

  my $root = OLE::Storage_Lite::PPS::Root.new(
    DateTime.new(
      second => 1,
      minute => 28,
      hour   => 18,
      day    => 5,
      month  => 9,
      year   => 1970 - 240
    ),
    DateTime.new(
      second => 31,
      minute => 58,
      hour   => 21,
      day    => 28,
      month  => 1,
      year   => 1970 + 101
    ),
    ( $workbook, $summary-information, $document-summary-information )
  );

  subtest 'workbook', {
    plan 6;

    my $node = $workbook;
 
    isa-ok $node, OLE::Storage_Lite::PPS::File;

    is $node.Child.elems, 0,          'Child';
    is $node.Data[0],     0x09,       'Data 0';
    is $node.Data[1],     0x08,       'Data 1';
    is $node.Name,        "Workbook", 'Name';
    is $node.Type,        2,          'Type';

    done-testing;
  };

  subtest 'summary information', {
    plan 6;

    my $node = $summary-information;
 
    isa-ok $node, OLE::Storage_Lite::PPS::File;

    is $node.Child.elems, 0,                        'Child';
    is $node.Data[0],     0xfe,                     'Data 0';
    is $node.Data[1],     0xff,                     'Data 1';
    is $node.Name,        "\x05SummaryInformation", 'Name';
    is $node.Type,        2,                        'Type';
 
    done-testing;
  };

  subtest 'document summary information', {
    plan 6;

    my $node = $document-summary-information;
 
    isa-ok $node, OLE::Storage_Lite::PPS::File;

    is $node.Child.elems, 0,                                  'Child count';
    is $node.Data[30],    0xcd,                               'Data 0';
    is $node.Data[31],    0xd5,                               'Data 1';
    is $node.Name,        "\x[05]DocumentSummaryInformation", 'Name';
    is $node.Type,        2,                                  'Type';
 
    done-testing;
  };

  subtest 'root', {
    plan 7;

    my $node = $root;

    isa-ok $node, OLE::Storage_Lite::PPS::Root;

    is $node.Child.elems, 3,                      'Child count';
    is $node.Data,        Any,                    'Data';
    is $node.Name,        'Root Entry',           'Name';
    is $node.Type,        5,                      'Type';
    is $node.Time1st,     '1730-09-05T18:28:01Z', 'Time1st';
    is $node.Time2nd,     '2071-01-28T21:58:31Z', 'Time2nd';
    
    done-testing;
  };

  $root.save( FILENAME, 1 );

  done-testing;
};

subtest 'read new file', {
  plan 7;

  my $ole = OLE::Storage_Lite.new( FILENAME );

  subtest 'pps-tree', {
    plan 4;

    my $new-root = $ole.pps-tree( 1 );

    subtest 'summary information', {
      plan 12;

      my $node = $new-root.[0].Child.[0];
    
      isa-ok $node, OLE::Storage_Lite::PPS::File;
    
      is $node.Child.elems, 0,                        'Child count';
      is $node.Data[0],     0xfe,                     'Data 0';
      is $node.Data[1],     0xff,                     'Data 1';
      is $node.DirPps,      0xffffffff,               'DirPps';
      is $node.NextPps,     0xffffffff,               'NextPps';
      is $node.PrevPps,     0xffffffff,               'PrevPps';
      is $node.Name,        "\x05SummaryInformation", 'Name';
      is $node.No,          1,                        'No';
      is $node.Size,        2**12,                    'Size';
      is $node.StartBlock,  0,                        'StartBlock';
      is $node.Type,        2,                        'Type';
    
      done-testing;
    };
    
    subtest 'workbook', {
      plan 12;

      my $node = $new-root.[0].Child.[1];
    
      isa-ok $node, OLE::Storage_Lite::PPS::File;
    
      is $node.Child.elems, 0,          'Child count';
      is $node.Data[0],     0x9,        'Data 0';
      is $node.Data[1],     0x8,        'Data 1';
      is $node.DirPps,      0xffffffff, 'DirPps';
      is $node.NextPps,     3,          'NextPps';
      is $node.PrevPps,     1,          'PrevPps';
      is $node.Name,        "Workbook", 'Name';
      is $node.No,          2,          'No';
      is $node.Size,        2**12,      'Size';
      is $node.StartBlock,  8,          'StartBlock';
      is $node.Type,        2,          'Type';
    
      done-testing;
    };
    
    subtest 'summary information', {
      plan 12;

      my $node = $new-root.[0].Child.[2];
    
      isa-ok $node, OLE::Storage_Lite::PPS::File;
    
      is $node.Child.elems, 0,                                  'Child count';
      is $node.Data[0],     0xfe,                               'Data 0';
      is $node.Data[1],     0xff,                               'Data 1';
      is $node.DirPps,      0xffffffff,                         'DirPps';
      is $node.NextPps,     0xffffffff,                         'NextPps';
      is $node.PrevPps,     0xffffffff,                         'PrevPps';
      is $node.Name,        "\x[05]DocumentSummaryInformation", 'Name';
      is $node.No,          3,                                  'No';
      is $node.Size,        2**12,                              'Size';
      is $node.StartBlock,  16,                                 'StartBlock';
      is $node.Type,        2,                                  'Type';
    
      done-testing;
    };
    
    subtest 'root', {
      plan 12;
    
      my $node = $new-root.[0];
    
      isa-ok $node, OLE::Storage_Lite::PPS::Root;
    
      is $node.Child.elems, 3,                      'Child count';
      is $node.DirPps,      2,                      'DirPps';
      is $node.NextPps,     0xffffffff,             'NextPps';
      is $node.PrevPps,     0xffffffff,             'PrevPps';
      is $node.Name,        'Root Entry',           'Name';
      is $node.No,          0,                      'No';
      is $node.Size,        0,                      'Size';
      is $node.StartBlock,  0,                      'StartBlock';
      is $node.Type,        5,                      'Type';
      is $node.Time1st,     '1730-09-05T18:28:01Z', 'Time1st';
      is $node.Time2nd,     '2071-01-28T21:58:31Z', 'Time2nd';
    
      done-testing;
    };
    
    done-testing;
  };

  subtest 'pps-tree without data', {
    plan 4;

    my $new-root = $ole.pps-tree;

    subtest 'summary information', {
      plan 11;

      my $node = $new-root.[0].Child.[0];
    
      isa-ok $node, OLE::Storage_Lite::PPS::File;
    
      is $node.Child.elems, 0,                        'Child count';
      is $node.Data,        Any,                      'Data missing';
      is $node.DirPps,      0xffffffff,               'DirPps';
      is $node.NextPps,     0xffffffff,               'NextPps';
      is $node.PrevPps,     0xffffffff,               'PrevPps';
      is $node.Name,        "\x05SummaryInformation", 'Name';
      is $node.No,          1,                        'No';
      is $node.Size,        2**12,                    'Size';
      is $node.StartBlock,  0,                        'StartBlock';
      is $node.Type,        2,                        'Type';
    
      done-testing;
    };
    
    subtest 'workbook', {
      plan 11;

      my $node = $new-root.[0].Child.[1];
    
      isa-ok $node, OLE::Storage_Lite::PPS::File;
    
      is $node.Child.elems, 0,          'Child count';
      is $node.Data,        Any,        'Data missing';
      is $node.DirPps,      0xffffffff, 'DirPps';
      is $node.NextPps,     3,          'NextPps';
      is $node.PrevPps,     1,          'PrevPps';
      is $node.Name,        "Workbook", 'Name';
      is $node.No,          2,          'No';
      is $node.Size,        2**12,      'Size';
      is $node.StartBlock,  8,          'StartBlock';
      is $node.Type,        2,          'Type';
    
      done-testing;
    };
    
    subtest 'summary information', {
      plan 11;

      my $node = $new-root.[0].Child.[2];
    
      isa-ok $node, OLE::Storage_Lite::PPS::File;
    
      is $node.Child.elems, 0,                                  'Child count';
      is $node.Data,        Any,                                'Data missing';
      is $node.DirPps,      0xffffffff,                         'DirPps';
      is $node.NextPps,     0xffffffff,                         'NextPps';
      is $node.PrevPps,     0xffffffff,                         'PrevPps';
      is $node.Name,        "\x[05]DocumentSummaryInformation", 'Name';
      is $node.No,          3,                                  'No';
      is $node.Size,        2**12,                              'Size';
      is $node.StartBlock,  16,                                 'StartBlock';
      is $node.Type,        2,                                  'Type';
    
      done-testing;
    };
    
    subtest 'root', {
      plan 13;
    
      my $node = $new-root.[0];
    
      isa-ok $node, OLE::Storage_Lite::PPS::Root;
    
      is $node.Child.elems, 3,                      'Child count';
      is $node.Data,        Any,                    'Data missing';
      is $node.DirPps,      2,                      'DirPps';
      is $node.NextPps,     0xffffffff,             'NextPps';
      is $node.PrevPps,     0xffffffff,             'PrevPps';
      is $node.Name,        'Root Entry',           'Name';
      is $node.No,          0,                      'No';
      is $node.Size,        0,                      'Size';
      is $node.StartBlock,  0,                      'StartBlock';
      is $node.Type,        5,                      'Type';
      is $node.Time1st,     '1730-09-05T18:28:01Z', 'Time1st';
      is $node.Time2nd,     '2071-01-28T21:58:31Z', 'Time2nd';
    
      done-testing;
    };
    
    done-testing;
  };

  subtest 'pps-search', {
    plan 12;

    my @search-names = "\x05SummaryInformation";
    my @new-nodes    = $ole.pps-search( @search-names, 1, 0 );
    my $node         = @new-nodes[0];
  
    isa-ok $node, OLE::Storage_Lite::PPS::File;
 
    is $node.Child.elems, 0,                        'Child count';
    is $node.Data[0],     0xfe,                     'Data 0';
    is $node.Data[1],     0xff,                     'Data 1';
    is $node.DirPps,      0xffffffff,               'DirPps';
    is $node.NextPps,     0xffffffff,               'NextPps';
    is $node.PrevPps,     0xffffffff,               'PrevPps';
    is $node.Name,        "\x05SummaryInformation", 'Name';
    is $node.No,          1,                        'No';
    is $node.Size,        2**12,                    'Size';
    is $node.StartBlock,  0,                        'StartBlock';
    is $node.Type,        2,                        'Type';
 
    done-testing;
  };

  subtest 'pps-search without data', {
    plan 11;

    my @search-names = "\x05SummaryInformation";
    my @new-nodes    = $ole.pps-search( @search-names, 0, 0 );
    my $node         = @new-nodes[0];
  
    isa-ok $node, OLE::Storage_Lite::PPS::File;
 
    is $node.Child.elems, 0,                        'Child count';
    is $node.Data,        Any,                      'Data missing';
    is $node.DirPps,      0xffffffff,               'DirPps';
    is $node.NextPps,     0xffffffff,               'NextPps';
    is $node.PrevPps,     0xffffffff,               'PrevPps';
    is $node.Name,        "\x05SummaryInformation", 'Name';
    is $node.No,          1,                        'No';
    is $node.Size,        2**12,                    'Size';
    is $node.StartBlock,  0,                        'StartBlock';
    is $node.Type,        2,                        'Type';
 
    done-testing;
  };

  subtest 'pps-search without data, insensitive', {
    plan 11;

    my @search-names = "\x05sUmmaryiNformation";
    my @new-nodes    = $ole.pps-search( @search-names, 0, 1 );
    my $node         = @new-nodes[0];
  
    isa-ok $node, OLE::Storage_Lite::PPS::File;
 
    is $node.Child.elems, 0,                        'Child count';
    is $node.Data,        Any,                      'Data missing';
    is $node.DirPps,      0xffffffff,               'DirPps';
    is $node.NextPps,     0xffffffff,               'NextPps';
    is $node.PrevPps,     0xffffffff,               'PrevPps';
    is $node.Name,        "\x05SummaryInformation", 'Name';
    is $node.No,          1,                        'No';
    is $node.Size,        2**12,                    'Size';
    is $node.StartBlock,  0,                        'StartBlock';
    is $node.Type,        2,                        'Type';
 
    done-testing;
  };

  subtest 'Nth-pps', {
    plan 12;

    my $node = $ole.Nth-pps( 2, 1 );
 
    isa-ok $node, OLE::Storage_Lite::PPS::File;
 
    is $node.Child.elems, 0,          'Child count';
    is $node.Data[0],     0x9,        'Data 0';
    is $node.Data[1],     0x8,        'Data 1';
    is $node.DirPps,      0xffffffff, 'DirPps';
    is $node.NextPps,     3,          'NextPps';
    is $node.PrevPps,     1,          'PrevPps';
    is $node.Name,        "Workbook", 'Name';
    is $node.No,          2,          'No';
    is $node.Size,        2**12,      'Size';
    is $node.StartBlock,  8,          'StartBlock';
    is $node.Type,        2,          'Type';
 
    done-testing;
  };

  subtest 'Nth-pps without data', {
    plan 11;

    my $node = $ole.Nth-pps( 2, 0 );
 
    isa-ok $node, OLE::Storage_Lite::PPS::File;
 
    is $node.Child.elems, 0,          'Child count';
    is $node.Data,        Any,        'Data missing';
    is $node.DirPps,      0xffffffff, 'DirPps';
    is $node.NextPps,     3,          'NextPps';
    is $node.PrevPps,     1,          'PrevPps';
    is $node.Name,        "Workbook", 'Name';
    is $node.No,          2,          'No';
    is $node.Size,        2**12,      'Size';
    is $node.StartBlock,  8,          'StartBlock';
    is $node.Type,        2,          'Type';
 
    done-testing;
  };

  done-testing;
};

FILENAME.IO.unlink if FILENAME.IO.e;

done-testing;


