- 108527AA9877FD1AA76FDF913C50760854260B8406DB12A4C7B1A1A052D593EACC2D59D8F36F7BF70BDC6AC21A3A28E80930C89A64020AE597B67976100F61E2
+ 60BA5DFFA63414F5B2D28611DA978EF0CDAACCAEEBA3383699E8EBFF223F608BED0F6752411067CF8A40BBB209040FCC621557BCF771F2459268ABE0EDCDC6A9
smg_comms/tests/test_serializing.adb
(130 . 5)(130 . 175)
606
607 end Serialize_Keys_Mgm;
608
609 procedure Serialize_File_Request( Reps: in Positive) is
610 MaxSz: Positive := 340;
611 O2 : Raw_Types.Octets_2;
612 U16 : Interfaces.Unsigned_16;
613 Counter : Interfaces.Unsigned_16;
614 ReadCounter: Interfaces.Unsigned_16;
615 Written: Natural;
616 Msg : Raw_Types.Serpent_Msg;
617 F_No, Sz: Text_Len;
618 begin
619 for I in 1 .. Reps loop
620 -- generate a random size
621 RNG.Get_Octets( O2 );
622 U16 := Raw_Types.Cast( O2 );
623 Sz := Text_Len( Positive(U16) mod MaxSz + 1);
624
625 -- generate a random number of files
626 RNG.Get_Octets( O2 );
627 U16 := Raw_Types.Cast( O2 );
628 F_No := Text_Len( Positive(U16) mod Sz );
629 if F_No = 0 then
630 F_No := 1;
631 end if;
632
633 declare
634 FR: Filenames(F_No, Sz);
635 ReadFR: Filenames;
636 O : Octets(1..Sz);
637 Len : Positive := Sz / F_No;
638 begin
639 Put_Line("Generating test for File Request with " &
640 Integer'Image(FR.F_No) & " filenames.");
641 -- generate a random counter
642 RNG.Get_Octets(O2);
643 Counter := Raw_Types.Cast(O2);
644
645 -- fill FR
646 RNG.Get_Octets( O );
647 -- replace separators if any
648 for I in O'Range loop
649 if O(I) = 59 then
650 O(I) := 69;
651 end if;
652 end loop;
653
654 Octets_To_String( O, FR.S );
655 for I in FR.Starts'Range loop
656 FR.Starts(I) := Interfaces.Unsigned_16( FR.Starts'First +
657 Len*(I-FR.Starts'First));
658 end loop;
659
660 -- write FR to message
661 Write_File_Request(FR, Counter, Msg, Written);
662
663 -- check how many filenames were written
664 if Written /= FR.F_No then
665 Put_Line("FAIL: only " & Natural'Image(Written) &
666 " filenames written out of " & Natural'Image(FR.F_No));
667 else
668 Put_Line("PASS: wrote " & Natural'Image(Written) & " filenames.");
669 end if;
670
671 -- read it from message and check result
672 Read_File_Request(Msg, ReadCounter, ReadFR);
673 if ReadCounter /= Counter then
674 Put_Line("FAIL: ReadCounter is " & Unsigned_16'Image(ReadCounter) &
675 " instead of expected " & Unsigned_16'Image(Counter) );
676 else
677 Put_Line("PASS: ReadCounter was read correctly as " &
678 Unsigned_16'Image(ReadCounter));
679 end if;
680 if ReadFr.Sz /= FR.Sz then
681 Put_Line("FAIL: Read FR.Sz = " & Text_Len'Image(ReadFr.Sz) &
682 " while expected sz is " & Text_Len'Image(FR.Sz));
683 else
684 Put_Line("PASS: Read FR.Sz as expected = " &
685 Text_Len'Image(ReadFr.Sz));
686 end if;
687 if ReadFr /= FR then
688 Put_Line("FAIL: ReadFr different from FR.");
689 else
690 Put_Line("PASS: ReadFr as expected, same as FR.");
691 end if;
692 end;
693 end loop;
694
695 -- test with more files than can fit
696 Put_Line("Test case for File Request with more files than fit.");
697 declare
698 F: Filenames(4, 16384);
699 ReadF: Filenames;
700 begin
701 F.Starts(1) := Interfaces.Unsigned_16(F.S'First);
702 F.Starts(2) := Interfaces.Unsigned_16(F.S'First + 342);
703 F.Starts(3) := 16370;
704 F.Starts(4) := 16380;
705 Write_File_Request(F, Counter, Msg, Written);
706 if Written /= 1 then
707 Put_Line("FAIL: Written is " & Natural'Image(Written) &
708 " instead of expected 1.");
709 else
710 Put_Line("PASS: Written is 1 out of 4, as expected.");
711 end if;
712 Read_File_Request(Msg, ReadCounter, ReadF);
713 if ReadF.F_No /= 1 or ReadF.Starts(1) /= 1 or ReadF.Sz /= 342 then
714 Put_Line("FAIL: F_No is " & Text_Len'Image(ReadF.F_No) &
715 " Sz is " & Text_Len'Image(ReadF.Sz));
716 else
717 Put_line("PASS: written 1 out of 4 correctly.");
718 end if;
719 end;
720 end Serialize_File_Request;
721
722 procedure Serialize_File_Chunk is
723 Filename : String := "afile.png";
724 FC : File_Chunk( Len => 945,
725 Count => 0,
726 Name_Len => Filename'Length);
727 ReadFC : File_Chunk;
728 Msg : Raw_Types.Serpent_Msg;
729 begin
730 -- fill FC with random content
731 FC.Filename := Filename;
732 RNG.Get_Octets(FC.Content);
733
734 -- write FC to message
735 Write_File_Transfer( FC, Msg );
736
737 -- read FC and check
738 Read_File_Transfer( Msg, ReadFC );
739
740 if FC /= ReadFC then
741 Put_Line("FAIL: read/write file chunk.");
742 else
743 Put_Line("PASS: read/write file chunk.");
744 end if;
745 end Serialize_File_Chunk;
746
747 procedure Converter_String_Octets is
748 Len: constant Natural := 234;
749 -- original values
750 S: String(1..Len);
751 O: Octets(1..Len);
752 -- converted values
753 CS: String(1..Len);
754 CO: Octets(1..Len);
755 begin
756 -- original octets
757 RNG.Get_Octets(O);
758 Octets_To_String(O, CS);
759 String_To_Octets(CS, CO);
760 if CO /= O then
761 Put_Line("FAIL: octets different after string/octets conversion.");
762 else
763 Put_Line("PASS: octets same after string/octets conversion.");
764 end if;
765
766 -- original string
767 for I in S'Range loop
768 S(I) := Character'Val(I mod 12);
769 end loop;
770 String_To_Octets(S, CO);
771 Octets_To_String(CO, CS);
772 if CS /= S then
773 Put_Line("FAIL: string different after string/octets conversion.");
774 else
775 Put_Line("PASS: string same after string/octets conversion.");
776 end if;
777 end Converter_String_Octets;
778
779 end Test_Serializing;
780