2014-02-24 14:08:58 +04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2008-05-19 19:31:59 +04:00
|
|
|
#include <string.h>
|
2008-05-20 16:26:37 +04:00
|
|
|
#include <unistd.h>
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
#include "torture.h"
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-02-04 16:24:53 +04:00
|
|
|
#include "csync_time.h"
|
2008-05-20 14:08:22 +04:00
|
|
|
#include "std/c_time.h"
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
static void check_c_tspecdiff(void **state)
|
2008-05-19 19:31:59 +04:00
|
|
|
{
|
2012-10-16 19:06:46 +04:00
|
|
|
struct timespec start, finish, diff;
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
(void) state; /* unused */
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
csync_gettime(&start);
|
|
|
|
csync_gettime(&finish);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
diff = c_tspecdiff(finish, start);
|
2008-05-20 16:26:37 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
assert_int_equal(diff.tv_sec, 0);
|
|
|
|
assert_true(diff.tv_nsec >= 0);
|
2008-05-20 16:26:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
static void check_c_tspecdiff_five(void **state)
|
2008-05-19 19:31:59 +04:00
|
|
|
{
|
2012-10-16 19:06:46 +04:00
|
|
|
struct timespec start, finish, diff;
|
|
|
|
|
|
|
|
(void) state; /* unused */
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
csync_gettime(&start);
|
|
|
|
sleep(5);
|
|
|
|
csync_gettime(&finish);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
diff = c_tspecdiff(finish, start);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
assert_int_equal(diff.tv_sec, 5);
|
|
|
|
assert_true(diff.tv_nsec > 0);
|
2008-05-20 16:26:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
static void check_c_secdiff(void **state)
|
2008-05-20 16:26:37 +04:00
|
|
|
{
|
2012-10-16 19:06:46 +04:00
|
|
|
struct timespec start, finish;
|
|
|
|
double diff;
|
2008-05-20 16:26:37 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
(void) state; /* unused */
|
2008-05-20 16:26:37 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
csync_gettime(&start);
|
|
|
|
csync_gettime(&finish);
|
2008-05-20 16:26:37 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
diff = c_secdiff(finish, start);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
assert_true(diff >= 0.00 && diff < 1.00);
|
2008-05-19 19:31:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
static void check_c_secdiff_three(void **state)
|
|
|
|
{
|
|
|
|
struct timespec start, finish;
|
|
|
|
double diff;
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
(void) state; /* unused */
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
csync_gettime(&start);
|
|
|
|
sleep(3);
|
|
|
|
csync_gettime(&finish);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
diff = c_secdiff(finish, start);
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
assert_true(diff > 3.00 && diff < 4.00);
|
|
|
|
}
|
2008-05-19 19:31:59 +04:00
|
|
|
|
2012-10-16 19:06:46 +04:00
|
|
|
int torture_run_tests(void)
|
|
|
|
{
|
|
|
|
const UnitTest tests[] = {
|
|
|
|
unit_test(check_c_tspecdiff),
|
|
|
|
unit_test(check_c_tspecdiff_five),
|
|
|
|
unit_test(check_c_secdiff),
|
|
|
|
unit_test(check_c_secdiff_three),
|
|
|
|
};
|
|
|
|
|
|
|
|
return run_tests(tests);
|
2008-05-19 19:31:59 +04:00
|
|
|
}
|
|
|
|
|