test/src/engine_tests/SyncTests.cc
author Volker Birk <vb@pep.foundation>
Tue, 21 Aug 2018 17:35:00 +0200
branchsync
changeset 2864 dcbed0d35466
parent 2853 f5f2abf9adcf
child 2871 4593a7b8b6a8
permissions -rw-r--r--
...
vb@2852
     1
// This file is under GNU General Public License 3.0
vb@2852
     2
// see LICENSE.txt
vb@2852
     3
vb@2852
     4
#include <stdlib.h>
vb@2852
     5
#include <string>
vb@2852
     6
vb@2852
     7
#include "pEpEngine.h"
vb@2852
     8
#include "sync_api.h"
vb@2852
     9
#include "Sync_event.h"
vb@2852
    10
vb@2852
    11
#include "EngineTestSessionSuite.h"
vb@2852
    12
#include "SyncTests.h"
vb@2852
    13
vb@2852
    14
#include "locked_queue.hh"
vb@2852
    15
vb@2852
    16
using namespace std;
vb@2852
    17
vb@2852
    18
class Sync_Adapter {
vb@2852
    19
public:
vb@2852
    20
    utility::locked_queue< Sync_event_t * > q;
vb@2852
    21
vb@2852
    22
    static PEP_STATUS notifyHandshake(
vb@2852
    23
        void *obj,
vb@2852
    24
        pEp_identity *me,
vb@2852
    25
        pEp_identity *partner,
vb@2852
    26
        sync_handshake_signal signal
vb@2852
    27
    )
vb@2852
    28
    {
vb@2852
    29
        return PEP_STATUS_OK;
vb@2852
    30
    }
vb@2852
    31
vb@2852
    32
    static int inject_sync_event(SYNC_EVENT ev, void *management)
vb@2852
    33
    {
vb@2853
    34
        auto adapter = static_cast< Sync_Adapter *>(management);
vb@2853
    35
        adapter->q.push_front(ev);
vb@2852
    36
        return 0;
vb@2852
    37
    }
vb@2864
    38
vb@2852
    39
    static Sync_event_t *retrieve_next_sync_event(void *management)
vb@2852
    40
    {
vb@2853
    41
        auto adapter = static_cast< Sync_Adapter *>(management);
vb@2853
    42
        return adapter->q.pop_front();
vb@2852
    43
    }
vb@2852
    44
};
vb@2852
    45
vb@2852
    46
SyncTests::SyncTests(string suitename, string test_home_dir) :
vb@2852
    47
    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
vb@2852
    48
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SyncTests::check_sync"),
vb@2852
    49
                                                                      static_cast<Func>(&SyncTests::check_sync)));
vb@2852
    50
}
vb@2852
    51
vb@2852
    52
void SyncTests::check_sync() {
vb@2852
    53
    Sync_Adapter adapter;
vb@2852
    54
vb@2852
    55
    PEP_STATUS status = register_sync_callbacks(
vb@2852
    56
            session,
vb@2852
    57
            &adapter.q,
vb@2852
    58
            Sync_Adapter::notifyHandshake,
vb@2852
    59
            Sync_Adapter::inject_sync_event,
vb@2852
    60
            Sync_Adapter::retrieve_next_sync_event
vb@2852
    61
        );
vb@2852
    62
vb@2852
    63
    TEST_ASSERT(status == PEP_STATUS_OK);
vb@2852
    64
    unregister_sync_callbacks(session);
vb@2852
    65
}
vb@2852
    66