exportheader_test.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "libshared.h"
  2. #include "libstatic.h"
  3. // #define BUILD_FAIL
  4. #ifndef BUILD_FAIL
  5. #define DOES_NOT_BUILD(function)
  6. #else
  7. #define DOES_NOT_BUILD(function) function
  8. #endif
  9. #include <fstream>
  10. #include <iostream>
  11. #include <stdlib.h>
  12. #include <string>
  13. void compare(const char* refName, const char* testName)
  14. {
  15. std::ifstream ref;
  16. ref.open(refName);
  17. if (!ref.is_open())
  18. {
  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. {
  26. std::cout << "Could not open \"" << testName << "\"." << std::endl;
  27. exit(1);
  28. }
  29. while (!ref.eof() && !test.eof())
  30. {
  31. std::string refLine;
  32. std::string testLine;
  33. std::getline(ref, refLine);
  34. std::getline(test, testLine);
  35. // Some very old Borland runtimes (C++ Builder 5 WITHOUT Update 1) add a
  36. // trailing null to the string that we need to strip before testing for a
  37. // trailing space.
  38. if (refLine.size() && refLine[refLine.size()-1] == 0)
  39. {
  40. refLine = refLine.substr(0, refLine.size() - 1);
  41. }
  42. if (testLine.size() && testLine[testLine.size()-1] == 0)
  43. {
  44. testLine = testLine.substr(0, testLine.size() - 1);
  45. }
  46. // The reference files never have trailing spaces:
  47. if (testLine.size() && testLine[testLine.size()-1] == ' ')
  48. {
  49. testLine = testLine.substr(0, testLine.size() - 1);
  50. }
  51. if (refLine != testLine)
  52. {
  53. std::cout << "Ref and test are not the same:\n Ref: \""
  54. << refLine << "\"\n Test: \"" << testLine << "\"\n";
  55. exit(1);
  56. }
  57. }
  58. if (!ref.eof() || !test.eof())
  59. {
  60. std::cout << "Ref and test have differing numbers of lines.";
  61. exit(1);
  62. }
  63. }
  64. int main()
  65. {
  66. {
  67. Libshared l;
  68. l.libshared();
  69. l.libshared_exported();
  70. l.libshared_deprecated();
  71. l.libshared_not_exported();
  72. DOES_NOT_BUILD(l.libshared_excluded();)
  73. }
  74. {
  75. LibsharedNotExported l;
  76. DOES_NOT_BUILD(l.libshared();)
  77. l.libshared_exported();
  78. l.libshared_deprecated();
  79. DOES_NOT_BUILD(l.libshared_not_exported();)
  80. DOES_NOT_BUILD(l.libshared_excluded();)
  81. }
  82. {
  83. LibsharedExcluded l;
  84. DOES_NOT_BUILD(l.libshared();)
  85. l.libshared_exported();
  86. l.libshared_deprecated();
  87. DOES_NOT_BUILD(l.libshared_not_exported();)
  88. DOES_NOT_BUILD(l.libshared_excluded();)
  89. }
  90. libshared_exported();
  91. libshared_deprecated();
  92. DOES_NOT_BUILD(libshared_not_exported();)
  93. DOES_NOT_BUILD(libshared_excluded();)
  94. {
  95. Libstatic l;
  96. l.libstatic();
  97. l.libstatic_exported();
  98. l.libstatic_deprecated();
  99. l.libstatic_not_exported();
  100. l.libstatic_excluded();
  101. }
  102. {
  103. LibstaticNotExported l;
  104. l.libstatic();
  105. l.libstatic_exported();
  106. l.libstatic_deprecated();
  107. l.libstatic_not_exported();
  108. l.libstatic_excluded();
  109. }
  110. {
  111. LibstaticExcluded l;
  112. l.libstatic();
  113. l.libstatic_exported();
  114. l.libstatic_deprecated();
  115. l.libstatic_not_exported();
  116. l.libstatic_excluded();
  117. }
  118. libstatic_exported();
  119. libstatic_deprecated();
  120. libstatic_not_exported();
  121. libstatic_excluded();
  122. compare(SRC_DIR "/libshared_export.h",
  123. BIN_DIR "/libshared/libshared_export.h");
  124. compare(SRC_DIR "/libstatic_export.h",
  125. BIN_DIR "/libstatic/libstatic_export.h");
  126. return 0;
  127. }