Welcome to mirror list, hosted at ThFree Co, Russian Federation.

check_std_c_time.c « std_tests « csync « test - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: db8e72ff67c15b2c2acb0ee9ac98a92cc9dcdeae (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
/*
 * libcsync -- a library to sync a directory with another
 *
 * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
#include <string.h>

#include "csync_time.h"
#include "std/c_time.h"
#include <unistd.h>

#include "torture.h"

static void check_c_tspecdiff(void **state)
{
    struct timespec start, finish, diff;

    (void) state; /* unused */

    csync_gettime(&start);
    csync_gettime(&finish);

    diff = c_tspecdiff(finish, start);

    assert_int_equal(diff.tv_sec, 0);
    assert_true(diff.tv_nsec >= 0);
}

static void check_c_tspecdiff_five(void **state)
{
    struct timespec start, finish, diff;

    (void) state; /* unused */

    csync_gettime(&start);
    sleep(5);
    csync_gettime(&finish);

    diff = c_tspecdiff(finish, start);

    assert_int_equal(diff.tv_sec, 5);
    assert_true(diff.tv_nsec > 0);
}

static void check_c_secdiff(void **state)
{
    struct timespec start, finish;
    double diff;

    (void) state; /* unused */

    csync_gettime(&start);
    csync_gettime(&finish);

    diff = c_secdiff(finish, start);

    assert_true(diff >= 0.00 && diff < 1.00);
}

static void check_c_secdiff_three(void **state)
{
    struct timespec start, finish;
    double diff;

    (void) state; /* unused */

    csync_gettime(&start);
    sleep(3);
    csync_gettime(&finish);

    diff = c_secdiff(finish, start);

    assert_true(diff > 3.00 && diff < 4.00);
}

int torture_run_tests(void)
{
    const struct CMUnitTest tests[] = {
        cmocka_unit_test(check_c_tspecdiff),
        cmocka_unit_test(check_c_tspecdiff_five),
        cmocka_unit_test(check_c_secdiff),
        cmocka_unit_test(check_c_secdiff_three),
    };

    return cmocka_run_group_tests(tests, NULL, NULL);
}