0

I am trying to make some unit tests for database functions in C language, but i am not aware is it possible with cmocka? I couldn't find any example on the internet for database testing using cmocka, so i wonder if someone has an example of testing database functions with cmocka. For example it could be connecting to database, reading from database, writing to database, updating database, any example would help.

EDIT Let's say i have the following function in a separate Base.c file:

static  void    dbclose(int SQLnumber)
    {

    if (hDbc[SQLnumber])
        {
        SQLDisconnect(hDbc[SQLnumber]);
        SQLFreeConnect(hDbc[SQLnumber]);
        }

    hDbc[SQLnumber] = NULL;
    }

How to define the wrap method in CMakeLists.txt so i could use it in Tests.c file? Also, is it possible to wrap the SQLDisconnect and SQLFreeConnect from the SQL API separately?

jst
  • 1
  • 1
  • Welcome to StackOverflow! Please take the [tour] to learn how this site works. And please read "[ask]". Recommendations are off-topic here, and this is not a forum. -- What do you want to test, the database or the functions implementing the actions listed? This is important, because you mock the surrounding systems, not the unit under test. – the busybee Aug 25 '22 at 19:28
  • As mentioned above, i need to test the functions. – jst Aug 31 '22 at 08:33
  • We might better help you if you add a [mre] to your question by [edit]ing it. (BTW, you did not yet take the [tour].) What database are you using? – the busybee Aug 31 '22 at 08:56

0 Answers0