summaryrefslogtreecommitdiff
path: root/gnss-service/test/compliance-test/gnss-service-compliance-test.c
blob: ae4ed9c7a918191b467d65378b6b89af41b0b6f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**************************************************************************
* @licence app begin@
*
* SPDX-License-Identifier: MPL-2.0
*
* \ingroup GNSSService
* \author Marco Residori <marco.residori@xse.de>
*
* \copyright Copyright (C) 2013, XS Embedded GmbH
* 
* \license
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @licence end@
**************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>

#include "gnss-init.h"
#include "gnss-ext.h"
#include "log.h"

DLT_DECLARE_CONTEXT(gCtx);

#define TEST_FAILED EXIT_FAILURE
#define TEST_PASSED EXIT_SUCCESS

static int testResult = TEST_PASSED;
static int cbPositionSuccess = 0;

static void cbPosition(const TGNSSPosition position[], uint16_t numElements)
{
    int i;    
    if(position == NULL || numElements < 1)
    {
        LOG_ERROR_MSG(gCtx,"cbPosition failed!");
        testResult = TEST_FAILED;
        return;
    }
    cbPositionSuccess++;
    
    
}


bool checkMajorVersion(int expectedMajor)
{
    int major = -1;

    gnssGetVersion(&major, 0, 0);

    if(major != expectedMajor)
    {
        LOG_ERROR(gCtx,"Wrong API version: gnssGetVersion returned unexpected value %d != %d",
                  major, 
                  expectedMajor);

        testResult = TEST_FAILED;
        return false;
    }

    return true;
}

bool init()
{
    if(!checkMajorVersion(2))
    {
        return false;
    }

    if(!gnssInit())
    {
        return false;
    }

    return true;
}

int main()
{
    int i = 0;

    DLT_REGISTER_APP("GNSS", "GNSS-SERVICE-COMPLIANCE-TEST");
    DLT_REGISTER_CONTEXT(gCtx,"GCLT", "Global Context");
    
    LOG_INFO_MSG(gCtx,"Starting gnss-service-compliance-test...");

    if(init())
    {
        //register for GNSS
        gnssRegisterPositionCallback(&cbPosition);        

        //listen for events for about 10 seconds
        for(i = 0; i < 10; i++)
        {
            sleep(1);
        }

        //deregister
        gnssDeregisterPositionCallback(&cbPosition);        

        gnssDestroy();
    }
    
    //return if the test succeded or failed
    if(testResult == TEST_FAILED)
    { 
         LOG_INFO_MSG(gCtx,"TEST_FAILED");
         return EXIT_FAILURE;
    }

    LOG_INFO(gCtx,"TEST_PASSED with %d successful callbacks", cbPositionSuccess);

    return EXIT_SUCCESS;
}