summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/GenerateExportHeader/exportheader_test.cpp
blob: 7e3e0e43fa7fcb60c27fe36ca3ff8b1425ba98ad (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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

#include "libshared.h"

#include "libstatic.h"

#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <string>

void compare(const char* refName, const char* testName)
{
  std::ifstream ref;
  ref.open(refName);
  if (!ref.is_open()) {
    std::cout << "Could not open \"" << refName << "\"." << std::endl;
    exit(1);
  }
  std::ifstream test;
  test.open(testName);
  if (!test.is_open()) {
    std::cout << "Could not open \"" << testName << "\"." << std::endl;
    exit(1);
  }

  while (!ref.eof() && !test.eof()) {
    std::string refLine;
    std::string testLine;
    std::getline(ref, refLine);
    std::getline(test, testLine);
    // Some very old Borland runtimes (C++ Builder 5 WITHOUT Update 1) add a
    // trailing null to the string that we need to strip before testing for a
    // trailing space.
    if (refLine.size() && refLine[refLine.size() - 1] == 0) {
      refLine = refLine.substr(0, refLine.size() - 1);
    }
    if (testLine.size() && testLine[testLine.size() - 1] == 0) {
      testLine = testLine.substr(0, testLine.size() - 1);
    }
    // The reference files never have trailing spaces:
    if (testLine.size() && testLine[testLine.size() - 1] == ' ') {
      testLine = testLine.substr(0, testLine.size() - 1);
    }
    if (refLine != testLine) {
      std::cout << "Ref and test are not the same:\n  Ref:  \"" << refLine
                << "\"\n  Test: \"" << testLine << "\"\n";
      exit(1);
    }
  }
  if (!ref.eof() || !test.eof()) {
    std::cout << "Ref and test have differing numbers of lines.";
    exit(1);
  }
}

int main()
{
  {
    libshared::Class l;
    // l.method(); LINK ERROR
    l.method_exported();
    // l.method_deprecated(); LINK ERROR
    l.method_deprecated_exported();
    // l.method_excluded(); LINK ERROR

    // use_int(l.data); LINK ERROR
    use_int(l.data_exported);
    // use_int(l.data_excluded); LINK ERROR
  }

  {
    libshared::ExportedClass l;
    l.method();
    l.method_deprecated();
#if defined(_WIN32) || defined(__CYGWIN__)
    l.method_excluded();
#else
// l.method_excluded(); LINK ERROR (NOT WIN32 AND NOT CYGWIN)
#endif

    use_int(l.data);
#if defined(_WIN32) || defined(__CYGWIN__)
    use_int(l.data_excluded);
#else
// use_int(l.data_excluded); LINK ERROR (NOT WIN32 AND NOT CYGWIN)
#endif
  }

  {
    libshared::ExcludedClass l;
    // l.method(); LINK ERROR
    l.method_exported();
    // l.method_deprecated(); LINK ERROR
    l.method_deprecated_exported();
    // l.method_excluded(); LINK ERROR

    // use_int(l.data); LINK ERROR
    use_int(l.data_exported);
    // use_int(l.data_excluded); LINK ERROR
  }

  // libshared::function(); LINK ERROR
  libshared::function_exported();
  // libshared::function_deprecated(); LINK ERROR
  libshared::function_deprecated_exported();
  // libshared::function_excluded(); LINK ERROR

  // use_int(libshared::data); LINK ERROR
  use_int(libshared::data_exported);
  // use_int(libshared::data_excluded); LINK ERROR

  {
    libstatic::Class l;
    l.method();
    l.method_exported();
    l.method_deprecated();
    l.method_deprecated_exported();
    l.method_excluded();

    use_int(l.data);
    use_int(l.data_exported);
    use_int(l.data_excluded);
  }

  {
    libstatic::ExportedClass l;
    l.method();
    l.method_exported();
    l.method_deprecated();
    l.method_deprecated_exported();
    l.method_excluded();

    use_int(l.data);
    use_int(l.data_exported);
    use_int(l.data_excluded);
  }

  {
    libstatic::ExcludedClass l;
    l.method();
    l.method_exported();
    l.method_deprecated();
    l.method_deprecated_exported();
    l.method_excluded();

    use_int(l.data);
    use_int(l.data_exported);
    use_int(l.data_excluded);
  }

  libstatic::function();
  libstatic::function_exported();
  libstatic::function_deprecated();
  libstatic::function_deprecated_exported();
  libstatic::function_excluded();

  use_int(libstatic::data);
  use_int(libstatic::data_exported);
  use_int(libstatic::data_excluded);

#if defined(SRC_DIR) && defined(BIN_DIR)
  compare(SRC_DIR "/libshared_export.h",
          BIN_DIR "/libshared/libshared_export.h");
  compare(SRC_DIR "/libstatic_export.h",
          BIN_DIR "/libstatic/libstatic_export.h");
#endif

  return 0;
}