test/src/engine_tests/SyncTests.cc
author Volker Birk <vb@pep.foundation>
Wed, 22 Aug 2018 18:34:52 +0200
branchsync
changeset 2871 4593a7b8b6a8
parent 2864 dcbed0d35466
child 2873 ceaa29b309ef
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@2871
     9
vb@2871
    10
#include "pEp_internal.h"
vb@2871
    11
#include "KeySync_fsm.h"
vb@2852
    12
vb@2852
    13
#include "EngineTestSessionSuite.h"
vb@2852
    14
#include "SyncTests.h"
vb@2852
    15
vb@2852
    16
#include "locked_queue.hh"
vb@2852
    17
vb@2852
    18
using namespace std;
vb@2852
    19
vb@2852
    20
class Sync_Adapter {
vb@2852
    21
public:
vb@2852
    22
    utility::locked_queue< Sync_event_t * > q;
vb@2852
    23
vb@2852
    24
    static PEP_STATUS notifyHandshake(
vb@2871
    25
            void *obj,
vb@2871
    26
            pEp_identity *me,
vb@2871
    27
            pEp_identity *partner,
vb@2871
    28
            sync_handshake_signal signal
vb@2871
    29
        )
vb@2852
    30
    {
vb@2852
    31
        return PEP_STATUS_OK;
vb@2852
    32
    }
vb@2852
    33
vb@2852
    34
    static int inject_sync_event(SYNC_EVENT ev, void *management)
vb@2852
    35
    {
vb@2853
    36
        auto adapter = static_cast< Sync_Adapter *>(management);
vb@2853
    37
        adapter->q.push_front(ev);
vb@2852
    38
        return 0;
vb@2852
    39
    }
vb@2864
    40
vb@2852
    41
    static Sync_event_t *retrieve_next_sync_event(void *management)
vb@2852
    42
    {
vb@2853
    43
        auto adapter = static_cast< Sync_Adapter *>(management);
vb@2853
    44
        return adapter->q.pop_front();
vb@2852
    45
    }
vb@2871
    46
vb@2871
    47
    static PEP_STATUS messageToSend(void *obj, struct _message *msg)
vb@2871
    48
    {
vb@2871
    49
        assert(msg);
vb@2871
    50
        return PEP_STATUS_OK;
vb@2871
    51
    }
vb@2852
    52
};
vb@2852
    53
vb@2852
    54
SyncTests::SyncTests(string suitename, string test_home_dir) :
vb@2852
    55
    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
vb@2852
    56
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SyncTests::check_sync"),
vb@2852
    57
                                                                      static_cast<Func>(&SyncTests::check_sync)));
vb@2852
    58
}
vb@2852
    59
vb@2871
    60
void SyncTests::check_sync()
vb@2871
    61
{
vb@2852
    62
    Sync_Adapter adapter;
vb@2871
    63
    PEP_SESSION sync = NULL;
vb@2852
    64
vb@2871
    65
    PEP_STATUS status = init(&sync, Sync_Adapter::messageToSend);
vb@2871
    66
    TEST_ASSERT(status == PEP_STATUS_OK);
vb@2871
    67
vb@2871
    68
    status = register_sync_callbacks(
vb@2871
    69
            sync,
vb@2852
    70
            &adapter.q,
vb@2852
    71
            Sync_Adapter::notifyHandshake,
vb@2852
    72
            Sync_Adapter::inject_sync_event,
vb@2852
    73
            Sync_Adapter::retrieve_next_sync_event
vb@2852
    74
        );
vb@2871
    75
    TEST_ASSERT(status == PEP_STATUS_OK);
vb@2852
    76
vb@2871
    77
    TEST_ASSERT(sync->sync_state.keysync.state == Sole);
vb@2871
    78
vb@2871
    79
    unregister_sync_callbacks(sync);
vb@2871
    80
    release(sync);
vb@2852
    81
}
vb@2852
    82