File: testFindPackageCommand.cxx

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • 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 (71 lines) | stat: -rw-r--r-- 2,914 bytes parent folder | download | duplicates (2)
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
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */

#include <cmConfigure.h> // IWYU pragma: keep

#include <iostream>
#include <string>
#include <vector>

#include "cmFindPackageCommand.h"

#define cmPassed(m) std::cout << "Passed: " << (m) << "\n"
#define cmFailed(m)                                                           \
  std::cout << "FAILED: " << (m) << "\n";                                     \
  failed = 1

int testFindPackageCommand(int /*unused*/, char* /*unused*/[])
{
  int failed = 0;

  // ----------------------------------------------------------------------
  // Test cmFindPackage::Sort
  std::vector<std::string> testString;
  testString.push_back("lib-0.0");
  testString.push_back("lib-1.2");
  testString.push_back("lib-2.0");
  testString.push_back("lib-19.0.1");
  testString.push_back("lib-20.01.1");
  testString.push_back("lib-20.2.2a");

  cmFindPackageCommand::Sort(testString.begin(), testString.end(),
                             cmFindPackageCommand::Natural,
                             cmFindPackageCommand::Asc);
  if (!(testString[0] == "lib-0.0" && testString[1] == "lib-1.2" &&
        testString[2] == "lib-2.0" && testString[3] == "lib-19.0.1" &&
        testString[4] == "lib-20.01.1" && testString[5] == "lib-20.2.2a")) {
    cmFailed("cmSystemTools::Sort fail with Natural ASC");
  }

  cmFindPackageCommand::Sort(testString.begin(), testString.end(),
                             cmFindPackageCommand::Natural,
                             cmFindPackageCommand::Dec);
  if (!(testString[5] == "lib-0.0" && testString[4] == "lib-1.2" &&
        testString[3] == "lib-2.0" && testString[2] == "lib-19.0.1" &&
        testString[1] == "lib-20.01.1" && testString[0] == "lib-20.2.2a")) {
    cmFailed("cmSystemTools::Sort fail with Natural ASC");
  }

  cmFindPackageCommand::Sort(testString.begin(), testString.end(),
                             cmFindPackageCommand::Name_order,
                             cmFindPackageCommand::Dec);
  if (!(testString[5] == "lib-0.0" && testString[4] == "lib-1.2" &&
        testString[3] == "lib-19.0.1" && testString[2] == "lib-2.0" &&
        testString[1] == "lib-20.01.1" && testString[0] == "lib-20.2.2a")) {
    cmFailed("cmSystemTools::Sort fail with Name DEC");
  }

  cmFindPackageCommand::Sort(testString.begin(), testString.end(),
                             cmFindPackageCommand::Name_order,
                             cmFindPackageCommand::Asc);
  if (!(testString[0] == "lib-0.0" && testString[1] == "lib-1.2" &&
        testString[2] == "lib-19.0.1" && testString[3] == "lib-2.0" &&
        testString[4] == "lib-20.01.1" && testString[5] == "lib-20.2.2a")) {
    cmFailed("cmSystemTools::Sort fail with Natural ASC");
  }

  if (!failed) {
    cmPassed("cmSystemTools::Sort working");
  }
  return failed;
}