X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Ftime.lisp;h=01c2090cafa46b3a719a8074c013a1b86ce29d52;hb=7004c2691d5695471c7bce9d62b82a1914cf05a2;hp=279dee0ff495f4ca27e19c38a76e8662ced9f899;hpb=ebedde4e67b858b1f65c5eb4dc7bc45978ed1e40;p=uffi.git diff --git a/tests/time.lisp b/tests/time.lisp index 279dee0..01c2090 100644 --- a/tests/time.lisp +++ b/tests/time.lisp @@ -26,16 +26,25 @@ (year :int) (wday :int) (yday :int) - (isdst :int)) + (isdst :int) + ;; gmoffset present on SusE SLES9 + (gmoffset :long)) (uffi:def-function ("time" c-time) ((time (* time-t))) + :module "c" :returning time-t) -(uffi:def-function ("gmtime" c-gmtime) +(uffi:def-function "gmtime" ((time (* time-t))) + :module "c" :returning (* tm)) +(uffi:def-function "asctime" + ((time (* tm))) + :module "c" + :returning :cstring) + (uffi:def-type time-t :unsigned-long) (uffi:def-type tm-pointer (* tm)) @@ -46,16 +55,16 @@ 7381) (deftest time.2 - (uffi:with-foreign-object (time 'time-t) - (setf (uffi:deref-pointer time :unsigned-long) 7381) - (let ((tm-ptr (the tm-pointer (c-gmtime time)))) - (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon)) - (uffi:get-slot-value tm-ptr 'tm 'mday) - (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year)) - (uffi:get-slot-value tm-ptr 'tm 'hour) - (uffi:get-slot-value tm-ptr 'tm 'min) - (uffi:get-slot-value tm-ptr 'tm 'sec) - ))) + (uffi:with-foreign-object (time 'time-t) + (setf (uffi:deref-pointer time :unsigned-long) 7381) + (let ((tm-ptr (the tm-pointer (gmtime time)))) + (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon)) + (uffi:get-slot-value tm-ptr 'tm 'mday) + (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year)) + (uffi:get-slot-value tm-ptr 'tm 'hour) + (uffi:get-slot-value tm-ptr 'tm 'min) + (uffi:get-slot-value tm-ptr 'tm 'sec) + ))) 1 1 1970 2 3 1) @@ -70,6 +79,7 @@ (uffi:def-function ("gettimeofday" c-gettimeofday) ((tv (* timeval)) (tz (* timezone))) + :module "c" :returning :int) (defun get-utime () @@ -90,3 +100,15 @@ (zerop res2)))) t) +(defun posix-time-to-asctime (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) + (asctime (gmtime time)))))) + +(deftest time.3 + (posix-time-to-asctime 0) + "Thu Jan 1 00:00:00 1970")