Browse Source

Greatest has colors. Documented TombRaider1.h

Thomas Buck 10 years ago
parent
commit
213c0f8e7d
3 changed files with 183 additions and 68 deletions
  1. 1
    1
      include/System.h
  2. 124
    41
      include/TombRaider1.h
  3. 58
    26
      test/greatest.h

+ 1
- 1
include/System.h View File

66
     virtual ~System();
66
     virtual ~System();
67
 
67
 
68
     /*!
68
     /*!
69
-     * \brief Generates a buufered string for the printf call
69
+     * \brief Generates a buffered string for the printf call
70
      * \param string Format string like for printf
70
      * \param string Format string like for printf
71
      * \returns string in a buffer
71
      * \returns string in a buffer
72
      */
72
      */

+ 124
- 41
include/TombRaider1.h View File

16
 class TombRaider1 {
16
 class TombRaider1 {
17
 public:
17
 public:
18
 
18
 
19
-    // Associated with Item 7
19
+    /*!
20
+     * \brief States of a Wolf (Item 7)
21
+     */
20
     enum WolfStates {
22
     enum WolfStates {
21
         WolfState_Walking       = 1,
23
         WolfState_Walking       = 1,
22
         WolfState_Running       = 2,
24
         WolfState_Running       = 2,
31
         WolfState_Biting        = 12
33
         WolfState_Biting        = 12
32
     };
34
     };
33
 
35
 
34
-    // Associated with Item 8
36
+    /*!
37
+     * \brief States of a Bear (Item 8)
38
+     */
35
     enum BearStates {
39
     enum BearStates {
36
         BearState_Walking       = 0, //!< Walking on all fours
40
         BearState_Walking       = 0, //!< Walking on all fours
37
         BearState_Getting       = 1, //!< Getting back to all fours
41
         BearState_Getting       = 1, //!< Getting back to all fours
45
         BearState_Dying         = 9
49
         BearState_Dying         = 9
46
     };
50
     };
47
 
51
 
48
-    // Associated with Item 9
52
+    /*!
53
+     * \brief States of a Bat (Item 9)
54
+     */
49
     enum BatStates {
55
     enum BatStates {
50
         BatState_Starting = 1, //!< Starting to fly
56
         BatState_Starting = 1, //!< Starting to fly
51
         BatState_Flying   = 2, //!< Flying straight
57
         BatState_Flying   = 2, //!< Flying straight
54
         BatState_Dying    = 5
60
         BatState_Dying    = 5
55
     };
61
     };
56
 
62
 
57
-    // Associated with Item 10
63
+    /*!
64
+     * \brief States of a Crocodile on land (Item 10)
65
+     */
58
     enum CrocodileLandStates {
66
     enum CrocodileLandStates {
59
         CrocodileLandState_Stationary = 1,
67
         CrocodileLandState_Stationary = 1,
60
         CrocodileLandState_Walking1   = 2,
68
         CrocodileLandState_Walking1   = 2,
64
         CrocodileLandState_Dying      = 7
72
         CrocodileLandState_Dying      = 7
65
     };
73
     };
66
 
74
 
67
-    // Associated with Item 11
75
+    /*!
76
+     * \brief States of a Crocodile in water (Item 11)
77
+     */
68
     enum CrocodileWaterStates {
78
     enum CrocodileWaterStates {
69
         CrocodileWaterState_Swimming = 1,
79
         CrocodileWaterState_Swimming = 1,
70
         CrocodileWaterState_Biting   = 2,
80
         CrocodileWaterState_Biting   = 2,
71
         CrocodileWaterState_Dying    = 3
81
         CrocodileWaterState_Dying    = 3
72
     };
82
     };
73
 
83
 
74
-    // Associated with Items 12, 13 and 14
84
+    /*!
85
+     * \brief States of a Lion (Male & Female) and a Panther (Items 12, 13, 14)
86
+     */
75
     enum LionStates {
87
     enum LionStates {
76
         LionState_Standing = 1,
88
         LionState_Standing = 1,
77
         LionState_Walking  = 2,
89
         LionState_Walking  = 2,
82
         LionState_Biting2  = 7
94
         LionState_Biting2  = 7
83
     };
95
     };
84
 
96
 
85
-    // Associated with Item 15
97
+    /*!
98
+     * \brief States of a Gorilla (Item 15)
99
+     */
86
     enum GorillaStates {
100
     enum GorillaStates {
87
         GorillaState_Standing = 1,  //!< Standing on all fours
101
         GorillaState_Standing = 1,  //!< Standing on all fours
88
         GorillaState_Running  = 3,  //!< Running on all fours
102
         GorillaState_Running  = 3,  //!< Running on all fours
96
         GorillaState_Climbing = 11
110
         GorillaState_Climbing = 11
97
     };
111
     };
98
 
112
 
99
-    // Associated with Item 16
113
+    /*!
114
+     * \brief States of a Giant Rat on land (Item 16)
115
+     */
100
     enum GiantRatLandStates {
116
     enum GiantRatLandStates {
101
         GiantRatLandState_Standing  = 1,
117
         GiantRatLandState_Standing  = 1,
102
         GiantRatLandState_JumpBite  = 2,
118
         GiantRatLandState_JumpBite  = 2,
106
         GiantRatLandState_RearingUp = 6
122
         GiantRatLandState_RearingUp = 6
107
     };
123
     };
108
 
124
 
109
-    // Associated with Item 17
125
+    /*!
126
+     * \brief States of a Giant Rat in the water (Item 17)
127
+     */
110
     enum GiantRatWaterStates {
128
     enum GiantRatWaterStates {
111
         GiantRatWaterState_Swimming = 1,
129
         GiantRatWaterState_Swimming = 1,
112
         GiantRatWaterState_Biting   = 2,
130
         GiantRatWaterState_Biting   = 2,
113
         GiantRatWaterState_Dying    = 3
131
         GiantRatWaterState_Dying    = 3
114
     };
132
     };
115
 
133
 
116
-    // Associated with Item 18
134
+    /*!
135
+     * \brief States of a Tyrannosaur (Item 18)
136
+     */
117
     enum TyrannosaurStates {
137
     enum TyrannosaurStates {
118
         TyrannosaurState_Standing  = 1,
138
         TyrannosaurState_Standing  = 1,
119
         TyrannosaurState_Walking   = 2,
139
         TyrannosaurState_Walking   = 2,
124
         TyrannosaurState_Shaking   = 8  //!< Shaking Head and Spitting Out
144
         TyrannosaurState_Shaking   = 8  //!< Shaking Head and Spitting Out
125
     };
145
     };
126
 
146
 
127
-    // Associated with Item 19
147
+    /*!
148
+     * \brief States of a Raptor (Item 19)
149
+     */
128
     enum RaptorStates {
150
     enum RaptorStates {
129
         RaptorState_Dying     = 0,
151
         RaptorState_Dying     = 0,
130
         RaptorState_Standing  = 1,
152
         RaptorState_Standing  = 1,
136
         RaptorState_Biting    = 8,
158
         RaptorState_Biting    = 8,
137
     };
159
     };
138
 
160
 
139
-    // Associated with Item 20
161
+    /*!
162
+     * \brief States of a Winged Mutant (Item 20)
163
+     */
140
     enum WingedMutantStates {
164
     enum WingedMutantStates {
141
         WingedMutantState_Crouching = 1,
165
         WingedMutantState_Crouching = 1,
142
         WingedMutantState_Walking   = 2,
166
         WingedMutantState_Walking   = 2,
145
         WingedMutantState_Looking   = 6,
169
         WingedMutantState_Looking   = 6,
146
         WingedMutantState_Jumping   = 7,
170
         WingedMutantState_Jumping   = 7,
147
         WingedMutantState_Clawing   = 8,
171
         WingedMutantState_Clawing   = 8,
148
-        WingedMutantState_Aiming    = 9, //!< Aiming Right-Hand Gun
172
+        WingedMutantState_Aiming    = 9,  //!< Aiming Right-Hand Gun
149
         WingedMutantState_AimFire   = 10, //!< Aiming and Firing Left-Hand Gun
173
         WingedMutantState_AimFire   = 10, //!< Aiming and Firing Left-Hand Gun
150
         WingedMutantState_Firing    = 11, //!< Firing Right-Hand Gun
174
         WingedMutantState_Firing    = 11, //!< Firing Right-Hand Gun
151
         WingedMutantState_Standing  = 12,
175
         WingedMutantState_Standing  = 12,
152
         WingedMutantState_Flying    = 13
176
         WingedMutantState_Flying    = 13
153
     };
177
     };
154
 
178
 
155
-    // Associated with Item 23
179
+    /*!
180
+     * \brief States of a Centaur Mutant (Item 23)
181
+     */
156
     enum CentaurMutantStates {
182
     enum CentaurMutantStates {
157
         CentaurMutantState_Standing  = 1,
183
         CentaurMutantState_Standing  = 1,
158
         CentaurMutantState_Firing    = 2,
184
         CentaurMutantState_Firing    = 2,
162
         CentaurMutantState_Rearing   = 6  //!<  Rearing up
188
         CentaurMutantState_Rearing   = 6  //!<  Rearing up
163
     };
189
     };
164
 
190
 
165
-    // Associated with Item 24
191
+    /*!
192
+     * \brief States of a Mummy (Item 24)
193
+     */
166
     enum MummyStates {
194
     enum MummyStates {
167
         MummyState_Standing = 1,
195
         MummyState_Standing = 1,
168
         MummyState_Falling  = 2  //!< Falling forward
196
         MummyState_Falling  = 2  //!< Falling forward
169
     };
197
     };
170
 
198
 
171
-    // Associated with Item 27
199
+    /*!
200
+     * \brief States of Larson (Item 27)
201
+     */
172
     enum LarsonStates {
202
     enum LarsonStates {
173
         LarsonState_Walking1    = 0,
203
         LarsonState_Walking1    = 0,
174
         LarsonState_StandingGun = 1,
204
         LarsonState_StandingGun = 1,
180
         LarsonState_Firing      = 7
210
         LarsonState_Firing      = 7
181
     };
211
     };
182
 
212
 
183
-    // Associated with Item 28
213
+    /*!
214
+     * \brief States of Pierre (Item 28)
215
+     */
184
     enum PierreStates {
216
     enum PierreStates {
185
         PierreState_Standing   = 1,
217
         PierreState_Standing   = 1,
186
         PierreState_Walking    = 2,
218
         PierreState_Walking    = 2,
191
         PierreState_Firing     = 7
223
         PierreState_Firing     = 7
192
     };
224
     };
193
 
225
 
194
-    // Associated with Item 29
226
+    /*!
227
+     * \brief States of the Skateboard (Item 29)
228
+     */
195
     enum SkateboardStates {
229
     enum SkateboardStates {
196
         SkateboardState_BeingTurned = 0,
230
         SkateboardState_BeingTurned = 0,
197
         SkateboardState_Stationary1 = 1,
231
         SkateboardState_Stationary1 = 1,
200
         SkateboardState_Stationary4 = 4
234
         SkateboardState_Stationary4 = 4
201
     };
235
     };
202
 
236
 
203
-    // Associated with Item 30
237
+    /*!
238
+     * \brief States of the Skateboard Kid (Item 30)
239
+     */
204
     enum SkateboardKidStates {
240
     enum SkateboardKidStates {
205
         SkateboardKidState_Turning = 0, //!< Turning and Aiming?
241
         SkateboardKidState_Turning = 0, //!< Turning and Aiming?
206
         SkateboardKidState_Firing1 = 1,
242
         SkateboardKidState_Firing1 = 1,
210
         SkateboardKidState_Dying   = 5
246
         SkateboardKidState_Dying   = 5
211
     };
247
     };
212
 
248
 
213
-    // Associated with Item 31
249
+    /*!
250
+     * \brief States of the Cowboy (Item 31)
251
+     */
214
     enum CowboyStates {
252
     enum CowboyStates {
215
         CowboyState_Aiming1 = 1,
253
         CowboyState_Aiming1 = 1,
216
         CowboyState_Walking = 2,
254
         CowboyState_Walking = 2,
220
         CowboyState_Firing  = 6
258
         CowboyState_Firing  = 6
221
     };
259
     };
222
 
260
 
223
-    // Associated with Item 32
261
+    /*!
262
+     * \brief States of Mr. T (Item 32)
263
+     */
224
     enum MrTStates {
264
     enum MrTStates {
225
         MrTState_Dying    = 0,
265
         MrTState_Dying    = 0,
226
         MrTState_Standing = 1,
266
         MrTState_Standing = 1,
230
         MrTState_Firing   = 6
270
         MrTState_Firing   = 6
231
     };
271
     };
232
 
272
 
233
-    // Associated with Item 33
273
+    /*!
274
+     * \brief States of Winged Natla (Item 33)
275
+     */
234
     enum WingedNatlaStates {
276
     enum WingedNatlaStates {
235
         WingedNatlaState_Standing1 = 1,
277
         WingedNatlaState_Standing1 = 1,
236
         WingedNatlaState_Flying    = 2,
278
         WingedNatlaState_Flying    = 2,
242
         WingedNatlaState_Dying2    = 9, //!< Dying for real
284
         WingedNatlaState_Dying2    = 9, //!< Dying for real
243
     };
285
     };
244
 
286
 
245
-    // Associated with Item 34
287
+    /*!
288
+     * \brief States of the Giant Mutant (Item 34)
289
+     */
246
     enum GiantMutantStates {
290
     enum GiantMutantStates {
247
         GiantMutantState_Dying         = 0,
291
         GiantMutantState_Dying         = 0,
248
         GiantMutantState_Sitting       = 1, //!< Sitting on floor
292
         GiantMutantState_Sitting       = 1, //!< Sitting on floor
255
         GiantMutantState_Shaking       = 11 //!< Shaking victim with right hand
299
         GiantMutantState_Shaking       = 11 //!< Shaking victim with right hand
256
     };
300
     };
257
 
301
 
258
-    // Associated with Item 35
302
+    /*!
303
+     * \brief States of a piece of Collapsible Floor (Item 35)
304
+     */
259
     enum CollapsibleFloorStates {
305
     enum CollapsibleFloorStates {
260
         CollapsibleFloorState_Stationary = 0,
306
         CollapsibleFloorState_Stationary = 0,
261
         CollapsibleFloorState_Shaking    = 1,
307
         CollapsibleFloorState_Shaking    = 1,
263
         CollapsibleFloorState_Settling   = 3  //!< Settling down
309
         CollapsibleFloorState_Settling   = 3  //!< Settling down
264
     };
310
     };
265
 
311
 
266
-    // Associated with Item 36
312
+    /*!
313
+     * \brief States of a Swinging Blade (Item 36)
314
+     */
267
     enum SwingingBladeStates {
315
     enum SwingingBladeStates {
268
         SwingingBladeState_Stationary = 0,
316
         SwingingBladeState_Stationary = 0,
269
         SwingingBladeState_Swinging   = 2
317
         SwingingBladeState_Swinging   = 2
270
     };
318
     };
271
 
319
 
272
-    // Associated with Item 38
320
+    /*!
321
+     * \brief States of a Boulder (Item 38)
322
+     */
273
     enum BoulderStates {
323
     enum BoulderStates {
274
         BoulderState_Stationary = 0,
324
         BoulderState_Stationary = 0,
275
         BoulderState_Rolling    = 1
325
         BoulderState_Rolling    = 1
276
     };
326
     };
277
 
327
 
278
-    // Associated with Item 40
328
+    /*!
329
+     * \brief States of a Dart Gun (Item 40)
330
+     */
279
     enum DartGunStates {
331
     enum DartGunStates {
280
         DartGunState_Idle   = 0, //!< ?
332
         DartGunState_Idle   = 0, //!< ?
281
         DartGunState_Firing = 1  //!< ?
333
         DartGunState_Firing = 1  //!< ?
282
     };
334
     };
283
 
335
 
284
-    // Associated with Item 41
336
+    /*!
337
+     * \brief States of a Door opening upwards (Item 41)
338
+     */
285
     enum DoorUpwardStates {
339
     enum DoorUpwardStates {
286
         DoorUpwardState_Upward = 0,
340
         DoorUpwardState_Upward = 0,
287
         DoorUpwardState_OnSide = 1
341
         DoorUpwardState_OnSide = 1
288
     };
342
     };
289
 
343
 
290
-    // Associated with Item 42
344
+    /*!
345
+     * \brief States of a Slamming Door (Item 42)
346
+     */
291
     enum SlammingDoorStates {
347
     enum SlammingDoorStates {
292
         SlammingDoorState_Open   = 0,
348
         SlammingDoorState_Open   = 0,
293
         SlammingDoorState_Closed = 1
349
         SlammingDoorState_Closed = 1
294
     };
350
     };
295
 
351
 
296
-    // Associated with Item 44
352
+    /*!
353
+     * \brief States of the Handle of Thors Hammer (Item 44)
354
+     */
297
     enum ThorHammerHandleStates {
355
     enum ThorHammerHandleStates {
298
         ThorHammerHandleState_Stationary = 0, //!< Stationary in up position
356
         ThorHammerHandleState_Stationary = 0, //!< Stationary in up position
299
         ThorHammerHandleState_Moving1    = 1, //!< Moving down a little and returning
357
         ThorHammerHandleState_Moving1    = 1, //!< Moving down a little and returning
301
         ThorHammerHandleState_Stopped    = 3  //!< Stopped at down position
359
         ThorHammerHandleState_Stopped    = 3  //!< Stopped at down position
302
     };
360
     };
303
 
361
 
304
-    // Associated with Item 45
362
+    /*!
363
+     * \brief States of the Block of Thors Hammer (Item 45)
364
+     */
305
     enum ThorHammerBlockStates {
365
     enum ThorHammerBlockStates {
306
         ThorHammerBlockState_Stationary = 0,
366
         ThorHammerBlockState_Stationary = 0,
307
         ThorHammerBlockState_Moving1    = 1, //!< Moving down a little and returning
367
         ThorHammerBlockState_Moving1    = 1, //!< Moving down a little and returning
308
         ThorHammerBlockState_Moving2    = 2  //!< Moving down all the way
368
         ThorHammerBlockState_Moving2    = 2  //!< Moving down all the way
309
     };
369
     };
310
 
370
 
311
-    // Associated with Item 47
371
+    /*!
372
+     * \brief States of a Metal Rod (Item 47)
373
+     */
312
     enum MetalRodStates {
374
     enum MetalRodStates {
313
         MetalRodState_Stationary = 0,
375
         MetalRodState_Stationary = 0,
314
         MetalRodState_Moving     = 1
376
         MetalRodState_Moving     = 1
315
     };
377
     };
316
 
378
 
317
-    // Associated with Items 48 - 51
379
+    /*!
380
+     * \brief States of a Pushable Cubical (Item 48 - 51)
381
+     */
318
     enum PushableStates {
382
     enum PushableStates {
319
         PushableState_Stationary = 0,
383
         PushableState_Stationary = 0,
320
         PushableState_Pulled     = 1, //!< ?
384
         PushableState_Pulled     = 1, //!< ?
321
         PushableState_Pushed     = 2  //!< ?
385
         PushableState_Pushed     = 2  //!< ?
322
     };
386
     };
323
 
387
 
324
-    // Associated with Item 52
388
+    /*!
389
+     * \brief States of a Movable Tall Block (Item 52)
390
+     */
325
     enum MovableTallBlockStates {
391
     enum MovableTallBlockStates {
326
         MovableTallBlockState_Stationary     = 0,
392
         MovableTallBlockState_Stationary     = 0,
327
         MovableTallBlockState_MovingForward  = 1, //!< ?
393
         MovableTallBlockState_MovingForward  = 1, //!< ?
328
         MovableTallBlockState_MovingBackward = 2  //!< ?
394
         MovableTallBlockState_MovingBackward = 2  //!< ?
329
     };
395
     };
330
 
396
 
331
-    // Associated with Item 53
397
+    /*!
398
+     * \brief States of Falling Pieces (Item 53)
399
+     */
332
     enum FallingPiecesStates {
400
     enum FallingPiecesStates {
333
         FallingPiecesState_Stationary = 0,
401
         FallingPiecesState_Stationary = 0,
334
         FallingPiecesState_Falling    = 1,
402
         FallingPiecesState_Falling    = 1,
335
         FallingPiecesState_Settling   = 2  //!< Settling down
403
         FallingPiecesState_Settling   = 2  //!< Settling down
336
     };
404
     };
337
 
405
 
338
-    // Associated with Items 55, 56
406
+    /*!
407
+     * \brief States of a Switch (Item 55, 56)
408
+     */
339
     enum SwitchStates {
409
     enum SwitchStates {
340
         SwitchState_Off = 0,
410
         SwitchState_Off = 0,
341
         SwitchState_On  = 1  //!< States may be reversed
411
         SwitchState_On  = 1  //!< States may be reversed
342
     };
412
     };
343
 
413
 
344
-    // Associated with Items 57 - 66
414
+    /*!
415
+     * \brief States of a Door (Item 57 - 66)
416
+     */
345
     enum DoorStates {
417
     enum DoorStates {
346
         DoorState_Closed = 0,
418
         DoorState_Closed = 0,
347
         DoorState_Open   = 1
419
         DoorState_Open   = 1
348
     };
420
     };
349
 
421
 
350
-    // Associated with Items 74 - 76
422
+    /*!
423
+     * \brief States of a Cog (Item 74 - 76)
424
+     */
351
     enum CogStates {
425
     enum CogStates {
352
         CogState_Stationary = 0,
426
         CogState_Stationary = 0,
353
         CogState_Turning    = 1
427
         CogState_Turning    = 1
354
     };
428
     };
355
 
429
 
356
-    // Associated with Item 162
430
+    /*!
431
+     * \brief States of a Shack (Item 162)
432
+     */
357
     enum ShackStates {
433
     enum ShackStates {
358
         ShackState_StartingPosition = 0,
434
         ShackState_StartingPosition = 0,
359
         ShackState_DroppingFirst    = 1, //!< Dropping after first fuse
435
         ShackState_DroppingFirst    = 1, //!< Dropping after first fuse
362
         ShackState_OnGround         = 4
438
         ShackState_OnGround         = 4
363
     };
439
     };
364
 
440
 
365
-    // Associated with Items 163 and 181
441
+    /*!
442
+     * \brief States of a Mutant Egg & Holder (Item 163 & 181)
443
+     */
366
     enum MutantEggStates {
444
     enum MutantEggStates {
367
         MutantEggState_Starting = 0,
445
         MutantEggState_Starting = 0,
368
         MutantEggState_Hatching = 1  //!< Is the fragmenting hardcoded?
446
         MutantEggState_Hatching = 1  //!< Is the fragmenting hardcoded?
369
     };
447
     };
370
 
448
 
371
-    // Associated with Item 182
449
+    /*!
450
+     * \brief States of a Motorboat (Item 182)
451
+     */
372
     enum MotorboatStates {
452
     enum MotorboatStates {
373
         MotorboatState_StationaryInitial = 1,
453
         MotorboatState_StationaryInitial = 1,
374
         MotorboatState_Moving            = 2,
454
         MotorboatState_Moving            = 2,
375
         MotorboatState_StationaryFinal   = 3,
455
         MotorboatState_StationaryFinal   = 3,
376
     };
456
     };
377
 
457
 
458
+    /*!
459
+     * \brief Items & IDs in Tomb Raider 1
460
+     */
378
     enum Items {
461
     enum Items {
379
         Lara             = 0,
462
         Lara             = 0,
380
         PistolAnimation  = 1,
463
         PistolAnimation  = 1,

+ 58
- 26
test/greatest.h View File

3
  *
3
  *
4
  * Modified 2014 by Thomas Buck <xythobuz@xythobuz.de>
4
  * Modified 2014 by Thomas Buck <xythobuz@xythobuz.de>
5
  * --> C++ support
5
  * --> C++ support
6
+ * --> Included janoskk color output patch
7
+ * --> Modified it so a tty output is detected at runtime (now unix only)
6
  *
8
  *
7
  * Permission to use, copy, modify, and/or distribute this software for any
9
  * Permission to use, copy, modify, and/or distribute this software for any
8
  * purpose with or without fee is hereby granted, provided that the above
10
  * purpose with or without fee is hereby granted, provided that the above
21
 #define GREATEST_H
23
 #define GREATEST_H
22
 
24
 
23
 #ifdef __cplusplus
25
 #ifdef __cplusplus
24
-#define __STDC_VERSION__ 19901L // C++11 compilers support var args
25
 extern "C"
26
 extern "C"
26
 {
27
 {
27
 #endif
28
 #endif
81
 #include <stdio.h>
82
 #include <stdio.h>
82
 #include <string.h>
83
 #include <string.h>
83
 #include <time.h>
84
 #include <time.h>
85
+#include <unistd.h>
84
 
86
 
85
 
87
 
86
 /***********
88
 /***********
102
 #define GREATEST_USE_ABBREVS 1
104
 #define GREATEST_USE_ABBREVS 1
103
 #endif
105
 #endif
104
 
106
 
107
+/* Colorize the passed/failed results */
108
+#ifndef COLOR_FAIL
109
+#define COLOR_FAIL  "\033[22;31;1m"
110
+#endif
111
+#ifndef COLOR_PASS
112
+#define COLOR_PASS  "\033[22;32m"
113
+#endif
114
+#define COLOR_RESET "\033[22;0m"
115
+
105
 
116
 
106
 /*********
117
 /*********
107
  * Types *
118
  * Types *
229
 
240
 
230
 /* If __VA_ARGS__ (C99) is supported, allow parametric testing
241
 /* If __VA_ARGS__ (C99) is supported, allow parametric testing
231
  * without needing to manually manage the argument struct. */
242
  * without needing to manually manage the argument struct. */
232
-#if __STDC_VERSION__ >= 19901L
243
+#if defined __cplusplus || (__STDC_VERSION__ >= 19901L)
233
 #define GREATEST_RUN_TESTp(TEST, ...)                                   \
244
 #define GREATEST_RUN_TESTp(TEST, ...)                                   \
234
     do {                                                                \
245
     do {                                                                \
235
         if (greatest_pre_test(#TEST) == 1) {                            \
246
         if (greatest_pre_test(#TEST) == 1) {                            \
421
     GREATEST_SET_TIME(greatest_info.suite.post_suite);                  \
432
     GREATEST_SET_TIME(greatest_info.suite.post_suite);                  \
422
     if (greatest_info.suite.tests_run > 0) {                            \
433
     if (greatest_info.suite.tests_run > 0) {                            \
423
         fprintf(GREATEST_STDOUT,                                        \
434
         fprintf(GREATEST_STDOUT,                                        \
424
-            "\n%u tests - %u pass, %u fail, %u skipped",                \
435
+            "\n%u tests - %u %spass%s, %u %sfail%s, %u skipped",        \
425
             greatest_info.suite.tests_run,                              \
436
             greatest_info.suite.tests_run,                              \
426
             greatest_info.suite.passed,                                 \
437
             greatest_info.suite.passed,                                 \
438
+            (isatty(fileno(GREATEST_STDOUT))) ? (                       \
439
+            (!greatest_info.suite.failed) ? COLOR_PASS : COLOR_RESET    \
440
+            ) : "",                                                     \
441
+            (isatty(fileno(GREATEST_STDOUT))) ? COLOR_RESET : "",       \
427
             greatest_info.suite.failed,                                 \
442
             greatest_info.suite.failed,                                 \
443
+            (isatty(fileno(GREATEST_STDOUT))) ? (                       \
444
+            (greatest_info.suite.failed) ? COLOR_FAIL : COLOR_RESET     \
445
+            ) : "",                                                     \
446
+            (isatty(fileno(GREATEST_STDOUT))) ? COLOR_RESET : "",       \
428
             greatest_info.suite.skipped);                               \
447
             greatest_info.suite.skipped);                               \
429
         GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite,              \
448
         GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite,              \
430
             greatest_info.suite.post_suite);                            \
449
             greatest_info.suite.post_suite);                            \
442
                                                                         \
461
                                                                         \
443
 void greatest_do_pass(const char *name) {                               \
462
 void greatest_do_pass(const char *name) {                               \
444
     if (GREATEST_IS_VERBOSE()) {                                        \
463
     if (GREATEST_IS_VERBOSE()) {                                        \
445
-        fprintf(GREATEST_STDOUT, "PASS %s: %s",                         \
446
-            name, greatest_info.msg ? greatest_info.msg : "");          \
464
+        fprintf(GREATEST_STDOUT,                                        \
465
+                (isatty(fileno(GREATEST_STDOUT))) ?                     \
466
+                COLOR_PASS "PASS" COLOR_RESET " %s: %s" :               \
467
+                "PASS %s: %s",                                          \
468
+                name, greatest_info.msg ? greatest_info.msg : "");      \
447
     } else {                                                            \
469
     } else {                                                            \
448
         fprintf(GREATEST_STDOUT, ".");                                  \
470
         fprintf(GREATEST_STDOUT, ".");                                  \
449
     }                                                                   \
471
     }                                                                   \
453
 void greatest_do_fail(const char *name) {                               \
475
 void greatest_do_fail(const char *name) {                               \
454
     if (GREATEST_IS_VERBOSE()) {                                        \
476
     if (GREATEST_IS_VERBOSE()) {                                        \
455
         fprintf(GREATEST_STDOUT,                                        \
477
         fprintf(GREATEST_STDOUT,                                        \
478
+            (isatty(fileno(GREATEST_STDOUT))) ?                         \
479
+            COLOR_FAIL "FAIL" COLOR_RESET " %s: %s (%s:%u)" :           \
456
             "FAIL %s: %s (%s:%u)",                                      \
480
             "FAIL %s: %s (%s:%u)",                                      \
457
             name, greatest_info.msg ? greatest_info.msg : "",           \
481
             name, greatest_info.msg ? greatest_info.msg : "",           \
458
             greatest_info.fail_file, greatest_info.fail_line);          \
482
             greatest_info.fail_file, greatest_info.fail_line);          \
462
         if (greatest_info.col % greatest_info.width != 0)               \
486
         if (greatest_info.col % greatest_info.width != 0)               \
463
             fprintf(GREATEST_STDOUT, "\n");                             \
487
             fprintf(GREATEST_STDOUT, "\n");                             \
464
         greatest_info.col = 0;                                          \
488
         greatest_info.col = 0;                                          \
465
-        fprintf(GREATEST_STDOUT, "FAIL %s: %s (%s:%u)\n",               \
489
+        fprintf(GREATEST_STDOUT,                                        \
490
+            (isatty(fileno(GREATEST_STDOUT))) ?                         \
491
+            COLOR_FAIL "FAIL" COLOR_RESET " %s: %s (%s:%u)\n" :         \
492
+            "FAIL %s: %s (%s:%u)\n",                                    \
466
             name,                                                       \
493
             name,                                                       \
467
             greatest_info.msg ? greatest_info.msg : "",                 \
494
             greatest_info.msg ? greatest_info.msg : "",                 \
468
             greatest_info.fail_file, greatest_info.fail_line);          \
495
             greatest_info.fail_file, greatest_info.fail_line);          \
510
 /* Handle command-line arguments, etc. */
537
 /* Handle command-line arguments, etc. */
511
 #define GREATEST_MAIN_BEGIN()                                           \
538
 #define GREATEST_MAIN_BEGIN()                                           \
512
     do {                                                                \
539
     do {                                                                \
513
-        int _i = 0;                                                      \
540
+        int _i = 0;                                                     \
514
         memset(&greatest_info, 0, sizeof(greatest_info));               \
541
         memset(&greatest_info, 0, sizeof(greatest_info));               \
515
         if (greatest_info.width == 0) {                                 \
542
         if (greatest_info.width == 0) {                                 \
516
             greatest_info.width = GREATEST_DEFAULT_WIDTH;               \
543
             greatest_info.width = GREATEST_DEFAULT_WIDTH;               \
517
         }                                                               \
544
         }                                                               \
518
-        for (_i = 1; _i < argc; _i++) {                                    \
519
-            if (0 == strcmp("-t", argv[_i])) {                           \
520
-                if (argc <= _i + 1) {                                    \
545
+        for (_i = 1; _i < argc; _i++) {                                 \
546
+            if (0 == strcmp("-t", argv[_i])) {                          \
547
+                if (argc <= _i + 1) {                                   \
521
                     greatest_usage(argv[0]);                            \
548
                     greatest_usage(argv[0]);                            \
522
                     exit(EXIT_FAILURE);                                 \
549
                     exit(EXIT_FAILURE);                                 \
523
                 }                                                       \
550
                 }                                                       \
524
-                greatest_info.test_filter = argv[_i+1];                  \
525
-                _i++;                                                    \
526
-            } else if (0 == strcmp("-s", argv[_i])) {                    \
527
-                if (argc <= _i + 1) {                                    \
551
+                greatest_info.test_filter = argv[_i+1];                 \
552
+                _i++;                                                   \
553
+            } else if (0 == strcmp("-s", argv[_i])) {                   \
554
+                if (argc <= _i + 1) {                                   \
528
                     greatest_usage(argv[0]);                            \
555
                     greatest_usage(argv[0]);                            \
529
                     exit(EXIT_FAILURE);                                 \
556
                     exit(EXIT_FAILURE);                                 \
530
                 }                                                       \
557
                 }                                                       \
531
-                greatest_info.suite_filter = argv[_i+1];                 \
532
-                _i++;                                                    \
533
-            } else if (0 == strcmp("-f", argv[_i])) {                    \
558
+                greatest_info.suite_filter = argv[_i+1];                \
559
+                _i++;                                                   \
560
+            } else if (0 == strcmp("-f", argv[_i])) {                   \
534
                 greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL;        \
561
                 greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL;        \
535
-            } else if (0 == strcmp("-v", argv[_i])) {                    \
562
+            } else if (0 == strcmp("-v", argv[_i])) {                   \
536
                 greatest_info.flags |= GREATEST_FLAG_VERBOSE;           \
563
                 greatest_info.flags |= GREATEST_FLAG_VERBOSE;           \
537
-            } else if (0 == strcmp("-l", argv[_i])) {                    \
564
+            } else if (0 == strcmp("-l", argv[_i])) {                   \
538
                 greatest_info.flags |= GREATEST_FLAG_LIST_ONLY;         \
565
                 greatest_info.flags |= GREATEST_FLAG_LIST_ONLY;         \
539
-            } else if (0 == strcmp("-h", argv[_i])) {                    \
566
+            } else if (0 == strcmp("-h", argv[_i])) {                   \
540
                 greatest_usage(argv[0]);                                \
567
                 greatest_usage(argv[0]);                                \
541
                 exit(EXIT_SUCCESS);                                     \
568
                 exit(EXIT_SUCCESS);                                     \
542
             } else {                                                    \
569
             } else {                                                    \
543
                 fprintf(GREATEST_STDOUT,                                \
570
                 fprintf(GREATEST_STDOUT,                                \
544
-                    "Unknown argument '%s'\n", argv[_i]);                \
571
+                    "Unknown argument '%s'\n", argv[_i]);               \
545
                 greatest_usage(argv[0]);                                \
572
                 greatest_usage(argv[0]);                                \
546
                 exit(EXIT_FAILURE);                                     \
573
                 exit(EXIT_FAILURE);                                     \
547
             }                                                           \
574
             }                                                           \
559
                 greatest_info.end);                                     \
586
                 greatest_info.end);                                     \
560
             fprintf(GREATEST_STDOUT, "\n");                             \
587
             fprintf(GREATEST_STDOUT, "\n");                             \
561
             fprintf(GREATEST_STDOUT,                                    \
588
             fprintf(GREATEST_STDOUT,                                    \
562
-                "Pass: %u, fail: %u, skip: %u.\n",                      \
563
-                greatest_info.passed,                                   \
564
-                greatest_info.failed, greatest_info.skipped);           \
589
+                "%sPass: %u, fail: %u, "                                \
590
+                "skip: %u.%s\n",                                        \
591
+                (isatty(fileno(GREATEST_STDOUT))) ?                     \
592
+                ((greatest_info.failed) ? COLOR_FAIL : COLOR_PASS) :    \
593
+                "", greatest_info.passed,                               \
594
+                greatest_info.failed,                                   \
595
+                greatest_info.skipped,                                  \
596
+                (isatty(fileno(GREATEST_STDOUT))) ? COLOR_RESET : "");  \
565
         }                                                               \
597
         }                                                               \
566
         return (greatest_info.failed > 0                                \
598
         return (greatest_info.failed > 0                                \
567
             ? EXIT_FAILURE : EXIT_SUCCESS);                             \
599
             ? EXIT_FAILURE : EXIT_SUCCESS);                             \
592
 #define SET_SETUP      GREATEST_SET_SETUP_CB
624
 #define SET_SETUP      GREATEST_SET_SETUP_CB
593
 #define SET_TEARDOWN   GREATEST_SET_TEARDOWN_CB
625
 #define SET_TEARDOWN   GREATEST_SET_TEARDOWN_CB
594
 
626
 
595
-#if __STDC_VERSION__ >= 19901L
596
-#endif /* C99 */
627
+#if defined __cplusplus || (__STDC_VERSION__ >= 19901L)
597
 #define RUN_TESTp      GREATEST_RUN_TESTp
628
 #define RUN_TESTp      GREATEST_RUN_TESTp
629
+#endif
598
 #endif /* USE_ABBREVS */
630
 #endif /* USE_ABBREVS */
599
 
631
 
600
 #ifdef __cplusplus
632
 #ifdef __cplusplus

Loading…
Cancel
Save