From ccedae1020b3037df3e568948d08dfcd8b459d53 Mon Sep 17 00:00:00 2001 From: Olivier Ramonat Date: Tue, 9 Dec 2008 18:35:17 +0100 Subject: [PATCH] Add new test t2 Clean output of make runtests --- makefile | 14 ++++++++++- tests/regtests.gpr | 2 +- tests/t1.adb | 12 ++++++++-- tests/t2.adb | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 tests/t2.adb diff --git a/makefile b/makefile index d5dafd7..155e40c 100644 --- a/makefile +++ b/makefile @@ -36,7 +36,19 @@ all: build setup: runtests: - (cd tests; $(GNATMAKE) -Pregtests; $(RUNTEST) ./t1) + (cd tests; $(GNATMAKE) -Pregtests;) + @(cd tests; printf 't1... '; \ + if test `$(RUNTEST) ./t1 | wc -l` = "10"; then \ + printf "ok\n"; \ + else \ + printf "nok\n"; \ + fi;) + @(cd tests; printf 't2... '; \ + if test `$(runtest) ./t2` = 1234; then \ + printf "ok\n"; \ + else \ + printf "nok\n"; \ + fi;) build: ifneq ($(INSTALL), "") diff --git a/tests/regtests.gpr b/tests/regtests.gpr index c22e08b..d5f1c12 100644 --- a/tests/regtests.gpr +++ b/tests/regtests.gpr @@ -2,7 +2,7 @@ with "../gnadelite"; project Regtests is for Source_Dirs use ("."); - for Main use ("t1"); + for Main use ("t1.adb", "t2.adb"); package Compiler is for Default_Switches ("Ada") use ("-gnat05"); diff --git a/tests/t1.adb b/tests/t1.adb index e7adf60..2f87046 100644 --- a/tests/t1.adb +++ b/tests/t1.adb @@ -35,6 +35,7 @@ procedure T1 is use Ada.Exceptions; Max_Insert : constant Positive := 10000; + Verbose : constant Boolean := False; task type Inserts is entry Start (Id : in Positive); @@ -115,6 +116,8 @@ procedure T1 is exit when Current = Max_Insert; Current := Current + 1; end loop; + + DBH.Handle.Close; exception when E : others => Text_IO.Put_Line @@ -133,7 +136,9 @@ procedure T1 is begin accept Start (Id : in Positive) do Task_Id := Id; - Text_IO.Put_Line ("Reader " & Positive'Image (Task_Id) & " start"); + if Verbose then + Text_IO.Put_Line ("Reader " & Positive'Image (Task_Id) & " start"); + end if; Connect (DBH); end Start; @@ -160,7 +165,7 @@ procedure T1 is exit; end if; - if Natural'Value + if Verbose and then Natural'Value (DB.String_Vectors.Element (Line, 1)) /= Last then Last := Natural'Value @@ -176,6 +181,8 @@ procedure T1 is Iter.End_Select; end; end loop; + + DBH.Handle.Close; exception when E : others => Text_IO.Put_Line @@ -212,4 +219,5 @@ begin Writers (K).Start (K); end loop; end; + end T1; diff --git a/tests/t2.adb b/tests/t2.adb new file mode 100644 index 0000000..bb63e34 --- /dev/null +++ b/tests/t2.adb @@ -0,0 +1,68 @@ +------------------------------------------------------------------------------ +-- GnadeLite -- +-- -- +-- Copyright (C) 2008 -- +-- Pascal Obry - Olivier Ramonat -- +-- -- +-- This library is free software; you can redistribute it and/or modify -- +-- it under the terms of the GNU General Public License as published by -- +-- the Free Software Foundation; either version 2 of the License, or (at -- +-- your option) any later version. -- +-- -- +-- This library is distributed in the hope that it will be useful, but -- +-- WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- +-- General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU General Public License -- +-- along with this library; if not, write to the Free Software Foundation, -- +-- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -- +------------------------------------------------------------------------------ + +with Ada.Text_IO; + +with DB.SQLite; +with DB.Tools; + +with Morzhol.Logs; + +procedure T2 is + + use Ada; + + Handle : DB.SQLite.Handle; +begin + Morzhol.Logs.Set (Morzhol.Logs.Information, False); + Morzhol.Logs.Set (Morzhol.Logs.Warnings, False); + Morzhol.Logs.Set (Morzhol.Logs.Error, False); + + + Handle.Connect (DB.SQLite.In_Memory_Database); + + Handle.Execute + ("create table t ('a' integer, 'b' integer);" + & "insert into t (a, b) values (1, 2);" + & "insert into t (a, b) values (3, 4);"); + + declare + Iter : DB.SQLite.Iterator; + Line : DB.String_Vectors.Vector; + begin + Handle.Prepare_Select + (Iter, "select * from t"); + + while Iter.More loop + Iter.Get_Line (Line); + + if DB.String_Vectors.Element (Line, 1) /= "" then + Text_IO.Put (DB.String_Vectors.Element (Line, 1)); + Text_IO.Put (DB.String_Vectors.Element (Line, 2)); + end if; + Line.Clear; + end loop; + Iter.End_Select; + end; + + Handle.Close; + +end T2; -- 2.11.4.GIT