adding test for get_own_addresses() keysync
authorVolker Birk <vb@pep.foundation>
Sat, 20 Aug 2016 16:03:54 +0200
branchkeysync
changeset 10453b77f5e254c1
parent 1044 10a56596be7d
child 1046 73be5d9af815
adding test for get_own_addresses()
src/pEpEngine.c
test/_test_template_cc
test/get_own_addresses_test.cc
test/pEpEngine_test.h
     1.1 --- a/src/pEpEngine.c	Sat Aug 20 15:29:43 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Sat Aug 20 16:03:54 2016 +0200
     1.3 @@ -1751,11 +1751,11 @@
     1.4      stringlist_t *_a = _addresses;
     1.5      do {
     1.6          result = sqlite3_step(session->get_own_addresses);
     1.7 -        char *address;
     1.8 +        const char *address;
     1.9          switch (result) {
    1.10              case SQLITE_ROW:
    1.11 -                sqlite3_bind_text(session->get_own_addresses, 1, address, -1,
    1.12 -                        SQLITE_STATIC);
    1.13 +                address = (const char *)
    1.14 +                    sqlite3_column_text(session->get_own_addresses, 0);
    1.15                  _a = stringlist_add(_a, address);
    1.16                  if (!_a) {
    1.17                      free_stringlist(_addresses);
    1.18 @@ -1763,6 +1763,9 @@
    1.19                  }
    1.20                  break;
    1.21  
    1.22 +            case SQLITE_DONE:
    1.23 +                break;
    1.24 +
    1.25              default:
    1.26                  status = PEP_UNKNOWN_ERROR;
    1.27          }
     2.1 --- a/test/_test_template_cc	Sat Aug 20 15:29:43 2016 +0200
     2.2 +++ b/test/_test_template_cc	Sat Aug 20 16:03:54 2016 +0200
     2.3 @@ -1,6 +1,7 @@
     2.4  #include <iostream>
     2.5  #include <string>
     2.6  #include <assert.h>
     2.7 +#include "pEpEngine_test.h"
     2.8  #include "MODULE.h"
     2.9  
    2.10  using namespace std;
    2.11 @@ -12,7 +13,7 @@
    2.12      
    2.13      cout << "calling init()\n";
    2.14      PEP_STATUS status1 = init(&session);   
    2.15 -    assert(status1 == PEP_STATUS_OK);
    2.16 +    ASSERT_STATUS(status1);
    2.17      assert(session);
    2.18      cout << "init() completed.\n";
    2.19  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/get_own_addresses_test.cc	Sat Aug 20 16:03:54 2016 +0200
     3.3 @@ -0,0 +1,38 @@
     3.4 +#include <iostream>
     3.5 +#include <string>
     3.6 +#include <assert.h>
     3.7 +#include "pEpEngine_test.h"
     3.8 +#include "pEpEngine.h"
     3.9 +
    3.10 +using namespace std;
    3.11 +
    3.12 +int main() {
    3.13 +    cout << "\n*** get_own_addresses_test ***\n\n";
    3.14 +
    3.15 +    PEP_SESSION session;
    3.16 +    
    3.17 +    cout << "calling init()\n";
    3.18 +    PEP_STATUS status1 = init(&session);   
    3.19 +    ASSERT_STATUS(status1);
    3.20 +    assert(session);
    3.21 +    cout << "init() completed.\n";
    3.22 +
    3.23 +    // get_own_addresses test code
    3.24 +
    3.25 +    cout << "calling get_own_addresses()\n";
    3.26 +    stringlist_t *addresses = NULL;
    3.27 +    PEP_STATUS status2 = get_own_addresses(session, &addresses);
    3.28 +    ASSERT_STATUS(status2);
    3.29 +    assert(addresses);
    3.30 +    cout << "success.\n";
    3.31 +
    3.32 +    cout << "addresses received:\n";
    3.33 +    for (stringlist_t *_a = addresses; _a && _a->value; _a = _a->next)
    3.34 +        cout << _a->value << "\n";
    3.35 +    cout << ".\n";
    3.36 +
    3.37 +    cout << "calling release()\n";
    3.38 +    release(session);
    3.39 +    return 0;
    3.40 +}
    3.41 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/pEpEngine_test.h	Sat Aug 20 16:03:54 2016 +0200
     4.3 @@ -0,0 +1,4 @@
     4.4 +#include <iomanip>
     4.5 +
     4.6 +#define ASSERT_STATUS(status) { cout << setfill('0') << "status: 0x" << hex << setw(4) << status << "\n"; assert(status == PEP_STATUS_OK); }
     4.7 +