X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Ftime.lisp;h=aeedba089c3f813bcf1f194fe435c29dd2832e4f;hb=dc12f6625ed6c85ad380525d01c0726100bf7a3d;hp=0dd1816d22aa6881c6acfacaacec8b190ba20eab;hpb=33b8a5afb55eb161ef04a1be94e6d2dca85c748c;p=uffi.git diff --git a/tests/time.lisp b/tests/time.lisp index 0dd1816..aeedba0 100644 --- a/tests/time.lisp +++ b/tests/time.lisp @@ -7,16 +7,13 @@ ;;;; Author: Kevin M. Rosenberg ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id: time.lisp,v 1.1 2003/04/30 14:06:14 kevin Exp $ +;;;; $Id$ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; -;;;; UFFI users are granted the rights to distribute and use this software -;;;; as governed by the terms of the Lisp Lesser GNU Public License -;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. ;;;; ************************************************************************* -(in-package :uffi-tests) +(in-package #:uffi-tests) (uffi:def-foreign-type time-t :unsigned-long) @@ -62,7 +59,44 @@ 1 1 1970 2 3 1) - +(uffi:def-struct timeval + (secs :long) + (usecs :long)) + +(uffi:def-struct timezone + (minutes-west :int) + (dsttime :int)) +(uffi:def-function ("gettimeofday" c-gettimeofday) + ((tv (* timeval)) + (tz (* timezone))) + :returning :int) + +(defun get-utime () + (uffi:with-foreign-object (tv 'timeval) + (let ((res (c-gettimeofday tv (uffi:make-null-pointer 'timezone)))) + (values + (+ (* 1000000 (uffi:get-slot-value tv 'timeval 'secs)) + (uffi:get-slot-value tv 'timeval 'usecs)) + res)))) +(deftest timeofday.1 + (multiple-value-bind (t1 res1) (get-utime) + (multiple-value-bind (t2 res2) (get-utime) + (and (or (= t2 t1) (> t2 t1)) + (> t1 1000000000) + (> t2 1000000000) + (zerop res1) + (zerop res2)))) + t) + +(defun posix-time-to-localtime-string (secs) + "Converts number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)" + (string-right-trim + '(#\newline #\return) + (uffi:convert-from-cstring + (uffi:with-foreign-object (time 'time-t) + (setf (uffi:deref-pointer time :unsigned-long) + secs) + (c-time time)))))