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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>~/Desktop/s/mu/003trace.test.cc.html</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; }
body { font-family: monospace; color: #d0d0d0; background-color: #000000; }
* { font-size: 1em; }
.cSpecial { color: #008000; }
.Constant { color: #008080; }
.Delimiter { color: #c000c0; }
.Comment { color: #8080ff; }
.Identifier { color: #008080; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
void test_trace_check_compares<span class="Delimiter">()</span> <span class="Delimiter">{</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer"</span><span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_check_filters_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_check_ignores_other_lines<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_check_always_finds_empty_lines<span class="Delimiter">()</span> <span class="Delimiter">{</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_check_treats_empty_layers_as_wildcards<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_check_multiple_lines_at_once<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">"foo^Dbar^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_check_always_finds_empty_lines2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"^D^D^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_orders_across_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">"foo^Dbar^Dqux^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_orders_across_layers2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"foo^Dbar^Dqux^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_checks_ordering_spanning_multiple_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"layer1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"layer2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"layer1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"layer1: foo^Dlayer2: bar^Dlayer1: qux^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_segments_within_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
new_trace_frame<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo^Dqux^D"</span><span class="Delimiter">);</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">"foo^D"</span><span class="Delimiter">);</span>
CHECK_TRACE_DOESNT_CONTAIN<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"foo^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_checks_ordering_across_layers_and_frames<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
new_trace_frame<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1/0: foo^Dtest layer 2: bar^Dtest layer 1: qux"</span><span class="Delimiter">);</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1: foo^Dtest layer 2: bar^Dtest layer 1/1: qux"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void trace_test_fn<span class="Delimiter">(</span>int n<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>n == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
new_trace_frame<span class="Delimiter">(</span><span class="Constant">"foo"</span><span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"foo"</span><span class="Delimiter">)</span> << <span class="Constant">"before: "</span> << n<span class="Delimiter">;</span>
trace_test_fn<span class="Delimiter">(</span>n-<span class="Constant">1</span><span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"foo"</span><span class="Delimiter">)</span> << <span class="Constant">"after: "</span> << n<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
void test_trace_keeps_level_together<span class="Delimiter">()</span> <span class="Delimiter">{</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"foo"</span><span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span>
trace_test_fn<span class="Delimiter">(</span><span class="Constant">4</span><span class="Delimiter">);</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"foo"</span><span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"before: 3^Dafter: 3^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_supports_multiple_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer 1,test layer 2"</span><span class="Delimiter">,</span> <span class="Constant">"foo^Dbar^Dqux^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_supports_hierarchical_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer/a"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"different layer/c"</span><span class="Delimiter">)</span> << <span class="Constant">"foo 2"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer/b"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"test layer/"</span><span class="Delimiter">,</span> <span class="Constant">"foo^Dbar^D"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_supports_count<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
CHECK_EQ<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_trace_supports_count2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span><span class="Delimiter">;</span>
CHECK_EQ<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Comment">// pending: DUMP tests</span>
<span class="Comment">// pending: readable_contents() adds newline if necessary.</span>
<span class="Comment">// pending: raise also prints to stderr.</span>
<span class="Comment">// pending: raise doesn't print to stderr if Hide_warnings is set.</span>
<span class="Comment">// pending: raise doesn't have to be saved if Hide_warnings is set, just printed.</span>
<span class="Comment">// pending: raise prints to stderr if Trace_stream is NULL.</span>
<span class="Comment">// pending: raise prints to stderr if Trace_stream is NULL even if Hide_warnings is set.</span>
<span class="Comment">// pending: raise << ... die() doesn't die if Hide_warnings is set.</span>
^L
<span class="Comment">// can't check trace because trace methods call 'split'</span>
void test_split_returns_at_least_one_elem<span class="Delimiter">()</span> <span class="Delimiter">{</span>
vector<string> result = split<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_split_returns_entire_input_when_no_delim<span class="Delimiter">()</span> <span class="Delimiter">{</span>
vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_split_works<span class="Delimiter">()</span> <span class="Delimiter">{</span>
vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc,def"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"def"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_split_works2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc,def,ghi"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"def"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">2</span>]<span class="Delimiter">,</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
void test_split_handles_multichar_delim<span class="Delimiter">()</span> <span class="Delimiter">{</span>
vector<string> result = split<span class="Delimiter">(</span><span class="Constant">"abc,,def,,ghi"</span><span class="Delimiter">,</span> <span class="Constant">",,"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">0</span>]<span class="Delimiter">,</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"def"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>result[<span class="Constant">2</span>]<span class="Delimiter">,</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|