summaryrefslogtreecommitdiffstats
path: root/test/unit/app/system_linux_test.cpp
blob: b0a05ca04819de3023d0d8bfe16e8cbd81b89f38 (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
#include "app/system.h"
#include "app/system_linux.h"

#include <gtest/gtest.h>

class CSystemUtilsLinuxWrapper : public CSystemUtilsLinux
{
public:
    CSystemUtilsLinuxWrapper() {}
};

class SystemUtilsLinuxUT : public testing::Test
{
protected:
    static const long long SEC = 1000000000;

    CSystemUtilsLinuxWrapper systemUtils;
};


TEST_F(SystemUtilsLinuxUT, TimeStampDiff)
{
    SystemTimeStamp before, after;

    before.clockTime.tv_sec = 1;
    before.clockTime.tv_nsec = 100;

    after.clockTime.tv_sec = 1;
    after.clockTime.tv_nsec = 900;

    long long tDiff = systemUtils.TimeStampExactDiff(&before, &after);
    EXPECT_EQ( 800, tDiff);

    tDiff = systemUtils.TimeStampExactDiff(&after, &before);
    EXPECT_EQ(-800, tDiff);

    // -------

    before.clockTime.tv_sec = 2;
    before.clockTime.tv_nsec = 200;

    after.clockTime.tv_sec = 3;
    after.clockTime.tv_nsec = 500;

    tDiff = systemUtils.TimeStampExactDiff(&before, &after);
    EXPECT_EQ( SEC + 300, tDiff);

    tDiff = systemUtils.TimeStampExactDiff(&after, &before);
    EXPECT_EQ(-SEC - 300, tDiff);

    // -------

    before.clockTime.tv_sec = 3;
    before.clockTime.tv_nsec = 200;

    after.clockTime.tv_sec = 4;
    after.clockTime.tv_nsec = 100;

    tDiff = systemUtils.TimeStampExactDiff(&before, &after);
    EXPECT_EQ( SEC - 100, tDiff);

    tDiff = systemUtils.TimeStampExactDiff(&after, &before);
    EXPECT_EQ(-SEC + 100, tDiff);
}