File: bom.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (82 lines) | stat: -rw-r--r-- 3,404 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
   Copyright (C) 2006 Free SoftwareFoundation, Inc.

   Written by: David Ayers <d.ayers@inode.at>
   Date: March 2006

   This file is part of the GNUstep Base Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
*/

/*
Testing of Various Byte Order Markers.
*/

#import "Testing.h"
#import <Foundation/Foundation.h>

int main(int argc, char **argv)
{
  NSAutoreleasePool *pool = [NSAutoreleasePool new];
  NSString *file=@"utf8bom.txt";
  NSString *contents;
  NSData *data;

  contents = [NSString stringWithContentsOfFile: file];
  PASS([contents hasPrefix: @"This"], "stringWithContentsOfFile: UTF-8 BOM");

  data = [NSData dataWithContentsOfFile: file];
  contents = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
  PASS([contents hasPrefix: @"This"], "initWithData:encoding: UTF-8 BOM");

  data = [@"a" dataUsingEncoding: NSUTF8StringEncoding];
  PASS([data length] == 1, "utf8 no bom")
  data = [@"a" dataUsingEncoding: NSUnicodeStringEncoding];
  PASS([data length] == 4, "unicode has bom")
  data = [@"a" dataUsingEncoding: NSUTF16BigEndianStringEncoding];
  PASS([data length] == 2, "utf16 big endian no bom")
  data = [@"a" dataUsingEncoding: NSUTF16LittleEndianStringEncoding];
  PASS([data length] == 2, "utf16 little endian no bom")
  data = [@"a" dataUsingEncoding: NSUTF16StringEncoding];
  PASS([data length] == 4, "utf16 has bom")
  data = [@"a" dataUsingEncoding: NSUTF32BigEndianStringEncoding];
  PASS([data length] == 4, "utf32 big endian no bom")
  data = [@"a" dataUsingEncoding: NSUTF32LittleEndianStringEncoding];
  PASS([data length] == 4, "utf32 little endian no bom")
  data = [@"a" dataUsingEncoding: NSUTF32StringEncoding];
  PASS([data length] == 8, "utf32 has bom")

  data = [@"" dataUsingEncoding: NSUTF8StringEncoding];
  PASS([data length] == 0, "utf8 empty no bom")
  data = [@"" dataUsingEncoding: NSUnicodeStringEncoding];
  PASS([data length] == 2, "unicode empty has bom")
  data = [@"" dataUsingEncoding: NSUTF16BigEndianStringEncoding];
  PASS([data length] == 0, "utf16 big endian empty no bom")
  data = [@"" dataUsingEncoding: NSUTF16LittleEndianStringEncoding];
  PASS([data length] == 0, "utf16 little endian empty no bom")
  data = [@"" dataUsingEncoding: NSUTF16StringEncoding];
  PASS([data length] == 2, "utf16 empty has bom")
  data = [@"" dataUsingEncoding: NSUTF32BigEndianStringEncoding];
  PASS([data length] == 0, "utf32 big endian empty no bom")
  data = [@"" dataUsingEncoding: NSUTF32LittleEndianStringEncoding];
  PASS([data length] == 0, "utf32 little endian empty no bom")
  data = [@"" dataUsingEncoding: NSUTF32StringEncoding];
  PASS([data length] == 4, "utf32 empty has bom")

  [pool release];
  return 0;
}