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

added JX9 test for database functions

parent 465e236a
......@@ -211,9 +211,20 @@ int UnQLiteVM::sntd_coll_create(unqlite_context *pCtx, int argc, unqlite_value *
} catch(...) {
b = false;
}
int ret = unqlite_result_bool(pCtx, b);
if(ret != UNQLITE_OK)
unqlite_value* result;
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, "collection_name", argv[1]);
} else {
result = unqlite_context_new_scalar(pCtx);
unqlite_value_null(result);
}
ret = unqlite_result_value(pCtx, result);
if(ret != UNQLITE_OK) {
throw Exception("Could not set result in unqlite context");
}
} CATCH_AND_ABORT();
return UNQLITE_OK;
}
......
$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";
print db_errlog();
$rc = FALSE;
return;
}
$db = { database_name : "dbFromJx9",
address : $addr,
provider_id : 0 };
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
print "OK\n";
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;
}
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;
return;
}
print "All done!";
......@@ -63,6 +63,7 @@ class Jx9Test : public CppUnit::TestFixture
for(const auto& jx9_file : m_jx9_files) {
std::cerr << "JX9 TEST from " << jx9_file << std::endl;
sonata::Admin admin(*engine);
admin.createDatabase(addr, 0, "mydb", "unqlite", db_config);
......@@ -81,7 +82,7 @@ class Jx9Test : public CppUnit::TestFixture
CPPUNIT_ASSERT_NO_THROW_MESSAGE(
"this call to execute should not throw.",
mydb.execute(code, vars, &results));
std::cout << results["__output__"];
if(jx9_file.find("failing") == std::string::npos) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"rc should be true.",
......@@ -91,7 +92,6 @@ class Jx9Test : public CppUnit::TestFixture
"rc should be false.",
std::string("false"), results["rc"]);
}
std::cout << results["__output__"];
admin.destroyDatabase(addr, 0, "mydb");
}
......
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