Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
4f6e3300 A |
6 | * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.1 (the "License"). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
14c7c974 A |
13 | * |
14 | * The Original Code and all software distributed under the License are | |
4f6e3300 | 15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
14c7c974 A |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
4f6e3300 A |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
14c7c974 A |
21 | * |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* test standalone library */ | |
25 | #include <stdarg.h> | |
57c72a9a | 26 | #include "libsa.h" |
14c7c974 A |
27 | |
28 | #define TEST_RESULT "The quick brown #5 fox did fine.\n" | |
29 | #define TEST_FMT "The quick %s #%d fox did fine.\n" | |
30 | #define TEST_ARGS "brown", 5 | |
31 | ||
32 | char error_buf[1024]; | |
33 | char *sa_rld_error_buf_addr = error_buf; | |
34 | int sa_rld_error_buf_size = 1024; | |
35 | char progname[] = "satest"; | |
36 | ||
37 | /* | |
38 | * All printing of all messages goes through this function. | |
39 | */ | |
40 | void | |
41 | vprint( | |
42 | const char *format, | |
43 | va_list ap) | |
44 | { | |
45 | sa_rld_error_buf_size =- slvprintf(sa_rld_error_buf_addr, | |
46 | sa_rld_error_buf_size, | |
47 | format, ap); | |
48 | } | |
57c72a9a A |
49 | |
50 | int printf(const char * fmt, ...) | |
51 | { | |
52 | extern void putchar(int); | |
53 | va_list ap; | |
54 | va_start(ap, fmt); | |
55 | prf(fmt, ap, putchar, 0); | |
56 | va_end(ap); | |
57 | return 0; | |
58 | } | |
59 | ||
14c7c974 A |
60 | /* |
61 | * Print the error message and set the 'error' indication. | |
62 | */ | |
63 | void | |
64 | error( | |
65 | const char *format, | |
66 | ...) | |
67 | { | |
68 | va_list ap; | |
69 | ||
70 | // if(arch_multiple) | |
71 | // print_architecture_banner(); | |
72 | va_start(ap, format); | |
73 | // print("%s: ", progname); | |
74 | vprint(format, ap); | |
75 | // print("\n"); | |
76 | va_end(ap); | |
77 | // errors = 1; | |
78 | } | |
79 | ||
57c72a9a A |
80 | int |
81 | main(int argc, char **argv) | |
14c7c974 A |
82 | { |
83 | char buf[1024]; | |
57c72a9a | 84 | int ret; |
14c7c974 A |
85 | |
86 | printf("Testing standalone library\n"); | |
87 | printf("The following two lines should be identical:\n"); | |
88 | sprintf(buf, TEST_FMT, TEST_ARGS); | |
89 | printf(buf); | |
90 | printf(TEST_RESULT); | |
91 | printf("\nThe following two lines should be identical:\n"); | |
92 | error(TEST_FMT, TEST_ARGS); | |
93 | printf(error_buf); | |
94 | printf(TEST_RESULT); | |
95 | ||
96 | printf("Comparing two strings:\n"); | |
97 | ret = strcmp("abra","cadabra"); | |
98 | printf("%d should not be 0.\n",ret); | |
99 | ||
100 | printf("Comparing two strings:\n"); | |
101 | ret = strcmp("abra","abra"); | |
102 | printf("%d should be 0.\n",ret); | |
103 | ||
104 | printf("Comparing two strings:\n"); | |
105 | ret = strncmp("abcdefghij","abcdef",6); | |
106 | printf("%d should be 0.\n",ret); | |
107 | ||
108 | printf("printf(\"Test: %% 12s\\n\",\"abb\");\n"); | |
109 | printf("Test: abb\n"); | |
110 | printf("Test: % 12s\n","abb"); | |
111 | ||
112 | printf("printf(\"Test: %%04d\\n\",77);\n"); | |
113 | printf("Test: 0077\n"); | |
114 | printf("Test: %04d\n",77); | |
115 | ||
116 | printf("printf(\"Test: %% 2d\\n\",9);\n"); | |
117 | printf("Test: 9\n"); | |
118 | printf("Test: % 2d\n",9); | |
119 | ||
120 | printf("printf(\"Test: %% 8d\\n\",-9);\n"); | |
121 | printf("Test: -9\n"); | |
122 | printf("Test: % 8d\n",-9); | |
57c72a9a A |
123 | |
124 | return 0; | |
14c7c974 | 125 | } |