exportheader_test.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. std::cout << "Could not open \"" << refName << "\"." << std::endl;
  19. exit(1);
  20. }
  21. std::ifstream test;
  22. test.open(testName);
  23. if (!test.is_open()) {
  24. std::cout << "Could not open \"" << testName << "\"." << std::endl;
  25. exit(1);
  26. }
  27. while (!ref.eof() && !test.eof()) {
  28. std::string refLine;
  29. std::string testLine;
  30. std::getline(ref, refLine);
  31. std::getline(test, testLine);
  32. // Some very old Borland runtimes (C++ Builder 5 WITHOUT Update 1) add a
  33. // trailing null to the string that we need to strip before testing for a
  34. // trailing space.
  35. if (refLine.size() && refLine[refLine.size() - 1] == 0) {
  36. refLine = refLine.substr(0, refLine.size() - 1);
  37. }
  38. if (testLine.size() && testLine[testLine.size() - 1] == 0) {
  39. testLine = testLine.substr(0, testLine.size() - 1);
  40. }
  41. // The reference files never have trailing spaces:
  42. if (testLine.size() && testLine[testLine.size() - 1] == ' ') {
  43. testLine = testLine.substr(0, testLine.size() - 1);
  44. }
  45. if (refLine != testLine) {
  46. std::cout << "Ref and test are not the same:\n Ref: \"" << refLine
  47. << "\"\n Test: \"" << testLine << "\"\n";
  48. exit(1);
  49. }
  50. }
  51. if (!ref.eof() || !test.eof()) {
  52. std::cout << "Ref and test have differing numbers of lines.";
  53. exit(1);
  54. }
  55. }
  56. int main()
  57. {
  58. {
  59. Libshared l;
  60. l.libshared();
  61. l.libshared_exported();
  62. l.libshared_deprecated();
  63. l.libshared_not_exported();
  64. DOES_NOT_BUILD(l.libshared_excluded();)
  65. }
  66. {
  67. LibsharedNotExported l;
  68. DOES_NOT_BUILD(l.libshared();)
  69. l.libshared_exported();
  70. l.libshared_deprecated();
  71. DOES_NOT_BUILD(l.libshared_not_exported();)
  72. DOES_NOT_BUILD(l.libshared_excluded();)
  73. }
  74. {
  75. LibsharedExcluded 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. libshared_exported();
  83. libshared_deprecated();
  84. DOES_NOT_BUILD(libshared_not_exported();)
  85. DOES_NOT_BUILD(libshared_excluded();)
  86. {
  87. Libstatic l;
  88. l.libstatic();
  89. l.libstatic_exported();
  90. l.libstatic_deprecated();
  91. l.libstatic_not_exported();
  92. l.libstatic_excluded();
  93. }
  94. {
  95. LibstaticNotExported l;
  96. l.libstatic();
  97. l.libstatic_exported();
  98. l.libstatic_deprecated();
  99. l.libstatic_not_exported();
  100. l.libstatic_excluded();
  101. }
  102. {
  103. LibstaticExcluded l;
  104. l.libstatic();
  105. l.libstatic_exported();
  106. l.libstatic_deprecated();
  107. l.libstatic_not_exported();
  108. l.libstatic_excluded();
  109. }
  110. libstatic_exported();
  111. libstatic_deprecated();
  112. libstatic_not_exported();
  113. libstatic_excluded();
  114. compare(SRC_DIR "/libshared_export.h",
  115. BIN_DIR "/libshared/libshared_export.h");
  116. compare(SRC_DIR "/libstatic_export.h",
  117. BIN_DIR "/libstatic/libstatic_export.h");
  118. return 0;
  119. }