Commits

Alexey Kishkin committed 562a386

add OUnit tests

Comments (0)

Files changed (1)

+open OUnit;;
+open Memcache;;
+
+let test_fixture = "Memcache binary protocol tests " >:::
+   [
+   "set_i8" >:: (fun () ->
+      assert_equal "\000" (let cargo = Buffer.create 1 in (set_i8 cargo 0; Buffer.contents cargo)); 
+      assert_equal "\010" (let cargo = Buffer.create 1 in (set_i8 cargo 10; Buffer.contents cargo)); 
+      assert_equal "\255" (let cargo = Buffer.create 1 in (set_i8 cargo 255; Buffer.contents cargo));
+ (*     assert_raises (Invalid_argument _) (fun () -> let cargo = Buffer.create 1 in ignore(set_i8 cargo 256) ); *)
+      );
+   "set_i16" >:: (fun() ->  
+       assert_equal "\000\000" (let cargo = Buffer.create 1 in (set_i16 cargo 0; Buffer.contents cargo)); 
+       assert_equal "\000\010" (let cargo = Buffer.create 1 in (set_i16 cargo 10; Buffer.contents cargo)); 
+       assert_equal "\000\255" (let cargo = Buffer.create 1 in (set_i16 cargo 255; Buffer.contents cargo));
+       assert_equal "\001\000" (let cargo = Buffer.create 1 in (set_i16 cargo 256; Buffer.contents cargo));
+       assert_equal "\255\255" (let cargo = Buffer.create 1 in (set_i16 cargo 0xFFFF; Buffer.contents cargo));
+(*       assert_raises (Invalid_argument _) (fun () -> let cargo = Buffer.create 1 in ignore(set_i16 cargo 256) ); *)
+      )
+   ];;
+
+let _ = run_test_tt ~verbose: true test_fixture