911e41fe9d65667c13b849892d086e5f0abcaa2e
[uffi.git] / tests / i18n.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          i18n.lisp
6 ;;;; Purpose:       UFFI test file of i18n functions
7 ;;;; Author:        Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2010
9 ;;;;
10 ;;;; This file, part of UFFI, is Copyright (c) 2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; *************************************************************************
13
14 (in-package #:uffi-tests)
15
16 (deftest :i18n/sto/1
17     (uffi:string-to-octets "")
18   #())
19
20 (deftest :i18n/sto/2
21     (uffi:string-to-octets "A")
22   #(65))
23
24 (deftest :i18n/sto/3
25     (uffi:string-to-octets "abc")
26   #(97 98 99))
27
28 ;; Below is UTF-8 encoded, 27 octets / 20 lisp characters
29 (deftest :i18n/sto/4
30     (uffi:string-to-octets "Iñtërnâtiônàlizætiøn" :encoding :utf-8)
31   #(73 195 177 116 195 171 114 110 195 162 116 105 195 180 110 195 160 108 105 122 195 166 116 105 195 184 110))
32
33 (deftest :i18n/sto/5
34     (length (uffi:string-to-octets "Iñtërnâtiônàlizætiøn" :encoding :utf-8))
35   27)
36
37 (deftest :i18n/feoc/1
38     (uffi:foreign-encoded-octet-count "")
39   0)
40
41 (deftest :i18n/feoc/2
42     (uffi:foreign-encoded-octet-count "A")
43   1)
44
45 (deftest :i18n/feoc/3
46     (uffi:foreign-encoded-octet-count "abc")
47   3)
48
49 (deftest :i18n/feoc/4
50     (uffi:foreign-encoded-octet-count "Iñtërnâtiônàlizætiøn"
51                                       :encoding :utf-8)
52   27)
53
54
55 (deftest :i18n/ots/1
56     (let ((octets '()))
57       (uffi:octets-to-string (make-array (list (length octets)) :element-type '(unsigned-byte 8)
58                                          :initial-contents octets)))
59   "")
60
61 (deftest :i18n/ots/2
62     (let ((octets '(65)))
63       (uffi:octets-to-string (make-array (list (length octets)) :element-type '(unsigned-byte 8)
64                                          :initial-contents octets)))
65   "A")
66
67 (deftest :i18n/ots/3
68     (let ((octets '(97 98 99)))
69       (uffi:octets-to-string (make-array (list (length octets)) :element-type '(unsigned-byte 8)
70                                          :initial-contents octets)))
71   "abc")
72
73 (deftest :i18n/ots/4
74     (let ((octets '(73 195 177 116 195 171 114 110 195 162 116 105 195 180
75                     110 195 160 108 105 122 195 166 116 105 195 184 110)))
76       (uffi:octets-to-string (make-array (list (length octets)) :element-type '(unsigned-byte 8)
77                                          :initial-contents octets)
78                              :encoding :utf-8))
79   "Iñtërnâtiônàlizætiøn")