Commit d021f1d1 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

done testing jx9 functions

parent bada44fb
......@@ -215,7 +215,7 @@ int UnQLiteVM::sntd_coll_create(unqlite_context *pCtx, int argc, unqlite_value *
int ret;
if(b) {
result = unqlite_context_new_array(pCtx);
unqlite_array_add_strkey_elem(result, "database_info", argv[0]);
unqlite_array_add_strkey_elem(result, "database", argv[0]);
unqlite_array_add_strkey_elem(result, "collection_name", argv[1]);
} else {
result = unqlite_context_new_scalar(pCtx);
......@@ -260,7 +260,7 @@ int UnQLiteVM::sntd_coll_open(unqlite_context *pCtx, int argc, unqlite_value **a
int ret;
if(b) {
result = unqlite_context_new_array(pCtx);
unqlite_array_add_strkey_elem(result, "database_info", argv[0]);
unqlite_array_add_strkey_elem(result, "database", argv[0]);
unqlite_array_add_strkey_elem(result, "collection_name", argv[1]);
ret = unqlite_result_value(pCtx, result);
} else {
......
......@@ -5,7 +5,6 @@ print "Executing snta_db_create test\n";
$rc = snta_db_create($addr, 0, "dbFromJx9", "unqlite", { path : "dbFromJx9" });
if($rc != TRUE) {
print "snta_db_create failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......@@ -17,7 +16,6 @@ print "Executing snta_db_detach test\n";
$rc = snta_db_detach($addr, 0, "dbFromJx9");
if($rc != TRUE) {
print "snta_db_detach failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......@@ -29,7 +27,6 @@ print "Executing snta_db_attach test\n";
$rc = snta_db_attach($addr, 0, "dbFromJx9", "unqlite", { path : "dbFromJx9" });
if($rc != TRUE) {
print "snta_db_attach failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......@@ -40,7 +37,6 @@ if($rc != TRUE) {
print "Executing snta_db_destroy test\n";
$rc = snta_db_destroy($addr, 0, "dbFromJx9");
if($rc != TRUE) {
print db_errlog();
print "snta_db_destroy failed\n";
$rc = FALSE;
return;
......
......@@ -4,7 +4,6 @@ print "Executing snta_db_attach test\n";
$rc = snta_db_attach($addr, 0, "dbFromJx9", "blabla", { path : "dbFromJx9" });
if($rc != TRUE) {
print "snta_db_attach failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......
......@@ -5,7 +5,6 @@ print "Executing snta_db_create test\n";
$rc = snta_db_create($addr, 0, "dbFromJx9", "blabla", { path : "dbFromJx9" });
if($rc != TRUE) {
print "snta_db_create failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......
......@@ -4,7 +4,6 @@ print "Executing snta_db_destroy test\n";
$rc = snta_db_destroy($addr, 0, "blabla");
if($rc != TRUE) {
print "snta_db_destroy failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......
......@@ -4,7 +4,6 @@ print "Executing snta_db_detach test\n";
$rc = snta_db_detach($addr, 0, "blabla");
if($rc != TRUE) {
print "snta_db_detach failed\n";
print db_errlog();
$rc = FALSE;
return;
} else {
......
......@@ -4,7 +4,6 @@ print "Executing test on address ", $addr, "\n";
$ret = snta_db_create($addr, 0, "dbFromJx9", "unqlite", { path : "dbFromJx9" });
if($ret != TRUE) {
print "snta_db_create failed\n";
print db_errlog();
$rc = FALSE;
return;
}
......@@ -17,7 +16,6 @@ print "Creating mycollection... ";
$coll_info = sntd_coll_create($db, "mycollection");
if($coll_info == NULL) {
print "snta_db_create failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -28,7 +26,6 @@ print "Creating mycollection again (should fail)... ";
$coll_info = sntd_coll_create($db, "mycollection");
if($coll_info != NULL) {
print "snta_db_create was successful when it should have failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -39,7 +36,6 @@ print "Checking if mycollection exists... ";
$exists = sntd_coll_exists($db, "mycollection");
if($exists != TRUE) {
print "sntd_coll_exists failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -50,7 +46,6 @@ print "Checking if blabla exists (should fail)... ";
$exists = sntd_coll_exists($db, "blabla");
if($exists == TRUE) {
print "sntd_coll_exists was successful when it should have failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -61,7 +56,6 @@ print "Opening mycollection... ";
$coll_info = sntd_coll_open($db, "mycollection");
if($coll_info == NULL) {
print "sntd_coll_open failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -72,7 +66,6 @@ print "Opening blabla (should fail)... ";
$coll_info = sntd_coll_open($db, "blabla");
if($coll_info != NULL) {
print "sntd_coll_open was successful when it should have failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -83,7 +76,6 @@ print "Dropping mycollection... ";
$ret = sntd_coll_drop($db, "mycollection");
if($ret != TRUE) {
print "sntd_coll_drop failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -94,7 +86,6 @@ print "Checking if mycollection exists (should return FALSE)... ";
$exists = sntd_coll_exists($db, "mycollection");
if($exists != FALSE) {
print "sntd_coll_exists returned TRUE for a collection that was erased\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -105,7 +96,6 @@ print "Dropping blabla (should fail)... ";
$ret = sntd_coll_drop($db, "blabla");
if($ret == TRUE) {
print "sntd_coll_drop returned TRUE for a collection that did not exist\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -115,7 +105,6 @@ print "OK\n";
print "Destroying database dbFromJx9\n";
$rc = snta_db_destroy($addr, 0, "dbFromJx9");
if($rc != TRUE) {
print db_errlog();
print "snta_db_destroy failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
......
......@@ -4,7 +4,6 @@ print "Executing test on address ", $addr, "\n";
$ret = snta_db_create($addr, 0, "dbFromJx9", "unqlite", { path : "dbFromJx9" });
if($ret != TRUE) {
print "snta_db_create failed\n";
print db_errlog();
$rc = FALSE;
return;
}
......@@ -23,7 +22,6 @@ function myfunction() {
$results = sntd_execute($db, myfunction, ["a","__output__"]);
if($results == NULL) {
print "sntd_execute failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -35,7 +33,6 @@ $fcode = "\$a = 42; print \"blabla\";";
$results = sntd_execute($db, $fcode, ["a","__output__"]);
if($results == NULL) {
print "sntd_execute failed\n";
print db_errlog();
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
......@@ -45,7 +42,6 @@ print "OK\n";
print "Destroying database dbFromJx9\n";
$rc = snta_db_destroy($addr, 0, "dbFromJx9");
if($rc != TRUE) {
print db_errlog();
print "snta_db_destroy failed\n";
$rc = FALSE;
return;
......
$rc = TRUE;
print "Executing test on address ", $addr, "\n";
$ret = snta_db_create($addr, 0, "dbFromJx9", "unqlite", { path : "dbFromJx9" });
if($ret != TRUE) {
print "snta_db_create failed\n";
$rc = FALSE;
return;
}
$db = { database_name : "dbFromJx9",
address : $addr,
provider_id : 0 };
// Create a collection
$coll = sntd_coll_create($db, "mycollection");
$records = [
{ name : "John Lennon", year : 1940 },
{ name : "Paul McCartney", year : 1942 },
{ name : "George Harrison", year : 1943 },
{ name : "Peter Best", year : 1941 }
];
print "Testing sntc_store... ";
for($i = 0; $i < 4 ; $i++) {
$id = sntc_store($coll, $records[$i]);
if($id == NULL) {
print "sntd_store failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
}
print "OK\n";
print "Testing sntc_fetch... ";
for($i = 0; $i < 4 ; $i++) {
$r = sntc_fetch($coll, $i);
if($r == NULL) {
print "sntc_fetch failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
if($r.name != $records[$i].name) {
print "record field not matching\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
}
print "OK\n";
print "Testing sntc_all... ";
$r = sntc_all($coll);
if($r == NULL) {
print "sntc_all failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
for($i = 0; $i < 4 ; $i++) {
if($r[$i].name != $records[$i].name) {
print "record field not matching\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
}
print "OK\n";
print "Testing sntc_filter... ";
function myfilter($member) {
if($member.year > 1941) {
return TRUE;
} else {
return FALSE;
}
}
$filtered = sntc_filter($coll, myfilter);
if($filtered == NULL) {
print "sntc_filter failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
if(count($filtered) != 2) {
print "unexpected number of returned records\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
print "OK\n";
print "Testing sntc_size... ";
$size = sntc_size($coll);
if($size != 4) {
print "sntc_size failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
print "OK\n";
print "Testing sntc_last_record_id... ";
$id = sntc_last_record_id($coll);
if($id != 3) {
print "sntc_last_record_id failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
print "OK\n";
print "Testing sntc_update... ";
$ret = sntc_update($coll, 3, { "name" : "Ringo Starr", "year" : 1940 });
if($r == NULL) {
print "sntc_update failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
$new_record = sntc_fetch($coll, 3);
if($new_record.name != "Ringo Starr") {
print "recod not matching after update\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
print "OK\n";
print "Testing sntc_erase... ";
$ret = sntc_erase($coll, 0);
if($ret == NULL) {
print "sntc_erase failed\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
$record0 = sntc_fetch($coll, 0);
if($record0 != NULL) {
print "sntc_fetch returned a result when it shouldn't have\n";
snta_db_destroy($addr, 0, "dbFromJx9");
$rc = FALSE;
return;
}
print "OK\n";
print "Destroying database dbFromJx9\n";
$rc = snta_db_destroy($addr, 0, "dbFromJx9");
if($rc != TRUE) {
print "snta_db_destroy failed\n";
$rc = FALSE;
return;
}
print "All done!";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment