| 1 |
|
| 2 |
#include <fstream> |
| 3 |
#include <iostream> |
| 4 |
#include <string> |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
#include "libshared.h" |
| 9 |
#include "libstatic.h" |
| 10 |
|
| 11 |
static void rtrim(std::string& str, char byte) |
| 12 |
{ |
| 13 |
size_t const size = str.size(); |
| 14 |
if (size && str[size - 1] == byte) { |
| 15 |
str.resize(size - 1); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
void compare(char const* refName, char const* testName) |
| 20 |
{ |
| 21 |
std::ifstream ref; |
| 22 |
ref.open(refName); |
| 23 |
if (!ref.is_open()) { |
| 24 |
std::cout << "Could not open \"" << refName << "\"." << std::endl; |
| 25 |
exit(1); |
| 26 |
} |
| 27 |
std::ifstream test; |
| 28 |
test.open(testName); |
| 29 |
if (!test.is_open()) { |
| 30 |
std::cout << "Could not open \"" << testName << "\"." << std::endl; |
| 31 |
exit(1); |
| 32 |
} |
| 33 |
|
| 34 |
while (!ref.eof() && !test.eof()) { |
| 35 |
std::string refLine; |
| 36 |
std::string testLine; |
| 37 |
std::getline(ref, refLine); |
| 38 |
std::getline(test, testLine); |
| 39 |
// Some very old Borland runtimes (C++ Builder 5 WITHOUT Update 1) add a |
| 40 |
// trailing null to the string that we need to strip before testing for a |
| 41 |
// trailing space. |
| 42 |
rtrim(refLine, 0); |
| 43 |
rtrim(testLine, 0); |
| 44 |
// The reference files never have trailing spaces: |
| 45 |
rtrim(testLine, ' '); |
| 46 |
// Strip trailing CR. LF is not returned by getline, but CR is returned |
| 47 |
// on some platforms. |
| 48 |
rtrim(refLine, '\r'); |
| 49 |
rtrim(testLine, '\r'); |
| 50 |
if (refLine != testLine) { |
| 51 |
std::cout << "Ref and test are not the same:\n Ref: \"" << refLine |
| 52 |
<< "\"\n Test: \"" << testLine << "\"\n"; |
| 53 |
exit(1); |
| 54 |
} |
| 55 |
} |
| 56 |
if (!ref.eof() || !test.eof()) { |
| 57 |
std::cout << "Ref and test have differing numbers of lines."; |
| 58 |
exit(1); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
int main() |
| 63 |
{ |
| 64 |
{ |
| 65 |
libshared::Class l; |
| 66 |
// l.method(); LINK ERROR |
| 67 |
l.method_exported(); |
| 68 |
// l.method_deprecated(); LINK ERROR |
| 69 |
l.method_deprecated_exported(); |
| 70 |
// l.method_excluded(); LINK ERROR |
| 71 |
|
| 72 |
// use_int(l.data); LINK ERROR |
| 73 |
use_int(l.data_exported); |
| 74 |
// use_int(l.data_excluded); LINK ERROR |
| 75 |
} |
| 76 |
|
| 77 |
{ |
| 78 |
libshared::ExportedClass l; |
| 79 |
l.method(); |
| 80 |
l.method_deprecated(); |
| 81 |
#if defined(_WIN32) || defined(__CYGWIN__) |
| 82 |
l.method_excluded(); |
| 83 |
#else |
| 84 |
// l.method_excluded(); LINK ERROR (NOT WIN32 AND NOT CYGWIN) |
| 85 |
#endif |
| 86 |
|
| 87 |
use_int(l.data); |
| 88 |
#if defined(_WIN32) || defined(__CYGWIN__) |
| 89 |
use_int(l.data_excluded); |
| 90 |
#else |
| 91 |
// use_int(l.data_excluded); LINK ERROR (NOT WIN32 AND NOT CYGWIN) |
| 92 |
#endif |
| 93 |
} |
| 94 |
|
| 95 |
{ |
| 96 |
libshared::ExcludedClass l; |
| 97 |
// l.method(); LINK ERROR |
| 98 |
l.method_exported(); |
| 99 |
// l.method_deprecated(); LINK ERROR |
| 100 |
l.method_deprecated_exported(); |
| 101 |
// l.method_excluded(); LINK ERROR |
| 102 |
|
| 103 |
// use_int(l.data); LINK ERROR |
| 104 |
use_int(l.data_exported); |
| 105 |
// use_int(l.data_excluded); LINK ERROR |
| 106 |
} |
| 107 |
|
| 108 |
// libshared::function(); LINK ERROR |
| 109 |
libshared::function_exported(); |
| 110 |
// libshared::function_deprecated(); LINK ERROR |
| 111 |
libshared::function_deprecated_exported(); |
| 112 |
// libshared::function_excluded(); LINK ERROR |
| 113 |
|
| 114 |
// use_int(libshared::data); LINK ERROR |
| 115 |
use_int(libshared::data_exported); |
| 116 |
// use_int(libshared::data_excluded); LINK ERROR |
| 117 |
|
| 118 |
{ |
| 119 |
libstatic::Class l; |
| 120 |
l.method(); |
| 121 |
l.method_exported(); |
| 122 |
l.method_deprecated(); |
| 123 |
l.method_deprecated_exported(); |
| 124 |
l.method_excluded(); |
| 125 |
|
| 126 |
use_int(l.data); |
| 127 |
use_int(l.data_exported); |
| 128 |
use_int(l.data_excluded); |
| 129 |
} |
| 130 |
|
| 131 |
{ |
| 132 |
libstatic::ExportedClass l; |
| 133 |
l.method(); |
| 134 |
l.method_exported(); |
| 135 |
l.method_deprecated(); |
| 136 |
l.method_deprecated_exported(); |
| 137 |
l.method_excluded(); |
| 138 |
|
| 139 |
use_int(l.data); |
| 140 |
use_int(l.data_exported); |
| 141 |
use_int(l.data_excluded); |
| 142 |
} |
| 143 |
|
| 144 |
{ |
| 145 |
libstatic::ExcludedClass l; |
| 146 |
l.method(); |
| 147 |
l.method_exported(); |
| 148 |
l.method_deprecated(); |
| 149 |
l.method_deprecated_exported(); |
| 150 |
l.method_excluded(); |
| 151 |
|
| 152 |
use_int(l.data); |
| 153 |
use_int(l.data_exported); |
| 154 |
use_int(l.data_excluded); |
| 155 |
} |
| 156 |
|
| 157 |
libstatic::function(); |
| 158 |
libstatic::function_exported(); |
| 159 |
libstatic::function_deprecated(); |
| 160 |
libstatic::function_deprecated_exported(); |
| 161 |
libstatic::function_excluded(); |
| 162 |
|
| 163 |
use_int(libstatic::data); |
| 164 |
use_int(libstatic::data_exported); |
| 165 |
use_int(libstatic::data_excluded); |
| 166 |
|
| 167 |
#if defined(SRC_DIR) && defined(BIN_DIR) |
| 168 |
compare(SRC_DIR "/libshared_export.h", |
| 169 |
BIN_DIR "/libshared/libshared_export.h"); |
| 170 |
compare(SRC_DIR "/libstatic_export.h", |
| 171 |
BIN_DIR "/libstatic/libstatic_export.h"); |
| 172 |
#endif |
| 173 |
|
| 174 |
return 0; |
| 175 |
} |