exportheader_test.cpp 4.2 KB

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