Implement a Set call which takes Ada.Calendar.Time

This commit is contained in:
R. Tyler Croy 2010-12-27 10:12:06 -08:00
parent 7fc0377eb6
commit 093c7f43f5
4 changed files with 49 additions and 2 deletions

View File

@ -353,6 +353,30 @@ package body Memcache is
return Unbounded.To_String (Command);
end Generate_Set;
function Generate_Set (Key : in String; Value : in String;
Flags : in Flags_Type;
Expire : in Ada.Calendar.Time;
No_Reply : in Boolean) return String is
Command : Unbounded.Unbounded_String;
Expire_Since_Epoch : constant Natural := Natural (Expire - Epoch);
begin
Validate (Key);
Command := Unbounded.To_Unbounded_String ("set " &
Key &
Flags_Type'Image (Flags) &
Natural'Image (Expire_Since_Epoch) &
Natural'Image (Value'Length) &
CRLF &
Append_CRLF (Value));
if No_Reply then
Unbounded.Append (Command,
Unbounded.To_Unbounded_String (" noreply"));
end if;
return Unbounded.To_String (Command);
end Generate_Set;
function Generate_Get (Key : in String) return String is
begin

View File

@ -168,6 +168,10 @@ private
Flags : in Flags_Type;
Expire : in Expiration;
No_Reply : in Boolean) return String;
function Generate_Set (Key : in String; Value : in String;
Flags : in Flags_Type;
Expire : in Ada.Calendar.Time;
No_Reply : in Boolean) return String;
function Generate_Get (Key : in String) return String;

View File

@ -9,6 +9,10 @@ package body Memcache.Test.Set is
Register_Routine (T, Test_Gen_Set'Access,
"Validate an set call generates the " &
"right string");
Register_Routine (T, Test_Gen_Set_Calendar'Access,
"Validate an set call with an Ada.Calendar.Time" &
" object generates the " &
"right string");
end Register_Tests;
@ -21,12 +25,25 @@ package body Memcache.Test.Set is
procedure Test_Gen_Set (T :
in out AUnit.Test_Cases.Test_Case'Class) is
Command : String := Generate_Set ("sets", "magicvalue", 0,
Command : constant String := Generate_Set ("sets", "magicvalue", 0,
60.0, False);
Expected : String := "set sets 0 60 10" &
Expected : constant String := "set sets 0 60 10" &
ASCII.CR & ASCII.LF &
"magicvalue" & ASCII.CR & ASCII.LF;
begin
Assert (Command = Expected, "Bad `set` command string");
end Test_Gen_Set;
procedure Test_Gen_Set_Calendar (T :
in out AUnit.Test_Cases.Test_Case'Class) is
Some_Time : constant Ada.Calendar.Time :=
Ada.Calendar.Time_Of (1985, 11, 20);
Command : constant String := Generate_Set ("sets", "magicvalue", 0,
Some_Time, False);
Expected : constant String := "set sets 0 501292800 10" &
ASCII.CR & ASCII.LF &
"magicvalue" & ASCII.CR & ASCII.LF;
begin
Assert (Command = Expected, "Bad `set` command string");
end Test_Gen_Set_Calendar;
end Memcache.Test.Set;

View File

@ -10,5 +10,7 @@ package Memcache.Test.Set is
procedure Test_Gen_Set (T :
in out AUnit.Test_Cases.Test_Case'Class);
procedure Test_Gen_Set_Calendar (T :
in out AUnit.Test_Cases.Test_Case'Class);
end Memcache.Test.Set;