gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cprintftest.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Nathan Binkert
29  */
30 
31 #include <iostream>
32 #include <list>
33 #include <sstream>
34 #include <string>
35 
36 #include "base/cprintf.hh"
37 #include "base/misc.hh"
38 
39 using namespace std;
40 
41 int
43 {
44  char foo[] = "foo";
45  cprintf("%s\n", foo);
46 
47  string _bar = "asdfkhasdlkfjhasdlkfhjalksdjfhalksdjhfalksdjfhalksdjhf";
48  int length = 11;
49  char bar[length + 1];
50  bar[length] = 0;
51 
52  memcpy(bar, _bar.c_str(), length);
53  warn("%s\n", bar);
54 
55  cprintf("%d\n", 'A');
56  cprintf("%shits%%s + %smisses%%s\n", "test", "test");
57  cprintf("%%s%-10s %c he went home \'\"%d %#o %#x %1.5f %1.2E\n",
58  "hello", 'A', 1, 0xff, 0xfffffffffffffULL, 3.141592653589, 1.1e10);
59 
60  cprintf("another test\n");
61 
62  stringstream buffer;
63  ccprintf(buffer, "%-10s %c he home \'\"%d %#o %#x %1.5f %1.2E\n",
64  "hello", 'A', 1, 0xff, 0xfffffffffffffULL, 3.14159265, 1.1e10);
65 
66  double f = 314159.26535897932384;
67 
68  #define ctest(x, y) printf(x, y); cprintf(x, y); cprintf("\n");
69  ctest("%1.8f\n", f);
70  ctest("%2.8f\n", f);
71  ctest("%3.8f\n", f);
72  ctest("%4.8f\n", f);
73  ctest("%5.8f\n", f);
74  ctest("%6.8f\n", f);
75  ctest("%12.8f\n", f);
76  ctest("%1000.8f\n", f);
77  ctest("%1.0f\n", f);
78  ctest("%1.1f\n", f);
79  ctest("%1.2f\n", f);
80  ctest("%1.3f\n", f);
81  ctest("%1.4f\n", f);
82  ctest("%1.5f\n", f);
83  ctest("%1.6f\n", f);
84  ctest("%1.7f\n", f);
85  ctest("%1.8f\n", f);
86  ctest("%1.9f\n", f);
87  ctest("%1.10f\n", f);
88  ctest("%1.11f\n", f);
89  ctest("%1.12f\n", f);
90  ctest("%1.13f\n", f);
91  ctest("%1.14f\n", f);
92  ctest("%1.15f\n", f);
93  ctest("%1.16f\n", f);
94  ctest("%1.17f\n", f);
95  ctest("%1.18f\n", f);
96 
97  cout << "foo\n";
98 
99  f = 0.00000026535897932384;
100  ctest("%1.8f\n", f);
101  ctest("%2.8f\n", f);
102  ctest("%3.8f\n", f);
103  ctest("%4.8f\n", f);
104  ctest("%5.8f\n", f);
105  ctest("%6.8f\n", f);
106  ctest("%12.8f\n", f);
107  ctest("%1.0f\n", f);
108  ctest("%1.1f\n", f);
109  ctest("%1.2f\n", f);
110  ctest("%1.3f\n", f);
111  ctest("%1.4f\n", f);
112  ctest("%1.5f\n", f);
113  ctest("%1.6f\n", f);
114  ctest("%1.7f\n", f);
115  ctest("%1.8f\n", f);
116  ctest("%1.9f\n", f);
117  ctest("%1.10f\n", f);
118  ctest("%1.11f\n", f);
119  ctest("%1.12f\n", f);
120  ctest("%1.13f\n", f);
121  ctest("%1.14f\n", f);
122  ctest("%1.15f\n", f);
123  ctest("%1.16f\n", f);
124  ctest("%1.17f\n", f);
125  ctest("%1.18f\n", f);
126 
127  f = 0.00000026535897932384;
128  ctest("%1.8e\n", f);
129  ctest("%2.8e\n", f);
130  ctest("%3.8e\n", f);
131  ctest("%4.8e\n", f);
132  ctest("%5.8e\n", f);
133  ctest("%6.8e\n", f);
134  ctest("%12.8e\n", f);
135  ctest("%1.0e\n", f);
136  ctest("%1.1e\n", f);
137  ctest("%1.2e\n", f);
138  ctest("%1.3e\n", f);
139  ctest("%1.4e\n", f);
140  ctest("%1.5e\n", f);
141  ctest("%1.6e\n", f);
142  ctest("%1.7e\n", f);
143  ctest("%1.8e\n", f);
144  ctest("%1.9e\n", f);
145  ctest("%1.10e\n", f);
146  ctest("%1.11e\n", f);
147  ctest("%1.12e\n", f);
148  ctest("%1.13e\n", f);
149  ctest("%1.14e\n", f);
150  ctest("%1.15e\n", f);
151  ctest("%1.16e\n", f);
152  ctest("%1.17e\n", f);
153  ctest("%1.18e\n", f);
154 
155  cout << buffer.str();
156 
157  cout.width(0);
158  cout.precision(1);
159  cout << f << "\n";
160 
161  string foo1 = "string test";
162  cprintf("%s\n", foo1);
163 
164  stringstream foo2;
165  foo2 << "stringstream test";
166  cprintf("%s\n", foo2);
167 
168  cprintf("%c %c\n", 'c', 65);
169 
170  cout << '9' << endl;
171 
172  cout << endl;
173 
174  cprintf("%08.4f\n", 99.99);
175  cprintf("%0*.*f\n", 8, 4, 99.99);
176  cprintf("%07.*f\n", 4, 1.234);
177  cprintf("%#0*x\n", 9, 123412);
178  return 0;
179 }
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
Bitfield< 6 > f
Definition: miscregs.hh:1379
#define warn(...)
Definition: misc.hh:219
uint8_t length
Definition: inet.hh:334
#define ctest(x, y)
int main()
Definition: cprintftest.cc:42
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155

Generated on Fri Jun 9 2017 13:03:52 for gem5 by doxygen 1.8.6