From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: AUnit question Date: Mon, 04 Aug 2014 14:28:10 +0300 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: AnnUDmZwVERVUXyHDyOl5A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: number.nntp.dca.giganews.com comp.lang.ada:188137 Date: 2014-08-04T14:28:10+03:00 List-Id: In the below source every test requires an object of type World_Type. Wouldn't it better to move the `World: World_Type` object into the test case object and not create it anew in every test procedure? But how to do this? Test functions receive Test_Cases.Test_Case'Class, not my type of test case. Should I manually do type conversion in every test function? or is there a better way? with AUnit, AUnit.Test_Cases, AUnit.Test_Results; use AUnit, AUnit.Test_Cases, AUnit.Test_Results; -- with RDF.Raptor.World; package Iostreams_Test is type Test_Case is new AUnit.Test_Cases.Test_Case with null record; procedure Register_Tests (T : in out Test_Case); -- Register routines to be run function Name (T : Test_Case) return Test_String; -- Returns name identifying the test case end Iostreams_Test; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with AUnit.Test_Cases; with AUnit.Assertions; use AUnit.Assertions; with RDF.Raptor.World; with RDF.Raptor.Iostream; use RDF.Raptor.Iostream; with Ada.Text_IO; package body Iostreams_Test is procedure Test_Sinks(T : in out Test_Cases.Test_Case'Class) is World: RDF.Raptor.World.World_Type; Str: aliased char_array := "qqq"; In_Sink: Stream_Type := From_Sink (World); Out_Sink: Stream_Type := To_Sink (World); begin Assert (Read_Bytes (To_Chars_Ptr (Str'Unchecked_Access), 10, 10, In_Sink) = 0, "Read zero bytes from a sink"); Write ("XYZ", Out_Sink); -- does nothing end; procedure Test_Strings(T : in out Test_Cases.Test_Case'Class) is World: RDF.Raptor.World.World_Type; Str : String := "xqqq"; Buf: aliased char_array := (1..99=>'w', 100=>NUL); In_String: Stream_From_String := Open_From_String (World, Str); Out_String: Stream_To_String := Open (World); Bytes_Read: size_t; begin Bytes_Read := Read_Bytes (To_Chars_Ptr (Buf'Unchecked_Access), 1, 100, In_String); Assert (Bytes_Read = 4, "Read 4 bytes from string"); Assert (To_Ada (Buf(1..4), Trim_Nul=>False) = Str, "Compare read string"); Write(Str, Out_String); Write("QQ", Out_String); Assert (Value (Out_String) = Str & "QQ", "Compare written string"); end; function Name (T : Test_Case) return Test_String is begin return Format ("Streams"); end Name; procedure Register_Tests (T : in out Test_Case) is use AUnit.Test_Cases.Registration; begin Register_Routine (T, Test_Sinks'Access, "Testing sinks"); -- FIXME: uncomment Register_Routine (T, Test_Strings'Access, "Testing string streams"); end Register_Tests; end Iostreams_Test; -- Victor Porton - http://portonvictor.org