aboutsummaryrefslogtreecommitdiff
path: root/tests/test/simple/generated/driver.cxx
blob: 18fd0ae4545307280eb23829d8a4a858c7727005 (plain)
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
// file      : tests/test/simple/generated/driver.cxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef _WIN32
#  include <chrono>
#  include <thread>
#else
#  include <libbutl/win32-utility.hxx>
#endif

#include <string>
#include <fstream>
#include <iostream>

using namespace std;

// If the -s option is specified, then also sleep for 5 seconds.
//
int
main (int argc, char* argv[])
{
  int i (1);
  for (; i != argc; ++i)
  {
    string a (argv[i]);

    if (a == "-s")
    {
      // MINGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep().
      //
#ifndef _WIN32
      this_thread::sleep_for (chrono::seconds (5));
#else
      Sleep (5000);
#endif
    }
    else
      break;
  }

  int r (0);

  if (i == argc)
  {
    cout << "1.2.3" << endl;
  }
  else
  {
    ifstream ifs (argv[i]);

    if (!ifs.is_open ())
      cerr << "unable to open " << argv[1] << endl;

    string s;
    r = getline (ifs, s) && s == "1.2.3" ? 0 : 1;
  }

  return r;
}