exportheader_test.cpp 4.2 KB

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