basic test code sync
authorVolker Birk <vb@pep.foundation>
Thu, 16 Aug 2018 15:28:36 +0200
branchsync
changeset 2852135a3e49e48d
parent 2851 af6de711d3a2
child 2853 f5f2abf9adcf
basic test code
test/include/SyncTests.h
test/include/locked_queue.hh
test/src/engine_tests/SyncTests.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/include/SyncTests.h	Thu Aug 16 15:28:36 2018 +0200
     1.3 @@ -0,0 +1,19 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#ifndef SYNC_H
     1.8 +#define SYNC_H
     1.9 +
    1.10 +#include <string>
    1.11 +#include "EngineTestSessionSuite.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +class SyncTests : public EngineTestSessionSuite {
    1.16 +    public:
    1.17 +        SyncTests(string test_suite, string test_home_dir);
    1.18 +    private:
    1.19 +        void check_sync();
    1.20 +};
    1.21 +
    1.22 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/include/locked_queue.hh	Thu Aug 16 15:28:36 2018 +0200
     2.3 @@ -0,0 +1,52 @@
     2.4 +#pragma once
     2.5 +
     2.6 +#include <list>
     2.7 +#include <mutex>
     2.8 +
     2.9 +namespace utility
    2.10 +{
    2.11 +    using namespace std;
    2.12 +
    2.13 +    template<class T> class locked_queue
    2.14 +    {
    2.15 +        mutex _mtx;
    2.16 +        list<T> _q;
    2.17 +
    2.18 +    public:
    2.19 +        T& back()
    2.20 +        {
    2.21 +            lock_guard<mutex> lg(_mtx);
    2.22 +            return _q.back();
    2.23 +        }
    2.24 +        T& front()
    2.25 +        {
    2.26 +            lock_guard<mutex> lg(_mtx);
    2.27 +            return _q.front();
    2.28 +        }
    2.29 +        void pop_back()
    2.30 +        {
    2.31 +            lock_guard<mutex> lg(_mtx);
    2.32 +            _q.pop_back();
    2.33 +        }
    2.34 +        void pop_front()
    2.35 +        {
    2.36 +            lock_guard<mutex> lg(_mtx);
    2.37 +            _q.pop_front();
    2.38 +        }
    2.39 +        void push_back(const T& data)
    2.40 +        {
    2.41 +            lock_guard<mutex> lg(_mtx);
    2.42 +            _q.push_back(data);
    2.43 +        }
    2.44 +        void push_front(const T& data)
    2.45 +        {
    2.46 +            lock_guard<mutex> lg(_mtx);
    2.47 +            _q.push_front(data);
    2.48 +        }
    2.49 +        size_t size()
    2.50 +        {
    2.51 +            lock_guard<mutex> lg(_mtx);
    2.52 +            return _q.size();
    2.53 +        }
    2.54 +    };
    2.55 +};
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/src/engine_tests/SyncTests.cc	Thu Aug 16 15:28:36 2018 +0200
     3.3 @@ -0,0 +1,62 @@
     3.4 +// This file is under GNU General Public License 3.0
     3.5 +// see LICENSE.txt
     3.6 +
     3.7 +#include <stdlib.h>
     3.8 +#include <string>
     3.9 +
    3.10 +#include "pEpEngine.h"
    3.11 +#include "sync_api.h"
    3.12 +#include "Sync_event.h"
    3.13 +
    3.14 +#include "EngineTestSessionSuite.h"
    3.15 +#include "SyncTests.h"
    3.16 +
    3.17 +#include "locked_queue.hh"
    3.18 +
    3.19 +using namespace std;
    3.20 +
    3.21 +class Sync_Adapter {
    3.22 +public:
    3.23 +    utility::locked_queue< Sync_event_t * > q;
    3.24 +
    3.25 +    static PEP_STATUS notifyHandshake(
    3.26 +        void *obj,
    3.27 +        pEp_identity *me,
    3.28 +        pEp_identity *partner,
    3.29 +        sync_handshake_signal signal
    3.30 +    )
    3.31 +    {
    3.32 +        return PEP_STATUS_OK;
    3.33 +    }
    3.34 +
    3.35 +    static int inject_sync_event(SYNC_EVENT ev, void *management)
    3.36 +    {
    3.37 +        return 0;
    3.38 +    }
    3.39 +    static Sync_event_t *retrieve_next_sync_event(void *management)
    3.40 +    {
    3.41 +        return NULL;
    3.42 +    }
    3.43 +};
    3.44 +
    3.45 +SyncTests::SyncTests(string suitename, string test_home_dir) :
    3.46 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
    3.47 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SyncTests::check_sync"),
    3.48 +                                                                      static_cast<Func>(&SyncTests::check_sync)));
    3.49 +}
    3.50 +
    3.51 +void SyncTests::check_sync() {
    3.52 +    Sync_Adapter adapter;
    3.53 +
    3.54 +    PEP_STATUS status = register_sync_callbacks(
    3.55 +            session,
    3.56 +            &adapter.q,
    3.57 +            Sync_Adapter::notifyHandshake,
    3.58 +            Sync_Adapter::inject_sync_event,
    3.59 +            Sync_Adapter::retrieve_next_sync_event
    3.60 +        );
    3.61 +
    3.62 +    TEST_ASSERT(status == PEP_STATUS_OK);
    3.63 +    unregister_sync_callbacks(session);
    3.64 +}
    3.65 +