Coverage Report

Created: 2026-03-07 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/tscore/TestBox.h
Line
Count
Source
1
/** @file
2
3
    Regression testing support class.
4
5
    @section license License
6
7
    Licensed to the Apache Software Foundation (ASF) under one
8
    or more contributor license agreements.  See the NOTICE file
9
    distributed with this work for additional information
10
    regarding copyright ownership.  The ASF licenses this file
11
    to you under the Apache License, Version 2.0 (the
12
    "License"); you may not use this file except in compliance
13
    with the License.  You may obtain a copy of the License at
14
15
    http://www.apache.org/licenses/LICENSE-2.0
16
17
    Unless required by applicable law or agreed to in writing, software
18
    distributed under the License is distributed on an "AS IS" BASIS,
19
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
    See the License for the specific language governing permissions and
21
    limitations under the License.
22
*/
23
24
#pragma once
25
26
#include <cstdarg>
27
#include "tscore/ink_apidefs.h"
28
#include "tscore/Regression.h"
29
30
namespace
31
{
32
/** Class to make handling regression tests easier.
33
    This holds the important regression test values so they don't have to
34
    be passed repeated.
35
*/
36
struct TestBox {
37
  using self = TestBox;    ///< Self reference type.
38
  RegressionTest *_test;   ///< The test object.
39
  int            *_status; ///< Current status pointer.
40
41
  /// Construct from @a test object and @a status pointer.
42
0
  TestBox(RegressionTest *test, int *status) : _test(test), _status(status) {}
43
  /// Construct from @a test object, @a status pointer and @a regression status.
44
0
  TestBox(RegressionTest *test, int *status, int rstatus) : _test(test), _status(status) { *this = rstatus; }
45
  /// Check the result and print a message on failure.
46
  bool check(bool result, char const *fmt, ...) TS_PRINTFLIKE(3, 4);
47
48
  /// Directly assign status.
49
  self &
50
  operator=(int status)
51
0
  {
52
0
    *_status = status;
53
0
    return *this;
54
0
  }
55
};
56
57
bool
58
TestBox::check(bool result, char const *fmt, ...)
59
0
{
60
0
  if (!result) {
61
0
    static size_t const N = 1 << 16;
62
0
    char                buffer[N]; // just stack, go big.
63
0
    va_list             ap;
64
0
    va_start(ap, fmt);
65
0
    vsnprintf(buffer, N, fmt, ap);
66
0
    va_end(ap);
67
0
    rprintf(_test, "%s\n", buffer);
68
0
    *_status = REGRESSION_TEST_FAILED;
69
0
  }
70
0
  return result;
71
0
}
72
} // namespace