File: spec_arg_verbosity_test.cc

package info (click to toggle)
benchmark 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,708 kB
  • sloc: cpp: 13,013; python: 2,390; ansic: 38; sh: 28; makefile: 12
file content (43 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download | duplicates (19)
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
#include <string.h>

#include <iostream>

#include "benchmark/benchmark.h"

// Tests that the user specified verbosity level can be get.
static void BM_Verbosity(benchmark::State& state) {
  for (auto _ : state) {
  }
}
BENCHMARK(BM_Verbosity);

int main(int argc, char** argv) {
  const int32_t flagv = 42;

  // Verify that argv specify --v=42.
  bool found = false;
  for (int i = 0; i < argc; ++i) {
    if (strcmp("--v=42", argv[i]) == 0) {
      found = true;
      break;
    }
  }
  if (!found) {
    std::cerr << "This test requires '--v=42' to be passed as a command-line "
              << "argument.\n";
    return 1;
  }

  benchmark::Initialize(&argc, argv);

  // Check that the current flag value is reported accurately via the
  // GetBenchmarkVerbosity() function.
  if (flagv != benchmark::GetBenchmarkVerbosity()) {
    std::cerr
        << "Seeing different value for flags. GetBenchmarkVerbosity() returns ["
        << benchmark::GetBenchmarkVerbosity() << "] expected flag=[" << flagv
        << "]\n";
    return 1;
  }
  return 0;
}