r4719: *** 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.1 2003/04/30 14:06:14 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package :uffi-tests)
20
21 (uffi:def-foreign-type time-t :unsigned-long)
22
23 (uffi:def-struct tm
24     (sec :int)
25   (min :int)
26   (hour :int)
27   (mday :int)
28   (mon :int)
29   (year :int)
30   (wday :int)
31   (yday :int)
32   (isdst :int))
33
34 (uffi:def-function ("time" c-time) 
35     ((time (* time-t)))
36   :returning time-t)
37
38 (uffi:def-function ("gmtime" c-gmtime)
39     ((time (* time-t)))
40   :returning (* tm))
41
42 (uffi:def-type time-t :unsigned-long)
43 (uffi:def-type tm-pointer (* tm))
44
45 (deftest time.1
46    (uffi:with-foreign-object (time 'time-t)
47      (setf (uffi:deref-pointer time :unsigned-long) 7381)
48      (uffi:deref-pointer time :unsigned-long))
49   7381)
50
51 (deftest time.2
52    (uffi:with-foreign-object (time 'time-t)
53      (setf (uffi:deref-pointer time :unsigned-long) 7381)
54      (let ((tm-ptr (the tm-pointer (c-gmtime time))))
55        (values (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
56                (uffi:get-slot-value tm-ptr 'tm 'mday)
57                (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
58                (uffi:get-slot-value tm-ptr 'tm 'hour)
59                (uffi:get-slot-value tm-ptr 'tm 'min)
60                (uffi:get-slot-value tm-ptr 'tm 'sec)
61                )))
62   1 1 1970 2 3 1)
63
64
65                     
66
67
68