r5493: *** empty log message ***
[uffi.git] / tests / time.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          time.lisp
6 ;;;; Purpose:       UFFI test file, time, use C structures
7 ;;;; Author:        Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: time.lisp,v 1.2 2003/08/13 18:53:42 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; *************************************************************************
15
16 (in-package #:uffi-tests)
17
18 (uffi:def-foreign-type time-t :unsigned-long)
19
20 (uffi:def-struct tm
21     (sec :int)
22   (min :int)
23   (hour :int)
24   (mday :int)
25   (mon :int)
26   (year :int)
27   (wday :int)
28   (yday :int)
29   (isdst :int))
30
31 (uffi:def-function ("time" c-time) 
32     ((time (* time-t)))
33   :returning time-t)
34
35 (uffi:def-function ("gmtime" c-gmtime)
36     ((time (* time-t)))
37   :returning (* tm))
38
39 (uffi:def-type time-t :unsigned-long)
40 (uffi:def-type tm-pointer (* tm))
41
42 (deftest time.1
43    (uffi:with-foreign-object (time 'time-t)
44      (setf (uffi:deref-pointer time :unsigned-long) 7381)
45      (uffi:deref-pointer time :unsigned-long))
46   7381)
47
48 (deftest time.2
49    (uffi:with-foreign-object (time 'time-t)
50      (setf (uffi:deref-pointer time :unsigned-long) 7381)
51      (let ((tm-ptr (the tm-pointer (c-gmtime time))))
52        (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
53                (uffi:get-slot-value tm-ptr 'tm 'mday)
54                (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
55                (uffi:get-slot-value tm-ptr 'tm 'hour)
56                (uffi:get-slot-value tm-ptr 'tm 'min)
57                (uffi:get-slot-value tm-ptr 'tm 'sec)
58                )))
59   1 1 1970 2 3 1)
60
61
62                     
63
64
65