Add more tests for previously-untested BIFs

This commit is contained in:
Daniel Thayer 2012-05-24 16:33:19 -05:00
parent 94e850397b
commit 03aee9197d
28 changed files with 272 additions and 2 deletions

View file

@ -0,0 +1,3 @@
F
F
T

View file

@ -0,0 +1,3 @@
T
F
F

View file

@ -0,0 +1,2 @@
1
0

View file

@ -0,0 +1 @@
hello

View file

@ -0,0 +1,3 @@
OK
OK
OK

View file

@ -0,0 +1,6 @@
1
4
2
0
0
0

View file

@ -2,3 +2,5 @@ f97c5d29941bfb1b2fdab0874906ab82
7b0391feb2e0cd271f1cf39aafb4376f 7b0391feb2e0cd271f1cf39aafb4376f
f97c5d29941bfb1b2fdab0874906ab82 f97c5d29941bfb1b2fdab0874906ab82
7b0391feb2e0cd271f1cf39aafb4376f 7b0391feb2e0cd271f1cf39aafb4376f
571c0a35c7858ad5a0e16b8fdb41adcd
1751cbd623726f423f734e23a8c7ec06

View file

@ -0,0 +1,6 @@
185
236
805
47
996
498

View file

@ -0,0 +1,4 @@
3
5
0
7

View file

@ -0,0 +1,2 @@
[5, 3, 8]
[3, 5, 8]

View file

@ -0,0 +1 @@
thistest

View file

@ -0,0 +1 @@
helloworld

View file

@ -0,0 +1,2 @@
72
72

View file

@ -0,0 +1,15 @@
#
# @TEST-EXEC: bro %INPUT >out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = vector( T, F, T );
print all_set(a);
local b = vector();
print all_set(b);
local c = vector( T );
print all_set(c);
}

View file

@ -0,0 +1,15 @@
#
# @TEST-EXEC: bro %INPUT >out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = vector( F, T, F );
print any_set(a);
local b = vector();
print any_set(b);
local c = vector( F );
print any_set(c);
}

View file

@ -0,0 +1,14 @@
#
# @TEST-EXEC: bro %INPUT > out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local mytable: table[string] of string = { ["key1"] = "val1" };
print |mytable|;
clear_table(mytable);
print |mytable|;
}

View file

@ -0,0 +1,9 @@
#
# @TEST-EXEC: bro %INPUT >out || test $? -eq 7
# @TEST-EXEC: btest-diff out
event bro_init()
{
print "hello";
exit(7);
}

View file

@ -0,0 +1,20 @@
#
# @TEST-EXEC: TESTBRO=testvalue bro %INPUT >out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = getenv("NOTDEFINED");
local b = getenv("TESTBRO");
if ( |a| == 0 )
print "OK";
if ( b == "testvalue" )
print "OK";
if ( setenv("NOTDEFINED", "now defined" ) == T )
{
if ( getenv("NOTDEFINED") == "now defined" )
print "OK";
}
}

View file

@ -0,0 +1,22 @@
#
# @TEST-EXEC: bro %INPUT > out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local mytable: table[string] of string = { ["key1"] = "val1" };
local myset: set[count] = set( 3, 6, 2, 7 );
local myvec: vector of string = vector( "value1", "value2" );
print length(mytable);
print length(myset);
print length(myvec);
mytable = table();
myset = set();
myvec = vector();
print length(mytable);
print length(myset);
print length(myvec);
}

View file

@ -14,3 +14,6 @@ md5_hash_update("b", "three");
print md5_hash_finish("a"); print md5_hash_finish("a");
print md5_hash_finish("b"); print md5_hash_finish("b");
print md5_hmac("one");
print md5_hmac("one", "two", "three");

View file

@ -0,0 +1,18 @@
#
# @TEST-EXEC: bro %INPUT >out
# @TEST-EXEC: btest-diff out
function myfunc(a: count, b: count): bool
{
return a < b;
}
event bro_init()
{
local a = vector( 5, 3, 8 );
print order(a, myfunc);
print a;
}

View file

@ -5,8 +5,10 @@
global cmds = "print \"hello world\";"; global cmds = "print \"hello world\";";
cmds = string_cat(cmds, "\nprint \"foobar\";"); cmds = string_cat(cmds, "\nprint \"foobar\";");
piped_exec("bro", cmds); if ( piped_exec("bro", cmds) != T )
exit(1);
# Test null output. # Test null output.
piped_exec("cat > test.txt", "\x00\x00hello\x00\x00"); if ( piped_exec("cat > test.txt", "\x00\x00hello\x00\x00") != T )
exit(1);

View file

@ -0,0 +1,24 @@
#
# @TEST-EXEC: bro %INPUT >out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = rand(1000);
local b = rand(1000);
local c = rand(1000);
print a;
print b;
print c;
srand(575);
local d = rand(1000);
local e = rand(1000);
local f = rand(1000);
print d;
print e;
print f;
}

View file

@ -0,0 +1,26 @@
#
# @TEST-EXEC: bro %INPUT >out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = vector( 5, 3, 8 );
print |a|;
if ( resize(a, 5) != 3 )
exit(1);
print |a|;
if ( resize(a, 0) != 5 )
exit(1);
print |a|;
if ( resize(a, 7) != 0 )
exit(1);
print |a|;
}

View file

@ -0,0 +1,18 @@
#
# @TEST-EXEC: bro %INPUT >out
# @TEST-EXEC: btest-diff out
function myfunc(a: count, b: count): bool
{
return a < b;
}
event bro_init()
{
local a = vector( 5, 3, 8 );
print sort(a, myfunc);
print a;
}

View file

@ -0,0 +1,15 @@
#
# @TEST-EXEC: bro %INPUT
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = system("echo thistest > out");
if ( a != 0 )
exit(1);
local b = system("");
if ( b == 0 )
exit(1);
}

View file

@ -0,0 +1,21 @@
#
# @TEST-EXEC: bro %INPUT
# @TEST-EXEC: btest-diff out
event bro_init()
{
local vars: table[string] of string = { ["TESTBRO"] = "helloworld" };
# make sure the env. variable is not set
local myvar = getenv("TESTBRO");
if ( |myvar| != 0 )
exit(1);
local a = system_env("echo $TESTBRO > out", vars);
if ( a != 0 )
exit(1);
myvar = getenv("TESTBRO");
if ( |myvar| != 0 )
exit(1);
}

View file

@ -0,0 +1,12 @@
#
# @TEST-EXEC: bro %INPUT > out
# @TEST-EXEC: btest-diff out
event bro_init()
{
local a = 1;
local b = T;
print val_size(a);
print val_size(b);
}