1
0

exportheader_test.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 l;
  54. l.libshared();
  55. l.libshared_exported();
  56. l.libshared_deprecated();
  57. l.libshared_not_exported();
  58. #if defined(_WIN32) || defined(__CYGWIN__)
  59. l.libshared_excluded();
  60. #else
  61. // l.libshared_excluded(); LINK ERROR (NOT WIN32 AND NOT CYGWIN)
  62. #endif
  63. }
  64. {
  65. LibsharedNotExported l;
  66. // l.libshared(); LINK ERROR
  67. l.libshared_exported();
  68. l.libshared_deprecated();
  69. // l.libshared_not_exported(); LINK ERROR
  70. // l.libshared_excluded(); LINK ERROR
  71. }
  72. {
  73. LibsharedExcluded l;
  74. // l.libshared(); LINK ERROR
  75. l.libshared_exported();
  76. l.libshared_deprecated();
  77. // l.libshared_not_exported(); LINK ERROR
  78. // l.libshared_excluded(); LINK ERROR
  79. }
  80. libshared_exported();
  81. libshared_deprecated();
  82. // libshared_not_exported(); LINK ERROR
  83. // libshared_excluded(); LINK ERROR
  84. {
  85. Libstatic l;
  86. l.libstatic();
  87. l.libstatic_exported();
  88. l.libstatic_deprecated();
  89. l.libstatic_not_exported();
  90. l.libstatic_excluded();
  91. }
  92. {
  93. LibstaticNotExported l;
  94. l.libstatic();
  95. l.libstatic_exported();
  96. l.libstatic_deprecated();
  97. l.libstatic_not_exported();
  98. l.libstatic_excluded();
  99. }
  100. {
  101. LibstaticExcluded l;
  102. l.libstatic();
  103. l.libstatic_exported();
  104. l.libstatic_deprecated();
  105. l.libstatic_not_exported();
  106. l.libstatic_excluded();
  107. }
  108. libstatic_exported();
  109. libstatic_deprecated();
  110. libstatic_not_exported();
  111. libstatic_excluded();
  112. #if defined(SRC_DIR) && defined(BIN_DIR)
  113. compare(SRC_DIR "/libshared_export.h",
  114. BIN_DIR "/libshared/libshared_export.h");
  115. compare(SRC_DIR "/libstatic_export.h",
  116. BIN_DIR "/libstatic/libstatic_export.h");
  117. #endif
  118. return 0;
  119. }