aboutsummaryrefslogtreecommitdiff
path: root/tests/test/simple/generated/driver.cxx
blob: ca6dfcb5de586fb2cd5c6286562f5586a561579b (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
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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>

#undef NDEBUG
#include <cassert>

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
  {
    istream* is;
    ifstream ifs;

    if (argv[i] != string ("-"))
    {
      ifs.open (argv[i]);

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

      is = &ifs;
    }
    else
      is = &cin;

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

  return r;
}