Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Srinivasan Ramesh
sonata
Commits
75e5f35f
Commit
75e5f35f
authored
Mar 31, 2020
by
Matthieu Dorier
Browse files
added execute test
parent
f3890b72
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/sonata/Exception.hpp
View file @
75e5f35f
...
@@ -8,7 +8,7 @@ namespace sonata {
...
@@ -8,7 +8,7 @@ namespace sonata {
class
Exception
:
public
std
::
exception
{
class
Exception
:
public
std
::
exception
{
const
std
::
string
&
m_error
;
std
::
string
m_error
;
public:
public:
...
...
src/UnQLiteVM.hpp
View file @
75e5f35f
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <type_traits>
#include <type_traits>
#include <string>
#include <string>
#include <spdlog/spdlog.h>
namespace
sonata
{
namespace
sonata
{
...
@@ -74,17 +75,17 @@ class UnQLiteVM {
...
@@ -74,17 +75,17 @@ class UnQLiteVM {
}
}
void
parse_and_throw_error
()
{
void
parse_and_throw_error
()
{
const
char
*
errorBuffer
;
const
char
*
errorBuffer
=
nullptr
;
int
len
;
int
len
=
0
;
unqlite_config
(
m_db
,
UNQLITE_CONFIG_JX9_ERR_LOG
,
&
errorBuffer
,
&
len
);
unqlite_config
(
m_db
,
UNQLITE_CONFIG_JX9_ERR_LOG
,
&
errorBuffer
,
&
len
);
std
::
string
error
=
"UnQLite error: "
s
;
std
::
string
error
=
"UnQLite error: "
s
;
if
(
len
>
0
)
{
if
(
len
>
0
)
{
error
+=
errorBuffer
;
error
+=
std
::
string
(
errorBuffer
,
len
)
;
throw
Exception
(
error
);
throw
Exception
(
error
);
}
}
unqlite_config
(
m_db
,
UNQLITE_CONFIG_ERR_LOG
,
&
errorBuffer
,
&
len
);
unqlite_config
(
m_db
,
UNQLITE_CONFIG_ERR_LOG
,
&
errorBuffer
,
&
len
);
if
(
len
>
0
)
{
if
(
len
>
0
)
{
error
+=
errorBuffer
;
error
+=
std
::
string
(
errorBuffer
,
len
)
;
throw
Exception
(
error
);
throw
Exception
(
error
);
}
}
error
+=
"(unknown)"
;
error
+=
"(unknown)"
;
...
...
test/CMakeLists.txt
View file @
75e5f35f
...
@@ -17,7 +17,11 @@ target_link_libraries(DatabaseTest sonata-test)
...
@@ -17,7 +17,11 @@ target_link_libraries(DatabaseTest sonata-test)
add_executable
(
CollectionTest CollectionTest.cpp
)
add_executable
(
CollectionTest CollectionTest.cpp
)
target_link_libraries
(
CollectionTest sonata-test
)
target_link_libraries
(
CollectionTest sonata-test
)
add_executable
(
ExecTest ExecTest.cpp
)
target_link_libraries
(
ExecTest sonata-test
)
add_test
(
NAME AdminTest COMMAND ./AdminTest AdminTest.xml
)
add_test
(
NAME AdminTest COMMAND ./AdminTest AdminTest.xml
)
add_test
(
NAME ClientTest COMMAND ./ClientTest ClientTest.xml
)
add_test
(
NAME ClientTest COMMAND ./ClientTest ClientTest.xml
)
add_test
(
NAME DatabaseTest COMMAND ./DatabaseTest DatabaseText.xml
)
add_test
(
NAME DatabaseTest COMMAND ./DatabaseTest DatabaseText.xml
)
add_test
(
NAME CollectionTest COMMAND ./CollectionTest CollectionTest.xml
)
add_test
(
NAME CollectionTest COMMAND ./CollectionTest CollectionTest.xml
)
add_test
(
NAME ExecTest COMMAND ./ExecTest ExecTest.xml
)
test/ExecTest.cpp
0 → 100644
View file @
75e5f35f
#include <cppunit/extensions/HelperMacros.h>
#include <sonata/Client.hpp>
#include <sonata/Admin.hpp>
#include <spdlog/spdlog.h>
extern
thallium
::
engine
*
engine
;
class
ExecTest
:
public
CppUnit
::
TestFixture
{
CPPUNIT_TEST_SUITE
(
ExecTest
);
CPPUNIT_TEST
(
testExec
);
CPPUNIT_TEST_SUITE_END
();
static
constexpr
const
char
*
db_config
=
"{
\"
path
\"
:
\"
mydb
\"
}"
;
public:
void
setUp
()
{
sonata
::
Admin
admin
(
*
engine
);
std
::
string
addr
=
engine
->
self
();
admin
.
createDatabase
(
addr
,
0
,
"mydb"
,
"unqlite"
,
db_config
);
}
void
tearDown
()
{
sonata
::
Admin
admin
(
*
engine
);
std
::
string
addr
=
engine
->
self
();
admin
.
destroyDatabase
(
addr
,
0
,
"mydb"
);
}
void
testExec
()
{
sonata
::
Client
client
(
*
engine
);
std
::
string
addr
=
engine
->
self
();
sonata
::
Database
mydb
=
client
.
open
(
addr
,
0
,
"mydb"
);
std
::
string
code
=
"$zCol = 'users';"
"if( db_exists($zCol) ){"
"print
\"
Collection users already created
\\
n
\"
;"
"}else{"
"$rc = db_create($zCol);"
"if ( !$rc ){"
"return;"
"}"
"print
\"
Collection users successfully created
\\
n
\"
;"
"}"
;
std
::
unordered_set
<
std
::
string
>
vars
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
results
;
vars
.
insert
(
"rc"
);
CPPUNIT_ASSERT_NO_THROW_MESSAGE
(
"this call of execute should not throw."
,
mydb
.
execute
(
code
,
vars
,
&
results
));
CPPUNIT_ASSERT_EQUAL_MESSAGE
(
"rc should be true."
,
std
::
string
(
"true"
),
results
[
"rc"
]);
// Assert that the collection the code above created is accessible
CPPUNIT_ASSERT_EQUAL_MESSAGE
(
"collection users should exist."
,
true
,
mydb
.
exists
(
"users"
));
// Test with an erroneous code
code
=
"sdasd{}[2"
;
CPPUNIT_ASSERT_THROW_MESSAGE
(
"this call of execute should throw."
,
mydb
.
execute
(
code
,
vars
,
&
results
),
sonata
::
Exception
);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION
(
ExecTest
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment