Overview
Comment: | s_expressions-file_rw_tests: new test suite for both S-expression file readers and writers |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
5787543b72f3eb479a2e5da16b7e4bfa |
User & Date: | nat on 2014-06-07 17:11:48 |
Other Links: | manifest | tags |
Context
2014-06-08
| ||
19:08 |
s_expressions-printers-pretty: add valid default values to Parameter objects
This ensures that default Parameters objects are valid, and therefore that pretty printers without explicit parameter initialization are valid (and canonical) too. check-in: 89b2db0d6d user: nat tags: trunk | |
2014-06-07
| ||
17:11 | s_expressions-file_rw_tests: new test suite for both S-expression file readers and writers check-in: 5787543b72 user: nat tags: trunk | |
2014-06-06
| ||
19:04 | s_expressions-file_writers: add a filename accessor function check-in: 9ef479b9be user: nat tags: trunk | |
Changes
Added tests/natools-s_expressions-file_rw_tests.adb version [02caf65edd].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | ------------------------------------------------------------------------------ -- Copyright (c) 2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Ada.Streams.Stream_IO; with Ada.Strings.Unbounded; with Ada.Unchecked_Deallocation; with Natools.S_Expressions.Atom_Buffers; with Natools.S_Expressions.File_Readers; with Natools.S_Expressions.File_Writers; with Natools.S_Expressions.Test_Tools; with GNAT.Debug_Pools; package body Natools.S_Expressions.File_RW_Tests is package Stream_IO renames Ada.Streams.Stream_IO; subtype String_Holder is Ada.Strings.Unbounded.Unbounded_String; function Hold (S : String) return String_Holder renames Ada.Strings.Unbounded.To_Unbounded_String; function To_String (H : String_Holder) return String renames Ada.Strings.Unbounded.To_String; ------------------------- -- Complete Test Suite -- ------------------------- procedure All_Tests (Report : in out NT.Reporter'Class) is begin Atom_IO (Report); S_Expression_IO (Report); end All_Tests; ----------------------- -- Inidividual Tests -- ----------------------- procedure Atom_IO (Report : in out NT.Reporter'Class) is Test : NT.Test := Report.Item ("Atom-based reading"); Payload : Atom (0 .. 255); Temporary_File_Name : String_Holder; begin for I in Payload'Range loop Payload (I) := Octet (I); end loop; Build_File : declare File : Stream_IO.File_Type; begin Stream_IO.Create (File, Stream_IO.Out_File, ""); Stream_IO.Write (File, Payload); Temporary_File_Name := Hold (Stream_IO.Name (File)); Stream_IO.Close (File); end Build_File; Read_Test : declare Reader : File_Readers.Atom_Reader := File_Readers.Reader (To_String (Temporary_File_Name)); begin Test_Tools.Test_Atom (Test, Payload, Reader.Read); Small_Read : declare Buffer : Atom (1 .. 100) := (others => 0); Length : Count; begin Reader.Read (Buffer, Length); Test_Tools.Test_Atom (Test, Payload (0 .. Buffer'Length - 1), Buffer); if Length /= Payload'Length then Test.Fail ("Expected total length" & Count'Image (Payload'Length) & " in small read, found" & Count'Image (Length)); end if; end Small_Read; Large_Read : declare Buffer : Atom (1 .. 512) := (others => 0); Length : Count; begin Reader.Read (Buffer, Length); Test_Tools.Test_Atom (Test, Payload, Buffer (Buffer'First .. Length)); Test_Tools.Test_Atom (Test, (1 .. Buffer'Length - Length => 0), Buffer (Length + 1 .. Buffer'Last)); end Large_Read; Reader.Set_Filename (To_String (Temporary_File_Name)); Buffer_Read : declare Buffer : Atom_Buffers.Atom_Buffer; begin Reader.Read (Buffer, 100); Test_Tools.Test_Atom (Test, Payload, Buffer.Data); end Buffer_Read; Block_Read : declare procedure Process (Block : in Atom); Offset : Count := 0; procedure Process (Block : in Atom) is Next : constant Count := Offset + Block'Length; begin Test_Tools.Test_Atom (Test, Payload (Offset .. Next - 1), Block); Offset := Next; end Process; begin Reader.Block_Query (100, Process'Access); if Offset /= Payload'Last + 1 then Test.Fail ("Expected final offset" & Count'Image (Payload'Last + 1) & ", found" & Count'Image (Offset)); end if; Offset := 0; Reader.Block_Query (350, Process'Access); if Offset /= Payload'Last + 1 then Test.Fail ("Expected second final offset" & Count'Image (Payload'Last + 1) & ", found" & Count'Image (Offset)); end if; end Block_Read; Heap_Read : declare procedure Tester (Data : in Atom); procedure Raiser (Data : in Atom); Local_Exception : exception; procedure Tester (Data : in Atom) is begin Test_Tools.Test_Atom (Test, Payload, Data); end Tester; procedure Raiser (Data : in Atom) is begin raise Local_Exception; end Raiser; Pool : GNAT.Debug_Pools.Debug_Pool; type Local_Atom_Access is access Atom; for Local_Atom_Access'Storage_Pool use Pool; procedure Unchecked_Deallocation is new Ada.Unchecked_Deallocation (Atom, Local_Atom_Access); procedure Query is new File_Readers.Query (Local_Atom_Access, Unchecked_Deallocation); begin Query (Reader, Tester'Access); begin Query (Reader, Raiser'Access); exception when Local_Exception => null; end; end Heap_Read; end Read_Test; exception when Error : others => Test.Report_Exception (Error); end Atom_IO; procedure S_Expression_IO (Report : in out NT.Reporter'Class) is Test : NT.Test := Report.Item ("S-expression writing and re-reading"); Temporary_File_Name, Secondary_File_Name : String_Holder; begin First_Write : declare Writer : File_Writers.Writer := File_Writers.Create (""); begin Temporary_File_Name := Hold (Writer.Name); Writer.Append_Atom (To_Atom ("begin")); Writer.Open_List; Writer.Open_List; Writer.Close_List; Writer.Open_List; Writer.Append_Atom (To_Atom ("head")); Writer.Append_Atom (To_Atom ("tail")); Writer.Close_List; Writer.Close_List; Writer.Append_Atom (To_Atom ("end")); Writer.Create (""); Secondary_File_Name := Hold (Writer.Name); Writer.Open_List; Writer.Append_Atom (To_Atom ("first")); Writer.Append_Atom (To_Atom ("last")); Writer.Close_List; end First_Write; First_Read : declare Reader : File_Readers.S_Reader := File_Readers.Reader (To_String (Temporary_File_Name)); begin Test_Tools.Test_Atom_Accessors (Test, Reader, To_Atom ("begin"), 0); Test_Tools.Next_And_Check (Test, Reader, Events.Open_List, 1); Test_Tools.Next_And_Check (Test, Reader, Events.Open_List, 2); Test_Tools.Next_And_Check (Test, Reader, Events.Close_List, 1); Test_Tools.Next_And_Check (Test, Reader, Events.Open_List, 2); Test_Tools.Next_And_Check (Test, Reader, To_Atom ("head"), 2); Test_Tools.Next_And_Check (Test, Reader, To_Atom ("tail"), 2); Test_Tools.Next_And_Check (Test, Reader, Events.Close_List, 1); Test_Tools.Next_And_Check (Test, Reader, Events.Close_List, 0); Test_Tools.Next_And_Check (Test, Reader, To_Atom ("end"), 0); Test_Tools.Next_And_Check (Test, Reader, Events.End_Of_Input, 0); Reader.Rewind; Test_Tools.Test_Atom_Accessors (Test, Reader, To_Atom ("begin"), 0); Reader.Set_Filename (To_String (Secondary_File_Name)); Test_Tools.Next_And_Check (Test, Reader, To_Atom ("first"), 1); Test_Tools.Next_And_Check (Test, Reader, To_Atom ("last"), 1); Test_Tools.Next_And_Check (Test, Reader, Events.Close_List, 0); Test_Tools.Next_And_Check (Test, Reader, Events.End_Of_Input, 0); end First_Read; Second_Write : declare Writer : File_Writers.Writer := File_Writers.Open (To_String (Temporary_File_Name)); begin Writer.Open_List; Writer.Append_Atom (To_Atom ("foo")); Writer.Append_Atom (To_Atom ("bar")); Writer.Open_List; Writer.Close_List; Writer.Close_List; Writer.Open (To_String (Secondary_File_Name)); Writer.Open_List; Writer.Append_Atom (To_Atom ("unfinished")); end Second_Write; Raw_Read : begin Test_Tools.Test_Atom (Test, To_Atom ("5:begin(()(4:head4:tail))3:end(3:foo3:bar())"), File_Readers.Reader (To_String (Temporary_File_Name)).Read); Test_Tools.Test_Atom (Test, To_Atom ("(5:first4:last)(10:unfinished"), File_Readers.Reader (To_String (Secondary_File_Name)).Read); end Raw_Read; exception when Error : others => Test.Report_Exception (Error); end S_Expression_IO; end Natools.S_Expressions.File_RW_Tests; |
Added tests/natools-s_expressions-file_rw_tests.ads version [2a4bb7628e].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ------------------------------------------------------------------------------ -- Copyright (c) 2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.S_Expressions.File_RW_Tests provides a test suite for both -- -- Natools.S_Expressions.File_Readers and File_Writers. -- ------------------------------------------------------------------------------ with Natools.Tests; package Natools.S_Expressions.File_RW_Tests is package NT renames Natools.Tests; procedure All_Tests (Report : in out NT.Reporter'Class); procedure Atom_IO (Report : in out NT.Reporter'Class); procedure S_Expression_IO (Report : in out NT.Reporter'Class); end Natools.S_Expressions.File_RW_Tests; |
Modified tests/test_all.adb from [6950136de8] to [d48cd7156c].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | with Natools.Getopt_Long_Tests; with Natools.HMAC_Tests; with Natools.Reference_Tests; with Natools.S_Expressions.Atom_Buffers.Tests; with Natools.S_Expressions.Cache_Tests; with Natools.S_Expressions.Dynamic_Interpreter_Tests; with Natools.S_Expressions.Encodings.Tests; with Natools.S_Expressions.Interpreter_Tests; with Natools.S_Expressions.Lockable.Tests; with Natools.S_Expressions.Parsers.Tests; with Natools.S_Expressions.Printers.Tests; with Natools.S_Expressions.Printers.Pretty.Tests; with Natools.S_Expressions.Printers.Pretty.Config.Tests; with Natools.Static_Hash_Maps.S_Expressions.Tests; | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | with Natools.Getopt_Long_Tests; with Natools.HMAC_Tests; with Natools.Reference_Tests; with Natools.S_Expressions.Atom_Buffers.Tests; with Natools.S_Expressions.Cache_Tests; with Natools.S_Expressions.Dynamic_Interpreter_Tests; with Natools.S_Expressions.Encodings.Tests; with Natools.S_Expressions.File_RW_Tests; with Natools.S_Expressions.Interpreter_Tests; with Natools.S_Expressions.Lockable.Tests; with Natools.S_Expressions.Parsers.Tests; with Natools.S_Expressions.Printers.Tests; with Natools.S_Expressions.Printers.Pretty.Tests; with Natools.S_Expressions.Printers.Pretty.Config.Tests; with Natools.Static_Hash_Maps.S_Expressions.Tests; |
︙ | ︙ | |||
95 96 97 98 99 100 101 102 103 104 105 106 107 108 | Report.Section ("S_Expressions.Dynamic_Interpreters"); Natools.S_Expressions.Dynamic_Interpreter_Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Encodings"); Natools.S_Expressions.Encodings.Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Interpreters"); Natools.S_Expressions.Interpreter_Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Lockable"); Natools.S_Expressions.Lockable.Tests.All_Tests (Report); | > > > > | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | Report.Section ("S_Expressions.Dynamic_Interpreters"); Natools.S_Expressions.Dynamic_Interpreter_Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Encodings"); Natools.S_Expressions.Encodings.Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.File_Readers and File_Writers"); Natools.S_Expressions.File_RW_Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Interpreters"); Natools.S_Expressions.Interpreter_Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Lockable"); Natools.S_Expressions.Lockable.Tests.All_Tests (Report); |
︙ | ︙ |