######################################################################
#
# File: tests.txt
# Purpose: This is a series of tests for the ClassAd library. 
#          Currently there is no good documentation for how to write
#          tests, you'll just have to look in test_classads.C
#
######################################################################

######################################################################
#
# Test the lexer
#
######################################################################
test-lexer-one-token    123    LEX_INTEGER_VALUE
test-lexer-one-token 123.456 LEX_REAL_VALUE
test-lexer-one-token true LEX_BOOLEAN_VALUE
test-lexer-one-token false LEX_BOOLEAN_VALUE
test-lexer-one-token "blah" LEX_STRING_VALUE
test-lexer-one-token "new\nline" LEX_STRING_VALUE
test-lexer-one-token "blue bibs be big" LEX_STRING_VALUE
test-lexer-one-token blah LEX_IDENTIFIER
test-lexer-one-token __ LEX_IDENTIFIER
test-lexer-one-token undefined LEX_UNDEFINED_VALUE
test-lexer-one-token error LEX_ERROR_VALUE
test-lexer-one-token . LEX_SELECTION
test-lexer-one-token * LEX_MULTIPLY
test-lexer-one-token / LEX_DIVIDE
test-lexer-one-token % LEX_MODULUS
test-lexer-one-token + LEX_PLUS
test-lexer-one-token - LEX_MINUS
test-lexer-one-token & LEX_BITWISE_AND
test-lexer-one-token | LEX_BITWISE_OR
test-lexer-one-token ~ LEX_BITWISE_NOT
test-lexer-one-token ^ LEX_BITWISE_XOR
test-lexer-one-token << LEX_LEFT_SHIFT
test-lexer-one-token >> LEX_RIGHT_SHIFT
test-lexer-one-token >>> LEX_URIGHT_SHIFT
test-lexer-one-token && LEX_LOGICAL_AND
test-lexer-one-token || LEX_LOGICAL_OR
test-lexer-one-token ! LEX_LOGICAL_NOT
test-lexer-one-token < LEX_LESS_THAN
test-lexer-one-token <= LEX_LESS_OR_EQUAL
test-lexer-one-token > LEX_GREATER_THAN
test-lexer-one-token >= LEX_GREATER_OR_EQUAL
test-lexer-one-token == LEX_EQUAL
test-lexer-one-token != LEX_NOT_EQUAL
test-lexer-one-token is LEX_META_EQUAL
test-lexer-one-token isnt LEX_META_NOT_EQUAL
test-lexer-one-token = LEX_BOUND_TO
test-lexer-one-token ? LEX_QMARK
test-lexer-one-token : LEX_COLON
test-lexer-one-token ; LEX_SEMICOLON
test-lexer-one-token , LEX_COMMA
test-lexer-one-token [ LEX_OPEN_BOX
test-lexer-one-token ] LEX_CLOSE_BOX
test-lexer-one-token ( LEX_OPEN_PAREN
test-lexer-one-token ) LEX_CLOSE_PAREN
test-lexer-one-token { LEX_OPEN_BRACE
test-lexer-one-token } LEX_CLOSE_BRACE

# I think this should evaluate to LEX_BACKSLASH. Apparently
# it's not actually used anywhere, so it's an error instead. 
test-lexer-one-token \ LEX_TOKEN_ERROR

######################################################################
#
# ClassAds
#
######################################################################
begin-classad Job-1
[
  Requirements = (other.Type == "Machine" && other.memory >= 4000);
  Type = "Job";
  Memoryused = 6000;
]
end-classad

begin-classad Machine-1
[
  Type = "machine";
  Requirements = (other.Type == "job" && other.memoryused < 8000);
  Memory = 5000;
]
end-classad

begin-classad Machine-2
[
  Type = "Machine";
  Requirements = other.mytype == "Job";
  Memory = 3000
]
end-classad

begin-classad Machine-3
[
  Type = "Machine";
  Requirements = other.mytype == "Job";
  Memory = 6000
]
end-classad

begin-classad Misc
[
  Type = "Misc";
  Self = [
           one = "foo";
		   two = "bar";
           rank = Other[StrCat(one, two)];
         ];
  Other = [
            one = 1;
            two = 2;
            foobar = 15
          ];
  Buddha = [
             which = Self.which;
           ];
  ClassAds = { [a = 1], [a = 2], [a = 3] };
  Set = ClassAds.a;
  SizeSet = size(Set);
  SizeZero = size({});
  SizeOne = size({1});
  SizeTwo = size({1, 2});
  Sum = sum(Set);
  Average = avg(Set);
  Min = min(Set);
  Max = max(Set);
  AllSmall = allcompare("<", Set, 100);
  AllBig   = allcompare(">", Set, 100); 
  AnyTwo   = anycompare("==", Set, 2);
  AllTwo   = allcompare("==", Set, 2);
  A = 1;
  B = true;
  C = !A;
  D = !B;
  R1 = regexp(".*\.cs\.uchicago\.edu",  "gargoyle.cs1uchicago.edu");
  R2 = regexp(".*\.cs\.wisc\.edu",     "beak.cs.wisc.edu");
  R3 = regexp(".*\.cs\.uchicago\.edu", "beak.cs.wisc.edu");
  R4 = regexp(".*\.cs\.wisc\.edu",     "gargoyle.cs.uchicago.edu");
  R5 = regexp(".*\.cs\.wisc\.edu|.*\.cs\.uchicago\.edu",     
              "gargoyle\.cs\.uchicago.edu");
  R6 = regexp(".*\.cs\.wisc\.edu|.*\.cs\.uchicago\.edu",     
              "beak.cs.wisc\.edu");

]
end-classad

begin-classad Motherboard
[
  have_match =    machine_enclosure.machine.Requirements 
              && job_enclosure.job.Requirements
              && storage_enclosure.storage.Requirements;

  machine_enclosure = 
  [ 
    job = job_enclosure.job;
	storage = storage_enclosure.storage;
    machine = [
                Type="Machine"; 
                RAM=6000;
                Requirements = (job.MemoryNeeded <= RAM);
              ];
  ];

  job_enclosure = 
  [
    machine = machine_enclosure.machine;
	storage = storage_enclosure.storage;
    job = [
            Type="Job";
            MemoryNeeded = 6000;
            DiskSpaceNeeded = 8000;
            Requirements = (machine.RAM >= MemoryNeeded
                         && storage.FreeDiskSpace > DiskSpaceNeeded)
          ];
  ];

  storage_enclosure = 
  [
    job = job_enclosure.job;
    machine = machine_enclosure.machine;
    storage = [
         Type = "Storage";
         FreeDiskSpace = 10000;
         Requirements = job.DiskSpaceNeeded < FreeDiskSpace;
         ];

  ];
]
end-classad

evaluate Motherboard job_enclosure.job.Requirements
evaluate Motherboard machine_enclosure.job.Requirements
evaluate Motherboard storage_enclosure.storage.Requirements
evaluate Motherboard have_match

######################################################################
#
# Basic Evaluation Tests
#
######################################################################
evaluate Job-1 TestTernary
evaluate Misc Self.rank
evaluate Machine-1 memory
evaluate Misc Set
evaluate Misc Sum
evaluate Misc Average
evaluate Misc Min
evaluate Misc Max
evaluate Misc AllSmall
evaluate Misc AllBig
evaluate Misc AnyTwo
evaluate Misc AllTwo
evaluate Misc ClassAds.b
evaluate Misc ClassAds.c
evaluate Misc All_Undefined
evaluate Misc Any_Undefined
evaluate Misc A
evaluate Misc B
evaluate Misc C
evaluate Misc D
evaluate Misc SizeSet;
evaluate Misc SizeZero;
evaluate Misc SizeOne;
evaluate Misc SizeTwo;
evaluate Misc R1;
evaluate Misc R2;
evaluate Misc R3;
evaluate Misc R4;
evaluate Misc R5;
evaluate Misc R6;

######################################################################
#
# Matching tests
#
######################################################################
test-match symmetricMatch Job-1 Machine-1 ExpectMatch
test-match leftMatchesRight Job-1 Machine-1 ExpectMatch
test-match rightMatchesLeft Job-1 Machine-1 ExpectMatch
test-match symmetricMatch Job-1 Machine-2 ExpectDontMatch

######################################################################
#
# Collections
#
######################################################################
#make-collection Machines machines-log
make-collection Machines
add-to-collection Machines Machine-1
add-to-collection Machines Machine-2
add-to-collection Machines Machine-3

create-subview Machines root Machine-View (other.Memory >= 4000)
check-in-view Machines Machine-View Machine-1 ExpectIn
check-in-view Machines Machine-View Machine-2 ExpectNotIn
check-in-view Machines Machine-View Machine-3 ExpectIn

create-subview Machines Machine-View BigMachine-View (other.Memory > 5000)
check-in-view Machines BigMachine-View Machine-1 ExpectNotIn
check-in-view Machines BigMachine-View Machine-2 ExpectNotIn
check-in-view Machines BigMachine-View Machine-3 ExpectIn

#truncate-log Machines

begin-classad Group-1
[
  Type = "Group";
  Users = {"Alain", "Peter"};
]
end-classad

begin-classad Group-2
[
  Type = "Group";
  Users = {"Annalisa", "David"};
]
end-classad

#make-collection Groups groups-log
make-collection Groups groups-log
add-to-collection Groups Group-1
add-to-collection Groups Group-2

begin-classad List-Eval
[ a = { x }; x = 1 ]
end-classad

evaluate Misc SizeOne;
evaluate Misc SizeTwo;
evaluate List-Eval a[0]

begin-classad Lexer-Fault
[ a=!b; b=true; ]
end-classad
evaluate Lexer-Fault b
evaluate Lexer-Fault a

begin-classad Octal
[ a = "\101\044\44\1"; /* Should be A(( */ ]
end-classad
evaluate Octal a

begin-classad Floats
[a = 0.7 * 4.5; ]
end-classad

begin-classad Quoted-Names
[
  'a' = 4;
  'b.##$%' = 5;
]
end-classad

begin-classad Times
[
  Abs1 = absTime("2003-09-03T");
  Rel1 = relTime("2+25:14:16.123");
]
end-classad

begin-classad Numbers
[
  X = 4.3;
  Y = real("4.3");
  Not = real("NaN");
  Infinite = real("INF");
  Negative_Infinite = real("-INF");
]
end-classad

print-classad Floats
print-classad Quoted-Names
print-classad Times
print-classad Numbers
print-classad-xml Numbers

begin-classad Loop
[
  attr = a//b
]
end-classad 

#begin-classad Crash
#[
#  attr = a<b>
#]
#end-classad 

begin-classad policy
[
  type = 'machine';
  access_times = 
    [
        globus = [start = 1900; end = 2100;];
        condor = [start = 100; end = 500;];
    ]
]
end-classad

evaluate policy access_times
evaluate policy access_times["globus"]
evaluate policy access_times["globus"].start

