File: testCTestResourceSpec.cxx

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (104 lines) | stat: -rw-r--r-- 2,585 bytes parent folder | download | duplicates (3)
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
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

#include "cmCTestResourceSpec.h"
#include "cmJSONState.h"

struct ExpectedSpec
{
  std::string Path;
  bool ParseResult;
  cmCTestResourceSpec Expected;
};

static std::vector<ExpectedSpec> const expectedResourceSpecs = {
  { "spec1.json",
    true,
    { { {
        { "gpus",
          {
            { "2", 4 },
            { "e", 1 },
          } },
        { "threads", {} },
      } },
      cmJSONState() } },
  { "spec2.json", true, {} },
  { "spec3.json", false, {} },
  { "spec4.json", false, {} },
  { "spec5.json", false, {} },
  { "spec6.json", false, {} },
  { "spec7.json", false, {} },
  { "spec8.json", false, {} },
  { "spec9.json", false, {} },
  { "spec10.json", false, {} },
  { "spec11.json", false, {} },
  { "spec12.json", false, {} },
  { "spec13.json", false, {} },
  { "spec14.json", true, {} },
  { "spec15.json", true, {} },
  { "spec16.json", true, {} },
  { "spec17.json", false, {} },
  { "spec18.json", false, {} },
  { "spec19.json", false, {} },
  { "spec20.json", true, {} },
  { "spec21.json", false, {} },
  { "spec22.json", false, {} },
  { "spec23.json", false, {} },
  { "spec24.json", false, {} },
  { "spec25.json", false, {} },
  { "spec26.json", false, {} },
  { "spec27.json", false, {} },
  { "spec28.json", false, {} },
  { "spec29.json", false, {} },
  { "spec30.json", false, {} },
  { "spec31.json", false, {} },
  { "spec32.json", false, {} },
  { "spec33.json", false, {} },
  { "spec34.json", false, {} },
  { "spec35.json", false, {} },
  { "spec36.json", false, {} },
  { "noexist.json", false, {} },
};

static bool testSpec(std::string const& path, bool expectedResult,
                     cmCTestResourceSpec const& expected)
{
  cmCTestResourceSpec actual;
  auto result = actual.ReadFromJSONFile(path);
  if (result != expectedResult) {
    std::cout << "ReadFromJSONFile(\"" << path << "\") failed \"" << std::endl;
    return false;
  }

  if (actual != expected) {
    std::cout << "ReadFromJSONFile(\"" << path
              << "\") did not give expected spec" << std::endl;
    return false;
  }

  return true;
}

int testCTestResourceSpec(int argc, char** const argv)
{
  if (argc < 2) {
    std::cout << "Invalid arguments.\n";
    return -1;
  }

  int retval = 0;
  for (auto const& spec : expectedResourceSpecs) {
    std::string path = argv[1];
    path += "/testCTestResourceSpec_data/";
    path += spec.Path;
    if (!testSpec(path, spec.ParseResult, spec.Expected)) {
      retval = -1;
    }
  }

  return retval;
}