head	1.2;
access;
symbols
	perseant-exfatfs-base-20250801:1.2
	perseant-exfatfs-base-20240630:1.2
	perseant-exfatfs:1.2.0.16
	perseant-exfatfs-base:1.2
	cjep_sun2x:1.2.0.14
	cjep_sun2x-base:1.2
	cjep_staticlib_x-base1:1.2
	cjep_staticlib_x:1.2.0.12
	cjep_staticlib_x-base:1.2
	phil-wifi-20200421:1.2
	phil-wifi-20200411:1.2
	phil-wifi-20200406:1.2
	pgoyette-compat-merge-20190127:1.2
	pgoyette-compat-20190127:1.2
	pgoyette-compat-20190118:1.2
	pgoyette-compat-1226:1.2
	pgoyette-compat-1126:1.2
	pgoyette-compat-1020:1.2
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.2
	pgoyette-compat-0728:1.2
	pgoyette-compat-0625:1.2
	pgoyette-compat-0521:1.2
	pgoyette-compat-0502:1.2
	pgoyette-compat-0422:1.2
	pgoyette-compat-0415:1.2
	pgoyette-compat-0407:1.2
	pgoyette-compat-0330:1.2
	pgoyette-compat-0322:1.2
	pgoyette-compat-0315:1.2
	pgoyette-compat:1.2.0.10
	pgoyette-compat-base:1.2
	perseant-stdc-iso10646:1.2.0.8
	perseant-stdc-iso10646-base:1.2
	prg-localcount2-base3:1.2
	prg-localcount2-base2:1.2
	prg-localcount2-base1:1.2
	prg-localcount2:1.2.0.6
	prg-localcount2-base:1.2
	pgoyette-localcount-20170426:1.2
	bouyer-socketcan-base1:1.2
	pgoyette-localcount-20170320:1.2
	bouyer-socketcan:1.2.0.4
	bouyer-socketcan-base:1.2
	pgoyette-localcount-20170107:1.2
	pgoyette-localcount-20161104:1.2
	localcount-20160914:1.2
	pgoyette-localcount-20160806:1.2
	pgoyette-localcount-20160726:1.2
	pgoyette-localcount:1.2.0.2
	pgoyette-localcount-base:1.2
	ntp-4-2-8p3:1.1.1.1
	UDEL:1.1.1;
locks; strict;
comment	@// @;


1.2
date	2015.10.23.18.06.24;	author christos;	state dead;
branches;
next	1.1;
commitid	yBAB8JCcf9IndgGy;

1.1
date	2015.07.10.13.02.52;	author christos;	state Exp;
branches
	1.1.1.1;
next	;
commitid	DcE5zM5BcAizUJsy;

1.1.1.1
date	2015.07.10.13.02.52;	author christos;	state Exp;
branches;
next	;
commitid	DcE5zM5BcAizUJsy;


desc
@@


1.2
log
@merge conflicts
@
text
@/*
 * timestructs.cpp -- test bed adaptors for time structs.
 *
 * Written by Juergen Perlinger (perlinger@@ntp.org) for the NTP project.
 * The contents of 'html/copyright.html' apply.
 */
#include "g_libntptest.h"
#include "g_timestructs.h"

extern "C" {
#include "timetoa.h"
#include "timevalops.h"
#include "timespecops.h"
}

namespace timeStruct {

std::ostream&
operator << (std::ostream& os, const timeStruct::l_fp_wrap& val)
{
	// raw data formatting
	os << "0x" << std::hex << val.V.l_ui << ':'
	   << std::setfill('0') << std::setw(8) << val.V.l_uf
	   << std::dec;
	// human-readable format
	os << '[' << lfptoa(&val.V, 10) << ']';
	return os;
}

std::ostream&
operator << (std::ostream& os, const timeStruct::timeval_wrap& val)
{
	// raw data formatting
	os << val.V.tv_sec << ':' << val.V.tv_usec;
	// human-readable format
	os << '['
	   << format_time_fraction(val.V.tv_sec, val.V.tv_usec, 6)
	   << ']';
	return os;
}

std::ostream&
operator << (std::ostream& os, const timeStruct::timespec_wrap& val)
{
	// raw data formatting
	os << val.V.tv_sec << ':' << val.V.tv_nsec;
	// human-readable format
	os << '['
	   << format_time_fraction(val.V.tv_sec, val.V.tv_nsec, 9)
	   << ']';
	return os;
}

// Implementation of the l_fp closeness predicate

AssertFpClose::AssertFpClose(
	u_int32 hi,
	u_int32 lo
	)
{
	limit.l_ui = hi;
	limit.l_uf = lo;
}

::testing::AssertionResult
AssertFpClose::operator()(
	const char* m_expr,
	const char* n_expr,
	const l_fp & m,
	const l_fp & n
	)
{
	l_fp diff;

	if (L_ISGEQ(&m, &n)) {
		diff = m;
		L_SUB(&diff, &n);
	} else {
		diff = n;
		L_SUB(&diff, &m);
	}
	if (L_ISGEQ(&limit, &diff))
		return ::testing::AssertionSuccess();

	return ::testing::AssertionFailure()
	    << m_expr << " which is " << l_fp_wrap(m)
	    << "\nand\n"
	    << n_expr << " which is " << l_fp_wrap(n)
	    << "\nare not close; diff=" << l_fp_wrap(diff);
}

// Implementation of the timeval closeness predicate

AssertTimevalClose::AssertTimevalClose(
	time_t hi,
	int32  lo
	)
{
	limit.tv_sec = hi;
	limit.tv_usec = lo;
}

::testing::AssertionResult
AssertTimevalClose::operator()(
	const char* m_expr,
	const char* n_expr,
	const struct timeval & m,
	const struct timeval & n
	)
{
	struct timeval diff;

	diff = abs_tval(sub_tval(m, n));
	if (cmp_tval(limit, diff) >= 0)
		return ::testing::AssertionSuccess();

	return ::testing::AssertionFailure()
	    << m_expr << " which is " << timeval_wrap(m)
	    << "\nand\n"
	    << n_expr << " which is " << timeval_wrap(n)
	    << "\nare not close; diff=" << timeval_wrap(diff);
}

// Implementation of the timespec closeness predicate

AssertTimespecClose::AssertTimespecClose(
	time_t hi,
	int32  lo
	)
{
	limit.tv_sec = hi;
	limit.tv_nsec = lo;
}

::testing::AssertionResult
AssertTimespecClose::operator()(
	const char* m_expr,
	const char* n_expr,
	const struct timespec & m,
	const struct timespec & n
	)
{
	struct timespec diff;

	diff = abs_tspec(sub_tspec(m, n));
	if (cmp_tspec(limit, diff) >= 0)
		return ::testing::AssertionSuccess();

	return ::testing::AssertionFailure()
	    << m_expr << " which is " << timespec_wrap(m)
	    << "\nand\n"
	    << n_expr << " which is " << timespec_wrap(n)
	    << "\nare not close; diff=" << timespec_wrap(diff);
}

} // namespace timeStruct
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Import ntp 4.2.8p3
@
text
@@
